blob: df7b1332a1ec2fa80834b94c233f38a427a0f350 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Bergf84f7712013-11-14 17:14:45 +010033static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020034 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010035static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg2a94fe42013-11-19 15:19:39 +010050/* multicast groups */
51enum nl80211_multicast_groups {
52 NL80211_MCGRP_CONFIG,
53 NL80211_MCGRP_SCAN,
54 NL80211_MCGRP_REGULATORY,
55 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010056 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010057 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
58};
59
60static const struct genl_multicast_group nl80211_mcgrps[] = {
61 [NL80211_MCGRP_CONFIG] = { .name = "config", },
62 [NL80211_MCGRP_SCAN] = { .name = "scan", },
63 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
64 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010065 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010066#ifdef CONFIG_NL80211_TESTMODE
67 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
68#endif
69};
70
Johannes Berg89a54e42012-06-15 14:33:17 +020071/* returns ERR_PTR values */
72static struct wireless_dev *
73__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040074{
Johannes Berg89a54e42012-06-15 14:33:17 +020075 struct cfg80211_registered_device *rdev;
76 struct wireless_dev *result = NULL;
77 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
78 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
79 u64 wdev_id;
80 int wiphy_idx = -1;
81 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040082
Johannes Berg5fe231e2013-05-08 21:45:15 +020083 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg89a54e42012-06-15 14:33:17 +020085 if (!have_ifidx && !have_wdev_id)
86 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040087
Johannes Berg89a54e42012-06-15 14:33:17 +020088 if (have_ifidx)
89 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
90 if (have_wdev_id) {
91 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
92 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040093 }
94
Johannes Berg89a54e42012-06-15 14:33:17 +020095 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
96 struct wireless_dev *wdev;
97
98 if (wiphy_net(&rdev->wiphy) != netns)
99 continue;
100
101 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
102 continue;
103
Johannes Berg89a54e42012-06-15 14:33:17 +0200104 list_for_each_entry(wdev, &rdev->wdev_list, list) {
105 if (have_ifidx && wdev->netdev &&
106 wdev->netdev->ifindex == ifidx) {
107 result = wdev;
108 break;
109 }
110 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
111 result = wdev;
112 break;
113 }
114 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200115
116 if (result)
117 break;
118 }
119
120 if (result)
121 return result;
122 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400123}
124
Johannes Berga9455402012-06-15 13:32:49 +0200125static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200126__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200127{
Johannes Berg7fee4772012-06-15 14:09:58 +0200128 struct cfg80211_registered_device *rdev = NULL, *tmp;
129 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200130
Johannes Berg5fe231e2013-05-08 21:45:15 +0200131 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg878d9ec2012-06-15 14:18:32 +0200133 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200134 !attrs[NL80211_ATTR_IFINDEX] &&
135 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200136 return ERR_PTR(-EINVAL);
137
Johannes Berg878d9ec2012-06-15 14:18:32 +0200138 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200139 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200141
Johannes Berg89a54e42012-06-15 14:33:17 +0200142 if (attrs[NL80211_ATTR_WDEV]) {
143 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
144 struct wireless_dev *wdev;
145 bool found = false;
146
147 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
148 if (tmp) {
149 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200150 list_for_each_entry(wdev, &tmp->wdev_list, list) {
151 if (wdev->identifier != (u32)wdev_id)
152 continue;
153 found = true;
154 break;
155 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200156
157 if (!found)
158 tmp = NULL;
159
160 if (rdev && tmp != rdev)
161 return ERR_PTR(-EINVAL);
162 rdev = tmp;
163 }
164 }
165
Johannes Berg878d9ec2012-06-15 14:18:32 +0200166 if (attrs[NL80211_ATTR_IFINDEX]) {
167 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800168 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200169 if (netdev) {
170 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800171 tmp = wiphy_to_rdev(
172 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200173 else
174 tmp = NULL;
175
Johannes Berg7fee4772012-06-15 14:09:58 +0200176 /* not wireless device -- return error */
177 if (!tmp)
178 return ERR_PTR(-EINVAL);
179
180 /* mismatch -- return error */
181 if (rdev && tmp != rdev)
182 return ERR_PTR(-EINVAL);
183
184 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200185 }
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
187
Johannes Berg4f7eff12012-06-15 14:14:22 +0200188 if (!rdev)
189 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (netns != wiphy_net(&rdev->wiphy))
192 return ERR_PTR(-ENODEV);
193
194 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200195}
196
197/*
198 * This function returns a pointer to the driver
199 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200200 *
201 * The result of this can be a PTR_ERR and hence must
202 * be checked with IS_ERR() for errors.
203 */
204static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200205cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200206{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200207 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200208}
209
Johannes Berg55682962007-09-20 13:09:35 -0400210/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000211static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400212 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
213 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700214 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200215 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100216
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200217 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530218 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
220 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
222
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200223 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
224 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
226 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100227 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400228
229 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
231 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100232
Eliad Pellere007b852011-11-24 18:13:56 +0200233 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
234 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Johannes Bergb9454e82009-07-08 13:29:08 +0200236 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100237 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
238 .len = WLAN_MAX_KEY_LEN },
239 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
240 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
241 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200242 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200243 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100244
245 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
246 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
247 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
248 .len = IEEE80211_MAX_DATA_LEN },
249 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100251 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
252 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
253 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
255 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100256 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100257 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200258 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800260 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300262
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700263 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
264 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
265
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
267 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
268 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200269 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
270 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100271 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300272
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800273 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700274 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700275
Johannes Berg6c739412011-11-03 09:27:01 +0100276 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200277
278 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
279 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
280 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100281 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
282 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200283
284 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_SSID_LEN },
286 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
287 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200288 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300289 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
293 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300340 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100341 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200342 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
343 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700344 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800345 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
346 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
347 .len = NL80211_HT_CAPABILITY_LEN
348 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100349 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530350 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530351 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200352 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700353 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300354 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000355 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700356 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100357 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
358 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530359 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
360 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200361 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
362 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100363 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100364 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
365 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
366 .len = NL80211_VHT_CAPABILITY_LEN,
367 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200368 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
369 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
370 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300371 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200372 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
373 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
374 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300375 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
376 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530377 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
378 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200379 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100380 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100381 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
382 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
383 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800384 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
385 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200386 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
387 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530388 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Johannes Berg78f22b62014-03-24 17:57:27 +0100389 [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300390 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Johannes Berg55682962007-09-20 13:09:35 -0400391};
392
Johannes Berge31b8212010-10-05 19:39:30 +0200393/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000394static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200395 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200396 [NL80211_KEY_IDX] = { .type = NLA_U8 },
397 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200398 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200399 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
400 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200401 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100402 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
403};
404
405/* policy for the key default flags */
406static const struct nla_policy
407nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
408 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
409 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200410};
411
Johannes Bergff1b6e62011-05-04 15:37:28 +0200412/* policy for WoWLAN attributes */
413static const struct nla_policy
414nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
415 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
416 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
417 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200419 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
420 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
421 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
422 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100423 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
424};
425
426static const struct nla_policy
427nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
428 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
429 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
430 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
431 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
432 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
434 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
435 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
436 },
437 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
438 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
439 },
440 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
441 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
442 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200443};
444
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700445/* policy for coalesce rule attributes */
446static const struct nla_policy
447nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
448 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
449 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
450 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
451};
452
Johannes Berge5497d72011-07-05 16:35:40 +0200453/* policy for GTK rekey offload attributes */
454static const struct nla_policy
455nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
456 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
457 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
458 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
459};
460
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300461static const struct nla_policy
462nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200463 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300464 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700465 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300466};
467
Johannes Berg97990a02013-04-19 01:02:55 +0200468static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
469 struct netlink_callback *cb,
470 struct cfg80211_registered_device **rdev,
471 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100472{
Johannes Berg67748892010-10-04 21:14:06 +0200473 int err;
474
Johannes Berg67748892010-10-04 21:14:06 +0200475 rtnl_lock();
476
Johannes Berg97990a02013-04-19 01:02:55 +0200477 if (!cb->args[0]) {
478 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
479 nl80211_fam.attrbuf, nl80211_fam.maxattr,
480 nl80211_policy);
481 if (err)
482 goto out_unlock;
483
484 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
485 nl80211_fam.attrbuf);
486 if (IS_ERR(*wdev)) {
487 err = PTR_ERR(*wdev);
488 goto out_unlock;
489 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800490 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200491 /* 0 is the first index - add 1 to parse only once */
492 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200493 cb->args[1] = (*wdev)->identifier;
494 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200495 /* subtract the 1 again here */
496 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200497 struct wireless_dev *tmp;
498
499 if (!wiphy) {
500 err = -ENODEV;
501 goto out_unlock;
502 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800503 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200504 *wdev = NULL;
505
Johannes Berg97990a02013-04-19 01:02:55 +0200506 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
507 if (tmp->identifier == cb->args[1]) {
508 *wdev = tmp;
509 break;
510 }
511 }
Johannes Berg97990a02013-04-19 01:02:55 +0200512
513 if (!*wdev) {
514 err = -ENODEV;
515 goto out_unlock;
516 }
Johannes Berg67748892010-10-04 21:14:06 +0200517 }
518
Johannes Berg67748892010-10-04 21:14:06 +0200519 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200520 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200521 rtnl_unlock();
522 return err;
523}
524
Johannes Berg97990a02013-04-19 01:02:55 +0200525static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200526{
Johannes Berg67748892010-10-04 21:14:06 +0200527 rtnl_unlock();
528}
529
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100530/* IE validation */
531static bool is_valid_ie_attr(const struct nlattr *attr)
532{
533 const u8 *pos;
534 int len;
535
536 if (!attr)
537 return true;
538
539 pos = nla_data(attr);
540 len = nla_len(attr);
541
542 while (len) {
543 u8 elemlen;
544
545 if (len < 2)
546 return false;
547 len -= 2;
548
549 elemlen = pos[1];
550 if (elemlen > len)
551 return false;
552
553 len -= elemlen;
554 pos += 2 + elemlen;
555 }
556
557 return true;
558}
559
Johannes Berg55682962007-09-20 13:09:35 -0400560/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000561static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400562 int flags, u8 cmd)
563{
564 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000565 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400566}
567
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400568static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100569 struct ieee80211_channel *chan,
570 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200572 /* Some channels must be completely excluded from the
573 * list to protect old user-space tools from breaking
574 */
575 if (!large && chan->flags &
576 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
577 return 0;
578
David S. Miller9360ffd2012-03-29 04:41:26 -0400579 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
580 chan->center_freq))
581 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400582
David S. Miller9360ffd2012-03-29 04:41:26 -0400583 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
584 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
585 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200586 if (chan->flags & IEEE80211_CHAN_NO_IR) {
587 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
588 goto nla_put_failure;
589 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
590 goto nla_put_failure;
591 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100592 if (chan->flags & IEEE80211_CHAN_RADAR) {
593 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
594 goto nla_put_failure;
595 if (large) {
596 u32 time;
597
598 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
599
600 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
601 chan->dfs_state))
602 goto nla_put_failure;
603 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
604 time))
605 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100606 if (nla_put_u32(msg,
607 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
608 chan->dfs_cac_ms))
609 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100610 }
611 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400612
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100613 if (large) {
614 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
615 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
616 goto nla_put_failure;
617 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
618 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
619 goto nla_put_failure;
620 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
621 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
622 goto nla_put_failure;
623 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
624 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
625 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200626 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
627 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
628 goto nla_put_failure;
629 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
630 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
631 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200632 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
633 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
634 goto nla_put_failure;
635 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
636 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
637 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100638 }
639
David S. Miller9360ffd2012-03-29 04:41:26 -0400640 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
641 DBM_TO_MBM(chan->max_power)))
642 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400643
644 return 0;
645
646 nla_put_failure:
647 return -ENOBUFS;
648}
649
Johannes Berg55682962007-09-20 13:09:35 -0400650/* netlink command implementations */
651
Johannes Bergb9454e82009-07-08 13:29:08 +0200652struct key_parse {
653 struct key_params p;
654 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200655 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200656 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100657 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200658};
659
660static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
661{
662 struct nlattr *tb[NL80211_KEY_MAX + 1];
663 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
664 nl80211_key_policy);
665 if (err)
666 return err;
667
668 k->def = !!tb[NL80211_KEY_DEFAULT];
669 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
670
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100671 if (k->def) {
672 k->def_uni = true;
673 k->def_multi = true;
674 }
675 if (k->defmgmt)
676 k->def_multi = true;
677
Johannes Bergb9454e82009-07-08 13:29:08 +0200678 if (tb[NL80211_KEY_IDX])
679 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
680
681 if (tb[NL80211_KEY_DATA]) {
682 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
683 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
684 }
685
686 if (tb[NL80211_KEY_SEQ]) {
687 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
688 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
689 }
690
691 if (tb[NL80211_KEY_CIPHER])
692 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
693
Johannes Berge31b8212010-10-05 19:39:30 +0200694 if (tb[NL80211_KEY_TYPE]) {
695 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
696 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
697 return -EINVAL;
698 }
699
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100700 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
701 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100702 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
703 tb[NL80211_KEY_DEFAULT_TYPES],
704 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100705 if (err)
706 return err;
707
708 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
709 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
710 }
711
Johannes Bergb9454e82009-07-08 13:29:08 +0200712 return 0;
713}
714
715static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
716{
717 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
718 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
719 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
720 }
721
722 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
723 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
724 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
725 }
726
727 if (info->attrs[NL80211_ATTR_KEY_IDX])
728 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
729
730 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
731 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
732
733 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
734 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
735
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100736 if (k->def) {
737 k->def_uni = true;
738 k->def_multi = true;
739 }
740 if (k->defmgmt)
741 k->def_multi = true;
742
Johannes Berge31b8212010-10-05 19:39:30 +0200743 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
744 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
745 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
746 return -EINVAL;
747 }
748
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100749 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
750 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
751 int err = nla_parse_nested(
752 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
753 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
754 nl80211_key_default_policy);
755 if (err)
756 return err;
757
758 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
759 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
760 }
761
Johannes Bergb9454e82009-07-08 13:29:08 +0200762 return 0;
763}
764
765static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
766{
767 int err;
768
769 memset(k, 0, sizeof(*k));
770 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200771 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200772
773 if (info->attrs[NL80211_ATTR_KEY])
774 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
775 else
776 err = nl80211_parse_key_old(info, k);
777
778 if (err)
779 return err;
780
781 if (k->def && k->defmgmt)
782 return -EINVAL;
783
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100784 if (k->defmgmt) {
785 if (k->def_uni || !k->def_multi)
786 return -EINVAL;
787 }
788
Johannes Bergb9454e82009-07-08 13:29:08 +0200789 if (k->idx != -1) {
790 if (k->defmgmt) {
791 if (k->idx < 4 || k->idx > 5)
792 return -EINVAL;
793 } else if (k->def) {
794 if (k->idx < 0 || k->idx > 3)
795 return -EINVAL;
796 } else {
797 if (k->idx < 0 || k->idx > 5)
798 return -EINVAL;
799 }
800 }
801
802 return 0;
803}
804
Johannes Bergfffd0932009-07-08 14:22:54 +0200805static struct cfg80211_cached_keys *
806nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530807 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200808{
809 struct key_parse parse;
810 struct nlattr *key;
811 struct cfg80211_cached_keys *result;
812 int rem, err, def = 0;
813
814 result = kzalloc(sizeof(*result), GFP_KERNEL);
815 if (!result)
816 return ERR_PTR(-ENOMEM);
817
818 result->def = -1;
819 result->defmgmt = -1;
820
821 nla_for_each_nested(key, keys, rem) {
822 memset(&parse, 0, sizeof(parse));
823 parse.idx = -1;
824
825 err = nl80211_parse_key_new(key, &parse);
826 if (err)
827 goto error;
828 err = -EINVAL;
829 if (!parse.p.key)
830 goto error;
831 if (parse.idx < 0 || parse.idx > 4)
832 goto error;
833 if (parse.def) {
834 if (def)
835 goto error;
836 def = 1;
837 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100838 if (!parse.def_uni || !parse.def_multi)
839 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200840 } else if (parse.defmgmt)
841 goto error;
842 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200843 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200844 if (err)
845 goto error;
846 result->params[parse.idx].cipher = parse.p.cipher;
847 result->params[parse.idx].key_len = parse.p.key_len;
848 result->params[parse.idx].key = result->data[parse.idx];
849 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530850
851 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
852 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
853 if (no_ht)
854 *no_ht = true;
855 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200856 }
857
858 return result;
859 error:
860 kfree(result);
861 return ERR_PTR(err);
862}
863
864static int nl80211_key_allowed(struct wireless_dev *wdev)
865{
866 ASSERT_WDEV_LOCK(wdev);
867
Johannes Bergfffd0932009-07-08 14:22:54 +0200868 switch (wdev->iftype) {
869 case NL80211_IFTYPE_AP:
870 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200871 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700872 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200873 break;
874 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200875 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200876 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200877 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 return -ENOLINK;
879 break;
880 default:
881 return -EINVAL;
882 }
883
884 return 0;
885}
886
Jouni Malinen664834d2014-01-15 00:01:44 +0200887static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
888 struct nlattr *tb)
889{
890 struct ieee80211_channel *chan;
891
892 if (tb == NULL)
893 return NULL;
894 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
895 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
896 return NULL;
897 return chan;
898}
899
Johannes Berg7527a782011-05-13 10:58:57 +0200900static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
901{
902 struct nlattr *nl_modes = nla_nest_start(msg, attr);
903 int i;
904
905 if (!nl_modes)
906 goto nla_put_failure;
907
908 i = 0;
909 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400910 if ((ifmodes & 1) && nla_put_flag(msg, i))
911 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200912 ifmodes >>= 1;
913 i++;
914 }
915
916 nla_nest_end(msg, nl_modes);
917 return 0;
918
919nla_put_failure:
920 return -ENOBUFS;
921}
922
923static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100924 struct sk_buff *msg,
925 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200926{
927 struct nlattr *nl_combis;
928 int i, j;
929
930 nl_combis = nla_nest_start(msg,
931 NL80211_ATTR_INTERFACE_COMBINATIONS);
932 if (!nl_combis)
933 goto nla_put_failure;
934
935 for (i = 0; i < wiphy->n_iface_combinations; i++) {
936 const struct ieee80211_iface_combination *c;
937 struct nlattr *nl_combi, *nl_limits;
938
939 c = &wiphy->iface_combinations[i];
940
941 nl_combi = nla_nest_start(msg, i + 1);
942 if (!nl_combi)
943 goto nla_put_failure;
944
945 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
946 if (!nl_limits)
947 goto nla_put_failure;
948
949 for (j = 0; j < c->n_limits; j++) {
950 struct nlattr *nl_limit;
951
952 nl_limit = nla_nest_start(msg, j + 1);
953 if (!nl_limit)
954 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400955 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
956 c->limits[j].max))
957 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200958 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
959 c->limits[j].types))
960 goto nla_put_failure;
961 nla_nest_end(msg, nl_limit);
962 }
963
964 nla_nest_end(msg, nl_limits);
965
David S. Miller9360ffd2012-03-29 04:41:26 -0400966 if (c->beacon_int_infra_match &&
967 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
968 goto nla_put_failure;
969 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
970 c->num_different_channels) ||
971 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
972 c->max_interfaces))
973 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100974 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200975 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
976 c->radar_detect_widths) ||
977 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
978 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100979 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200980
981 nla_nest_end(msg, nl_combi);
982 }
983
984 nla_nest_end(msg, nl_combis);
985
986 return 0;
987nla_put_failure:
988 return -ENOBUFS;
989}
990
Johannes Berg3713b4e2013-02-14 16:19:38 +0100991#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100992static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
993 struct sk_buff *msg)
994{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200995 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100996 struct nlattr *nl_tcp;
997
998 if (!tcp)
999 return 0;
1000
1001 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1002 if (!nl_tcp)
1003 return -ENOBUFS;
1004
1005 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1006 tcp->data_payload_max))
1007 return -ENOBUFS;
1008
1009 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1010 tcp->data_payload_max))
1011 return -ENOBUFS;
1012
1013 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1014 return -ENOBUFS;
1015
1016 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1017 sizeof(*tcp->tok), tcp->tok))
1018 return -ENOBUFS;
1019
1020 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1021 tcp->data_interval_max))
1022 return -ENOBUFS;
1023
1024 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1025 tcp->wake_payload_max))
1026 return -ENOBUFS;
1027
1028 nla_nest_end(msg, nl_tcp);
1029 return 0;
1030}
1031
Johannes Berg3713b4e2013-02-14 16:19:38 +01001032static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001033 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001034 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001035{
1036 struct nlattr *nl_wowlan;
1037
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001038 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001039 return 0;
1040
1041 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1042 if (!nl_wowlan)
1043 return -ENOBUFS;
1044
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001045 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001046 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001047 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001048 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001049 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001052 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001053 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001054 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001055 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001056 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001057 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001058 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1061 return -ENOBUFS;
1062
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001064 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1066 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1067 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1068 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069 };
1070
1071 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1072 sizeof(pat), &pat))
1073 return -ENOBUFS;
1074 }
1075
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001077 return -ENOBUFS;
1078
Johannes Berg3713b4e2013-02-14 16:19:38 +01001079 nla_nest_end(msg, nl_wowlan);
1080
1081 return 0;
1082}
1083#endif
1084
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001085static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001086 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001087{
1088 struct nl80211_coalesce_rule_support rule;
1089
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001091 return 0;
1092
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001093 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1094 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1095 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1096 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1097 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1098 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001099
1100 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1101 return -ENOBUFS;
1102
1103 return 0;
1104}
1105
Johannes Berg3713b4e2013-02-14 16:19:38 +01001106static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1107 struct ieee80211_supported_band *sband)
1108{
1109 struct nlattr *nl_rates, *nl_rate;
1110 struct ieee80211_rate *rate;
1111 int i;
1112
1113 /* add HT info */
1114 if (sband->ht_cap.ht_supported &&
1115 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1116 sizeof(sband->ht_cap.mcs),
1117 &sband->ht_cap.mcs) ||
1118 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1119 sband->ht_cap.cap) ||
1120 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1121 sband->ht_cap.ampdu_factor) ||
1122 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1123 sband->ht_cap.ampdu_density)))
1124 return -ENOBUFS;
1125
1126 /* add VHT info */
1127 if (sband->vht_cap.vht_supported &&
1128 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1129 sizeof(sband->vht_cap.vht_mcs),
1130 &sband->vht_cap.vht_mcs) ||
1131 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1132 sband->vht_cap.cap)))
1133 return -ENOBUFS;
1134
1135 /* add bitrates */
1136 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1137 if (!nl_rates)
1138 return -ENOBUFS;
1139
1140 for (i = 0; i < sband->n_bitrates; i++) {
1141 nl_rate = nla_nest_start(msg, i);
1142 if (!nl_rate)
1143 return -ENOBUFS;
1144
1145 rate = &sband->bitrates[i];
1146 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1147 rate->bitrate))
1148 return -ENOBUFS;
1149 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1150 nla_put_flag(msg,
1151 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1152 return -ENOBUFS;
1153
1154 nla_nest_end(msg, nl_rate);
1155 }
1156
1157 nla_nest_end(msg, nl_rates);
1158
1159 return 0;
1160}
1161
1162static int
1163nl80211_send_mgmt_stypes(struct sk_buff *msg,
1164 const struct ieee80211_txrx_stypes *mgmt_stypes)
1165{
1166 u16 stypes;
1167 struct nlattr *nl_ftypes, *nl_ifs;
1168 enum nl80211_iftype ift;
1169 int i;
1170
1171 if (!mgmt_stypes)
1172 return 0;
1173
1174 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1175 if (!nl_ifs)
1176 return -ENOBUFS;
1177
1178 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1179 nl_ftypes = nla_nest_start(msg, ift);
1180 if (!nl_ftypes)
1181 return -ENOBUFS;
1182 i = 0;
1183 stypes = mgmt_stypes[ift].tx;
1184 while (stypes) {
1185 if ((stypes & 1) &&
1186 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1187 (i << 4) | IEEE80211_FTYPE_MGMT))
1188 return -ENOBUFS;
1189 stypes >>= 1;
1190 i++;
1191 }
1192 nla_nest_end(msg, nl_ftypes);
1193 }
1194
1195 nla_nest_end(msg, nl_ifs);
1196
1197 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1198 if (!nl_ifs)
1199 return -ENOBUFS;
1200
1201 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1202 nl_ftypes = nla_nest_start(msg, ift);
1203 if (!nl_ftypes)
1204 return -ENOBUFS;
1205 i = 0;
1206 stypes = mgmt_stypes[ift].rx;
1207 while (stypes) {
1208 if ((stypes & 1) &&
1209 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1210 (i << 4) | IEEE80211_FTYPE_MGMT))
1211 return -ENOBUFS;
1212 stypes >>= 1;
1213 i++;
1214 }
1215 nla_nest_end(msg, nl_ftypes);
1216 }
1217 nla_nest_end(msg, nl_ifs);
1218
1219 return 0;
1220}
1221
Johannes Berg86e8cf92013-06-19 10:57:22 +02001222struct nl80211_dump_wiphy_state {
1223 s64 filter_wiphy;
1224 long start;
1225 long split_start, band_start, chan_start;
1226 bool split;
1227};
1228
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001229static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001230 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001231 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001232 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001233{
1234 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001235 struct nlattr *nl_bands, *nl_band;
1236 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001237 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001238 enum ieee80211_band band;
1239 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001240 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001241 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001242 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001243 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001244
Johannes Berg3bb20552014-05-26 13:52:25 +02001245 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001246 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001247 return -ENOBUFS;
1248
Johannes Berg86e8cf92013-06-19 10:57:22 +02001249 if (WARN_ON(!state))
1250 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001251
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001252 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001254 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001255 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001256 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001257 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001258
Johannes Berg3bb20552014-05-26 13:52:25 +02001259 if (cmd != NL80211_CMD_NEW_WIPHY)
1260 goto finish;
1261
Johannes Berg86e8cf92013-06-19 10:57:22 +02001262 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 case 0:
1264 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001266 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001274 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001276 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001279 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001283 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001284 goto nla_put_failure;
1285
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1288 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001289 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001290 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1291 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1294 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001295 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001296 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1297 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1300 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001303 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001304 state->split_start++;
1305 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 break;
1307 case 1:
1308 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1310 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001311 goto nla_put_failure;
1312
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001314 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001315 goto nla_put_failure;
1316
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1319 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001320
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001322 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001326
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001327 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001331
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001332 if ((rdev->wiphy.available_antennas_tx ||
1333 rdev->wiphy.available_antennas_rx) &&
1334 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 u32 tx_ant = 0, rx_ant = 0;
1336 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 if (!res) {
1339 if (nla_put_u32(msg,
1340 NL80211_ATTR_WIPHY_ANTENNA_TX,
1341 tx_ant) ||
1342 nla_put_u32(msg,
1343 NL80211_ATTR_WIPHY_ANTENNA_RX,
1344 rx_ant))
1345 goto nla_put_failure;
1346 }
Johannes Bergee688b002008-01-24 19:38:39 +01001347 }
1348
Johannes Berg86e8cf92013-06-19 10:57:22 +02001349 state->split_start++;
1350 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 break;
1352 case 2:
1353 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001354 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 state->split_start++;
1357 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 break;
1359 case 3:
1360 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1361 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001362 goto nla_put_failure;
1363
Johannes Berg86e8cf92013-06-19 10:57:22 +02001364 for (band = state->band_start;
1365 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 struct ieee80211_supported_band *sband;
1367
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369
1370 if (!sband)
1371 continue;
1372
1373 nl_band = nla_nest_start(msg, band);
1374 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001375 goto nla_put_failure;
1376
Johannes Berg86e8cf92013-06-19 10:57:22 +02001377 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 case 0:
1379 if (nl80211_send_band_rateinfo(msg, sband))
1380 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001381 state->chan_start++;
1382 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 break;
1384 default:
1385 /* add frequencies */
1386 nl_freqs = nla_nest_start(
1387 msg, NL80211_BAND_ATTR_FREQS);
1388 if (!nl_freqs)
1389 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001390
Johannes Berg86e8cf92013-06-19 10:57:22 +02001391 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392 i < sband->n_channels;
1393 i++) {
1394 nl_freq = nla_nest_start(msg, i);
1395 if (!nl_freq)
1396 goto nla_put_failure;
1397
1398 chan = &sband->channels[i];
1399
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 if (nl80211_msg_put_channel(
1401 msg, chan,
1402 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 goto nla_put_failure;
1404
1405 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001406 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001407 break;
1408 }
1409 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001410 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001411 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 nla_nest_end(msg, nl_freqs);
1414 }
1415
1416 nla_nest_end(msg, nl_band);
1417
Johannes Berg86e8cf92013-06-19 10:57:22 +02001418 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001420 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 band--;
1422 break;
1423 }
Johannes Bergee688b002008-01-24 19:38:39 +01001424 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001425 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001426
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001428 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001430 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001431
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001433 if (state->band_start == 0 && state->chan_start == 0)
1434 state->split_start++;
1435 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 break;
1437 case 4:
1438 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1439 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001440 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001441
1442 i = 0;
1443#define CMD(op, n) \
1444 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001445 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 i++; \
1447 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1448 goto nla_put_failure; \
1449 } \
1450 } while (0)
1451
1452 CMD(add_virtual_intf, NEW_INTERFACE);
1453 CMD(change_virtual_intf, SET_INTERFACE);
1454 CMD(add_key, NEW_KEY);
1455 CMD(start_ap, START_AP);
1456 CMD(add_station, NEW_STATION);
1457 CMD(add_mpath, NEW_MPATH);
1458 CMD(update_mesh_config, SET_MESH_CONFIG);
1459 CMD(change_bss, SET_BSS);
1460 CMD(auth, AUTHENTICATE);
1461 CMD(assoc, ASSOCIATE);
1462 CMD(deauth, DEAUTHENTICATE);
1463 CMD(disassoc, DISASSOCIATE);
1464 CMD(join_ibss, JOIN_IBSS);
1465 CMD(join_mesh, JOIN_MESH);
1466 CMD(set_pmksa, SET_PMKSA);
1467 CMD(del_pmksa, DEL_PMKSA);
1468 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001469 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1471 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1472 CMD(mgmt_tx, FRAME);
1473 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001474 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 i++;
1476 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1477 goto nla_put_failure;
1478 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001479 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1480 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 i++;
1482 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1483 goto nla_put_failure;
1484 }
1485 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 CMD(tdls_mgmt, TDLS_MGMT);
1488 CMD(tdls_oper, TDLS_OPER);
1489 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001490 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 CMD(sched_scan_start, START_SCHED_SCAN);
1492 CMD(probe_client, PROBE_CLIENT);
1493 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 i++;
1496 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1497 goto nla_put_failure;
1498 }
1499 CMD(start_p2p_device, START_P2P_DEVICE);
1500 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001501#ifdef CONFIG_NL80211_TESTMODE
1502 CMD(testmode_cmd, TESTMODE);
1503#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001504 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001505 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1506 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001507 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001508 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001509 CMD(set_qos_map, SET_QOS_MAP);
Arend van Spriel5de17982013-04-18 15:49:00 +02001510 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001511 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001512#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001513
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 i++;
1516 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001517 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001518 }
1519
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001520 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 i++;
1522 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1523 goto nla_put_failure;
1524 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001525
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 state->split_start++;
1528 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 break;
1530 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001531 if (rdev->ops->remain_on_channel &&
1532 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001533 nla_put_u32(msg,
1534 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001535 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001536 goto nla_put_failure;
1537
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1540 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001541
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1543 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001544 state->split_start++;
1545 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 break;
1547 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001548#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001549 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001550 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001551 state->split_start++;
1552 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 break;
1554#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001555 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556#endif
1557 case 7:
1558 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001560 goto nla_put_failure;
1561
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001565
Johannes Berg86e8cf92013-06-19 10:57:22 +02001566 state->split_start++;
1567 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 break;
1569 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001570 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001571 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 goto nla_put_failure;
1574
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001576 /*
1577 * We can only add the per-channel limit information if the
1578 * dump is split, otherwise it makes it too big. Therefore
1579 * only advertise it in that case.
1580 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001582 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1583 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 goto nla_put_failure;
1585
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001586 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1589 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 goto nla_put_failure;
1591
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001592 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1593 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001595 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596 goto nla_put_failure;
1597
1598 /*
1599 * Any information below this point is only available to
1600 * applications that can deal with it being split. This
1601 * helps ensure that newly added capabilities don't break
1602 * older tools by overrunning their buffers.
1603 *
1604 * We still increment split_start so that in the split
1605 * case we'll continue with more data in the next round,
1606 * but break unconditionally so unsplit data stops here.
1607 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 break;
1610 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001611 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001612 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 rdev->wiphy.extended_capabilities_len,
1614 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001615 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001616 rdev->wiphy.extended_capabilities_len,
1617 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001618 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001620 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001621 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1623 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001624 goto nla_put_failure;
1625
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001626 state->split_start++;
1627 break;
1628 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001629 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001630 goto nla_put_failure;
1631
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001633 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1634 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1635 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001636
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001638 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001640 goto nla_put_failure;
1641
Johannes Bergad7e7182013-11-13 13:37:47 +01001642 state->split_start++;
1643 break;
1644 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001645 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001646 const struct nl80211_vendor_cmd_info *info;
1647 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001648
Johannes Berg567ffc32013-12-18 14:43:31 +01001649 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1650 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001651 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001652
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1654 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001655 if (nla_put(msg, i + 1, sizeof(*info), info))
1656 goto nla_put_failure;
1657 }
1658 nla_nest_end(msg, nested);
1659 }
1660
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001661 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001662 const struct nl80211_vendor_cmd_info *info;
1663 struct nlattr *nested;
1664
1665 nested = nla_nest_start(msg,
1666 NL80211_ATTR_VENDOR_EVENTS);
1667 if (!nested)
1668 goto nla_put_failure;
1669
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1671 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001672 if (nla_put(msg, i + 1, sizeof(*info), info))
1673 goto nla_put_failure;
1674 }
1675 nla_nest_end(msg, nested);
1676 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001677 state->split_start++;
1678 break;
1679 case 12:
1680 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1681 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1682 rdev->wiphy.max_num_csa_counters))
1683 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001684
Johannes Berg3713b4e2013-02-14 16:19:38 +01001685 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001686 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001687 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001688 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001689 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001690 return genlmsg_end(msg, hdr);
1691
1692 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001693 genlmsg_cancel(msg, hdr);
1694 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001695}
1696
Johannes Berg86e8cf92013-06-19 10:57:22 +02001697static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1698 struct netlink_callback *cb,
1699 struct nl80211_dump_wiphy_state *state)
1700{
1701 struct nlattr **tb = nl80211_fam.attrbuf;
1702 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1703 tb, nl80211_fam.maxattr, nl80211_policy);
1704 /* ignore parse errors for backward compatibility */
1705 if (ret)
1706 return 0;
1707
1708 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1709 if (tb[NL80211_ATTR_WIPHY])
1710 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1711 if (tb[NL80211_ATTR_WDEV])
1712 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1713 if (tb[NL80211_ATTR_IFINDEX]) {
1714 struct net_device *netdev;
1715 struct cfg80211_registered_device *rdev;
1716 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1717
Ying Xue7f2b8562014-01-15 10:23:45 +08001718 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 if (!netdev)
1720 return -ENODEV;
1721 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001722 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001723 netdev->ieee80211_ptr->wiphy);
1724 state->filter_wiphy = rdev->wiphy_idx;
1725 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001726 }
1727
1728 return 0;
1729}
1730
Johannes Berg55682962007-09-20 13:09:35 -04001731static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1732{
Johannes Berg645e77d2013-03-01 14:03:49 +01001733 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001734 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001735 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001736
Johannes Berg5fe231e2013-05-08 21:45:15 +02001737 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001738 if (!state) {
1739 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001740 if (!state) {
1741 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001742 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001743 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 state->filter_wiphy = -1;
1745 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1746 if (ret) {
1747 kfree(state);
1748 rtnl_unlock();
1749 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001750 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001751 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001752 }
1753
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001754 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1755 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001756 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001757 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001758 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001759 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001760 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001761 continue;
1762 /* attempt to fit multiple wiphy data chunks into the skb */
1763 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001764 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1765 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001766 NETLINK_CB(cb->skb).portid,
1767 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001768 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001769 if (ret < 0) {
1770 /*
1771 * If sending the wiphy data didn't fit (ENOBUFS
1772 * or EMSGSIZE returned), this SKB is still
1773 * empty (so it's not too big because another
1774 * wiphy dataset is already in the skb) and
1775 * we've not tried to adjust the dump allocation
1776 * yet ... then adjust the alloc size to be
1777 * bigger, and return 1 but with the empty skb.
1778 * This results in an empty message being RX'ed
1779 * in userspace, but that is ignored.
1780 *
1781 * We can then retry with the larger buffer.
1782 */
1783 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001784 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001785 cb->min_dump_alloc < 4096) {
1786 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001787 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001788 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001789 return 1;
1790 }
1791 idx--;
1792 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001793 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001794 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001795 break;
Johannes Berg55682962007-09-20 13:09:35 -04001796 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001797 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001798
Johannes Berg86e8cf92013-06-19 10:57:22 +02001799 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001800
1801 return skb->len;
1802}
1803
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1805{
1806 kfree((void *)cb->args[0]);
1807 return 0;
1808}
1809
Johannes Berg55682962007-09-20 13:09:35 -04001810static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1811{
1812 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001815
Johannes Berg645e77d2013-03-01 14:03:49 +01001816 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001817 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001818 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001819
Johannes Berg3bb20552014-05-26 13:52:25 +02001820 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1821 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001822 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001823 nlmsg_free(msg);
1824 return -ENOBUFS;
1825 }
Johannes Berg55682962007-09-20 13:09:35 -04001826
Johannes Berg134e6372009-07-10 09:51:34 +00001827 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001828}
1829
Jouni Malinen31888482008-10-30 16:59:24 +02001830static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1831 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1832 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1833 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1834 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1835 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1836};
1837
1838static int parse_txq_params(struct nlattr *tb[],
1839 struct ieee80211_txq_params *txq_params)
1840{
Johannes Berga3304b02012-03-28 11:04:24 +02001841 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001842 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1843 !tb[NL80211_TXQ_ATTR_AIFS])
1844 return -EINVAL;
1845
Johannes Berga3304b02012-03-28 11:04:24 +02001846 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001847 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1848 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1849 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1850 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1851
Johannes Berga3304b02012-03-28 11:04:24 +02001852 if (txq_params->ac >= NL80211_NUM_ACS)
1853 return -EINVAL;
1854
Jouni Malinen31888482008-10-30 16:59:24 +02001855 return 0;
1856}
1857
Johannes Bergf444de02010-05-05 15:25:02 +02001858static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1859{
1860 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001861 * You can only set the channel explicitly for WDS interfaces,
1862 * all others have their channel managed via their respective
1863 * "establish a connection" command (connect, join, ...)
1864 *
1865 * For AP/GO and mesh mode, the channel can be set with the
1866 * channel userspace API, but is only stored and passed to the
1867 * low-level driver when the AP starts or the mesh is joined.
1868 * This is for backward compatibility, userspace can also give
1869 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001870 *
1871 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001872 * whatever else is going on, so they have their own special
1873 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001874 */
1875 return !wdev ||
1876 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001877 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001878 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1879 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001880}
1881
Johannes Berg683b6d32012-11-08 21:25:48 +01001882static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1883 struct genl_info *info,
1884 struct cfg80211_chan_def *chandef)
1885{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301886 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001887
1888 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1889 return -EINVAL;
1890
1891 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1892
1893 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001894 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1895 chandef->center_freq1 = control_freq;
1896 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001897
1898 /* Primary channel not allowed */
1899 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1900 return -EINVAL;
1901
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001902 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1903 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001904
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001905 chantype = nla_get_u32(
1906 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1907
1908 switch (chantype) {
1909 case NL80211_CHAN_NO_HT:
1910 case NL80211_CHAN_HT20:
1911 case NL80211_CHAN_HT40PLUS:
1912 case NL80211_CHAN_HT40MINUS:
1913 cfg80211_chandef_create(chandef, chandef->chan,
1914 chantype);
1915 break;
1916 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001917 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001918 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001919 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1920 chandef->width =
1921 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1922 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1923 chandef->center_freq1 =
1924 nla_get_u32(
1925 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1926 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1927 chandef->center_freq2 =
1928 nla_get_u32(
1929 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1930 }
1931
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001932 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001933 return -EINVAL;
1934
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001935 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1936 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001937 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001939 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1940 chandef->width == NL80211_CHAN_WIDTH_10) &&
1941 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1942 return -EINVAL;
1943
Johannes Berg683b6d32012-11-08 21:25:48 +01001944 return 0;
1945}
1946
Johannes Bergf444de02010-05-05 15:25:02 +02001947static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001948 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001949 struct genl_info *info)
1950{
Johannes Berg683b6d32012-11-08 21:25:48 +01001951 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001952 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001953 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001954 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001955
Jouni Malinene16821b2014-04-28 11:22:08 +03001956 if (dev)
1957 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001958 if (!nl80211_can_set_dev_channel(wdev))
1959 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001960 if (wdev)
1961 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001962
Johannes Berg683b6d32012-11-08 21:25:48 +01001963 result = nl80211_parse_chandef(rdev, info, &chandef);
1964 if (result)
1965 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001966
Johannes Berge8c9bd52012-06-06 08:18:22 +02001967 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001968 case NL80211_IFTYPE_AP:
1969 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001970 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001971 result = -EINVAL;
1972 break;
1973 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001974 if (wdev->beacon_interval) {
1975 if (!dev || !rdev->ops->set_ap_chanwidth ||
1976 !(rdev->wiphy.features &
1977 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1978 result = -EBUSY;
1979 break;
1980 }
1981
1982 /* Only allow dynamic channel width changes */
1983 if (chandef.chan != wdev->preset_chandef.chan) {
1984 result = -EBUSY;
1985 break;
1986 }
1987 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1988 if (result)
1989 break;
1990 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001991 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001992 result = 0;
1993 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001994 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001995 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001996 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001997 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001998 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001999 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002000 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002001 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002002 }
Johannes Bergf444de02010-05-05 15:25:02 +02002003
2004 return result;
2005}
2006
2007static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2008{
Johannes Berg4c476992010-10-04 21:36:35 +02002009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2010 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002011
Jouni Malinene16821b2014-04-28 11:22:08 +03002012 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002013}
2014
Bill Jordane8347eb2010-10-01 13:54:28 -04002015static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2016{
Johannes Berg43b19952010-10-07 13:10:30 +02002017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2018 struct net_device *dev = info->user_ptr[1];
2019 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002020 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002021
2022 if (!info->attrs[NL80211_ATTR_MAC])
2023 return -EINVAL;
2024
Johannes Berg43b19952010-10-07 13:10:30 +02002025 if (netif_running(dev))
2026 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002027
Johannes Berg43b19952010-10-07 13:10:30 +02002028 if (!rdev->ops->set_wds_peer)
2029 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002030
Johannes Berg43b19952010-10-07 13:10:30 +02002031 if (wdev->iftype != NL80211_IFTYPE_WDS)
2032 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002033
2034 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002035 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002036}
2037
2038
Johannes Berg55682962007-09-20 13:09:35 -04002039static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2040{
2041 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002042 struct net_device *netdev = NULL;
2043 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002044 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002045 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002046 u32 changed;
2047 u8 retry_short = 0, retry_long = 0;
2048 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002049 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002050
Johannes Berg5fe231e2013-05-08 21:45:15 +02002051 ASSERT_RTNL();
2052
Johannes Bergf444de02010-05-05 15:25:02 +02002053 /*
2054 * Try to find the wiphy and netdev. Normally this
2055 * function shouldn't need the netdev, but this is
2056 * done for backward compatibility -- previously
2057 * setting the channel was done per wiphy, but now
2058 * it is per netdev. Previous userland like hostapd
2059 * also passed a netdev to set_wiphy, so that it is
2060 * possible to let that go to the right netdev!
2061 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002062
Johannes Bergf444de02010-05-05 15:25:02 +02002063 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2064 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2065
Ying Xue7f2b8562014-01-15 10:23:45 +08002066 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002067 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002068 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002069 else
Johannes Bergf444de02010-05-05 15:25:02 +02002070 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002071 }
2072
Johannes Bergf444de02010-05-05 15:25:02 +02002073 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002074 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2075 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002076 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002077 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002078 wdev = NULL;
2079 netdev = NULL;
2080 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002081 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002082 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002083
2084 /*
2085 * end workaround code, by now the rdev is available
2086 * and locked, and wdev may or may not be NULL.
2087 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002088
2089 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002090 result = cfg80211_dev_rename(
2091 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002092
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002093 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002094 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002095
Jouni Malinen31888482008-10-30 16:59:24 +02002096 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2097 struct ieee80211_txq_params txq_params;
2098 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2099
Ying Xue7f2b8562014-01-15 10:23:45 +08002100 if (!rdev->ops->set_txq_params)
2101 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002102
Ying Xue7f2b8562014-01-15 10:23:45 +08002103 if (!netdev)
2104 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002105
Johannes Berg133a3ff2011-11-03 14:50:13 +01002106 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002107 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2108 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002109
Ying Xue7f2b8562014-01-15 10:23:45 +08002110 if (!netif_running(netdev))
2111 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002112
Jouni Malinen31888482008-10-30 16:59:24 +02002113 nla_for_each_nested(nl_txq_params,
2114 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2115 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002116 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2117 nla_data(nl_txq_params),
2118 nla_len(nl_txq_params),
2119 txq_params_policy);
2120 if (result)
2121 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002122 result = parse_txq_params(tb, &txq_params);
2123 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002124 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002125
Hila Gonene35e4d22012-06-27 17:19:42 +03002126 result = rdev_set_txq_params(rdev, netdev,
2127 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002128 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002129 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002130 }
2131 }
2132
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002133 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002134 result = __nl80211_set_channel(
2135 rdev,
2136 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2137 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002138 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002140 }
2141
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002142 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002143 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002144 enum nl80211_tx_power_setting type;
2145 int idx, mbm = 0;
2146
Johannes Bergc8442112012-10-24 10:17:18 +02002147 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2148 txp_wdev = NULL;
2149
Ying Xue7f2b8562014-01-15 10:23:45 +08002150 if (!rdev->ops->set_tx_power)
2151 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002152
2153 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2154 type = nla_get_u32(info->attrs[idx]);
2155
2156 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002157 (type != NL80211_TX_POWER_AUTOMATIC))
2158 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002159
2160 if (type != NL80211_TX_POWER_AUTOMATIC) {
2161 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2162 mbm = nla_get_u32(info->attrs[idx]);
2163 }
2164
Johannes Bergc8442112012-10-24 10:17:18 +02002165 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002166 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002168 }
2169
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002170 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2171 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2172 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002173 if ((!rdev->wiphy.available_antennas_tx &&
2174 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 !rdev->ops->set_antenna)
2176 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002177
2178 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2179 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2180
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002181 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002182 * available antenna masks, except for the "all" mask */
2183 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002184 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2185 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002186
Bruno Randolf7f531e02010-12-16 11:30:22 +09002187 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2188 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002189
Hila Gonene35e4d22012-06-27 17:19:42 +03002190 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002191 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002192 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002193 }
2194
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002195 changed = 0;
2196
2197 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2198 retry_short = nla_get_u8(
2199 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002200 if (retry_short == 0)
2201 return -EINVAL;
2202
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002203 changed |= WIPHY_PARAM_RETRY_SHORT;
2204 }
2205
2206 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2207 retry_long = nla_get_u8(
2208 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002209 if (retry_long == 0)
2210 return -EINVAL;
2211
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002212 changed |= WIPHY_PARAM_RETRY_LONG;
2213 }
2214
2215 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2216 frag_threshold = nla_get_u32(
2217 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002218 if (frag_threshold < 256)
2219 return -EINVAL;
2220
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002221 if (frag_threshold != (u32) -1) {
2222 /*
2223 * Fragments (apart from the last one) are required to
2224 * have even length. Make the fragmentation code
2225 * simpler by stripping LSB should someone try to use
2226 * odd threshold value.
2227 */
2228 frag_threshold &= ~0x1;
2229 }
2230 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2231 }
2232
2233 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2234 rts_threshold = nla_get_u32(
2235 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2236 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2237 }
2238
Lukáš Turek81077e82009-12-21 22:50:47 +01002239 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2240 coverage_class = nla_get_u8(
2241 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2242 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2243 }
2244
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002245 if (changed) {
2246 u8 old_retry_short, old_retry_long;
2247 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002248 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002249
Ying Xue7f2b8562014-01-15 10:23:45 +08002250 if (!rdev->ops->set_wiphy_params)
2251 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002252
2253 old_retry_short = rdev->wiphy.retry_short;
2254 old_retry_long = rdev->wiphy.retry_long;
2255 old_frag_threshold = rdev->wiphy.frag_threshold;
2256 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002257 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002258
2259 if (changed & WIPHY_PARAM_RETRY_SHORT)
2260 rdev->wiphy.retry_short = retry_short;
2261 if (changed & WIPHY_PARAM_RETRY_LONG)
2262 rdev->wiphy.retry_long = retry_long;
2263 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2264 rdev->wiphy.frag_threshold = frag_threshold;
2265 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2266 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002267 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2268 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002269
Hila Gonene35e4d22012-06-27 17:19:42 +03002270 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002271 if (result) {
2272 rdev->wiphy.retry_short = old_retry_short;
2273 rdev->wiphy.retry_long = old_retry_long;
2274 rdev->wiphy.frag_threshold = old_frag_threshold;
2275 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002276 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002277 }
2278 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002279 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002280}
2281
Johannes Berg71bbc992012-06-15 15:30:18 +02002282static inline u64 wdev_id(struct wireless_dev *wdev)
2283{
2284 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002285 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002286}
Johannes Berg55682962007-09-20 13:09:35 -04002287
Johannes Berg683b6d32012-11-08 21:25:48 +01002288static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002289 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002290{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002291 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002292
Johannes Berg683b6d32012-11-08 21:25:48 +01002293 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2294 chandef->chan->center_freq))
2295 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002296 switch (chandef->width) {
2297 case NL80211_CHAN_WIDTH_20_NOHT:
2298 case NL80211_CHAN_WIDTH_20:
2299 case NL80211_CHAN_WIDTH_40:
2300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2301 cfg80211_get_chandef_type(chandef)))
2302 return -ENOBUFS;
2303 break;
2304 default:
2305 break;
2306 }
2307 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2308 return -ENOBUFS;
2309 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2310 return -ENOBUFS;
2311 if (chandef->center_freq2 &&
2312 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002313 return -ENOBUFS;
2314 return 0;
2315}
2316
Eric W. Biederman15e47302012-09-07 20:12:54 +00002317static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002318 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002319 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002320{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002321 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002322 void *hdr;
2323
Eric W. Biederman15e47302012-09-07 20:12:54 +00002324 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002325 if (!hdr)
2326 return -1;
2327
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002328 if (dev &&
2329 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002330 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002331 goto nla_put_failure;
2332
2333 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2334 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002335 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002336 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002337 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2338 rdev->devlist_generation ^
2339 (cfg80211_rdev_list_generation << 2)))
2340 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002341
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002342 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002343 int ret;
2344 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002345
Johannes Berg683b6d32012-11-08 21:25:48 +01002346 ret = rdev_get_channel(rdev, wdev, &chandef);
2347 if (ret == 0) {
2348 if (nl80211_send_chandef(msg, &chandef))
2349 goto nla_put_failure;
2350 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002351 }
2352
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002353 if (wdev->ssid_len) {
2354 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2355 goto nla_put_failure;
2356 }
2357
Johannes Berg55682962007-09-20 13:09:35 -04002358 return genlmsg_end(msg, hdr);
2359
2360 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002361 genlmsg_cancel(msg, hdr);
2362 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002363}
2364
2365static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2366{
2367 int wp_idx = 0;
2368 int if_idx = 0;
2369 int wp_start = cb->args[0];
2370 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002371 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002372 struct wireless_dev *wdev;
2373
Johannes Berg5fe231e2013-05-08 21:45:15 +02002374 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002375 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2376 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002377 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002378 if (wp_idx < wp_start) {
2379 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002380 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002381 }
Johannes Berg55682962007-09-20 13:09:35 -04002382 if_idx = 0;
2383
Johannes Berg89a54e42012-06-15 14:33:17 +02002384 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002385 if (if_idx < if_start) {
2386 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002387 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002388 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002389 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002390 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002391 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002392 goto out;
2393 }
2394 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002395 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002396
2397 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002398 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002399 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002400 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002401
2402 cb->args[0] = wp_idx;
2403 cb->args[1] = if_idx;
2404
2405 return skb->len;
2406}
2407
2408static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2409{
2410 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002412 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002413
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002414 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002415 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002416 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002417
Eric W. Biederman15e47302012-09-07 20:12:54 +00002418 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002419 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002420 nlmsg_free(msg);
2421 return -ENOBUFS;
2422 }
Johannes Berg55682962007-09-20 13:09:35 -04002423
Johannes Berg134e6372009-07-10 09:51:34 +00002424 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002425}
2426
Michael Wu66f7ac52008-01-31 19:48:22 +01002427static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2428 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2429 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2430 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2431 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2432 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002433 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002434};
2435
2436static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2437{
2438 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2439 int flag;
2440
2441 *mntrflags = 0;
2442
2443 if (!nla)
2444 return -EINVAL;
2445
2446 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2447 nla, mntr_flags_policy))
2448 return -EINVAL;
2449
2450 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2451 if (flags[flag])
2452 *mntrflags |= (1<<flag);
2453
2454 return 0;
2455}
2456
Johannes Berg9bc383d2009-11-19 11:55:19 +01002457static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002458 struct net_device *netdev, u8 use_4addr,
2459 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002460{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002461 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002462 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002463 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002464 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002465 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002466
2467 switch (iftype) {
2468 case NL80211_IFTYPE_AP_VLAN:
2469 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2470 return 0;
2471 break;
2472 case NL80211_IFTYPE_STATION:
2473 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2474 return 0;
2475 break;
2476 default:
2477 break;
2478 }
2479
2480 return -EOPNOTSUPP;
2481}
2482
Johannes Berg55682962007-09-20 13:09:35 -04002483static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2484{
Johannes Berg4c476992010-10-04 21:36:35 +02002485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002486 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002487 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002488 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002489 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002490 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002491 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002492
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002493 memset(&params, 0, sizeof(params));
2494
Johannes Berg04a773a2009-04-19 21:24:32 +02002495 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002496
Johannes Berg723b0382008-09-16 20:22:09 +02002497 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002498 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002499 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002500 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002501 if (ntype > NL80211_IFTYPE_MAX)
2502 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002503 }
2504
Johannes Berg92ffe052008-09-16 20:39:36 +02002505 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002506 struct wireless_dev *wdev = dev->ieee80211_ptr;
2507
Johannes Berg4c476992010-10-04 21:36:35 +02002508 if (ntype != NL80211_IFTYPE_MESH_POINT)
2509 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002510 if (netif_running(dev))
2511 return -EBUSY;
2512
2513 wdev_lock(wdev);
2514 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2515 IEEE80211_MAX_MESH_ID_LEN);
2516 wdev->mesh_id_up_len =
2517 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2518 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2519 wdev->mesh_id_up_len);
2520 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002521 }
2522
Felix Fietkau8b787642009-11-10 18:53:10 +01002523 if (info->attrs[NL80211_ATTR_4ADDR]) {
2524 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2525 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002526 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002527 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002528 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002529 } else {
2530 params.use_4addr = -1;
2531 }
2532
Johannes Berg92ffe052008-09-16 20:39:36 +02002533 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002534 if (ntype != NL80211_IFTYPE_MONITOR)
2535 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002536 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2537 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002538 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002539 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002540
2541 flags = &_flags;
2542 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002543 }
Johannes Berg3b858752009-03-12 09:55:09 +01002544
Luciano Coelho18003292013-08-29 13:26:57 +03002545 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002546 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2547 return -EOPNOTSUPP;
2548
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002549 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002550 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002551 else
2552 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002553
Johannes Berg9bc383d2009-11-19 11:55:19 +01002554 if (!err && params.use_4addr != -1)
2555 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2556
Johannes Berg55682962007-09-20 13:09:35 -04002557 return err;
2558}
2559
2560static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2561{
Johannes Berg4c476992010-10-04 21:36:35 +02002562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002563 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002564 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002565 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002566 int err;
2567 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002568 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002569
Johannes Berg78f22b62014-03-24 17:57:27 +01002570 /* to avoid failing a new interface creation due to pending removal */
2571 cfg80211_destroy_ifaces(rdev);
2572
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002573 memset(&params, 0, sizeof(params));
2574
Johannes Berg55682962007-09-20 13:09:35 -04002575 if (!info->attrs[NL80211_ATTR_IFNAME])
2576 return -EINVAL;
2577
2578 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2579 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2580 if (type > NL80211_IFTYPE_MAX)
2581 return -EINVAL;
2582 }
2583
Johannes Berg79c97e92009-07-07 03:56:12 +02002584 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002585 !(rdev->wiphy.interface_modes & (1 << type)))
2586 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002587
Arend van Spriel1c18f142013-01-08 10:17:27 +01002588 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2589 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2590 ETH_ALEN);
2591 if (!is_valid_ether_addr(params.macaddr))
2592 return -EADDRNOTAVAIL;
2593 }
2594
Johannes Berg9bc383d2009-11-19 11:55:19 +01002595 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002596 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002597 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002598 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002599 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002600 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002601
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2603 if (!msg)
2604 return -ENOMEM;
2605
Michael Wu66f7ac52008-01-31 19:48:22 +01002606 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2607 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2608 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002609
Luciano Coelho18003292013-08-29 13:26:57 +03002610 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002611 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2612 return -EOPNOTSUPP;
2613
Hila Gonene35e4d22012-06-27 17:19:42 +03002614 wdev = rdev_add_virtual_intf(rdev,
2615 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2616 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002617 if (IS_ERR(wdev)) {
2618 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002619 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002620 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002621
Johannes Berg78f22b62014-03-24 17:57:27 +01002622 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2623 wdev->owner_nlportid = info->snd_portid;
2624
Johannes Berg98104fde2012-06-16 00:19:54 +02002625 switch (type) {
2626 case NL80211_IFTYPE_MESH_POINT:
2627 if (!info->attrs[NL80211_ATTR_MESH_ID])
2628 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002629 wdev_lock(wdev);
2630 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2631 IEEE80211_MAX_MESH_ID_LEN);
2632 wdev->mesh_id_up_len =
2633 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2634 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2635 wdev->mesh_id_up_len);
2636 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002637 break;
2638 case NL80211_IFTYPE_P2P_DEVICE:
2639 /*
2640 * P2P Device doesn't have a netdev, so doesn't go
2641 * through the netdev notifier and must be added here
2642 */
2643 mutex_init(&wdev->mtx);
2644 INIT_LIST_HEAD(&wdev->event_list);
2645 spin_lock_init(&wdev->event_lock);
2646 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2647 spin_lock_init(&wdev->mgmt_registrations_lock);
2648
Johannes Berg98104fde2012-06-16 00:19:54 +02002649 wdev->identifier = ++rdev->wdev_id;
2650 list_add_rcu(&wdev->list, &rdev->wdev_list);
2651 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002652 break;
2653 default:
2654 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002655 }
2656
Eric W. Biederman15e47302012-09-07 20:12:54 +00002657 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002658 rdev, wdev) < 0) {
2659 nlmsg_free(msg);
2660 return -ENOBUFS;
2661 }
2662
2663 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002664}
2665
2666static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2667{
Johannes Berg4c476992010-10-04 21:36:35 +02002668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002669 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002670
Johannes Berg4c476992010-10-04 21:36:35 +02002671 if (!rdev->ops->del_virtual_intf)
2672 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002673
Johannes Berg84efbb82012-06-16 00:00:26 +02002674 /*
2675 * If we remove a wireless device without a netdev then clear
2676 * user_ptr[1] so that nl80211_post_doit won't dereference it
2677 * to check if it needs to do dev_put(). Otherwise it crashes
2678 * since the wdev has been freed, unlike with a netdev where
2679 * we need the dev_put() for the netdev to really be freed.
2680 */
2681 if (!wdev->netdev)
2682 info->user_ptr[1] = NULL;
2683
Hila Gonene35e4d22012-06-27 17:19:42 +03002684 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002685}
2686
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002687static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2688{
2689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2690 struct net_device *dev = info->user_ptr[1];
2691 u16 noack_map;
2692
2693 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2694 return -EINVAL;
2695
2696 if (!rdev->ops->set_noack_map)
2697 return -EOPNOTSUPP;
2698
2699 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2700
Hila Gonene35e4d22012-06-27 17:19:42 +03002701 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002702}
2703
Johannes Berg41ade002007-12-19 02:03:29 +01002704struct get_key_cookie {
2705 struct sk_buff *msg;
2706 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002707 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002708};
2709
2710static void get_key_callback(void *c, struct key_params *params)
2711{
Johannes Bergb9454e82009-07-08 13:29:08 +02002712 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002713 struct get_key_cookie *cookie = c;
2714
David S. Miller9360ffd2012-03-29 04:41:26 -04002715 if ((params->key &&
2716 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2717 params->key_len, params->key)) ||
2718 (params->seq &&
2719 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2720 params->seq_len, params->seq)) ||
2721 (params->cipher &&
2722 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2723 params->cipher)))
2724 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002725
Johannes Bergb9454e82009-07-08 13:29:08 +02002726 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2727 if (!key)
2728 goto nla_put_failure;
2729
David S. Miller9360ffd2012-03-29 04:41:26 -04002730 if ((params->key &&
2731 nla_put(cookie->msg, NL80211_KEY_DATA,
2732 params->key_len, params->key)) ||
2733 (params->seq &&
2734 nla_put(cookie->msg, NL80211_KEY_SEQ,
2735 params->seq_len, params->seq)) ||
2736 (params->cipher &&
2737 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2738 params->cipher)))
2739 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002740
David S. Miller9360ffd2012-03-29 04:41:26 -04002741 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2742 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002743
2744 nla_nest_end(cookie->msg, key);
2745
Johannes Berg41ade002007-12-19 02:03:29 +01002746 return;
2747 nla_put_failure:
2748 cookie->error = 1;
2749}
2750
2751static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2752{
Johannes Berg4c476992010-10-04 21:36:35 +02002753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002754 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002755 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002756 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002757 const u8 *mac_addr = NULL;
2758 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002759 struct get_key_cookie cookie = {
2760 .error = 0,
2761 };
2762 void *hdr;
2763 struct sk_buff *msg;
2764
2765 if (info->attrs[NL80211_ATTR_KEY_IDX])
2766 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2767
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002768 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002769 return -EINVAL;
2770
2771 if (info->attrs[NL80211_ATTR_MAC])
2772 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2773
Johannes Berge31b8212010-10-05 19:39:30 +02002774 pairwise = !!mac_addr;
2775 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2776 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2777 if (kt >= NUM_NL80211_KEYTYPES)
2778 return -EINVAL;
2779 if (kt != NL80211_KEYTYPE_GROUP &&
2780 kt != NL80211_KEYTYPE_PAIRWISE)
2781 return -EINVAL;
2782 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2783 }
2784
Johannes Berg4c476992010-10-04 21:36:35 +02002785 if (!rdev->ops->get_key)
2786 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002787
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002789 if (!msg)
2790 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002791
Eric W. Biederman15e47302012-09-07 20:12:54 +00002792 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002793 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002794 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002795 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002796
2797 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002798 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002799
David S. Miller9360ffd2012-03-29 04:41:26 -04002800 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2801 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2802 goto nla_put_failure;
2803 if (mac_addr &&
2804 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2805 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002806
Johannes Berge31b8212010-10-05 19:39:30 +02002807 if (pairwise && mac_addr &&
2808 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2809 return -ENOENT;
2810
Hila Gonene35e4d22012-06-27 17:19:42 +03002811 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2812 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002813
2814 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002815 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002816
2817 if (cookie.error)
2818 goto nla_put_failure;
2819
2820 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002821 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002822
2823 nla_put_failure:
2824 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002825 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002826 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002827 return err;
2828}
2829
2830static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2831{
Johannes Berg4c476992010-10-04 21:36:35 +02002832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002833 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002834 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002835 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002836
Johannes Bergb9454e82009-07-08 13:29:08 +02002837 err = nl80211_parse_key(info, &key);
2838 if (err)
2839 return err;
2840
2841 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002842 return -EINVAL;
2843
Johannes Bergb9454e82009-07-08 13:29:08 +02002844 /* only support setting default key */
2845 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002846 return -EINVAL;
2847
Johannes Bergfffd0932009-07-08 14:22:54 +02002848 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002849
2850 if (key.def) {
2851 if (!rdev->ops->set_default_key) {
2852 err = -EOPNOTSUPP;
2853 goto out;
2854 }
2855
2856 err = nl80211_key_allowed(dev->ieee80211_ptr);
2857 if (err)
2858 goto out;
2859
Hila Gonene35e4d22012-06-27 17:19:42 +03002860 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002861 key.def_uni, key.def_multi);
2862
2863 if (err)
2864 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002865
Johannes Berg3d23e342009-09-29 23:27:28 +02002866#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002867 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002868#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002869 } else {
2870 if (key.def_uni || !key.def_multi) {
2871 err = -EINVAL;
2872 goto out;
2873 }
2874
2875 if (!rdev->ops->set_default_mgmt_key) {
2876 err = -EOPNOTSUPP;
2877 goto out;
2878 }
2879
2880 err = nl80211_key_allowed(dev->ieee80211_ptr);
2881 if (err)
2882 goto out;
2883
Hila Gonene35e4d22012-06-27 17:19:42 +03002884 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002885 if (err)
2886 goto out;
2887
2888#ifdef CONFIG_CFG80211_WEXT
2889 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2890#endif
2891 }
2892
2893 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002894 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002895
Johannes Berg41ade002007-12-19 02:03:29 +01002896 return err;
2897}
2898
2899static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2900{
Johannes Berg4c476992010-10-04 21:36:35 +02002901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002902 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002903 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002904 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002905 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002906
Johannes Bergb9454e82009-07-08 13:29:08 +02002907 err = nl80211_parse_key(info, &key);
2908 if (err)
2909 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002910
Johannes Bergb9454e82009-07-08 13:29:08 +02002911 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002912 return -EINVAL;
2913
Johannes Berg41ade002007-12-19 02:03:29 +01002914 if (info->attrs[NL80211_ATTR_MAC])
2915 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2916
Johannes Berge31b8212010-10-05 19:39:30 +02002917 if (key.type == -1) {
2918 if (mac_addr)
2919 key.type = NL80211_KEYTYPE_PAIRWISE;
2920 else
2921 key.type = NL80211_KEYTYPE_GROUP;
2922 }
2923
2924 /* for now */
2925 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2926 key.type != NL80211_KEYTYPE_GROUP)
2927 return -EINVAL;
2928
Johannes Berg4c476992010-10-04 21:36:35 +02002929 if (!rdev->ops->add_key)
2930 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002931
Johannes Berge31b8212010-10-05 19:39:30 +02002932 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2933 key.type == NL80211_KEYTYPE_PAIRWISE,
2934 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002935 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002936
2937 wdev_lock(dev->ieee80211_ptr);
2938 err = nl80211_key_allowed(dev->ieee80211_ptr);
2939 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002940 err = rdev_add_key(rdev, dev, key.idx,
2941 key.type == NL80211_KEYTYPE_PAIRWISE,
2942 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002943 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002944
Johannes Berg41ade002007-12-19 02:03:29 +01002945 return err;
2946}
2947
2948static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2949{
Johannes Berg4c476992010-10-04 21:36:35 +02002950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002951 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002952 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002953 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002954 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002955
Johannes Bergb9454e82009-07-08 13:29:08 +02002956 err = nl80211_parse_key(info, &key);
2957 if (err)
2958 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002959
2960 if (info->attrs[NL80211_ATTR_MAC])
2961 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2962
Johannes Berge31b8212010-10-05 19:39:30 +02002963 if (key.type == -1) {
2964 if (mac_addr)
2965 key.type = NL80211_KEYTYPE_PAIRWISE;
2966 else
2967 key.type = NL80211_KEYTYPE_GROUP;
2968 }
2969
2970 /* for now */
2971 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2972 key.type != NL80211_KEYTYPE_GROUP)
2973 return -EINVAL;
2974
Johannes Berg4c476992010-10-04 21:36:35 +02002975 if (!rdev->ops->del_key)
2976 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002977
Johannes Bergfffd0932009-07-08 14:22:54 +02002978 wdev_lock(dev->ieee80211_ptr);
2979 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002980
2981 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2982 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2983 err = -ENOENT;
2984
Johannes Bergfffd0932009-07-08 14:22:54 +02002985 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002986 err = rdev_del_key(rdev, dev, key.idx,
2987 key.type == NL80211_KEYTYPE_PAIRWISE,
2988 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002989
Johannes Berg3d23e342009-09-29 23:27:28 +02002990#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002991 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002992 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002993 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002994 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002995 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2996 }
2997#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002998 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002999
Johannes Berg41ade002007-12-19 02:03:29 +01003000 return err;
3001}
3002
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303003/* This function returns an error or the number of nested attributes */
3004static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3005{
3006 struct nlattr *attr;
3007 int n_entries = 0, tmp;
3008
3009 nla_for_each_nested(attr, nl_attr, tmp) {
3010 if (nla_len(attr) != ETH_ALEN)
3011 return -EINVAL;
3012
3013 n_entries++;
3014 }
3015
3016 return n_entries;
3017}
3018
3019/*
3020 * This function parses ACL information and allocates memory for ACL data.
3021 * On successful return, the calling function is responsible to free the
3022 * ACL buffer returned by this function.
3023 */
3024static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3025 struct genl_info *info)
3026{
3027 enum nl80211_acl_policy acl_policy;
3028 struct nlattr *attr;
3029 struct cfg80211_acl_data *acl;
3030 int i = 0, n_entries, tmp;
3031
3032 if (!wiphy->max_acl_mac_addrs)
3033 return ERR_PTR(-EOPNOTSUPP);
3034
3035 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3036 return ERR_PTR(-EINVAL);
3037
3038 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3039 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3040 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3041 return ERR_PTR(-EINVAL);
3042
3043 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3044 return ERR_PTR(-EINVAL);
3045
3046 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3047 if (n_entries < 0)
3048 return ERR_PTR(n_entries);
3049
3050 if (n_entries > wiphy->max_acl_mac_addrs)
3051 return ERR_PTR(-ENOTSUPP);
3052
3053 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3054 GFP_KERNEL);
3055 if (!acl)
3056 return ERR_PTR(-ENOMEM);
3057
3058 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3059 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3060 i++;
3061 }
3062
3063 acl->n_acl_entries = n_entries;
3064 acl->acl_policy = acl_policy;
3065
3066 return acl;
3067}
3068
3069static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3070{
3071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3072 struct net_device *dev = info->user_ptr[1];
3073 struct cfg80211_acl_data *acl;
3074 int err;
3075
3076 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3077 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3078 return -EOPNOTSUPP;
3079
3080 if (!dev->ieee80211_ptr->beacon_interval)
3081 return -EINVAL;
3082
3083 acl = parse_acl_data(&rdev->wiphy, info);
3084 if (IS_ERR(acl))
3085 return PTR_ERR(acl);
3086
3087 err = rdev_set_mac_acl(rdev, dev, acl);
3088
3089 kfree(acl);
3090
3091 return err;
3092}
3093
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003094static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003095 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003096{
Johannes Berg88600202012-02-13 15:17:18 +01003097 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003098
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003099 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3100 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3101 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3102 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003103 return -EINVAL;
3104
Johannes Berg88600202012-02-13 15:17:18 +01003105 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003106
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003107 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3108 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3109 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003110 if (!bcn->head_len)
3111 return -EINVAL;
3112 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003113 }
3114
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003115 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3116 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3117 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003118 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003119 }
3120
Johannes Berg4c476992010-10-04 21:36:35 +02003121 if (!haveinfo)
3122 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003123
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003124 if (attrs[NL80211_ATTR_IE]) {
3125 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3126 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003127 }
3128
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003129 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003130 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003131 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003132 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003133 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003134 }
3135
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003136 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003137 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003138 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003139 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003140 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003141 }
3142
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003143 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3144 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3145 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003146 }
3147
Johannes Berg88600202012-02-13 15:17:18 +01003148 return 0;
3149}
3150
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003151static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3152 struct cfg80211_ap_settings *params)
3153{
3154 struct wireless_dev *wdev;
3155 bool ret = false;
3156
Johannes Berg89a54e42012-06-15 14:33:17 +02003157 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003158 if (wdev->iftype != NL80211_IFTYPE_AP &&
3159 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3160 continue;
3161
Johannes Berg683b6d32012-11-08 21:25:48 +01003162 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003163 continue;
3164
Johannes Berg683b6d32012-11-08 21:25:48 +01003165 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003166 ret = true;
3167 break;
3168 }
3169
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003170 return ret;
3171}
3172
Jouni Malinene39e5b52012-09-30 19:29:39 +03003173static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3174 enum nl80211_auth_type auth_type,
3175 enum nl80211_commands cmd)
3176{
3177 if (auth_type > NL80211_AUTHTYPE_MAX)
3178 return false;
3179
3180 switch (cmd) {
3181 case NL80211_CMD_AUTHENTICATE:
3182 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3183 auth_type == NL80211_AUTHTYPE_SAE)
3184 return false;
3185 return true;
3186 case NL80211_CMD_CONNECT:
3187 case NL80211_CMD_START_AP:
3188 /* SAE not supported yet */
3189 if (auth_type == NL80211_AUTHTYPE_SAE)
3190 return false;
3191 return true;
3192 default:
3193 return false;
3194 }
3195}
3196
Johannes Berg88600202012-02-13 15:17:18 +01003197static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3198{
3199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3200 struct net_device *dev = info->user_ptr[1];
3201 struct wireless_dev *wdev = dev->ieee80211_ptr;
3202 struct cfg80211_ap_settings params;
3203 int err;
3204
3205 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3206 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3207 return -EOPNOTSUPP;
3208
3209 if (!rdev->ops->start_ap)
3210 return -EOPNOTSUPP;
3211
3212 if (wdev->beacon_interval)
3213 return -EALREADY;
3214
3215 memset(&params, 0, sizeof(params));
3216
3217 /* these are required for START_AP */
3218 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3219 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3220 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3221 return -EINVAL;
3222
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003223 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003224 if (err)
3225 return err;
3226
3227 params.beacon_interval =
3228 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3229 params.dtim_period =
3230 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3231
3232 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3233 if (err)
3234 return err;
3235
3236 /*
3237 * In theory, some of these attributes should be required here
3238 * but since they were not used when the command was originally
3239 * added, keep them optional for old user space programs to let
3240 * them continue to work with drivers that do not need the
3241 * additional information -- drivers must check!
3242 */
3243 if (info->attrs[NL80211_ATTR_SSID]) {
3244 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3245 params.ssid_len =
3246 nla_len(info->attrs[NL80211_ATTR_SSID]);
3247 if (params.ssid_len == 0 ||
3248 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3249 return -EINVAL;
3250 }
3251
3252 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3253 params.hidden_ssid = nla_get_u32(
3254 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3255 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3256 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3257 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3258 return -EINVAL;
3259 }
3260
3261 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3262
3263 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3264 params.auth_type = nla_get_u32(
3265 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003266 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3267 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003268 return -EINVAL;
3269 } else
3270 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3271
3272 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3273 NL80211_MAX_NR_CIPHER_SUITES);
3274 if (err)
3275 return err;
3276
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303277 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3278 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3279 return -EOPNOTSUPP;
3280 params.inactivity_timeout = nla_get_u16(
3281 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3282 }
3283
Johannes Berg53cabad2012-11-14 15:17:28 +01003284 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3285 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3286 return -EINVAL;
3287 params.p2p_ctwindow =
3288 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3289 if (params.p2p_ctwindow > 127)
3290 return -EINVAL;
3291 if (params.p2p_ctwindow != 0 &&
3292 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3293 return -EINVAL;
3294 }
3295
3296 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3297 u8 tmp;
3298
3299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3300 return -EINVAL;
3301 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3302 if (tmp > 1)
3303 return -EINVAL;
3304 params.p2p_opp_ps = tmp;
3305 if (params.p2p_opp_ps != 0 &&
3306 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3307 return -EINVAL;
3308 }
3309
Johannes Bergaa430da2012-05-16 23:50:18 +02003310 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003311 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3312 if (err)
3313 return err;
3314 } else if (wdev->preset_chandef.chan) {
3315 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003316 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003317 return -EINVAL;
3318
Ilan Peer174e0cd2014-02-23 09:13:01 +02003319 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3320 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003321 return -EINVAL;
3322
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303323 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3324 params.acl = parse_acl_data(&rdev->wiphy, info);
3325 if (IS_ERR(params.acl))
3326 return PTR_ERR(params.acl);
3327 }
3328
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003329 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003330 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003331 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003332 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003333 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003334 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003335 wdev->ssid_len = params.ssid_len;
3336 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003337 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003338 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303339
3340 kfree(params.acl);
3341
Johannes Berg56d18932011-05-09 18:41:15 +02003342 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003343}
3344
Johannes Berg88600202012-02-13 15:17:18 +01003345static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3346{
3347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3348 struct net_device *dev = info->user_ptr[1];
3349 struct wireless_dev *wdev = dev->ieee80211_ptr;
3350 struct cfg80211_beacon_data params;
3351 int err;
3352
3353 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3354 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3355 return -EOPNOTSUPP;
3356
3357 if (!rdev->ops->change_beacon)
3358 return -EOPNOTSUPP;
3359
3360 if (!wdev->beacon_interval)
3361 return -EINVAL;
3362
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003363 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003364 if (err)
3365 return err;
3366
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003367 wdev_lock(wdev);
3368 err = rdev_change_beacon(rdev, dev, &params);
3369 wdev_unlock(wdev);
3370
3371 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003372}
3373
3374static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003375{
Johannes Berg4c476992010-10-04 21:36:35 +02003376 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3377 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003378
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003379 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003380}
3381
Johannes Berg5727ef12007-12-19 02:03:34 +01003382static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3383 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3384 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3385 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003386 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003387 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003388 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003389};
3390
Johannes Bergeccb8e82009-05-11 21:57:56 +03003391static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003392 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003393 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003394{
3395 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003396 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003397 int flag;
3398
Johannes Bergeccb8e82009-05-11 21:57:56 +03003399 /*
3400 * Try parsing the new attribute first so userspace
3401 * can specify both for older kernels.
3402 */
3403 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3404 if (nla) {
3405 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003406
Johannes Bergeccb8e82009-05-11 21:57:56 +03003407 sta_flags = nla_data(nla);
3408 params->sta_flags_mask = sta_flags->mask;
3409 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003410 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003411 if ((params->sta_flags_mask |
3412 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3413 return -EINVAL;
3414 return 0;
3415 }
3416
3417 /* if present, parse the old attribute */
3418
3419 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003420 if (!nla)
3421 return 0;
3422
3423 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3424 nla, sta_flags_policy))
3425 return -EINVAL;
3426
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003427 /*
3428 * Only allow certain flags for interface types so that
3429 * other attributes are silently ignored. Remember that
3430 * this is backward compatibility code with old userspace
3431 * and shouldn't be hit in other cases anyway.
3432 */
3433 switch (iftype) {
3434 case NL80211_IFTYPE_AP:
3435 case NL80211_IFTYPE_AP_VLAN:
3436 case NL80211_IFTYPE_P2P_GO:
3437 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3438 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3439 BIT(NL80211_STA_FLAG_WME) |
3440 BIT(NL80211_STA_FLAG_MFP);
3441 break;
3442 case NL80211_IFTYPE_P2P_CLIENT:
3443 case NL80211_IFTYPE_STATION:
3444 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3445 BIT(NL80211_STA_FLAG_TDLS_PEER);
3446 break;
3447 case NL80211_IFTYPE_MESH_POINT:
3448 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3449 BIT(NL80211_STA_FLAG_MFP) |
3450 BIT(NL80211_STA_FLAG_AUTHORIZED);
3451 default:
3452 return -EINVAL;
3453 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003454
Johannes Berg3383b5a2012-05-10 20:14:43 +02003455 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3456 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003457 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003458
Johannes Berg3383b5a2012-05-10 20:14:43 +02003459 /* no longer support new API additions in old API */
3460 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3461 return -EINVAL;
3462 }
3463 }
3464
Johannes Berg5727ef12007-12-19 02:03:34 +01003465 return 0;
3466}
3467
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003468static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3469 int attr)
3470{
3471 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003472 u32 bitrate;
3473 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003474
3475 rate = nla_nest_start(msg, attr);
3476 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003477 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003478
3479 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3480 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003481 /* report 16-bit bitrate only if we can */
3482 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003483 if (bitrate > 0 &&
3484 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3485 return false;
3486 if (bitrate_compat > 0 &&
3487 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3488 return false;
3489
3490 if (info->flags & RATE_INFO_FLAGS_MCS) {
3491 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3492 return false;
3493 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3494 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3495 return false;
3496 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3497 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3498 return false;
3499 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3500 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3501 return false;
3502 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3503 return false;
3504 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3505 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3506 return false;
3507 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3508 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3509 return false;
3510 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3511 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3512 return false;
3513 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3514 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3515 return false;
3516 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3517 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3518 return false;
3519 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003520
3521 nla_nest_end(msg, rate);
3522 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003523}
3524
Felix Fietkau119363c2013-04-22 16:29:30 +02003525static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3526 int id)
3527{
3528 void *attr;
3529 int i = 0;
3530
3531 if (!mask)
3532 return true;
3533
3534 attr = nla_nest_start(msg, id);
3535 if (!attr)
3536 return false;
3537
3538 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3539 if (!(mask & BIT(i)))
3540 continue;
3541
3542 if (nla_put_u8(msg, i, signal[i]))
3543 return false;
3544 }
3545
3546 nla_nest_end(msg, attr);
3547
3548 return true;
3549}
3550
Eric W. Biederman15e47302012-09-07 20:12:54 +00003551static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003552 int flags,
3553 struct cfg80211_registered_device *rdev,
3554 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003555 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003556{
3557 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003558 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003559
Eric W. Biederman15e47302012-09-07 20:12:54 +00003560 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003561 if (!hdr)
3562 return -1;
3563
David S. Miller9360ffd2012-03-29 04:41:26 -04003564 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3565 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3566 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3567 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003568
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3570 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003571 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003572 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3573 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3574 sinfo->connected_time))
3575 goto nla_put_failure;
3576 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3577 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3578 sinfo->inactive_time))
3579 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003580 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3581 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003582 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003583 (u32)sinfo->rx_bytes))
3584 goto nla_put_failure;
3585 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003586 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003587 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3588 (u32)sinfo->tx_bytes))
3589 goto nla_put_failure;
3590 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3591 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003592 sinfo->rx_bytes))
3593 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003594 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3595 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003596 sinfo->tx_bytes))
3597 goto nla_put_failure;
3598 if ((sinfo->filled & STATION_INFO_LLID) &&
3599 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3600 goto nla_put_failure;
3601 if ((sinfo->filled & STATION_INFO_PLID) &&
3602 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3603 goto nla_put_failure;
3604 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3605 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3606 sinfo->plink_state))
3607 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003608 switch (rdev->wiphy.signal_type) {
3609 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003610 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3611 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3612 sinfo->signal))
3613 goto nla_put_failure;
3614 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3615 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3616 sinfo->signal_avg))
3617 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003618 break;
3619 default:
3620 break;
3621 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003622 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3623 if (!nl80211_put_signal(msg, sinfo->chains,
3624 sinfo->chain_signal,
3625 NL80211_STA_INFO_CHAIN_SIGNAL))
3626 goto nla_put_failure;
3627 }
3628 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3629 if (!nl80211_put_signal(msg, sinfo->chains,
3630 sinfo->chain_signal_avg,
3631 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3632 goto nla_put_failure;
3633 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003634 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003635 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3636 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003637 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003638 }
3639 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3640 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3641 NL80211_STA_INFO_RX_BITRATE))
3642 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003643 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003644 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3645 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3646 sinfo->rx_packets))
3647 goto nla_put_failure;
3648 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3649 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3650 sinfo->tx_packets))
3651 goto nla_put_failure;
3652 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3653 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3654 sinfo->tx_retries))
3655 goto nla_put_failure;
3656 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3657 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3658 sinfo->tx_failed))
3659 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003660 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3661 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3662 sinfo->expected_throughput))
3663 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003664 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3665 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3666 sinfo->beacon_loss_count))
3667 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003668 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3669 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3670 sinfo->local_pm))
3671 goto nla_put_failure;
3672 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3673 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3674 sinfo->peer_pm))
3675 goto nla_put_failure;
3676 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3677 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3678 sinfo->nonpeer_pm))
3679 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003680 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3681 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3682 if (!bss_param)
3683 goto nla_put_failure;
3684
David S. Miller9360ffd2012-03-29 04:41:26 -04003685 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3686 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3687 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3688 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3689 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3690 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3691 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3692 sinfo->bss_param.dtim_period) ||
3693 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3694 sinfo->bss_param.beacon_interval))
3695 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003696
3697 nla_nest_end(msg, bss_param);
3698 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003699 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3700 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3701 sizeof(struct nl80211_sta_flag_update),
3702 &sinfo->sta_flags))
3703 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003704 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3705 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3706 sinfo->t_offset))
3707 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003708 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003709
David S. Miller9360ffd2012-03-29 04:41:26 -04003710 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3711 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3712 sinfo->assoc_req_ies))
3713 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003714
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003715 return genlmsg_end(msg, hdr);
3716
3717 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003718 genlmsg_cancel(msg, hdr);
3719 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003720}
3721
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003722static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003723 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003724{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003725 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003726 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003727 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003728 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003729 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003730 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003731
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003732 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003733 if (err)
3734 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003735
Johannes Berg97990a02013-04-19 01:02:55 +02003736 if (!wdev->netdev) {
3737 err = -EINVAL;
3738 goto out_err;
3739 }
3740
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003741 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003742 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003743 goto out_err;
3744 }
3745
Johannes Bergbba95fe2008-07-29 13:22:51 +02003746 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003747 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003748 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003749 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003750 if (err == -ENOENT)
3751 break;
3752 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003753 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003754
3755 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003756 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003757 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003758 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003759 &sinfo) < 0)
3760 goto out;
3761
3762 sta_idx++;
3763 }
3764
3765
3766 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003767 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003768 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003769 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003770 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003771
3772 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003773}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003774
Johannes Berg5727ef12007-12-19 02:03:34 +01003775static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3776{
Johannes Berg4c476992010-10-04 21:36:35 +02003777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3778 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003779 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003780 struct sk_buff *msg;
3781 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003782 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003783
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003784 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003785
3786 if (!info->attrs[NL80211_ATTR_MAC])
3787 return -EINVAL;
3788
3789 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3790
Johannes Berg4c476992010-10-04 21:36:35 +02003791 if (!rdev->ops->get_station)
3792 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003793
Hila Gonene35e4d22012-06-27 17:19:42 +03003794 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003795 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003796 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003797
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003799 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003800 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003801
Eric W. Biederman15e47302012-09-07 20:12:54 +00003802 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003803 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003804 nlmsg_free(msg);
3805 return -ENOBUFS;
3806 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003807
Johannes Berg4c476992010-10-04 21:36:35 +02003808 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003809}
3810
Johannes Berg77ee7c82013-02-15 00:48:33 +01003811int cfg80211_check_station_change(struct wiphy *wiphy,
3812 struct station_parameters *params,
3813 enum cfg80211_station_type statype)
3814{
3815 if (params->listen_interval != -1)
3816 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003817 if (params->aid &&
3818 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003819 return -EINVAL;
3820
3821 /* When you run into this, adjust the code below for the new flag */
3822 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3823
3824 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003825 case CFG80211_STA_MESH_PEER_KERNEL:
3826 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003827 /*
3828 * No ignoring the TDLS flag here -- the userspace mesh
3829 * code doesn't have the bug of including TDLS in the
3830 * mask everywhere.
3831 */
3832 if (params->sta_flags_mask &
3833 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3834 BIT(NL80211_STA_FLAG_MFP) |
3835 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3836 return -EINVAL;
3837 break;
3838 case CFG80211_STA_TDLS_PEER_SETUP:
3839 case CFG80211_STA_TDLS_PEER_ACTIVE:
3840 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3841 return -EINVAL;
3842 /* ignore since it can't change */
3843 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3844 break;
3845 default:
3846 /* disallow mesh-specific things */
3847 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3848 return -EINVAL;
3849 if (params->local_pm)
3850 return -EINVAL;
3851 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3852 return -EINVAL;
3853 }
3854
3855 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3856 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3857 /* TDLS can't be set, ... */
3858 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3859 return -EINVAL;
3860 /*
3861 * ... but don't bother the driver with it. This works around
3862 * a hostapd/wpa_supplicant issue -- it always includes the
3863 * TLDS_PEER flag in the mask even for AP mode.
3864 */
3865 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3866 }
3867
3868 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3869 /* reject other things that can't change */
3870 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3871 return -EINVAL;
3872 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3873 return -EINVAL;
3874 if (params->supported_rates)
3875 return -EINVAL;
3876 if (params->ext_capab || params->ht_capa || params->vht_capa)
3877 return -EINVAL;
3878 }
3879
3880 if (statype != CFG80211_STA_AP_CLIENT) {
3881 if (params->vlan)
3882 return -EINVAL;
3883 }
3884
3885 switch (statype) {
3886 case CFG80211_STA_AP_MLME_CLIENT:
3887 /* Use this only for authorizing/unauthorizing a station */
3888 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3889 return -EOPNOTSUPP;
3890 break;
3891 case CFG80211_STA_AP_CLIENT:
3892 /* accept only the listed bits */
3893 if (params->sta_flags_mask &
3894 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3895 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3896 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3897 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3898 BIT(NL80211_STA_FLAG_WME) |
3899 BIT(NL80211_STA_FLAG_MFP)))
3900 return -EINVAL;
3901
3902 /* but authenticated/associated only if driver handles it */
3903 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3904 params->sta_flags_mask &
3905 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3906 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3907 return -EINVAL;
3908 break;
3909 case CFG80211_STA_IBSS:
3910 case CFG80211_STA_AP_STA:
3911 /* reject any changes other than AUTHORIZED */
3912 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3913 return -EINVAL;
3914 break;
3915 case CFG80211_STA_TDLS_PEER_SETUP:
3916 /* reject any changes other than AUTHORIZED or WME */
3917 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3918 BIT(NL80211_STA_FLAG_WME)))
3919 return -EINVAL;
3920 /* force (at least) rates when authorizing */
3921 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3922 !params->supported_rates)
3923 return -EINVAL;
3924 break;
3925 case CFG80211_STA_TDLS_PEER_ACTIVE:
3926 /* reject any changes */
3927 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003928 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003929 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3930 return -EINVAL;
3931 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003932 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003933 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3934 return -EINVAL;
3935 break;
3936 }
3937
3938 return 0;
3939}
3940EXPORT_SYMBOL(cfg80211_check_station_change);
3941
Johannes Berg5727ef12007-12-19 02:03:34 +01003942/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003943 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003944 */
Johannes Berg80b99892011-11-18 16:23:01 +01003945static struct net_device *get_vlan(struct genl_info *info,
3946 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003947{
Johannes Berg463d0182009-07-14 00:33:35 +02003948 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003949 struct net_device *v;
3950 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003951
Johannes Berg80b99892011-11-18 16:23:01 +01003952 if (!vlanattr)
3953 return NULL;
3954
3955 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3956 if (!v)
3957 return ERR_PTR(-ENODEV);
3958
3959 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3960 ret = -EINVAL;
3961 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003962 }
Johannes Berg80b99892011-11-18 16:23:01 +01003963
Johannes Berg77ee7c82013-02-15 00:48:33 +01003964 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3965 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3966 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3967 ret = -EINVAL;
3968 goto error;
3969 }
3970
Johannes Berg80b99892011-11-18 16:23:01 +01003971 if (!netif_running(v)) {
3972 ret = -ENETDOWN;
3973 goto error;
3974 }
3975
3976 return v;
3977 error:
3978 dev_put(v);
3979 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003980}
3981
Johannes Berg94e860f2014-01-20 23:58:15 +01003982static const struct nla_policy
3983nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003984 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3985 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3986};
3987
Johannes Bergff276692013-02-15 00:09:01 +01003988static int nl80211_parse_sta_wme(struct genl_info *info,
3989 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003990{
Jouni Malinendf881292013-02-14 21:10:54 +02003991 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3992 struct nlattr *nla;
3993 int err;
3994
Jouni Malinendf881292013-02-14 21:10:54 +02003995 /* parse WME attributes if present */
3996 if (!info->attrs[NL80211_ATTR_STA_WME])
3997 return 0;
3998
3999 nla = info->attrs[NL80211_ATTR_STA_WME];
4000 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4001 nl80211_sta_wme_policy);
4002 if (err)
4003 return err;
4004
4005 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4006 params->uapsd_queues = nla_get_u8(
4007 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4008 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4009 return -EINVAL;
4010
4011 if (tb[NL80211_STA_WME_MAX_SP])
4012 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4013
4014 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4015 return -EINVAL;
4016
4017 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4018
4019 return 0;
4020}
4021
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304022static int nl80211_parse_sta_channel_info(struct genl_info *info,
4023 struct station_parameters *params)
4024{
4025 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4026 params->supported_channels =
4027 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4028 params->supported_channels_len =
4029 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4030 /*
4031 * Need to include at least one (first channel, number of
4032 * channels) tuple for each subband, and must have proper
4033 * tuples for the rest of the data as well.
4034 */
4035 if (params->supported_channels_len < 2)
4036 return -EINVAL;
4037 if (params->supported_channels_len % 2)
4038 return -EINVAL;
4039 }
4040
4041 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4042 params->supported_oper_classes =
4043 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4044 params->supported_oper_classes_len =
4045 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4046 /*
4047 * The value of the Length field of the Supported Operating
4048 * Classes element is between 2 and 253.
4049 */
4050 if (params->supported_oper_classes_len < 2 ||
4051 params->supported_oper_classes_len > 253)
4052 return -EINVAL;
4053 }
4054 return 0;
4055}
4056
Johannes Bergff276692013-02-15 00:09:01 +01004057static int nl80211_set_station_tdls(struct genl_info *info,
4058 struct station_parameters *params)
4059{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304060 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004061 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004062 if (info->attrs[NL80211_ATTR_PEER_AID])
4063 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004064 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4065 params->ht_capa =
4066 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4067 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4068 params->vht_capa =
4069 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4070
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304071 err = nl80211_parse_sta_channel_info(info, params);
4072 if (err)
4073 return err;
4074
Johannes Bergff276692013-02-15 00:09:01 +01004075 return nl80211_parse_sta_wme(info, params);
4076}
4077
Johannes Berg5727ef12007-12-19 02:03:34 +01004078static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4079{
Johannes Berg4c476992010-10-04 21:36:35 +02004080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004081 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004082 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004083 u8 *mac_addr;
4084 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004085
4086 memset(&params, 0, sizeof(params));
4087
4088 params.listen_interval = -1;
4089
Johannes Berg77ee7c82013-02-15 00:48:33 +01004090 if (!rdev->ops->change_station)
4091 return -EOPNOTSUPP;
4092
Johannes Berg5727ef12007-12-19 02:03:34 +01004093 if (info->attrs[NL80211_ATTR_STA_AID])
4094 return -EINVAL;
4095
4096 if (!info->attrs[NL80211_ATTR_MAC])
4097 return -EINVAL;
4098
4099 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4100
4101 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4102 params.supported_rates =
4103 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4104 params.supported_rates_len =
4105 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4106 }
4107
Jouni Malinen9d62a982013-02-14 21:10:13 +02004108 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4109 params.capability =
4110 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4111 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4112 }
4113
4114 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4115 params.ext_capab =
4116 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4117 params.ext_capab_len =
4118 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4119 }
4120
Jouni Malinendf881292013-02-14 21:10:54 +02004121 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004122 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004123
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004124 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004125 return -EINVAL;
4126
Johannes Bergf8bacc22013-02-14 23:27:01 +01004127 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004128 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004129 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4130 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4131 return -EINVAL;
4132 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004133
Johannes Bergf8bacc22013-02-14 23:27:01 +01004134 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004135 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004136 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4137 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4138 return -EINVAL;
4139 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4140 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004141
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004142 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4143 enum nl80211_mesh_power_mode pm = nla_get_u32(
4144 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4145
4146 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4147 pm > NL80211_MESH_POWER_MAX)
4148 return -EINVAL;
4149
4150 params.local_pm = pm;
4151 }
4152
Johannes Berg77ee7c82013-02-15 00:48:33 +01004153 /* Include parameters for TDLS peer (will check later) */
4154 err = nl80211_set_station_tdls(info, &params);
4155 if (err)
4156 return err;
4157
4158 params.vlan = get_vlan(info, rdev);
4159 if (IS_ERR(params.vlan))
4160 return PTR_ERR(params.vlan);
4161
Johannes Berga97f4422009-06-18 17:23:43 +02004162 switch (dev->ieee80211_ptr->iftype) {
4163 case NL80211_IFTYPE_AP:
4164 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004165 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004166 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004167 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004168 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004169 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004170 break;
4171 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004172 err = -EOPNOTSUPP;
4173 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004174 }
4175
Johannes Berg77ee7c82013-02-15 00:48:33 +01004176 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004177 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004178
Johannes Berg77ee7c82013-02-15 00:48:33 +01004179 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004180 if (params.vlan)
4181 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004182
Johannes Berg5727ef12007-12-19 02:03:34 +01004183 return err;
4184}
4185
4186static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4187{
Johannes Berg4c476992010-10-04 21:36:35 +02004188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004189 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004190 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004191 struct station_parameters params;
4192 u8 *mac_addr = NULL;
4193
4194 memset(&params, 0, sizeof(params));
4195
Johannes Berg984c3112013-02-14 23:43:25 +01004196 if (!rdev->ops->add_station)
4197 return -EOPNOTSUPP;
4198
Johannes Berg5727ef12007-12-19 02:03:34 +01004199 if (!info->attrs[NL80211_ATTR_MAC])
4200 return -EINVAL;
4201
Johannes Berg5727ef12007-12-19 02:03:34 +01004202 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4203 return -EINVAL;
4204
4205 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4206 return -EINVAL;
4207
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004208 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4209 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004210 return -EINVAL;
4211
Johannes Berg5727ef12007-12-19 02:03:34 +01004212 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4213 params.supported_rates =
4214 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4215 params.supported_rates_len =
4216 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4217 params.listen_interval =
4218 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004219
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004220 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004221 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004222 else
4223 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004224 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4225 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004226
Jouni Malinen9d62a982013-02-14 21:10:13 +02004227 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4228 params.capability =
4229 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4230 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4231 }
4232
4233 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4234 params.ext_capab =
4235 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4236 params.ext_capab_len =
4237 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4238 }
4239
Jouni Malinen36aedc902008-08-25 11:58:58 +03004240 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4241 params.ht_capa =
4242 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004243
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004244 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4245 params.vht_capa =
4246 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4247
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004248 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4249 params.opmode_notif_used = true;
4250 params.opmode_notif =
4251 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4252 }
4253
Johannes Bergf8bacc22013-02-14 23:27:01 +01004254 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004255 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004256 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4257 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4258 return -EINVAL;
4259 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004260
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304261 err = nl80211_parse_sta_channel_info(info, &params);
4262 if (err)
4263 return err;
4264
Johannes Bergff276692013-02-15 00:09:01 +01004265 err = nl80211_parse_sta_wme(info, &params);
4266 if (err)
4267 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004268
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004269 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004270 return -EINVAL;
4271
Johannes Berg77ee7c82013-02-15 00:48:33 +01004272 /* When you run into this, adjust the code below for the new flag */
4273 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4274
Johannes Bergbdd90d52011-12-14 12:20:27 +01004275 switch (dev->ieee80211_ptr->iftype) {
4276 case NL80211_IFTYPE_AP:
4277 case NL80211_IFTYPE_AP_VLAN:
4278 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004279 /* ignore WME attributes if iface/sta is not capable */
4280 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4281 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4282 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004283
Johannes Bergbdd90d52011-12-14 12:20:27 +01004284 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004285 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4286 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004287 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004288 /* but don't bother the driver with it */
4289 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004290
Johannes Bergd582cff2012-10-26 17:53:44 +02004291 /* allow authenticated/associated only if driver handles it */
4292 if (!(rdev->wiphy.features &
4293 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4294 params.sta_flags_mask &
4295 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4296 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4297 return -EINVAL;
4298
Johannes Bergbdd90d52011-12-14 12:20:27 +01004299 /* must be last in here for error handling */
4300 params.vlan = get_vlan(info, rdev);
4301 if (IS_ERR(params.vlan))
4302 return PTR_ERR(params.vlan);
4303 break;
4304 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004305 /* ignore uAPSD data */
4306 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4307
Johannes Bergd582cff2012-10-26 17:53:44 +02004308 /* associated is disallowed */
4309 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4310 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004311 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004312 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4313 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004314 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004315 break;
4316 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004317 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004318 /* ignore uAPSD data */
4319 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4320
Johannes Berg77ee7c82013-02-15 00:48:33 +01004321 /* these are disallowed */
4322 if (params.sta_flags_mask &
4323 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4324 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004325 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004326 /* Only TDLS peers can be added */
4327 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4328 return -EINVAL;
4329 /* Can only add if TDLS ... */
4330 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4331 return -EOPNOTSUPP;
4332 /* ... with external setup is supported */
4333 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4334 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004335 /*
4336 * Older wpa_supplicant versions always mark the TDLS peer
4337 * as authorized, but it shouldn't yet be.
4338 */
4339 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004340 break;
4341 default:
4342 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004343 }
4344
Johannes Bergbdd90d52011-12-14 12:20:27 +01004345 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004346
Hila Gonene35e4d22012-06-27 17:19:42 +03004347 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004348
Johannes Berg5727ef12007-12-19 02:03:34 +01004349 if (params.vlan)
4350 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004351 return err;
4352}
4353
4354static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4355{
Johannes Berg4c476992010-10-04 21:36:35 +02004356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4357 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004358 u8 *mac_addr = NULL;
4359
4360 if (info->attrs[NL80211_ATTR_MAC])
4361 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4362
Johannes Berge80cf852009-05-11 14:43:13 +02004363 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004364 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004365 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004366 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4367 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004368
Johannes Berg4c476992010-10-04 21:36:35 +02004369 if (!rdev->ops->del_station)
4370 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004371
Hila Gonene35e4d22012-06-27 17:19:42 +03004372 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004373}
4374
Eric W. Biederman15e47302012-09-07 20:12:54 +00004375static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004376 int flags, struct net_device *dev,
4377 u8 *dst, u8 *next_hop,
4378 struct mpath_info *pinfo)
4379{
4380 void *hdr;
4381 struct nlattr *pinfoattr;
4382
Eric W. Biederman15e47302012-09-07 20:12:54 +00004383 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004384 if (!hdr)
4385 return -1;
4386
David S. Miller9360ffd2012-03-29 04:41:26 -04004387 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4388 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4389 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4390 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4391 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004392
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004393 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4394 if (!pinfoattr)
4395 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004396 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4397 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4398 pinfo->frame_qlen))
4399 goto nla_put_failure;
4400 if (((pinfo->filled & MPATH_INFO_SN) &&
4401 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4402 ((pinfo->filled & MPATH_INFO_METRIC) &&
4403 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4404 pinfo->metric)) ||
4405 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4406 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4407 pinfo->exptime)) ||
4408 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4409 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4410 pinfo->flags)) ||
4411 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4412 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4413 pinfo->discovery_timeout)) ||
4414 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4415 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4416 pinfo->discovery_retries)))
4417 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004418
4419 nla_nest_end(msg, pinfoattr);
4420
4421 return genlmsg_end(msg, hdr);
4422
4423 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004424 genlmsg_cancel(msg, hdr);
4425 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004426}
4427
4428static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004429 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004430{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004431 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004432 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004433 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004434 u8 dst[ETH_ALEN];
4435 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004436 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004437 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004438
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004439 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004440 if (err)
4441 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004442
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004443 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004444 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004445 goto out_err;
4446 }
4447
Johannes Berg97990a02013-04-19 01:02:55 +02004448 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004449 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004450 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004451 }
4452
Johannes Bergbba95fe2008-07-29 13:22:51 +02004453 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004454 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004455 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004456 if (err == -ENOENT)
4457 break;
4458 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004459 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004460
Eric W. Biederman15e47302012-09-07 20:12:54 +00004461 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004462 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004463 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004464 &pinfo) < 0)
4465 goto out;
4466
4467 path_idx++;
4468 }
4469
4470
4471 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004472 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004473 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004474 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004475 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004476 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004477}
4478
4479static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4480{
Johannes Berg4c476992010-10-04 21:36:35 +02004481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004482 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004483 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004484 struct mpath_info pinfo;
4485 struct sk_buff *msg;
4486 u8 *dst = NULL;
4487 u8 next_hop[ETH_ALEN];
4488
4489 memset(&pinfo, 0, sizeof(pinfo));
4490
4491 if (!info->attrs[NL80211_ATTR_MAC])
4492 return -EINVAL;
4493
4494 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4495
Johannes Berg4c476992010-10-04 21:36:35 +02004496 if (!rdev->ops->get_mpath)
4497 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004498
Johannes Berg4c476992010-10-04 21:36:35 +02004499 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4500 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004501
Hila Gonene35e4d22012-06-27 17:19:42 +03004502 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004503 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004504 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004505
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004506 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004507 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004508 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004509
Eric W. Biederman15e47302012-09-07 20:12:54 +00004510 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004511 dev, dst, next_hop, &pinfo) < 0) {
4512 nlmsg_free(msg);
4513 return -ENOBUFS;
4514 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004515
Johannes Berg4c476992010-10-04 21:36:35 +02004516 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004517}
4518
4519static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4520{
Johannes Berg4c476992010-10-04 21:36:35 +02004521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4522 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004523 u8 *dst = NULL;
4524 u8 *next_hop = NULL;
4525
4526 if (!info->attrs[NL80211_ATTR_MAC])
4527 return -EINVAL;
4528
4529 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4530 return -EINVAL;
4531
4532 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4533 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4534
Johannes Berg4c476992010-10-04 21:36:35 +02004535 if (!rdev->ops->change_mpath)
4536 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004537
Johannes Berg4c476992010-10-04 21:36:35 +02004538 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4539 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004540
Hila Gonene35e4d22012-06-27 17:19:42 +03004541 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004542}
Johannes Berg4c476992010-10-04 21:36:35 +02004543
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004544static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4545{
Johannes Berg4c476992010-10-04 21:36:35 +02004546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4547 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004548 u8 *dst = NULL;
4549 u8 *next_hop = NULL;
4550
4551 if (!info->attrs[NL80211_ATTR_MAC])
4552 return -EINVAL;
4553
4554 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4555 return -EINVAL;
4556
4557 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4558 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4559
Johannes Berg4c476992010-10-04 21:36:35 +02004560 if (!rdev->ops->add_mpath)
4561 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004562
Johannes Berg4c476992010-10-04 21:36:35 +02004563 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4564 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004565
Hila Gonene35e4d22012-06-27 17:19:42 +03004566 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004567}
4568
4569static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4570{
Johannes Berg4c476992010-10-04 21:36:35 +02004571 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4572 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004573 u8 *dst = NULL;
4574
4575 if (info->attrs[NL80211_ATTR_MAC])
4576 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4577
Johannes Berg4c476992010-10-04 21:36:35 +02004578 if (!rdev->ops->del_mpath)
4579 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004580
Hila Gonene35e4d22012-06-27 17:19:42 +03004581 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004582}
4583
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004584static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4585{
Johannes Berg4c476992010-10-04 21:36:35 +02004586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4587 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004588 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004589 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004590 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004591
4592 memset(&params, 0, sizeof(params));
4593 /* default to not changing parameters */
4594 params.use_cts_prot = -1;
4595 params.use_short_preamble = -1;
4596 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004597 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004598 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004599 params.p2p_ctwindow = -1;
4600 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004601
4602 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4603 params.use_cts_prot =
4604 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4605 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4606 params.use_short_preamble =
4607 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4608 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4609 params.use_short_slot_time =
4610 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004611 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4612 params.basic_rates =
4613 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4614 params.basic_rates_len =
4615 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4616 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004617 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4618 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004619 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4620 params.ht_opmode =
4621 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004622
Johannes Berg53cabad2012-11-14 15:17:28 +01004623 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4624 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4625 return -EINVAL;
4626 params.p2p_ctwindow =
4627 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4628 if (params.p2p_ctwindow < 0)
4629 return -EINVAL;
4630 if (params.p2p_ctwindow != 0 &&
4631 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4632 return -EINVAL;
4633 }
4634
4635 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4636 u8 tmp;
4637
4638 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4639 return -EINVAL;
4640 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4641 if (tmp > 1)
4642 return -EINVAL;
4643 params.p2p_opp_ps = tmp;
4644 if (params.p2p_opp_ps &&
4645 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4646 return -EINVAL;
4647 }
4648
Johannes Berg4c476992010-10-04 21:36:35 +02004649 if (!rdev->ops->change_bss)
4650 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004651
Johannes Berg074ac8d2010-09-16 14:58:22 +02004652 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004653 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4654 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004655
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004656 wdev_lock(wdev);
4657 err = rdev_change_bss(rdev, dev, &params);
4658 wdev_unlock(wdev);
4659
4660 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004661}
4662
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004663static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004664 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4665 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4666 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4667 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4668 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4669 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004670 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004671};
4672
4673static int parse_reg_rule(struct nlattr *tb[],
4674 struct ieee80211_reg_rule *reg_rule)
4675{
4676 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4677 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4678
4679 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4680 return -EINVAL;
4681 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4682 return -EINVAL;
4683 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4684 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004685 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4686 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004687 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4688 return -EINVAL;
4689
4690 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4691
4692 freq_range->start_freq_khz =
4693 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4694 freq_range->end_freq_khz =
4695 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004696 freq_range->max_bandwidth_khz =
4697 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004698
4699 power_rule->max_eirp =
4700 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4701
4702 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4703 power_rule->max_antenna_gain =
4704 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4705
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004706 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4707 reg_rule->dfs_cac_ms =
4708 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4709
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004710 return 0;
4711}
4712
4713static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4714{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004715 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004716 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004717
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004718 /*
4719 * You should only get this when cfg80211 hasn't yet initialized
4720 * completely when built-in to the kernel right between the time
4721 * window between nl80211_init() and regulatory_init(), if that is
4722 * even possible.
4723 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004724 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004725 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004726
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004727 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4728 user_reg_hint_type =
4729 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4730 else
4731 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4732
4733 switch (user_reg_hint_type) {
4734 case NL80211_USER_REG_HINT_USER:
4735 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004736 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4737 return -EINVAL;
4738
4739 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4740 return regulatory_hint_user(data, user_reg_hint_type);
4741 case NL80211_USER_REG_HINT_INDOOR:
4742 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004743 default:
4744 return -EINVAL;
4745 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004746}
4747
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004748static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004749 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004750{
Johannes Berg4c476992010-10-04 21:36:35 +02004751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004752 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004753 struct wireless_dev *wdev = dev->ieee80211_ptr;
4754 struct mesh_config cur_params;
4755 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004756 void *hdr;
4757 struct nlattr *pinfoattr;
4758 struct sk_buff *msg;
4759
Johannes Berg29cbe682010-12-03 09:20:44 +01004760 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4761 return -EOPNOTSUPP;
4762
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004763 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004764 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004765
Johannes Berg29cbe682010-12-03 09:20:44 +01004766 wdev_lock(wdev);
4767 /* If not connected, get default parameters */
4768 if (!wdev->mesh_id_len)
4769 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4770 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004771 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004772 wdev_unlock(wdev);
4773
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004774 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004775 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004776
4777 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004778 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004779 if (!msg)
4780 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004781 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004782 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004783 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004784 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004785 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004786 if (!pinfoattr)
4787 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004788 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4789 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4790 cur_params.dot11MeshRetryTimeout) ||
4791 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4792 cur_params.dot11MeshConfirmTimeout) ||
4793 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4794 cur_params.dot11MeshHoldingTimeout) ||
4795 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4796 cur_params.dot11MeshMaxPeerLinks) ||
4797 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4798 cur_params.dot11MeshMaxRetries) ||
4799 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4800 cur_params.dot11MeshTTL) ||
4801 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4802 cur_params.element_ttl) ||
4803 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4804 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004805 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4806 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004807 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4808 cur_params.dot11MeshHWMPmaxPREQretries) ||
4809 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4810 cur_params.path_refresh_time) ||
4811 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4812 cur_params.min_discovery_timeout) ||
4813 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4814 cur_params.dot11MeshHWMPactivePathTimeout) ||
4815 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4816 cur_params.dot11MeshHWMPpreqMinInterval) ||
4817 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4818 cur_params.dot11MeshHWMPperrMinInterval) ||
4819 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4820 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4821 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4822 cur_params.dot11MeshHWMPRootMode) ||
4823 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4824 cur_params.dot11MeshHWMPRannInterval) ||
4825 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4826 cur_params.dot11MeshGateAnnouncementProtocol) ||
4827 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4828 cur_params.dot11MeshForwarding) ||
4829 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004830 cur_params.rssi_threshold) ||
4831 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004832 cur_params.ht_opmode) ||
4833 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4834 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4835 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004836 cur_params.dot11MeshHWMProotInterval) ||
4837 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004838 cur_params.dot11MeshHWMPconfirmationInterval) ||
4839 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4840 cur_params.power_mode) ||
4841 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004842 cur_params.dot11MeshAwakeWindowDuration) ||
4843 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4844 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004845 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004846 nla_nest_end(msg, pinfoattr);
4847 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004848 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004849
Johannes Berg3b858752009-03-12 09:55:09 +01004850 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004851 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004852 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004853 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004854 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004855}
4856
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004857static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004858 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4859 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4860 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4861 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4862 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4863 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004864 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004865 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004866 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004867 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4868 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4869 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4870 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4871 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004872 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004873 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004874 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004875 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004876 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004877 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004878 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4879 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004880 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4881 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004882 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004883 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4884 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004885 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004886};
4887
Javier Cardonac80d5452010-12-16 17:37:49 -08004888static const struct nla_policy
4889 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004890 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004891 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4892 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004893 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004894 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004895 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004896 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004897 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004898 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004899};
4900
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004901static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004902 struct mesh_config *cfg,
4903 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004904{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004905 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004906 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004907
Marco Porschea54fba2013-01-07 16:04:48 +01004908#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4909do { \
4910 if (tb[attr]) { \
4911 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4912 return -EINVAL; \
4913 cfg->param = fn(tb[attr]); \
4914 mask |= (1 << (attr - 1)); \
4915 } \
4916} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004917
4918
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004919 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004920 return -EINVAL;
4921 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004922 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004923 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004924 return -EINVAL;
4925
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004926 /* This makes sure that there aren't more than 32 mesh config
4927 * parameters (otherwise our bitfield scheme would not work.) */
4928 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4929
4930 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004932 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4933 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004934 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004935 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4936 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004937 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004938 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4939 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004940 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004941 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4942 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004943 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004944 mask, NL80211_MESHCONF_MAX_RETRIES,
4945 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004946 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004947 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004948 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004949 mask, NL80211_MESHCONF_ELEMENT_TTL,
4950 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004951 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004952 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4953 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004954 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4955 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004956 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4957 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004958 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004959 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4960 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004961 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004962 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4963 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004965 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4966 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4968 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004969 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4970 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004971 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004972 1, 65535, mask,
4973 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004974 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004975 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004976 1, 65535, mask,
4977 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004978 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004979 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004980 dot11MeshHWMPnetDiameterTraversalTime,
4981 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004982 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4983 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004984 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4985 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4986 nla_get_u8);
4987 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4988 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004989 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004990 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004991 dot11MeshGateAnnouncementProtocol, 0, 1,
4992 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004993 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004994 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004995 mask, NL80211_MESHCONF_FORWARDING,
4996 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004997 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004998 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004999 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005000 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005001 mask, NL80211_MESHCONF_HT_OPMODE,
5002 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005003 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005004 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005005 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5006 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005007 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005008 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5009 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005010 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005011 dot11MeshHWMPconfirmationInterval,
5012 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005013 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5014 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005015 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5016 NL80211_MESH_POWER_ACTIVE,
5017 NL80211_MESH_POWER_MAX,
5018 mask, NL80211_MESHCONF_POWER_MODE,
5019 nla_get_u32);
5020 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5021 0, 65535, mask,
5022 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005023 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5024 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5025 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005026 if (mask_out)
5027 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005028
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005029 return 0;
5030
5031#undef FILL_IN_MESH_PARAM_IF_SET
5032}
5033
Javier Cardonac80d5452010-12-16 17:37:49 -08005034static int nl80211_parse_mesh_setup(struct genl_info *info,
5035 struct mesh_setup *setup)
5036{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005038 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5039
5040 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5041 return -EINVAL;
5042 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5043 info->attrs[NL80211_ATTR_MESH_SETUP],
5044 nl80211_mesh_setup_params_policy))
5045 return -EINVAL;
5046
Javier Cardonad299a1f2012-03-31 11:31:33 -07005047 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5048 setup->sync_method =
5049 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5050 IEEE80211_SYNC_METHOD_VENDOR :
5051 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5052
Javier Cardonac80d5452010-12-16 17:37:49 -08005053 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5054 setup->path_sel_proto =
5055 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5056 IEEE80211_PATH_PROTOCOL_VENDOR :
5057 IEEE80211_PATH_PROTOCOL_HWMP;
5058
5059 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5060 setup->path_metric =
5061 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5062 IEEE80211_PATH_METRIC_VENDOR :
5063 IEEE80211_PATH_METRIC_AIRTIME;
5064
Javier Cardona581a8b02011-04-07 15:08:27 -07005065
5066 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005067 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005068 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005069 if (!is_valid_ie_attr(ieattr))
5070 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005071 setup->ie = nla_data(ieattr);
5072 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005073 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005074 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5075 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5076 return -EINVAL;
5077 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005078 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5079 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005080 if (setup->is_secure)
5081 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005082
Colleen Twitty6e16d902013-05-08 11:45:59 -07005083 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5084 if (!setup->user_mpm)
5085 return -EINVAL;
5086 setup->auth_id =
5087 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5088 }
5089
Javier Cardonac80d5452010-12-16 17:37:49 -08005090 return 0;
5091}
5092
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005093static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005094 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005095{
5096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5097 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005098 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005099 struct mesh_config cfg;
5100 u32 mask;
5101 int err;
5102
Johannes Berg29cbe682010-12-03 09:20:44 +01005103 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5104 return -EOPNOTSUPP;
5105
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005106 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005107 return -EOPNOTSUPP;
5108
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005109 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005110 if (err)
5111 return err;
5112
Johannes Berg29cbe682010-12-03 09:20:44 +01005113 wdev_lock(wdev);
5114 if (!wdev->mesh_id_len)
5115 err = -ENOLINK;
5116
5117 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005118 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005119
5120 wdev_unlock(wdev);
5121
5122 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005123}
5124
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005125static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5126{
Johannes Berg458f4f92012-12-06 15:47:38 +01005127 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005128 struct sk_buff *msg;
5129 void *hdr = NULL;
5130 struct nlattr *nl_reg_rules;
5131 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005132
5133 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005134 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005135
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005136 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005137 if (!msg)
5138 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005139
Eric W. Biederman15e47302012-09-07 20:12:54 +00005140 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005141 NL80211_CMD_GET_REG);
5142 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005143 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005144
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005145 if (reg_last_request_cell_base() &&
5146 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5147 NL80211_USER_REG_HINT_CELL_BASE))
5148 goto nla_put_failure;
5149
Johannes Berg458f4f92012-12-06 15:47:38 +01005150 rcu_read_lock();
5151 regdom = rcu_dereference(cfg80211_regdomain);
5152
5153 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5154 (regdom->dfs_region &&
5155 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5156 goto nla_put_failure_rcu;
5157
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005158 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5159 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005160 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005161
Johannes Berg458f4f92012-12-06 15:47:38 +01005162 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005163 struct nlattr *nl_reg_rule;
5164 const struct ieee80211_reg_rule *reg_rule;
5165 const struct ieee80211_freq_range *freq_range;
5166 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005167 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005168
Johannes Berg458f4f92012-12-06 15:47:38 +01005169 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005170 freq_range = &reg_rule->freq_range;
5171 power_rule = &reg_rule->power_rule;
5172
5173 nl_reg_rule = nla_nest_start(msg, i);
5174 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005175 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005176
Janusz Dziedzic97524822014-01-30 09:52:20 +01005177 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5178 if (!max_bandwidth_khz)
5179 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5180 reg_rule);
5181
David S. Miller9360ffd2012-03-29 04:41:26 -04005182 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5183 reg_rule->flags) ||
5184 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5185 freq_range->start_freq_khz) ||
5186 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5187 freq_range->end_freq_khz) ||
5188 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005189 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005190 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5191 power_rule->max_antenna_gain) ||
5192 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005193 power_rule->max_eirp) ||
5194 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5195 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005196 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005197
5198 nla_nest_end(msg, nl_reg_rule);
5199 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005200 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005201
5202 nla_nest_end(msg, nl_reg_rules);
5203
5204 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005205 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005206
Johannes Berg458f4f92012-12-06 15:47:38 +01005207nla_put_failure_rcu:
5208 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005209nla_put_failure:
5210 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005211put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005212 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005213 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005214}
5215
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005216static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5217{
5218 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5219 struct nlattr *nl_reg_rule;
5220 char *alpha2 = NULL;
5221 int rem_reg_rules = 0, r = 0;
5222 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005223 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005224 struct ieee80211_regdomain *rd = NULL;
5225
5226 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5227 return -EINVAL;
5228
5229 if (!info->attrs[NL80211_ATTR_REG_RULES])
5230 return -EINVAL;
5231
5232 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5233
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005234 if (info->attrs[NL80211_ATTR_DFS_REGION])
5235 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5236
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005237 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005238 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005239 num_rules++;
5240 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005241 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005242 }
5243
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005244 if (!reg_is_valid_request(alpha2))
5245 return -EINVAL;
5246
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005247 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005248 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005249
5250 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005251 if (!rd)
5252 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005253
5254 rd->n_reg_rules = num_rules;
5255 rd->alpha2[0] = alpha2[0];
5256 rd->alpha2[1] = alpha2[1];
5257
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005258 /*
5259 * Disable DFS master mode if the DFS region was
5260 * not supported or known on this kernel.
5261 */
5262 if (reg_supported_dfs_region(dfs_region))
5263 rd->dfs_region = dfs_region;
5264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005265 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005266 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005267 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5268 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5269 reg_rule_policy);
5270 if (r)
5271 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005272 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5273 if (r)
5274 goto bad_reg;
5275
5276 rule_idx++;
5277
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005278 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5279 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005280 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005281 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005282 }
5283
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005284 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005285 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005286 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005287
Johannes Bergd2372b32008-10-24 20:32:20 +02005288 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005289 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005290 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005291}
5292
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005293static int validate_scan_freqs(struct nlattr *freqs)
5294{
5295 struct nlattr *attr1, *attr2;
5296 int n_channels = 0, tmp1, tmp2;
5297
5298 nla_for_each_nested(attr1, freqs, tmp1) {
5299 n_channels++;
5300 /*
5301 * Some hardware has a limited channel list for
5302 * scanning, and it is pretty much nonsensical
5303 * to scan for a channel twice, so disallow that
5304 * and don't require drivers to check that the
5305 * channel list they get isn't longer than what
5306 * they can scan, as long as they can scan all
5307 * the channels they registered at once.
5308 */
5309 nla_for_each_nested(attr2, freqs, tmp2)
5310 if (attr1 != attr2 &&
5311 nla_get_u32(attr1) == nla_get_u32(attr2))
5312 return 0;
5313 }
5314
5315 return n_channels;
5316}
5317
Johannes Berg2a519312009-02-10 21:25:55 +01005318static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5319{
Johannes Berg4c476992010-10-04 21:36:35 +02005320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005321 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005322 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005323 struct nlattr *attr;
5324 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005325 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005326 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005327
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005328 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5329 return -EINVAL;
5330
Johannes Berg79c97e92009-07-07 03:56:12 +02005331 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005332
Johannes Berg4c476992010-10-04 21:36:35 +02005333 if (!rdev->ops->scan)
5334 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005335
Johannes Bergf9d15d12014-01-22 11:14:19 +02005336 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005337 err = -EBUSY;
5338 goto unlock;
5339 }
Johannes Berg2a519312009-02-10 21:25:55 +01005340
5341 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005342 n_channels = validate_scan_freqs(
5343 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005344 if (!n_channels) {
5345 err = -EINVAL;
5346 goto unlock;
5347 }
Johannes Berg2a519312009-02-10 21:25:55 +01005348 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005349 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005350 }
5351
5352 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5353 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5354 n_ssids++;
5355
Johannes Bergf9f47522013-03-19 15:04:07 +01005356 if (n_ssids > wiphy->max_scan_ssids) {
5357 err = -EINVAL;
5358 goto unlock;
5359 }
Johannes Berg2a519312009-02-10 21:25:55 +01005360
Jouni Malinen70692ad2009-02-16 19:39:13 +02005361 if (info->attrs[NL80211_ATTR_IE])
5362 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5363 else
5364 ie_len = 0;
5365
Johannes Bergf9f47522013-03-19 15:04:07 +01005366 if (ie_len > wiphy->max_scan_ie_len) {
5367 err = -EINVAL;
5368 goto unlock;
5369 }
Johannes Berg18a83652009-03-31 12:12:05 +02005370
Johannes Berg2a519312009-02-10 21:25:55 +01005371 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005372 + sizeof(*request->ssids) * n_ssids
5373 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005374 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005375 if (!request) {
5376 err = -ENOMEM;
5377 goto unlock;
5378 }
Johannes Berg2a519312009-02-10 21:25:55 +01005379
Johannes Berg2a519312009-02-10 21:25:55 +01005380 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005381 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005382 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005383 if (ie_len) {
5384 if (request->ssids)
5385 request->ie = (void *)(request->ssids + n_ssids);
5386 else
5387 request->ie = (void *)(request->channels + n_channels);
5388 }
Johannes Berg2a519312009-02-10 21:25:55 +01005389
Johannes Berg584991d2009-11-02 13:32:03 +01005390 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005391 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5392 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005393 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005394 struct ieee80211_channel *chan;
5395
5396 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5397
5398 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005399 err = -EINVAL;
5400 goto out_free;
5401 }
Johannes Berg584991d2009-11-02 13:32:03 +01005402
5403 /* ignore disabled channels */
5404 if (chan->flags & IEEE80211_CHAN_DISABLED)
5405 continue;
5406
5407 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005408 i++;
5409 }
5410 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005411 enum ieee80211_band band;
5412
Johannes Berg2a519312009-02-10 21:25:55 +01005413 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005414 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5415 int j;
5416 if (!wiphy->bands[band])
5417 continue;
5418 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005419 struct ieee80211_channel *chan;
5420
5421 chan = &wiphy->bands[band]->channels[j];
5422
5423 if (chan->flags & IEEE80211_CHAN_DISABLED)
5424 continue;
5425
5426 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005427 i++;
5428 }
5429 }
5430 }
5431
Johannes Berg584991d2009-11-02 13:32:03 +01005432 if (!i) {
5433 err = -EINVAL;
5434 goto out_free;
5435 }
5436
5437 request->n_channels = i;
5438
Johannes Berg2a519312009-02-10 21:25:55 +01005439 i = 0;
5440 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5441 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005442 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005443 err = -EINVAL;
5444 goto out_free;
5445 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005446 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005447 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005448 i++;
5449 }
5450 }
5451
Jouni Malinen70692ad2009-02-16 19:39:13 +02005452 if (info->attrs[NL80211_ATTR_IE]) {
5453 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005454 memcpy((void *)request->ie,
5455 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005456 request->ie_len);
5457 }
5458
Johannes Berg34850ab2011-07-18 18:08:35 +02005459 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005460 if (wiphy->bands[i])
5461 request->rates[i] =
5462 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005463
5464 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5465 nla_for_each_nested(attr,
5466 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5467 tmp) {
5468 enum ieee80211_band band = nla_type(attr);
5469
Dan Carpenter84404622011-07-29 11:52:18 +03005470 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005471 err = -EINVAL;
5472 goto out_free;
5473 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005474
5475 if (!wiphy->bands[band])
5476 continue;
5477
Johannes Berg34850ab2011-07-18 18:08:35 +02005478 err = ieee80211_get_ratemask(wiphy->bands[band],
5479 nla_data(attr),
5480 nla_len(attr),
5481 &request->rates[band]);
5482 if (err)
5483 goto out_free;
5484 }
5485 }
5486
Sam Leffler46856bb2012-10-11 21:03:32 -07005487 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005488 request->flags = nla_get_u32(
5489 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005490 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5491 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005492 err = -EOPNOTSUPP;
5493 goto out_free;
5494 }
5495 }
Sam Lefflered4737712012-10-11 21:03:31 -07005496
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305497 request->no_cck =
5498 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5499
Johannes Bergfd014282012-06-18 19:17:03 +02005500 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005501 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005502 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005503
Johannes Berg79c97e92009-07-07 03:56:12 +02005504 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005505 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005506
Johannes Berg463d0182009-07-14 00:33:35 +02005507 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005508 nl80211_send_scan_start(rdev, wdev);
5509 if (wdev->netdev)
5510 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005511 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005512 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005513 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005514 kfree(request);
5515 }
Johannes Berg3b858752009-03-12 09:55:09 +01005516
Johannes Bergf9f47522013-03-19 15:04:07 +01005517 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005518 return err;
5519}
5520
Luciano Coelho807f8a82011-05-11 17:09:35 +03005521static int nl80211_start_sched_scan(struct sk_buff *skb,
5522 struct genl_info *info)
5523{
5524 struct cfg80211_sched_scan_request *request;
5525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5526 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005527 struct nlattr *attr;
5528 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005529 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005530 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005531 enum ieee80211_band band;
5532 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005533 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005534 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005535
5536 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5537 !rdev->ops->sched_scan_start)
5538 return -EOPNOTSUPP;
5539
5540 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5541 return -EINVAL;
5542
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005543 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5544 return -EINVAL;
5545
5546 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5547 if (interval == 0)
5548 return -EINVAL;
5549
Luciano Coelho807f8a82011-05-11 17:09:35 +03005550 wiphy = &rdev->wiphy;
5551
5552 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5553 n_channels = validate_scan_freqs(
5554 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5555 if (!n_channels)
5556 return -EINVAL;
5557 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005558 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005559 }
5560
5561 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5562 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5563 tmp)
5564 n_ssids++;
5565
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005566 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005567 return -EINVAL;
5568
Johannes Bergea73cbc2014-01-24 10:53:53 +01005569 /*
5570 * First, count the number of 'real' matchsets. Due to an issue with
5571 * the old implementation, matchsets containing only the RSSI attribute
5572 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5573 * RSSI for all matchsets, rather than their own matchset for reporting
5574 * all APs with a strong RSSI. This is needed to be compatible with
5575 * older userspace that treated a matchset with only the RSSI as the
5576 * global RSSI for all other matchsets - if there are other matchsets.
5577 */
5578 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005579 nla_for_each_nested(attr,
5580 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005581 tmp) {
5582 struct nlattr *rssi;
5583
5584 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5585 nla_data(attr), nla_len(attr),
5586 nl80211_match_policy);
5587 if (err)
5588 return err;
5589 /* add other standalone attributes here */
5590 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5591 n_match_sets++;
5592 continue;
5593 }
5594 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5595 if (rssi)
5596 default_match_rssi = nla_get_s32(rssi);
5597 }
5598 }
5599
5600 /* However, if there's no other matchset, add the RSSI one */
5601 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5602 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005603
5604 if (n_match_sets > wiphy->max_match_sets)
5605 return -EINVAL;
5606
Luciano Coelho807f8a82011-05-11 17:09:35 +03005607 if (info->attrs[NL80211_ATTR_IE])
5608 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5609 else
5610 ie_len = 0;
5611
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005612 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005613 return -EINVAL;
5614
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005615 if (rdev->sched_scan_req) {
5616 err = -EINPROGRESS;
5617 goto out;
5618 }
5619
Luciano Coelho807f8a82011-05-11 17:09:35 +03005620 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005621 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005622 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005623 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005624 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005625 if (!request) {
5626 err = -ENOMEM;
5627 goto out;
5628 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005629
5630 if (n_ssids)
5631 request->ssids = (void *)&request->channels[n_channels];
5632 request->n_ssids = n_ssids;
5633 if (ie_len) {
5634 if (request->ssids)
5635 request->ie = (void *)(request->ssids + n_ssids);
5636 else
5637 request->ie = (void *)(request->channels + n_channels);
5638 }
5639
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005640 if (n_match_sets) {
5641 if (request->ie)
5642 request->match_sets = (void *)(request->ie + ie_len);
5643 else if (request->ssids)
5644 request->match_sets =
5645 (void *)(request->ssids + n_ssids);
5646 else
5647 request->match_sets =
5648 (void *)(request->channels + n_channels);
5649 }
5650 request->n_match_sets = n_match_sets;
5651
Luciano Coelho807f8a82011-05-11 17:09:35 +03005652 i = 0;
5653 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5654 /* user specified, bail out if channel not found */
5655 nla_for_each_nested(attr,
5656 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5657 tmp) {
5658 struct ieee80211_channel *chan;
5659
5660 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5661
5662 if (!chan) {
5663 err = -EINVAL;
5664 goto out_free;
5665 }
5666
5667 /* ignore disabled channels */
5668 if (chan->flags & IEEE80211_CHAN_DISABLED)
5669 continue;
5670
5671 request->channels[i] = chan;
5672 i++;
5673 }
5674 } else {
5675 /* all channels */
5676 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5677 int j;
5678 if (!wiphy->bands[band])
5679 continue;
5680 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5681 struct ieee80211_channel *chan;
5682
5683 chan = &wiphy->bands[band]->channels[j];
5684
5685 if (chan->flags & IEEE80211_CHAN_DISABLED)
5686 continue;
5687
5688 request->channels[i] = chan;
5689 i++;
5690 }
5691 }
5692 }
5693
5694 if (!i) {
5695 err = -EINVAL;
5696 goto out_free;
5697 }
5698
5699 request->n_channels = i;
5700
5701 i = 0;
5702 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5703 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5704 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005705 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005706 err = -EINVAL;
5707 goto out_free;
5708 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005709 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005710 memcpy(request->ssids[i].ssid, nla_data(attr),
5711 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005712 i++;
5713 }
5714 }
5715
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005716 i = 0;
5717 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5718 nla_for_each_nested(attr,
5719 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5720 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005721 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005722
Johannes Bergae811e22014-01-24 10:17:47 +01005723 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5724 nla_data(attr), nla_len(attr),
5725 nl80211_match_policy);
5726 if (err)
5727 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005728 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005729 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005730 if (WARN_ON(i >= n_match_sets)) {
5731 /* this indicates a programming error,
5732 * the loop above should have verified
5733 * things properly
5734 */
5735 err = -EINVAL;
5736 goto out_free;
5737 }
5738
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005739 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5740 err = -EINVAL;
5741 goto out_free;
5742 }
5743 memcpy(request->match_sets[i].ssid.ssid,
5744 nla_data(ssid), nla_len(ssid));
5745 request->match_sets[i].ssid.ssid_len =
5746 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005747 /* special attribute - old implemenation w/a */
5748 request->match_sets[i].rssi_thold =
5749 default_match_rssi;
5750 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5751 if (rssi)
5752 request->match_sets[i].rssi_thold =
5753 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005754 }
5755 i++;
5756 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005757
5758 /* there was no other matchset, so the RSSI one is alone */
5759 if (i == 0)
5760 request->match_sets[0].rssi_thold = default_match_rssi;
5761
5762 request->min_rssi_thold = INT_MAX;
5763 for (i = 0; i < n_match_sets; i++)
5764 request->min_rssi_thold =
5765 min(request->match_sets[i].rssi_thold,
5766 request->min_rssi_thold);
5767 } else {
5768 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005769 }
5770
Johannes Berg9900e482014-02-04 21:01:25 +01005771 if (ie_len) {
5772 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005773 memcpy((void *)request->ie,
5774 nla_data(info->attrs[NL80211_ATTR_IE]),
5775 request->ie_len);
5776 }
5777
Sam Leffler46856bb2012-10-11 21:03:32 -07005778 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005779 request->flags = nla_get_u32(
5780 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005781 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5782 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005783 err = -EOPNOTSUPP;
5784 goto out_free;
5785 }
5786 }
Sam Lefflered4737712012-10-11 21:03:31 -07005787
Luciano Coelho807f8a82011-05-11 17:09:35 +03005788 request->dev = dev;
5789 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005790 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005791 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005792
Hila Gonene35e4d22012-06-27 17:19:42 +03005793 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005794 if (!err) {
5795 rdev->sched_scan_req = request;
5796 nl80211_send_sched_scan(rdev, dev,
5797 NL80211_CMD_START_SCHED_SCAN);
5798 goto out;
5799 }
5800
5801out_free:
5802 kfree(request);
5803out:
5804 return err;
5805}
5806
5807static int nl80211_stop_sched_scan(struct sk_buff *skb,
5808 struct genl_info *info)
5809{
5810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5811
5812 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5813 !rdev->ops->sched_scan_stop)
5814 return -EOPNOTSUPP;
5815
Johannes Berg5fe231e2013-05-08 21:45:15 +02005816 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005817}
5818
Simon Wunderlich04f39042013-02-08 18:16:19 +01005819static int nl80211_start_radar_detection(struct sk_buff *skb,
5820 struct genl_info *info)
5821{
5822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5823 struct net_device *dev = info->user_ptr[1];
5824 struct wireless_dev *wdev = dev->ieee80211_ptr;
5825 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005826 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005827 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005828 int err;
5829
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005830 dfs_region = reg_get_dfs_region(wdev->wiphy);
5831 if (dfs_region == NL80211_DFS_UNSET)
5832 return -EINVAL;
5833
Simon Wunderlich04f39042013-02-08 18:16:19 +01005834 err = nl80211_parse_chandef(rdev, info, &chandef);
5835 if (err)
5836 return err;
5837
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005838 if (netif_carrier_ok(dev))
5839 return -EBUSY;
5840
Simon Wunderlich04f39042013-02-08 18:16:19 +01005841 if (wdev->cac_started)
5842 return -EBUSY;
5843
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02005844 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03005845 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005846 if (err < 0)
5847 return err;
5848
5849 if (err == 0)
5850 return -EINVAL;
5851
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005852 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005853 return -EINVAL;
5854
5855 if (!rdev->ops->start_radar_detection)
5856 return -EOPNOTSUPP;
5857
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005858 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5859 if (WARN_ON(!cac_time_ms))
5860 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5861
5862 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5863 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005864 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005865 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005866 wdev->cac_started = true;
5867 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005868 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005869 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005870 return err;
5871}
5872
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005873static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5874{
5875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5876 struct net_device *dev = info->user_ptr[1];
5877 struct wireless_dev *wdev = dev->ieee80211_ptr;
5878 struct cfg80211_csa_settings params;
5879 /* csa_attrs is defined static to avoid waste of stack size - this
5880 * function is called under RTNL lock, so this should not be a problem.
5881 */
5882 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5883 u8 radar_detect_width = 0;
5884 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005885 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005886 int len, i;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005887
5888 if (!rdev->ops->channel_switch ||
5889 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5890 return -EOPNOTSUPP;
5891
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005892 switch (dev->ieee80211_ptr->iftype) {
5893 case NL80211_IFTYPE_AP:
5894 case NL80211_IFTYPE_P2P_GO:
5895 need_new_beacon = true;
5896
5897 /* useless if AP is not running */
5898 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005899 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005900 break;
5901 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005902 if (!wdev->ssid_len)
5903 return -ENOTCONN;
5904 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005905 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005906 if (!wdev->mesh_id_len)
5907 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005908 break;
5909 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005910 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005911 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005912
5913 memset(&params, 0, sizeof(params));
5914
5915 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5916 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5917 return -EINVAL;
5918
5919 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005920 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005921 return -EINVAL;
5922
5923 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5924
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005925 if (!need_new_beacon)
5926 goto skip_beacons;
5927
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005928 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5929 if (err)
5930 return err;
5931
5932 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5933 info->attrs[NL80211_ATTR_CSA_IES],
5934 nl80211_policy);
5935 if (err)
5936 return err;
5937
5938 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5939 if (err)
5940 return err;
5941
5942 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5943 return -EINVAL;
5944
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005945 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5946 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005947 return -EINVAL;
5948
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005949 params.n_counter_offsets_beacon = len / sizeof(u16);
5950 if (rdev->wiphy.max_num_csa_counters &&
5951 (params.n_counter_offsets_beacon >
5952 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005953 return -EINVAL;
5954
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005955 params.counter_offsets_beacon =
5956 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5957
5958 /* sanity checks - counters should fit and be the same */
5959 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
5960 u16 offset = params.counter_offsets_beacon[i];
5961
5962 if (offset >= params.beacon_csa.tail_len)
5963 return -EINVAL;
5964
5965 if (params.beacon_csa.tail[offset] != params.count)
5966 return -EINVAL;
5967 }
5968
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005969 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005970 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5971 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005972 return -EINVAL;
5973
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005974 params.n_counter_offsets_presp = len / sizeof(u16);
5975 if (rdev->wiphy.max_num_csa_counters &&
5976 (params.n_counter_offsets_beacon >
5977 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005978 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005979
5980 params.counter_offsets_presp =
5981 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5982
5983 /* sanity checks - counters should fit and be the same */
5984 for (i = 0; i < params.n_counter_offsets_presp; i++) {
5985 u16 offset = params.counter_offsets_presp[i];
5986
5987 if (offset >= params.beacon_csa.probe_resp_len)
5988 return -EINVAL;
5989
5990 if (params.beacon_csa.probe_resp[offset] !=
5991 params.count)
5992 return -EINVAL;
5993 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005994 }
5995
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005996skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005997 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5998 if (err)
5999 return err;
6000
Ilan Peer174e0cd2014-02-23 09:13:01 +02006001 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6002 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006003 return -EINVAL;
6004
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006005 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6006 &params.chandef,
6007 wdev->iftype);
6008 if (err < 0)
6009 return err;
6010
6011 if (err > 0) {
6012 radar_detect_width = BIT(params.chandef.width);
6013 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006014 }
6015
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006016 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6017 params.block_tx = true;
6018
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006019 wdev_lock(wdev);
6020 err = rdev_channel_switch(rdev, dev, &params);
6021 wdev_unlock(wdev);
6022
6023 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006024}
6025
Johannes Berg9720bb32011-06-21 09:45:33 +02006026static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6027 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006028 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006029 struct wireless_dev *wdev,
6030 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006031{
Johannes Berg48ab9052009-07-10 18:42:31 +02006032 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006033 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006034 void *hdr;
6035 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006036 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02006037
6038 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006039
Eric W. Biederman15e47302012-09-07 20:12:54 +00006040 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006041 NL80211_CMD_NEW_SCAN_RESULTS);
6042 if (!hdr)
6043 return -1;
6044
Johannes Berg9720bb32011-06-21 09:45:33 +02006045 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6046
Johannes Berg97990a02013-04-19 01:02:55 +02006047 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6048 goto nla_put_failure;
6049 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006050 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6051 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006052 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6053 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006054
6055 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6056 if (!bss)
6057 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006058 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006059 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006060 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006061
6062 rcu_read_lock();
6063 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006064 if (ies) {
6065 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6066 goto fail_unlock_rcu;
6067 tsf = true;
6068 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6069 ies->len, ies->data))
6070 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006071 }
6072 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006073 if (ies) {
6074 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6075 goto fail_unlock_rcu;
6076 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6077 ies->len, ies->data))
6078 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006079 }
6080 rcu_read_unlock();
6081
David S. Miller9360ffd2012-03-29 04:41:26 -04006082 if (res->beacon_interval &&
6083 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6084 goto nla_put_failure;
6085 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6086 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006087 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006088 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6089 jiffies_to_msecs(jiffies - intbss->ts)))
6090 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006091
Johannes Berg77965c92009-02-18 18:45:06 +01006092 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006093 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006094 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6095 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006096 break;
6097 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006098 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6099 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006100 break;
6101 default:
6102 break;
6103 }
6104
Johannes Berg48ab9052009-07-10 18:42:31 +02006105 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006106 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006107 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006108 if (intbss == wdev->current_bss &&
6109 nla_put_u32(msg, NL80211_BSS_STATUS,
6110 NL80211_BSS_STATUS_ASSOCIATED))
6111 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006112 break;
6113 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006114 if (intbss == wdev->current_bss &&
6115 nla_put_u32(msg, NL80211_BSS_STATUS,
6116 NL80211_BSS_STATUS_IBSS_JOINED))
6117 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006118 break;
6119 default:
6120 break;
6121 }
6122
Johannes Berg2a519312009-02-10 21:25:55 +01006123 nla_nest_end(msg, bss);
6124
6125 return genlmsg_end(msg, hdr);
6126
Johannes Berg8cef2c92013-02-05 16:54:31 +01006127 fail_unlock_rcu:
6128 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006129 nla_put_failure:
6130 genlmsg_cancel(msg, hdr);
6131 return -EMSGSIZE;
6132}
6133
Johannes Berg97990a02013-04-19 01:02:55 +02006134static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006135{
Johannes Berg48ab9052009-07-10 18:42:31 +02006136 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006137 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006138 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006139 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006140 int err;
6141
Johannes Berg97990a02013-04-19 01:02:55 +02006142 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006143 if (err)
6144 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006145
Johannes Berg48ab9052009-07-10 18:42:31 +02006146 wdev_lock(wdev);
6147 spin_lock_bh(&rdev->bss_lock);
6148 cfg80211_bss_expire(rdev);
6149
Johannes Berg9720bb32011-06-21 09:45:33 +02006150 cb->seq = rdev->bss_generation;
6151
Johannes Berg48ab9052009-07-10 18:42:31 +02006152 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006153 if (++idx <= start)
6154 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006155 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006156 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006157 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006158 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006159 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006160 }
6161 }
6162
Johannes Berg48ab9052009-07-10 18:42:31 +02006163 spin_unlock_bh(&rdev->bss_lock);
6164 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006165
Johannes Berg97990a02013-04-19 01:02:55 +02006166 cb->args[2] = idx;
6167 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006168
Johannes Berg67748892010-10-04 21:14:06 +02006169 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006170}
6171
Eric W. Biederman15e47302012-09-07 20:12:54 +00006172static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006173 int flags, struct net_device *dev,
6174 struct survey_info *survey)
6175{
6176 void *hdr;
6177 struct nlattr *infoattr;
6178
Eric W. Biederman15e47302012-09-07 20:12:54 +00006179 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006180 NL80211_CMD_NEW_SURVEY_RESULTS);
6181 if (!hdr)
6182 return -ENOMEM;
6183
David S. Miller9360ffd2012-03-29 04:41:26 -04006184 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6185 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006186
6187 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6188 if (!infoattr)
6189 goto nla_put_failure;
6190
David S. Miller9360ffd2012-03-29 04:41:26 -04006191 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6192 survey->channel->center_freq))
6193 goto nla_put_failure;
6194
6195 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6196 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6197 goto nla_put_failure;
6198 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6199 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6200 goto nla_put_failure;
6201 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6202 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6203 survey->channel_time))
6204 goto nla_put_failure;
6205 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6206 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6207 survey->channel_time_busy))
6208 goto nla_put_failure;
6209 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6210 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6211 survey->channel_time_ext_busy))
6212 goto nla_put_failure;
6213 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6214 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6215 survey->channel_time_rx))
6216 goto nla_put_failure;
6217 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6218 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6219 survey->channel_time_tx))
6220 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006221
6222 nla_nest_end(msg, infoattr);
6223
6224 return genlmsg_end(msg, hdr);
6225
6226 nla_put_failure:
6227 genlmsg_cancel(msg, hdr);
6228 return -EMSGSIZE;
6229}
6230
6231static int nl80211_dump_survey(struct sk_buff *skb,
6232 struct netlink_callback *cb)
6233{
6234 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006235 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006236 struct wireless_dev *wdev;
6237 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006238 int res;
6239
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006240 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006241 if (res)
6242 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006243
Johannes Berg97990a02013-04-19 01:02:55 +02006244 if (!wdev->netdev) {
6245 res = -EINVAL;
6246 goto out_err;
6247 }
6248
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006249 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006250 res = -EOPNOTSUPP;
6251 goto out_err;
6252 }
6253
6254 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006255 struct ieee80211_channel *chan;
6256
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006257 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006258 if (res == -ENOENT)
6259 break;
6260 if (res)
6261 goto out_err;
6262
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006263 /* Survey without a channel doesn't make sense */
6264 if (!survey.channel) {
6265 res = -EINVAL;
6266 goto out;
6267 }
6268
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006269 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006270 survey.channel->center_freq);
6271 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6272 survey_idx++;
6273 continue;
6274 }
6275
Holger Schurig61fa7132009-11-11 12:25:40 +01006276 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006277 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006278 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006279 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006280 goto out;
6281 survey_idx++;
6282 }
6283
6284 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006285 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006286 res = skb->len;
6287 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006288 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006289 return res;
6290}
6291
Samuel Ortizb23aa672009-07-01 21:26:54 +02006292static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6293{
6294 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6295 NL80211_WPA_VERSION_2));
6296}
6297
Jouni Malinen636a5d32009-03-19 13:39:22 +02006298static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6299{
Johannes Berg4c476992010-10-04 21:36:35 +02006300 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6301 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006302 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006303 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6304 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006305 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006306 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006307 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006308
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006309 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6310 return -EINVAL;
6311
6312 if (!info->attrs[NL80211_ATTR_MAC])
6313 return -EINVAL;
6314
Jouni Malinen17780922009-03-27 20:52:47 +02006315 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6316 return -EINVAL;
6317
Johannes Berg19957bb2009-07-02 17:20:43 +02006318 if (!info->attrs[NL80211_ATTR_SSID])
6319 return -EINVAL;
6320
6321 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6322 return -EINVAL;
6323
Johannes Bergfffd0932009-07-08 14:22:54 +02006324 err = nl80211_parse_key(info, &key);
6325 if (err)
6326 return err;
6327
6328 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006329 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6330 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006331 if (!key.p.key || !key.p.key_len)
6332 return -EINVAL;
6333 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6334 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6335 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6336 key.p.key_len != WLAN_KEY_LEN_WEP104))
6337 return -EINVAL;
6338 if (key.idx > 4)
6339 return -EINVAL;
6340 } else {
6341 key.p.key_len = 0;
6342 key.p.key = NULL;
6343 }
6344
Johannes Bergafea0b72010-08-10 09:46:42 +02006345 if (key.idx >= 0) {
6346 int i;
6347 bool ok = false;
6348 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6349 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6350 ok = true;
6351 break;
6352 }
6353 }
Johannes Berg4c476992010-10-04 21:36:35 +02006354 if (!ok)
6355 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006356 }
6357
Johannes Berg4c476992010-10-04 21:36:35 +02006358 if (!rdev->ops->auth)
6359 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006360
Johannes Berg074ac8d2010-09-16 14:58:22 +02006361 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006362 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6363 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006364
Johannes Berg19957bb2009-07-02 17:20:43 +02006365 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006366 chan = nl80211_get_valid_chan(&rdev->wiphy,
6367 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6368 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006369 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006370
Johannes Berg19957bb2009-07-02 17:20:43 +02006371 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6372 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6373
6374 if (info->attrs[NL80211_ATTR_IE]) {
6375 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6376 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6377 }
6378
6379 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006380 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006381 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006382
Jouni Malinene39e5b52012-09-30 19:29:39 +03006383 if (auth_type == NL80211_AUTHTYPE_SAE &&
6384 !info->attrs[NL80211_ATTR_SAE_DATA])
6385 return -EINVAL;
6386
6387 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6388 if (auth_type != NL80211_AUTHTYPE_SAE)
6389 return -EINVAL;
6390 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6391 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6392 /* need to include at least Auth Transaction and Status Code */
6393 if (sae_data_len < 4)
6394 return -EINVAL;
6395 }
6396
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006397 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6398
Johannes Berg95de8172012-01-20 13:55:25 +01006399 /*
6400 * Since we no longer track auth state, ignore
6401 * requests to only change local state.
6402 */
6403 if (local_state_change)
6404 return 0;
6405
Johannes Berg91bf9b22013-05-15 17:44:01 +02006406 wdev_lock(dev->ieee80211_ptr);
6407 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6408 ssid, ssid_len, ie, ie_len,
6409 key.p.key, key.p.key_len, key.idx,
6410 sae_data, sae_data_len);
6411 wdev_unlock(dev->ieee80211_ptr);
6412 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006413}
6414
Johannes Bergc0692b82010-08-27 14:26:53 +03006415static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6416 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006417 struct cfg80211_crypto_settings *settings,
6418 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006419{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006420 memset(settings, 0, sizeof(*settings));
6421
Samuel Ortizb23aa672009-07-01 21:26:54 +02006422 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6423
Johannes Bergc0692b82010-08-27 14:26:53 +03006424 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6425 u16 proto;
6426 proto = nla_get_u16(
6427 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6428 settings->control_port_ethertype = cpu_to_be16(proto);
6429 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6430 proto != ETH_P_PAE)
6431 return -EINVAL;
6432 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6433 settings->control_port_no_encrypt = true;
6434 } else
6435 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6436
Samuel Ortizb23aa672009-07-01 21:26:54 +02006437 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6438 void *data;
6439 int len, i;
6440
6441 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6442 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6443 settings->n_ciphers_pairwise = len / sizeof(u32);
6444
6445 if (len % sizeof(u32))
6446 return -EINVAL;
6447
Johannes Berg3dc27d22009-07-02 21:36:37 +02006448 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006449 return -EINVAL;
6450
6451 memcpy(settings->ciphers_pairwise, data, len);
6452
6453 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006454 if (!cfg80211_supported_cipher_suite(
6455 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006456 settings->ciphers_pairwise[i]))
6457 return -EINVAL;
6458 }
6459
6460 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6461 settings->cipher_group =
6462 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006463 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6464 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006465 return -EINVAL;
6466 }
6467
6468 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6469 settings->wpa_versions =
6470 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6471 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6472 return -EINVAL;
6473 }
6474
6475 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6476 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006477 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006478
6479 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6480 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6481 settings->n_akm_suites = len / sizeof(u32);
6482
6483 if (len % sizeof(u32))
6484 return -EINVAL;
6485
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006486 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6487 return -EINVAL;
6488
Samuel Ortizb23aa672009-07-01 21:26:54 +02006489 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006490 }
6491
6492 return 0;
6493}
6494
Jouni Malinen636a5d32009-03-19 13:39:22 +02006495static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6496{
Johannes Berg4c476992010-10-04 21:36:35 +02006497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6498 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006499 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006500 struct cfg80211_assoc_request req = {};
6501 const u8 *bssid, *ssid;
6502 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006503
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006504 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6505 return -EINVAL;
6506
6507 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006508 !info->attrs[NL80211_ATTR_SSID] ||
6509 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006510 return -EINVAL;
6511
Johannes Berg4c476992010-10-04 21:36:35 +02006512 if (!rdev->ops->assoc)
6513 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006514
Johannes Berg074ac8d2010-09-16 14:58:22 +02006515 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006516 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6517 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006518
Johannes Berg19957bb2009-07-02 17:20:43 +02006519 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006520
Jouni Malinen664834d2014-01-15 00:01:44 +02006521 chan = nl80211_get_valid_chan(&rdev->wiphy,
6522 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6523 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006524 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006525
Johannes Berg19957bb2009-07-02 17:20:43 +02006526 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6527 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006528
6529 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006530 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6531 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006532 }
6533
Jouni Malinendc6382c2009-05-06 22:09:37 +03006534 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006535 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006536 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006537 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006538 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006539 else if (mfp != NL80211_MFP_NO)
6540 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006541 }
6542
Johannes Berg3e5d7642009-07-07 14:37:26 +02006543 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006544 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006545
Ben Greear7e7c8922011-11-18 11:31:59 -08006546 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006547 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006548
6549 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006550 memcpy(&req.ht_capa_mask,
6551 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6552 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006553
6554 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006555 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006556 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006557 memcpy(&req.ht_capa,
6558 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6559 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006560 }
6561
Johannes Bergee2aca32013-02-21 17:36:01 +01006562 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006563 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006564
6565 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006566 memcpy(&req.vht_capa_mask,
6567 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6568 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006569
6570 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006571 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006572 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006573 memcpy(&req.vht_capa,
6574 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6575 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006576 }
6577
Johannes Bergf62fab72013-02-21 20:09:09 +01006578 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006579 if (!err) {
6580 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006581 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6582 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006583 wdev_unlock(dev->ieee80211_ptr);
6584 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006585
Jouni Malinen636a5d32009-03-19 13:39:22 +02006586 return err;
6587}
6588
6589static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6590{
Johannes Berg4c476992010-10-04 21:36:35 +02006591 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6592 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006593 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006594 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006595 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006596 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006597
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006598 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6599 return -EINVAL;
6600
6601 if (!info->attrs[NL80211_ATTR_MAC])
6602 return -EINVAL;
6603
6604 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6605 return -EINVAL;
6606
Johannes Berg4c476992010-10-04 21:36:35 +02006607 if (!rdev->ops->deauth)
6608 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006609
Johannes Berg074ac8d2010-09-16 14:58:22 +02006610 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006611 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6612 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006613
Johannes Berg19957bb2009-07-02 17:20:43 +02006614 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006615
Johannes Berg19957bb2009-07-02 17:20:43 +02006616 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6617 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006618 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006619 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006620 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006621
6622 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006623 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6624 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006625 }
6626
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006627 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6628
Johannes Berg91bf9b22013-05-15 17:44:01 +02006629 wdev_lock(dev->ieee80211_ptr);
6630 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6631 local_state_change);
6632 wdev_unlock(dev->ieee80211_ptr);
6633 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006634}
6635
6636static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6637{
Johannes Berg4c476992010-10-04 21:36:35 +02006638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6639 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006640 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006641 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006642 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006643 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006644
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006645 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6646 return -EINVAL;
6647
6648 if (!info->attrs[NL80211_ATTR_MAC])
6649 return -EINVAL;
6650
6651 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6652 return -EINVAL;
6653
Johannes Berg4c476992010-10-04 21:36:35 +02006654 if (!rdev->ops->disassoc)
6655 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006656
Johannes Berg074ac8d2010-09-16 14:58:22 +02006657 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006658 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6659 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006660
Johannes Berg19957bb2009-07-02 17:20:43 +02006661 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006662
Johannes Berg19957bb2009-07-02 17:20:43 +02006663 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6664 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006665 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006666 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006667 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006668
6669 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006670 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6671 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006672 }
6673
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006674 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6675
Johannes Berg91bf9b22013-05-15 17:44:01 +02006676 wdev_lock(dev->ieee80211_ptr);
6677 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6678 local_state_change);
6679 wdev_unlock(dev->ieee80211_ptr);
6680 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006681}
6682
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006683static bool
6684nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6685 int mcast_rate[IEEE80211_NUM_BANDS],
6686 int rateval)
6687{
6688 struct wiphy *wiphy = &rdev->wiphy;
6689 bool found = false;
6690 int band, i;
6691
6692 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6693 struct ieee80211_supported_band *sband;
6694
6695 sband = wiphy->bands[band];
6696 if (!sband)
6697 continue;
6698
6699 for (i = 0; i < sband->n_bitrates; i++) {
6700 if (sband->bitrates[i].bitrate == rateval) {
6701 mcast_rate[band] = i + 1;
6702 found = true;
6703 break;
6704 }
6705 }
6706 }
6707
6708 return found;
6709}
6710
Johannes Berg04a773a2009-04-19 21:24:32 +02006711static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6712{
Johannes Berg4c476992010-10-04 21:36:35 +02006713 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6714 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006715 struct cfg80211_ibss_params ibss;
6716 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006717 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006718 int err;
6719
Johannes Berg8e30bc52009-04-22 17:45:38 +02006720 memset(&ibss, 0, sizeof(ibss));
6721
Johannes Berg04a773a2009-04-19 21:24:32 +02006722 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6723 return -EINVAL;
6724
Johannes Berg683b6d32012-11-08 21:25:48 +01006725 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006726 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6727 return -EINVAL;
6728
Johannes Berg8e30bc52009-04-22 17:45:38 +02006729 ibss.beacon_interval = 100;
6730
6731 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6732 ibss.beacon_interval =
6733 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6734 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6735 return -EINVAL;
6736 }
6737
Johannes Berg4c476992010-10-04 21:36:35 +02006738 if (!rdev->ops->join_ibss)
6739 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006740
Johannes Berg4c476992010-10-04 21:36:35 +02006741 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6742 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006743
Johannes Berg79c97e92009-07-07 03:56:12 +02006744 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006745
Johannes Berg39193492011-09-16 13:45:25 +02006746 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006747 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006748
6749 if (!is_valid_ether_addr(ibss.bssid))
6750 return -EINVAL;
6751 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006752 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6753 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6754
6755 if (info->attrs[NL80211_ATTR_IE]) {
6756 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6757 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6758 }
6759
Johannes Berg683b6d32012-11-08 21:25:48 +01006760 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6761 if (err)
6762 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006763
Ilan Peer174e0cd2014-02-23 09:13:01 +02006764 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6765 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006766 return -EINVAL;
6767
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006768 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006769 case NL80211_CHAN_WIDTH_5:
6770 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006771 case NL80211_CHAN_WIDTH_20_NOHT:
6772 break;
6773 case NL80211_CHAN_WIDTH_20:
6774 case NL80211_CHAN_WIDTH_40:
6775 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6776 break;
6777 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006778 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006779 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006780
Johannes Berg04a773a2009-04-19 21:24:32 +02006781 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006782 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006783
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006784 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6785 u8 *rates =
6786 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6787 int n_rates =
6788 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6789 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006790 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006791
Johannes Berg34850ab2011-07-18 18:08:35 +02006792 err = ieee80211_get_ratemask(sband, rates, n_rates,
6793 &ibss.basic_rates);
6794 if (err)
6795 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006796 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006797
Simon Wunderlich803768f2013-06-28 10:39:58 +02006798 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6799 memcpy(&ibss.ht_capa_mask,
6800 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6801 sizeof(ibss.ht_capa_mask));
6802
6803 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6804 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6805 return -EINVAL;
6806 memcpy(&ibss.ht_capa,
6807 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6808 sizeof(ibss.ht_capa));
6809 }
6810
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006811 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6812 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6813 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6814 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006815
Johannes Berg4c476992010-10-04 21:36:35 +02006816 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306817 bool no_ht = false;
6818
Johannes Berg4c476992010-10-04 21:36:35 +02006819 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306820 info->attrs[NL80211_ATTR_KEYS],
6821 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006822 if (IS_ERR(connkeys))
6823 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306824
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006825 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6826 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306827 kfree(connkeys);
6828 return -EINVAL;
6829 }
Johannes Berg4c476992010-10-04 21:36:35 +02006830 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006831
Antonio Quartulli267335d2012-01-31 20:25:47 +01006832 ibss.control_port =
6833 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6834
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006835 ibss.userspace_handles_dfs =
6836 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6837
Johannes Berg4c476992010-10-04 21:36:35 +02006838 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006839 if (err)
6840 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006841 return err;
6842}
6843
6844static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6845{
Johannes Berg4c476992010-10-04 21:36:35 +02006846 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6847 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006848
Johannes Berg4c476992010-10-04 21:36:35 +02006849 if (!rdev->ops->leave_ibss)
6850 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006851
Johannes Berg4c476992010-10-04 21:36:35 +02006852 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6853 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006854
Johannes Berg4c476992010-10-04 21:36:35 +02006855 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006856}
6857
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006858static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6859{
6860 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6861 struct net_device *dev = info->user_ptr[1];
6862 int mcast_rate[IEEE80211_NUM_BANDS];
6863 u32 nla_rate;
6864 int err;
6865
6866 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6867 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6868 return -EOPNOTSUPP;
6869
6870 if (!rdev->ops->set_mcast_rate)
6871 return -EOPNOTSUPP;
6872
6873 memset(mcast_rate, 0, sizeof(mcast_rate));
6874
6875 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6876 return -EINVAL;
6877
6878 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6879 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6880 return -EINVAL;
6881
6882 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6883
6884 return err;
6885}
6886
Johannes Bergad7e7182013-11-13 13:37:47 +01006887static struct sk_buff *
6888__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6889 int approxlen, u32 portid, u32 seq,
6890 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006891 enum nl80211_attrs attr,
6892 const struct nl80211_vendor_cmd_info *info,
6893 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006894{
6895 struct sk_buff *skb;
6896 void *hdr;
6897 struct nlattr *data;
6898
6899 skb = nlmsg_new(approxlen + 100, gfp);
6900 if (!skb)
6901 return NULL;
6902
6903 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6904 if (!hdr) {
6905 kfree_skb(skb);
6906 return NULL;
6907 }
6908
6909 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6910 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006911
6912 if (info) {
6913 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6914 info->vendor_id))
6915 goto nla_put_failure;
6916 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6917 info->subcmd))
6918 goto nla_put_failure;
6919 }
6920
Johannes Bergad7e7182013-11-13 13:37:47 +01006921 data = nla_nest_start(skb, attr);
6922
6923 ((void **)skb->cb)[0] = rdev;
6924 ((void **)skb->cb)[1] = hdr;
6925 ((void **)skb->cb)[2] = data;
6926
6927 return skb;
6928
6929 nla_put_failure:
6930 kfree_skb(skb);
6931 return NULL;
6932}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006933
Johannes Berge03ad6e2014-01-01 17:22:30 +01006934struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6935 enum nl80211_commands cmd,
6936 enum nl80211_attrs attr,
6937 int vendor_event_idx,
6938 int approxlen, gfp_t gfp)
6939{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006940 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006941 const struct nl80211_vendor_cmd_info *info;
6942
6943 switch (cmd) {
6944 case NL80211_CMD_TESTMODE:
6945 if (WARN_ON(vendor_event_idx != -1))
6946 return NULL;
6947 info = NULL;
6948 break;
6949 case NL80211_CMD_VENDOR:
6950 if (WARN_ON(vendor_event_idx < 0 ||
6951 vendor_event_idx >= wiphy->n_vendor_events))
6952 return NULL;
6953 info = &wiphy->vendor_events[vendor_event_idx];
6954 break;
6955 default:
6956 WARN_ON(1);
6957 return NULL;
6958 }
6959
6960 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6961 cmd, attr, info, gfp);
6962}
6963EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6964
6965void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6966{
6967 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6968 void *hdr = ((void **)skb->cb)[1];
6969 struct nlattr *data = ((void **)skb->cb)[2];
6970 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6971
6972 nla_nest_end(skb, data);
6973 genlmsg_end(skb, hdr);
6974
6975 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6976 mcgrp = NL80211_MCGRP_VENDOR;
6977
6978 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6979 mcgrp, gfp);
6980}
6981EXPORT_SYMBOL(__cfg80211_send_event_skb);
6982
Johannes Bergaff89a92009-07-01 21:26:51 +02006983#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006984static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6985{
Johannes Berg4c476992010-10-04 21:36:35 +02006986 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006987 struct wireless_dev *wdev =
6988 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006989 int err;
6990
David Spinadelfc73f112013-07-31 18:04:15 +03006991 if (!rdev->ops->testmode_cmd)
6992 return -EOPNOTSUPP;
6993
6994 if (IS_ERR(wdev)) {
6995 err = PTR_ERR(wdev);
6996 if (err != -EINVAL)
6997 return err;
6998 wdev = NULL;
6999 } else if (wdev->wiphy != &rdev->wiphy) {
7000 return -EINVAL;
7001 }
7002
Johannes Bergaff89a92009-07-01 21:26:51 +02007003 if (!info->attrs[NL80211_ATTR_TESTDATA])
7004 return -EINVAL;
7005
Johannes Bergad7e7182013-11-13 13:37:47 +01007006 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007007 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007008 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7009 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007010 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007011
Johannes Bergaff89a92009-07-01 21:26:51 +02007012 return err;
7013}
7014
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007015static int nl80211_testmode_dump(struct sk_buff *skb,
7016 struct netlink_callback *cb)
7017{
Johannes Berg00918d32011-12-13 17:22:05 +01007018 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007019 int err;
7020 long phy_idx;
7021 void *data = NULL;
7022 int data_len = 0;
7023
Johannes Berg5fe231e2013-05-08 21:45:15 +02007024 rtnl_lock();
7025
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007026 if (cb->args[0]) {
7027 /*
7028 * 0 is a valid index, but not valid for args[0],
7029 * so we need to offset by 1.
7030 */
7031 phy_idx = cb->args[0] - 1;
7032 } else {
7033 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7034 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7035 nl80211_policy);
7036 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007037 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007038
Johannes Berg2bd7e352012-06-15 14:23:16 +02007039 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7040 nl80211_fam.attrbuf);
7041 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007042 err = PTR_ERR(rdev);
7043 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007044 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007045 phy_idx = rdev->wiphy_idx;
7046 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007047
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007048 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7049 cb->args[1] =
7050 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7051 }
7052
7053 if (cb->args[1]) {
7054 data = nla_data((void *)cb->args[1]);
7055 data_len = nla_len((void *)cb->args[1]);
7056 }
7057
Johannes Berg00918d32011-12-13 17:22:05 +01007058 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7059 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007060 err = -ENOENT;
7061 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007062 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007063
Johannes Berg00918d32011-12-13 17:22:05 +01007064 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007065 err = -EOPNOTSUPP;
7066 goto out_err;
7067 }
7068
7069 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007070 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007071 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7072 NL80211_CMD_TESTMODE);
7073 struct nlattr *tmdata;
7074
Dan Carpentercb35fba2013-08-14 14:50:01 +03007075 if (!hdr)
7076 break;
7077
David S. Miller9360ffd2012-03-29 04:41:26 -04007078 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007079 genlmsg_cancel(skb, hdr);
7080 break;
7081 }
7082
7083 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7084 if (!tmdata) {
7085 genlmsg_cancel(skb, hdr);
7086 break;
7087 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007088 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007089 nla_nest_end(skb, tmdata);
7090
7091 if (err == -ENOBUFS || err == -ENOENT) {
7092 genlmsg_cancel(skb, hdr);
7093 break;
7094 } else if (err) {
7095 genlmsg_cancel(skb, hdr);
7096 goto out_err;
7097 }
7098
7099 genlmsg_end(skb, hdr);
7100 }
7101
7102 err = skb->len;
7103 /* see above */
7104 cb->args[0] = phy_idx + 1;
7105 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007106 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007107 return err;
7108}
Johannes Bergaff89a92009-07-01 21:26:51 +02007109#endif
7110
Samuel Ortizb23aa672009-07-01 21:26:54 +02007111static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7112{
Johannes Berg4c476992010-10-04 21:36:35 +02007113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7114 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007115 struct cfg80211_connect_params connect;
7116 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007117 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007118 int err;
7119
7120 memset(&connect, 0, sizeof(connect));
7121
7122 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7123 return -EINVAL;
7124
7125 if (!info->attrs[NL80211_ATTR_SSID] ||
7126 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7127 return -EINVAL;
7128
7129 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7130 connect.auth_type =
7131 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007132 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7133 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007134 return -EINVAL;
7135 } else
7136 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7137
7138 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7139
Johannes Bergc0692b82010-08-27 14:26:53 +03007140 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007141 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007142 if (err)
7143 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007144
Johannes Berg074ac8d2010-09-16 14:58:22 +02007145 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007146 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7147 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007148
Johannes Berg79c97e92009-07-07 03:56:12 +02007149 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007150
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307151 connect.bg_scan_period = -1;
7152 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7153 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7154 connect.bg_scan_period =
7155 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7156 }
7157
Samuel Ortizb23aa672009-07-01 21:26:54 +02007158 if (info->attrs[NL80211_ATTR_MAC])
7159 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007160 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7161 connect.bssid_hint =
7162 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007163 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7164 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7165
7166 if (info->attrs[NL80211_ATTR_IE]) {
7167 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7168 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7169 }
7170
Jouni Malinencee00a92013-01-15 17:15:57 +02007171 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7172 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7173 if (connect.mfp != NL80211_MFP_REQUIRED &&
7174 connect.mfp != NL80211_MFP_NO)
7175 return -EINVAL;
7176 } else {
7177 connect.mfp = NL80211_MFP_NO;
7178 }
7179
Samuel Ortizb23aa672009-07-01 21:26:54 +02007180 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007181 connect.channel = nl80211_get_valid_chan(
7182 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7183 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007184 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007185 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007186 connect.channel_hint = nl80211_get_valid_chan(
7187 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7188 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007189 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007190 }
7191
Johannes Bergfffd0932009-07-08 14:22:54 +02007192 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7193 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307194 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007195 if (IS_ERR(connkeys))
7196 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007197 }
7198
Ben Greear7e7c8922011-11-18 11:31:59 -08007199 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7200 connect.flags |= ASSOC_REQ_DISABLE_HT;
7201
7202 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7203 memcpy(&connect.ht_capa_mask,
7204 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7205 sizeof(connect.ht_capa_mask));
7206
7207 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007208 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7209 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007210 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007211 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007212 memcpy(&connect.ht_capa,
7213 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7214 sizeof(connect.ht_capa));
7215 }
7216
Johannes Bergee2aca32013-02-21 17:36:01 +01007217 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7218 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7219
7220 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7221 memcpy(&connect.vht_capa_mask,
7222 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7223 sizeof(connect.vht_capa_mask));
7224
7225 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7226 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7227 kfree(connkeys);
7228 return -EINVAL;
7229 }
7230 memcpy(&connect.vht_capa,
7231 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7232 sizeof(connect.vht_capa));
7233 }
7234
Johannes Berg83739b02013-05-15 17:44:01 +02007235 wdev_lock(dev->ieee80211_ptr);
7236 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7237 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007238 if (err)
7239 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007240 return err;
7241}
7242
7243static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7244{
Johannes Berg4c476992010-10-04 21:36:35 +02007245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7246 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007247 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007248 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007249
7250 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7251 reason = WLAN_REASON_DEAUTH_LEAVING;
7252 else
7253 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7254
7255 if (reason == 0)
7256 return -EINVAL;
7257
Johannes Berg074ac8d2010-09-16 14:58:22 +02007258 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007259 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7260 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007261
Johannes Berg83739b02013-05-15 17:44:01 +02007262 wdev_lock(dev->ieee80211_ptr);
7263 ret = cfg80211_disconnect(rdev, dev, reason, true);
7264 wdev_unlock(dev->ieee80211_ptr);
7265 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007266}
7267
Johannes Berg463d0182009-07-14 00:33:35 +02007268static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7269{
Johannes Berg4c476992010-10-04 21:36:35 +02007270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007271 struct net *net;
7272 int err;
7273 u32 pid;
7274
7275 if (!info->attrs[NL80211_ATTR_PID])
7276 return -EINVAL;
7277
7278 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7279
Johannes Berg463d0182009-07-14 00:33:35 +02007280 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007281 if (IS_ERR(net))
7282 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007283
7284 err = 0;
7285
7286 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007287 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7288 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007289
Johannes Berg463d0182009-07-14 00:33:35 +02007290 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007291 return err;
7292}
7293
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007294static int nl80211_setdel_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];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007297 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7298 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007299 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007300 struct cfg80211_pmksa pmksa;
7301
7302 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7303
7304 if (!info->attrs[NL80211_ATTR_MAC])
7305 return -EINVAL;
7306
7307 if (!info->attrs[NL80211_ATTR_PMKID])
7308 return -EINVAL;
7309
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007310 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7311 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7312
Johannes Berg074ac8d2010-09-16 14:58:22 +02007313 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007314 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7315 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007316
7317 switch (info->genlhdr->cmd) {
7318 case NL80211_CMD_SET_PMKSA:
7319 rdev_ops = rdev->ops->set_pmksa;
7320 break;
7321 case NL80211_CMD_DEL_PMKSA:
7322 rdev_ops = rdev->ops->del_pmksa;
7323 break;
7324 default:
7325 WARN_ON(1);
7326 break;
7327 }
7328
Johannes Berg4c476992010-10-04 21:36:35 +02007329 if (!rdev_ops)
7330 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007331
Johannes Berg4c476992010-10-04 21:36:35 +02007332 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007333}
7334
7335static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7336{
Johannes Berg4c476992010-10-04 21:36:35 +02007337 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7338 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007339
Johannes Berg074ac8d2010-09-16 14:58:22 +02007340 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007341 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7342 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007343
Johannes Berg4c476992010-10-04 21:36:35 +02007344 if (!rdev->ops->flush_pmksa)
7345 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007346
Hila Gonene35e4d22012-06-27 17:19:42 +03007347 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007348}
7349
Arik Nemtsov109086c2011-09-28 14:12:50 +03007350static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7351{
7352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7353 struct net_device *dev = info->user_ptr[1];
7354 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307355 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007356 u16 status_code;
7357 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007358 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007359
7360 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7361 !rdev->ops->tdls_mgmt)
7362 return -EOPNOTSUPP;
7363
7364 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7365 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7366 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7367 !info->attrs[NL80211_ATTR_IE] ||
7368 !info->attrs[NL80211_ATTR_MAC])
7369 return -EINVAL;
7370
7371 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7372 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7373 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7374 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007375 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307376 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7377 peer_capability =
7378 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007379
Hila Gonene35e4d22012-06-27 17:19:42 +03007380 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307381 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007382 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007383 nla_data(info->attrs[NL80211_ATTR_IE]),
7384 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007385}
7386
7387static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7388{
7389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7390 struct net_device *dev = info->user_ptr[1];
7391 enum nl80211_tdls_operation operation;
7392 u8 *peer;
7393
7394 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7395 !rdev->ops->tdls_oper)
7396 return -EOPNOTSUPP;
7397
7398 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7399 !info->attrs[NL80211_ATTR_MAC])
7400 return -EINVAL;
7401
7402 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7403 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7404
Hila Gonene35e4d22012-06-27 17:19:42 +03007405 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007406}
7407
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007408static int nl80211_remain_on_channel(struct sk_buff *skb,
7409 struct genl_info *info)
7410{
Johannes Berg4c476992010-10-04 21:36:35 +02007411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007412 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007413 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007414 struct sk_buff *msg;
7415 void *hdr;
7416 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007417 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007418 int err;
7419
7420 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7421 !info->attrs[NL80211_ATTR_DURATION])
7422 return -EINVAL;
7423
7424 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7425
Johannes Berg7c4ef712011-11-18 15:33:48 +01007426 if (!rdev->ops->remain_on_channel ||
7427 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007428 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007429
Johannes Bergebf348f2012-06-01 12:50:54 +02007430 /*
7431 * We should be on that channel for at least a minimum amount of
7432 * time (10ms) but no longer than the driver supports.
7433 */
7434 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7435 duration > rdev->wiphy.max_remain_on_channel_duration)
7436 return -EINVAL;
7437
Johannes Berg683b6d32012-11-08 21:25:48 +01007438 err = nl80211_parse_chandef(rdev, info, &chandef);
7439 if (err)
7440 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007441
7442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007443 if (!msg)
7444 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007445
Eric W. Biederman15e47302012-09-07 20:12:54 +00007446 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007447 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007448 if (!hdr) {
7449 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007450 goto free_msg;
7451 }
7452
Johannes Berg683b6d32012-11-08 21:25:48 +01007453 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7454 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007455
7456 if (err)
7457 goto free_msg;
7458
David S. Miller9360ffd2012-03-29 04:41:26 -04007459 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7460 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007461
7462 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007463
7464 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007465
7466 nla_put_failure:
7467 err = -ENOBUFS;
7468 free_msg:
7469 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007470 return err;
7471}
7472
7473static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7474 struct genl_info *info)
7475{
Johannes Berg4c476992010-10-04 21:36:35 +02007476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007477 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007478 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007479
7480 if (!info->attrs[NL80211_ATTR_COOKIE])
7481 return -EINVAL;
7482
Johannes Berg4c476992010-10-04 21:36:35 +02007483 if (!rdev->ops->cancel_remain_on_channel)
7484 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007485
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007486 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7487
Hila Gonene35e4d22012-06-27 17:19:42 +03007488 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007489}
7490
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007491static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7492 u8 *rates, u8 rates_len)
7493{
7494 u8 i;
7495 u32 mask = 0;
7496
7497 for (i = 0; i < rates_len; i++) {
7498 int rate = (rates[i] & 0x7f) * 5;
7499 int ridx;
7500 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7501 struct ieee80211_rate *srate =
7502 &sband->bitrates[ridx];
7503 if (rate == srate->bitrate) {
7504 mask |= 1 << ridx;
7505 break;
7506 }
7507 }
7508 if (ridx == sband->n_bitrates)
7509 return 0; /* rate not found */
7510 }
7511
7512 return mask;
7513}
7514
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007515static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7516 u8 *rates, u8 rates_len,
7517 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7518{
7519 u8 i;
7520
7521 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7522
7523 for (i = 0; i < rates_len; i++) {
7524 int ridx, rbit;
7525
7526 ridx = rates[i] / 8;
7527 rbit = BIT(rates[i] % 8);
7528
7529 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007530 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007531 return false;
7532
7533 /* check availability */
7534 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7535 mcs[ridx] |= rbit;
7536 else
7537 return false;
7538 }
7539
7540 return true;
7541}
7542
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007543static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7544{
7545 u16 mcs_mask = 0;
7546
7547 switch (vht_mcs_map) {
7548 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7549 break;
7550 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7551 mcs_mask = 0x00FF;
7552 break;
7553 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7554 mcs_mask = 0x01FF;
7555 break;
7556 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7557 mcs_mask = 0x03FF;
7558 break;
7559 default:
7560 break;
7561 }
7562
7563 return mcs_mask;
7564}
7565
7566static void vht_build_mcs_mask(u16 vht_mcs_map,
7567 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7568{
7569 u8 nss;
7570
7571 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7572 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7573 vht_mcs_map >>= 2;
7574 }
7575}
7576
7577static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7578 struct nl80211_txrate_vht *txrate,
7579 u16 mcs[NL80211_VHT_NSS_MAX])
7580{
7581 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7582 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7583 u8 i;
7584
7585 if (!sband->vht_cap.vht_supported)
7586 return false;
7587
7588 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7589
7590 /* Build vht_mcs_mask from VHT capabilities */
7591 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7592
7593 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7594 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7595 mcs[i] = txrate->mcs[i];
7596 else
7597 return false;
7598 }
7599
7600 return true;
7601}
7602
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007603static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007604 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7605 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007606 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7607 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007608 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007609 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007610};
7611
7612static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7613 struct genl_info *info)
7614{
7615 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007616 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007617 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007618 int rem, i;
7619 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007620 struct nlattr *tx_rates;
7621 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007622 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007623
Johannes Berg4c476992010-10-04 21:36:35 +02007624 if (!rdev->ops->set_bitrate_mask)
7625 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007626
7627 memset(&mask, 0, sizeof(mask));
7628 /* Default to all rates enabled */
7629 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7630 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007631
7632 if (!sband)
7633 continue;
7634
7635 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007636 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007637 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007638 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007639
7640 if (!sband->vht_cap.vht_supported)
7641 continue;
7642
7643 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7644 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007645 }
7646
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007647 /* if no rates are given set it back to the defaults */
7648 if (!info->attrs[NL80211_ATTR_TX_RATES])
7649 goto out;
7650
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007651 /*
7652 * The nested attribute uses enum nl80211_band as the index. This maps
7653 * directly to the enum ieee80211_band values used in cfg80211.
7654 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007655 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007656 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007657 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007658 int err;
7659
Johannes Berg4c476992010-10-04 21:36:35 +02007660 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7661 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007662 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007663 if (sband == NULL)
7664 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007665 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7666 nla_len(tx_rates), nl80211_txattr_policy);
7667 if (err)
7668 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007669 if (tb[NL80211_TXRATE_LEGACY]) {
7670 mask.control[band].legacy = rateset_to_mask(
7671 sband,
7672 nla_data(tb[NL80211_TXRATE_LEGACY]),
7673 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307674 if ((mask.control[band].legacy == 0) &&
7675 nla_len(tb[NL80211_TXRATE_LEGACY]))
7676 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007677 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007678 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007679 if (!ht_rateset_to_mask(
7680 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007681 nla_data(tb[NL80211_TXRATE_HT]),
7682 nla_len(tb[NL80211_TXRATE_HT]),
7683 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007684 return -EINVAL;
7685 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007686 if (tb[NL80211_TXRATE_VHT]) {
7687 if (!vht_set_mcs_mask(
7688 sband,
7689 nla_data(tb[NL80211_TXRATE_VHT]),
7690 mask.control[band].vht_mcs))
7691 return -EINVAL;
7692 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007693 if (tb[NL80211_TXRATE_GI]) {
7694 mask.control[band].gi =
7695 nla_get_u8(tb[NL80211_TXRATE_GI]);
7696 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7697 return -EINVAL;
7698 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007699
7700 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007701 /* don't allow empty legacy rates if HT or VHT
7702 * are not even supported.
7703 */
7704 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7705 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007706 return -EINVAL;
7707
7708 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007709 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007710 goto out;
7711
7712 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7713 if (mask.control[band].vht_mcs[i])
7714 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007715
7716 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007717 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007718 }
7719 }
7720
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007721out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007722 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007723}
7724
Johannes Berg2e161f72010-08-12 15:38:38 +02007725static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007726{
Johannes Berg4c476992010-10-04 21:36:35 +02007727 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007728 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007729 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007730
7731 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7732 return -EINVAL;
7733
Johannes Berg2e161f72010-08-12 15:38:38 +02007734 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7735 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007736
Johannes Berg71bbc992012-06-15 15:30:18 +02007737 switch (wdev->iftype) {
7738 case NL80211_IFTYPE_STATION:
7739 case NL80211_IFTYPE_ADHOC:
7740 case NL80211_IFTYPE_P2P_CLIENT:
7741 case NL80211_IFTYPE_AP:
7742 case NL80211_IFTYPE_AP_VLAN:
7743 case NL80211_IFTYPE_MESH_POINT:
7744 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007745 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007746 break;
7747 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007748 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007749 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007750
7751 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007752 if (!rdev->ops->mgmt_tx)
7753 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007754
Eric W. Biederman15e47302012-09-07 20:12:54 +00007755 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007756 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7757 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007758}
7759
Johannes Berg2e161f72010-08-12 15:38:38 +02007760static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007761{
Johannes Berg4c476992010-10-04 21:36:35 +02007762 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007763 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007764 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007765 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007766 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007767 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007768 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007769 struct cfg80211_mgmt_tx_params params = {
7770 .dont_wait_for_ack =
7771 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7772 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007773
Johannes Berg683b6d32012-11-08 21:25:48 +01007774 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007775 return -EINVAL;
7776
Johannes Berg4c476992010-10-04 21:36:35 +02007777 if (!rdev->ops->mgmt_tx)
7778 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007779
Johannes Berg71bbc992012-06-15 15:30:18 +02007780 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007781 case NL80211_IFTYPE_P2P_DEVICE:
7782 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7783 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007784 case NL80211_IFTYPE_STATION:
7785 case NL80211_IFTYPE_ADHOC:
7786 case NL80211_IFTYPE_P2P_CLIENT:
7787 case NL80211_IFTYPE_AP:
7788 case NL80211_IFTYPE_AP_VLAN:
7789 case NL80211_IFTYPE_MESH_POINT:
7790 case NL80211_IFTYPE_P2P_GO:
7791 break;
7792 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007793 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007794 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007795
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007796 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007797 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007798 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007799 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007800
7801 /*
7802 * We should wait on the channel for at least a minimum amount
7803 * of time (10ms) but no longer than the driver supports.
7804 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007805 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7806 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007807 return -EINVAL;
7808
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007809 }
7810
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007811 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007812
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007813 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007814 return -EINVAL;
7815
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007816 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307817
Antonio Quartulliea141b752013-06-11 14:20:03 +02007818 /* get the channel if any has been specified, otherwise pass NULL to
7819 * the driver. The latter will use the current one
7820 */
7821 chandef.chan = NULL;
7822 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7823 err = nl80211_parse_chandef(rdev, info, &chandef);
7824 if (err)
7825 return err;
7826 }
7827
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007828 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007829 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007830
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03007831 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7832 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7833
7834 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
7835 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7836 int i;
7837
7838 if (len % sizeof(u16))
7839 return -EINVAL;
7840
7841 params.n_csa_offsets = len / sizeof(u16);
7842 params.csa_offsets =
7843 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7844
7845 /* check that all the offsets fit the frame */
7846 for (i = 0; i < params.n_csa_offsets; i++) {
7847 if (params.csa_offsets[i] >= params.len)
7848 return -EINVAL;
7849 }
7850 }
7851
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007852 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7854 if (!msg)
7855 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007856
Eric W. Biederman15e47302012-09-07 20:12:54 +00007857 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007858 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007859 if (!hdr) {
7860 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007861 goto free_msg;
7862 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007863 }
Johannes Berge247bd902011-11-04 11:18:21 +01007864
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007865 params.chan = chandef.chan;
7866 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007867 if (err)
7868 goto free_msg;
7869
Johannes Berge247bd902011-11-04 11:18:21 +01007870 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007871 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7872 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007873
Johannes Berge247bd902011-11-04 11:18:21 +01007874 genlmsg_end(msg, hdr);
7875 return genlmsg_reply(msg, info);
7876 }
7877
7878 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007879
7880 nla_put_failure:
7881 err = -ENOBUFS;
7882 free_msg:
7883 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007884 return err;
7885}
7886
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007887static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7888{
7889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007890 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007891 u64 cookie;
7892
7893 if (!info->attrs[NL80211_ATTR_COOKIE])
7894 return -EINVAL;
7895
7896 if (!rdev->ops->mgmt_tx_cancel_wait)
7897 return -EOPNOTSUPP;
7898
Johannes Berg71bbc992012-06-15 15:30:18 +02007899 switch (wdev->iftype) {
7900 case NL80211_IFTYPE_STATION:
7901 case NL80211_IFTYPE_ADHOC:
7902 case NL80211_IFTYPE_P2P_CLIENT:
7903 case NL80211_IFTYPE_AP:
7904 case NL80211_IFTYPE_AP_VLAN:
7905 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007906 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007907 break;
7908 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007909 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007910 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007911
7912 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7913
Hila Gonene35e4d22012-06-27 17:19:42 +03007914 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007915}
7916
Kalle Valoffb9eb32010-02-17 17:58:10 +02007917static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7918{
Johannes Berg4c476992010-10-04 21:36:35 +02007919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007920 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007921 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007922 u8 ps_state;
7923 bool state;
7924 int err;
7925
Johannes Berg4c476992010-10-04 21:36:35 +02007926 if (!info->attrs[NL80211_ATTR_PS_STATE])
7927 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007928
7929 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7930
Johannes Berg4c476992010-10-04 21:36:35 +02007931 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7932 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007933
7934 wdev = dev->ieee80211_ptr;
7935
Johannes Berg4c476992010-10-04 21:36:35 +02007936 if (!rdev->ops->set_power_mgmt)
7937 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007938
7939 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7940
7941 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007942 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007943
Hila Gonene35e4d22012-06-27 17:19:42 +03007944 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007945 if (!err)
7946 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007947 return err;
7948}
7949
7950static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7951{
Johannes Berg4c476992010-10-04 21:36:35 +02007952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007953 enum nl80211_ps_state ps_state;
7954 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007955 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007956 struct sk_buff *msg;
7957 void *hdr;
7958 int err;
7959
Kalle Valoffb9eb32010-02-17 17:58:10 +02007960 wdev = dev->ieee80211_ptr;
7961
Johannes Berg4c476992010-10-04 21:36:35 +02007962 if (!rdev->ops->set_power_mgmt)
7963 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007964
7965 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007966 if (!msg)
7967 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007968
Eric W. Biederman15e47302012-09-07 20:12:54 +00007969 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007970 NL80211_CMD_GET_POWER_SAVE);
7971 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007972 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007973 goto free_msg;
7974 }
7975
7976 if (wdev->ps)
7977 ps_state = NL80211_PS_ENABLED;
7978 else
7979 ps_state = NL80211_PS_DISABLED;
7980
David S. Miller9360ffd2012-03-29 04:41:26 -04007981 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7982 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007983
7984 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007985 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007986
Johannes Berg4c476992010-10-04 21:36:35 +02007987 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007988 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007989 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007990 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007991 return err;
7992}
7993
Johannes Berg94e860f2014-01-20 23:58:15 +01007994static const struct nla_policy
7995nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007996 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7997 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7998 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007999 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8000 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8001 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008002};
8003
Thomas Pedersen84f10702012-07-12 16:17:33 -07008004static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008005 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008006{
8007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008008 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008009 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008010
Johannes Bergd9d8b012012-11-26 12:51:52 +01008011 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008012 return -EINVAL;
8013
Thomas Pedersen84f10702012-07-12 16:17:33 -07008014 if (!rdev->ops->set_cqm_txe_config)
8015 return -EOPNOTSUPP;
8016
8017 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8018 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8019 return -EOPNOTSUPP;
8020
Hila Gonene35e4d22012-06-27 17:19:42 +03008021 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008022}
8023
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008024static int nl80211_set_cqm_rssi(struct genl_info *info,
8025 s32 threshold, u32 hysteresis)
8026{
Johannes Berg4c476992010-10-04 21:36:35 +02008027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008028 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008029 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008030
8031 if (threshold > 0)
8032 return -EINVAL;
8033
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008034 /* disabling - hysteresis should also be zero then */
8035 if (threshold == 0)
8036 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008037
Johannes Berg4c476992010-10-04 21:36:35 +02008038 if (!rdev->ops->set_cqm_rssi_config)
8039 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008040
Johannes Berg074ac8d2010-09-16 14:58:22 +02008041 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008042 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8043 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008044
Hila Gonene35e4d22012-06-27 17:19:42 +03008045 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008046}
8047
8048static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8049{
8050 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8051 struct nlattr *cqm;
8052 int err;
8053
8054 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008055 if (!cqm)
8056 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008057
8058 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8059 nl80211_attr_cqm_policy);
8060 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008061 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008062
8063 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8064 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008065 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8066 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008067
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008068 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8069 }
8070
8071 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8072 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8073 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8074 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8075 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8076 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8077
8078 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8079 }
8080
8081 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008082}
8083
Johannes Berg29cbe682010-12-03 09:20:44 +01008084static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8085{
8086 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8087 struct net_device *dev = info->user_ptr[1];
8088 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008089 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008090 int err;
8091
8092 /* start with default */
8093 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008094 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008095
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008096 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008097 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008098 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008099 if (err)
8100 return err;
8101 }
8102
8103 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8104 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8105 return -EINVAL;
8106
Javier Cardonac80d5452010-12-16 17:37:49 -08008107 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8108 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8109
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008110 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8111 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8112 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8113 return -EINVAL;
8114
Marco Porsch9bdbf042013-01-07 16:04:51 +01008115 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8116 setup.beacon_interval =
8117 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8118 if (setup.beacon_interval < 10 ||
8119 setup.beacon_interval > 10000)
8120 return -EINVAL;
8121 }
8122
8123 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8124 setup.dtim_period =
8125 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8126 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8127 return -EINVAL;
8128 }
8129
Javier Cardonac80d5452010-12-16 17:37:49 -08008130 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8131 /* parse additional setup parameters if given */
8132 err = nl80211_parse_mesh_setup(info, &setup);
8133 if (err)
8134 return err;
8135 }
8136
Thomas Pedersend37bb182013-03-04 13:06:13 -08008137 if (setup.user_mpm)
8138 cfg.auto_open_plinks = false;
8139
Johannes Bergcc1d2802012-05-16 23:50:20 +02008140 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008141 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8142 if (err)
8143 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008144 } else {
8145 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008146 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008147 }
8148
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008149 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8150 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8151 int n_rates =
8152 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8153 struct ieee80211_supported_band *sband;
8154
8155 if (!setup.chandef.chan)
8156 return -EINVAL;
8157
8158 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8159
8160 err = ieee80211_get_ratemask(sband, rates, n_rates,
8161 &setup.basic_rates);
8162 if (err)
8163 return err;
8164 }
8165
Javier Cardonac80d5452010-12-16 17:37:49 -08008166 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008167}
8168
8169static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8170{
8171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8172 struct net_device *dev = info->user_ptr[1];
8173
8174 return cfg80211_leave_mesh(rdev, dev);
8175}
8176
Johannes Bergdfb89c52012-06-27 09:23:48 +02008177#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008178static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8179 struct cfg80211_registered_device *rdev)
8180{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008181 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008182 struct nlattr *nl_pats, *nl_pat;
8183 int i, pat_len;
8184
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008185 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008186 return 0;
8187
8188 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8189 if (!nl_pats)
8190 return -ENOBUFS;
8191
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008192 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008193 nl_pat = nla_nest_start(msg, i + 1);
8194 if (!nl_pat)
8195 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008196 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008197 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008198 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008199 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8200 wowlan->patterns[i].pattern) ||
8201 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008202 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008203 return -ENOBUFS;
8204 nla_nest_end(msg, nl_pat);
8205 }
8206 nla_nest_end(msg, nl_pats);
8207
8208 return 0;
8209}
8210
Johannes Berg2a0e0472013-01-23 22:57:40 +01008211static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8212 struct cfg80211_wowlan_tcp *tcp)
8213{
8214 struct nlattr *nl_tcp;
8215
8216 if (!tcp)
8217 return 0;
8218
8219 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8220 if (!nl_tcp)
8221 return -ENOBUFS;
8222
8223 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8224 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8225 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8226 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8227 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8228 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8229 tcp->payload_len, tcp->payload) ||
8230 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8231 tcp->data_interval) ||
8232 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8233 tcp->wake_len, tcp->wake_data) ||
8234 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8235 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8236 return -ENOBUFS;
8237
8238 if (tcp->payload_seq.len &&
8239 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8240 sizeof(tcp->payload_seq), &tcp->payload_seq))
8241 return -ENOBUFS;
8242
8243 if (tcp->payload_tok.len &&
8244 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8245 sizeof(tcp->payload_tok) + tcp->tokens_size,
8246 &tcp->payload_tok))
8247 return -ENOBUFS;
8248
Johannes Berge248ad32013-05-16 10:24:28 +02008249 nla_nest_end(msg, nl_tcp);
8250
Johannes Berg2a0e0472013-01-23 22:57:40 +01008251 return 0;
8252}
8253
Johannes Bergff1b6e62011-05-04 15:37:28 +02008254static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8255{
8256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8257 struct sk_buff *msg;
8258 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008259 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008260
Johannes Berg964dc9e2013-06-03 17:25:34 +02008261 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008262 return -EOPNOTSUPP;
8263
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008264 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008265 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008266 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8267 rdev->wiphy.wowlan_config->tcp->payload_len +
8268 rdev->wiphy.wowlan_config->tcp->wake_len +
8269 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008270 }
8271
8272 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008273 if (!msg)
8274 return -ENOMEM;
8275
Eric W. Biederman15e47302012-09-07 20:12:54 +00008276 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008277 NL80211_CMD_GET_WOWLAN);
8278 if (!hdr)
8279 goto nla_put_failure;
8280
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008281 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008282 struct nlattr *nl_wowlan;
8283
8284 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8285 if (!nl_wowlan)
8286 goto nla_put_failure;
8287
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008288 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008289 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008290 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008291 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008292 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008293 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008294 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008295 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008296 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008297 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008298 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008299 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008300 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008301 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8302 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008303
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008304 if (nl80211_send_wowlan_patterns(msg, rdev))
8305 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008306
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008307 if (nl80211_send_wowlan_tcp(msg,
8308 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008309 goto nla_put_failure;
8310
Johannes Bergff1b6e62011-05-04 15:37:28 +02008311 nla_nest_end(msg, nl_wowlan);
8312 }
8313
8314 genlmsg_end(msg, hdr);
8315 return genlmsg_reply(msg, info);
8316
8317nla_put_failure:
8318 nlmsg_free(msg);
8319 return -ENOBUFS;
8320}
8321
Johannes Berg2a0e0472013-01-23 22:57:40 +01008322static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8323 struct nlattr *attr,
8324 struct cfg80211_wowlan *trig)
8325{
8326 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8327 struct cfg80211_wowlan_tcp *cfg;
8328 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8329 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8330 u32 size;
8331 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8332 int err, port;
8333
Johannes Berg964dc9e2013-06-03 17:25:34 +02008334 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008335 return -EINVAL;
8336
8337 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8338 nla_data(attr), nla_len(attr),
8339 nl80211_wowlan_tcp_policy);
8340 if (err)
8341 return err;
8342
8343 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8344 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8345 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8346 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8347 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8348 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8349 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8350 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8351 return -EINVAL;
8352
8353 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008354 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008355 return -EINVAL;
8356
8357 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008358 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008359 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008360 return -EINVAL;
8361
8362 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008363 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008364 return -EINVAL;
8365
8366 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8367 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8368 return -EINVAL;
8369
8370 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8371 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8372
8373 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8374 tokens_size = tokln - sizeof(*tok);
8375
8376 if (!tok->len || tokens_size % tok->len)
8377 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008378 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008379 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008380 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008381 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008382 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008383 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008384 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008385 return -EINVAL;
8386 if (tok->offset + tok->len > data_size)
8387 return -EINVAL;
8388 }
8389
8390 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8391 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008392 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008393 return -EINVAL;
8394 if (seq->len == 0 || seq->len > 4)
8395 return -EINVAL;
8396 if (seq->len + seq->offset > data_size)
8397 return -EINVAL;
8398 }
8399
8400 size = sizeof(*cfg);
8401 size += data_size;
8402 size += wake_size + wake_mask_size;
8403 size += tokens_size;
8404
8405 cfg = kzalloc(size, GFP_KERNEL);
8406 if (!cfg)
8407 return -ENOMEM;
8408 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8409 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8410 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8411 ETH_ALEN);
8412 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8413 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8414 else
8415 port = 0;
8416#ifdef CONFIG_INET
8417 /* allocate a socket and port for it and use it */
8418 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8419 IPPROTO_TCP, &cfg->sock, 1);
8420 if (err) {
8421 kfree(cfg);
8422 return err;
8423 }
8424 if (inet_csk_get_port(cfg->sock->sk, port)) {
8425 sock_release(cfg->sock);
8426 kfree(cfg);
8427 return -EADDRINUSE;
8428 }
8429 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8430#else
8431 if (!port) {
8432 kfree(cfg);
8433 return -EINVAL;
8434 }
8435 cfg->src_port = port;
8436#endif
8437
8438 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8439 cfg->payload_len = data_size;
8440 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8441 memcpy((void *)cfg->payload,
8442 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8443 data_size);
8444 if (seq)
8445 cfg->payload_seq = *seq;
8446 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8447 cfg->wake_len = wake_size;
8448 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8449 memcpy((void *)cfg->wake_data,
8450 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8451 wake_size);
8452 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8453 data_size + wake_size;
8454 memcpy((void *)cfg->wake_mask,
8455 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8456 wake_mask_size);
8457 if (tok) {
8458 cfg->tokens_size = tokens_size;
8459 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8460 }
8461
8462 trig->tcp = cfg;
8463
8464 return 0;
8465}
8466
Johannes Bergff1b6e62011-05-04 15:37:28 +02008467static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8468{
8469 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8470 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008471 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008472 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008473 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008474 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008475 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008476
Johannes Berg964dc9e2013-06-03 17:25:34 +02008477 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008478 return -EOPNOTSUPP;
8479
Johannes Bergae33bd82012-07-12 16:25:02 +02008480 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8481 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008482 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008483 goto set_wakeup;
8484 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008485
8486 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8487 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8488 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8489 nl80211_wowlan_policy);
8490 if (err)
8491 return err;
8492
8493 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8494 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8495 return -EINVAL;
8496 new_triggers.any = true;
8497 }
8498
8499 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8500 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8501 return -EINVAL;
8502 new_triggers.disconnect = true;
8503 }
8504
8505 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8506 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8507 return -EINVAL;
8508 new_triggers.magic_pkt = true;
8509 }
8510
Johannes Berg77dbbb12011-07-13 10:48:55 +02008511 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8512 return -EINVAL;
8513
8514 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8515 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8516 return -EINVAL;
8517 new_triggers.gtk_rekey_failure = true;
8518 }
8519
8520 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8521 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8522 return -EINVAL;
8523 new_triggers.eap_identity_req = true;
8524 }
8525
8526 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8527 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8528 return -EINVAL;
8529 new_triggers.four_way_handshake = true;
8530 }
8531
8532 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8533 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8534 return -EINVAL;
8535 new_triggers.rfkill_release = true;
8536 }
8537
Johannes Bergff1b6e62011-05-04 15:37:28 +02008538 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8539 struct nlattr *pat;
8540 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008541 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008542 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008543
8544 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8545 rem)
8546 n_patterns++;
8547 if (n_patterns > wowlan->n_patterns)
8548 return -EINVAL;
8549
8550 new_triggers.patterns = kcalloc(n_patterns,
8551 sizeof(new_triggers.patterns[0]),
8552 GFP_KERNEL);
8553 if (!new_triggers.patterns)
8554 return -ENOMEM;
8555
8556 new_triggers.n_patterns = n_patterns;
8557 i = 0;
8558
8559 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8560 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008561 u8 *mask_pat;
8562
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008563 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8564 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008565 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008566 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8567 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008568 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008569 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008570 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008571 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008572 goto error;
8573 if (pat_len > wowlan->pattern_max_len ||
8574 pat_len < wowlan->pattern_min_len)
8575 goto error;
8576
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008577 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008578 pkt_offset = 0;
8579 else
8580 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008581 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008582 if (pkt_offset > wowlan->max_pkt_offset)
8583 goto error;
8584 new_triggers.patterns[i].pkt_offset = pkt_offset;
8585
Johannes Berg922bd802014-05-19 17:59:50 +02008586 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8587 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008588 err = -ENOMEM;
8589 goto error;
8590 }
Johannes Berg922bd802014-05-19 17:59:50 +02008591 new_triggers.patterns[i].mask = mask_pat;
8592 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008593 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008594 mask_pat += mask_len;
8595 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008596 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008597 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008598 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008599 pat_len);
8600 i++;
8601 }
8602 }
8603
Johannes Berg2a0e0472013-01-23 22:57:40 +01008604 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8605 err = nl80211_parse_wowlan_tcp(
8606 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8607 &new_triggers);
8608 if (err)
8609 goto error;
8610 }
8611
Johannes Bergae33bd82012-07-12 16:25:02 +02008612 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8613 if (!ntrig) {
8614 err = -ENOMEM;
8615 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008616 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008617 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008618 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008619
Johannes Bergae33bd82012-07-12 16:25:02 +02008620 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008621 if (rdev->ops->set_wakeup &&
8622 prev_enabled != !!rdev->wiphy.wowlan_config)
8623 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008624
Johannes Bergff1b6e62011-05-04 15:37:28 +02008625 return 0;
8626 error:
8627 for (i = 0; i < new_triggers.n_patterns; i++)
8628 kfree(new_triggers.patterns[i].mask);
8629 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008630 if (new_triggers.tcp && new_triggers.tcp->sock)
8631 sock_release(new_triggers.tcp->sock);
8632 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008633 return err;
8634}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008635#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008636
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008637static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8638 struct cfg80211_registered_device *rdev)
8639{
8640 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8641 int i, j, pat_len;
8642 struct cfg80211_coalesce_rules *rule;
8643
8644 if (!rdev->coalesce->n_rules)
8645 return 0;
8646
8647 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8648 if (!nl_rules)
8649 return -ENOBUFS;
8650
8651 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8652 nl_rule = nla_nest_start(msg, i + 1);
8653 if (!nl_rule)
8654 return -ENOBUFS;
8655
8656 rule = &rdev->coalesce->rules[i];
8657 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8658 rule->delay))
8659 return -ENOBUFS;
8660
8661 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8662 rule->condition))
8663 return -ENOBUFS;
8664
8665 nl_pats = nla_nest_start(msg,
8666 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8667 if (!nl_pats)
8668 return -ENOBUFS;
8669
8670 for (j = 0; j < rule->n_patterns; j++) {
8671 nl_pat = nla_nest_start(msg, j + 1);
8672 if (!nl_pat)
8673 return -ENOBUFS;
8674 pat_len = rule->patterns[j].pattern_len;
8675 if (nla_put(msg, NL80211_PKTPAT_MASK,
8676 DIV_ROUND_UP(pat_len, 8),
8677 rule->patterns[j].mask) ||
8678 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8679 rule->patterns[j].pattern) ||
8680 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8681 rule->patterns[j].pkt_offset))
8682 return -ENOBUFS;
8683 nla_nest_end(msg, nl_pat);
8684 }
8685 nla_nest_end(msg, nl_pats);
8686 nla_nest_end(msg, nl_rule);
8687 }
8688 nla_nest_end(msg, nl_rules);
8689
8690 return 0;
8691}
8692
8693static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8694{
8695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8696 struct sk_buff *msg;
8697 void *hdr;
8698
8699 if (!rdev->wiphy.coalesce)
8700 return -EOPNOTSUPP;
8701
8702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8703 if (!msg)
8704 return -ENOMEM;
8705
8706 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8707 NL80211_CMD_GET_COALESCE);
8708 if (!hdr)
8709 goto nla_put_failure;
8710
8711 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8712 goto nla_put_failure;
8713
8714 genlmsg_end(msg, hdr);
8715 return genlmsg_reply(msg, info);
8716
8717nla_put_failure:
8718 nlmsg_free(msg);
8719 return -ENOBUFS;
8720}
8721
8722void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8723{
8724 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8725 int i, j;
8726 struct cfg80211_coalesce_rules *rule;
8727
8728 if (!coalesce)
8729 return;
8730
8731 for (i = 0; i < coalesce->n_rules; i++) {
8732 rule = &coalesce->rules[i];
8733 for (j = 0; j < rule->n_patterns; j++)
8734 kfree(rule->patterns[j].mask);
8735 kfree(rule->patterns);
8736 }
8737 kfree(coalesce->rules);
8738 kfree(coalesce);
8739 rdev->coalesce = NULL;
8740}
8741
8742static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8743 struct nlattr *rule,
8744 struct cfg80211_coalesce_rules *new_rule)
8745{
8746 int err, i;
8747 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8748 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8749 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8750 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8751
8752 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8753 nla_len(rule), nl80211_coalesce_policy);
8754 if (err)
8755 return err;
8756
8757 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8758 new_rule->delay =
8759 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8760 if (new_rule->delay > coalesce->max_delay)
8761 return -EINVAL;
8762
8763 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8764 new_rule->condition =
8765 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8766 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8767 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8768 return -EINVAL;
8769
8770 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8771 return -EINVAL;
8772
8773 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8774 rem)
8775 n_patterns++;
8776 if (n_patterns > coalesce->n_patterns)
8777 return -EINVAL;
8778
8779 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8780 GFP_KERNEL);
8781 if (!new_rule->patterns)
8782 return -ENOMEM;
8783
8784 new_rule->n_patterns = n_patterns;
8785 i = 0;
8786
8787 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8788 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008789 u8 *mask_pat;
8790
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008791 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8792 nla_len(pat), NULL);
8793 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8794 !pat_tb[NL80211_PKTPAT_PATTERN])
8795 return -EINVAL;
8796 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8797 mask_len = DIV_ROUND_UP(pat_len, 8);
8798 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8799 return -EINVAL;
8800 if (pat_len > coalesce->pattern_max_len ||
8801 pat_len < coalesce->pattern_min_len)
8802 return -EINVAL;
8803
8804 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8805 pkt_offset = 0;
8806 else
8807 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8808 if (pkt_offset > coalesce->max_pkt_offset)
8809 return -EINVAL;
8810 new_rule->patterns[i].pkt_offset = pkt_offset;
8811
Johannes Berg922bd802014-05-19 17:59:50 +02008812 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8813 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008814 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02008815
8816 new_rule->patterns[i].mask = mask_pat;
8817 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
8818 mask_len);
8819
8820 mask_pat += mask_len;
8821 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008822 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008823 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
8824 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008825 i++;
8826 }
8827
8828 return 0;
8829}
8830
8831static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8832{
8833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8834 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8835 struct cfg80211_coalesce new_coalesce = {};
8836 struct cfg80211_coalesce *n_coalesce;
8837 int err, rem_rule, n_rules = 0, i, j;
8838 struct nlattr *rule;
8839 struct cfg80211_coalesce_rules *tmp_rule;
8840
8841 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8842 return -EOPNOTSUPP;
8843
8844 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8845 cfg80211_rdev_free_coalesce(rdev);
8846 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8847 return 0;
8848 }
8849
8850 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8851 rem_rule)
8852 n_rules++;
8853 if (n_rules > coalesce->n_rules)
8854 return -EINVAL;
8855
8856 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8857 GFP_KERNEL);
8858 if (!new_coalesce.rules)
8859 return -ENOMEM;
8860
8861 new_coalesce.n_rules = n_rules;
8862 i = 0;
8863
8864 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8865 rem_rule) {
8866 err = nl80211_parse_coalesce_rule(rdev, rule,
8867 &new_coalesce.rules[i]);
8868 if (err)
8869 goto error;
8870
8871 i++;
8872 }
8873
8874 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8875 if (err)
8876 goto error;
8877
8878 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8879 if (!n_coalesce) {
8880 err = -ENOMEM;
8881 goto error;
8882 }
8883 cfg80211_rdev_free_coalesce(rdev);
8884 rdev->coalesce = n_coalesce;
8885
8886 return 0;
8887error:
8888 for (i = 0; i < new_coalesce.n_rules; i++) {
8889 tmp_rule = &new_coalesce.rules[i];
8890 for (j = 0; j < tmp_rule->n_patterns; j++)
8891 kfree(tmp_rule->patterns[j].mask);
8892 kfree(tmp_rule->patterns);
8893 }
8894 kfree(new_coalesce.rules);
8895
8896 return err;
8897}
8898
Johannes Berge5497d72011-07-05 16:35:40 +02008899static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8900{
8901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8902 struct net_device *dev = info->user_ptr[1];
8903 struct wireless_dev *wdev = dev->ieee80211_ptr;
8904 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8905 struct cfg80211_gtk_rekey_data rekey_data;
8906 int err;
8907
8908 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8909 return -EINVAL;
8910
8911 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8912 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8913 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8914 nl80211_rekey_policy);
8915 if (err)
8916 return err;
8917
8918 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8919 return -ERANGE;
8920 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8921 return -ERANGE;
8922 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8923 return -ERANGE;
8924
8925 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8926 NL80211_KEK_LEN);
8927 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8928 NL80211_KCK_LEN);
8929 memcpy(rekey_data.replay_ctr,
8930 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8931 NL80211_REPLAY_CTR_LEN);
8932
8933 wdev_lock(wdev);
8934 if (!wdev->current_bss) {
8935 err = -ENOTCONN;
8936 goto out;
8937 }
8938
8939 if (!rdev->ops->set_rekey_data) {
8940 err = -EOPNOTSUPP;
8941 goto out;
8942 }
8943
Hila Gonene35e4d22012-06-27 17:19:42 +03008944 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008945 out:
8946 wdev_unlock(wdev);
8947 return err;
8948}
8949
Johannes Berg28946da2011-11-04 11:18:12 +01008950static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8951 struct genl_info *info)
8952{
8953 struct net_device *dev = info->user_ptr[1];
8954 struct wireless_dev *wdev = dev->ieee80211_ptr;
8955
8956 if (wdev->iftype != NL80211_IFTYPE_AP &&
8957 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8958 return -EINVAL;
8959
Eric W. Biederman15e47302012-09-07 20:12:54 +00008960 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008961 return -EBUSY;
8962
Eric W. Biederman15e47302012-09-07 20:12:54 +00008963 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008964 return 0;
8965}
8966
Johannes Berg7f6cf312011-11-04 11:18:15 +01008967static int nl80211_probe_client(struct sk_buff *skb,
8968 struct genl_info *info)
8969{
8970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8971 struct net_device *dev = info->user_ptr[1];
8972 struct wireless_dev *wdev = dev->ieee80211_ptr;
8973 struct sk_buff *msg;
8974 void *hdr;
8975 const u8 *addr;
8976 u64 cookie;
8977 int err;
8978
8979 if (wdev->iftype != NL80211_IFTYPE_AP &&
8980 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8981 return -EOPNOTSUPP;
8982
8983 if (!info->attrs[NL80211_ATTR_MAC])
8984 return -EINVAL;
8985
8986 if (!rdev->ops->probe_client)
8987 return -EOPNOTSUPP;
8988
8989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8990 if (!msg)
8991 return -ENOMEM;
8992
Eric W. Biederman15e47302012-09-07 20:12:54 +00008993 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008994 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008995 if (!hdr) {
8996 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008997 goto free_msg;
8998 }
8999
9000 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9001
Hila Gonene35e4d22012-06-27 17:19:42 +03009002 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009003 if (err)
9004 goto free_msg;
9005
David S. Miller9360ffd2012-03-29 04:41:26 -04009006 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9007 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009008
9009 genlmsg_end(msg, hdr);
9010
9011 return genlmsg_reply(msg, info);
9012
9013 nla_put_failure:
9014 err = -ENOBUFS;
9015 free_msg:
9016 nlmsg_free(msg);
9017 return err;
9018}
9019
Johannes Berg5e7602302011-11-04 11:18:17 +01009020static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9021{
9022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009023 struct cfg80211_beacon_registration *reg, *nreg;
9024 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009025
9026 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9027 return -EOPNOTSUPP;
9028
Ben Greear37c73b52012-10-26 14:49:25 -07009029 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9030 if (!nreg)
9031 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01009032
Ben Greear37c73b52012-10-26 14:49:25 -07009033 /* First, check if already registered. */
9034 spin_lock_bh(&rdev->beacon_registrations_lock);
9035 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9036 if (reg->nlportid == info->snd_portid) {
9037 rv = -EALREADY;
9038 goto out_err;
9039 }
9040 }
9041 /* Add it to the list */
9042 nreg->nlportid = info->snd_portid;
9043 list_add(&nreg->list, &rdev->beacon_registrations);
9044
9045 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01009046
9047 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009048out_err:
9049 spin_unlock_bh(&rdev->beacon_registrations_lock);
9050 kfree(nreg);
9051 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009052}
9053
Johannes Berg98104fde2012-06-16 00:19:54 +02009054static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9055{
9056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9057 struct wireless_dev *wdev = info->user_ptr[1];
9058 int err;
9059
9060 if (!rdev->ops->start_p2p_device)
9061 return -EOPNOTSUPP;
9062
9063 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9064 return -EOPNOTSUPP;
9065
9066 if (wdev->p2p_started)
9067 return 0;
9068
Luciano Coelhob6a55012014-02-27 11:07:21 +02009069 if (rfkill_blocked(rdev->rfkill))
9070 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009071
Johannes Bergeeb126e2012-10-23 15:16:50 +02009072 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009073 if (err)
9074 return err;
9075
9076 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009077 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009078
9079 return 0;
9080}
9081
9082static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9083{
9084 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9085 struct wireless_dev *wdev = info->user_ptr[1];
9086
9087 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9088 return -EOPNOTSUPP;
9089
9090 if (!rdev->ops->stop_p2p_device)
9091 return -EOPNOTSUPP;
9092
Johannes Bergf9f47522013-03-19 15:04:07 +01009093 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009094
9095 return 0;
9096}
9097
Johannes Berg3713b4e2013-02-14 16:19:38 +01009098static int nl80211_get_protocol_features(struct sk_buff *skb,
9099 struct genl_info *info)
9100{
9101 void *hdr;
9102 struct sk_buff *msg;
9103
9104 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9105 if (!msg)
9106 return -ENOMEM;
9107
9108 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9109 NL80211_CMD_GET_PROTOCOL_FEATURES);
9110 if (!hdr)
9111 goto nla_put_failure;
9112
9113 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9114 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9115 goto nla_put_failure;
9116
9117 genlmsg_end(msg, hdr);
9118 return genlmsg_reply(msg, info);
9119
9120 nla_put_failure:
9121 kfree_skb(msg);
9122 return -ENOBUFS;
9123}
9124
Jouni Malinen355199e2013-02-27 17:14:27 +02009125static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9126{
9127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9128 struct cfg80211_update_ft_ies_params ft_params;
9129 struct net_device *dev = info->user_ptr[1];
9130
9131 if (!rdev->ops->update_ft_ies)
9132 return -EOPNOTSUPP;
9133
9134 if (!info->attrs[NL80211_ATTR_MDID] ||
9135 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9136 return -EINVAL;
9137
9138 memset(&ft_params, 0, sizeof(ft_params));
9139 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9140 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9141 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9142
9143 return rdev_update_ft_ies(rdev, dev, &ft_params);
9144}
9145
Arend van Spriel5de17982013-04-18 15:49:00 +02009146static int nl80211_crit_protocol_start(struct sk_buff *skb,
9147 struct genl_info *info)
9148{
9149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9150 struct wireless_dev *wdev = info->user_ptr[1];
9151 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9152 u16 duration;
9153 int ret;
9154
9155 if (!rdev->ops->crit_proto_start)
9156 return -EOPNOTSUPP;
9157
9158 if (WARN_ON(!rdev->ops->crit_proto_stop))
9159 return -EINVAL;
9160
9161 if (rdev->crit_proto_nlportid)
9162 return -EBUSY;
9163
9164 /* determine protocol if provided */
9165 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9166 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9167
9168 if (proto >= NUM_NL80211_CRIT_PROTO)
9169 return -EINVAL;
9170
9171 /* timeout must be provided */
9172 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9173 return -EINVAL;
9174
9175 duration =
9176 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9177
9178 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9179 return -ERANGE;
9180
9181 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9182 if (!ret)
9183 rdev->crit_proto_nlportid = info->snd_portid;
9184
9185 return ret;
9186}
9187
9188static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9189 struct genl_info *info)
9190{
9191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9192 struct wireless_dev *wdev = info->user_ptr[1];
9193
9194 if (!rdev->ops->crit_proto_stop)
9195 return -EOPNOTSUPP;
9196
9197 if (rdev->crit_proto_nlportid) {
9198 rdev->crit_proto_nlportid = 0;
9199 rdev_crit_proto_stop(rdev, wdev);
9200 }
9201 return 0;
9202}
9203
Johannes Bergad7e7182013-11-13 13:37:47 +01009204static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9205{
9206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9207 struct wireless_dev *wdev =
9208 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9209 int i, err;
9210 u32 vid, subcmd;
9211
9212 if (!rdev->wiphy.vendor_commands)
9213 return -EOPNOTSUPP;
9214
9215 if (IS_ERR(wdev)) {
9216 err = PTR_ERR(wdev);
9217 if (err != -EINVAL)
9218 return err;
9219 wdev = NULL;
9220 } else if (wdev->wiphy != &rdev->wiphy) {
9221 return -EINVAL;
9222 }
9223
9224 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9225 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9226 return -EINVAL;
9227
9228 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9229 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9230 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9231 const struct wiphy_vendor_command *vcmd;
9232 void *data = NULL;
9233 int len = 0;
9234
9235 vcmd = &rdev->wiphy.vendor_commands[i];
9236
9237 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9238 continue;
9239
9240 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9241 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9242 if (!wdev)
9243 return -EINVAL;
9244 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9245 !wdev->netdev)
9246 return -EINVAL;
9247
9248 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9249 if (wdev->netdev &&
9250 !netif_running(wdev->netdev))
9251 return -ENETDOWN;
9252 if (!wdev->netdev && !wdev->p2p_started)
9253 return -ENETDOWN;
9254 }
9255 } else {
9256 wdev = NULL;
9257 }
9258
9259 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9260 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9261 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9262 }
9263
9264 rdev->cur_cmd_info = info;
9265 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9266 data, len);
9267 rdev->cur_cmd_info = NULL;
9268 return err;
9269 }
9270
9271 return -EOPNOTSUPP;
9272}
9273
9274struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9275 enum nl80211_commands cmd,
9276 enum nl80211_attrs attr,
9277 int approxlen)
9278{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009279 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009280
9281 if (WARN_ON(!rdev->cur_cmd_info))
9282 return NULL;
9283
9284 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9285 rdev->cur_cmd_info->snd_portid,
9286 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009287 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009288}
9289EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9290
9291int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9292{
9293 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9294 void *hdr = ((void **)skb->cb)[1];
9295 struct nlattr *data = ((void **)skb->cb)[2];
9296
9297 if (WARN_ON(!rdev->cur_cmd_info)) {
9298 kfree_skb(skb);
9299 return -EINVAL;
9300 }
9301
9302 nla_nest_end(skb, data);
9303 genlmsg_end(skb, hdr);
9304 return genlmsg_reply(skb, rdev->cur_cmd_info);
9305}
9306EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9307
9308
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009309static int nl80211_set_qos_map(struct sk_buff *skb,
9310 struct genl_info *info)
9311{
9312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9313 struct cfg80211_qos_map *qos_map = NULL;
9314 struct net_device *dev = info->user_ptr[1];
9315 u8 *pos, len, num_des, des_len, des;
9316 int ret;
9317
9318 if (!rdev->ops->set_qos_map)
9319 return -EOPNOTSUPP;
9320
9321 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9322 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9323 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9324
9325 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9326 len > IEEE80211_QOS_MAP_LEN_MAX)
9327 return -EINVAL;
9328
9329 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9330 if (!qos_map)
9331 return -ENOMEM;
9332
9333 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9334 if (num_des) {
9335 des_len = num_des *
9336 sizeof(struct cfg80211_dscp_exception);
9337 memcpy(qos_map->dscp_exception, pos, des_len);
9338 qos_map->num_des = num_des;
9339 for (des = 0; des < num_des; des++) {
9340 if (qos_map->dscp_exception[des].up > 7) {
9341 kfree(qos_map);
9342 return -EINVAL;
9343 }
9344 }
9345 pos += des_len;
9346 }
9347 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9348 }
9349
9350 wdev_lock(dev->ieee80211_ptr);
9351 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9352 if (!ret)
9353 ret = rdev_set_qos_map(rdev, dev, qos_map);
9354 wdev_unlock(dev->ieee80211_ptr);
9355
9356 kfree(qos_map);
9357 return ret;
9358}
9359
Johannes Berg4c476992010-10-04 21:36:35 +02009360#define NL80211_FLAG_NEED_WIPHY 0x01
9361#define NL80211_FLAG_NEED_NETDEV 0x02
9362#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009363#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9364#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9365 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009366#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009367/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009368#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9369 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009370
Johannes Bergf84f7712013-11-14 17:14:45 +01009371static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009372 struct genl_info *info)
9373{
9374 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009375 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009376 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009377 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9378
9379 if (rtnl)
9380 rtnl_lock();
9381
9382 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009383 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009384 if (IS_ERR(rdev)) {
9385 if (rtnl)
9386 rtnl_unlock();
9387 return PTR_ERR(rdev);
9388 }
9389 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009390 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9391 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009392 ASSERT_RTNL();
9393
Johannes Berg89a54e42012-06-15 14:33:17 +02009394 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9395 info->attrs);
9396 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009397 if (rtnl)
9398 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009399 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009400 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009401
Johannes Berg89a54e42012-06-15 14:33:17 +02009402 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009403 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009404
Johannes Berg1bf614e2012-06-15 15:23:36 +02009405 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9406 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009407 if (rtnl)
9408 rtnl_unlock();
9409 return -EINVAL;
9410 }
9411
9412 info->user_ptr[1] = dev;
9413 } else {
9414 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009415 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009416
Johannes Berg1bf614e2012-06-15 15:23:36 +02009417 if (dev) {
9418 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9419 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009420 if (rtnl)
9421 rtnl_unlock();
9422 return -ENETDOWN;
9423 }
9424
9425 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009426 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9427 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009428 if (rtnl)
9429 rtnl_unlock();
9430 return -ENETDOWN;
9431 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009432 }
9433
Johannes Berg4c476992010-10-04 21:36:35 +02009434 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009435 }
9436
9437 return 0;
9438}
9439
Johannes Bergf84f7712013-11-14 17:14:45 +01009440static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009441 struct genl_info *info)
9442{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009443 if (info->user_ptr[1]) {
9444 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9445 struct wireless_dev *wdev = info->user_ptr[1];
9446
9447 if (wdev->netdev)
9448 dev_put(wdev->netdev);
9449 } else {
9450 dev_put(info->user_ptr[1]);
9451 }
9452 }
Johannes Berg4c476992010-10-04 21:36:35 +02009453 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9454 rtnl_unlock();
9455}
9456
Johannes Berg4534de82013-11-14 17:14:46 +01009457static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009458 {
9459 .cmd = NL80211_CMD_GET_WIPHY,
9460 .doit = nl80211_get_wiphy,
9461 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009462 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009463 .policy = nl80211_policy,
9464 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009465 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9466 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009467 },
9468 {
9469 .cmd = NL80211_CMD_SET_WIPHY,
9470 .doit = nl80211_set_wiphy,
9471 .policy = nl80211_policy,
9472 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009473 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009474 },
9475 {
9476 .cmd = NL80211_CMD_GET_INTERFACE,
9477 .doit = nl80211_get_interface,
9478 .dumpit = nl80211_dump_interface,
9479 .policy = nl80211_policy,
9480 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009481 .internal_flags = NL80211_FLAG_NEED_WDEV |
9482 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009483 },
9484 {
9485 .cmd = NL80211_CMD_SET_INTERFACE,
9486 .doit = nl80211_set_interface,
9487 .policy = nl80211_policy,
9488 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009489 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9490 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009491 },
9492 {
9493 .cmd = NL80211_CMD_NEW_INTERFACE,
9494 .doit = nl80211_new_interface,
9495 .policy = nl80211_policy,
9496 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009497 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9498 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009499 },
9500 {
9501 .cmd = NL80211_CMD_DEL_INTERFACE,
9502 .doit = nl80211_del_interface,
9503 .policy = nl80211_policy,
9504 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009505 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009506 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009507 },
Johannes Berg41ade002007-12-19 02:03:29 +01009508 {
9509 .cmd = NL80211_CMD_GET_KEY,
9510 .doit = nl80211_get_key,
9511 .policy = nl80211_policy,
9512 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009513 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009514 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009515 },
9516 {
9517 .cmd = NL80211_CMD_SET_KEY,
9518 .doit = nl80211_set_key,
9519 .policy = nl80211_policy,
9520 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009521 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009522 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009523 },
9524 {
9525 .cmd = NL80211_CMD_NEW_KEY,
9526 .doit = nl80211_new_key,
9527 .policy = nl80211_policy,
9528 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009529 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009530 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009531 },
9532 {
9533 .cmd = NL80211_CMD_DEL_KEY,
9534 .doit = nl80211_del_key,
9535 .policy = nl80211_policy,
9536 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009537 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009538 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009539 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009540 {
9541 .cmd = NL80211_CMD_SET_BEACON,
9542 .policy = nl80211_policy,
9543 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009544 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009546 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009547 },
9548 {
Johannes Berg88600202012-02-13 15:17:18 +01009549 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009550 .policy = nl80211_policy,
9551 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009552 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009553 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009554 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009555 },
9556 {
Johannes Berg88600202012-02-13 15:17:18 +01009557 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009558 .policy = nl80211_policy,
9559 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009560 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009561 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009562 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009563 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009564 {
9565 .cmd = NL80211_CMD_GET_STATION,
9566 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009567 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009568 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009569 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9570 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009571 },
9572 {
9573 .cmd = NL80211_CMD_SET_STATION,
9574 .doit = nl80211_set_station,
9575 .policy = nl80211_policy,
9576 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009577 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009578 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009579 },
9580 {
9581 .cmd = NL80211_CMD_NEW_STATION,
9582 .doit = nl80211_new_station,
9583 .policy = nl80211_policy,
9584 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009585 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009586 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009587 },
9588 {
9589 .cmd = NL80211_CMD_DEL_STATION,
9590 .doit = nl80211_del_station,
9591 .policy = nl80211_policy,
9592 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009593 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009594 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009595 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009596 {
9597 .cmd = NL80211_CMD_GET_MPATH,
9598 .doit = nl80211_get_mpath,
9599 .dumpit = nl80211_dump_mpath,
9600 .policy = nl80211_policy,
9601 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009603 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009604 },
9605 {
9606 .cmd = NL80211_CMD_SET_MPATH,
9607 .doit = nl80211_set_mpath,
9608 .policy = nl80211_policy,
9609 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009611 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009612 },
9613 {
9614 .cmd = NL80211_CMD_NEW_MPATH,
9615 .doit = nl80211_new_mpath,
9616 .policy = nl80211_policy,
9617 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009618 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009619 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009620 },
9621 {
9622 .cmd = NL80211_CMD_DEL_MPATH,
9623 .doit = nl80211_del_mpath,
9624 .policy = nl80211_policy,
9625 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009626 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009627 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009628 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009629 {
9630 .cmd = NL80211_CMD_SET_BSS,
9631 .doit = nl80211_set_bss,
9632 .policy = nl80211_policy,
9633 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009634 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009635 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009636 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009637 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009638 .cmd = NL80211_CMD_GET_REG,
9639 .doit = nl80211_get_reg,
9640 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009641 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009642 /* can be retrieved by unprivileged users */
9643 },
9644 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009645 .cmd = NL80211_CMD_SET_REG,
9646 .doit = nl80211_set_reg,
9647 .policy = nl80211_policy,
9648 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009649 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009650 },
9651 {
9652 .cmd = NL80211_CMD_REQ_SET_REG,
9653 .doit = nl80211_req_set_reg,
9654 .policy = nl80211_policy,
9655 .flags = GENL_ADMIN_PERM,
9656 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009657 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009658 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9659 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009660 .policy = nl80211_policy,
9661 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009662 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009663 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009664 },
9665 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009666 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9667 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009668 .policy = nl80211_policy,
9669 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009670 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009671 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009672 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009673 {
Johannes Berg2a519312009-02-10 21:25:55 +01009674 .cmd = NL80211_CMD_TRIGGER_SCAN,
9675 .doit = nl80211_trigger_scan,
9676 .policy = nl80211_policy,
9677 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009678 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009679 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009680 },
9681 {
9682 .cmd = NL80211_CMD_GET_SCAN,
9683 .policy = nl80211_policy,
9684 .dumpit = nl80211_dump_scan,
9685 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009686 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009687 .cmd = NL80211_CMD_START_SCHED_SCAN,
9688 .doit = nl80211_start_sched_scan,
9689 .policy = nl80211_policy,
9690 .flags = GENL_ADMIN_PERM,
9691 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9692 NL80211_FLAG_NEED_RTNL,
9693 },
9694 {
9695 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9696 .doit = nl80211_stop_sched_scan,
9697 .policy = nl80211_policy,
9698 .flags = GENL_ADMIN_PERM,
9699 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9700 NL80211_FLAG_NEED_RTNL,
9701 },
9702 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009703 .cmd = NL80211_CMD_AUTHENTICATE,
9704 .doit = nl80211_authenticate,
9705 .policy = nl80211_policy,
9706 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009707 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009708 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009709 },
9710 {
9711 .cmd = NL80211_CMD_ASSOCIATE,
9712 .doit = nl80211_associate,
9713 .policy = nl80211_policy,
9714 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009715 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009716 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009717 },
9718 {
9719 .cmd = NL80211_CMD_DEAUTHENTICATE,
9720 .doit = nl80211_deauthenticate,
9721 .policy = nl80211_policy,
9722 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009723 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009724 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009725 },
9726 {
9727 .cmd = NL80211_CMD_DISASSOCIATE,
9728 .doit = nl80211_disassociate,
9729 .policy = nl80211_policy,
9730 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009731 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009732 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009733 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009734 {
9735 .cmd = NL80211_CMD_JOIN_IBSS,
9736 .doit = nl80211_join_ibss,
9737 .policy = nl80211_policy,
9738 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009739 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009740 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009741 },
9742 {
9743 .cmd = NL80211_CMD_LEAVE_IBSS,
9744 .doit = nl80211_leave_ibss,
9745 .policy = nl80211_policy,
9746 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009747 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009748 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009749 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009750#ifdef CONFIG_NL80211_TESTMODE
9751 {
9752 .cmd = NL80211_CMD_TESTMODE,
9753 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009754 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009755 .policy = nl80211_policy,
9756 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009757 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9758 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009759 },
9760#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009761 {
9762 .cmd = NL80211_CMD_CONNECT,
9763 .doit = nl80211_connect,
9764 .policy = nl80211_policy,
9765 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009766 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009767 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009768 },
9769 {
9770 .cmd = NL80211_CMD_DISCONNECT,
9771 .doit = nl80211_disconnect,
9772 .policy = nl80211_policy,
9773 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009774 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009775 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009776 },
Johannes Berg463d0182009-07-14 00:33:35 +02009777 {
9778 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9779 .doit = nl80211_wiphy_netns,
9780 .policy = nl80211_policy,
9781 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009782 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9783 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009784 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009785 {
9786 .cmd = NL80211_CMD_GET_SURVEY,
9787 .policy = nl80211_policy,
9788 .dumpit = nl80211_dump_survey,
9789 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009790 {
9791 .cmd = NL80211_CMD_SET_PMKSA,
9792 .doit = nl80211_setdel_pmksa,
9793 .policy = nl80211_policy,
9794 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009795 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009796 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009797 },
9798 {
9799 .cmd = NL80211_CMD_DEL_PMKSA,
9800 .doit = nl80211_setdel_pmksa,
9801 .policy = nl80211_policy,
9802 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009804 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009805 },
9806 {
9807 .cmd = NL80211_CMD_FLUSH_PMKSA,
9808 .doit = nl80211_flush_pmksa,
9809 .policy = nl80211_policy,
9810 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009812 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009813 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009814 {
9815 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9816 .doit = nl80211_remain_on_channel,
9817 .policy = nl80211_policy,
9818 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009819 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009820 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009821 },
9822 {
9823 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9824 .doit = nl80211_cancel_remain_on_channel,
9825 .policy = nl80211_policy,
9826 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009827 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009828 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009829 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009830 {
9831 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9832 .doit = nl80211_set_tx_bitrate_mask,
9833 .policy = nl80211_policy,
9834 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009835 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9836 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009837 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009838 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009839 .cmd = NL80211_CMD_REGISTER_FRAME,
9840 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009841 .policy = nl80211_policy,
9842 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009843 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009844 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009845 },
9846 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009847 .cmd = NL80211_CMD_FRAME,
9848 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009849 .policy = nl80211_policy,
9850 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009851 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009852 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009853 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009854 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009855 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9856 .doit = nl80211_tx_mgmt_cancel_wait,
9857 .policy = nl80211_policy,
9858 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009859 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009860 NL80211_FLAG_NEED_RTNL,
9861 },
9862 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009863 .cmd = NL80211_CMD_SET_POWER_SAVE,
9864 .doit = nl80211_set_power_save,
9865 .policy = nl80211_policy,
9866 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009867 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9868 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009869 },
9870 {
9871 .cmd = NL80211_CMD_GET_POWER_SAVE,
9872 .doit = nl80211_get_power_save,
9873 .policy = nl80211_policy,
9874 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009875 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9876 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009877 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009878 {
9879 .cmd = NL80211_CMD_SET_CQM,
9880 .doit = nl80211_set_cqm,
9881 .policy = nl80211_policy,
9882 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009883 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9884 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009885 },
Johannes Bergf444de02010-05-05 15:25:02 +02009886 {
9887 .cmd = NL80211_CMD_SET_CHANNEL,
9888 .doit = nl80211_set_channel,
9889 .policy = nl80211_policy,
9890 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009891 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9892 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009893 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009894 {
9895 .cmd = NL80211_CMD_SET_WDS_PEER,
9896 .doit = nl80211_set_wds_peer,
9897 .policy = nl80211_policy,
9898 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009899 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9900 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009901 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009902 {
9903 .cmd = NL80211_CMD_JOIN_MESH,
9904 .doit = nl80211_join_mesh,
9905 .policy = nl80211_policy,
9906 .flags = GENL_ADMIN_PERM,
9907 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9908 NL80211_FLAG_NEED_RTNL,
9909 },
9910 {
9911 .cmd = NL80211_CMD_LEAVE_MESH,
9912 .doit = nl80211_leave_mesh,
9913 .policy = nl80211_policy,
9914 .flags = GENL_ADMIN_PERM,
9915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9916 NL80211_FLAG_NEED_RTNL,
9917 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009918#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009919 {
9920 .cmd = NL80211_CMD_GET_WOWLAN,
9921 .doit = nl80211_get_wowlan,
9922 .policy = nl80211_policy,
9923 /* can be retrieved by unprivileged users */
9924 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9925 NL80211_FLAG_NEED_RTNL,
9926 },
9927 {
9928 .cmd = NL80211_CMD_SET_WOWLAN,
9929 .doit = nl80211_set_wowlan,
9930 .policy = nl80211_policy,
9931 .flags = GENL_ADMIN_PERM,
9932 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9933 NL80211_FLAG_NEED_RTNL,
9934 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009935#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009936 {
9937 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9938 .doit = nl80211_set_rekey_data,
9939 .policy = nl80211_policy,
9940 .flags = GENL_ADMIN_PERM,
9941 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9942 NL80211_FLAG_NEED_RTNL,
9943 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009944 {
9945 .cmd = NL80211_CMD_TDLS_MGMT,
9946 .doit = nl80211_tdls_mgmt,
9947 .policy = nl80211_policy,
9948 .flags = GENL_ADMIN_PERM,
9949 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9950 NL80211_FLAG_NEED_RTNL,
9951 },
9952 {
9953 .cmd = NL80211_CMD_TDLS_OPER,
9954 .doit = nl80211_tdls_oper,
9955 .policy = nl80211_policy,
9956 .flags = GENL_ADMIN_PERM,
9957 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9958 NL80211_FLAG_NEED_RTNL,
9959 },
Johannes Berg28946da2011-11-04 11:18:12 +01009960 {
9961 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9962 .doit = nl80211_register_unexpected_frame,
9963 .policy = nl80211_policy,
9964 .flags = GENL_ADMIN_PERM,
9965 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9966 NL80211_FLAG_NEED_RTNL,
9967 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009968 {
9969 .cmd = NL80211_CMD_PROBE_CLIENT,
9970 .doit = nl80211_probe_client,
9971 .policy = nl80211_policy,
9972 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009973 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009974 NL80211_FLAG_NEED_RTNL,
9975 },
Johannes Berg5e7602302011-11-04 11:18:17 +01009976 {
9977 .cmd = NL80211_CMD_REGISTER_BEACONS,
9978 .doit = nl80211_register_beacons,
9979 .policy = nl80211_policy,
9980 .flags = GENL_ADMIN_PERM,
9981 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9982 NL80211_FLAG_NEED_RTNL,
9983 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009984 {
9985 .cmd = NL80211_CMD_SET_NOACK_MAP,
9986 .doit = nl80211_set_noack_map,
9987 .policy = nl80211_policy,
9988 .flags = GENL_ADMIN_PERM,
9989 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9990 NL80211_FLAG_NEED_RTNL,
9991 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009992 {
9993 .cmd = NL80211_CMD_START_P2P_DEVICE,
9994 .doit = nl80211_start_p2p_device,
9995 .policy = nl80211_policy,
9996 .flags = GENL_ADMIN_PERM,
9997 .internal_flags = NL80211_FLAG_NEED_WDEV |
9998 NL80211_FLAG_NEED_RTNL,
9999 },
10000 {
10001 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10002 .doit = nl80211_stop_p2p_device,
10003 .policy = nl80211_policy,
10004 .flags = GENL_ADMIN_PERM,
10005 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10006 NL80211_FLAG_NEED_RTNL,
10007 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010008 {
10009 .cmd = NL80211_CMD_SET_MCAST_RATE,
10010 .doit = nl80211_set_mcast_rate,
10011 .policy = nl80211_policy,
10012 .flags = GENL_ADMIN_PERM,
10013 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10014 NL80211_FLAG_NEED_RTNL,
10015 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010016 {
10017 .cmd = NL80211_CMD_SET_MAC_ACL,
10018 .doit = nl80211_set_mac_acl,
10019 .policy = nl80211_policy,
10020 .flags = GENL_ADMIN_PERM,
10021 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10022 NL80211_FLAG_NEED_RTNL,
10023 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010024 {
10025 .cmd = NL80211_CMD_RADAR_DETECT,
10026 .doit = nl80211_start_radar_detection,
10027 .policy = nl80211_policy,
10028 .flags = GENL_ADMIN_PERM,
10029 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10030 NL80211_FLAG_NEED_RTNL,
10031 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010032 {
10033 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10034 .doit = nl80211_get_protocol_features,
10035 .policy = nl80211_policy,
10036 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010037 {
10038 .cmd = NL80211_CMD_UPDATE_FT_IES,
10039 .doit = nl80211_update_ft_ies,
10040 .policy = nl80211_policy,
10041 .flags = GENL_ADMIN_PERM,
10042 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10043 NL80211_FLAG_NEED_RTNL,
10044 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010045 {
10046 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10047 .doit = nl80211_crit_protocol_start,
10048 .policy = nl80211_policy,
10049 .flags = GENL_ADMIN_PERM,
10050 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10051 NL80211_FLAG_NEED_RTNL,
10052 },
10053 {
10054 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10055 .doit = nl80211_crit_protocol_stop,
10056 .policy = nl80211_policy,
10057 .flags = GENL_ADMIN_PERM,
10058 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10059 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010060 },
10061 {
10062 .cmd = NL80211_CMD_GET_COALESCE,
10063 .doit = nl80211_get_coalesce,
10064 .policy = nl80211_policy,
10065 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10066 NL80211_FLAG_NEED_RTNL,
10067 },
10068 {
10069 .cmd = NL80211_CMD_SET_COALESCE,
10070 .doit = nl80211_set_coalesce,
10071 .policy = nl80211_policy,
10072 .flags = GENL_ADMIN_PERM,
10073 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10074 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010075 },
10076 {
10077 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10078 .doit = nl80211_channel_switch,
10079 .policy = nl80211_policy,
10080 .flags = GENL_ADMIN_PERM,
10081 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10082 NL80211_FLAG_NEED_RTNL,
10083 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010084 {
10085 .cmd = NL80211_CMD_VENDOR,
10086 .doit = nl80211_vendor_cmd,
10087 .policy = nl80211_policy,
10088 .flags = GENL_ADMIN_PERM,
10089 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10090 NL80211_FLAG_NEED_RTNL,
10091 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010092 {
10093 .cmd = NL80211_CMD_SET_QOS_MAP,
10094 .doit = nl80211_set_qos_map,
10095 .policy = nl80211_policy,
10096 .flags = GENL_ADMIN_PERM,
10097 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10098 NL80211_FLAG_NEED_RTNL,
10099 },
Johannes Berg55682962007-09-20 13:09:35 -040010100};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010101
Johannes Berg55682962007-09-20 13:09:35 -040010102/* notification functions */
10103
Johannes Berg3bb20552014-05-26 13:52:25 +020010104void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10105 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010106{
10107 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010108 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010109
Johannes Berg3bb20552014-05-26 13:52:25 +020010110 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10111 cmd != NL80211_CMD_DEL_WIPHY);
10112
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010113 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010114 if (!msg)
10115 return;
10116
Johannes Berg3bb20552014-05-26 13:52:25 +020010117 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010118 nlmsg_free(msg);
10119 return;
10120 }
10121
Johannes Berg68eb5502013-11-19 15:19:38 +010010122 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010123 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010124}
10125
Johannes Berg362a4152009-05-24 16:43:15 +020010126static int nl80211_add_scan_req(struct sk_buff *msg,
10127 struct cfg80211_registered_device *rdev)
10128{
10129 struct cfg80211_scan_request *req = rdev->scan_req;
10130 struct nlattr *nest;
10131 int i;
10132
10133 if (WARN_ON(!req))
10134 return 0;
10135
10136 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10137 if (!nest)
10138 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010139 for (i = 0; i < req->n_ssids; i++) {
10140 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10141 goto nla_put_failure;
10142 }
Johannes Berg362a4152009-05-24 16:43:15 +020010143 nla_nest_end(msg, nest);
10144
10145 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10146 if (!nest)
10147 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010148 for (i = 0; i < req->n_channels; i++) {
10149 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10150 goto nla_put_failure;
10151 }
Johannes Berg362a4152009-05-24 16:43:15 +020010152 nla_nest_end(msg, nest);
10153
David S. Miller9360ffd2012-03-29 04:41:26 -040010154 if (req->ie &&
10155 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10156 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010157
Johannes Bergae917c92013-10-25 11:05:22 +020010158 if (req->flags &&
10159 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10160 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010161
Johannes Berg362a4152009-05-24 16:43:15 +020010162 return 0;
10163 nla_put_failure:
10164 return -ENOBUFS;
10165}
10166
Johannes Berga538e2d2009-06-16 19:56:42 +020010167static int nl80211_send_scan_msg(struct sk_buff *msg,
10168 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010169 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010170 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010171 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010172{
10173 void *hdr;
10174
Eric W. Biederman15e47302012-09-07 20:12:54 +000010175 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010176 if (!hdr)
10177 return -1;
10178
David S. Miller9360ffd2012-03-29 04:41:26 -040010179 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010180 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10181 wdev->netdev->ifindex)) ||
10182 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010183 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010184
Johannes Berg362a4152009-05-24 16:43:15 +020010185 /* ignore errors and send incomplete event anyway */
10186 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010187
10188 return genlmsg_end(msg, hdr);
10189
10190 nla_put_failure:
10191 genlmsg_cancel(msg, hdr);
10192 return -EMSGSIZE;
10193}
10194
Luciano Coelho807f8a82011-05-11 17:09:35 +030010195static int
10196nl80211_send_sched_scan_msg(struct sk_buff *msg,
10197 struct cfg80211_registered_device *rdev,
10198 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010199 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010200{
10201 void *hdr;
10202
Eric W. Biederman15e47302012-09-07 20:12:54 +000010203 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010204 if (!hdr)
10205 return -1;
10206
David S. Miller9360ffd2012-03-29 04:41:26 -040010207 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10208 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10209 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010210
10211 return genlmsg_end(msg, hdr);
10212
10213 nla_put_failure:
10214 genlmsg_cancel(msg, hdr);
10215 return -EMSGSIZE;
10216}
10217
Johannes Berga538e2d2009-06-16 19:56:42 +020010218void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010219 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010220{
10221 struct sk_buff *msg;
10222
Thomas Graf58050fc2012-06-28 03:57:45 +000010223 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010224 if (!msg)
10225 return;
10226
Johannes Bergfd014282012-06-18 19:17:03 +020010227 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010228 NL80211_CMD_TRIGGER_SCAN) < 0) {
10229 nlmsg_free(msg);
10230 return;
10231 }
10232
Johannes Berg68eb5502013-11-19 15:19:38 +010010233 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010234 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010235}
10236
Johannes Bergf9d15d12014-01-22 11:14:19 +020010237struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10238 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010239{
10240 struct sk_buff *msg;
10241
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010243 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010244 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010245
Johannes Bergfd014282012-06-18 19:17:03 +020010246 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010247 aborted ? NL80211_CMD_SCAN_ABORTED :
10248 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010249 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010250 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010251 }
10252
Johannes Bergf9d15d12014-01-22 11:14:19 +020010253 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010254}
10255
Johannes Bergf9d15d12014-01-22 11:14:19 +020010256void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10257 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010258{
Johannes Berg2a519312009-02-10 21:25:55 +010010259 if (!msg)
10260 return;
10261
Johannes Berg68eb5502013-11-19 15:19:38 +010010262 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010263 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010264}
10265
Luciano Coelho807f8a82011-05-11 17:09:35 +030010266void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10267 struct net_device *netdev)
10268{
10269 struct sk_buff *msg;
10270
10271 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10272 if (!msg)
10273 return;
10274
10275 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10276 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10277 nlmsg_free(msg);
10278 return;
10279 }
10280
Johannes Berg68eb5502013-11-19 15:19:38 +010010281 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010282 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010283}
10284
10285void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10286 struct net_device *netdev, u32 cmd)
10287{
10288 struct sk_buff *msg;
10289
Thomas Graf58050fc2012-06-28 03:57:45 +000010290 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010291 if (!msg)
10292 return;
10293
10294 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10295 nlmsg_free(msg);
10296 return;
10297 }
10298
Johannes Berg68eb5502013-11-19 15:19:38 +010010299 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010300 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010301}
10302
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010303/*
10304 * This can happen on global regulatory changes or device specific settings
10305 * based on custom world regulatory domains.
10306 */
10307void nl80211_send_reg_change_event(struct regulatory_request *request)
10308{
10309 struct sk_buff *msg;
10310 void *hdr;
10311
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010312 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010313 if (!msg)
10314 return;
10315
10316 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10317 if (!hdr) {
10318 nlmsg_free(msg);
10319 return;
10320 }
10321
10322 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010323 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10324 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010325
David S. Miller9360ffd2012-03-29 04:41:26 -040010326 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10327 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10328 NL80211_REGDOM_TYPE_WORLD))
10329 goto nla_put_failure;
10330 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10331 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10332 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10333 goto nla_put_failure;
10334 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10335 request->intersect) {
10336 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10337 NL80211_REGDOM_TYPE_INTERSECTION))
10338 goto nla_put_failure;
10339 } else {
10340 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10341 NL80211_REGDOM_TYPE_COUNTRY) ||
10342 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10343 request->alpha2))
10344 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010345 }
10346
Johannes Bergf4173762012-12-03 18:23:37 +010010347 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010348 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10349 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010350
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010351 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010352
Johannes Bergbc43b282009-07-25 10:54:13 +020010353 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010354 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010355 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010356 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010357
10358 return;
10359
10360nla_put_failure:
10361 genlmsg_cancel(msg, hdr);
10362 nlmsg_free(msg);
10363}
10364
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010365static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10366 struct net_device *netdev,
10367 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010368 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010369{
10370 struct sk_buff *msg;
10371 void *hdr;
10372
Johannes Berge6d6e342009-07-01 21:26:47 +020010373 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010374 if (!msg)
10375 return;
10376
10377 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10378 if (!hdr) {
10379 nlmsg_free(msg);
10380 return;
10381 }
10382
David S. Miller9360ffd2012-03-29 04:41:26 -040010383 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10384 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10385 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10386 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010387
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010388 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010389
Johannes Berg68eb5502013-11-19 15:19:38 +010010390 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010391 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010392 return;
10393
10394 nla_put_failure:
10395 genlmsg_cancel(msg, hdr);
10396 nlmsg_free(msg);
10397}
10398
10399void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010400 struct net_device *netdev, const u8 *buf,
10401 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010402{
10403 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010404 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010405}
10406
10407void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10408 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010409 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010410{
Johannes Berge6d6e342009-07-01 21:26:47 +020010411 nl80211_send_mlme_event(rdev, netdev, buf, len,
10412 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010413}
10414
Jouni Malinen53b46b82009-03-27 20:53:56 +020010415void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010416 struct net_device *netdev, const u8 *buf,
10417 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010418{
10419 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010420 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010421}
10422
Jouni Malinen53b46b82009-03-27 20:53:56 +020010423void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10424 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010425 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010426{
10427 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010428 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010429}
10430
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010431void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10432 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010433{
Johannes Berg947add32013-02-22 22:05:20 +010010434 struct wireless_dev *wdev = dev->ieee80211_ptr;
10435 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010436 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010437 const struct ieee80211_mgmt *mgmt = (void *)buf;
10438 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010439
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010440 if (WARN_ON(len < 2))
10441 return;
10442
10443 if (ieee80211_is_deauth(mgmt->frame_control))
10444 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10445 else
10446 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10447
10448 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10449 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010450}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010451EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010452
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010453static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10454 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010455 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010456{
10457 struct sk_buff *msg;
10458 void *hdr;
10459
Johannes Berge6d6e342009-07-01 21:26:47 +020010460 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010461 if (!msg)
10462 return;
10463
10464 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10465 if (!hdr) {
10466 nlmsg_free(msg);
10467 return;
10468 }
10469
David S. Miller9360ffd2012-03-29 04:41:26 -040010470 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10471 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10472 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10473 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10474 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010475
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010476 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010477
Johannes Berg68eb5502013-11-19 15:19:38 +010010478 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010479 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010480 return;
10481
10482 nla_put_failure:
10483 genlmsg_cancel(msg, hdr);
10484 nlmsg_free(msg);
10485}
10486
10487void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010488 struct net_device *netdev, const u8 *addr,
10489 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010490{
10491 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010492 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010493}
10494
10495void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010496 struct net_device *netdev, const u8 *addr,
10497 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010498{
Johannes Berge6d6e342009-07-01 21:26:47 +020010499 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10500 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010501}
10502
Samuel Ortizb23aa672009-07-01 21:26:54 +020010503void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10504 struct net_device *netdev, const u8 *bssid,
10505 const u8 *req_ie, size_t req_ie_len,
10506 const u8 *resp_ie, size_t resp_ie_len,
10507 u16 status, gfp_t gfp)
10508{
10509 struct sk_buff *msg;
10510 void *hdr;
10511
Thomas Graf58050fc2012-06-28 03:57:45 +000010512 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010513 if (!msg)
10514 return;
10515
10516 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10517 if (!hdr) {
10518 nlmsg_free(msg);
10519 return;
10520 }
10521
David S. Miller9360ffd2012-03-29 04:41:26 -040010522 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10523 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10524 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10525 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10526 (req_ie &&
10527 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10528 (resp_ie &&
10529 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10530 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010531
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010532 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010533
Johannes Berg68eb5502013-11-19 15:19:38 +010010534 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010535 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010536 return;
10537
10538 nla_put_failure:
10539 genlmsg_cancel(msg, hdr);
10540 nlmsg_free(msg);
10541
10542}
10543
10544void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10545 struct net_device *netdev, const u8 *bssid,
10546 const u8 *req_ie, size_t req_ie_len,
10547 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10548{
10549 struct sk_buff *msg;
10550 void *hdr;
10551
Thomas Graf58050fc2012-06-28 03:57:45 +000010552 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010553 if (!msg)
10554 return;
10555
10556 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10557 if (!hdr) {
10558 nlmsg_free(msg);
10559 return;
10560 }
10561
David S. Miller9360ffd2012-03-29 04:41:26 -040010562 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10563 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10564 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10565 (req_ie &&
10566 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10567 (resp_ie &&
10568 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10569 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010570
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010571 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +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);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010575 return;
10576
10577 nla_put_failure:
10578 genlmsg_cancel(msg, hdr);
10579 nlmsg_free(msg);
10580
10581}
10582
10583void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10584 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010585 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010586{
10587 struct sk_buff *msg;
10588 void *hdr;
10589
Thomas Graf58050fc2012-06-28 03:57:45 +000010590 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010591 if (!msg)
10592 return;
10593
10594 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10595 if (!hdr) {
10596 nlmsg_free(msg);
10597 return;
10598 }
10599
David S. Miller9360ffd2012-03-29 04:41:26 -040010600 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10601 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10602 (from_ap && reason &&
10603 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10604 (from_ap &&
10605 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10606 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10607 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010608
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010609 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010610
Johannes Berg68eb5502013-11-19 15:19:38 +010010611 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010612 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010613 return;
10614
10615 nla_put_failure:
10616 genlmsg_cancel(msg, hdr);
10617 nlmsg_free(msg);
10618
10619}
10620
Johannes Berg04a773a2009-04-19 21:24:32 +020010621void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10622 struct net_device *netdev, const u8 *bssid,
10623 gfp_t gfp)
10624{
10625 struct sk_buff *msg;
10626 void *hdr;
10627
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010628 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010629 if (!msg)
10630 return;
10631
10632 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10633 if (!hdr) {
10634 nlmsg_free(msg);
10635 return;
10636 }
10637
David S. Miller9360ffd2012-03-29 04:41:26 -040010638 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10639 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10640 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10641 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010642
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010643 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010644
Johannes Berg68eb5502013-11-19 15:19:38 +010010645 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010646 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010647 return;
10648
10649 nla_put_failure:
10650 genlmsg_cancel(msg, hdr);
10651 nlmsg_free(msg);
10652}
10653
Johannes Berg947add32013-02-22 22:05:20 +010010654void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10655 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010656{
Johannes Berg947add32013-02-22 22:05:20 +010010657 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010658 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010659 struct sk_buff *msg;
10660 void *hdr;
10661
Johannes Berg947add32013-02-22 22:05:20 +010010662 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10663 return;
10664
10665 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10666
Javier Cardonac93b5e72011-04-07 15:08:34 -070010667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10668 if (!msg)
10669 return;
10670
10671 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10672 if (!hdr) {
10673 nlmsg_free(msg);
10674 return;
10675 }
10676
David S. Miller9360ffd2012-03-29 04:41:26 -040010677 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010678 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10679 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010680 (ie_len && ie &&
10681 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10682 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010683
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010684 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010685
Johannes Berg68eb5502013-11-19 15:19:38 +010010686 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010687 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010688 return;
10689
10690 nla_put_failure:
10691 genlmsg_cancel(msg, hdr);
10692 nlmsg_free(msg);
10693}
Johannes Berg947add32013-02-22 22:05:20 +010010694EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010695
Jouni Malinena3b8b052009-03-27 21:59:49 +020010696void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10697 struct net_device *netdev, const u8 *addr,
10698 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010699 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010700{
10701 struct sk_buff *msg;
10702 void *hdr;
10703
Johannes Berge6d6e342009-07-01 21:26:47 +020010704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010705 if (!msg)
10706 return;
10707
10708 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10709 if (!hdr) {
10710 nlmsg_free(msg);
10711 return;
10712 }
10713
David S. Miller9360ffd2012-03-29 04:41:26 -040010714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10716 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10717 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10718 (key_id != -1 &&
10719 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10720 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10721 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010722
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010723 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010724
Johannes Berg68eb5502013-11-19 15:19:38 +010010725 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010726 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010727 return;
10728
10729 nla_put_failure:
10730 genlmsg_cancel(msg, hdr);
10731 nlmsg_free(msg);
10732}
10733
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010734void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10735 struct ieee80211_channel *channel_before,
10736 struct ieee80211_channel *channel_after)
10737{
10738 struct sk_buff *msg;
10739 void *hdr;
10740 struct nlattr *nl_freq;
10741
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010743 if (!msg)
10744 return;
10745
10746 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10747 if (!hdr) {
10748 nlmsg_free(msg);
10749 return;
10750 }
10751
10752 /*
10753 * Since we are applying the beacon hint to a wiphy we know its
10754 * wiphy_idx is valid
10755 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010756 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10757 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010758
10759 /* Before */
10760 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10761 if (!nl_freq)
10762 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010763 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010764 goto nla_put_failure;
10765 nla_nest_end(msg, nl_freq);
10766
10767 /* After */
10768 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10769 if (!nl_freq)
10770 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010771 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010772 goto nla_put_failure;
10773 nla_nest_end(msg, nl_freq);
10774
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010775 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010776
Johannes Berg463d0182009-07-14 00:33:35 +020010777 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010778 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010779 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010780 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010781
10782 return;
10783
10784nla_put_failure:
10785 genlmsg_cancel(msg, hdr);
10786 nlmsg_free(msg);
10787}
10788
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010789static void nl80211_send_remain_on_chan_event(
10790 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010791 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010792 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010793 unsigned int duration, gfp_t gfp)
10794{
10795 struct sk_buff *msg;
10796 void *hdr;
10797
10798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10799 if (!msg)
10800 return;
10801
10802 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10803 if (!hdr) {
10804 nlmsg_free(msg);
10805 return;
10806 }
10807
David S. Miller9360ffd2012-03-29 04:41:26 -040010808 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010809 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10810 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010811 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010812 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010813 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10814 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010815 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10816 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010817
David S. Miller9360ffd2012-03-29 04:41:26 -040010818 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10819 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10820 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010821
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010822 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010823
Johannes Berg68eb5502013-11-19 15:19:38 +010010824 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010825 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010826 return;
10827
10828 nla_put_failure:
10829 genlmsg_cancel(msg, hdr);
10830 nlmsg_free(msg);
10831}
10832
Johannes Berg947add32013-02-22 22:05:20 +010010833void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10834 struct ieee80211_channel *chan,
10835 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010836{
Johannes Berg947add32013-02-22 22:05:20 +010010837 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010838 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010839
10840 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010841 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010842 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010843 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010844}
Johannes Berg947add32013-02-22 22:05:20 +010010845EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010846
Johannes Berg947add32013-02-22 22:05:20 +010010847void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10848 struct ieee80211_channel *chan,
10849 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010850{
Johannes Berg947add32013-02-22 22:05:20 +010010851 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010852 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010853
10854 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010855 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010856 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010857}
Johannes Berg947add32013-02-22 22:05:20 +010010858EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010859
Johannes Berg947add32013-02-22 22:05:20 +010010860void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10861 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010862{
Johannes Berg947add32013-02-22 22:05:20 +010010863 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010864 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010865 struct sk_buff *msg;
10866
Johannes Berg947add32013-02-22 22:05:20 +010010867 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10868
Thomas Graf58050fc2012-06-28 03:57:45 +000010869 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010870 if (!msg)
10871 return;
10872
John W. Linville66266b32012-03-15 13:25:41 -040010873 if (nl80211_send_station(msg, 0, 0, 0,
10874 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010875 nlmsg_free(msg);
10876 return;
10877 }
10878
Johannes Berg68eb5502013-11-19 15:19:38 +010010879 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010880 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010881}
Johannes Berg947add32013-02-22 22:05:20 +010010882EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010883
Johannes Berg947add32013-02-22 22:05:20 +010010884void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010885{
Johannes Berg947add32013-02-22 22:05:20 +010010886 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010887 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010888 struct sk_buff *msg;
10889 void *hdr;
10890
Johannes Berg947add32013-02-22 22:05:20 +010010891 trace_cfg80211_del_sta(dev, mac_addr);
10892
Thomas Graf58050fc2012-06-28 03:57:45 +000010893 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010894 if (!msg)
10895 return;
10896
10897 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10898 if (!hdr) {
10899 nlmsg_free(msg);
10900 return;
10901 }
10902
David S. Miller9360ffd2012-03-29 04:41:26 -040010903 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10904 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10905 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010906
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010907 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010908
Johannes Berg68eb5502013-11-19 15:19:38 +010010909 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010910 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010911 return;
10912
10913 nla_put_failure:
10914 genlmsg_cancel(msg, hdr);
10915 nlmsg_free(msg);
10916}
Johannes Berg947add32013-02-22 22:05:20 +010010917EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010918
Johannes Berg947add32013-02-22 22:05:20 +010010919void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10920 enum nl80211_connect_failed_reason reason,
10921 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010922{
Johannes Berg947add32013-02-22 22:05:20 +010010923 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010924 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010925 struct sk_buff *msg;
10926 void *hdr;
10927
10928 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10929 if (!msg)
10930 return;
10931
10932 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10933 if (!hdr) {
10934 nlmsg_free(msg);
10935 return;
10936 }
10937
10938 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10939 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10940 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10941 goto nla_put_failure;
10942
10943 genlmsg_end(msg, hdr);
10944
Johannes Berg68eb5502013-11-19 15:19:38 +010010945 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010946 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010947 return;
10948
10949 nla_put_failure:
10950 genlmsg_cancel(msg, hdr);
10951 nlmsg_free(msg);
10952}
Johannes Berg947add32013-02-22 22:05:20 +010010953EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010954
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010955static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10956 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010957{
10958 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010959 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010960 struct sk_buff *msg;
10961 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010962 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010963
Eric W. Biederman15e47302012-09-07 20:12:54 +000010964 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010965 return false;
10966
10967 msg = nlmsg_new(100, gfp);
10968 if (!msg)
10969 return true;
10970
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010971 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010972 if (!hdr) {
10973 nlmsg_free(msg);
10974 return true;
10975 }
10976
David S. Miller9360ffd2012-03-29 04:41:26 -040010977 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10978 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10979 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10980 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010981
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010982 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010983 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010984 return true;
10985
10986 nla_put_failure:
10987 genlmsg_cancel(msg, hdr);
10988 nlmsg_free(msg);
10989 return true;
10990}
10991
Johannes Berg947add32013-02-22 22:05:20 +010010992bool cfg80211_rx_spurious_frame(struct net_device *dev,
10993 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010994{
Johannes Berg947add32013-02-22 22:05:20 +010010995 struct wireless_dev *wdev = dev->ieee80211_ptr;
10996 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010997
Johannes Berg947add32013-02-22 22:05:20 +010010998 trace_cfg80211_rx_spurious_frame(dev, addr);
10999
11000 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11001 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11002 trace_cfg80211_return_bool(false);
11003 return false;
11004 }
11005 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11006 addr, gfp);
11007 trace_cfg80211_return_bool(ret);
11008 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011009}
Johannes Berg947add32013-02-22 22:05:20 +010011010EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11011
11012bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11013 const u8 *addr, gfp_t gfp)
11014{
11015 struct wireless_dev *wdev = dev->ieee80211_ptr;
11016 bool ret;
11017
11018 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11019
11020 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11021 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11022 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11023 trace_cfg80211_return_bool(false);
11024 return false;
11025 }
11026 ret = __nl80211_unexpected_frame(dev,
11027 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11028 addr, gfp);
11029 trace_cfg80211_return_bool(ret);
11030 return ret;
11031}
11032EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011033
Johannes Berg2e161f72010-08-12 15:38:38 +020011034int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011035 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011036 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011037 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011038{
Johannes Berg71bbc992012-06-15 15:30:18 +020011039 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011040 struct sk_buff *msg;
11041 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011042
11043 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11044 if (!msg)
11045 return -ENOMEM;
11046
Johannes Berg2e161f72010-08-12 15:38:38 +020011047 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011048 if (!hdr) {
11049 nlmsg_free(msg);
11050 return -ENOMEM;
11051 }
11052
David S. Miller9360ffd2012-03-29 04:41:26 -040011053 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011054 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11055 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011056 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011057 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11058 (sig_dbm &&
11059 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011060 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11061 (flags &&
11062 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011063 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011064
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011065 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011066
Eric W. Biederman15e47302012-09-07 20:12:54 +000011067 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011068
11069 nla_put_failure:
11070 genlmsg_cancel(msg, hdr);
11071 nlmsg_free(msg);
11072 return -ENOBUFS;
11073}
11074
Johannes Berg947add32013-02-22 22:05:20 +010011075void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11076 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011077{
Johannes Berg947add32013-02-22 22:05:20 +010011078 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011079 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011080 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011081 struct sk_buff *msg;
11082 void *hdr;
11083
Johannes Berg947add32013-02-22 22:05:20 +010011084 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11085
Jouni Malinen026331c2010-02-15 12:53:10 +020011086 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11087 if (!msg)
11088 return;
11089
Johannes Berg2e161f72010-08-12 15:38:38 +020011090 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011091 if (!hdr) {
11092 nlmsg_free(msg);
11093 return;
11094 }
11095
David S. Miller9360ffd2012-03-29 04:41:26 -040011096 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011097 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11098 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011099 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011100 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11101 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11102 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11103 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011104
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011105 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011106
Johannes Berg68eb5502013-11-19 15:19:38 +010011107 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011108 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011109 return;
11110
11111 nla_put_failure:
11112 genlmsg_cancel(msg, hdr);
11113 nlmsg_free(msg);
11114}
Johannes Berg947add32013-02-22 22:05:20 +010011115EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011116
Johannes Berg947add32013-02-22 22:05:20 +010011117void cfg80211_cqm_rssi_notify(struct net_device *dev,
11118 enum nl80211_cqm_rssi_threshold_event rssi_event,
11119 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011120{
Johannes Berg947add32013-02-22 22:05:20 +010011121 struct wireless_dev *wdev = dev->ieee80211_ptr;
11122 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011123 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011124 struct sk_buff *msg;
11125 struct nlattr *pinfoattr;
11126 void *hdr;
11127
Johannes Berg947add32013-02-22 22:05:20 +010011128 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11129
Thomas Graf58050fc2012-06-28 03:57:45 +000011130 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011131 if (!msg)
11132 return;
11133
11134 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11135 if (!hdr) {
11136 nlmsg_free(msg);
11137 return;
11138 }
11139
David S. Miller9360ffd2012-03-29 04:41:26 -040011140 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011141 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011142 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011143
11144 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11145 if (!pinfoattr)
11146 goto nla_put_failure;
11147
David S. Miller9360ffd2012-03-29 04:41:26 -040011148 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11149 rssi_event))
11150 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011151
11152 nla_nest_end(msg, pinfoattr);
11153
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011154 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011155
Johannes Berg68eb5502013-11-19 15:19:38 +010011156 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011157 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011158 return;
11159
11160 nla_put_failure:
11161 genlmsg_cancel(msg, hdr);
11162 nlmsg_free(msg);
11163}
Johannes Berg947add32013-02-22 22:05:20 +010011164EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011165
Johannes Berg947add32013-02-22 22:05:20 +010011166static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11167 struct net_device *netdev, const u8 *bssid,
11168 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011169{
11170 struct sk_buff *msg;
11171 struct nlattr *rekey_attr;
11172 void *hdr;
11173
Thomas Graf58050fc2012-06-28 03:57:45 +000011174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011175 if (!msg)
11176 return;
11177
11178 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11179 if (!hdr) {
11180 nlmsg_free(msg);
11181 return;
11182 }
11183
David S. Miller9360ffd2012-03-29 04:41:26 -040011184 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11185 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11186 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11187 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011188
11189 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11190 if (!rekey_attr)
11191 goto nla_put_failure;
11192
David S. Miller9360ffd2012-03-29 04:41:26 -040011193 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11194 NL80211_REPLAY_CTR_LEN, replay_ctr))
11195 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011196
11197 nla_nest_end(msg, rekey_attr);
11198
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011199 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011200
Johannes Berg68eb5502013-11-19 15:19:38 +010011201 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011202 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011203 return;
11204
11205 nla_put_failure:
11206 genlmsg_cancel(msg, hdr);
11207 nlmsg_free(msg);
11208}
11209
Johannes Berg947add32013-02-22 22:05:20 +010011210void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11211 const u8 *replay_ctr, gfp_t gfp)
11212{
11213 struct wireless_dev *wdev = dev->ieee80211_ptr;
11214 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011215 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011216
11217 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11218 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11219}
11220EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11221
11222static void
11223nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11224 struct net_device *netdev, int index,
11225 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011226{
11227 struct sk_buff *msg;
11228 struct nlattr *attr;
11229 void *hdr;
11230
Thomas Graf58050fc2012-06-28 03:57:45 +000011231 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011232 if (!msg)
11233 return;
11234
11235 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11236 if (!hdr) {
11237 nlmsg_free(msg);
11238 return;
11239 }
11240
David S. Miller9360ffd2012-03-29 04:41:26 -040011241 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11242 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11243 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011244
11245 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11246 if (!attr)
11247 goto nla_put_failure;
11248
David S. Miller9360ffd2012-03-29 04:41:26 -040011249 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11250 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11251 (preauth &&
11252 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11253 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011254
11255 nla_nest_end(msg, attr);
11256
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011257 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011258
Johannes Berg68eb5502013-11-19 15:19:38 +010011259 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011260 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011261 return;
11262
11263 nla_put_failure:
11264 genlmsg_cancel(msg, hdr);
11265 nlmsg_free(msg);
11266}
11267
Johannes Berg947add32013-02-22 22:05:20 +010011268void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11269 const u8 *bssid, bool preauth, gfp_t gfp)
11270{
11271 struct wireless_dev *wdev = dev->ieee80211_ptr;
11272 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011273 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011274
11275 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11276 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11277}
11278EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11279
11280static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11281 struct net_device *netdev,
11282 struct cfg80211_chan_def *chandef,
11283 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011284{
11285 struct sk_buff *msg;
11286 void *hdr;
11287
Thomas Graf58050fc2012-06-28 03:57:45 +000011288 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011289 if (!msg)
11290 return;
11291
11292 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11293 if (!hdr) {
11294 nlmsg_free(msg);
11295 return;
11296 }
11297
Johannes Berg683b6d32012-11-08 21:25:48 +010011298 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11299 goto nla_put_failure;
11300
11301 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011302 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011303
11304 genlmsg_end(msg, hdr);
11305
Johannes Berg68eb5502013-11-19 15:19:38 +010011306 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011307 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011308 return;
11309
11310 nla_put_failure:
11311 genlmsg_cancel(msg, hdr);
11312 nlmsg_free(msg);
11313}
11314
Johannes Berg947add32013-02-22 22:05:20 +010011315void cfg80211_ch_switch_notify(struct net_device *dev,
11316 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011317{
Johannes Berg947add32013-02-22 22:05:20 +010011318 struct wireless_dev *wdev = dev->ieee80211_ptr;
11319 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011320 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011321
Simon Wunderliche487eae2013-11-21 18:19:51 +010011322 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011323
Simon Wunderliche487eae2013-11-21 18:19:51 +010011324 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011325
11326 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011327 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011328 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11329 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011330 return;
Johannes Berg947add32013-02-22 22:05:20 +010011331
Michal Kazior9e0e2962014-01-29 14:22:27 +010011332 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011333 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011334 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011335}
11336EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11337
11338void cfg80211_cqm_txe_notify(struct net_device *dev,
11339 const u8 *peer, u32 num_packets,
11340 u32 rate, u32 intvl, gfp_t gfp)
11341{
11342 struct wireless_dev *wdev = dev->ieee80211_ptr;
11343 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011344 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011345 struct sk_buff *msg;
11346 struct nlattr *pinfoattr;
11347 void *hdr;
11348
11349 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11350 if (!msg)
11351 return;
11352
11353 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11354 if (!hdr) {
11355 nlmsg_free(msg);
11356 return;
11357 }
11358
11359 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011360 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011361 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11362 goto nla_put_failure;
11363
11364 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11365 if (!pinfoattr)
11366 goto nla_put_failure;
11367
11368 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11369 goto nla_put_failure;
11370
11371 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11372 goto nla_put_failure;
11373
11374 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11375 goto nla_put_failure;
11376
11377 nla_nest_end(msg, pinfoattr);
11378
11379 genlmsg_end(msg, hdr);
11380
Johannes Berg68eb5502013-11-19 15:19:38 +010011381 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011382 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011383 return;
11384
11385 nla_put_failure:
11386 genlmsg_cancel(msg, hdr);
11387 nlmsg_free(msg);
11388}
Johannes Berg947add32013-02-22 22:05:20 +010011389EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011390
11391void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011392nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011393 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011394 enum nl80211_radar_event event,
11395 struct net_device *netdev, gfp_t gfp)
11396{
11397 struct sk_buff *msg;
11398 void *hdr;
11399
11400 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11401 if (!msg)
11402 return;
11403
11404 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11405 if (!hdr) {
11406 nlmsg_free(msg);
11407 return;
11408 }
11409
11410 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11411 goto nla_put_failure;
11412
11413 /* NOP and radar events don't need a netdev parameter */
11414 if (netdev) {
11415 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11416
11417 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11418 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11419 goto nla_put_failure;
11420 }
11421
11422 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11423 goto nla_put_failure;
11424
11425 if (nl80211_send_chandef(msg, chandef))
11426 goto nla_put_failure;
11427
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011428 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011429
Johannes Berg68eb5502013-11-19 15:19:38 +010011430 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011431 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011432 return;
11433
11434 nla_put_failure:
11435 genlmsg_cancel(msg, hdr);
11436 nlmsg_free(msg);
11437}
11438
Johannes Berg947add32013-02-22 22:05:20 +010011439void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11440 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011441{
Johannes Berg947add32013-02-22 22:05:20 +010011442 struct wireless_dev *wdev = dev->ieee80211_ptr;
11443 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011444 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011445 struct sk_buff *msg;
11446 struct nlattr *pinfoattr;
11447 void *hdr;
11448
Johannes Berg947add32013-02-22 22:05:20 +010011449 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11450
Thomas Graf58050fc2012-06-28 03:57:45 +000011451 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011452 if (!msg)
11453 return;
11454
11455 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11456 if (!hdr) {
11457 nlmsg_free(msg);
11458 return;
11459 }
11460
David S. Miller9360ffd2012-03-29 04:41:26 -040011461 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011462 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011463 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11464 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011465
11466 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11467 if (!pinfoattr)
11468 goto nla_put_failure;
11469
David S. Miller9360ffd2012-03-29 04:41:26 -040011470 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11471 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011472
11473 nla_nest_end(msg, pinfoattr);
11474
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011475 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011476
Johannes Berg68eb5502013-11-19 15:19:38 +010011477 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011478 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011479 return;
11480
11481 nla_put_failure:
11482 genlmsg_cancel(msg, hdr);
11483 nlmsg_free(msg);
11484}
Johannes Berg947add32013-02-22 22:05:20 +010011485EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011486
Johannes Berg7f6cf312011-11-04 11:18:15 +010011487void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11488 u64 cookie, bool acked, gfp_t gfp)
11489{
11490 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011491 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011492 struct sk_buff *msg;
11493 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011494
Beni Lev4ee3e062012-08-27 12:49:39 +030011495 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11496
Thomas Graf58050fc2012-06-28 03:57:45 +000011497 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011498
Johannes Berg7f6cf312011-11-04 11:18:15 +010011499 if (!msg)
11500 return;
11501
11502 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11503 if (!hdr) {
11504 nlmsg_free(msg);
11505 return;
11506 }
11507
David S. Miller9360ffd2012-03-29 04:41:26 -040011508 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11509 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11510 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11511 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11512 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11513 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011514
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011515 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011516
Johannes Berg68eb5502013-11-19 15:19:38 +010011517 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011518 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011519 return;
11520
11521 nla_put_failure:
11522 genlmsg_cancel(msg, hdr);
11523 nlmsg_free(msg);
11524}
11525EXPORT_SYMBOL(cfg80211_probe_status);
11526
Johannes Berg5e7602302011-11-04 11:18:17 +010011527void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11528 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011529 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010011530{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011531 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010011532 struct sk_buff *msg;
11533 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011534 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010011535
Beni Lev4ee3e062012-08-27 12:49:39 +030011536 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11537
Ben Greear37c73b52012-10-26 14:49:25 -070011538 spin_lock_bh(&rdev->beacon_registrations_lock);
11539 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11540 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11541 if (!msg) {
11542 spin_unlock_bh(&rdev->beacon_registrations_lock);
11543 return;
11544 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011545
Ben Greear37c73b52012-10-26 14:49:25 -070011546 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11547 if (!hdr)
11548 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010011549
Ben Greear37c73b52012-10-26 14:49:25 -070011550 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11551 (freq &&
11552 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11553 (sig_dbm &&
11554 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11555 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11556 goto nla_put_failure;
11557
11558 genlmsg_end(msg, hdr);
11559
11560 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010011561 }
Ben Greear37c73b52012-10-26 14:49:25 -070011562 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011563 return;
11564
11565 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011566 spin_unlock_bh(&rdev->beacon_registrations_lock);
11567 if (hdr)
11568 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010011569 nlmsg_free(msg);
11570}
11571EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11572
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011573#ifdef CONFIG_PM
11574void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11575 struct cfg80211_wowlan_wakeup *wakeup,
11576 gfp_t gfp)
11577{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011578 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011579 struct sk_buff *msg;
11580 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011581 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011582
11583 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11584
11585 if (wakeup)
11586 size += wakeup->packet_present_len;
11587
11588 msg = nlmsg_new(size, gfp);
11589 if (!msg)
11590 return;
11591
11592 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11593 if (!hdr)
11594 goto free_msg;
11595
11596 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11597 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11598 goto free_msg;
11599
11600 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11601 wdev->netdev->ifindex))
11602 goto free_msg;
11603
11604 if (wakeup) {
11605 struct nlattr *reasons;
11606
11607 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011608 if (!reasons)
11609 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011610
11611 if (wakeup->disconnect &&
11612 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11613 goto free_msg;
11614 if (wakeup->magic_pkt &&
11615 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11616 goto free_msg;
11617 if (wakeup->gtk_rekey_failure &&
11618 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11619 goto free_msg;
11620 if (wakeup->eap_identity_req &&
11621 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11622 goto free_msg;
11623 if (wakeup->four_way_handshake &&
11624 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11625 goto free_msg;
11626 if (wakeup->rfkill_release &&
11627 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11628 goto free_msg;
11629
11630 if (wakeup->pattern_idx >= 0 &&
11631 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11632 wakeup->pattern_idx))
11633 goto free_msg;
11634
Johannes Bergae917c92013-10-25 11:05:22 +020011635 if (wakeup->tcp_match &&
11636 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11637 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011638
Johannes Bergae917c92013-10-25 11:05:22 +020011639 if (wakeup->tcp_connlost &&
11640 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11641 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011642
Johannes Bergae917c92013-10-25 11:05:22 +020011643 if (wakeup->tcp_nomoretokens &&
11644 nla_put_flag(msg,
11645 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11646 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011647
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011648 if (wakeup->packet) {
11649 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11650 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11651
11652 if (!wakeup->packet_80211) {
11653 pkt_attr =
11654 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11655 len_attr =
11656 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11657 }
11658
11659 if (wakeup->packet_len &&
11660 nla_put_u32(msg, len_attr, wakeup->packet_len))
11661 goto free_msg;
11662
11663 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11664 wakeup->packet))
11665 goto free_msg;
11666 }
11667
11668 nla_nest_end(msg, reasons);
11669 }
11670
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011671 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011672
Johannes Berg68eb5502013-11-19 15:19:38 +010011673 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011674 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011675 return;
11676
11677 free_msg:
11678 nlmsg_free(msg);
11679}
11680EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11681#endif
11682
Jouni Malinen3475b092012-11-16 22:49:57 +020011683void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11684 enum nl80211_tdls_operation oper,
11685 u16 reason_code, gfp_t gfp)
11686{
11687 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011688 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011689 struct sk_buff *msg;
11690 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011691
11692 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11693 reason_code);
11694
11695 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11696 if (!msg)
11697 return;
11698
11699 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11700 if (!hdr) {
11701 nlmsg_free(msg);
11702 return;
11703 }
11704
11705 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11707 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11708 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11709 (reason_code > 0 &&
11710 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11711 goto nla_put_failure;
11712
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011713 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011714
Johannes Berg68eb5502013-11-19 15:19:38 +010011715 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011716 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011717 return;
11718
11719 nla_put_failure:
11720 genlmsg_cancel(msg, hdr);
11721 nlmsg_free(msg);
11722}
11723EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11724
Jouni Malinen026331c2010-02-15 12:53:10 +020011725static int nl80211_netlink_notify(struct notifier_block * nb,
11726 unsigned long state,
11727 void *_notify)
11728{
11729 struct netlink_notify *notify = _notify;
11730 struct cfg80211_registered_device *rdev;
11731 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011732 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011733
11734 if (state != NETLINK_URELEASE)
11735 return NOTIFY_DONE;
11736
11737 rcu_read_lock();
11738
Johannes Berg5e7602302011-11-04 11:18:17 +010011739 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011740 bool schedule_destroy_work = false;
11741
11742 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011743 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011744
Johannes Berg78f22b62014-03-24 17:57:27 +010011745 if (wdev->owner_nlportid == notify->portid)
11746 schedule_destroy_work = true;
11747 }
11748
Ben Greear37c73b52012-10-26 14:49:25 -070011749 spin_lock_bh(&rdev->beacon_registrations_lock);
11750 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11751 list) {
11752 if (reg->nlportid == notify->portid) {
11753 list_del(&reg->list);
11754 kfree(reg);
11755 break;
11756 }
11757 }
11758 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011759
11760 if (schedule_destroy_work) {
11761 struct cfg80211_iface_destroy *destroy;
11762
11763 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11764 if (destroy) {
11765 destroy->nlportid = notify->portid;
11766 spin_lock(&rdev->destroy_list_lock);
11767 list_add(&destroy->list, &rdev->destroy_list);
11768 spin_unlock(&rdev->destroy_list_lock);
11769 schedule_work(&rdev->destroy_work);
11770 }
11771 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011772 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011773
11774 rcu_read_unlock();
11775
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011776 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011777}
11778
11779static struct notifier_block nl80211_netlink_notifier = {
11780 .notifier_call = nl80211_netlink_notify,
11781};
11782
Jouni Malinen355199e2013-02-27 17:14:27 +020011783void cfg80211_ft_event(struct net_device *netdev,
11784 struct cfg80211_ft_event_params *ft_event)
11785{
11786 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011787 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011788 struct sk_buff *msg;
11789 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011790
11791 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11792
11793 if (!ft_event->target_ap)
11794 return;
11795
11796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11797 if (!msg)
11798 return;
11799
11800 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011801 if (!hdr)
11802 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011803
Johannes Bergae917c92013-10-25 11:05:22 +020011804 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11805 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11806 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11807 goto out;
11808
11809 if (ft_event->ies &&
11810 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11811 goto out;
11812 if (ft_event->ric_ies &&
11813 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11814 ft_event->ric_ies))
11815 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011816
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011817 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011818
Johannes Berg68eb5502013-11-19 15:19:38 +010011819 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011820 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011821 return;
11822 out:
11823 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011824}
11825EXPORT_SYMBOL(cfg80211_ft_event);
11826
Arend van Spriel5de17982013-04-18 15:49:00 +020011827void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11828{
11829 struct cfg80211_registered_device *rdev;
11830 struct sk_buff *msg;
11831 void *hdr;
11832 u32 nlportid;
11833
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011834 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011835 if (!rdev->crit_proto_nlportid)
11836 return;
11837
11838 nlportid = rdev->crit_proto_nlportid;
11839 rdev->crit_proto_nlportid = 0;
11840
11841 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11842 if (!msg)
11843 return;
11844
11845 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11846 if (!hdr)
11847 goto nla_put_failure;
11848
11849 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11850 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11851 goto nla_put_failure;
11852
11853 genlmsg_end(msg, hdr);
11854
11855 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11856 return;
11857
11858 nla_put_failure:
11859 if (hdr)
11860 genlmsg_cancel(msg, hdr);
11861 nlmsg_free(msg);
11862
11863}
11864EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11865
Johannes Berg348baf02014-01-24 14:06:29 +010011866void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11867{
11868 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011869 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011870 struct sk_buff *msg;
11871 void *hdr;
11872
11873 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11874 if (!msg)
11875 return;
11876
11877 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11878 if (!hdr)
11879 goto out;
11880
11881 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11882 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11883 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11884 goto out;
11885
11886 genlmsg_end(msg, hdr);
11887
11888 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11889 NL80211_MCGRP_MLME, GFP_KERNEL);
11890 return;
11891 out:
11892 nlmsg_free(msg);
11893}
11894
Johannes Berg55682962007-09-20 13:09:35 -040011895/* initialisation/exit functions */
11896
11897int nl80211_init(void)
11898{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011899 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011900
Johannes Berg2a94fe42013-11-19 15:19:39 +010011901 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11902 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011903 if (err)
11904 return err;
11905
Jouni Malinen026331c2010-02-15 12:53:10 +020011906 err = netlink_register_notifier(&nl80211_netlink_notifier);
11907 if (err)
11908 goto err_out;
11909
Johannes Berg55682962007-09-20 13:09:35 -040011910 return 0;
11911 err_out:
11912 genl_unregister_family(&nl80211_fam);
11913 return err;
11914}
11915
11916void nl80211_exit(void)
11917{
Jouni Malinen026331c2010-02-15 12:53:10 +020011918 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011919 genl_unregister_family(&nl80211_fam);
11920}