blob: 20857126f742227127bbe013c84c2185a3990e3c [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]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200168 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200169 if (netdev) {
170 if (netdev->ieee80211_ptr)
171 tmp = wiphy_to_dev(
172 netdev->ieee80211_ptr->wiphy);
173 else
174 tmp = NULL;
175
176 dev_put(netdev);
177
178 /* not wireless device -- return error */
179 if (!tmp)
180 return ERR_PTR(-EINVAL);
181
182 /* mismatch -- return error */
183 if (rdev && tmp != rdev)
184 return ERR_PTR(-EINVAL);
185
186 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
189
Johannes Berg4f7eff12012-06-15 14:14:22 +0200190 if (!rdev)
191 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200192
Johannes Berg4f7eff12012-06-15 14:14:22 +0200193 if (netns != wiphy_net(&rdev->wiphy))
194 return ERR_PTR(-ENODEV);
195
196 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200197}
198
199/*
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200202 *
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
205 */
206static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200207cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200208{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200209 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200210}
211
Johannes Berg55682962007-09-20 13:09:35 -0400212/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000213static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400214 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
215 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700216 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200217 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100218
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200219 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100221 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
224
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200225 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100342 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200343 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
344 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700345 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800346 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
347 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
348 .len = NL80211_HT_CAPABILITY_LEN
349 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100350 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530351 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530352 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200353 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700354 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300355 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000356 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700357 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100358 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
359 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530360 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
361 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200362 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
363 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100364 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100365 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
366 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
367 .len = NL80211_VHT_CAPABILITY_LEN,
368 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200369 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
370 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
371 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300372 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200373 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
374 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
375 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
376 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
377 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530378 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
379 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200380 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100381 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100382 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
383 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800385 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
386 .len = IEEE80211_QOS_MAP_LEN_MAX },
Johannes Berg55682962007-09-20 13:09:35 -0400387};
388
Johannes Berge31b8212010-10-05 19:39:30 +0200389/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000390static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200391 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200392 [NL80211_KEY_IDX] = { .type = NLA_U8 },
393 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200394 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200395 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
396 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200397 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100398 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
399};
400
401/* policy for the key default flags */
402static const struct nla_policy
403nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
404 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
405 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200406};
407
Johannes Bergff1b6e62011-05-04 15:37:28 +0200408/* policy for WoWLAN attributes */
409static const struct nla_policy
410nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
411 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
412 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
413 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
414 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200415 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
416 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
417 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100419 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
420};
421
422static const struct nla_policy
423nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
424 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
425 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
426 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
427 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
428 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
429 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
430 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
431 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
432 },
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
434 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
435 },
436 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
437 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
438 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200439};
440
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700441/* policy for coalesce rule attributes */
442static const struct nla_policy
443nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
444 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
445 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
446 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
447};
448
Johannes Berge5497d72011-07-05 16:35:40 +0200449/* policy for GTK rekey offload attributes */
450static const struct nla_policy
451nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
452 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
453 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
454 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
455};
456
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300457static const struct nla_policy
458nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200459 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300460 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700461 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300462};
463
Johannes Berg97990a02013-04-19 01:02:55 +0200464static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
465 struct netlink_callback *cb,
466 struct cfg80211_registered_device **rdev,
467 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100468{
Johannes Berg67748892010-10-04 21:14:06 +0200469 int err;
470
Johannes Berg67748892010-10-04 21:14:06 +0200471 rtnl_lock();
472
Johannes Berg97990a02013-04-19 01:02:55 +0200473 if (!cb->args[0]) {
474 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
475 nl80211_fam.attrbuf, nl80211_fam.maxattr,
476 nl80211_policy);
477 if (err)
478 goto out_unlock;
479
480 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
481 nl80211_fam.attrbuf);
482 if (IS_ERR(*wdev)) {
483 err = PTR_ERR(*wdev);
484 goto out_unlock;
485 }
486 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200487 /* 0 is the first index - add 1 to parse only once */
488 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200489 cb->args[1] = (*wdev)->identifier;
490 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200491 /* subtract the 1 again here */
492 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200493 struct wireless_dev *tmp;
494
495 if (!wiphy) {
496 err = -ENODEV;
497 goto out_unlock;
498 }
499 *rdev = wiphy_to_dev(wiphy);
500 *wdev = NULL;
501
Johannes Berg97990a02013-04-19 01:02:55 +0200502 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
503 if (tmp->identifier == cb->args[1]) {
504 *wdev = tmp;
505 break;
506 }
507 }
Johannes Berg97990a02013-04-19 01:02:55 +0200508
509 if (!*wdev) {
510 err = -ENODEV;
511 goto out_unlock;
512 }
Johannes Berg67748892010-10-04 21:14:06 +0200513 }
514
Johannes Berg67748892010-10-04 21:14:06 +0200515 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200516 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200517 rtnl_unlock();
518 return err;
519}
520
Johannes Berg97990a02013-04-19 01:02:55 +0200521static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200522{
Johannes Berg67748892010-10-04 21:14:06 +0200523 rtnl_unlock();
524}
525
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100526/* IE validation */
527static bool is_valid_ie_attr(const struct nlattr *attr)
528{
529 const u8 *pos;
530 int len;
531
532 if (!attr)
533 return true;
534
535 pos = nla_data(attr);
536 len = nla_len(attr);
537
538 while (len) {
539 u8 elemlen;
540
541 if (len < 2)
542 return false;
543 len -= 2;
544
545 elemlen = pos[1];
546 if (elemlen > len)
547 return false;
548
549 len -= elemlen;
550 pos += 2 + elemlen;
551 }
552
553 return true;
554}
555
Johannes Berg55682962007-09-20 13:09:35 -0400556/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000557static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400558 int flags, u8 cmd)
559{
560 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000561 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400562}
563
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400564static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100565 struct ieee80211_channel *chan,
566 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400567{
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
569 chan->center_freq))
570 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
David S. Miller9360ffd2012-03-29 04:41:26 -0400572 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
573 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
574 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200575 if (chan->flags & IEEE80211_CHAN_NO_IR) {
576 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
577 goto nla_put_failure;
578 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
579 goto nla_put_failure;
580 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100581 if (chan->flags & IEEE80211_CHAN_RADAR) {
582 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
583 goto nla_put_failure;
584 if (large) {
585 u32 time;
586
587 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
588
589 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
590 chan->dfs_state))
591 goto nla_put_failure;
592 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
593 time))
594 goto nla_put_failure;
595 }
596 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400597
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100598 if (large) {
599 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
600 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
601 goto nla_put_failure;
602 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
603 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
604 goto nla_put_failure;
605 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
606 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
607 goto nla_put_failure;
608 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
609 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
610 goto nla_put_failure;
611 }
612
David S. Miller9360ffd2012-03-29 04:41:26 -0400613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
614 DBM_TO_MBM(chan->max_power)))
615 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400616
617 return 0;
618
619 nla_put_failure:
620 return -ENOBUFS;
621}
622
Johannes Berg55682962007-09-20 13:09:35 -0400623/* netlink command implementations */
624
Johannes Bergb9454e82009-07-08 13:29:08 +0200625struct key_parse {
626 struct key_params p;
627 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200628 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200629 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100630 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200631};
632
633static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
634{
635 struct nlattr *tb[NL80211_KEY_MAX + 1];
636 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
637 nl80211_key_policy);
638 if (err)
639 return err;
640
641 k->def = !!tb[NL80211_KEY_DEFAULT];
642 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
643
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100644 if (k->def) {
645 k->def_uni = true;
646 k->def_multi = true;
647 }
648 if (k->defmgmt)
649 k->def_multi = true;
650
Johannes Bergb9454e82009-07-08 13:29:08 +0200651 if (tb[NL80211_KEY_IDX])
652 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
653
654 if (tb[NL80211_KEY_DATA]) {
655 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
656 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
657 }
658
659 if (tb[NL80211_KEY_SEQ]) {
660 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
661 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
662 }
663
664 if (tb[NL80211_KEY_CIPHER])
665 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
666
Johannes Berge31b8212010-10-05 19:39:30 +0200667 if (tb[NL80211_KEY_TYPE]) {
668 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
669 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
670 return -EINVAL;
671 }
672
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100673 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
674 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100675 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
676 tb[NL80211_KEY_DEFAULT_TYPES],
677 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100678 if (err)
679 return err;
680
681 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
682 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
683 }
684
Johannes Bergb9454e82009-07-08 13:29:08 +0200685 return 0;
686}
687
688static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
689{
690 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
691 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
692 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
693 }
694
695 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
696 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
697 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
698 }
699
700 if (info->attrs[NL80211_ATTR_KEY_IDX])
701 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
702
703 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
704 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
705
706 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
707 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
708
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100709 if (k->def) {
710 k->def_uni = true;
711 k->def_multi = true;
712 }
713 if (k->defmgmt)
714 k->def_multi = true;
715
Johannes Berge31b8212010-10-05 19:39:30 +0200716 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
717 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
718 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
719 return -EINVAL;
720 }
721
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100722 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
723 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
724 int err = nla_parse_nested(
725 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
726 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
727 nl80211_key_default_policy);
728 if (err)
729 return err;
730
731 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
732 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
733 }
734
Johannes Bergb9454e82009-07-08 13:29:08 +0200735 return 0;
736}
737
738static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
739{
740 int err;
741
742 memset(k, 0, sizeof(*k));
743 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200744 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200745
746 if (info->attrs[NL80211_ATTR_KEY])
747 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
748 else
749 err = nl80211_parse_key_old(info, k);
750
751 if (err)
752 return err;
753
754 if (k->def && k->defmgmt)
755 return -EINVAL;
756
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100757 if (k->defmgmt) {
758 if (k->def_uni || !k->def_multi)
759 return -EINVAL;
760 }
761
Johannes Bergb9454e82009-07-08 13:29:08 +0200762 if (k->idx != -1) {
763 if (k->defmgmt) {
764 if (k->idx < 4 || k->idx > 5)
765 return -EINVAL;
766 } else if (k->def) {
767 if (k->idx < 0 || k->idx > 3)
768 return -EINVAL;
769 } else {
770 if (k->idx < 0 || k->idx > 5)
771 return -EINVAL;
772 }
773 }
774
775 return 0;
776}
777
Johannes Bergfffd0932009-07-08 14:22:54 +0200778static struct cfg80211_cached_keys *
779nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530780 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200781{
782 struct key_parse parse;
783 struct nlattr *key;
784 struct cfg80211_cached_keys *result;
785 int rem, err, def = 0;
786
787 result = kzalloc(sizeof(*result), GFP_KERNEL);
788 if (!result)
789 return ERR_PTR(-ENOMEM);
790
791 result->def = -1;
792 result->defmgmt = -1;
793
794 nla_for_each_nested(key, keys, rem) {
795 memset(&parse, 0, sizeof(parse));
796 parse.idx = -1;
797
798 err = nl80211_parse_key_new(key, &parse);
799 if (err)
800 goto error;
801 err = -EINVAL;
802 if (!parse.p.key)
803 goto error;
804 if (parse.idx < 0 || parse.idx > 4)
805 goto error;
806 if (parse.def) {
807 if (def)
808 goto error;
809 def = 1;
810 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100811 if (!parse.def_uni || !parse.def_multi)
812 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200813 } else if (parse.defmgmt)
814 goto error;
815 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200816 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200817 if (err)
818 goto error;
819 result->params[parse.idx].cipher = parse.p.cipher;
820 result->params[parse.idx].key_len = parse.p.key_len;
821 result->params[parse.idx].key = result->data[parse.idx];
822 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530823
824 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
825 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
826 if (no_ht)
827 *no_ht = true;
828 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200829 }
830
831 return result;
832 error:
833 kfree(result);
834 return ERR_PTR(err);
835}
836
837static int nl80211_key_allowed(struct wireless_dev *wdev)
838{
839 ASSERT_WDEV_LOCK(wdev);
840
Johannes Bergfffd0932009-07-08 14:22:54 +0200841 switch (wdev->iftype) {
842 case NL80211_IFTYPE_AP:
843 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200844 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700845 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200846 break;
847 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200848 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200849 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200850 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200851 return -ENOLINK;
852 break;
853 default:
854 return -EINVAL;
855 }
856
857 return 0;
858}
859
Johannes Berg7527a782011-05-13 10:58:57 +0200860static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
861{
862 struct nlattr *nl_modes = nla_nest_start(msg, attr);
863 int i;
864
865 if (!nl_modes)
866 goto nla_put_failure;
867
868 i = 0;
869 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if ((ifmodes & 1) && nla_put_flag(msg, i))
871 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200872 ifmodes >>= 1;
873 i++;
874 }
875
876 nla_nest_end(msg, nl_modes);
877 return 0;
878
879nla_put_failure:
880 return -ENOBUFS;
881}
882
883static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100884 struct sk_buff *msg,
885 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200886{
887 struct nlattr *nl_combis;
888 int i, j;
889
890 nl_combis = nla_nest_start(msg,
891 NL80211_ATTR_INTERFACE_COMBINATIONS);
892 if (!nl_combis)
893 goto nla_put_failure;
894
895 for (i = 0; i < wiphy->n_iface_combinations; i++) {
896 const struct ieee80211_iface_combination *c;
897 struct nlattr *nl_combi, *nl_limits;
898
899 c = &wiphy->iface_combinations[i];
900
901 nl_combi = nla_nest_start(msg, i + 1);
902 if (!nl_combi)
903 goto nla_put_failure;
904
905 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
906 if (!nl_limits)
907 goto nla_put_failure;
908
909 for (j = 0; j < c->n_limits; j++) {
910 struct nlattr *nl_limit;
911
912 nl_limit = nla_nest_start(msg, j + 1);
913 if (!nl_limit)
914 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400915 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
916 c->limits[j].max))
917 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200918 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
919 c->limits[j].types))
920 goto nla_put_failure;
921 nla_nest_end(msg, nl_limit);
922 }
923
924 nla_nest_end(msg, nl_limits);
925
David S. Miller9360ffd2012-03-29 04:41:26 -0400926 if (c->beacon_int_infra_match &&
927 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
928 goto nla_put_failure;
929 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
930 c->num_different_channels) ||
931 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
932 c->max_interfaces))
933 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100934 if (large &&
935 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
936 c->radar_detect_widths))
937 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200938
939 nla_nest_end(msg, nl_combi);
940 }
941
942 nla_nest_end(msg, nl_combis);
943
944 return 0;
945nla_put_failure:
946 return -ENOBUFS;
947}
948
Johannes Berg3713b4e2013-02-14 16:19:38 +0100949#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100950static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
951 struct sk_buff *msg)
952{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200953 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100954 struct nlattr *nl_tcp;
955
956 if (!tcp)
957 return 0;
958
959 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
960 if (!nl_tcp)
961 return -ENOBUFS;
962
963 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
964 tcp->data_payload_max))
965 return -ENOBUFS;
966
967 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
968 tcp->data_payload_max))
969 return -ENOBUFS;
970
971 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
972 return -ENOBUFS;
973
974 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
975 sizeof(*tcp->tok), tcp->tok))
976 return -ENOBUFS;
977
978 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
979 tcp->data_interval_max))
980 return -ENOBUFS;
981
982 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
983 tcp->wake_payload_max))
984 return -ENOBUFS;
985
986 nla_nest_end(msg, nl_tcp);
987 return 0;
988}
989
Johannes Berg3713b4e2013-02-14 16:19:38 +0100990static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100991 struct cfg80211_registered_device *dev,
992 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100993{
994 struct nlattr *nl_wowlan;
995
Johannes Berg964dc9e2013-06-03 17:25:34 +0200996 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100997 return 0;
998
999 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1000 if (!nl_wowlan)
1001 return -ENOBUFS;
1002
Johannes Berg964dc9e2013-06-03 17:25:34 +02001003 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001005 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001007 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001008 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001009 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001010 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001011 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001012 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001013 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001014 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001015 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001016 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001017 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001018 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1019 return -ENOBUFS;
1020
Johannes Berg964dc9e2013-06-03 17:25:34 +02001021 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001022 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +02001023 .max_patterns = dev->wiphy.wowlan->n_patterns,
1024 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
1025 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1026 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001027 };
1028
1029 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1030 sizeof(pat), &pat))
1031 return -ENOBUFS;
1032 }
1033
Johannes Bergb56cf722013-02-20 01:02:38 +01001034 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1035 return -ENOBUFS;
1036
Johannes Berg3713b4e2013-02-14 16:19:38 +01001037 nla_nest_end(msg, nl_wowlan);
1038
1039 return 0;
1040}
1041#endif
1042
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001043static int nl80211_send_coalesce(struct sk_buff *msg,
1044 struct cfg80211_registered_device *dev)
1045{
1046 struct nl80211_coalesce_rule_support rule;
1047
1048 if (!dev->wiphy.coalesce)
1049 return 0;
1050
1051 rule.max_rules = dev->wiphy.coalesce->n_rules;
1052 rule.max_delay = dev->wiphy.coalesce->max_delay;
1053 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1054 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1055 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1056 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1057
1058 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1059 return -ENOBUFS;
1060
1061 return 0;
1062}
1063
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1065 struct ieee80211_supported_band *sband)
1066{
1067 struct nlattr *nl_rates, *nl_rate;
1068 struct ieee80211_rate *rate;
1069 int i;
1070
1071 /* add HT info */
1072 if (sband->ht_cap.ht_supported &&
1073 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1074 sizeof(sband->ht_cap.mcs),
1075 &sband->ht_cap.mcs) ||
1076 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1077 sband->ht_cap.cap) ||
1078 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1079 sband->ht_cap.ampdu_factor) ||
1080 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1081 sband->ht_cap.ampdu_density)))
1082 return -ENOBUFS;
1083
1084 /* add VHT info */
1085 if (sband->vht_cap.vht_supported &&
1086 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1087 sizeof(sband->vht_cap.vht_mcs),
1088 &sband->vht_cap.vht_mcs) ||
1089 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1090 sband->vht_cap.cap)))
1091 return -ENOBUFS;
1092
1093 /* add bitrates */
1094 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1095 if (!nl_rates)
1096 return -ENOBUFS;
1097
1098 for (i = 0; i < sband->n_bitrates; i++) {
1099 nl_rate = nla_nest_start(msg, i);
1100 if (!nl_rate)
1101 return -ENOBUFS;
1102
1103 rate = &sband->bitrates[i];
1104 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1105 rate->bitrate))
1106 return -ENOBUFS;
1107 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1108 nla_put_flag(msg,
1109 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1110 return -ENOBUFS;
1111
1112 nla_nest_end(msg, nl_rate);
1113 }
1114
1115 nla_nest_end(msg, nl_rates);
1116
1117 return 0;
1118}
1119
1120static int
1121nl80211_send_mgmt_stypes(struct sk_buff *msg,
1122 const struct ieee80211_txrx_stypes *mgmt_stypes)
1123{
1124 u16 stypes;
1125 struct nlattr *nl_ftypes, *nl_ifs;
1126 enum nl80211_iftype ift;
1127 int i;
1128
1129 if (!mgmt_stypes)
1130 return 0;
1131
1132 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1133 if (!nl_ifs)
1134 return -ENOBUFS;
1135
1136 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1137 nl_ftypes = nla_nest_start(msg, ift);
1138 if (!nl_ftypes)
1139 return -ENOBUFS;
1140 i = 0;
1141 stypes = mgmt_stypes[ift].tx;
1142 while (stypes) {
1143 if ((stypes & 1) &&
1144 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1145 (i << 4) | IEEE80211_FTYPE_MGMT))
1146 return -ENOBUFS;
1147 stypes >>= 1;
1148 i++;
1149 }
1150 nla_nest_end(msg, nl_ftypes);
1151 }
1152
1153 nla_nest_end(msg, nl_ifs);
1154
1155 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1156 if (!nl_ifs)
1157 return -ENOBUFS;
1158
1159 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1160 nl_ftypes = nla_nest_start(msg, ift);
1161 if (!nl_ftypes)
1162 return -ENOBUFS;
1163 i = 0;
1164 stypes = mgmt_stypes[ift].rx;
1165 while (stypes) {
1166 if ((stypes & 1) &&
1167 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1168 (i << 4) | IEEE80211_FTYPE_MGMT))
1169 return -ENOBUFS;
1170 stypes >>= 1;
1171 i++;
1172 }
1173 nla_nest_end(msg, nl_ftypes);
1174 }
1175 nla_nest_end(msg, nl_ifs);
1176
1177 return 0;
1178}
1179
Johannes Berg86e8cf92013-06-19 10:57:22 +02001180struct nl80211_dump_wiphy_state {
1181 s64 filter_wiphy;
1182 long start;
1183 long split_start, band_start, chan_start;
1184 bool split;
1185};
1186
Johannes Berg3713b4e2013-02-14 16:19:38 +01001187static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1188 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001189 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001190{
1191 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001192 struct nlattr *nl_bands, *nl_band;
1193 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001194 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001195 enum ieee80211_band band;
1196 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001197 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001198 const struct ieee80211_txrx_stypes *mgmt_stypes =
1199 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001200 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001201
Eric W. Biederman15e47302012-09-07 20:12:54 +00001202 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001203 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001204 return -ENOBUFS;
1205
Johannes Berg86e8cf92013-06-19 10:57:22 +02001206 if (WARN_ON(!state))
1207 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001208
David S. Miller9360ffd2012-03-29 04:41:26 -04001209 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001210 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1211 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001212 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001213 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001214 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001215
Johannes Berg86e8cf92013-06-19 10:57:22 +02001216 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001217 case 0:
1218 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1219 dev->wiphy.retry_short) ||
1220 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1221 dev->wiphy.retry_long) ||
1222 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1223 dev->wiphy.frag_threshold) ||
1224 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1225 dev->wiphy.rts_threshold) ||
1226 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1227 dev->wiphy.coverage_class) ||
1228 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1229 dev->wiphy.max_scan_ssids) ||
1230 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1231 dev->wiphy.max_sched_scan_ssids) ||
1232 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1233 dev->wiphy.max_scan_ie_len) ||
1234 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1235 dev->wiphy.max_sched_scan_ie_len) ||
1236 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1237 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001238 goto nla_put_failure;
1239
Johannes Berg3713b4e2013-02-14 16:19:38 +01001240 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1241 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1242 goto nla_put_failure;
1243 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1244 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1245 goto nla_put_failure;
1246 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1247 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1248 goto nla_put_failure;
1249 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1250 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1251 goto nla_put_failure;
1252 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1253 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1254 goto nla_put_failure;
1255 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1256 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001257 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001258 state->split_start++;
1259 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001260 break;
1261 case 1:
1262 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1263 sizeof(u32) * dev->wiphy.n_cipher_suites,
1264 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001265 goto nla_put_failure;
1266
Johannes Berg3713b4e2013-02-14 16:19:38 +01001267 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1268 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001269 goto nla_put_failure;
1270
Johannes Berg3713b4e2013-02-14 16:19:38 +01001271 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1272 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1273 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001274
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1276 dev->wiphy.available_antennas_tx) ||
1277 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1278 dev->wiphy.available_antennas_rx))
1279 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001280
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1282 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1283 dev->wiphy.probe_resp_offload))
1284 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001285
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 if ((dev->wiphy.available_antennas_tx ||
1287 dev->wiphy.available_antennas_rx) &&
1288 dev->ops->get_antenna) {
1289 u32 tx_ant = 0, rx_ant = 0;
1290 int res;
1291 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1292 if (!res) {
1293 if (nla_put_u32(msg,
1294 NL80211_ATTR_WIPHY_ANTENNA_TX,
1295 tx_ant) ||
1296 nla_put_u32(msg,
1297 NL80211_ATTR_WIPHY_ANTENNA_RX,
1298 rx_ant))
1299 goto nla_put_failure;
1300 }
Johannes Bergee688b002008-01-24 19:38:39 +01001301 }
1302
Johannes Berg86e8cf92013-06-19 10:57:22 +02001303 state->split_start++;
1304 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 break;
1306 case 2:
1307 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1308 dev->wiphy.interface_modes))
1309 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001310 state->split_start++;
1311 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 break;
1313 case 3:
1314 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1315 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001316 goto nla_put_failure;
1317
Johannes Berg86e8cf92013-06-19 10:57:22 +02001318 for (band = state->band_start;
1319 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 struct ieee80211_supported_band *sband;
1321
1322 sband = dev->wiphy.bands[band];
1323
1324 if (!sband)
1325 continue;
1326
1327 nl_band = nla_nest_start(msg, band);
1328 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001329 goto nla_put_failure;
1330
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 case 0:
1333 if (nl80211_send_band_rateinfo(msg, sband))
1334 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001335 state->chan_start++;
1336 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 break;
1338 default:
1339 /* add frequencies */
1340 nl_freqs = nla_nest_start(
1341 msg, NL80211_BAND_ATTR_FREQS);
1342 if (!nl_freqs)
1343 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001344
Johannes Berg86e8cf92013-06-19 10:57:22 +02001345 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 i < sband->n_channels;
1347 i++) {
1348 nl_freq = nla_nest_start(msg, i);
1349 if (!nl_freq)
1350 goto nla_put_failure;
1351
1352 chan = &sband->channels[i];
1353
Johannes Berg86e8cf92013-06-19 10:57:22 +02001354 if (nl80211_msg_put_channel(
1355 msg, chan,
1356 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 goto nla_put_failure;
1358
1359 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001360 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 break;
1362 }
1363 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001364 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001365 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001366 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 nla_nest_end(msg, nl_freqs);
1368 }
1369
1370 nla_nest_end(msg, nl_band);
1371
Johannes Berg86e8cf92013-06-19 10:57:22 +02001372 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001374 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 band--;
1376 break;
1377 }
Johannes Bergee688b002008-01-24 19:38:39 +01001378 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001380
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001382 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001384 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001385
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001387 if (state->band_start == 0 && state->chan_start == 0)
1388 state->split_start++;
1389 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001390 break;
1391 case 4:
1392 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1393 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001394 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395
1396 i = 0;
1397#define CMD(op, n) \
1398 do { \
1399 if (dev->ops->op) { \
1400 i++; \
1401 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1402 goto nla_put_failure; \
1403 } \
1404 } while (0)
1405
1406 CMD(add_virtual_intf, NEW_INTERFACE);
1407 CMD(change_virtual_intf, SET_INTERFACE);
1408 CMD(add_key, NEW_KEY);
1409 CMD(start_ap, START_AP);
1410 CMD(add_station, NEW_STATION);
1411 CMD(add_mpath, NEW_MPATH);
1412 CMD(update_mesh_config, SET_MESH_CONFIG);
1413 CMD(change_bss, SET_BSS);
1414 CMD(auth, AUTHENTICATE);
1415 CMD(assoc, ASSOCIATE);
1416 CMD(deauth, DEAUTHENTICATE);
1417 CMD(disassoc, DISASSOCIATE);
1418 CMD(join_ibss, JOIN_IBSS);
1419 CMD(join_mesh, JOIN_MESH);
1420 CMD(set_pmksa, SET_PMKSA);
1421 CMD(del_pmksa, DEL_PMKSA);
1422 CMD(flush_pmksa, FLUSH_PMKSA);
1423 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1424 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1425 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1426 CMD(mgmt_tx, FRAME);
1427 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1428 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1429 i++;
1430 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1431 goto nla_put_failure;
1432 }
1433 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1434 dev->ops->join_mesh) {
1435 i++;
1436 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1437 goto nla_put_failure;
1438 }
1439 CMD(set_wds_peer, SET_WDS_PEER);
1440 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1441 CMD(tdls_mgmt, TDLS_MGMT);
1442 CMD(tdls_oper, TDLS_OPER);
1443 }
1444 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1445 CMD(sched_scan_start, START_SCHED_SCAN);
1446 CMD(probe_client, PROBE_CLIENT);
1447 CMD(set_noack_map, SET_NOACK_MAP);
1448 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1449 i++;
1450 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1451 goto nla_put_failure;
1452 }
1453 CMD(start_p2p_device, START_P2P_DEVICE);
1454 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001456 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1457 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001458 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1459 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001460 }
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001461 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001462
Kalle Valo4745fc02011-11-17 19:06:10 +02001463#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001465#endif
1466
Johannes Berg8fdc6212009-03-14 09:34:01 +01001467#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001468
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 if (dev->ops->connect || dev->ops->auth) {
1470 i++;
1471 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001472 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001473 }
1474
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 if (dev->ops->disconnect || dev->ops->deauth) {
1476 i++;
1477 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1478 goto nla_put_failure;
1479 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001480
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001482 state->split_start++;
1483 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 break;
1485 case 5:
1486 if (dev->ops->remain_on_channel &&
1487 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1488 nla_put_u32(msg,
1489 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1490 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001491 goto nla_put_failure;
1492
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1494 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1495 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001496
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1498 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001499 state->split_start++;
1500 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 break;
1502 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001503#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001504 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001505 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001506 state->split_start++;
1507 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001508 break;
1509#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001510 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511#endif
1512 case 7:
1513 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1514 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001515 goto nla_put_failure;
1516
Johannes Berg86e8cf92013-06-19 10:57:22 +02001517 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1518 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001520
Johannes Berg86e8cf92013-06-19 10:57:22 +02001521 state->split_start++;
1522 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 break;
1524 case 8:
1525 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1526 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1527 dev->wiphy.ap_sme_capa))
1528 goto nla_put_failure;
1529
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001530 features = dev->wiphy.features;
1531 /*
1532 * We can only add the per-channel limit information if the
1533 * dump is split, otherwise it makes it too big. Therefore
1534 * only advertise it in that case.
1535 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001536 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001537 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1538 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 goto nla_put_failure;
1540
1541 if (dev->wiphy.ht_capa_mod_mask &&
1542 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1543 sizeof(*dev->wiphy.ht_capa_mod_mask),
1544 dev->wiphy.ht_capa_mod_mask))
1545 goto nla_put_failure;
1546
1547 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1548 dev->wiphy.max_acl_mac_addrs &&
1549 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1550 dev->wiphy.max_acl_mac_addrs))
1551 goto nla_put_failure;
1552
1553 /*
1554 * Any information below this point is only available to
1555 * applications that can deal with it being split. This
1556 * helps ensure that newly added capabilities don't break
1557 * older tools by overrunning their buffers.
1558 *
1559 * We still increment split_start so that in the split
1560 * case we'll continue with more data in the next round,
1561 * but break unconditionally so unsplit data stops here.
1562 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 break;
1565 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001566 if (dev->wiphy.extended_capabilities &&
1567 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1568 dev->wiphy.extended_capabilities_len,
1569 dev->wiphy.extended_capabilities) ||
1570 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1571 dev->wiphy.extended_capabilities_len,
1572 dev->wiphy.extended_capabilities_mask)))
1573 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574
Johannes Bergee2aca32013-02-21 17:36:01 +01001575 if (dev->wiphy.vht_capa_mod_mask &&
1576 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1577 sizeof(*dev->wiphy.vht_capa_mod_mask),
1578 dev->wiphy.vht_capa_mod_mask))
1579 goto nla_put_failure;
1580
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001581 state->split_start++;
1582 break;
1583 case 10:
1584 if (nl80211_send_coalesce(msg, dev))
1585 goto nla_put_failure;
1586
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001587 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1588 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1589 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1590 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01001591 state->split_start++;
1592 break;
1593 case 11:
Johannes Berg567ffc32013-12-18 14:43:31 +01001594 if (dev->wiphy.n_vendor_commands) {
1595 const struct nl80211_vendor_cmd_info *info;
1596 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001597
Johannes Berg567ffc32013-12-18 14:43:31 +01001598 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1599 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001600 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001601
1602 for (i = 0; i < dev->wiphy.n_vendor_commands; i++) {
1603 info = &dev->wiphy.vendor_commands[i].info;
1604 if (nla_put(msg, i + 1, sizeof(*info), info))
1605 goto nla_put_failure;
1606 }
1607 nla_nest_end(msg, nested);
1608 }
1609
1610 if (dev->wiphy.n_vendor_events) {
1611 const struct nl80211_vendor_cmd_info *info;
1612 struct nlattr *nested;
1613
1614 nested = nla_nest_start(msg,
1615 NL80211_ATTR_VENDOR_EVENTS);
1616 if (!nested)
1617 goto nla_put_failure;
1618
1619 for (i = 0; i < dev->wiphy.n_vendor_events; i++) {
1620 info = &dev->wiphy.vendor_events[i];
1621 if (nla_put(msg, i + 1, sizeof(*info), info))
1622 goto nla_put_failure;
1623 }
1624 nla_nest_end(msg, nested);
1625 }
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001626
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001628 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001630 }
Johannes Berg55682962007-09-20 13:09:35 -04001631 return genlmsg_end(msg, hdr);
1632
1633 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001634 genlmsg_cancel(msg, hdr);
1635 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001636}
1637
Johannes Berg86e8cf92013-06-19 10:57:22 +02001638static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1639 struct netlink_callback *cb,
1640 struct nl80211_dump_wiphy_state *state)
1641{
1642 struct nlattr **tb = nl80211_fam.attrbuf;
1643 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1644 tb, nl80211_fam.maxattr, nl80211_policy);
1645 /* ignore parse errors for backward compatibility */
1646 if (ret)
1647 return 0;
1648
1649 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1650 if (tb[NL80211_ATTR_WIPHY])
1651 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1652 if (tb[NL80211_ATTR_WDEV])
1653 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1654 if (tb[NL80211_ATTR_IFINDEX]) {
1655 struct net_device *netdev;
1656 struct cfg80211_registered_device *rdev;
1657 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1658
1659 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1660 if (!netdev)
1661 return -ENODEV;
1662 if (netdev->ieee80211_ptr) {
1663 rdev = wiphy_to_dev(
1664 netdev->ieee80211_ptr->wiphy);
1665 state->filter_wiphy = rdev->wiphy_idx;
1666 }
1667 dev_put(netdev);
1668 }
1669
1670 return 0;
1671}
1672
Johannes Berg55682962007-09-20 13:09:35 -04001673static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1674{
Johannes Berg645e77d2013-03-01 14:03:49 +01001675 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001676 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001677 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001678
Johannes Berg5fe231e2013-05-08 21:45:15 +02001679 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001680 if (!state) {
1681 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001682 if (!state) {
1683 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001684 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001685 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001686 state->filter_wiphy = -1;
1687 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1688 if (ret) {
1689 kfree(state);
1690 rtnl_unlock();
1691 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001692 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001693 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001694 }
1695
Johannes Berg79c97e92009-07-07 03:56:12 +02001696 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001697 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1698 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001699 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001700 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001701 if (state->filter_wiphy != -1 &&
1702 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 continue;
1704 /* attempt to fit multiple wiphy data chunks into the skb */
1705 do {
1706 ret = nl80211_send_wiphy(dev, skb,
1707 NETLINK_CB(cb->skb).portid,
1708 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001709 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001710 if (ret < 0) {
1711 /*
1712 * If sending the wiphy data didn't fit (ENOBUFS
1713 * or EMSGSIZE returned), this SKB is still
1714 * empty (so it's not too big because another
1715 * wiphy dataset is already in the skb) and
1716 * we've not tried to adjust the dump allocation
1717 * yet ... then adjust the alloc size to be
1718 * bigger, and return 1 but with the empty skb.
1719 * This results in an empty message being RX'ed
1720 * in userspace, but that is ignored.
1721 *
1722 * We can then retry with the larger buffer.
1723 */
1724 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1725 !skb->len &&
1726 cb->min_dump_alloc < 4096) {
1727 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001728 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001729 return 1;
1730 }
1731 idx--;
1732 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001733 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001734 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001735 break;
Johannes Berg55682962007-09-20 13:09:35 -04001736 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001737 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001738
Johannes Berg86e8cf92013-06-19 10:57:22 +02001739 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001740
1741 return skb->len;
1742}
1743
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1745{
1746 kfree((void *)cb->args[0]);
1747 return 0;
1748}
1749
Johannes Berg55682962007-09-20 13:09:35 -04001750static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1751{
1752 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001753 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001754 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001755
Johannes Berg645e77d2013-03-01 14:03:49 +01001756 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001757 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001758 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001759
Johannes Berg3713b4e2013-02-14 16:19:38 +01001760 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001761 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001762 nlmsg_free(msg);
1763 return -ENOBUFS;
1764 }
Johannes Berg55682962007-09-20 13:09:35 -04001765
Johannes Berg134e6372009-07-10 09:51:34 +00001766 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001767}
1768
Jouni Malinen31888482008-10-30 16:59:24 +02001769static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1770 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1771 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1772 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1773 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1774 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1775};
1776
1777static int parse_txq_params(struct nlattr *tb[],
1778 struct ieee80211_txq_params *txq_params)
1779{
Johannes Berga3304b02012-03-28 11:04:24 +02001780 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001781 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1782 !tb[NL80211_TXQ_ATTR_AIFS])
1783 return -EINVAL;
1784
Johannes Berga3304b02012-03-28 11:04:24 +02001785 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001786 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1787 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1788 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1789 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1790
Johannes Berga3304b02012-03-28 11:04:24 +02001791 if (txq_params->ac >= NL80211_NUM_ACS)
1792 return -EINVAL;
1793
Jouni Malinen31888482008-10-30 16:59:24 +02001794 return 0;
1795}
1796
Johannes Bergf444de02010-05-05 15:25:02 +02001797static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1798{
1799 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001800 * You can only set the channel explicitly for WDS interfaces,
1801 * all others have their channel managed via their respective
1802 * "establish a connection" command (connect, join, ...)
1803 *
1804 * For AP/GO and mesh mode, the channel can be set with the
1805 * channel userspace API, but is only stored and passed to the
1806 * low-level driver when the AP starts or the mesh is joined.
1807 * This is for backward compatibility, userspace can also give
1808 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001809 *
1810 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001811 * whatever else is going on, so they have their own special
1812 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001813 */
1814 return !wdev ||
1815 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001816 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001817 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1818 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001819}
1820
Johannes Berg683b6d32012-11-08 21:25:48 +01001821static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1822 struct genl_info *info,
1823 struct cfg80211_chan_def *chandef)
1824{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301825 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001826
1827 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1828 return -EINVAL;
1829
1830 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1831
1832 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001833 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1834 chandef->center_freq1 = control_freq;
1835 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001836
1837 /* Primary channel not allowed */
1838 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1839 return -EINVAL;
1840
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001841 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1842 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001843
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001844 chantype = nla_get_u32(
1845 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1846
1847 switch (chantype) {
1848 case NL80211_CHAN_NO_HT:
1849 case NL80211_CHAN_HT20:
1850 case NL80211_CHAN_HT40PLUS:
1851 case NL80211_CHAN_HT40MINUS:
1852 cfg80211_chandef_create(chandef, chandef->chan,
1853 chantype);
1854 break;
1855 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001856 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001857 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001858 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1859 chandef->width =
1860 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1861 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1862 chandef->center_freq1 =
1863 nla_get_u32(
1864 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1865 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1866 chandef->center_freq2 =
1867 nla_get_u32(
1868 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1869 }
1870
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001871 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001872 return -EINVAL;
1873
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001874 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1875 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001876 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001877
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001878 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1879 chandef->width == NL80211_CHAN_WIDTH_10) &&
1880 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1881 return -EINVAL;
1882
Johannes Berg683b6d32012-11-08 21:25:48 +01001883 return 0;
1884}
1885
Johannes Bergf444de02010-05-05 15:25:02 +02001886static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1887 struct wireless_dev *wdev,
1888 struct genl_info *info)
1889{
Johannes Berg683b6d32012-11-08 21:25:48 +01001890 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001891 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001892 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1893
1894 if (wdev)
1895 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001896
Johannes Bergf444de02010-05-05 15:25:02 +02001897 if (!nl80211_can_set_dev_channel(wdev))
1898 return -EOPNOTSUPP;
1899
Johannes Berg683b6d32012-11-08 21:25:48 +01001900 result = nl80211_parse_chandef(rdev, info, &chandef);
1901 if (result)
1902 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001903
Johannes Berge8c9bd52012-06-06 08:18:22 +02001904 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001905 case NL80211_IFTYPE_AP:
1906 case NL80211_IFTYPE_P2P_GO:
1907 if (wdev->beacon_interval) {
1908 result = -EBUSY;
1909 break;
1910 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001911 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001912 result = -EINVAL;
1913 break;
1914 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001915 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001916 result = 0;
1917 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001918 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001919 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001920 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001921 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001922 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001923 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001924 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001925 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001926 }
Johannes Bergf444de02010-05-05 15:25:02 +02001927
1928 return result;
1929}
1930
1931static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1932{
Johannes Berg4c476992010-10-04 21:36:35 +02001933 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1934 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001935
Johannes Berg4c476992010-10-04 21:36:35 +02001936 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001937}
1938
Bill Jordane8347eb2010-10-01 13:54:28 -04001939static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1940{
Johannes Berg43b19952010-10-07 13:10:30 +02001941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1942 struct net_device *dev = info->user_ptr[1];
1943 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001944 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001945
1946 if (!info->attrs[NL80211_ATTR_MAC])
1947 return -EINVAL;
1948
Johannes Berg43b19952010-10-07 13:10:30 +02001949 if (netif_running(dev))
1950 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001951
Johannes Berg43b19952010-10-07 13:10:30 +02001952 if (!rdev->ops->set_wds_peer)
1953 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001954
Johannes Berg43b19952010-10-07 13:10:30 +02001955 if (wdev->iftype != NL80211_IFTYPE_WDS)
1956 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001957
1958 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001959 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001960}
1961
1962
Johannes Berg55682962007-09-20 13:09:35 -04001963static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1964{
1965 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001966 struct net_device *netdev = NULL;
1967 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001968 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001969 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001970 u32 changed;
1971 u8 retry_short = 0, retry_long = 0;
1972 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001973 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001974
Johannes Berg5fe231e2013-05-08 21:45:15 +02001975 ASSERT_RTNL();
1976
Johannes Bergf444de02010-05-05 15:25:02 +02001977 /*
1978 * Try to find the wiphy and netdev. Normally this
1979 * function shouldn't need the netdev, but this is
1980 * done for backward compatibility -- previously
1981 * setting the channel was done per wiphy, but now
1982 * it is per netdev. Previous userland like hostapd
1983 * also passed a netdev to set_wiphy, so that it is
1984 * possible to let that go to the right netdev!
1985 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001986
Johannes Bergf444de02010-05-05 15:25:02 +02001987 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1988 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1989
1990 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001991 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001992 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001993 else
Johannes Bergf444de02010-05-05 15:25:02 +02001994 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001995 }
1996
Johannes Bergf444de02010-05-05 15:25:02 +02001997 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001998 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1999 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002000 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002001 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002002 wdev = NULL;
2003 netdev = NULL;
2004 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002005 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002006 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002007
2008 /*
2009 * end workaround code, by now the rdev is available
2010 * and locked, and wdev may or may not be NULL.
2011 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002012
2013 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002014 result = cfg80211_dev_rename(
2015 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002016
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002017 if (result)
2018 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04002019
Jouni Malinen31888482008-10-30 16:59:24 +02002020 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2021 struct ieee80211_txq_params txq_params;
2022 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2023
2024 if (!rdev->ops->set_txq_params) {
2025 result = -EOPNOTSUPP;
2026 goto bad_res;
2027 }
2028
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002029 if (!netdev) {
2030 result = -EINVAL;
2031 goto bad_res;
2032 }
2033
Johannes Berg133a3ff2011-11-03 14:50:13 +01002034 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2035 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
2036 result = -EINVAL;
2037 goto bad_res;
2038 }
2039
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002040 if (!netif_running(netdev)) {
2041 result = -ENETDOWN;
2042 goto bad_res;
2043 }
2044
Jouni Malinen31888482008-10-30 16:59:24 +02002045 nla_for_each_nested(nl_txq_params,
2046 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2047 rem_txq_params) {
2048 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2049 nla_data(nl_txq_params),
2050 nla_len(nl_txq_params),
2051 txq_params_policy);
2052 result = parse_txq_params(tb, &txq_params);
2053 if (result)
2054 goto bad_res;
2055
Hila Gonene35e4d22012-06-27 17:19:42 +03002056 result = rdev_set_txq_params(rdev, netdev,
2057 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002058 if (result)
2059 goto bad_res;
2060 }
2061 }
2062
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002063 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002064 result = __nl80211_set_channel(rdev,
2065 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2066 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002067 if (result)
2068 goto bad_res;
2069 }
2070
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002071 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002072 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002073 enum nl80211_tx_power_setting type;
2074 int idx, mbm = 0;
2075
Johannes Bergc8442112012-10-24 10:17:18 +02002076 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2077 txp_wdev = NULL;
2078
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002079 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002080 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002081 goto bad_res;
2082 }
2083
2084 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2085 type = nla_get_u32(info->attrs[idx]);
2086
2087 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2088 (type != NL80211_TX_POWER_AUTOMATIC)) {
2089 result = -EINVAL;
2090 goto bad_res;
2091 }
2092
2093 if (type != NL80211_TX_POWER_AUTOMATIC) {
2094 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2095 mbm = nla_get_u32(info->attrs[idx]);
2096 }
2097
Johannes Bergc8442112012-10-24 10:17:18 +02002098 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002099 if (result)
2100 goto bad_res;
2101 }
2102
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002103 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2104 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2105 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002106 if ((!rdev->wiphy.available_antennas_tx &&
2107 !rdev->wiphy.available_antennas_rx) ||
2108 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002109 result = -EOPNOTSUPP;
2110 goto bad_res;
2111 }
2112
2113 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2114 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2115
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002116 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002117 * available antenna masks, except for the "all" mask */
2118 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2119 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002120 result = -EINVAL;
2121 goto bad_res;
2122 }
2123
Bruno Randolf7f531e02010-12-16 11:30:22 +09002124 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2125 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002126
Hila Gonene35e4d22012-06-27 17:19:42 +03002127 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002128 if (result)
2129 goto bad_res;
2130 }
2131
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002132 changed = 0;
2133
2134 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2135 retry_short = nla_get_u8(
2136 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2137 if (retry_short == 0) {
2138 result = -EINVAL;
2139 goto bad_res;
2140 }
2141 changed |= WIPHY_PARAM_RETRY_SHORT;
2142 }
2143
2144 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2145 retry_long = nla_get_u8(
2146 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2147 if (retry_long == 0) {
2148 result = -EINVAL;
2149 goto bad_res;
2150 }
2151 changed |= WIPHY_PARAM_RETRY_LONG;
2152 }
2153
2154 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2155 frag_threshold = nla_get_u32(
2156 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2157 if (frag_threshold < 256) {
2158 result = -EINVAL;
2159 goto bad_res;
2160 }
2161 if (frag_threshold != (u32) -1) {
2162 /*
2163 * Fragments (apart from the last one) are required to
2164 * have even length. Make the fragmentation code
2165 * simpler by stripping LSB should someone try to use
2166 * odd threshold value.
2167 */
2168 frag_threshold &= ~0x1;
2169 }
2170 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2171 }
2172
2173 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2174 rts_threshold = nla_get_u32(
2175 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2176 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2177 }
2178
Lukáš Turek81077e82009-12-21 22:50:47 +01002179 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2180 coverage_class = nla_get_u8(
2181 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2182 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2183 }
2184
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002185 if (changed) {
2186 u8 old_retry_short, old_retry_long;
2187 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002188 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002189
2190 if (!rdev->ops->set_wiphy_params) {
2191 result = -EOPNOTSUPP;
2192 goto bad_res;
2193 }
2194
2195 old_retry_short = rdev->wiphy.retry_short;
2196 old_retry_long = rdev->wiphy.retry_long;
2197 old_frag_threshold = rdev->wiphy.frag_threshold;
2198 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002199 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002200
2201 if (changed & WIPHY_PARAM_RETRY_SHORT)
2202 rdev->wiphy.retry_short = retry_short;
2203 if (changed & WIPHY_PARAM_RETRY_LONG)
2204 rdev->wiphy.retry_long = retry_long;
2205 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2206 rdev->wiphy.frag_threshold = frag_threshold;
2207 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2208 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002209 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2210 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002211
Hila Gonene35e4d22012-06-27 17:19:42 +03002212 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002213 if (result) {
2214 rdev->wiphy.retry_short = old_retry_short;
2215 rdev->wiphy.retry_long = old_retry_long;
2216 rdev->wiphy.frag_threshold = old_frag_threshold;
2217 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002218 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002219 }
2220 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002221
Johannes Berg306d6112008-12-08 12:39:04 +01002222 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002223 if (netdev)
2224 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002225 return result;
2226}
2227
Johannes Berg71bbc992012-06-15 15:30:18 +02002228static inline u64 wdev_id(struct wireless_dev *wdev)
2229{
2230 return (u64)wdev->identifier |
2231 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2232}
Johannes Berg55682962007-09-20 13:09:35 -04002233
Johannes Berg683b6d32012-11-08 21:25:48 +01002234static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002235 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002236{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002237 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002238
Johannes Berg683b6d32012-11-08 21:25:48 +01002239 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2240 chandef->chan->center_freq))
2241 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002242 switch (chandef->width) {
2243 case NL80211_CHAN_WIDTH_20_NOHT:
2244 case NL80211_CHAN_WIDTH_20:
2245 case NL80211_CHAN_WIDTH_40:
2246 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2247 cfg80211_get_chandef_type(chandef)))
2248 return -ENOBUFS;
2249 break;
2250 default:
2251 break;
2252 }
2253 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2254 return -ENOBUFS;
2255 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2256 return -ENOBUFS;
2257 if (chandef->center_freq2 &&
2258 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002259 return -ENOBUFS;
2260 return 0;
2261}
2262
Eric W. Biederman15e47302012-09-07 20:12:54 +00002263static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002264 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002265 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002266{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002267 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002268 void *hdr;
2269
Eric W. Biederman15e47302012-09-07 20:12:54 +00002270 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002271 if (!hdr)
2272 return -1;
2273
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002274 if (dev &&
2275 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002276 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002277 goto nla_put_failure;
2278
2279 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2280 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002281 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002282 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002283 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2284 rdev->devlist_generation ^
2285 (cfg80211_rdev_list_generation << 2)))
2286 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002287
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002288 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002289 int ret;
2290 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002291
Johannes Berg683b6d32012-11-08 21:25:48 +01002292 ret = rdev_get_channel(rdev, wdev, &chandef);
2293 if (ret == 0) {
2294 if (nl80211_send_chandef(msg, &chandef))
2295 goto nla_put_failure;
2296 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002297 }
2298
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002299 if (wdev->ssid_len) {
2300 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2301 goto nla_put_failure;
2302 }
2303
Johannes Berg55682962007-09-20 13:09:35 -04002304 return genlmsg_end(msg, hdr);
2305
2306 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002307 genlmsg_cancel(msg, hdr);
2308 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002309}
2310
2311static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2312{
2313 int wp_idx = 0;
2314 int if_idx = 0;
2315 int wp_start = cb->args[0];
2316 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002317 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002318 struct wireless_dev *wdev;
2319
Johannes Berg5fe231e2013-05-08 21:45:15 +02002320 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002321 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2322 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002323 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002324 if (wp_idx < wp_start) {
2325 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002326 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002327 }
Johannes Berg55682962007-09-20 13:09:35 -04002328 if_idx = 0;
2329
Johannes Berg89a54e42012-06-15 14:33:17 +02002330 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002331 if (if_idx < if_start) {
2332 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002333 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002334 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002335 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002336 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002337 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002338 goto out;
2339 }
2340 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002341 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002342
2343 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002344 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002345 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002346 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002347
2348 cb->args[0] = wp_idx;
2349 cb->args[1] = if_idx;
2350
2351 return skb->len;
2352}
2353
2354static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2355{
2356 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002357 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002358 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002359
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002360 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002361 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002362 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002363
Eric W. Biederman15e47302012-09-07 20:12:54 +00002364 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002365 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002366 nlmsg_free(msg);
2367 return -ENOBUFS;
2368 }
Johannes Berg55682962007-09-20 13:09:35 -04002369
Johannes Berg134e6372009-07-10 09:51:34 +00002370 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002371}
2372
Michael Wu66f7ac52008-01-31 19:48:22 +01002373static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2374 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2375 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2376 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2377 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2378 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002379 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002380};
2381
2382static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2383{
2384 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2385 int flag;
2386
2387 *mntrflags = 0;
2388
2389 if (!nla)
2390 return -EINVAL;
2391
2392 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2393 nla, mntr_flags_policy))
2394 return -EINVAL;
2395
2396 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2397 if (flags[flag])
2398 *mntrflags |= (1<<flag);
2399
2400 return 0;
2401}
2402
Johannes Berg9bc383d2009-11-19 11:55:19 +01002403static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002404 struct net_device *netdev, u8 use_4addr,
2405 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002406{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002407 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002408 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002409 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002410 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002411 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002412
2413 switch (iftype) {
2414 case NL80211_IFTYPE_AP_VLAN:
2415 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2416 return 0;
2417 break;
2418 case NL80211_IFTYPE_STATION:
2419 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2420 return 0;
2421 break;
2422 default:
2423 break;
2424 }
2425
2426 return -EOPNOTSUPP;
2427}
2428
Johannes Berg55682962007-09-20 13:09:35 -04002429static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2430{
Johannes Berg4c476992010-10-04 21:36:35 +02002431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002432 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002433 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002434 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002435 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002436 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002437 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002438
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002439 memset(&params, 0, sizeof(params));
2440
Johannes Berg04a773a2009-04-19 21:24:32 +02002441 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002442
Johannes Berg723b0382008-09-16 20:22:09 +02002443 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002444 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002445 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002446 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002447 if (ntype > NL80211_IFTYPE_MAX)
2448 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002449 }
2450
Johannes Berg92ffe052008-09-16 20:39:36 +02002451 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002452 struct wireless_dev *wdev = dev->ieee80211_ptr;
2453
Johannes Berg4c476992010-10-04 21:36:35 +02002454 if (ntype != NL80211_IFTYPE_MESH_POINT)
2455 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002456 if (netif_running(dev))
2457 return -EBUSY;
2458
2459 wdev_lock(wdev);
2460 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2461 IEEE80211_MAX_MESH_ID_LEN);
2462 wdev->mesh_id_up_len =
2463 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2464 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2465 wdev->mesh_id_up_len);
2466 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002467 }
2468
Felix Fietkau8b787642009-11-10 18:53:10 +01002469 if (info->attrs[NL80211_ATTR_4ADDR]) {
2470 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2471 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002472 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002473 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002474 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002475 } else {
2476 params.use_4addr = -1;
2477 }
2478
Johannes Berg92ffe052008-09-16 20:39:36 +02002479 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002480 if (ntype != NL80211_IFTYPE_MONITOR)
2481 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002482 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2483 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002484 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002485 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002486
2487 flags = &_flags;
2488 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002489 }
Johannes Berg3b858752009-03-12 09:55:09 +01002490
Luciano Coelho18003292013-08-29 13:26:57 +03002491 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002492 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2493 return -EOPNOTSUPP;
2494
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002495 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002496 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002497 else
2498 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002499
Johannes Berg9bc383d2009-11-19 11:55:19 +01002500 if (!err && params.use_4addr != -1)
2501 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2502
Johannes Berg55682962007-09-20 13:09:35 -04002503 return err;
2504}
2505
2506static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2507{
Johannes Berg4c476992010-10-04 21:36:35 +02002508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002509 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002510 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002511 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002512 int err;
2513 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002514 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002515
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002516 memset(&params, 0, sizeof(params));
2517
Johannes Berg55682962007-09-20 13:09:35 -04002518 if (!info->attrs[NL80211_ATTR_IFNAME])
2519 return -EINVAL;
2520
2521 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2522 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2523 if (type > NL80211_IFTYPE_MAX)
2524 return -EINVAL;
2525 }
2526
Johannes Berg79c97e92009-07-07 03:56:12 +02002527 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002528 !(rdev->wiphy.interface_modes & (1 << type)))
2529 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002530
Arend van Spriel1c18f142013-01-08 10:17:27 +01002531 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2532 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2533 ETH_ALEN);
2534 if (!is_valid_ether_addr(params.macaddr))
2535 return -EADDRNOTAVAIL;
2536 }
2537
Johannes Berg9bc383d2009-11-19 11:55:19 +01002538 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002539 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002540 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002541 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002542 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002543 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002544
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002545 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2546 if (!msg)
2547 return -ENOMEM;
2548
Michael Wu66f7ac52008-01-31 19:48:22 +01002549 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2550 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2551 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002552
Luciano Coelho18003292013-08-29 13:26:57 +03002553 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002554 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2555 return -EOPNOTSUPP;
2556
Hila Gonene35e4d22012-06-27 17:19:42 +03002557 wdev = rdev_add_virtual_intf(rdev,
2558 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2559 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002560 if (IS_ERR(wdev)) {
2561 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002562 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002563 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002564
Johannes Berg98104fde2012-06-16 00:19:54 +02002565 switch (type) {
2566 case NL80211_IFTYPE_MESH_POINT:
2567 if (!info->attrs[NL80211_ATTR_MESH_ID])
2568 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002569 wdev_lock(wdev);
2570 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2571 IEEE80211_MAX_MESH_ID_LEN);
2572 wdev->mesh_id_up_len =
2573 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2574 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2575 wdev->mesh_id_up_len);
2576 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002577 break;
2578 case NL80211_IFTYPE_P2P_DEVICE:
2579 /*
2580 * P2P Device doesn't have a netdev, so doesn't go
2581 * through the netdev notifier and must be added here
2582 */
2583 mutex_init(&wdev->mtx);
2584 INIT_LIST_HEAD(&wdev->event_list);
2585 spin_lock_init(&wdev->event_lock);
2586 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2587 spin_lock_init(&wdev->mgmt_registrations_lock);
2588
Johannes Berg98104fde2012-06-16 00:19:54 +02002589 wdev->identifier = ++rdev->wdev_id;
2590 list_add_rcu(&wdev->list, &rdev->wdev_list);
2591 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002592 break;
2593 default:
2594 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002595 }
2596
Eric W. Biederman15e47302012-09-07 20:12:54 +00002597 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002598 rdev, wdev) < 0) {
2599 nlmsg_free(msg);
2600 return -ENOBUFS;
2601 }
2602
2603 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002604}
2605
2606static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2607{
Johannes Berg4c476992010-10-04 21:36:35 +02002608 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002609 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002610
Johannes Berg4c476992010-10-04 21:36:35 +02002611 if (!rdev->ops->del_virtual_intf)
2612 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002613
Johannes Berg84efbb82012-06-16 00:00:26 +02002614 /*
2615 * If we remove a wireless device without a netdev then clear
2616 * user_ptr[1] so that nl80211_post_doit won't dereference it
2617 * to check if it needs to do dev_put(). Otherwise it crashes
2618 * since the wdev has been freed, unlike with a netdev where
2619 * we need the dev_put() for the netdev to really be freed.
2620 */
2621 if (!wdev->netdev)
2622 info->user_ptr[1] = NULL;
2623
Hila Gonene35e4d22012-06-27 17:19:42 +03002624 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002625}
2626
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002627static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2628{
2629 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2630 struct net_device *dev = info->user_ptr[1];
2631 u16 noack_map;
2632
2633 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2634 return -EINVAL;
2635
2636 if (!rdev->ops->set_noack_map)
2637 return -EOPNOTSUPP;
2638
2639 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2640
Hila Gonene35e4d22012-06-27 17:19:42 +03002641 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002642}
2643
Johannes Berg41ade002007-12-19 02:03:29 +01002644struct get_key_cookie {
2645 struct sk_buff *msg;
2646 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002647 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002648};
2649
2650static void get_key_callback(void *c, struct key_params *params)
2651{
Johannes Bergb9454e82009-07-08 13:29:08 +02002652 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002653 struct get_key_cookie *cookie = c;
2654
David S. Miller9360ffd2012-03-29 04:41:26 -04002655 if ((params->key &&
2656 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2657 params->key_len, params->key)) ||
2658 (params->seq &&
2659 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2660 params->seq_len, params->seq)) ||
2661 (params->cipher &&
2662 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2663 params->cipher)))
2664 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002665
Johannes Bergb9454e82009-07-08 13:29:08 +02002666 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2667 if (!key)
2668 goto nla_put_failure;
2669
David S. Miller9360ffd2012-03-29 04:41:26 -04002670 if ((params->key &&
2671 nla_put(cookie->msg, NL80211_KEY_DATA,
2672 params->key_len, params->key)) ||
2673 (params->seq &&
2674 nla_put(cookie->msg, NL80211_KEY_SEQ,
2675 params->seq_len, params->seq)) ||
2676 (params->cipher &&
2677 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2678 params->cipher)))
2679 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002680
David S. Miller9360ffd2012-03-29 04:41:26 -04002681 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2682 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002683
2684 nla_nest_end(cookie->msg, key);
2685
Johannes Berg41ade002007-12-19 02:03:29 +01002686 return;
2687 nla_put_failure:
2688 cookie->error = 1;
2689}
2690
2691static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2692{
Johannes Berg4c476992010-10-04 21:36:35 +02002693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002694 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002695 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002696 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002697 const u8 *mac_addr = NULL;
2698 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002699 struct get_key_cookie cookie = {
2700 .error = 0,
2701 };
2702 void *hdr;
2703 struct sk_buff *msg;
2704
2705 if (info->attrs[NL80211_ATTR_KEY_IDX])
2706 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2707
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002708 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002709 return -EINVAL;
2710
2711 if (info->attrs[NL80211_ATTR_MAC])
2712 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2713
Johannes Berge31b8212010-10-05 19:39:30 +02002714 pairwise = !!mac_addr;
2715 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2716 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2717 if (kt >= NUM_NL80211_KEYTYPES)
2718 return -EINVAL;
2719 if (kt != NL80211_KEYTYPE_GROUP &&
2720 kt != NL80211_KEYTYPE_PAIRWISE)
2721 return -EINVAL;
2722 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2723 }
2724
Johannes Berg4c476992010-10-04 21:36:35 +02002725 if (!rdev->ops->get_key)
2726 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002727
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002728 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002729 if (!msg)
2730 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002731
Eric W. Biederman15e47302012-09-07 20:12:54 +00002732 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002733 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002734 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002735 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002736
2737 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002738 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002739
David S. Miller9360ffd2012-03-29 04:41:26 -04002740 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2741 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2742 goto nla_put_failure;
2743 if (mac_addr &&
2744 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2745 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002746
Johannes Berge31b8212010-10-05 19:39:30 +02002747 if (pairwise && mac_addr &&
2748 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2749 return -ENOENT;
2750
Hila Gonene35e4d22012-06-27 17:19:42 +03002751 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2752 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002753
2754 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002755 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002756
2757 if (cookie.error)
2758 goto nla_put_failure;
2759
2760 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002761 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002762
2763 nla_put_failure:
2764 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002765 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002766 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002767 return err;
2768}
2769
2770static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2771{
Johannes Berg4c476992010-10-04 21:36:35 +02002772 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002773 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002774 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002775 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002776
Johannes Bergb9454e82009-07-08 13:29:08 +02002777 err = nl80211_parse_key(info, &key);
2778 if (err)
2779 return err;
2780
2781 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002782 return -EINVAL;
2783
Johannes Bergb9454e82009-07-08 13:29:08 +02002784 /* only support setting default key */
2785 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002786 return -EINVAL;
2787
Johannes Bergfffd0932009-07-08 14:22:54 +02002788 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002789
2790 if (key.def) {
2791 if (!rdev->ops->set_default_key) {
2792 err = -EOPNOTSUPP;
2793 goto out;
2794 }
2795
2796 err = nl80211_key_allowed(dev->ieee80211_ptr);
2797 if (err)
2798 goto out;
2799
Hila Gonene35e4d22012-06-27 17:19:42 +03002800 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002801 key.def_uni, key.def_multi);
2802
2803 if (err)
2804 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002805
Johannes Berg3d23e342009-09-29 23:27:28 +02002806#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002807 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002808#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002809 } else {
2810 if (key.def_uni || !key.def_multi) {
2811 err = -EINVAL;
2812 goto out;
2813 }
2814
2815 if (!rdev->ops->set_default_mgmt_key) {
2816 err = -EOPNOTSUPP;
2817 goto out;
2818 }
2819
2820 err = nl80211_key_allowed(dev->ieee80211_ptr);
2821 if (err)
2822 goto out;
2823
Hila Gonene35e4d22012-06-27 17:19:42 +03002824 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002825 if (err)
2826 goto out;
2827
2828#ifdef CONFIG_CFG80211_WEXT
2829 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2830#endif
2831 }
2832
2833 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002834 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002835
Johannes Berg41ade002007-12-19 02:03:29 +01002836 return err;
2837}
2838
2839static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2840{
Johannes Berg4c476992010-10-04 21:36:35 +02002841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002842 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002843 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002844 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002845 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002846
Johannes Bergb9454e82009-07-08 13:29:08 +02002847 err = nl80211_parse_key(info, &key);
2848 if (err)
2849 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002850
Johannes Bergb9454e82009-07-08 13:29:08 +02002851 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002852 return -EINVAL;
2853
Johannes Berg41ade002007-12-19 02:03:29 +01002854 if (info->attrs[NL80211_ATTR_MAC])
2855 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2856
Johannes Berge31b8212010-10-05 19:39:30 +02002857 if (key.type == -1) {
2858 if (mac_addr)
2859 key.type = NL80211_KEYTYPE_PAIRWISE;
2860 else
2861 key.type = NL80211_KEYTYPE_GROUP;
2862 }
2863
2864 /* for now */
2865 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2866 key.type != NL80211_KEYTYPE_GROUP)
2867 return -EINVAL;
2868
Johannes Berg4c476992010-10-04 21:36:35 +02002869 if (!rdev->ops->add_key)
2870 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002871
Johannes Berge31b8212010-10-05 19:39:30 +02002872 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2873 key.type == NL80211_KEYTYPE_PAIRWISE,
2874 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002875 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002876
2877 wdev_lock(dev->ieee80211_ptr);
2878 err = nl80211_key_allowed(dev->ieee80211_ptr);
2879 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002880 err = rdev_add_key(rdev, dev, key.idx,
2881 key.type == NL80211_KEYTYPE_PAIRWISE,
2882 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002883 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002884
Johannes Berg41ade002007-12-19 02:03:29 +01002885 return err;
2886}
2887
2888static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2889{
Johannes Berg4c476992010-10-04 21:36:35 +02002890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002891 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002892 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002893 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002894 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002895
Johannes Bergb9454e82009-07-08 13:29:08 +02002896 err = nl80211_parse_key(info, &key);
2897 if (err)
2898 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002899
2900 if (info->attrs[NL80211_ATTR_MAC])
2901 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2902
Johannes Berge31b8212010-10-05 19:39:30 +02002903 if (key.type == -1) {
2904 if (mac_addr)
2905 key.type = NL80211_KEYTYPE_PAIRWISE;
2906 else
2907 key.type = NL80211_KEYTYPE_GROUP;
2908 }
2909
2910 /* for now */
2911 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2912 key.type != NL80211_KEYTYPE_GROUP)
2913 return -EINVAL;
2914
Johannes Berg4c476992010-10-04 21:36:35 +02002915 if (!rdev->ops->del_key)
2916 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002917
Johannes Bergfffd0932009-07-08 14:22:54 +02002918 wdev_lock(dev->ieee80211_ptr);
2919 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002920
2921 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2922 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2923 err = -ENOENT;
2924
Johannes Bergfffd0932009-07-08 14:22:54 +02002925 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002926 err = rdev_del_key(rdev, dev, key.idx,
2927 key.type == NL80211_KEYTYPE_PAIRWISE,
2928 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002929
Johannes Berg3d23e342009-09-29 23:27:28 +02002930#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002931 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002932 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002933 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002934 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002935 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2936 }
2937#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002938 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002939
Johannes Berg41ade002007-12-19 02:03:29 +01002940 return err;
2941}
2942
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302943/* This function returns an error or the number of nested attributes */
2944static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2945{
2946 struct nlattr *attr;
2947 int n_entries = 0, tmp;
2948
2949 nla_for_each_nested(attr, nl_attr, tmp) {
2950 if (nla_len(attr) != ETH_ALEN)
2951 return -EINVAL;
2952
2953 n_entries++;
2954 }
2955
2956 return n_entries;
2957}
2958
2959/*
2960 * This function parses ACL information and allocates memory for ACL data.
2961 * On successful return, the calling function is responsible to free the
2962 * ACL buffer returned by this function.
2963 */
2964static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2965 struct genl_info *info)
2966{
2967 enum nl80211_acl_policy acl_policy;
2968 struct nlattr *attr;
2969 struct cfg80211_acl_data *acl;
2970 int i = 0, n_entries, tmp;
2971
2972 if (!wiphy->max_acl_mac_addrs)
2973 return ERR_PTR(-EOPNOTSUPP);
2974
2975 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2976 return ERR_PTR(-EINVAL);
2977
2978 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2979 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2980 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2981 return ERR_PTR(-EINVAL);
2982
2983 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2984 return ERR_PTR(-EINVAL);
2985
2986 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2987 if (n_entries < 0)
2988 return ERR_PTR(n_entries);
2989
2990 if (n_entries > wiphy->max_acl_mac_addrs)
2991 return ERR_PTR(-ENOTSUPP);
2992
2993 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2994 GFP_KERNEL);
2995 if (!acl)
2996 return ERR_PTR(-ENOMEM);
2997
2998 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2999 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3000 i++;
3001 }
3002
3003 acl->n_acl_entries = n_entries;
3004 acl->acl_policy = acl_policy;
3005
3006 return acl;
3007}
3008
3009static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3010{
3011 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3012 struct net_device *dev = info->user_ptr[1];
3013 struct cfg80211_acl_data *acl;
3014 int err;
3015
3016 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3017 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3018 return -EOPNOTSUPP;
3019
3020 if (!dev->ieee80211_ptr->beacon_interval)
3021 return -EINVAL;
3022
3023 acl = parse_acl_data(&rdev->wiphy, info);
3024 if (IS_ERR(acl))
3025 return PTR_ERR(acl);
3026
3027 err = rdev_set_mac_acl(rdev, dev, acl);
3028
3029 kfree(acl);
3030
3031 return err;
3032}
3033
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003034static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003035 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003036{
Johannes Berg88600202012-02-13 15:17:18 +01003037 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003038
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003039 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3040 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3041 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3042 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003043 return -EINVAL;
3044
Johannes Berg88600202012-02-13 15:17:18 +01003045 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003046
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003047 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3048 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3049 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003050 if (!bcn->head_len)
3051 return -EINVAL;
3052 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003053 }
3054
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003055 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3056 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3057 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003058 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003059 }
3060
Johannes Berg4c476992010-10-04 21:36:35 +02003061 if (!haveinfo)
3062 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003063
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003064 if (attrs[NL80211_ATTR_IE]) {
3065 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3066 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003067 }
3068
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003069 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003070 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003071 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003072 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003073 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003074 }
3075
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003076 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003077 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003078 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003079 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003080 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003081 }
3082
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003083 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3084 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3085 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003086 }
3087
Johannes Berg88600202012-02-13 15:17:18 +01003088 return 0;
3089}
3090
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003091static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3092 struct cfg80211_ap_settings *params)
3093{
3094 struct wireless_dev *wdev;
3095 bool ret = false;
3096
Johannes Berg89a54e42012-06-15 14:33:17 +02003097 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003098 if (wdev->iftype != NL80211_IFTYPE_AP &&
3099 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3100 continue;
3101
Johannes Berg683b6d32012-11-08 21:25:48 +01003102 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003103 continue;
3104
Johannes Berg683b6d32012-11-08 21:25:48 +01003105 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003106 ret = true;
3107 break;
3108 }
3109
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003110 return ret;
3111}
3112
Jouni Malinene39e5b52012-09-30 19:29:39 +03003113static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3114 enum nl80211_auth_type auth_type,
3115 enum nl80211_commands cmd)
3116{
3117 if (auth_type > NL80211_AUTHTYPE_MAX)
3118 return false;
3119
3120 switch (cmd) {
3121 case NL80211_CMD_AUTHENTICATE:
3122 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3123 auth_type == NL80211_AUTHTYPE_SAE)
3124 return false;
3125 return true;
3126 case NL80211_CMD_CONNECT:
3127 case NL80211_CMD_START_AP:
3128 /* SAE not supported yet */
3129 if (auth_type == NL80211_AUTHTYPE_SAE)
3130 return false;
3131 return true;
3132 default:
3133 return false;
3134 }
3135}
3136
Johannes Berg88600202012-02-13 15:17:18 +01003137static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3138{
3139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3140 struct net_device *dev = info->user_ptr[1];
3141 struct wireless_dev *wdev = dev->ieee80211_ptr;
3142 struct cfg80211_ap_settings params;
3143 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003144 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003145
3146 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3147 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3148 return -EOPNOTSUPP;
3149
3150 if (!rdev->ops->start_ap)
3151 return -EOPNOTSUPP;
3152
3153 if (wdev->beacon_interval)
3154 return -EALREADY;
3155
3156 memset(&params, 0, sizeof(params));
3157
3158 /* these are required for START_AP */
3159 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3160 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3161 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3162 return -EINVAL;
3163
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003164 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003165 if (err)
3166 return err;
3167
3168 params.beacon_interval =
3169 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3170 params.dtim_period =
3171 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3172
3173 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3174 if (err)
3175 return err;
3176
3177 /*
3178 * In theory, some of these attributes should be required here
3179 * but since they were not used when the command was originally
3180 * added, keep them optional for old user space programs to let
3181 * them continue to work with drivers that do not need the
3182 * additional information -- drivers must check!
3183 */
3184 if (info->attrs[NL80211_ATTR_SSID]) {
3185 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3186 params.ssid_len =
3187 nla_len(info->attrs[NL80211_ATTR_SSID]);
3188 if (params.ssid_len == 0 ||
3189 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3190 return -EINVAL;
3191 }
3192
3193 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3194 params.hidden_ssid = nla_get_u32(
3195 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3196 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3197 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3198 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3199 return -EINVAL;
3200 }
3201
3202 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3203
3204 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3205 params.auth_type = nla_get_u32(
3206 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003207 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3208 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003209 return -EINVAL;
3210 } else
3211 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3212
3213 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3214 NL80211_MAX_NR_CIPHER_SUITES);
3215 if (err)
3216 return err;
3217
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303218 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3219 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3220 return -EOPNOTSUPP;
3221 params.inactivity_timeout = nla_get_u16(
3222 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3223 }
3224
Johannes Berg53cabad2012-11-14 15:17:28 +01003225 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3226 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3227 return -EINVAL;
3228 params.p2p_ctwindow =
3229 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3230 if (params.p2p_ctwindow > 127)
3231 return -EINVAL;
3232 if (params.p2p_ctwindow != 0 &&
3233 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3234 return -EINVAL;
3235 }
3236
3237 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3238 u8 tmp;
3239
3240 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3241 return -EINVAL;
3242 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3243 if (tmp > 1)
3244 return -EINVAL;
3245 params.p2p_opp_ps = tmp;
3246 if (params.p2p_opp_ps != 0 &&
3247 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3248 return -EINVAL;
3249 }
3250
Johannes Bergaa430da2012-05-16 23:50:18 +02003251 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003252 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3253 if (err)
3254 return err;
3255 } else if (wdev->preset_chandef.chan) {
3256 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003257 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003258 return -EINVAL;
3259
Johannes Berg683b6d32012-11-08 21:25:48 +01003260 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003261 return -EINVAL;
3262
Simon Wunderlich04f39042013-02-08 18:16:19 +01003263 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3264 if (err < 0)
3265 return err;
3266 if (err) {
3267 radar_detect_width = BIT(params.chandef.width);
3268 params.radar_required = true;
3269 }
3270
Simon Wunderlich04f39042013-02-08 18:16:19 +01003271 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3272 params.chandef.chan,
3273 CHAN_MODE_SHARED,
3274 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003275 if (err)
3276 return err;
3277
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303278 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3279 params.acl = parse_acl_data(&rdev->wiphy, info);
3280 if (IS_ERR(params.acl))
3281 return PTR_ERR(params.acl);
3282 }
3283
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003284 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003285 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003286 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003287 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003288 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003289 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003290 wdev->ssid_len = params.ssid_len;
3291 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003292 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003293 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303294
3295 kfree(params.acl);
3296
Johannes Berg56d18932011-05-09 18:41:15 +02003297 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003298}
3299
Johannes Berg88600202012-02-13 15:17:18 +01003300static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3301{
3302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3303 struct net_device *dev = info->user_ptr[1];
3304 struct wireless_dev *wdev = dev->ieee80211_ptr;
3305 struct cfg80211_beacon_data params;
3306 int err;
3307
3308 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3309 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3310 return -EOPNOTSUPP;
3311
3312 if (!rdev->ops->change_beacon)
3313 return -EOPNOTSUPP;
3314
3315 if (!wdev->beacon_interval)
3316 return -EINVAL;
3317
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003318 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003319 if (err)
3320 return err;
3321
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003322 wdev_lock(wdev);
3323 err = rdev_change_beacon(rdev, dev, &params);
3324 wdev_unlock(wdev);
3325
3326 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003327}
3328
3329static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003330{
Johannes Berg4c476992010-10-04 21:36:35 +02003331 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3332 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003333
Michal Kazior60771782012-06-29 12:46:56 +02003334 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003335}
3336
Johannes Berg5727ef12007-12-19 02:03:34 +01003337static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3338 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3339 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3340 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003341 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003342 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003343 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003344};
3345
Johannes Bergeccb8e82009-05-11 21:57:56 +03003346static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003347 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003348 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003349{
3350 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003351 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003352 int flag;
3353
Johannes Bergeccb8e82009-05-11 21:57:56 +03003354 /*
3355 * Try parsing the new attribute first so userspace
3356 * can specify both for older kernels.
3357 */
3358 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3359 if (nla) {
3360 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003361
Johannes Bergeccb8e82009-05-11 21:57:56 +03003362 sta_flags = nla_data(nla);
3363 params->sta_flags_mask = sta_flags->mask;
3364 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003365 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003366 if ((params->sta_flags_mask |
3367 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3368 return -EINVAL;
3369 return 0;
3370 }
3371
3372 /* if present, parse the old attribute */
3373
3374 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003375 if (!nla)
3376 return 0;
3377
3378 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3379 nla, sta_flags_policy))
3380 return -EINVAL;
3381
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003382 /*
3383 * Only allow certain flags for interface types so that
3384 * other attributes are silently ignored. Remember that
3385 * this is backward compatibility code with old userspace
3386 * and shouldn't be hit in other cases anyway.
3387 */
3388 switch (iftype) {
3389 case NL80211_IFTYPE_AP:
3390 case NL80211_IFTYPE_AP_VLAN:
3391 case NL80211_IFTYPE_P2P_GO:
3392 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3393 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3394 BIT(NL80211_STA_FLAG_WME) |
3395 BIT(NL80211_STA_FLAG_MFP);
3396 break;
3397 case NL80211_IFTYPE_P2P_CLIENT:
3398 case NL80211_IFTYPE_STATION:
3399 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3400 BIT(NL80211_STA_FLAG_TDLS_PEER);
3401 break;
3402 case NL80211_IFTYPE_MESH_POINT:
3403 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3404 BIT(NL80211_STA_FLAG_MFP) |
3405 BIT(NL80211_STA_FLAG_AUTHORIZED);
3406 default:
3407 return -EINVAL;
3408 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003409
Johannes Berg3383b5a2012-05-10 20:14:43 +02003410 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3411 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003412 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003413
Johannes Berg3383b5a2012-05-10 20:14:43 +02003414 /* no longer support new API additions in old API */
3415 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3416 return -EINVAL;
3417 }
3418 }
3419
Johannes Berg5727ef12007-12-19 02:03:34 +01003420 return 0;
3421}
3422
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003423static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3424 int attr)
3425{
3426 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003427 u32 bitrate;
3428 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003429
3430 rate = nla_nest_start(msg, attr);
3431 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003432 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003433
3434 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3435 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003436 /* report 16-bit bitrate only if we can */
3437 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003438 if (bitrate > 0 &&
3439 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3440 return false;
3441 if (bitrate_compat > 0 &&
3442 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3443 return false;
3444
3445 if (info->flags & RATE_INFO_FLAGS_MCS) {
3446 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3447 return false;
3448 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3449 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3450 return false;
3451 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3452 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3453 return false;
3454 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3455 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3456 return false;
3457 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3458 return false;
3459 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3460 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3461 return false;
3462 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3463 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3464 return false;
3465 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3466 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3467 return false;
3468 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3469 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3470 return false;
3471 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3472 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3473 return false;
3474 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003475
3476 nla_nest_end(msg, rate);
3477 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003478}
3479
Felix Fietkau119363c2013-04-22 16:29:30 +02003480static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3481 int id)
3482{
3483 void *attr;
3484 int i = 0;
3485
3486 if (!mask)
3487 return true;
3488
3489 attr = nla_nest_start(msg, id);
3490 if (!attr)
3491 return false;
3492
3493 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3494 if (!(mask & BIT(i)))
3495 continue;
3496
3497 if (nla_put_u8(msg, i, signal[i]))
3498 return false;
3499 }
3500
3501 nla_nest_end(msg, attr);
3502
3503 return true;
3504}
3505
Eric W. Biederman15e47302012-09-07 20:12:54 +00003506static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003507 int flags,
3508 struct cfg80211_registered_device *rdev,
3509 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003510 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003511{
3512 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003513 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003514
Eric W. Biederman15e47302012-09-07 20:12:54 +00003515 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003516 if (!hdr)
3517 return -1;
3518
David S. Miller9360ffd2012-03-29 04:41:26 -04003519 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3520 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3521 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3522 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003523
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003524 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3525 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003526 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003527 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3528 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3529 sinfo->connected_time))
3530 goto nla_put_failure;
3531 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3532 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3533 sinfo->inactive_time))
3534 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003535 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3536 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003537 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003538 (u32)sinfo->rx_bytes))
3539 goto nla_put_failure;
3540 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003541 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003542 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3543 (u32)sinfo->tx_bytes))
3544 goto nla_put_failure;
3545 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3546 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003547 sinfo->rx_bytes))
3548 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003549 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3550 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003551 sinfo->tx_bytes))
3552 goto nla_put_failure;
3553 if ((sinfo->filled & STATION_INFO_LLID) &&
3554 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3555 goto nla_put_failure;
3556 if ((sinfo->filled & STATION_INFO_PLID) &&
3557 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3558 goto nla_put_failure;
3559 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3560 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3561 sinfo->plink_state))
3562 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003563 switch (rdev->wiphy.signal_type) {
3564 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003565 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3566 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3567 sinfo->signal))
3568 goto nla_put_failure;
3569 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3570 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3571 sinfo->signal_avg))
3572 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003573 break;
3574 default:
3575 break;
3576 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003577 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3578 if (!nl80211_put_signal(msg, sinfo->chains,
3579 sinfo->chain_signal,
3580 NL80211_STA_INFO_CHAIN_SIGNAL))
3581 goto nla_put_failure;
3582 }
3583 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3584 if (!nl80211_put_signal(msg, sinfo->chains,
3585 sinfo->chain_signal_avg,
3586 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3587 goto nla_put_failure;
3588 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003589 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003590 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3591 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003592 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003593 }
3594 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3595 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3596 NL80211_STA_INFO_RX_BITRATE))
3597 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003598 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003599 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3600 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3601 sinfo->rx_packets))
3602 goto nla_put_failure;
3603 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3604 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3605 sinfo->tx_packets))
3606 goto nla_put_failure;
3607 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3608 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3609 sinfo->tx_retries))
3610 goto nla_put_failure;
3611 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3612 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3613 sinfo->tx_failed))
3614 goto nla_put_failure;
3615 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3616 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3617 sinfo->beacon_loss_count))
3618 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003619 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3620 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3621 sinfo->local_pm))
3622 goto nla_put_failure;
3623 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3624 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3625 sinfo->peer_pm))
3626 goto nla_put_failure;
3627 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3628 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3629 sinfo->nonpeer_pm))
3630 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003631 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3632 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3633 if (!bss_param)
3634 goto nla_put_failure;
3635
David S. Miller9360ffd2012-03-29 04:41:26 -04003636 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3637 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3638 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3639 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3640 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3641 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3642 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3643 sinfo->bss_param.dtim_period) ||
3644 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3645 sinfo->bss_param.beacon_interval))
3646 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003647
3648 nla_nest_end(msg, bss_param);
3649 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003650 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3651 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3652 sizeof(struct nl80211_sta_flag_update),
3653 &sinfo->sta_flags))
3654 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003655 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3656 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3657 sinfo->t_offset))
3658 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003659 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003660
David S. Miller9360ffd2012-03-29 04:41:26 -04003661 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3662 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3663 sinfo->assoc_req_ies))
3664 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003665
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003666 return genlmsg_end(msg, hdr);
3667
3668 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003669 genlmsg_cancel(msg, hdr);
3670 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003671}
3672
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003673static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003674 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003675{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003676 struct station_info sinfo;
3677 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003678 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003679 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003680 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003681 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003682
Johannes Berg97990a02013-04-19 01:02:55 +02003683 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003684 if (err)
3685 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003686
Johannes Berg97990a02013-04-19 01:02:55 +02003687 if (!wdev->netdev) {
3688 err = -EINVAL;
3689 goto out_err;
3690 }
3691
Johannes Bergbba95fe2008-07-29 13:22:51 +02003692 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003693 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003694 goto out_err;
3695 }
3696
Johannes Bergbba95fe2008-07-29 13:22:51 +02003697 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003698 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003699 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003700 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003701 if (err == -ENOENT)
3702 break;
3703 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003704 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003705
3706 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003707 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003708 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003709 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003710 &sinfo) < 0)
3711 goto out;
3712
3713 sta_idx++;
3714 }
3715
3716
3717 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003718 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003719 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003720 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003721 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003722
3723 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003724}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003725
Johannes Berg5727ef12007-12-19 02:03:34 +01003726static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3727{
Johannes Berg4c476992010-10-04 21:36:35 +02003728 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3729 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003730 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003731 struct sk_buff *msg;
3732 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003733 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003734
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003735 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003736
3737 if (!info->attrs[NL80211_ATTR_MAC])
3738 return -EINVAL;
3739
3740 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3741
Johannes Berg4c476992010-10-04 21:36:35 +02003742 if (!rdev->ops->get_station)
3743 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003744
Hila Gonene35e4d22012-06-27 17:19:42 +03003745 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003746 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003747 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003748
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003749 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003750 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003751 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003752
Eric W. Biederman15e47302012-09-07 20:12:54 +00003753 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003754 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003755 nlmsg_free(msg);
3756 return -ENOBUFS;
3757 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003758
Johannes Berg4c476992010-10-04 21:36:35 +02003759 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003760}
3761
Johannes Berg77ee7c82013-02-15 00:48:33 +01003762int cfg80211_check_station_change(struct wiphy *wiphy,
3763 struct station_parameters *params,
3764 enum cfg80211_station_type statype)
3765{
3766 if (params->listen_interval != -1)
3767 return -EINVAL;
3768 if (params->aid)
3769 return -EINVAL;
3770
3771 /* When you run into this, adjust the code below for the new flag */
3772 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3773
3774 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003775 case CFG80211_STA_MESH_PEER_KERNEL:
3776 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003777 /*
3778 * No ignoring the TDLS flag here -- the userspace mesh
3779 * code doesn't have the bug of including TDLS in the
3780 * mask everywhere.
3781 */
3782 if (params->sta_flags_mask &
3783 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3784 BIT(NL80211_STA_FLAG_MFP) |
3785 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3786 return -EINVAL;
3787 break;
3788 case CFG80211_STA_TDLS_PEER_SETUP:
3789 case CFG80211_STA_TDLS_PEER_ACTIVE:
3790 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3791 return -EINVAL;
3792 /* ignore since it can't change */
3793 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3794 break;
3795 default:
3796 /* disallow mesh-specific things */
3797 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3798 return -EINVAL;
3799 if (params->local_pm)
3800 return -EINVAL;
3801 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3802 return -EINVAL;
3803 }
3804
3805 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3806 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3807 /* TDLS can't be set, ... */
3808 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3809 return -EINVAL;
3810 /*
3811 * ... but don't bother the driver with it. This works around
3812 * a hostapd/wpa_supplicant issue -- it always includes the
3813 * TLDS_PEER flag in the mask even for AP mode.
3814 */
3815 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3816 }
3817
3818 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3819 /* reject other things that can't change */
3820 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3821 return -EINVAL;
3822 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3823 return -EINVAL;
3824 if (params->supported_rates)
3825 return -EINVAL;
3826 if (params->ext_capab || params->ht_capa || params->vht_capa)
3827 return -EINVAL;
3828 }
3829
3830 if (statype != CFG80211_STA_AP_CLIENT) {
3831 if (params->vlan)
3832 return -EINVAL;
3833 }
3834
3835 switch (statype) {
3836 case CFG80211_STA_AP_MLME_CLIENT:
3837 /* Use this only for authorizing/unauthorizing a station */
3838 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3839 return -EOPNOTSUPP;
3840 break;
3841 case CFG80211_STA_AP_CLIENT:
3842 /* accept only the listed bits */
3843 if (params->sta_flags_mask &
3844 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3845 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3846 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3847 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3848 BIT(NL80211_STA_FLAG_WME) |
3849 BIT(NL80211_STA_FLAG_MFP)))
3850 return -EINVAL;
3851
3852 /* but authenticated/associated only if driver handles it */
3853 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3854 params->sta_flags_mask &
3855 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3856 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3857 return -EINVAL;
3858 break;
3859 case CFG80211_STA_IBSS:
3860 case CFG80211_STA_AP_STA:
3861 /* reject any changes other than AUTHORIZED */
3862 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3863 return -EINVAL;
3864 break;
3865 case CFG80211_STA_TDLS_PEER_SETUP:
3866 /* reject any changes other than AUTHORIZED or WME */
3867 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3868 BIT(NL80211_STA_FLAG_WME)))
3869 return -EINVAL;
3870 /* force (at least) rates when authorizing */
3871 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3872 !params->supported_rates)
3873 return -EINVAL;
3874 break;
3875 case CFG80211_STA_TDLS_PEER_ACTIVE:
3876 /* reject any changes */
3877 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003878 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003879 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3880 return -EINVAL;
3881 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003882 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003883 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3884 return -EINVAL;
3885 break;
3886 }
3887
3888 return 0;
3889}
3890EXPORT_SYMBOL(cfg80211_check_station_change);
3891
Johannes Berg5727ef12007-12-19 02:03:34 +01003892/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003893 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003894 */
Johannes Berg80b99892011-11-18 16:23:01 +01003895static struct net_device *get_vlan(struct genl_info *info,
3896 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003897{
Johannes Berg463d0182009-07-14 00:33:35 +02003898 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003899 struct net_device *v;
3900 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003901
Johannes Berg80b99892011-11-18 16:23:01 +01003902 if (!vlanattr)
3903 return NULL;
3904
3905 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3906 if (!v)
3907 return ERR_PTR(-ENODEV);
3908
3909 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3910 ret = -EINVAL;
3911 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003912 }
Johannes Berg80b99892011-11-18 16:23:01 +01003913
Johannes Berg77ee7c82013-02-15 00:48:33 +01003914 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3915 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3916 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3917 ret = -EINVAL;
3918 goto error;
3919 }
3920
Johannes Berg80b99892011-11-18 16:23:01 +01003921 if (!netif_running(v)) {
3922 ret = -ENETDOWN;
3923 goto error;
3924 }
3925
3926 return v;
3927 error:
3928 dev_put(v);
3929 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003930}
3931
Jouni Malinendf881292013-02-14 21:10:54 +02003932static struct nla_policy
3933nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3934 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3935 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3936};
3937
Johannes Bergff276692013-02-15 00:09:01 +01003938static int nl80211_parse_sta_wme(struct genl_info *info,
3939 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003940{
Jouni Malinendf881292013-02-14 21:10:54 +02003941 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3942 struct nlattr *nla;
3943 int err;
3944
Jouni Malinendf881292013-02-14 21:10:54 +02003945 /* parse WME attributes if present */
3946 if (!info->attrs[NL80211_ATTR_STA_WME])
3947 return 0;
3948
3949 nla = info->attrs[NL80211_ATTR_STA_WME];
3950 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3951 nl80211_sta_wme_policy);
3952 if (err)
3953 return err;
3954
3955 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3956 params->uapsd_queues = nla_get_u8(
3957 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3958 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3959 return -EINVAL;
3960
3961 if (tb[NL80211_STA_WME_MAX_SP])
3962 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3963
3964 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3965 return -EINVAL;
3966
3967 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3968
3969 return 0;
3970}
3971
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303972static int nl80211_parse_sta_channel_info(struct genl_info *info,
3973 struct station_parameters *params)
3974{
3975 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3976 params->supported_channels =
3977 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3978 params->supported_channels_len =
3979 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3980 /*
3981 * Need to include at least one (first channel, number of
3982 * channels) tuple for each subband, and must have proper
3983 * tuples for the rest of the data as well.
3984 */
3985 if (params->supported_channels_len < 2)
3986 return -EINVAL;
3987 if (params->supported_channels_len % 2)
3988 return -EINVAL;
3989 }
3990
3991 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3992 params->supported_oper_classes =
3993 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3994 params->supported_oper_classes_len =
3995 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3996 /*
3997 * The value of the Length field of the Supported Operating
3998 * Classes element is between 2 and 253.
3999 */
4000 if (params->supported_oper_classes_len < 2 ||
4001 params->supported_oper_classes_len > 253)
4002 return -EINVAL;
4003 }
4004 return 0;
4005}
4006
Johannes Bergff276692013-02-15 00:09:01 +01004007static int nl80211_set_station_tdls(struct genl_info *info,
4008 struct station_parameters *params)
4009{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304010 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004011 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004012 if (info->attrs[NL80211_ATTR_PEER_AID])
4013 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004014 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4015 params->ht_capa =
4016 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4017 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4018 params->vht_capa =
4019 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4020
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304021 err = nl80211_parse_sta_channel_info(info, params);
4022 if (err)
4023 return err;
4024
Johannes Bergff276692013-02-15 00:09:01 +01004025 return nl80211_parse_sta_wme(info, params);
4026}
4027
Johannes Berg5727ef12007-12-19 02:03:34 +01004028static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4029{
Johannes Berg4c476992010-10-04 21:36:35 +02004030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004031 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004032 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004033 u8 *mac_addr;
4034 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004035
4036 memset(&params, 0, sizeof(params));
4037
4038 params.listen_interval = -1;
4039
Johannes Berg77ee7c82013-02-15 00:48:33 +01004040 if (!rdev->ops->change_station)
4041 return -EOPNOTSUPP;
4042
Johannes Berg5727ef12007-12-19 02:03:34 +01004043 if (info->attrs[NL80211_ATTR_STA_AID])
4044 return -EINVAL;
4045
4046 if (!info->attrs[NL80211_ATTR_MAC])
4047 return -EINVAL;
4048
4049 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4050
4051 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4052 params.supported_rates =
4053 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4054 params.supported_rates_len =
4055 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4056 }
4057
Jouni Malinen9d62a982013-02-14 21:10:13 +02004058 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4059 params.capability =
4060 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4061 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4062 }
4063
4064 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4065 params.ext_capab =
4066 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4067 params.ext_capab_len =
4068 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4069 }
4070
Jouni Malinendf881292013-02-14 21:10:54 +02004071 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004072 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004073
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004074 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004075 return -EINVAL;
4076
Johannes Bergf8bacc22013-02-14 23:27:01 +01004077 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004078 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004079 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4080 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4081 return -EINVAL;
4082 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004083
Johannes Bergf8bacc22013-02-14 23:27:01 +01004084 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004085 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004086 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4087 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4088 return -EINVAL;
4089 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4090 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004091
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004092 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4093 enum nl80211_mesh_power_mode pm = nla_get_u32(
4094 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4095
4096 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4097 pm > NL80211_MESH_POWER_MAX)
4098 return -EINVAL;
4099
4100 params.local_pm = pm;
4101 }
4102
Johannes Berg77ee7c82013-02-15 00:48:33 +01004103 /* Include parameters for TDLS peer (will check later) */
4104 err = nl80211_set_station_tdls(info, &params);
4105 if (err)
4106 return err;
4107
4108 params.vlan = get_vlan(info, rdev);
4109 if (IS_ERR(params.vlan))
4110 return PTR_ERR(params.vlan);
4111
Johannes Berga97f4422009-06-18 17:23:43 +02004112 switch (dev->ieee80211_ptr->iftype) {
4113 case NL80211_IFTYPE_AP:
4114 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004115 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004116 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004117 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004118 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004119 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004120 break;
4121 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004122 err = -EOPNOTSUPP;
4123 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004124 }
4125
Johannes Berg77ee7c82013-02-15 00:48:33 +01004126 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004127 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004128
Johannes Berg77ee7c82013-02-15 00:48:33 +01004129 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004130 if (params.vlan)
4131 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004132
Johannes Berg5727ef12007-12-19 02:03:34 +01004133 return err;
4134}
4135
4136static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4137{
Johannes Berg4c476992010-10-04 21:36:35 +02004138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004139 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004140 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004141 struct station_parameters params;
4142 u8 *mac_addr = NULL;
4143
4144 memset(&params, 0, sizeof(params));
4145
Johannes Berg984c3112013-02-14 23:43:25 +01004146 if (!rdev->ops->add_station)
4147 return -EOPNOTSUPP;
4148
Johannes Berg5727ef12007-12-19 02:03:34 +01004149 if (!info->attrs[NL80211_ATTR_MAC])
4150 return -EINVAL;
4151
Johannes Berg5727ef12007-12-19 02:03:34 +01004152 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4153 return -EINVAL;
4154
4155 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4156 return -EINVAL;
4157
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004158 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4159 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004160 return -EINVAL;
4161
Johannes Berg5727ef12007-12-19 02:03:34 +01004162 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4163 params.supported_rates =
4164 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4165 params.supported_rates_len =
4166 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4167 params.listen_interval =
4168 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004169
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004170 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004171 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004172 else
4173 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004174 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4175 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004176
Jouni Malinen9d62a982013-02-14 21:10:13 +02004177 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4178 params.capability =
4179 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4180 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4181 }
4182
4183 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4184 params.ext_capab =
4185 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4186 params.ext_capab_len =
4187 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4188 }
4189
Jouni Malinen36aedc92008-08-25 11:58:58 +03004190 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4191 params.ht_capa =
4192 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004193
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004194 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4195 params.vht_capa =
4196 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4197
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004198 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4199 params.opmode_notif_used = true;
4200 params.opmode_notif =
4201 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4202 }
4203
Johannes Bergf8bacc22013-02-14 23:27:01 +01004204 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004205 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004206 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4207 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4208 return -EINVAL;
4209 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004210
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304211 err = nl80211_parse_sta_channel_info(info, &params);
4212 if (err)
4213 return err;
4214
Johannes Bergff276692013-02-15 00:09:01 +01004215 err = nl80211_parse_sta_wme(info, &params);
4216 if (err)
4217 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004218
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004219 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004220 return -EINVAL;
4221
Johannes Berg77ee7c82013-02-15 00:48:33 +01004222 /* When you run into this, adjust the code below for the new flag */
4223 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4224
Johannes Bergbdd90d52011-12-14 12:20:27 +01004225 switch (dev->ieee80211_ptr->iftype) {
4226 case NL80211_IFTYPE_AP:
4227 case NL80211_IFTYPE_AP_VLAN:
4228 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004229 /* ignore WME attributes if iface/sta is not capable */
4230 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4231 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4232 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004233
Johannes Bergbdd90d52011-12-14 12:20:27 +01004234 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004235 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4236 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004237 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004238 /* but don't bother the driver with it */
4239 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004240
Johannes Bergd582cff2012-10-26 17:53:44 +02004241 /* allow authenticated/associated only if driver handles it */
4242 if (!(rdev->wiphy.features &
4243 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4244 params.sta_flags_mask &
4245 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4246 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4247 return -EINVAL;
4248
Johannes Bergbdd90d52011-12-14 12:20:27 +01004249 /* must be last in here for error handling */
4250 params.vlan = get_vlan(info, rdev);
4251 if (IS_ERR(params.vlan))
4252 return PTR_ERR(params.vlan);
4253 break;
4254 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004255 /* ignore uAPSD data */
4256 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4257
Johannes Bergd582cff2012-10-26 17:53:44 +02004258 /* associated is disallowed */
4259 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4260 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004261 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004262 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4263 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004264 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004265 break;
4266 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004267 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004268 /* ignore uAPSD data */
4269 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4270
Johannes Berg77ee7c82013-02-15 00:48:33 +01004271 /* these are disallowed */
4272 if (params.sta_flags_mask &
4273 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4274 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004275 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004276 /* Only TDLS peers can be added */
4277 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4278 return -EINVAL;
4279 /* Can only add if TDLS ... */
4280 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4281 return -EOPNOTSUPP;
4282 /* ... with external setup is supported */
4283 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4284 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004285 /*
4286 * Older wpa_supplicant versions always mark the TDLS peer
4287 * as authorized, but it shouldn't yet be.
4288 */
4289 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004290 break;
4291 default:
4292 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004293 }
4294
Johannes Bergbdd90d52011-12-14 12:20:27 +01004295 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004296
Hila Gonene35e4d22012-06-27 17:19:42 +03004297 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004298
Johannes Berg5727ef12007-12-19 02:03:34 +01004299 if (params.vlan)
4300 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004301 return err;
4302}
4303
4304static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4305{
Johannes Berg4c476992010-10-04 21:36:35 +02004306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4307 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004308 u8 *mac_addr = NULL;
4309
4310 if (info->attrs[NL80211_ATTR_MAC])
4311 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4312
Johannes Berge80cf852009-05-11 14:43:13 +02004313 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004314 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004315 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004316 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4317 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004318
Johannes Berg4c476992010-10-04 21:36:35 +02004319 if (!rdev->ops->del_station)
4320 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004321
Hila Gonene35e4d22012-06-27 17:19:42 +03004322 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004323}
4324
Eric W. Biederman15e47302012-09-07 20:12:54 +00004325static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004326 int flags, struct net_device *dev,
4327 u8 *dst, u8 *next_hop,
4328 struct mpath_info *pinfo)
4329{
4330 void *hdr;
4331 struct nlattr *pinfoattr;
4332
Eric W. Biederman15e47302012-09-07 20:12:54 +00004333 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004334 if (!hdr)
4335 return -1;
4336
David S. Miller9360ffd2012-03-29 04:41:26 -04004337 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4338 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4339 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4340 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4341 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004342
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004343 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4344 if (!pinfoattr)
4345 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004346 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4347 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4348 pinfo->frame_qlen))
4349 goto nla_put_failure;
4350 if (((pinfo->filled & MPATH_INFO_SN) &&
4351 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4352 ((pinfo->filled & MPATH_INFO_METRIC) &&
4353 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4354 pinfo->metric)) ||
4355 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4356 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4357 pinfo->exptime)) ||
4358 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4359 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4360 pinfo->flags)) ||
4361 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4362 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4363 pinfo->discovery_timeout)) ||
4364 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4365 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4366 pinfo->discovery_retries)))
4367 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004368
4369 nla_nest_end(msg, pinfoattr);
4370
4371 return genlmsg_end(msg, hdr);
4372
4373 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004374 genlmsg_cancel(msg, hdr);
4375 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004376}
4377
4378static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004379 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004380{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004381 struct mpath_info pinfo;
4382 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004383 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004384 u8 dst[ETH_ALEN];
4385 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004386 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004387 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004388
Johannes Berg97990a02013-04-19 01:02:55 +02004389 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004390 if (err)
4391 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004392
4393 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004394 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004395 goto out_err;
4396 }
4397
Johannes Berg97990a02013-04-19 01:02:55 +02004398 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004399 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004400 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004401 }
4402
Johannes Bergbba95fe2008-07-29 13:22:51 +02004403 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004404 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4405 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004406 if (err == -ENOENT)
4407 break;
4408 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004409 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004410
Eric W. Biederman15e47302012-09-07 20:12:54 +00004411 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004412 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004413 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004414 &pinfo) < 0)
4415 goto out;
4416
4417 path_idx++;
4418 }
4419
4420
4421 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004422 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004423 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004424 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004425 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004426 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004427}
4428
4429static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4430{
Johannes Berg4c476992010-10-04 21:36:35 +02004431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004432 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004433 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004434 struct mpath_info pinfo;
4435 struct sk_buff *msg;
4436 u8 *dst = NULL;
4437 u8 next_hop[ETH_ALEN];
4438
4439 memset(&pinfo, 0, sizeof(pinfo));
4440
4441 if (!info->attrs[NL80211_ATTR_MAC])
4442 return -EINVAL;
4443
4444 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4445
Johannes Berg4c476992010-10-04 21:36:35 +02004446 if (!rdev->ops->get_mpath)
4447 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004448
Johannes Berg4c476992010-10-04 21:36:35 +02004449 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4450 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004451
Hila Gonene35e4d22012-06-27 17:19:42 +03004452 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004453 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004454 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004455
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004456 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004457 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004458 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004459
Eric W. Biederman15e47302012-09-07 20:12:54 +00004460 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004461 dev, dst, next_hop, &pinfo) < 0) {
4462 nlmsg_free(msg);
4463 return -ENOBUFS;
4464 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004465
Johannes Berg4c476992010-10-04 21:36:35 +02004466 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004467}
4468
4469static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4470{
Johannes Berg4c476992010-10-04 21:36:35 +02004471 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4472 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004473 u8 *dst = NULL;
4474 u8 *next_hop = NULL;
4475
4476 if (!info->attrs[NL80211_ATTR_MAC])
4477 return -EINVAL;
4478
4479 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4480 return -EINVAL;
4481
4482 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4483 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4484
Johannes Berg4c476992010-10-04 21:36:35 +02004485 if (!rdev->ops->change_mpath)
4486 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004487
Johannes Berg4c476992010-10-04 21:36:35 +02004488 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4489 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004490
Hila Gonene35e4d22012-06-27 17:19:42 +03004491 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004492}
Johannes Berg4c476992010-10-04 21:36:35 +02004493
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004494static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4495{
Johannes Berg4c476992010-10-04 21:36:35 +02004496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4497 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004498 u8 *dst = NULL;
4499 u8 *next_hop = NULL;
4500
4501 if (!info->attrs[NL80211_ATTR_MAC])
4502 return -EINVAL;
4503
4504 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4505 return -EINVAL;
4506
4507 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4508 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4509
Johannes Berg4c476992010-10-04 21:36:35 +02004510 if (!rdev->ops->add_mpath)
4511 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004512
Johannes Berg4c476992010-10-04 21:36:35 +02004513 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4514 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004515
Hila Gonene35e4d22012-06-27 17:19:42 +03004516 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004517}
4518
4519static int nl80211_del_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
4525 if (info->attrs[NL80211_ATTR_MAC])
4526 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4527
Johannes Berg4c476992010-10-04 21:36:35 +02004528 if (!rdev->ops->del_mpath)
4529 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004530
Hila Gonene35e4d22012-06-27 17:19:42 +03004531 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004532}
4533
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004534static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4535{
Johannes Berg4c476992010-10-04 21:36:35 +02004536 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4537 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004538 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004539 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004540 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004541
4542 memset(&params, 0, sizeof(params));
4543 /* default to not changing parameters */
4544 params.use_cts_prot = -1;
4545 params.use_short_preamble = -1;
4546 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004547 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004548 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004549 params.p2p_ctwindow = -1;
4550 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004551
4552 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4553 params.use_cts_prot =
4554 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4555 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4556 params.use_short_preamble =
4557 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4558 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4559 params.use_short_slot_time =
4560 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004561 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4562 params.basic_rates =
4563 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4564 params.basic_rates_len =
4565 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4566 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004567 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4568 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004569 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4570 params.ht_opmode =
4571 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004572
Johannes Berg53cabad2012-11-14 15:17:28 +01004573 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4574 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4575 return -EINVAL;
4576 params.p2p_ctwindow =
4577 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4578 if (params.p2p_ctwindow < 0)
4579 return -EINVAL;
4580 if (params.p2p_ctwindow != 0 &&
4581 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4582 return -EINVAL;
4583 }
4584
4585 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4586 u8 tmp;
4587
4588 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4589 return -EINVAL;
4590 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4591 if (tmp > 1)
4592 return -EINVAL;
4593 params.p2p_opp_ps = tmp;
4594 if (params.p2p_opp_ps &&
4595 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4596 return -EINVAL;
4597 }
4598
Johannes Berg4c476992010-10-04 21:36:35 +02004599 if (!rdev->ops->change_bss)
4600 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004601
Johannes Berg074ac8d2010-09-16 14:58:22 +02004602 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004603 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4604 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004605
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004606 wdev_lock(wdev);
4607 err = rdev_change_bss(rdev, dev, &params);
4608 wdev_unlock(wdev);
4609
4610 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004611}
4612
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004613static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004614 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4615 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4616 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4617 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4618 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4619 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4620};
4621
4622static int parse_reg_rule(struct nlattr *tb[],
4623 struct ieee80211_reg_rule *reg_rule)
4624{
4625 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4626 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4627
4628 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4629 return -EINVAL;
4630 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4631 return -EINVAL;
4632 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4633 return -EINVAL;
4634 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4635 return -EINVAL;
4636 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4637 return -EINVAL;
4638
4639 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4640
4641 freq_range->start_freq_khz =
4642 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4643 freq_range->end_freq_khz =
4644 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4645 freq_range->max_bandwidth_khz =
4646 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4647
4648 power_rule->max_eirp =
4649 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4650
4651 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4652 power_rule->max_antenna_gain =
4653 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4654
4655 return 0;
4656}
4657
4658static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4659{
4660 int r;
4661 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004662 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004663
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004664 /*
4665 * You should only get this when cfg80211 hasn't yet initialized
4666 * completely when built-in to the kernel right between the time
4667 * window between nl80211_init() and regulatory_init(), if that is
4668 * even possible.
4669 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004670 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004671 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004672
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004673 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4674 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004675
4676 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4677
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004678 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4679 user_reg_hint_type =
4680 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4681 else
4682 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4683
4684 switch (user_reg_hint_type) {
4685 case NL80211_USER_REG_HINT_USER:
4686 case NL80211_USER_REG_HINT_CELL_BASE:
4687 break;
4688 default:
4689 return -EINVAL;
4690 }
4691
4692 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004693
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004694 return r;
4695}
4696
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004697static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004698 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004699{
Johannes Berg4c476992010-10-04 21:36:35 +02004700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004701 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004702 struct wireless_dev *wdev = dev->ieee80211_ptr;
4703 struct mesh_config cur_params;
4704 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004705 void *hdr;
4706 struct nlattr *pinfoattr;
4707 struct sk_buff *msg;
4708
Johannes Berg29cbe682010-12-03 09:20:44 +01004709 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4710 return -EOPNOTSUPP;
4711
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004712 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004713 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004714
Johannes Berg29cbe682010-12-03 09:20:44 +01004715 wdev_lock(wdev);
4716 /* If not connected, get default parameters */
4717 if (!wdev->mesh_id_len)
4718 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4719 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004720 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004721 wdev_unlock(wdev);
4722
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004723 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004724 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004725
4726 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004727 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004728 if (!msg)
4729 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004730 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004731 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004732 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004733 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004734 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004735 if (!pinfoattr)
4736 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004737 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4738 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4739 cur_params.dot11MeshRetryTimeout) ||
4740 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4741 cur_params.dot11MeshConfirmTimeout) ||
4742 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4743 cur_params.dot11MeshHoldingTimeout) ||
4744 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4745 cur_params.dot11MeshMaxPeerLinks) ||
4746 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4747 cur_params.dot11MeshMaxRetries) ||
4748 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4749 cur_params.dot11MeshTTL) ||
4750 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4751 cur_params.element_ttl) ||
4752 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4753 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004754 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4755 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004756 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4757 cur_params.dot11MeshHWMPmaxPREQretries) ||
4758 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4759 cur_params.path_refresh_time) ||
4760 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4761 cur_params.min_discovery_timeout) ||
4762 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4763 cur_params.dot11MeshHWMPactivePathTimeout) ||
4764 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4765 cur_params.dot11MeshHWMPpreqMinInterval) ||
4766 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4767 cur_params.dot11MeshHWMPperrMinInterval) ||
4768 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4769 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4770 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4771 cur_params.dot11MeshHWMPRootMode) ||
4772 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4773 cur_params.dot11MeshHWMPRannInterval) ||
4774 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4775 cur_params.dot11MeshGateAnnouncementProtocol) ||
4776 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4777 cur_params.dot11MeshForwarding) ||
4778 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004779 cur_params.rssi_threshold) ||
4780 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004781 cur_params.ht_opmode) ||
4782 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4783 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4784 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004785 cur_params.dot11MeshHWMProotInterval) ||
4786 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004787 cur_params.dot11MeshHWMPconfirmationInterval) ||
4788 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4789 cur_params.power_mode) ||
4790 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004791 cur_params.dot11MeshAwakeWindowDuration) ||
4792 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4793 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004794 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004795 nla_nest_end(msg, pinfoattr);
4796 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004797 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004798
Johannes Berg3b858752009-03-12 09:55:09 +01004799 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004800 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004801 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004802 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004803 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004804}
4805
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004806static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004807 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4808 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4809 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4810 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4811 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4812 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004813 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004814 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004815 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004816 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4817 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4818 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4819 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4820 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004821 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004822 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004823 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004824 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004825 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004826 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004827 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4828 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004829 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4830 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004831 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004832 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4833 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004834 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004835};
4836
Javier Cardonac80d5452010-12-16 17:37:49 -08004837static const struct nla_policy
4838 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004839 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004840 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4841 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004842 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004843 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004844 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004845 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004846 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004847 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004848};
4849
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004850static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004851 struct mesh_config *cfg,
4852 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004853{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004854 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004855 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004856
Marco Porschea54fba2013-01-07 16:04:48 +01004857#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4858do { \
4859 if (tb[attr]) { \
4860 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4861 return -EINVAL; \
4862 cfg->param = fn(tb[attr]); \
4863 mask |= (1 << (attr - 1)); \
4864 } \
4865} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004866
4867
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004868 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004869 return -EINVAL;
4870 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004871 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004872 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004873 return -EINVAL;
4874
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004875 /* This makes sure that there aren't more than 32 mesh config
4876 * parameters (otherwise our bitfield scheme would not work.) */
4877 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4878
4879 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004880 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004881 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4882 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004883 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004884 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4885 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004886 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004887 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4888 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004889 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004890 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4891 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004892 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004893 mask, NL80211_MESHCONF_MAX_RETRIES,
4894 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004895 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004896 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004897 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004898 mask, NL80211_MESHCONF_ELEMENT_TTL,
4899 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004900 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004901 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4902 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004903 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4904 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004905 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4906 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004907 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004908 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4909 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004910 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004911 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4912 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004913 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004914 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4915 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004916 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4917 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004918 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4919 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004921 1, 65535, mask,
4922 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004923 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004924 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004925 1, 65535, mask,
4926 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004927 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004928 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004929 dot11MeshHWMPnetDiameterTraversalTime,
4930 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004931 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4932 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004933 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4934 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4935 nla_get_u8);
4936 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4937 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004938 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004939 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004940 dot11MeshGateAnnouncementProtocol, 0, 1,
4941 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004942 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004943 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004944 mask, NL80211_MESHCONF_FORWARDING,
4945 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004946 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004947 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004948 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004949 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004950 mask, NL80211_MESHCONF_HT_OPMODE,
4951 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004952 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004953 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004954 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4955 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004956 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004957 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4958 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004960 dot11MeshHWMPconfirmationInterval,
4961 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004962 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4963 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4965 NL80211_MESH_POWER_ACTIVE,
4966 NL80211_MESH_POWER_MAX,
4967 mask, NL80211_MESHCONF_POWER_MODE,
4968 nla_get_u32);
4969 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4970 0, 65535, mask,
4971 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004972 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4973 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4974 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004975 if (mask_out)
4976 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004977
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004978 return 0;
4979
4980#undef FILL_IN_MESH_PARAM_IF_SET
4981}
4982
Javier Cardonac80d5452010-12-16 17:37:49 -08004983static int nl80211_parse_mesh_setup(struct genl_info *info,
4984 struct mesh_setup *setup)
4985{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004986 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004987 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4988
4989 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4990 return -EINVAL;
4991 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4992 info->attrs[NL80211_ATTR_MESH_SETUP],
4993 nl80211_mesh_setup_params_policy))
4994 return -EINVAL;
4995
Javier Cardonad299a1f2012-03-31 11:31:33 -07004996 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4997 setup->sync_method =
4998 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4999 IEEE80211_SYNC_METHOD_VENDOR :
5000 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5001
Javier Cardonac80d5452010-12-16 17:37:49 -08005002 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5003 setup->path_sel_proto =
5004 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5005 IEEE80211_PATH_PROTOCOL_VENDOR :
5006 IEEE80211_PATH_PROTOCOL_HWMP;
5007
5008 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5009 setup->path_metric =
5010 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5011 IEEE80211_PATH_METRIC_VENDOR :
5012 IEEE80211_PATH_METRIC_AIRTIME;
5013
Javier Cardona581a8b02011-04-07 15:08:27 -07005014
5015 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005016 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005017 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005018 if (!is_valid_ie_attr(ieattr))
5019 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005020 setup->ie = nla_data(ieattr);
5021 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005022 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005023 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5024 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5025 return -EINVAL;
5026 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005027 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5028 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005029 if (setup->is_secure)
5030 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005031
Colleen Twitty6e16d902013-05-08 11:45:59 -07005032 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5033 if (!setup->user_mpm)
5034 return -EINVAL;
5035 setup->auth_id =
5036 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5037 }
5038
Javier Cardonac80d5452010-12-16 17:37:49 -08005039 return 0;
5040}
5041
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005042static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005043 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005044{
5045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5046 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005047 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005048 struct mesh_config cfg;
5049 u32 mask;
5050 int err;
5051
Johannes Berg29cbe682010-12-03 09:20:44 +01005052 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5053 return -EOPNOTSUPP;
5054
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005055 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005056 return -EOPNOTSUPP;
5057
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005058 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005059 if (err)
5060 return err;
5061
Johannes Berg29cbe682010-12-03 09:20:44 +01005062 wdev_lock(wdev);
5063 if (!wdev->mesh_id_len)
5064 err = -ENOLINK;
5065
5066 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005067 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005068
5069 wdev_unlock(wdev);
5070
5071 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005072}
5073
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005074static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5075{
Johannes Berg458f4f92012-12-06 15:47:38 +01005076 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005077 struct sk_buff *msg;
5078 void *hdr = NULL;
5079 struct nlattr *nl_reg_rules;
5080 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005081
5082 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005083 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005084
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005085 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005086 if (!msg)
5087 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005088
Eric W. Biederman15e47302012-09-07 20:12:54 +00005089 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005090 NL80211_CMD_GET_REG);
5091 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005092 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005093
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005094 if (reg_last_request_cell_base() &&
5095 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5096 NL80211_USER_REG_HINT_CELL_BASE))
5097 goto nla_put_failure;
5098
Johannes Berg458f4f92012-12-06 15:47:38 +01005099 rcu_read_lock();
5100 regdom = rcu_dereference(cfg80211_regdomain);
5101
5102 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5103 (regdom->dfs_region &&
5104 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5105 goto nla_put_failure_rcu;
5106
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005107 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5108 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005109 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005110
Johannes Berg458f4f92012-12-06 15:47:38 +01005111 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005112 struct nlattr *nl_reg_rule;
5113 const struct ieee80211_reg_rule *reg_rule;
5114 const struct ieee80211_freq_range *freq_range;
5115 const struct ieee80211_power_rule *power_rule;
5116
Johannes Berg458f4f92012-12-06 15:47:38 +01005117 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005118 freq_range = &reg_rule->freq_range;
5119 power_rule = &reg_rule->power_rule;
5120
5121 nl_reg_rule = nla_nest_start(msg, i);
5122 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005123 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005124
David S. Miller9360ffd2012-03-29 04:41:26 -04005125 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5126 reg_rule->flags) ||
5127 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5128 freq_range->start_freq_khz) ||
5129 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5130 freq_range->end_freq_khz) ||
5131 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5132 freq_range->max_bandwidth_khz) ||
5133 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5134 power_rule->max_antenna_gain) ||
5135 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5136 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005137 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005138
5139 nla_nest_end(msg, nl_reg_rule);
5140 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005141 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005142
5143 nla_nest_end(msg, nl_reg_rules);
5144
5145 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005146 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005147
Johannes Berg458f4f92012-12-06 15:47:38 +01005148nla_put_failure_rcu:
5149 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005150nla_put_failure:
5151 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005152put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005153 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005154 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005155}
5156
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005157static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5158{
5159 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5160 struct nlattr *nl_reg_rule;
5161 char *alpha2 = NULL;
5162 int rem_reg_rules = 0, r = 0;
5163 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005164 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005165 struct ieee80211_regdomain *rd = NULL;
5166
5167 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5168 return -EINVAL;
5169
5170 if (!info->attrs[NL80211_ATTR_REG_RULES])
5171 return -EINVAL;
5172
5173 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5174
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005175 if (info->attrs[NL80211_ATTR_DFS_REGION])
5176 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5177
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005178 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005179 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005180 num_rules++;
5181 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005182 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005183 }
5184
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005185 if (!reg_is_valid_request(alpha2))
5186 return -EINVAL;
5187
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005188 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005189 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005190
5191 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005192 if (!rd)
5193 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005194
5195 rd->n_reg_rules = num_rules;
5196 rd->alpha2[0] = alpha2[0];
5197 rd->alpha2[1] = alpha2[1];
5198
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005199 /*
5200 * Disable DFS master mode if the DFS region was
5201 * not supported or known on this kernel.
5202 */
5203 if (reg_supported_dfs_region(dfs_region))
5204 rd->dfs_region = dfs_region;
5205
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005206 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005207 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005208 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005209 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5210 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005211 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5212 if (r)
5213 goto bad_reg;
5214
5215 rule_idx++;
5216
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005217 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5218 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005219 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005220 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005221 }
5222
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005223 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005224 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005225 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005226
Johannes Bergd2372b32008-10-24 20:32:20 +02005227 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005228 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005229 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005230}
5231
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005232static int validate_scan_freqs(struct nlattr *freqs)
5233{
5234 struct nlattr *attr1, *attr2;
5235 int n_channels = 0, tmp1, tmp2;
5236
5237 nla_for_each_nested(attr1, freqs, tmp1) {
5238 n_channels++;
5239 /*
5240 * Some hardware has a limited channel list for
5241 * scanning, and it is pretty much nonsensical
5242 * to scan for a channel twice, so disallow that
5243 * and don't require drivers to check that the
5244 * channel list they get isn't longer than what
5245 * they can scan, as long as they can scan all
5246 * the channels they registered at once.
5247 */
5248 nla_for_each_nested(attr2, freqs, tmp2)
5249 if (attr1 != attr2 &&
5250 nla_get_u32(attr1) == nla_get_u32(attr2))
5251 return 0;
5252 }
5253
5254 return n_channels;
5255}
5256
Johannes Berg2a519312009-02-10 21:25:55 +01005257static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5258{
Johannes Berg4c476992010-10-04 21:36:35 +02005259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005260 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005261 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005262 struct nlattr *attr;
5263 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005264 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005265 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005266
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005267 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5268 return -EINVAL;
5269
Johannes Berg79c97e92009-07-07 03:56:12 +02005270 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005271
Johannes Berg4c476992010-10-04 21:36:35 +02005272 if (!rdev->ops->scan)
5273 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005274
Johannes Bergf9f47522013-03-19 15:04:07 +01005275 if (rdev->scan_req) {
5276 err = -EBUSY;
5277 goto unlock;
5278 }
Johannes Berg2a519312009-02-10 21:25:55 +01005279
5280 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005281 n_channels = validate_scan_freqs(
5282 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005283 if (!n_channels) {
5284 err = -EINVAL;
5285 goto unlock;
5286 }
Johannes Berg2a519312009-02-10 21:25:55 +01005287 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005288 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005289 n_channels = 0;
5290
Johannes Berg2a519312009-02-10 21:25:55 +01005291 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5292 if (wiphy->bands[band])
5293 n_channels += wiphy->bands[band]->n_channels;
5294 }
5295
5296 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5297 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5298 n_ssids++;
5299
Johannes Bergf9f47522013-03-19 15:04:07 +01005300 if (n_ssids > wiphy->max_scan_ssids) {
5301 err = -EINVAL;
5302 goto unlock;
5303 }
Johannes Berg2a519312009-02-10 21:25:55 +01005304
Jouni Malinen70692ad2009-02-16 19:39:13 +02005305 if (info->attrs[NL80211_ATTR_IE])
5306 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5307 else
5308 ie_len = 0;
5309
Johannes Bergf9f47522013-03-19 15:04:07 +01005310 if (ie_len > wiphy->max_scan_ie_len) {
5311 err = -EINVAL;
5312 goto unlock;
5313 }
Johannes Berg18a83652009-03-31 12:12:05 +02005314
Johannes Berg2a519312009-02-10 21:25:55 +01005315 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005316 + sizeof(*request->ssids) * n_ssids
5317 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005318 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005319 if (!request) {
5320 err = -ENOMEM;
5321 goto unlock;
5322 }
Johannes Berg2a519312009-02-10 21:25:55 +01005323
Johannes Berg2a519312009-02-10 21:25:55 +01005324 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005325 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005326 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005327 if (ie_len) {
5328 if (request->ssids)
5329 request->ie = (void *)(request->ssids + n_ssids);
5330 else
5331 request->ie = (void *)(request->channels + n_channels);
5332 }
Johannes Berg2a519312009-02-10 21:25:55 +01005333
Johannes Berg584991d2009-11-02 13:32:03 +01005334 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005335 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5336 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005337 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005338 struct ieee80211_channel *chan;
5339
5340 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5341
5342 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005343 err = -EINVAL;
5344 goto out_free;
5345 }
Johannes Berg584991d2009-11-02 13:32:03 +01005346
5347 /* ignore disabled channels */
5348 if (chan->flags & IEEE80211_CHAN_DISABLED)
5349 continue;
5350
5351 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005352 i++;
5353 }
5354 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005355 enum ieee80211_band band;
5356
Johannes Berg2a519312009-02-10 21:25:55 +01005357 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005358 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5359 int j;
5360 if (!wiphy->bands[band])
5361 continue;
5362 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005363 struct ieee80211_channel *chan;
5364
5365 chan = &wiphy->bands[band]->channels[j];
5366
5367 if (chan->flags & IEEE80211_CHAN_DISABLED)
5368 continue;
5369
5370 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005371 i++;
5372 }
5373 }
5374 }
5375
Johannes Berg584991d2009-11-02 13:32:03 +01005376 if (!i) {
5377 err = -EINVAL;
5378 goto out_free;
5379 }
5380
5381 request->n_channels = i;
5382
Johannes Berg2a519312009-02-10 21:25:55 +01005383 i = 0;
5384 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5385 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005386 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005387 err = -EINVAL;
5388 goto out_free;
5389 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005390 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005391 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005392 i++;
5393 }
5394 }
5395
Jouni Malinen70692ad2009-02-16 19:39:13 +02005396 if (info->attrs[NL80211_ATTR_IE]) {
5397 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005398 memcpy((void *)request->ie,
5399 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005400 request->ie_len);
5401 }
5402
Johannes Berg34850ab2011-07-18 18:08:35 +02005403 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005404 if (wiphy->bands[i])
5405 request->rates[i] =
5406 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005407
5408 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5409 nla_for_each_nested(attr,
5410 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5411 tmp) {
5412 enum ieee80211_band band = nla_type(attr);
5413
Dan Carpenter84404622011-07-29 11:52:18 +03005414 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005415 err = -EINVAL;
5416 goto out_free;
5417 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005418
5419 if (!wiphy->bands[band])
5420 continue;
5421
Johannes Berg34850ab2011-07-18 18:08:35 +02005422 err = ieee80211_get_ratemask(wiphy->bands[band],
5423 nla_data(attr),
5424 nla_len(attr),
5425 &request->rates[band]);
5426 if (err)
5427 goto out_free;
5428 }
5429 }
5430
Sam Leffler46856bb2012-10-11 21:03:32 -07005431 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005432 request->flags = nla_get_u32(
5433 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005434 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5435 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005436 err = -EOPNOTSUPP;
5437 goto out_free;
5438 }
5439 }
Sam Lefflered4737712012-10-11 21:03:31 -07005440
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305441 request->no_cck =
5442 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5443
Johannes Bergfd014282012-06-18 19:17:03 +02005444 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005445 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005446 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005447
Johannes Berg79c97e92009-07-07 03:56:12 +02005448 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005449 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005450
Johannes Berg463d0182009-07-14 00:33:35 +02005451 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005452 nl80211_send_scan_start(rdev, wdev);
5453 if (wdev->netdev)
5454 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005455 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005456 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005457 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005458 kfree(request);
5459 }
Johannes Berg3b858752009-03-12 09:55:09 +01005460
Johannes Bergf9f47522013-03-19 15:04:07 +01005461 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005462 return err;
5463}
5464
Luciano Coelho807f8a82011-05-11 17:09:35 +03005465static int nl80211_start_sched_scan(struct sk_buff *skb,
5466 struct genl_info *info)
5467{
5468 struct cfg80211_sched_scan_request *request;
5469 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5470 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005471 struct nlattr *attr;
5472 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005473 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005474 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005475 enum ieee80211_band band;
5476 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005477 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005478
5479 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5480 !rdev->ops->sched_scan_start)
5481 return -EOPNOTSUPP;
5482
5483 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5484 return -EINVAL;
5485
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005486 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5487 return -EINVAL;
5488
5489 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5490 if (interval == 0)
5491 return -EINVAL;
5492
Luciano Coelho807f8a82011-05-11 17:09:35 +03005493 wiphy = &rdev->wiphy;
5494
5495 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5496 n_channels = validate_scan_freqs(
5497 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5498 if (!n_channels)
5499 return -EINVAL;
5500 } else {
5501 n_channels = 0;
5502
5503 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5504 if (wiphy->bands[band])
5505 n_channels += wiphy->bands[band]->n_channels;
5506 }
5507
5508 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5509 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5510 tmp)
5511 n_ssids++;
5512
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005513 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005514 return -EINVAL;
5515
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005516 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5517 nla_for_each_nested(attr,
5518 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5519 tmp)
5520 n_match_sets++;
5521
5522 if (n_match_sets > wiphy->max_match_sets)
5523 return -EINVAL;
5524
Luciano Coelho807f8a82011-05-11 17:09:35 +03005525 if (info->attrs[NL80211_ATTR_IE])
5526 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5527 else
5528 ie_len = 0;
5529
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005530 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005531 return -EINVAL;
5532
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005533 if (rdev->sched_scan_req) {
5534 err = -EINPROGRESS;
5535 goto out;
5536 }
5537
Luciano Coelho807f8a82011-05-11 17:09:35 +03005538 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005539 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005540 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005541 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005542 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005543 if (!request) {
5544 err = -ENOMEM;
5545 goto out;
5546 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005547
5548 if (n_ssids)
5549 request->ssids = (void *)&request->channels[n_channels];
5550 request->n_ssids = n_ssids;
5551 if (ie_len) {
5552 if (request->ssids)
5553 request->ie = (void *)(request->ssids + n_ssids);
5554 else
5555 request->ie = (void *)(request->channels + n_channels);
5556 }
5557
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005558 if (n_match_sets) {
5559 if (request->ie)
5560 request->match_sets = (void *)(request->ie + ie_len);
5561 else if (request->ssids)
5562 request->match_sets =
5563 (void *)(request->ssids + n_ssids);
5564 else
5565 request->match_sets =
5566 (void *)(request->channels + n_channels);
5567 }
5568 request->n_match_sets = n_match_sets;
5569
Luciano Coelho807f8a82011-05-11 17:09:35 +03005570 i = 0;
5571 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5572 /* user specified, bail out if channel not found */
5573 nla_for_each_nested(attr,
5574 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5575 tmp) {
5576 struct ieee80211_channel *chan;
5577
5578 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5579
5580 if (!chan) {
5581 err = -EINVAL;
5582 goto out_free;
5583 }
5584
5585 /* ignore disabled channels */
5586 if (chan->flags & IEEE80211_CHAN_DISABLED)
5587 continue;
5588
5589 request->channels[i] = chan;
5590 i++;
5591 }
5592 } else {
5593 /* all channels */
5594 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5595 int j;
5596 if (!wiphy->bands[band])
5597 continue;
5598 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5599 struct ieee80211_channel *chan;
5600
5601 chan = &wiphy->bands[band]->channels[j];
5602
5603 if (chan->flags & IEEE80211_CHAN_DISABLED)
5604 continue;
5605
5606 request->channels[i] = chan;
5607 i++;
5608 }
5609 }
5610 }
5611
5612 if (!i) {
5613 err = -EINVAL;
5614 goto out_free;
5615 }
5616
5617 request->n_channels = i;
5618
5619 i = 0;
5620 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5621 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5622 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005623 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005624 err = -EINVAL;
5625 goto out_free;
5626 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005627 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005628 memcpy(request->ssids[i].ssid, nla_data(attr),
5629 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005630 i++;
5631 }
5632 }
5633
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005634 i = 0;
5635 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5636 nla_for_each_nested(attr,
5637 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5638 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005639 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005640
5641 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5642 nla_data(attr), nla_len(attr),
5643 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005644 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005645 if (ssid) {
5646 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5647 err = -EINVAL;
5648 goto out_free;
5649 }
5650 memcpy(request->match_sets[i].ssid.ssid,
5651 nla_data(ssid), nla_len(ssid));
5652 request->match_sets[i].ssid.ssid_len =
5653 nla_len(ssid);
5654 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005655 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5656 if (rssi)
5657 request->rssi_thold = nla_get_u32(rssi);
5658 else
5659 request->rssi_thold =
5660 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005661 i++;
5662 }
5663 }
5664
Luciano Coelho807f8a82011-05-11 17:09:35 +03005665 if (info->attrs[NL80211_ATTR_IE]) {
5666 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5667 memcpy((void *)request->ie,
5668 nla_data(info->attrs[NL80211_ATTR_IE]),
5669 request->ie_len);
5670 }
5671
Sam Leffler46856bb2012-10-11 21:03:32 -07005672 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005673 request->flags = nla_get_u32(
5674 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005675 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5676 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005677 err = -EOPNOTSUPP;
5678 goto out_free;
5679 }
5680 }
Sam Lefflered4737712012-10-11 21:03:31 -07005681
Luciano Coelho807f8a82011-05-11 17:09:35 +03005682 request->dev = dev;
5683 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005684 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005685 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005686
Hila Gonene35e4d22012-06-27 17:19:42 +03005687 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005688 if (!err) {
5689 rdev->sched_scan_req = request;
5690 nl80211_send_sched_scan(rdev, dev,
5691 NL80211_CMD_START_SCHED_SCAN);
5692 goto out;
5693 }
5694
5695out_free:
5696 kfree(request);
5697out:
5698 return err;
5699}
5700
5701static int nl80211_stop_sched_scan(struct sk_buff *skb,
5702 struct genl_info *info)
5703{
5704 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5705
5706 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5707 !rdev->ops->sched_scan_stop)
5708 return -EOPNOTSUPP;
5709
Johannes Berg5fe231e2013-05-08 21:45:15 +02005710 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005711}
5712
Simon Wunderlich04f39042013-02-08 18:16:19 +01005713static int nl80211_start_radar_detection(struct sk_buff *skb,
5714 struct genl_info *info)
5715{
5716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5717 struct net_device *dev = info->user_ptr[1];
5718 struct wireless_dev *wdev = dev->ieee80211_ptr;
5719 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005720 enum nl80211_dfs_regions dfs_region;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005721 int err;
5722
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005723 dfs_region = reg_get_dfs_region(wdev->wiphy);
5724 if (dfs_region == NL80211_DFS_UNSET)
5725 return -EINVAL;
5726
Simon Wunderlich04f39042013-02-08 18:16:19 +01005727 err = nl80211_parse_chandef(rdev, info, &chandef);
5728 if (err)
5729 return err;
5730
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005731 if (netif_carrier_ok(dev))
5732 return -EBUSY;
5733
Simon Wunderlich04f39042013-02-08 18:16:19 +01005734 if (wdev->cac_started)
5735 return -EBUSY;
5736
5737 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5738 if (err < 0)
5739 return err;
5740
5741 if (err == 0)
5742 return -EINVAL;
5743
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005744 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005745 return -EINVAL;
5746
5747 if (!rdev->ops->start_radar_detection)
5748 return -EOPNOTSUPP;
5749
Simon Wunderlich04f39042013-02-08 18:16:19 +01005750 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5751 chandef.chan, CHAN_MODE_SHARED,
5752 BIT(chandef.width));
5753 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005754 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005755
5756 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5757 if (!err) {
5758 wdev->channel = chandef.chan;
5759 wdev->cac_started = true;
5760 wdev->cac_start_time = jiffies;
5761 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005762 return err;
5763}
5764
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005765static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5766{
5767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5768 struct net_device *dev = info->user_ptr[1];
5769 struct wireless_dev *wdev = dev->ieee80211_ptr;
5770 struct cfg80211_csa_settings params;
5771 /* csa_attrs is defined static to avoid waste of stack size - this
5772 * function is called under RTNL lock, so this should not be a problem.
5773 */
5774 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5775 u8 radar_detect_width = 0;
5776 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005777 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005778
5779 if (!rdev->ops->channel_switch ||
5780 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5781 return -EOPNOTSUPP;
5782
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005783 switch (dev->ieee80211_ptr->iftype) {
5784 case NL80211_IFTYPE_AP:
5785 case NL80211_IFTYPE_P2P_GO:
5786 need_new_beacon = true;
5787
5788 /* useless if AP is not running */
5789 if (!wdev->beacon_interval)
5790 return -EINVAL;
5791 break;
5792 case NL80211_IFTYPE_ADHOC:
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005793 case NL80211_IFTYPE_MESH_POINT:
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005794 break;
5795 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005796 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005797 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005798
5799 memset(&params, 0, sizeof(params));
5800
5801 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5802 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5803 return -EINVAL;
5804
5805 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005806 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005807 return -EINVAL;
5808
5809 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5810
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005811 if (!need_new_beacon)
5812 goto skip_beacons;
5813
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005814 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5815 if (err)
5816 return err;
5817
5818 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5819 info->attrs[NL80211_ATTR_CSA_IES],
5820 nl80211_policy);
5821 if (err)
5822 return err;
5823
5824 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5825 if (err)
5826 return err;
5827
5828 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5829 return -EINVAL;
5830
5831 params.counter_offset_beacon =
5832 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5833 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5834 return -EINVAL;
5835
5836 /* sanity check - counters should be the same */
5837 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5838 params.count)
5839 return -EINVAL;
5840
5841 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5842 params.counter_offset_presp =
5843 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5844 if (params.counter_offset_presp >=
5845 params.beacon_csa.probe_resp_len)
5846 return -EINVAL;
5847
5848 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5849 params.count)
5850 return -EINVAL;
5851 }
5852
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005853skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005854 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5855 if (err)
5856 return err;
5857
5858 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5859 return -EINVAL;
5860
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005861 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005862 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5863 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005864 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5865 &params.chandef);
5866 if (err < 0) {
5867 return err;
5868 } else if (err) {
5869 radar_detect_width = BIT(params.chandef.width);
5870 params.radar_required = true;
5871 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005872 }
5873
5874 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5875 params.chandef.chan,
5876 CHAN_MODE_SHARED,
5877 radar_detect_width);
5878 if (err)
5879 return err;
5880
5881 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5882 params.block_tx = true;
5883
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005884 wdev_lock(wdev);
5885 err = rdev_channel_switch(rdev, dev, &params);
5886 wdev_unlock(wdev);
5887
5888 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005889}
5890
Johannes Berg9720bb32011-06-21 09:45:33 +02005891static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5892 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005893 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005894 struct wireless_dev *wdev,
5895 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005896{
Johannes Berg48ab9052009-07-10 18:42:31 +02005897 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005898 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005899 void *hdr;
5900 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005901 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005902
5903 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005904
Eric W. Biederman15e47302012-09-07 20:12:54 +00005905 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005906 NL80211_CMD_NEW_SCAN_RESULTS);
5907 if (!hdr)
5908 return -1;
5909
Johannes Berg9720bb32011-06-21 09:45:33 +02005910 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5911
Johannes Berg97990a02013-04-19 01:02:55 +02005912 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5913 goto nla_put_failure;
5914 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005915 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5916 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005917 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5918 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005919
5920 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5921 if (!bss)
5922 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005923 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005924 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005925 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005926
5927 rcu_read_lock();
5928 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005929 if (ies) {
5930 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5931 goto fail_unlock_rcu;
5932 tsf = true;
5933 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5934 ies->len, ies->data))
5935 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005936 }
5937 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005938 if (ies) {
5939 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5940 goto fail_unlock_rcu;
5941 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5942 ies->len, ies->data))
5943 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005944 }
5945 rcu_read_unlock();
5946
David S. Miller9360ffd2012-03-29 04:41:26 -04005947 if (res->beacon_interval &&
5948 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5949 goto nla_put_failure;
5950 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5951 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005952 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005953 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5954 jiffies_to_msecs(jiffies - intbss->ts)))
5955 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005956
Johannes Berg77965c92009-02-18 18:45:06 +01005957 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005958 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005959 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5960 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005961 break;
5962 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005963 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5964 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005965 break;
5966 default:
5967 break;
5968 }
5969
Johannes Berg48ab9052009-07-10 18:42:31 +02005970 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005971 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005972 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005973 if (intbss == wdev->current_bss &&
5974 nla_put_u32(msg, NL80211_BSS_STATUS,
5975 NL80211_BSS_STATUS_ASSOCIATED))
5976 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005977 break;
5978 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005979 if (intbss == wdev->current_bss &&
5980 nla_put_u32(msg, NL80211_BSS_STATUS,
5981 NL80211_BSS_STATUS_IBSS_JOINED))
5982 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005983 break;
5984 default:
5985 break;
5986 }
5987
Johannes Berg2a519312009-02-10 21:25:55 +01005988 nla_nest_end(msg, bss);
5989
5990 return genlmsg_end(msg, hdr);
5991
Johannes Berg8cef2c92013-02-05 16:54:31 +01005992 fail_unlock_rcu:
5993 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005994 nla_put_failure:
5995 genlmsg_cancel(msg, hdr);
5996 return -EMSGSIZE;
5997}
5998
Johannes Berg97990a02013-04-19 01:02:55 +02005999static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006000{
Johannes Berg48ab9052009-07-10 18:42:31 +02006001 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006002 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006003 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006004 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006005 int err;
6006
Johannes Berg97990a02013-04-19 01:02:55 +02006007 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006008 if (err)
6009 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006010
Johannes Berg48ab9052009-07-10 18:42:31 +02006011 wdev_lock(wdev);
6012 spin_lock_bh(&rdev->bss_lock);
6013 cfg80211_bss_expire(rdev);
6014
Johannes Berg9720bb32011-06-21 09:45:33 +02006015 cb->seq = rdev->bss_generation;
6016
Johannes Berg48ab9052009-07-10 18:42:31 +02006017 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006018 if (++idx <= start)
6019 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006020 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006021 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006022 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006023 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006024 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006025 }
6026 }
6027
Johannes Berg48ab9052009-07-10 18:42:31 +02006028 spin_unlock_bh(&rdev->bss_lock);
6029 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006030
Johannes Berg97990a02013-04-19 01:02:55 +02006031 cb->args[2] = idx;
6032 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006033
Johannes Berg67748892010-10-04 21:14:06 +02006034 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006035}
6036
Eric W. Biederman15e47302012-09-07 20:12:54 +00006037static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006038 int flags, struct net_device *dev,
6039 struct survey_info *survey)
6040{
6041 void *hdr;
6042 struct nlattr *infoattr;
6043
Eric W. Biederman15e47302012-09-07 20:12:54 +00006044 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006045 NL80211_CMD_NEW_SURVEY_RESULTS);
6046 if (!hdr)
6047 return -ENOMEM;
6048
David S. Miller9360ffd2012-03-29 04:41:26 -04006049 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6050 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006051
6052 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6053 if (!infoattr)
6054 goto nla_put_failure;
6055
David S. Miller9360ffd2012-03-29 04:41:26 -04006056 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6057 survey->channel->center_freq))
6058 goto nla_put_failure;
6059
6060 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6061 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6062 goto nla_put_failure;
6063 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6064 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6065 goto nla_put_failure;
6066 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6067 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6068 survey->channel_time))
6069 goto nla_put_failure;
6070 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6071 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6072 survey->channel_time_busy))
6073 goto nla_put_failure;
6074 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6075 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6076 survey->channel_time_ext_busy))
6077 goto nla_put_failure;
6078 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6079 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6080 survey->channel_time_rx))
6081 goto nla_put_failure;
6082 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6083 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6084 survey->channel_time_tx))
6085 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006086
6087 nla_nest_end(msg, infoattr);
6088
6089 return genlmsg_end(msg, hdr);
6090
6091 nla_put_failure:
6092 genlmsg_cancel(msg, hdr);
6093 return -EMSGSIZE;
6094}
6095
6096static int nl80211_dump_survey(struct sk_buff *skb,
6097 struct netlink_callback *cb)
6098{
6099 struct survey_info survey;
6100 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006101 struct wireless_dev *wdev;
6102 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006103 int res;
6104
Johannes Berg97990a02013-04-19 01:02:55 +02006105 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006106 if (res)
6107 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006108
Johannes Berg97990a02013-04-19 01:02:55 +02006109 if (!wdev->netdev) {
6110 res = -EINVAL;
6111 goto out_err;
6112 }
6113
Holger Schurig61fa7132009-11-11 12:25:40 +01006114 if (!dev->ops->dump_survey) {
6115 res = -EOPNOTSUPP;
6116 goto out_err;
6117 }
6118
6119 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006120 struct ieee80211_channel *chan;
6121
Johannes Berg97990a02013-04-19 01:02:55 +02006122 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006123 if (res == -ENOENT)
6124 break;
6125 if (res)
6126 goto out_err;
6127
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006128 /* Survey without a channel doesn't make sense */
6129 if (!survey.channel) {
6130 res = -EINVAL;
6131 goto out;
6132 }
6133
6134 chan = ieee80211_get_channel(&dev->wiphy,
6135 survey.channel->center_freq);
6136 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6137 survey_idx++;
6138 continue;
6139 }
6140
Holger Schurig61fa7132009-11-11 12:25:40 +01006141 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006142 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006143 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006144 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006145 goto out;
6146 survey_idx++;
6147 }
6148
6149 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006150 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006151 res = skb->len;
6152 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006153 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006154 return res;
6155}
6156
Samuel Ortizb23aa672009-07-01 21:26:54 +02006157static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6158{
6159 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6160 NL80211_WPA_VERSION_2));
6161}
6162
Jouni Malinen636a5d32009-03-19 13:39:22 +02006163static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6164{
Johannes Berg4c476992010-10-04 21:36:35 +02006165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6166 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006167 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006168 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6169 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006170 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006171 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006172 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006173
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006174 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6175 return -EINVAL;
6176
6177 if (!info->attrs[NL80211_ATTR_MAC])
6178 return -EINVAL;
6179
Jouni Malinen17780922009-03-27 20:52:47 +02006180 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6181 return -EINVAL;
6182
Johannes Berg19957bb2009-07-02 17:20:43 +02006183 if (!info->attrs[NL80211_ATTR_SSID])
6184 return -EINVAL;
6185
6186 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6187 return -EINVAL;
6188
Johannes Bergfffd0932009-07-08 14:22:54 +02006189 err = nl80211_parse_key(info, &key);
6190 if (err)
6191 return err;
6192
6193 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006194 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6195 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006196 if (!key.p.key || !key.p.key_len)
6197 return -EINVAL;
6198 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6199 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6200 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6201 key.p.key_len != WLAN_KEY_LEN_WEP104))
6202 return -EINVAL;
6203 if (key.idx > 4)
6204 return -EINVAL;
6205 } else {
6206 key.p.key_len = 0;
6207 key.p.key = NULL;
6208 }
6209
Johannes Bergafea0b72010-08-10 09:46:42 +02006210 if (key.idx >= 0) {
6211 int i;
6212 bool ok = false;
6213 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6214 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6215 ok = true;
6216 break;
6217 }
6218 }
Johannes Berg4c476992010-10-04 21:36:35 +02006219 if (!ok)
6220 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006221 }
6222
Johannes Berg4c476992010-10-04 21:36:35 +02006223 if (!rdev->ops->auth)
6224 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006225
Johannes Berg074ac8d2010-09-16 14:58:22 +02006226 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006227 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6228 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006229
Johannes Berg19957bb2009-07-02 17:20:43 +02006230 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006231 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006232 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006233 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6234 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006235
Johannes Berg19957bb2009-07-02 17:20:43 +02006236 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6237 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6238
6239 if (info->attrs[NL80211_ATTR_IE]) {
6240 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6241 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6242 }
6243
6244 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006245 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006246 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006247
Jouni Malinene39e5b52012-09-30 19:29:39 +03006248 if (auth_type == NL80211_AUTHTYPE_SAE &&
6249 !info->attrs[NL80211_ATTR_SAE_DATA])
6250 return -EINVAL;
6251
6252 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6253 if (auth_type != NL80211_AUTHTYPE_SAE)
6254 return -EINVAL;
6255 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6256 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6257 /* need to include at least Auth Transaction and Status Code */
6258 if (sae_data_len < 4)
6259 return -EINVAL;
6260 }
6261
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006262 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6263
Johannes Berg95de8172012-01-20 13:55:25 +01006264 /*
6265 * Since we no longer track auth state, ignore
6266 * requests to only change local state.
6267 */
6268 if (local_state_change)
6269 return 0;
6270
Johannes Berg91bf9b22013-05-15 17:44:01 +02006271 wdev_lock(dev->ieee80211_ptr);
6272 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6273 ssid, ssid_len, ie, ie_len,
6274 key.p.key, key.p.key_len, key.idx,
6275 sae_data, sae_data_len);
6276 wdev_unlock(dev->ieee80211_ptr);
6277 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006278}
6279
Johannes Bergc0692b82010-08-27 14:26:53 +03006280static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6281 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006282 struct cfg80211_crypto_settings *settings,
6283 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006284{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006285 memset(settings, 0, sizeof(*settings));
6286
Samuel Ortizb23aa672009-07-01 21:26:54 +02006287 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6288
Johannes Bergc0692b82010-08-27 14:26:53 +03006289 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6290 u16 proto;
6291 proto = nla_get_u16(
6292 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6293 settings->control_port_ethertype = cpu_to_be16(proto);
6294 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6295 proto != ETH_P_PAE)
6296 return -EINVAL;
6297 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6298 settings->control_port_no_encrypt = true;
6299 } else
6300 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6301
Samuel Ortizb23aa672009-07-01 21:26:54 +02006302 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6303 void *data;
6304 int len, i;
6305
6306 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6307 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6308 settings->n_ciphers_pairwise = len / sizeof(u32);
6309
6310 if (len % sizeof(u32))
6311 return -EINVAL;
6312
Johannes Berg3dc27d22009-07-02 21:36:37 +02006313 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006314 return -EINVAL;
6315
6316 memcpy(settings->ciphers_pairwise, data, len);
6317
6318 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006319 if (!cfg80211_supported_cipher_suite(
6320 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006321 settings->ciphers_pairwise[i]))
6322 return -EINVAL;
6323 }
6324
6325 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6326 settings->cipher_group =
6327 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006328 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6329 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006330 return -EINVAL;
6331 }
6332
6333 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6334 settings->wpa_versions =
6335 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6336 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6337 return -EINVAL;
6338 }
6339
6340 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6341 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006342 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006343
6344 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6345 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6346 settings->n_akm_suites = len / sizeof(u32);
6347
6348 if (len % sizeof(u32))
6349 return -EINVAL;
6350
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006351 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6352 return -EINVAL;
6353
Samuel Ortizb23aa672009-07-01 21:26:54 +02006354 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006355 }
6356
6357 return 0;
6358}
6359
Jouni Malinen636a5d32009-03-19 13:39:22 +02006360static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6361{
Johannes Berg4c476992010-10-04 21:36:35 +02006362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6363 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006364 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006365 struct cfg80211_assoc_request req = {};
6366 const u8 *bssid, *ssid;
6367 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006368
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006369 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6370 return -EINVAL;
6371
6372 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006373 !info->attrs[NL80211_ATTR_SSID] ||
6374 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006375 return -EINVAL;
6376
Johannes Berg4c476992010-10-04 21:36:35 +02006377 if (!rdev->ops->assoc)
6378 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006379
Johannes Berg074ac8d2010-09-16 14:58:22 +02006380 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006381 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6382 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006383
Johannes Berg19957bb2009-07-02 17:20:43 +02006384 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006385
Johannes Berg19957bb2009-07-02 17:20:43 +02006386 chan = ieee80211_get_channel(&rdev->wiphy,
6387 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006388 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6389 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006390
Johannes Berg19957bb2009-07-02 17:20:43 +02006391 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6392 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006393
6394 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006395 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6396 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006397 }
6398
Jouni Malinendc6382c2009-05-06 22:09:37 +03006399 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006400 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006401 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006402 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006403 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006404 else if (mfp != NL80211_MFP_NO)
6405 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006406 }
6407
Johannes Berg3e5d7642009-07-07 14:37:26 +02006408 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006409 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006410
Ben Greear7e7c8922011-11-18 11:31:59 -08006411 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006412 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006413
6414 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006415 memcpy(&req.ht_capa_mask,
6416 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6417 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006418
6419 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006420 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006421 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006422 memcpy(&req.ht_capa,
6423 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6424 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006425 }
6426
Johannes Bergee2aca32013-02-21 17:36:01 +01006427 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006428 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006429
6430 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006431 memcpy(&req.vht_capa_mask,
6432 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6433 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006434
6435 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006436 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006437 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006438 memcpy(&req.vht_capa,
6439 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6440 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006441 }
6442
Johannes Bergf62fab72013-02-21 20:09:09 +01006443 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006444 if (!err) {
6445 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006446 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6447 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006448 wdev_unlock(dev->ieee80211_ptr);
6449 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006450
Jouni Malinen636a5d32009-03-19 13:39:22 +02006451 return err;
6452}
6453
6454static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6455{
Johannes Berg4c476992010-10-04 21:36:35 +02006456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6457 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006458 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006459 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006460 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006461 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006462
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006463 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6464 return -EINVAL;
6465
6466 if (!info->attrs[NL80211_ATTR_MAC])
6467 return -EINVAL;
6468
6469 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6470 return -EINVAL;
6471
Johannes Berg4c476992010-10-04 21:36:35 +02006472 if (!rdev->ops->deauth)
6473 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006474
Johannes Berg074ac8d2010-09-16 14:58:22 +02006475 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006476 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6477 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006478
Johannes Berg19957bb2009-07-02 17:20:43 +02006479 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006480
Johannes Berg19957bb2009-07-02 17:20:43 +02006481 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6482 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006483 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006484 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006485 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006486
6487 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006488 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6489 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006490 }
6491
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006492 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6493
Johannes Berg91bf9b22013-05-15 17:44:01 +02006494 wdev_lock(dev->ieee80211_ptr);
6495 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6496 local_state_change);
6497 wdev_unlock(dev->ieee80211_ptr);
6498 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006499}
6500
6501static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6502{
Johannes Berg4c476992010-10-04 21:36:35 +02006503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6504 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006505 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006506 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006507 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006508 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006509
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006510 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6511 return -EINVAL;
6512
6513 if (!info->attrs[NL80211_ATTR_MAC])
6514 return -EINVAL;
6515
6516 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6517 return -EINVAL;
6518
Johannes Berg4c476992010-10-04 21:36:35 +02006519 if (!rdev->ops->disassoc)
6520 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006521
Johannes Berg074ac8d2010-09-16 14:58:22 +02006522 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006523 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6524 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006525
Johannes Berg19957bb2009-07-02 17:20:43 +02006526 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006527
Johannes Berg19957bb2009-07-02 17:20:43 +02006528 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6529 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006530 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006531 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006532 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006533
6534 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006535 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6536 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006537 }
6538
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006539 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6540
Johannes Berg91bf9b22013-05-15 17:44:01 +02006541 wdev_lock(dev->ieee80211_ptr);
6542 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6543 local_state_change);
6544 wdev_unlock(dev->ieee80211_ptr);
6545 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006546}
6547
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006548static bool
6549nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6550 int mcast_rate[IEEE80211_NUM_BANDS],
6551 int rateval)
6552{
6553 struct wiphy *wiphy = &rdev->wiphy;
6554 bool found = false;
6555 int band, i;
6556
6557 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6558 struct ieee80211_supported_band *sband;
6559
6560 sband = wiphy->bands[band];
6561 if (!sband)
6562 continue;
6563
6564 for (i = 0; i < sband->n_bitrates; i++) {
6565 if (sband->bitrates[i].bitrate == rateval) {
6566 mcast_rate[band] = i + 1;
6567 found = true;
6568 break;
6569 }
6570 }
6571 }
6572
6573 return found;
6574}
6575
Johannes Berg04a773a2009-04-19 21:24:32 +02006576static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6577{
Johannes Berg4c476992010-10-04 21:36:35 +02006578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6579 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006580 struct cfg80211_ibss_params ibss;
6581 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006582 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006583 int err;
6584
Johannes Berg8e30bc52009-04-22 17:45:38 +02006585 memset(&ibss, 0, sizeof(ibss));
6586
Johannes Berg04a773a2009-04-19 21:24:32 +02006587 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6588 return -EINVAL;
6589
Johannes Berg683b6d32012-11-08 21:25:48 +01006590 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006591 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6592 return -EINVAL;
6593
Johannes Berg8e30bc52009-04-22 17:45:38 +02006594 ibss.beacon_interval = 100;
6595
6596 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6597 ibss.beacon_interval =
6598 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6599 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6600 return -EINVAL;
6601 }
6602
Johannes Berg4c476992010-10-04 21:36:35 +02006603 if (!rdev->ops->join_ibss)
6604 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006605
Johannes Berg4c476992010-10-04 21:36:35 +02006606 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6607 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006608
Johannes Berg79c97e92009-07-07 03:56:12 +02006609 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006610
Johannes Berg39193492011-09-16 13:45:25 +02006611 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006612 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006613
6614 if (!is_valid_ether_addr(ibss.bssid))
6615 return -EINVAL;
6616 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006617 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6618 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6619
6620 if (info->attrs[NL80211_ATTR_IE]) {
6621 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6622 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6623 }
6624
Johannes Berg683b6d32012-11-08 21:25:48 +01006625 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6626 if (err)
6627 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006628
Johannes Berg683b6d32012-11-08 21:25:48 +01006629 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006630 return -EINVAL;
6631
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006632 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006633 case NL80211_CHAN_WIDTH_5:
6634 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006635 case NL80211_CHAN_WIDTH_20_NOHT:
6636 break;
6637 case NL80211_CHAN_WIDTH_20:
6638 case NL80211_CHAN_WIDTH_40:
6639 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6640 break;
6641 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006642 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006643 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006644
Johannes Berg04a773a2009-04-19 21:24:32 +02006645 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006646 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006647
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006648 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6649 u8 *rates =
6650 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6651 int n_rates =
6652 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6653 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006654 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006655
Johannes Berg34850ab2011-07-18 18:08:35 +02006656 err = ieee80211_get_ratemask(sband, rates, n_rates,
6657 &ibss.basic_rates);
6658 if (err)
6659 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006660 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006661
Simon Wunderlich803768f2013-06-28 10:39:58 +02006662 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6663 memcpy(&ibss.ht_capa_mask,
6664 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6665 sizeof(ibss.ht_capa_mask));
6666
6667 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6668 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6669 return -EINVAL;
6670 memcpy(&ibss.ht_capa,
6671 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6672 sizeof(ibss.ht_capa));
6673 }
6674
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006675 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6676 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6677 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6678 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006679
Johannes Berg4c476992010-10-04 21:36:35 +02006680 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306681 bool no_ht = false;
6682
Johannes Berg4c476992010-10-04 21:36:35 +02006683 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306684 info->attrs[NL80211_ATTR_KEYS],
6685 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006686 if (IS_ERR(connkeys))
6687 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306688
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006689 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6690 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306691 kfree(connkeys);
6692 return -EINVAL;
6693 }
Johannes Berg4c476992010-10-04 21:36:35 +02006694 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006695
Antonio Quartulli267335d2012-01-31 20:25:47 +01006696 ibss.control_port =
6697 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6698
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006699 ibss.userspace_handles_dfs =
6700 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6701
Johannes Berg4c476992010-10-04 21:36:35 +02006702 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006703 if (err)
6704 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006705 return err;
6706}
6707
6708static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6709{
Johannes Berg4c476992010-10-04 21:36:35 +02006710 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6711 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006712
Johannes Berg4c476992010-10-04 21:36:35 +02006713 if (!rdev->ops->leave_ibss)
6714 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006715
Johannes Berg4c476992010-10-04 21:36:35 +02006716 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6717 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006718
Johannes Berg4c476992010-10-04 21:36:35 +02006719 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006720}
6721
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006722static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6723{
6724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6725 struct net_device *dev = info->user_ptr[1];
6726 int mcast_rate[IEEE80211_NUM_BANDS];
6727 u32 nla_rate;
6728 int err;
6729
6730 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6731 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6732 return -EOPNOTSUPP;
6733
6734 if (!rdev->ops->set_mcast_rate)
6735 return -EOPNOTSUPP;
6736
6737 memset(mcast_rate, 0, sizeof(mcast_rate));
6738
6739 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6740 return -EINVAL;
6741
6742 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6743 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6744 return -EINVAL;
6745
6746 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6747
6748 return err;
6749}
6750
Johannes Bergad7e7182013-11-13 13:37:47 +01006751static struct sk_buff *
6752__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6753 int approxlen, u32 portid, u32 seq,
6754 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006755 enum nl80211_attrs attr,
6756 const struct nl80211_vendor_cmd_info *info,
6757 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006758{
6759 struct sk_buff *skb;
6760 void *hdr;
6761 struct nlattr *data;
6762
6763 skb = nlmsg_new(approxlen + 100, gfp);
6764 if (!skb)
6765 return NULL;
6766
6767 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6768 if (!hdr) {
6769 kfree_skb(skb);
6770 return NULL;
6771 }
6772
6773 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6774 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006775
6776 if (info) {
6777 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6778 info->vendor_id))
6779 goto nla_put_failure;
6780 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6781 info->subcmd))
6782 goto nla_put_failure;
6783 }
6784
Johannes Bergad7e7182013-11-13 13:37:47 +01006785 data = nla_nest_start(skb, attr);
6786
6787 ((void **)skb->cb)[0] = rdev;
6788 ((void **)skb->cb)[1] = hdr;
6789 ((void **)skb->cb)[2] = data;
6790
6791 return skb;
6792
6793 nla_put_failure:
6794 kfree_skb(skb);
6795 return NULL;
6796}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006797
Johannes Berge03ad6e2014-01-01 17:22:30 +01006798struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6799 enum nl80211_commands cmd,
6800 enum nl80211_attrs attr,
6801 int vendor_event_idx,
6802 int approxlen, gfp_t gfp)
6803{
6804 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6805 const struct nl80211_vendor_cmd_info *info;
6806
6807 switch (cmd) {
6808 case NL80211_CMD_TESTMODE:
6809 if (WARN_ON(vendor_event_idx != -1))
6810 return NULL;
6811 info = NULL;
6812 break;
6813 case NL80211_CMD_VENDOR:
6814 if (WARN_ON(vendor_event_idx < 0 ||
6815 vendor_event_idx >= wiphy->n_vendor_events))
6816 return NULL;
6817 info = &wiphy->vendor_events[vendor_event_idx];
6818 break;
6819 default:
6820 WARN_ON(1);
6821 return NULL;
6822 }
6823
6824 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6825 cmd, attr, info, gfp);
6826}
6827EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6828
6829void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6830{
6831 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6832 void *hdr = ((void **)skb->cb)[1];
6833 struct nlattr *data = ((void **)skb->cb)[2];
6834 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6835
6836 nla_nest_end(skb, data);
6837 genlmsg_end(skb, hdr);
6838
6839 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6840 mcgrp = NL80211_MCGRP_VENDOR;
6841
6842 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6843 mcgrp, gfp);
6844}
6845EXPORT_SYMBOL(__cfg80211_send_event_skb);
6846
Johannes Bergaff89a92009-07-01 21:26:51 +02006847#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006848static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6849{
Johannes Berg4c476992010-10-04 21:36:35 +02006850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006851 struct wireless_dev *wdev =
6852 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006853 int err;
6854
David Spinadelfc73f112013-07-31 18:04:15 +03006855 if (!rdev->ops->testmode_cmd)
6856 return -EOPNOTSUPP;
6857
6858 if (IS_ERR(wdev)) {
6859 err = PTR_ERR(wdev);
6860 if (err != -EINVAL)
6861 return err;
6862 wdev = NULL;
6863 } else if (wdev->wiphy != &rdev->wiphy) {
6864 return -EINVAL;
6865 }
6866
Johannes Bergaff89a92009-07-01 21:26:51 +02006867 if (!info->attrs[NL80211_ATTR_TESTDATA])
6868 return -EINVAL;
6869
Johannes Bergad7e7182013-11-13 13:37:47 +01006870 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03006871 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006872 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6873 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01006874 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006875
Johannes Bergaff89a92009-07-01 21:26:51 +02006876 return err;
6877}
6878
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006879static int nl80211_testmode_dump(struct sk_buff *skb,
6880 struct netlink_callback *cb)
6881{
Johannes Berg00918d32011-12-13 17:22:05 +01006882 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006883 int err;
6884 long phy_idx;
6885 void *data = NULL;
6886 int data_len = 0;
6887
Johannes Berg5fe231e2013-05-08 21:45:15 +02006888 rtnl_lock();
6889
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006890 if (cb->args[0]) {
6891 /*
6892 * 0 is a valid index, but not valid for args[0],
6893 * so we need to offset by 1.
6894 */
6895 phy_idx = cb->args[0] - 1;
6896 } else {
6897 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6898 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6899 nl80211_policy);
6900 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006901 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006902
Johannes Berg2bd7e352012-06-15 14:23:16 +02006903 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6904 nl80211_fam.attrbuf);
6905 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006906 err = PTR_ERR(rdev);
6907 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006908 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006909 phy_idx = rdev->wiphy_idx;
6910 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006911
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006912 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6913 cb->args[1] =
6914 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6915 }
6916
6917 if (cb->args[1]) {
6918 data = nla_data((void *)cb->args[1]);
6919 data_len = nla_len((void *)cb->args[1]);
6920 }
6921
Johannes Berg00918d32011-12-13 17:22:05 +01006922 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6923 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006924 err = -ENOENT;
6925 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006926 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006927
Johannes Berg00918d32011-12-13 17:22:05 +01006928 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006929 err = -EOPNOTSUPP;
6930 goto out_err;
6931 }
6932
6933 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006934 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006935 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6936 NL80211_CMD_TESTMODE);
6937 struct nlattr *tmdata;
6938
Dan Carpentercb35fba2013-08-14 14:50:01 +03006939 if (!hdr)
6940 break;
6941
David S. Miller9360ffd2012-03-29 04:41:26 -04006942 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006943 genlmsg_cancel(skb, hdr);
6944 break;
6945 }
6946
6947 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6948 if (!tmdata) {
6949 genlmsg_cancel(skb, hdr);
6950 break;
6951 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006952 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006953 nla_nest_end(skb, tmdata);
6954
6955 if (err == -ENOBUFS || err == -ENOENT) {
6956 genlmsg_cancel(skb, hdr);
6957 break;
6958 } else if (err) {
6959 genlmsg_cancel(skb, hdr);
6960 goto out_err;
6961 }
6962
6963 genlmsg_end(skb, hdr);
6964 }
6965
6966 err = skb->len;
6967 /* see above */
6968 cb->args[0] = phy_idx + 1;
6969 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006970 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006971 return err;
6972}
Johannes Bergaff89a92009-07-01 21:26:51 +02006973#endif
6974
Samuel Ortizb23aa672009-07-01 21:26:54 +02006975static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6976{
Johannes Berg4c476992010-10-04 21:36:35 +02006977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6978 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006979 struct cfg80211_connect_params connect;
6980 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006981 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006982 int err;
6983
6984 memset(&connect, 0, sizeof(connect));
6985
6986 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6987 return -EINVAL;
6988
6989 if (!info->attrs[NL80211_ATTR_SSID] ||
6990 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6991 return -EINVAL;
6992
6993 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6994 connect.auth_type =
6995 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006996 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6997 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006998 return -EINVAL;
6999 } else
7000 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7001
7002 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7003
Johannes Bergc0692b82010-08-27 14:26:53 +03007004 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007005 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007006 if (err)
7007 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007008
Johannes Berg074ac8d2010-09-16 14:58:22 +02007009 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007010 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7011 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007012
Johannes Berg79c97e92009-07-07 03:56:12 +02007013 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007014
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307015 connect.bg_scan_period = -1;
7016 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7017 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7018 connect.bg_scan_period =
7019 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7020 }
7021
Samuel Ortizb23aa672009-07-01 21:26:54 +02007022 if (info->attrs[NL80211_ATTR_MAC])
7023 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7024 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7025 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7026
7027 if (info->attrs[NL80211_ATTR_IE]) {
7028 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7029 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7030 }
7031
Jouni Malinencee00a92013-01-15 17:15:57 +02007032 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7033 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7034 if (connect.mfp != NL80211_MFP_REQUIRED &&
7035 connect.mfp != NL80211_MFP_NO)
7036 return -EINVAL;
7037 } else {
7038 connect.mfp = NL80211_MFP_NO;
7039 }
7040
Samuel Ortizb23aa672009-07-01 21:26:54 +02007041 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7042 connect.channel =
7043 ieee80211_get_channel(wiphy,
7044 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
7045 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02007046 connect.channel->flags & IEEE80211_CHAN_DISABLED)
7047 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007048 }
7049
Johannes Bergfffd0932009-07-08 14:22:54 +02007050 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7051 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307052 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007053 if (IS_ERR(connkeys))
7054 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007055 }
7056
Ben Greear7e7c8922011-11-18 11:31:59 -08007057 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7058 connect.flags |= ASSOC_REQ_DISABLE_HT;
7059
7060 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7061 memcpy(&connect.ht_capa_mask,
7062 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7063 sizeof(connect.ht_capa_mask));
7064
7065 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007066 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7067 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007068 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007069 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007070 memcpy(&connect.ht_capa,
7071 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7072 sizeof(connect.ht_capa));
7073 }
7074
Johannes Bergee2aca32013-02-21 17:36:01 +01007075 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7076 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7077
7078 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7079 memcpy(&connect.vht_capa_mask,
7080 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7081 sizeof(connect.vht_capa_mask));
7082
7083 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7084 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7085 kfree(connkeys);
7086 return -EINVAL;
7087 }
7088 memcpy(&connect.vht_capa,
7089 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7090 sizeof(connect.vht_capa));
7091 }
7092
Johannes Berg83739b02013-05-15 17:44:01 +02007093 wdev_lock(dev->ieee80211_ptr);
7094 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7095 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007096 if (err)
7097 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007098 return err;
7099}
7100
7101static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7102{
Johannes Berg4c476992010-10-04 21:36:35 +02007103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7104 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007105 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007106 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007107
7108 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7109 reason = WLAN_REASON_DEAUTH_LEAVING;
7110 else
7111 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7112
7113 if (reason == 0)
7114 return -EINVAL;
7115
Johannes Berg074ac8d2010-09-16 14:58:22 +02007116 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007117 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7118 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007119
Johannes Berg83739b02013-05-15 17:44:01 +02007120 wdev_lock(dev->ieee80211_ptr);
7121 ret = cfg80211_disconnect(rdev, dev, reason, true);
7122 wdev_unlock(dev->ieee80211_ptr);
7123 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007124}
7125
Johannes Berg463d0182009-07-14 00:33:35 +02007126static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7127{
Johannes Berg4c476992010-10-04 21:36:35 +02007128 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007129 struct net *net;
7130 int err;
7131 u32 pid;
7132
7133 if (!info->attrs[NL80211_ATTR_PID])
7134 return -EINVAL;
7135
7136 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7137
Johannes Berg463d0182009-07-14 00:33:35 +02007138 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007139 if (IS_ERR(net))
7140 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007141
7142 err = 0;
7143
7144 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007145 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7146 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007147
Johannes Berg463d0182009-07-14 00:33:35 +02007148 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007149 return err;
7150}
7151
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007152static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7153{
Johannes Berg4c476992010-10-04 21:36:35 +02007154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007155 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7156 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007157 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007158 struct cfg80211_pmksa pmksa;
7159
7160 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7161
7162 if (!info->attrs[NL80211_ATTR_MAC])
7163 return -EINVAL;
7164
7165 if (!info->attrs[NL80211_ATTR_PMKID])
7166 return -EINVAL;
7167
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007168 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7169 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7170
Johannes Berg074ac8d2010-09-16 14:58:22 +02007171 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007172 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7173 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007174
7175 switch (info->genlhdr->cmd) {
7176 case NL80211_CMD_SET_PMKSA:
7177 rdev_ops = rdev->ops->set_pmksa;
7178 break;
7179 case NL80211_CMD_DEL_PMKSA:
7180 rdev_ops = rdev->ops->del_pmksa;
7181 break;
7182 default:
7183 WARN_ON(1);
7184 break;
7185 }
7186
Johannes Berg4c476992010-10-04 21:36:35 +02007187 if (!rdev_ops)
7188 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007189
Johannes Berg4c476992010-10-04 21:36:35 +02007190 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007191}
7192
7193static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7194{
Johannes Berg4c476992010-10-04 21:36:35 +02007195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7196 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007197
Johannes Berg074ac8d2010-09-16 14:58:22 +02007198 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007199 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7200 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007201
Johannes Berg4c476992010-10-04 21:36:35 +02007202 if (!rdev->ops->flush_pmksa)
7203 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007204
Hila Gonene35e4d22012-06-27 17:19:42 +03007205 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007206}
7207
Arik Nemtsov109086c2011-09-28 14:12:50 +03007208static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7209{
7210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7211 struct net_device *dev = info->user_ptr[1];
7212 u8 action_code, dialog_token;
7213 u16 status_code;
7214 u8 *peer;
7215
7216 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7217 !rdev->ops->tdls_mgmt)
7218 return -EOPNOTSUPP;
7219
7220 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7221 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7222 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7223 !info->attrs[NL80211_ATTR_IE] ||
7224 !info->attrs[NL80211_ATTR_MAC])
7225 return -EINVAL;
7226
7227 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7228 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7229 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7230 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7231
Hila Gonene35e4d22012-06-27 17:19:42 +03007232 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7233 dialog_token, status_code,
7234 nla_data(info->attrs[NL80211_ATTR_IE]),
7235 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007236}
7237
7238static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7239{
7240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7241 struct net_device *dev = info->user_ptr[1];
7242 enum nl80211_tdls_operation operation;
7243 u8 *peer;
7244
7245 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7246 !rdev->ops->tdls_oper)
7247 return -EOPNOTSUPP;
7248
7249 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7250 !info->attrs[NL80211_ATTR_MAC])
7251 return -EINVAL;
7252
7253 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7254 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7255
Hila Gonene35e4d22012-06-27 17:19:42 +03007256 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007257}
7258
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007259static int nl80211_remain_on_channel(struct sk_buff *skb,
7260 struct genl_info *info)
7261{
Johannes Berg4c476992010-10-04 21:36:35 +02007262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007263 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007264 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007265 struct sk_buff *msg;
7266 void *hdr;
7267 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007268 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007269 int err;
7270
7271 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7272 !info->attrs[NL80211_ATTR_DURATION])
7273 return -EINVAL;
7274
7275 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7276
Johannes Berg7c4ef712011-11-18 15:33:48 +01007277 if (!rdev->ops->remain_on_channel ||
7278 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007279 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007280
Johannes Bergebf348f2012-06-01 12:50:54 +02007281 /*
7282 * We should be on that channel for at least a minimum amount of
7283 * time (10ms) but no longer than the driver supports.
7284 */
7285 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7286 duration > rdev->wiphy.max_remain_on_channel_duration)
7287 return -EINVAL;
7288
Johannes Berg683b6d32012-11-08 21:25:48 +01007289 err = nl80211_parse_chandef(rdev, info, &chandef);
7290 if (err)
7291 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007292
7293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007294 if (!msg)
7295 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007296
Eric W. Biederman15e47302012-09-07 20:12:54 +00007297 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007298 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007299 if (!hdr) {
7300 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007301 goto free_msg;
7302 }
7303
Johannes Berg683b6d32012-11-08 21:25:48 +01007304 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7305 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007306
7307 if (err)
7308 goto free_msg;
7309
David S. Miller9360ffd2012-03-29 04:41:26 -04007310 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7311 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007312
7313 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007314
7315 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007316
7317 nla_put_failure:
7318 err = -ENOBUFS;
7319 free_msg:
7320 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007321 return err;
7322}
7323
7324static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7325 struct genl_info *info)
7326{
Johannes Berg4c476992010-10-04 21:36:35 +02007327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007328 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007329 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007330
7331 if (!info->attrs[NL80211_ATTR_COOKIE])
7332 return -EINVAL;
7333
Johannes Berg4c476992010-10-04 21:36:35 +02007334 if (!rdev->ops->cancel_remain_on_channel)
7335 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007336
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007337 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7338
Hila Gonene35e4d22012-06-27 17:19:42 +03007339 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007340}
7341
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007342static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7343 u8 *rates, u8 rates_len)
7344{
7345 u8 i;
7346 u32 mask = 0;
7347
7348 for (i = 0; i < rates_len; i++) {
7349 int rate = (rates[i] & 0x7f) * 5;
7350 int ridx;
7351 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7352 struct ieee80211_rate *srate =
7353 &sband->bitrates[ridx];
7354 if (rate == srate->bitrate) {
7355 mask |= 1 << ridx;
7356 break;
7357 }
7358 }
7359 if (ridx == sband->n_bitrates)
7360 return 0; /* rate not found */
7361 }
7362
7363 return mask;
7364}
7365
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007366static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7367 u8 *rates, u8 rates_len,
7368 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7369{
7370 u8 i;
7371
7372 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7373
7374 for (i = 0; i < rates_len; i++) {
7375 int ridx, rbit;
7376
7377 ridx = rates[i] / 8;
7378 rbit = BIT(rates[i] % 8);
7379
7380 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007381 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007382 return false;
7383
7384 /* check availability */
7385 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7386 mcs[ridx] |= rbit;
7387 else
7388 return false;
7389 }
7390
7391 return true;
7392}
7393
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007394static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7395{
7396 u16 mcs_mask = 0;
7397
7398 switch (vht_mcs_map) {
7399 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7400 break;
7401 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7402 mcs_mask = 0x00FF;
7403 break;
7404 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7405 mcs_mask = 0x01FF;
7406 break;
7407 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7408 mcs_mask = 0x03FF;
7409 break;
7410 default:
7411 break;
7412 }
7413
7414 return mcs_mask;
7415}
7416
7417static void vht_build_mcs_mask(u16 vht_mcs_map,
7418 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7419{
7420 u8 nss;
7421
7422 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7423 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7424 vht_mcs_map >>= 2;
7425 }
7426}
7427
7428static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7429 struct nl80211_txrate_vht *txrate,
7430 u16 mcs[NL80211_VHT_NSS_MAX])
7431{
7432 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7433 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7434 u8 i;
7435
7436 if (!sband->vht_cap.vht_supported)
7437 return false;
7438
7439 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7440
7441 /* Build vht_mcs_mask from VHT capabilities */
7442 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7443
7444 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7445 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7446 mcs[i] = txrate->mcs[i];
7447 else
7448 return false;
7449 }
7450
7451 return true;
7452}
7453
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007454static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007455 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7456 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007457 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7458 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007459 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007460};
7461
7462static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7463 struct genl_info *info)
7464{
7465 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007466 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007467 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007468 int rem, i;
7469 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007470 struct nlattr *tx_rates;
7471 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007472 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007473
Johannes Berg4c476992010-10-04 21:36:35 +02007474 if (!rdev->ops->set_bitrate_mask)
7475 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007476
7477 memset(&mask, 0, sizeof(mask));
7478 /* Default to all rates enabled */
7479 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7480 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007481
7482 if (!sband)
7483 continue;
7484
7485 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007486 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007487 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007488 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007489
7490 if (!sband->vht_cap.vht_supported)
7491 continue;
7492
7493 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7494 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007495 }
7496
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007497 /* if no rates are given set it back to the defaults */
7498 if (!info->attrs[NL80211_ATTR_TX_RATES])
7499 goto out;
7500
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007501 /*
7502 * The nested attribute uses enum nl80211_band as the index. This maps
7503 * directly to the enum ieee80211_band values used in cfg80211.
7504 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007505 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007506 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7507 {
7508 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007509 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7510 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007511 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007512 if (sband == NULL)
7513 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007514 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7515 nla_len(tx_rates), nl80211_txattr_policy);
7516 if (tb[NL80211_TXRATE_LEGACY]) {
7517 mask.control[band].legacy = rateset_to_mask(
7518 sband,
7519 nla_data(tb[NL80211_TXRATE_LEGACY]),
7520 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307521 if ((mask.control[band].legacy == 0) &&
7522 nla_len(tb[NL80211_TXRATE_LEGACY]))
7523 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007524 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007525 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007526 if (!ht_rateset_to_mask(
7527 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007528 nla_data(tb[NL80211_TXRATE_HT]),
7529 nla_len(tb[NL80211_TXRATE_HT]),
7530 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007531 return -EINVAL;
7532 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007533 if (tb[NL80211_TXRATE_VHT]) {
7534 if (!vht_set_mcs_mask(
7535 sband,
7536 nla_data(tb[NL80211_TXRATE_VHT]),
7537 mask.control[band].vht_mcs))
7538 return -EINVAL;
7539 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007540
7541 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007542 /* don't allow empty legacy rates if HT or VHT
7543 * are not even supported.
7544 */
7545 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7546 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007547 return -EINVAL;
7548
7549 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007550 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007551 goto out;
7552
7553 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7554 if (mask.control[band].vht_mcs[i])
7555 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007556
7557 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007558 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007559 }
7560 }
7561
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007562out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007563 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007564}
7565
Johannes Berg2e161f72010-08-12 15:38:38 +02007566static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007567{
Johannes Berg4c476992010-10-04 21:36:35 +02007568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007569 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007570 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007571
7572 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7573 return -EINVAL;
7574
Johannes Berg2e161f72010-08-12 15:38:38 +02007575 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7576 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007577
Johannes Berg71bbc992012-06-15 15:30:18 +02007578 switch (wdev->iftype) {
7579 case NL80211_IFTYPE_STATION:
7580 case NL80211_IFTYPE_ADHOC:
7581 case NL80211_IFTYPE_P2P_CLIENT:
7582 case NL80211_IFTYPE_AP:
7583 case NL80211_IFTYPE_AP_VLAN:
7584 case NL80211_IFTYPE_MESH_POINT:
7585 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007586 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007587 break;
7588 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007589 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007590 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007591
7592 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007593 if (!rdev->ops->mgmt_tx)
7594 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007595
Eric W. Biederman15e47302012-09-07 20:12:54 +00007596 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007597 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7598 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007599}
7600
Johannes Berg2e161f72010-08-12 15:38:38 +02007601static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007602{
Johannes Berg4c476992010-10-04 21:36:35 +02007603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007604 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007605 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007606 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007607 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007608 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007609 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007610 struct cfg80211_mgmt_tx_params params = {
7611 .dont_wait_for_ack =
7612 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7613 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007614
Johannes Berg683b6d32012-11-08 21:25:48 +01007615 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007616 return -EINVAL;
7617
Johannes Berg4c476992010-10-04 21:36:35 +02007618 if (!rdev->ops->mgmt_tx)
7619 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007620
Johannes Berg71bbc992012-06-15 15:30:18 +02007621 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007622 case NL80211_IFTYPE_P2P_DEVICE:
7623 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7624 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007625 case NL80211_IFTYPE_STATION:
7626 case NL80211_IFTYPE_ADHOC:
7627 case NL80211_IFTYPE_P2P_CLIENT:
7628 case NL80211_IFTYPE_AP:
7629 case NL80211_IFTYPE_AP_VLAN:
7630 case NL80211_IFTYPE_MESH_POINT:
7631 case NL80211_IFTYPE_P2P_GO:
7632 break;
7633 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007634 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007635 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007636
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007637 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007638 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007639 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007640 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007641
7642 /*
7643 * We should wait on the channel for at least a minimum amount
7644 * of time (10ms) but no longer than the driver supports.
7645 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007646 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7647 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007648 return -EINVAL;
7649
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007650 }
7651
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007652 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007653
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007654 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007655 return -EINVAL;
7656
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007657 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307658
Antonio Quartulliea141b752013-06-11 14:20:03 +02007659 /* get the channel if any has been specified, otherwise pass NULL to
7660 * the driver. The latter will use the current one
7661 */
7662 chandef.chan = NULL;
7663 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7664 err = nl80211_parse_chandef(rdev, info, &chandef);
7665 if (err)
7666 return err;
7667 }
7668
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007669 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007670 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007671
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007672 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007673 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7674 if (!msg)
7675 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007676
Eric W. Biederman15e47302012-09-07 20:12:54 +00007677 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007678 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007679 if (!hdr) {
7680 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007681 goto free_msg;
7682 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007683 }
Johannes Berge247bd902011-11-04 11:18:21 +01007684
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007685 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7686 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7687 params.chan = chandef.chan;
7688 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007689 if (err)
7690 goto free_msg;
7691
Johannes Berge247bd902011-11-04 11:18:21 +01007692 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007693 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7694 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007695
Johannes Berge247bd902011-11-04 11:18:21 +01007696 genlmsg_end(msg, hdr);
7697 return genlmsg_reply(msg, info);
7698 }
7699
7700 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007701
7702 nla_put_failure:
7703 err = -ENOBUFS;
7704 free_msg:
7705 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007706 return err;
7707}
7708
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007709static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7710{
7711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007712 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007713 u64 cookie;
7714
7715 if (!info->attrs[NL80211_ATTR_COOKIE])
7716 return -EINVAL;
7717
7718 if (!rdev->ops->mgmt_tx_cancel_wait)
7719 return -EOPNOTSUPP;
7720
Johannes Berg71bbc992012-06-15 15:30:18 +02007721 switch (wdev->iftype) {
7722 case NL80211_IFTYPE_STATION:
7723 case NL80211_IFTYPE_ADHOC:
7724 case NL80211_IFTYPE_P2P_CLIENT:
7725 case NL80211_IFTYPE_AP:
7726 case NL80211_IFTYPE_AP_VLAN:
7727 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007728 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007729 break;
7730 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007731 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007732 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007733
7734 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7735
Hila Gonene35e4d22012-06-27 17:19:42 +03007736 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007737}
7738
Kalle Valoffb9eb32010-02-17 17:58:10 +02007739static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7740{
Johannes Berg4c476992010-10-04 21:36:35 +02007741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007742 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007743 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007744 u8 ps_state;
7745 bool state;
7746 int err;
7747
Johannes Berg4c476992010-10-04 21:36:35 +02007748 if (!info->attrs[NL80211_ATTR_PS_STATE])
7749 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007750
7751 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7752
Johannes Berg4c476992010-10-04 21:36:35 +02007753 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7754 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007755
7756 wdev = dev->ieee80211_ptr;
7757
Johannes Berg4c476992010-10-04 21:36:35 +02007758 if (!rdev->ops->set_power_mgmt)
7759 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007760
7761 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7762
7763 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007764 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007765
Hila Gonene35e4d22012-06-27 17:19:42 +03007766 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007767 if (!err)
7768 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007769 return err;
7770}
7771
7772static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7773{
Johannes Berg4c476992010-10-04 21:36:35 +02007774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007775 enum nl80211_ps_state ps_state;
7776 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007777 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007778 struct sk_buff *msg;
7779 void *hdr;
7780 int err;
7781
Kalle Valoffb9eb32010-02-17 17:58:10 +02007782 wdev = dev->ieee80211_ptr;
7783
Johannes Berg4c476992010-10-04 21:36:35 +02007784 if (!rdev->ops->set_power_mgmt)
7785 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007786
7787 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007788 if (!msg)
7789 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007790
Eric W. Biederman15e47302012-09-07 20:12:54 +00007791 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007792 NL80211_CMD_GET_POWER_SAVE);
7793 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007794 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007795 goto free_msg;
7796 }
7797
7798 if (wdev->ps)
7799 ps_state = NL80211_PS_ENABLED;
7800 else
7801 ps_state = NL80211_PS_DISABLED;
7802
David S. Miller9360ffd2012-03-29 04:41:26 -04007803 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7804 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007805
7806 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007807 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007808
Johannes Berg4c476992010-10-04 21:36:35 +02007809 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007810 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007811 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007812 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007813 return err;
7814}
7815
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007816static struct nla_policy
7817nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7818 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7819 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7820 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007821 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7822 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7823 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007824};
7825
Thomas Pedersen84f10702012-07-12 16:17:33 -07007826static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007827 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007828{
7829 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007830 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007831 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007832
Johannes Bergd9d8b012012-11-26 12:51:52 +01007833 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007834 return -EINVAL;
7835
Thomas Pedersen84f10702012-07-12 16:17:33 -07007836 if (!rdev->ops->set_cqm_txe_config)
7837 return -EOPNOTSUPP;
7838
7839 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7840 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7841 return -EOPNOTSUPP;
7842
Hila Gonene35e4d22012-06-27 17:19:42 +03007843 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007844}
7845
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007846static int nl80211_set_cqm_rssi(struct genl_info *info,
7847 s32 threshold, u32 hysteresis)
7848{
Johannes Berg4c476992010-10-04 21:36:35 +02007849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007850 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007851 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007852
7853 if (threshold > 0)
7854 return -EINVAL;
7855
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007856 /* disabling - hysteresis should also be zero then */
7857 if (threshold == 0)
7858 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007859
Johannes Berg4c476992010-10-04 21:36:35 +02007860 if (!rdev->ops->set_cqm_rssi_config)
7861 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007862
Johannes Berg074ac8d2010-09-16 14:58:22 +02007863 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007864 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7865 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007866
Hila Gonene35e4d22012-06-27 17:19:42 +03007867 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007868}
7869
7870static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7871{
7872 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7873 struct nlattr *cqm;
7874 int err;
7875
7876 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007877 if (!cqm)
7878 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007879
7880 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7881 nl80211_attr_cqm_policy);
7882 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007883 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007884
7885 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7886 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007887 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7888 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007889
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007890 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7891 }
7892
7893 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7894 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7895 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7896 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7897 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7898 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7899
7900 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7901 }
7902
7903 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007904}
7905
Johannes Berg29cbe682010-12-03 09:20:44 +01007906static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7907{
7908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7909 struct net_device *dev = info->user_ptr[1];
7910 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007911 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007912 int err;
7913
7914 /* start with default */
7915 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007916 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007917
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007918 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007919 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007920 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007921 if (err)
7922 return err;
7923 }
7924
7925 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7926 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7927 return -EINVAL;
7928
Javier Cardonac80d5452010-12-16 17:37:49 -08007929 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7930 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7931
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007932 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7933 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7934 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7935 return -EINVAL;
7936
Marco Porsch9bdbf042013-01-07 16:04:51 +01007937 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7938 setup.beacon_interval =
7939 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7940 if (setup.beacon_interval < 10 ||
7941 setup.beacon_interval > 10000)
7942 return -EINVAL;
7943 }
7944
7945 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7946 setup.dtim_period =
7947 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7948 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7949 return -EINVAL;
7950 }
7951
Javier Cardonac80d5452010-12-16 17:37:49 -08007952 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7953 /* parse additional setup parameters if given */
7954 err = nl80211_parse_mesh_setup(info, &setup);
7955 if (err)
7956 return err;
7957 }
7958
Thomas Pedersend37bb182013-03-04 13:06:13 -08007959 if (setup.user_mpm)
7960 cfg.auto_open_plinks = false;
7961
Johannes Bergcc1d2802012-05-16 23:50:20 +02007962 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007963 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7964 if (err)
7965 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007966 } else {
7967 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007968 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007969 }
7970
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007971 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7972 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7973 int n_rates =
7974 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7975 struct ieee80211_supported_band *sband;
7976
7977 if (!setup.chandef.chan)
7978 return -EINVAL;
7979
7980 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7981
7982 err = ieee80211_get_ratemask(sband, rates, n_rates,
7983 &setup.basic_rates);
7984 if (err)
7985 return err;
7986 }
7987
Javier Cardonac80d5452010-12-16 17:37:49 -08007988 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007989}
7990
7991static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7992{
7993 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7994 struct net_device *dev = info->user_ptr[1];
7995
7996 return cfg80211_leave_mesh(rdev, dev);
7997}
7998
Johannes Bergdfb89c52012-06-27 09:23:48 +02007999#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008000static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8001 struct cfg80211_registered_device *rdev)
8002{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008003 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008004 struct nlattr *nl_pats, *nl_pat;
8005 int i, pat_len;
8006
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008007 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008008 return 0;
8009
8010 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8011 if (!nl_pats)
8012 return -ENOBUFS;
8013
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008014 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008015 nl_pat = nla_nest_start(msg, i + 1);
8016 if (!nl_pat)
8017 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008018 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008019 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008020 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008021 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8022 wowlan->patterns[i].pattern) ||
8023 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008024 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008025 return -ENOBUFS;
8026 nla_nest_end(msg, nl_pat);
8027 }
8028 nla_nest_end(msg, nl_pats);
8029
8030 return 0;
8031}
8032
Johannes Berg2a0e0472013-01-23 22:57:40 +01008033static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8034 struct cfg80211_wowlan_tcp *tcp)
8035{
8036 struct nlattr *nl_tcp;
8037
8038 if (!tcp)
8039 return 0;
8040
8041 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8042 if (!nl_tcp)
8043 return -ENOBUFS;
8044
8045 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8046 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8047 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8048 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8049 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8050 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8051 tcp->payload_len, tcp->payload) ||
8052 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8053 tcp->data_interval) ||
8054 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8055 tcp->wake_len, tcp->wake_data) ||
8056 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8057 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8058 return -ENOBUFS;
8059
8060 if (tcp->payload_seq.len &&
8061 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8062 sizeof(tcp->payload_seq), &tcp->payload_seq))
8063 return -ENOBUFS;
8064
8065 if (tcp->payload_tok.len &&
8066 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8067 sizeof(tcp->payload_tok) + tcp->tokens_size,
8068 &tcp->payload_tok))
8069 return -ENOBUFS;
8070
Johannes Berge248ad32013-05-16 10:24:28 +02008071 nla_nest_end(msg, nl_tcp);
8072
Johannes Berg2a0e0472013-01-23 22:57:40 +01008073 return 0;
8074}
8075
Johannes Bergff1b6e62011-05-04 15:37:28 +02008076static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8077{
8078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8079 struct sk_buff *msg;
8080 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008081 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008082
Johannes Berg964dc9e2013-06-03 17:25:34 +02008083 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008084 return -EOPNOTSUPP;
8085
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008086 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008087 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008088 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8089 rdev->wiphy.wowlan_config->tcp->payload_len +
8090 rdev->wiphy.wowlan_config->tcp->wake_len +
8091 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008092 }
8093
8094 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008095 if (!msg)
8096 return -ENOMEM;
8097
Eric W. Biederman15e47302012-09-07 20:12:54 +00008098 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008099 NL80211_CMD_GET_WOWLAN);
8100 if (!hdr)
8101 goto nla_put_failure;
8102
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008103 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008104 struct nlattr *nl_wowlan;
8105
8106 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8107 if (!nl_wowlan)
8108 goto nla_put_failure;
8109
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008110 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008111 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008112 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008113 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008114 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008115 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008116 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008117 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008118 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008119 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008120 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008121 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008122 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008123 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8124 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008125
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008126 if (nl80211_send_wowlan_patterns(msg, rdev))
8127 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008128
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008129 if (nl80211_send_wowlan_tcp(msg,
8130 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008131 goto nla_put_failure;
8132
Johannes Bergff1b6e62011-05-04 15:37:28 +02008133 nla_nest_end(msg, nl_wowlan);
8134 }
8135
8136 genlmsg_end(msg, hdr);
8137 return genlmsg_reply(msg, info);
8138
8139nla_put_failure:
8140 nlmsg_free(msg);
8141 return -ENOBUFS;
8142}
8143
Johannes Berg2a0e0472013-01-23 22:57:40 +01008144static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8145 struct nlattr *attr,
8146 struct cfg80211_wowlan *trig)
8147{
8148 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8149 struct cfg80211_wowlan_tcp *cfg;
8150 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8151 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8152 u32 size;
8153 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8154 int err, port;
8155
Johannes Berg964dc9e2013-06-03 17:25:34 +02008156 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008157 return -EINVAL;
8158
8159 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8160 nla_data(attr), nla_len(attr),
8161 nl80211_wowlan_tcp_policy);
8162 if (err)
8163 return err;
8164
8165 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8166 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8167 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8168 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8169 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8170 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8171 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8172 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8173 return -EINVAL;
8174
8175 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008176 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008177 return -EINVAL;
8178
8179 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008180 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008181 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008182 return -EINVAL;
8183
8184 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008185 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008186 return -EINVAL;
8187
8188 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8189 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8190 return -EINVAL;
8191
8192 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8193 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8194
8195 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8196 tokens_size = tokln - sizeof(*tok);
8197
8198 if (!tok->len || tokens_size % tok->len)
8199 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008200 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008201 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008202 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008203 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008204 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008205 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008206 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008207 return -EINVAL;
8208 if (tok->offset + tok->len > data_size)
8209 return -EINVAL;
8210 }
8211
8212 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8213 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008214 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008215 return -EINVAL;
8216 if (seq->len == 0 || seq->len > 4)
8217 return -EINVAL;
8218 if (seq->len + seq->offset > data_size)
8219 return -EINVAL;
8220 }
8221
8222 size = sizeof(*cfg);
8223 size += data_size;
8224 size += wake_size + wake_mask_size;
8225 size += tokens_size;
8226
8227 cfg = kzalloc(size, GFP_KERNEL);
8228 if (!cfg)
8229 return -ENOMEM;
8230 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8231 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8232 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8233 ETH_ALEN);
8234 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8235 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8236 else
8237 port = 0;
8238#ifdef CONFIG_INET
8239 /* allocate a socket and port for it and use it */
8240 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8241 IPPROTO_TCP, &cfg->sock, 1);
8242 if (err) {
8243 kfree(cfg);
8244 return err;
8245 }
8246 if (inet_csk_get_port(cfg->sock->sk, port)) {
8247 sock_release(cfg->sock);
8248 kfree(cfg);
8249 return -EADDRINUSE;
8250 }
8251 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8252#else
8253 if (!port) {
8254 kfree(cfg);
8255 return -EINVAL;
8256 }
8257 cfg->src_port = port;
8258#endif
8259
8260 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8261 cfg->payload_len = data_size;
8262 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8263 memcpy((void *)cfg->payload,
8264 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8265 data_size);
8266 if (seq)
8267 cfg->payload_seq = *seq;
8268 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8269 cfg->wake_len = wake_size;
8270 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8271 memcpy((void *)cfg->wake_data,
8272 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8273 wake_size);
8274 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8275 data_size + wake_size;
8276 memcpy((void *)cfg->wake_mask,
8277 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8278 wake_mask_size);
8279 if (tok) {
8280 cfg->tokens_size = tokens_size;
8281 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8282 }
8283
8284 trig->tcp = cfg;
8285
8286 return 0;
8287}
8288
Johannes Bergff1b6e62011-05-04 15:37:28 +02008289static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8290{
8291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8292 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008293 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008294 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008295 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008296 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008297 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008298
Johannes Berg964dc9e2013-06-03 17:25:34 +02008299 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008300 return -EOPNOTSUPP;
8301
Johannes Bergae33bd82012-07-12 16:25:02 +02008302 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8303 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008304 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008305 goto set_wakeup;
8306 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008307
8308 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8309 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8310 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8311 nl80211_wowlan_policy);
8312 if (err)
8313 return err;
8314
8315 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8316 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8317 return -EINVAL;
8318 new_triggers.any = true;
8319 }
8320
8321 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8322 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8323 return -EINVAL;
8324 new_triggers.disconnect = true;
8325 }
8326
8327 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8328 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8329 return -EINVAL;
8330 new_triggers.magic_pkt = true;
8331 }
8332
Johannes Berg77dbbb12011-07-13 10:48:55 +02008333 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8334 return -EINVAL;
8335
8336 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8337 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8338 return -EINVAL;
8339 new_triggers.gtk_rekey_failure = true;
8340 }
8341
8342 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8343 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8344 return -EINVAL;
8345 new_triggers.eap_identity_req = true;
8346 }
8347
8348 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8349 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8350 return -EINVAL;
8351 new_triggers.four_way_handshake = true;
8352 }
8353
8354 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8355 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8356 return -EINVAL;
8357 new_triggers.rfkill_release = true;
8358 }
8359
Johannes Bergff1b6e62011-05-04 15:37:28 +02008360 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8361 struct nlattr *pat;
8362 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008363 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008364 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008365
8366 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8367 rem)
8368 n_patterns++;
8369 if (n_patterns > wowlan->n_patterns)
8370 return -EINVAL;
8371
8372 new_triggers.patterns = kcalloc(n_patterns,
8373 sizeof(new_triggers.patterns[0]),
8374 GFP_KERNEL);
8375 if (!new_triggers.patterns)
8376 return -ENOMEM;
8377
8378 new_triggers.n_patterns = n_patterns;
8379 i = 0;
8380
8381 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8382 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008383 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8384 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008385 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008386 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8387 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008388 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008389 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008390 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008391 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008392 goto error;
8393 if (pat_len > wowlan->pattern_max_len ||
8394 pat_len < wowlan->pattern_min_len)
8395 goto error;
8396
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008397 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008398 pkt_offset = 0;
8399 else
8400 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008401 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008402 if (pkt_offset > wowlan->max_pkt_offset)
8403 goto error;
8404 new_triggers.patterns[i].pkt_offset = pkt_offset;
8405
Johannes Bergff1b6e62011-05-04 15:37:28 +02008406 new_triggers.patterns[i].mask =
8407 kmalloc(mask_len + pat_len, GFP_KERNEL);
8408 if (!new_triggers.patterns[i].mask) {
8409 err = -ENOMEM;
8410 goto error;
8411 }
8412 new_triggers.patterns[i].pattern =
8413 new_triggers.patterns[i].mask + mask_len;
8414 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008415 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008416 mask_len);
8417 new_triggers.patterns[i].pattern_len = pat_len;
8418 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008419 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008420 pat_len);
8421 i++;
8422 }
8423 }
8424
Johannes Berg2a0e0472013-01-23 22:57:40 +01008425 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8426 err = nl80211_parse_wowlan_tcp(
8427 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8428 &new_triggers);
8429 if (err)
8430 goto error;
8431 }
8432
Johannes Bergae33bd82012-07-12 16:25:02 +02008433 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8434 if (!ntrig) {
8435 err = -ENOMEM;
8436 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008437 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008438 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008439 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008440
Johannes Bergae33bd82012-07-12 16:25:02 +02008441 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008442 if (rdev->ops->set_wakeup &&
8443 prev_enabled != !!rdev->wiphy.wowlan_config)
8444 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008445
Johannes Bergff1b6e62011-05-04 15:37:28 +02008446 return 0;
8447 error:
8448 for (i = 0; i < new_triggers.n_patterns; i++)
8449 kfree(new_triggers.patterns[i].mask);
8450 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008451 if (new_triggers.tcp && new_triggers.tcp->sock)
8452 sock_release(new_triggers.tcp->sock);
8453 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008454 return err;
8455}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008456#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008457
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008458static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8459 struct cfg80211_registered_device *rdev)
8460{
8461 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8462 int i, j, pat_len;
8463 struct cfg80211_coalesce_rules *rule;
8464
8465 if (!rdev->coalesce->n_rules)
8466 return 0;
8467
8468 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8469 if (!nl_rules)
8470 return -ENOBUFS;
8471
8472 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8473 nl_rule = nla_nest_start(msg, i + 1);
8474 if (!nl_rule)
8475 return -ENOBUFS;
8476
8477 rule = &rdev->coalesce->rules[i];
8478 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8479 rule->delay))
8480 return -ENOBUFS;
8481
8482 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8483 rule->condition))
8484 return -ENOBUFS;
8485
8486 nl_pats = nla_nest_start(msg,
8487 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8488 if (!nl_pats)
8489 return -ENOBUFS;
8490
8491 for (j = 0; j < rule->n_patterns; j++) {
8492 nl_pat = nla_nest_start(msg, j + 1);
8493 if (!nl_pat)
8494 return -ENOBUFS;
8495 pat_len = rule->patterns[j].pattern_len;
8496 if (nla_put(msg, NL80211_PKTPAT_MASK,
8497 DIV_ROUND_UP(pat_len, 8),
8498 rule->patterns[j].mask) ||
8499 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8500 rule->patterns[j].pattern) ||
8501 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8502 rule->patterns[j].pkt_offset))
8503 return -ENOBUFS;
8504 nla_nest_end(msg, nl_pat);
8505 }
8506 nla_nest_end(msg, nl_pats);
8507 nla_nest_end(msg, nl_rule);
8508 }
8509 nla_nest_end(msg, nl_rules);
8510
8511 return 0;
8512}
8513
8514static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8515{
8516 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8517 struct sk_buff *msg;
8518 void *hdr;
8519
8520 if (!rdev->wiphy.coalesce)
8521 return -EOPNOTSUPP;
8522
8523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8524 if (!msg)
8525 return -ENOMEM;
8526
8527 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8528 NL80211_CMD_GET_COALESCE);
8529 if (!hdr)
8530 goto nla_put_failure;
8531
8532 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8533 goto nla_put_failure;
8534
8535 genlmsg_end(msg, hdr);
8536 return genlmsg_reply(msg, info);
8537
8538nla_put_failure:
8539 nlmsg_free(msg);
8540 return -ENOBUFS;
8541}
8542
8543void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8544{
8545 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8546 int i, j;
8547 struct cfg80211_coalesce_rules *rule;
8548
8549 if (!coalesce)
8550 return;
8551
8552 for (i = 0; i < coalesce->n_rules; i++) {
8553 rule = &coalesce->rules[i];
8554 for (j = 0; j < rule->n_patterns; j++)
8555 kfree(rule->patterns[j].mask);
8556 kfree(rule->patterns);
8557 }
8558 kfree(coalesce->rules);
8559 kfree(coalesce);
8560 rdev->coalesce = NULL;
8561}
8562
8563static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8564 struct nlattr *rule,
8565 struct cfg80211_coalesce_rules *new_rule)
8566{
8567 int err, i;
8568 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8569 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8570 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8571 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8572
8573 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8574 nla_len(rule), nl80211_coalesce_policy);
8575 if (err)
8576 return err;
8577
8578 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8579 new_rule->delay =
8580 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8581 if (new_rule->delay > coalesce->max_delay)
8582 return -EINVAL;
8583
8584 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8585 new_rule->condition =
8586 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8587 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8588 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8589 return -EINVAL;
8590
8591 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8592 return -EINVAL;
8593
8594 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8595 rem)
8596 n_patterns++;
8597 if (n_patterns > coalesce->n_patterns)
8598 return -EINVAL;
8599
8600 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8601 GFP_KERNEL);
8602 if (!new_rule->patterns)
8603 return -ENOMEM;
8604
8605 new_rule->n_patterns = n_patterns;
8606 i = 0;
8607
8608 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8609 rem) {
8610 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8611 nla_len(pat), NULL);
8612 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8613 !pat_tb[NL80211_PKTPAT_PATTERN])
8614 return -EINVAL;
8615 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8616 mask_len = DIV_ROUND_UP(pat_len, 8);
8617 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8618 return -EINVAL;
8619 if (pat_len > coalesce->pattern_max_len ||
8620 pat_len < coalesce->pattern_min_len)
8621 return -EINVAL;
8622
8623 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8624 pkt_offset = 0;
8625 else
8626 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8627 if (pkt_offset > coalesce->max_pkt_offset)
8628 return -EINVAL;
8629 new_rule->patterns[i].pkt_offset = pkt_offset;
8630
8631 new_rule->patterns[i].mask =
8632 kmalloc(mask_len + pat_len, GFP_KERNEL);
8633 if (!new_rule->patterns[i].mask)
8634 return -ENOMEM;
8635 new_rule->patterns[i].pattern =
8636 new_rule->patterns[i].mask + mask_len;
8637 memcpy(new_rule->patterns[i].mask,
8638 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8639 new_rule->patterns[i].pattern_len = pat_len;
8640 memcpy(new_rule->patterns[i].pattern,
8641 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8642 i++;
8643 }
8644
8645 return 0;
8646}
8647
8648static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8649{
8650 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8651 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8652 struct cfg80211_coalesce new_coalesce = {};
8653 struct cfg80211_coalesce *n_coalesce;
8654 int err, rem_rule, n_rules = 0, i, j;
8655 struct nlattr *rule;
8656 struct cfg80211_coalesce_rules *tmp_rule;
8657
8658 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8659 return -EOPNOTSUPP;
8660
8661 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8662 cfg80211_rdev_free_coalesce(rdev);
8663 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8664 return 0;
8665 }
8666
8667 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8668 rem_rule)
8669 n_rules++;
8670 if (n_rules > coalesce->n_rules)
8671 return -EINVAL;
8672
8673 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8674 GFP_KERNEL);
8675 if (!new_coalesce.rules)
8676 return -ENOMEM;
8677
8678 new_coalesce.n_rules = n_rules;
8679 i = 0;
8680
8681 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8682 rem_rule) {
8683 err = nl80211_parse_coalesce_rule(rdev, rule,
8684 &new_coalesce.rules[i]);
8685 if (err)
8686 goto error;
8687
8688 i++;
8689 }
8690
8691 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8692 if (err)
8693 goto error;
8694
8695 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8696 if (!n_coalesce) {
8697 err = -ENOMEM;
8698 goto error;
8699 }
8700 cfg80211_rdev_free_coalesce(rdev);
8701 rdev->coalesce = n_coalesce;
8702
8703 return 0;
8704error:
8705 for (i = 0; i < new_coalesce.n_rules; i++) {
8706 tmp_rule = &new_coalesce.rules[i];
8707 for (j = 0; j < tmp_rule->n_patterns; j++)
8708 kfree(tmp_rule->patterns[j].mask);
8709 kfree(tmp_rule->patterns);
8710 }
8711 kfree(new_coalesce.rules);
8712
8713 return err;
8714}
8715
Johannes Berge5497d72011-07-05 16:35:40 +02008716static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8717{
8718 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8719 struct net_device *dev = info->user_ptr[1];
8720 struct wireless_dev *wdev = dev->ieee80211_ptr;
8721 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8722 struct cfg80211_gtk_rekey_data rekey_data;
8723 int err;
8724
8725 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8726 return -EINVAL;
8727
8728 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8729 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8730 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8731 nl80211_rekey_policy);
8732 if (err)
8733 return err;
8734
8735 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8736 return -ERANGE;
8737 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8738 return -ERANGE;
8739 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8740 return -ERANGE;
8741
8742 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8743 NL80211_KEK_LEN);
8744 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8745 NL80211_KCK_LEN);
8746 memcpy(rekey_data.replay_ctr,
8747 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8748 NL80211_REPLAY_CTR_LEN);
8749
8750 wdev_lock(wdev);
8751 if (!wdev->current_bss) {
8752 err = -ENOTCONN;
8753 goto out;
8754 }
8755
8756 if (!rdev->ops->set_rekey_data) {
8757 err = -EOPNOTSUPP;
8758 goto out;
8759 }
8760
Hila Gonene35e4d22012-06-27 17:19:42 +03008761 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008762 out:
8763 wdev_unlock(wdev);
8764 return err;
8765}
8766
Johannes Berg28946da2011-11-04 11:18:12 +01008767static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8768 struct genl_info *info)
8769{
8770 struct net_device *dev = info->user_ptr[1];
8771 struct wireless_dev *wdev = dev->ieee80211_ptr;
8772
8773 if (wdev->iftype != NL80211_IFTYPE_AP &&
8774 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8775 return -EINVAL;
8776
Eric W. Biederman15e47302012-09-07 20:12:54 +00008777 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008778 return -EBUSY;
8779
Eric W. Biederman15e47302012-09-07 20:12:54 +00008780 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008781 return 0;
8782}
8783
Johannes Berg7f6cf312011-11-04 11:18:15 +01008784static int nl80211_probe_client(struct sk_buff *skb,
8785 struct genl_info *info)
8786{
8787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8788 struct net_device *dev = info->user_ptr[1];
8789 struct wireless_dev *wdev = dev->ieee80211_ptr;
8790 struct sk_buff *msg;
8791 void *hdr;
8792 const u8 *addr;
8793 u64 cookie;
8794 int err;
8795
8796 if (wdev->iftype != NL80211_IFTYPE_AP &&
8797 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8798 return -EOPNOTSUPP;
8799
8800 if (!info->attrs[NL80211_ATTR_MAC])
8801 return -EINVAL;
8802
8803 if (!rdev->ops->probe_client)
8804 return -EOPNOTSUPP;
8805
8806 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8807 if (!msg)
8808 return -ENOMEM;
8809
Eric W. Biederman15e47302012-09-07 20:12:54 +00008810 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008811 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008812 if (!hdr) {
8813 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008814 goto free_msg;
8815 }
8816
8817 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8818
Hila Gonene35e4d22012-06-27 17:19:42 +03008819 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008820 if (err)
8821 goto free_msg;
8822
David S. Miller9360ffd2012-03-29 04:41:26 -04008823 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8824 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008825
8826 genlmsg_end(msg, hdr);
8827
8828 return genlmsg_reply(msg, info);
8829
8830 nla_put_failure:
8831 err = -ENOBUFS;
8832 free_msg:
8833 nlmsg_free(msg);
8834 return err;
8835}
8836
Johannes Berg5e760232011-11-04 11:18:17 +01008837static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8838{
8839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008840 struct cfg80211_beacon_registration *reg, *nreg;
8841 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008842
8843 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8844 return -EOPNOTSUPP;
8845
Ben Greear37c73b52012-10-26 14:49:25 -07008846 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8847 if (!nreg)
8848 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008849
Ben Greear37c73b52012-10-26 14:49:25 -07008850 /* First, check if already registered. */
8851 spin_lock_bh(&rdev->beacon_registrations_lock);
8852 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8853 if (reg->nlportid == info->snd_portid) {
8854 rv = -EALREADY;
8855 goto out_err;
8856 }
8857 }
8858 /* Add it to the list */
8859 nreg->nlportid = info->snd_portid;
8860 list_add(&nreg->list, &rdev->beacon_registrations);
8861
8862 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008863
8864 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008865out_err:
8866 spin_unlock_bh(&rdev->beacon_registrations_lock);
8867 kfree(nreg);
8868 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008869}
8870
Johannes Berg98104fde2012-06-16 00:19:54 +02008871static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8872{
8873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8874 struct wireless_dev *wdev = info->user_ptr[1];
8875 int err;
8876
8877 if (!rdev->ops->start_p2p_device)
8878 return -EOPNOTSUPP;
8879
8880 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8881 return -EOPNOTSUPP;
8882
8883 if (wdev->p2p_started)
8884 return 0;
8885
Johannes Berg98104fde2012-06-16 00:19:54 +02008886 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008887 if (err)
8888 return err;
8889
Johannes Bergeeb126e2012-10-23 15:16:50 +02008890 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008891 if (err)
8892 return err;
8893
8894 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008895 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008896
8897 return 0;
8898}
8899
8900static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8901{
8902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8903 struct wireless_dev *wdev = info->user_ptr[1];
8904
8905 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8906 return -EOPNOTSUPP;
8907
8908 if (!rdev->ops->stop_p2p_device)
8909 return -EOPNOTSUPP;
8910
Johannes Bergf9f47522013-03-19 15:04:07 +01008911 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008912
8913 return 0;
8914}
8915
Johannes Berg3713b4e2013-02-14 16:19:38 +01008916static int nl80211_get_protocol_features(struct sk_buff *skb,
8917 struct genl_info *info)
8918{
8919 void *hdr;
8920 struct sk_buff *msg;
8921
8922 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8923 if (!msg)
8924 return -ENOMEM;
8925
8926 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8927 NL80211_CMD_GET_PROTOCOL_FEATURES);
8928 if (!hdr)
8929 goto nla_put_failure;
8930
8931 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8932 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8933 goto nla_put_failure;
8934
8935 genlmsg_end(msg, hdr);
8936 return genlmsg_reply(msg, info);
8937
8938 nla_put_failure:
8939 kfree_skb(msg);
8940 return -ENOBUFS;
8941}
8942
Jouni Malinen355199e2013-02-27 17:14:27 +02008943static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8944{
8945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8946 struct cfg80211_update_ft_ies_params ft_params;
8947 struct net_device *dev = info->user_ptr[1];
8948
8949 if (!rdev->ops->update_ft_ies)
8950 return -EOPNOTSUPP;
8951
8952 if (!info->attrs[NL80211_ATTR_MDID] ||
8953 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8954 return -EINVAL;
8955
8956 memset(&ft_params, 0, sizeof(ft_params));
8957 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8958 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8959 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8960
8961 return rdev_update_ft_ies(rdev, dev, &ft_params);
8962}
8963
Arend van Spriel5de17982013-04-18 15:49:00 +02008964static int nl80211_crit_protocol_start(struct sk_buff *skb,
8965 struct genl_info *info)
8966{
8967 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8968 struct wireless_dev *wdev = info->user_ptr[1];
8969 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8970 u16 duration;
8971 int ret;
8972
8973 if (!rdev->ops->crit_proto_start)
8974 return -EOPNOTSUPP;
8975
8976 if (WARN_ON(!rdev->ops->crit_proto_stop))
8977 return -EINVAL;
8978
8979 if (rdev->crit_proto_nlportid)
8980 return -EBUSY;
8981
8982 /* determine protocol if provided */
8983 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8984 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8985
8986 if (proto >= NUM_NL80211_CRIT_PROTO)
8987 return -EINVAL;
8988
8989 /* timeout must be provided */
8990 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8991 return -EINVAL;
8992
8993 duration =
8994 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8995
8996 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8997 return -ERANGE;
8998
8999 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9000 if (!ret)
9001 rdev->crit_proto_nlportid = info->snd_portid;
9002
9003 return ret;
9004}
9005
9006static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9007 struct genl_info *info)
9008{
9009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9010 struct wireless_dev *wdev = info->user_ptr[1];
9011
9012 if (!rdev->ops->crit_proto_stop)
9013 return -EOPNOTSUPP;
9014
9015 if (rdev->crit_proto_nlportid) {
9016 rdev->crit_proto_nlportid = 0;
9017 rdev_crit_proto_stop(rdev, wdev);
9018 }
9019 return 0;
9020}
9021
Johannes Bergad7e7182013-11-13 13:37:47 +01009022static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9023{
9024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9025 struct wireless_dev *wdev =
9026 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9027 int i, err;
9028 u32 vid, subcmd;
9029
9030 if (!rdev->wiphy.vendor_commands)
9031 return -EOPNOTSUPP;
9032
9033 if (IS_ERR(wdev)) {
9034 err = PTR_ERR(wdev);
9035 if (err != -EINVAL)
9036 return err;
9037 wdev = NULL;
9038 } else if (wdev->wiphy != &rdev->wiphy) {
9039 return -EINVAL;
9040 }
9041
9042 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9043 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9044 return -EINVAL;
9045
9046 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9047 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9048 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9049 const struct wiphy_vendor_command *vcmd;
9050 void *data = NULL;
9051 int len = 0;
9052
9053 vcmd = &rdev->wiphy.vendor_commands[i];
9054
9055 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9056 continue;
9057
9058 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9059 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9060 if (!wdev)
9061 return -EINVAL;
9062 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9063 !wdev->netdev)
9064 return -EINVAL;
9065
9066 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9067 if (wdev->netdev &&
9068 !netif_running(wdev->netdev))
9069 return -ENETDOWN;
9070 if (!wdev->netdev && !wdev->p2p_started)
9071 return -ENETDOWN;
9072 }
9073 } else {
9074 wdev = NULL;
9075 }
9076
9077 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9078 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9079 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9080 }
9081
9082 rdev->cur_cmd_info = info;
9083 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9084 data, len);
9085 rdev->cur_cmd_info = NULL;
9086 return err;
9087 }
9088
9089 return -EOPNOTSUPP;
9090}
9091
9092struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9093 enum nl80211_commands cmd,
9094 enum nl80211_attrs attr,
9095 int approxlen)
9096{
9097 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9098
9099 if (WARN_ON(!rdev->cur_cmd_info))
9100 return NULL;
9101
9102 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9103 rdev->cur_cmd_info->snd_portid,
9104 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009105 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009106}
9107EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9108
9109int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9110{
9111 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9112 void *hdr = ((void **)skb->cb)[1];
9113 struct nlattr *data = ((void **)skb->cb)[2];
9114
9115 if (WARN_ON(!rdev->cur_cmd_info)) {
9116 kfree_skb(skb);
9117 return -EINVAL;
9118 }
9119
9120 nla_nest_end(skb, data);
9121 genlmsg_end(skb, hdr);
9122 return genlmsg_reply(skb, rdev->cur_cmd_info);
9123}
9124EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9125
9126
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009127static int nl80211_set_qos_map(struct sk_buff *skb,
9128 struct genl_info *info)
9129{
9130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9131 struct cfg80211_qos_map *qos_map = NULL;
9132 struct net_device *dev = info->user_ptr[1];
9133 u8 *pos, len, num_des, des_len, des;
9134 int ret;
9135
9136 if (!rdev->ops->set_qos_map)
9137 return -EOPNOTSUPP;
9138
9139 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9140 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9141 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9142
9143 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9144 len > IEEE80211_QOS_MAP_LEN_MAX)
9145 return -EINVAL;
9146
9147 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9148 if (!qos_map)
9149 return -ENOMEM;
9150
9151 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9152 if (num_des) {
9153 des_len = num_des *
9154 sizeof(struct cfg80211_dscp_exception);
9155 memcpy(qos_map->dscp_exception, pos, des_len);
9156 qos_map->num_des = num_des;
9157 for (des = 0; des < num_des; des++) {
9158 if (qos_map->dscp_exception[des].up > 7) {
9159 kfree(qos_map);
9160 return -EINVAL;
9161 }
9162 }
9163 pos += des_len;
9164 }
9165 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9166 }
9167
9168 wdev_lock(dev->ieee80211_ptr);
9169 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9170 if (!ret)
9171 ret = rdev_set_qos_map(rdev, dev, qos_map);
9172 wdev_unlock(dev->ieee80211_ptr);
9173
9174 kfree(qos_map);
9175 return ret;
9176}
9177
Johannes Berg4c476992010-10-04 21:36:35 +02009178#define NL80211_FLAG_NEED_WIPHY 0x01
9179#define NL80211_FLAG_NEED_NETDEV 0x02
9180#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009181#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9182#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9183 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009184#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009185/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009186#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9187 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009188
Johannes Bergf84f7712013-11-14 17:14:45 +01009189static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009190 struct genl_info *info)
9191{
9192 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009193 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009194 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009195 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9196
9197 if (rtnl)
9198 rtnl_lock();
9199
9200 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009201 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009202 if (IS_ERR(rdev)) {
9203 if (rtnl)
9204 rtnl_unlock();
9205 return PTR_ERR(rdev);
9206 }
9207 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009208 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9209 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009210 ASSERT_RTNL();
9211
Johannes Berg89a54e42012-06-15 14:33:17 +02009212 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9213 info->attrs);
9214 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009215 if (rtnl)
9216 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009217 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009218 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009219
Johannes Berg89a54e42012-06-15 14:33:17 +02009220 dev = wdev->netdev;
9221 rdev = wiphy_to_dev(wdev->wiphy);
9222
Johannes Berg1bf614e2012-06-15 15:23:36 +02009223 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9224 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009225 if (rtnl)
9226 rtnl_unlock();
9227 return -EINVAL;
9228 }
9229
9230 info->user_ptr[1] = dev;
9231 } else {
9232 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009233 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009234
Johannes Berg1bf614e2012-06-15 15:23:36 +02009235 if (dev) {
9236 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9237 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009238 if (rtnl)
9239 rtnl_unlock();
9240 return -ENETDOWN;
9241 }
9242
9243 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009244 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9245 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009246 if (rtnl)
9247 rtnl_unlock();
9248 return -ENETDOWN;
9249 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009250 }
9251
Johannes Berg4c476992010-10-04 21:36:35 +02009252 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009253 }
9254
9255 return 0;
9256}
9257
Johannes Bergf84f7712013-11-14 17:14:45 +01009258static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009259 struct genl_info *info)
9260{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009261 if (info->user_ptr[1]) {
9262 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9263 struct wireless_dev *wdev = info->user_ptr[1];
9264
9265 if (wdev->netdev)
9266 dev_put(wdev->netdev);
9267 } else {
9268 dev_put(info->user_ptr[1]);
9269 }
9270 }
Johannes Berg4c476992010-10-04 21:36:35 +02009271 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9272 rtnl_unlock();
9273}
9274
Johannes Berg4534de82013-11-14 17:14:46 +01009275static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009276 {
9277 .cmd = NL80211_CMD_GET_WIPHY,
9278 .doit = nl80211_get_wiphy,
9279 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009280 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009281 .policy = nl80211_policy,
9282 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009283 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9284 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009285 },
9286 {
9287 .cmd = NL80211_CMD_SET_WIPHY,
9288 .doit = nl80211_set_wiphy,
9289 .policy = nl80211_policy,
9290 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009291 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009292 },
9293 {
9294 .cmd = NL80211_CMD_GET_INTERFACE,
9295 .doit = nl80211_get_interface,
9296 .dumpit = nl80211_dump_interface,
9297 .policy = nl80211_policy,
9298 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009299 .internal_flags = NL80211_FLAG_NEED_WDEV |
9300 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009301 },
9302 {
9303 .cmd = NL80211_CMD_SET_INTERFACE,
9304 .doit = nl80211_set_interface,
9305 .policy = nl80211_policy,
9306 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009307 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9308 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009309 },
9310 {
9311 .cmd = NL80211_CMD_NEW_INTERFACE,
9312 .doit = nl80211_new_interface,
9313 .policy = nl80211_policy,
9314 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009315 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9316 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009317 },
9318 {
9319 .cmd = NL80211_CMD_DEL_INTERFACE,
9320 .doit = nl80211_del_interface,
9321 .policy = nl80211_policy,
9322 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009323 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009324 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009325 },
Johannes Berg41ade002007-12-19 02:03:29 +01009326 {
9327 .cmd = NL80211_CMD_GET_KEY,
9328 .doit = nl80211_get_key,
9329 .policy = nl80211_policy,
9330 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009332 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009333 },
9334 {
9335 .cmd = NL80211_CMD_SET_KEY,
9336 .doit = nl80211_set_key,
9337 .policy = nl80211_policy,
9338 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009339 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009340 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009341 },
9342 {
9343 .cmd = NL80211_CMD_NEW_KEY,
9344 .doit = nl80211_new_key,
9345 .policy = nl80211_policy,
9346 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009347 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009348 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009349 },
9350 {
9351 .cmd = NL80211_CMD_DEL_KEY,
9352 .doit = nl80211_del_key,
9353 .policy = nl80211_policy,
9354 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009356 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009357 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009358 {
9359 .cmd = NL80211_CMD_SET_BEACON,
9360 .policy = nl80211_policy,
9361 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009362 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009364 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009365 },
9366 {
Johannes Berg88600202012-02-13 15:17:18 +01009367 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009368 .policy = nl80211_policy,
9369 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009370 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009372 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009373 },
9374 {
Johannes Berg88600202012-02-13 15:17:18 +01009375 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009376 .policy = nl80211_policy,
9377 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009378 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009379 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009380 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009381 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009382 {
9383 .cmd = NL80211_CMD_GET_STATION,
9384 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009385 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009386 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009387 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9388 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009389 },
9390 {
9391 .cmd = NL80211_CMD_SET_STATION,
9392 .doit = nl80211_set_station,
9393 .policy = nl80211_policy,
9394 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009396 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009397 },
9398 {
9399 .cmd = NL80211_CMD_NEW_STATION,
9400 .doit = nl80211_new_station,
9401 .policy = nl80211_policy,
9402 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009403 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009404 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009405 },
9406 {
9407 .cmd = NL80211_CMD_DEL_STATION,
9408 .doit = nl80211_del_station,
9409 .policy = nl80211_policy,
9410 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009412 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009413 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009414 {
9415 .cmd = NL80211_CMD_GET_MPATH,
9416 .doit = nl80211_get_mpath,
9417 .dumpit = nl80211_dump_mpath,
9418 .policy = nl80211_policy,
9419 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009420 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009421 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009422 },
9423 {
9424 .cmd = NL80211_CMD_SET_MPATH,
9425 .doit = nl80211_set_mpath,
9426 .policy = nl80211_policy,
9427 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009428 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009429 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009430 },
9431 {
9432 .cmd = NL80211_CMD_NEW_MPATH,
9433 .doit = nl80211_new_mpath,
9434 .policy = nl80211_policy,
9435 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009436 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009437 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009438 },
9439 {
9440 .cmd = NL80211_CMD_DEL_MPATH,
9441 .doit = nl80211_del_mpath,
9442 .policy = nl80211_policy,
9443 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009444 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009445 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009446 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009447 {
9448 .cmd = NL80211_CMD_SET_BSS,
9449 .doit = nl80211_set_bss,
9450 .policy = nl80211_policy,
9451 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009452 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009453 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009454 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009455 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009456 .cmd = NL80211_CMD_GET_REG,
9457 .doit = nl80211_get_reg,
9458 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009459 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009460 /* can be retrieved by unprivileged users */
9461 },
9462 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009463 .cmd = NL80211_CMD_SET_REG,
9464 .doit = nl80211_set_reg,
9465 .policy = nl80211_policy,
9466 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009467 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009468 },
9469 {
9470 .cmd = NL80211_CMD_REQ_SET_REG,
9471 .doit = nl80211_req_set_reg,
9472 .policy = nl80211_policy,
9473 .flags = GENL_ADMIN_PERM,
9474 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009475 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009476 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9477 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009478 .policy = nl80211_policy,
9479 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009480 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009481 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009482 },
9483 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009484 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9485 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009486 .policy = nl80211_policy,
9487 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009488 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009489 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009490 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009491 {
Johannes Berg2a519312009-02-10 21:25:55 +01009492 .cmd = NL80211_CMD_TRIGGER_SCAN,
9493 .doit = nl80211_trigger_scan,
9494 .policy = nl80211_policy,
9495 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009496 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009497 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009498 },
9499 {
9500 .cmd = NL80211_CMD_GET_SCAN,
9501 .policy = nl80211_policy,
9502 .dumpit = nl80211_dump_scan,
9503 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009504 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009505 .cmd = NL80211_CMD_START_SCHED_SCAN,
9506 .doit = nl80211_start_sched_scan,
9507 .policy = nl80211_policy,
9508 .flags = GENL_ADMIN_PERM,
9509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9510 NL80211_FLAG_NEED_RTNL,
9511 },
9512 {
9513 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9514 .doit = nl80211_stop_sched_scan,
9515 .policy = nl80211_policy,
9516 .flags = GENL_ADMIN_PERM,
9517 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9518 NL80211_FLAG_NEED_RTNL,
9519 },
9520 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009521 .cmd = NL80211_CMD_AUTHENTICATE,
9522 .doit = nl80211_authenticate,
9523 .policy = nl80211_policy,
9524 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009526 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009527 },
9528 {
9529 .cmd = NL80211_CMD_ASSOCIATE,
9530 .doit = nl80211_associate,
9531 .policy = nl80211_policy,
9532 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009533 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009534 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009535 },
9536 {
9537 .cmd = NL80211_CMD_DEAUTHENTICATE,
9538 .doit = nl80211_deauthenticate,
9539 .policy = nl80211_policy,
9540 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009542 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009543 },
9544 {
9545 .cmd = NL80211_CMD_DISASSOCIATE,
9546 .doit = nl80211_disassociate,
9547 .policy = nl80211_policy,
9548 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009549 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009550 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009551 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009552 {
9553 .cmd = NL80211_CMD_JOIN_IBSS,
9554 .doit = nl80211_join_ibss,
9555 .policy = nl80211_policy,
9556 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009557 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009558 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009559 },
9560 {
9561 .cmd = NL80211_CMD_LEAVE_IBSS,
9562 .doit = nl80211_leave_ibss,
9563 .policy = nl80211_policy,
9564 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009565 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009566 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009567 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009568#ifdef CONFIG_NL80211_TESTMODE
9569 {
9570 .cmd = NL80211_CMD_TESTMODE,
9571 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009572 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009573 .policy = nl80211_policy,
9574 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009575 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9576 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009577 },
9578#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009579 {
9580 .cmd = NL80211_CMD_CONNECT,
9581 .doit = nl80211_connect,
9582 .policy = nl80211_policy,
9583 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009584 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009585 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009586 },
9587 {
9588 .cmd = NL80211_CMD_DISCONNECT,
9589 .doit = nl80211_disconnect,
9590 .policy = nl80211_policy,
9591 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009592 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009593 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009594 },
Johannes Berg463d0182009-07-14 00:33:35 +02009595 {
9596 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9597 .doit = nl80211_wiphy_netns,
9598 .policy = nl80211_policy,
9599 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009600 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9601 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009602 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009603 {
9604 .cmd = NL80211_CMD_GET_SURVEY,
9605 .policy = nl80211_policy,
9606 .dumpit = nl80211_dump_survey,
9607 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009608 {
9609 .cmd = NL80211_CMD_SET_PMKSA,
9610 .doit = nl80211_setdel_pmksa,
9611 .policy = nl80211_policy,
9612 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009613 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009614 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009615 },
9616 {
9617 .cmd = NL80211_CMD_DEL_PMKSA,
9618 .doit = nl80211_setdel_pmksa,
9619 .policy = nl80211_policy,
9620 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009621 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009622 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009623 },
9624 {
9625 .cmd = NL80211_CMD_FLUSH_PMKSA,
9626 .doit = nl80211_flush_pmksa,
9627 .policy = nl80211_policy,
9628 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009629 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009630 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009631 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009632 {
9633 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9634 .doit = nl80211_remain_on_channel,
9635 .policy = nl80211_policy,
9636 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009637 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009638 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009639 },
9640 {
9641 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9642 .doit = nl80211_cancel_remain_on_channel,
9643 .policy = nl80211_policy,
9644 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009645 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009646 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009647 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009648 {
9649 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9650 .doit = nl80211_set_tx_bitrate_mask,
9651 .policy = nl80211_policy,
9652 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009653 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9654 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009655 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009656 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009657 .cmd = NL80211_CMD_REGISTER_FRAME,
9658 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009659 .policy = nl80211_policy,
9660 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009661 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009662 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009663 },
9664 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009665 .cmd = NL80211_CMD_FRAME,
9666 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009667 .policy = nl80211_policy,
9668 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009669 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009670 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009671 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009672 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009673 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9674 .doit = nl80211_tx_mgmt_cancel_wait,
9675 .policy = nl80211_policy,
9676 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009677 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009678 NL80211_FLAG_NEED_RTNL,
9679 },
9680 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009681 .cmd = NL80211_CMD_SET_POWER_SAVE,
9682 .doit = nl80211_set_power_save,
9683 .policy = nl80211_policy,
9684 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009685 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9686 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009687 },
9688 {
9689 .cmd = NL80211_CMD_GET_POWER_SAVE,
9690 .doit = nl80211_get_power_save,
9691 .policy = nl80211_policy,
9692 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009693 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9694 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009695 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009696 {
9697 .cmd = NL80211_CMD_SET_CQM,
9698 .doit = nl80211_set_cqm,
9699 .policy = nl80211_policy,
9700 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009701 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9702 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009703 },
Johannes Bergf444de02010-05-05 15:25:02 +02009704 {
9705 .cmd = NL80211_CMD_SET_CHANNEL,
9706 .doit = nl80211_set_channel,
9707 .policy = nl80211_policy,
9708 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009709 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9710 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009711 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009712 {
9713 .cmd = NL80211_CMD_SET_WDS_PEER,
9714 .doit = nl80211_set_wds_peer,
9715 .policy = nl80211_policy,
9716 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009717 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9718 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009719 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009720 {
9721 .cmd = NL80211_CMD_JOIN_MESH,
9722 .doit = nl80211_join_mesh,
9723 .policy = nl80211_policy,
9724 .flags = GENL_ADMIN_PERM,
9725 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9726 NL80211_FLAG_NEED_RTNL,
9727 },
9728 {
9729 .cmd = NL80211_CMD_LEAVE_MESH,
9730 .doit = nl80211_leave_mesh,
9731 .policy = nl80211_policy,
9732 .flags = GENL_ADMIN_PERM,
9733 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9734 NL80211_FLAG_NEED_RTNL,
9735 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009736#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009737 {
9738 .cmd = NL80211_CMD_GET_WOWLAN,
9739 .doit = nl80211_get_wowlan,
9740 .policy = nl80211_policy,
9741 /* can be retrieved by unprivileged users */
9742 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9743 NL80211_FLAG_NEED_RTNL,
9744 },
9745 {
9746 .cmd = NL80211_CMD_SET_WOWLAN,
9747 .doit = nl80211_set_wowlan,
9748 .policy = nl80211_policy,
9749 .flags = GENL_ADMIN_PERM,
9750 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9751 NL80211_FLAG_NEED_RTNL,
9752 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009753#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009754 {
9755 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9756 .doit = nl80211_set_rekey_data,
9757 .policy = nl80211_policy,
9758 .flags = GENL_ADMIN_PERM,
9759 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9760 NL80211_FLAG_NEED_RTNL,
9761 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009762 {
9763 .cmd = NL80211_CMD_TDLS_MGMT,
9764 .doit = nl80211_tdls_mgmt,
9765 .policy = nl80211_policy,
9766 .flags = GENL_ADMIN_PERM,
9767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9768 NL80211_FLAG_NEED_RTNL,
9769 },
9770 {
9771 .cmd = NL80211_CMD_TDLS_OPER,
9772 .doit = nl80211_tdls_oper,
9773 .policy = nl80211_policy,
9774 .flags = GENL_ADMIN_PERM,
9775 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9776 NL80211_FLAG_NEED_RTNL,
9777 },
Johannes Berg28946da2011-11-04 11:18:12 +01009778 {
9779 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9780 .doit = nl80211_register_unexpected_frame,
9781 .policy = nl80211_policy,
9782 .flags = GENL_ADMIN_PERM,
9783 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9784 NL80211_FLAG_NEED_RTNL,
9785 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009786 {
9787 .cmd = NL80211_CMD_PROBE_CLIENT,
9788 .doit = nl80211_probe_client,
9789 .policy = nl80211_policy,
9790 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009791 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009792 NL80211_FLAG_NEED_RTNL,
9793 },
Johannes Berg5e760232011-11-04 11:18:17 +01009794 {
9795 .cmd = NL80211_CMD_REGISTER_BEACONS,
9796 .doit = nl80211_register_beacons,
9797 .policy = nl80211_policy,
9798 .flags = GENL_ADMIN_PERM,
9799 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9800 NL80211_FLAG_NEED_RTNL,
9801 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009802 {
9803 .cmd = NL80211_CMD_SET_NOACK_MAP,
9804 .doit = nl80211_set_noack_map,
9805 .policy = nl80211_policy,
9806 .flags = GENL_ADMIN_PERM,
9807 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9808 NL80211_FLAG_NEED_RTNL,
9809 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009810 {
9811 .cmd = NL80211_CMD_START_P2P_DEVICE,
9812 .doit = nl80211_start_p2p_device,
9813 .policy = nl80211_policy,
9814 .flags = GENL_ADMIN_PERM,
9815 .internal_flags = NL80211_FLAG_NEED_WDEV |
9816 NL80211_FLAG_NEED_RTNL,
9817 },
9818 {
9819 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9820 .doit = nl80211_stop_p2p_device,
9821 .policy = nl80211_policy,
9822 .flags = GENL_ADMIN_PERM,
9823 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9824 NL80211_FLAG_NEED_RTNL,
9825 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009826 {
9827 .cmd = NL80211_CMD_SET_MCAST_RATE,
9828 .doit = nl80211_set_mcast_rate,
9829 .policy = nl80211_policy,
9830 .flags = GENL_ADMIN_PERM,
9831 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9832 NL80211_FLAG_NEED_RTNL,
9833 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309834 {
9835 .cmd = NL80211_CMD_SET_MAC_ACL,
9836 .doit = nl80211_set_mac_acl,
9837 .policy = nl80211_policy,
9838 .flags = GENL_ADMIN_PERM,
9839 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9840 NL80211_FLAG_NEED_RTNL,
9841 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009842 {
9843 .cmd = NL80211_CMD_RADAR_DETECT,
9844 .doit = nl80211_start_radar_detection,
9845 .policy = nl80211_policy,
9846 .flags = GENL_ADMIN_PERM,
9847 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9848 NL80211_FLAG_NEED_RTNL,
9849 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009850 {
9851 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9852 .doit = nl80211_get_protocol_features,
9853 .policy = nl80211_policy,
9854 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009855 {
9856 .cmd = NL80211_CMD_UPDATE_FT_IES,
9857 .doit = nl80211_update_ft_ies,
9858 .policy = nl80211_policy,
9859 .flags = GENL_ADMIN_PERM,
9860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9861 NL80211_FLAG_NEED_RTNL,
9862 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009863 {
9864 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9865 .doit = nl80211_crit_protocol_start,
9866 .policy = nl80211_policy,
9867 .flags = GENL_ADMIN_PERM,
9868 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9869 NL80211_FLAG_NEED_RTNL,
9870 },
9871 {
9872 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9873 .doit = nl80211_crit_protocol_stop,
9874 .policy = nl80211_policy,
9875 .flags = GENL_ADMIN_PERM,
9876 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9877 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009878 },
9879 {
9880 .cmd = NL80211_CMD_GET_COALESCE,
9881 .doit = nl80211_get_coalesce,
9882 .policy = nl80211_policy,
9883 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9884 NL80211_FLAG_NEED_RTNL,
9885 },
9886 {
9887 .cmd = NL80211_CMD_SET_COALESCE,
9888 .doit = nl80211_set_coalesce,
9889 .policy = nl80211_policy,
9890 .flags = GENL_ADMIN_PERM,
9891 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9892 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009893 },
9894 {
9895 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9896 .doit = nl80211_channel_switch,
9897 .policy = nl80211_policy,
9898 .flags = GENL_ADMIN_PERM,
9899 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9900 NL80211_FLAG_NEED_RTNL,
9901 },
Johannes Bergad7e7182013-11-13 13:37:47 +01009902 {
9903 .cmd = NL80211_CMD_VENDOR,
9904 .doit = nl80211_vendor_cmd,
9905 .policy = nl80211_policy,
9906 .flags = GENL_ADMIN_PERM,
9907 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9908 NL80211_FLAG_NEED_RTNL,
9909 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009910 {
9911 .cmd = NL80211_CMD_SET_QOS_MAP,
9912 .doit = nl80211_set_qos_map,
9913 .policy = nl80211_policy,
9914 .flags = GENL_ADMIN_PERM,
9915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9916 NL80211_FLAG_NEED_RTNL,
9917 },
Johannes Berg55682962007-09-20 13:09:35 -04009918};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009919
Johannes Berg55682962007-09-20 13:09:35 -04009920/* notification functions */
9921
9922void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9923{
9924 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009925 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009926
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009928 if (!msg)
9929 return;
9930
Johannes Berg86e8cf92013-06-19 10:57:22 +02009931 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009932 nlmsg_free(msg);
9933 return;
9934 }
9935
Johannes Berg68eb5502013-11-19 15:19:38 +01009936 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009937 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009938}
9939
Johannes Berg362a4152009-05-24 16:43:15 +02009940static int nl80211_add_scan_req(struct sk_buff *msg,
9941 struct cfg80211_registered_device *rdev)
9942{
9943 struct cfg80211_scan_request *req = rdev->scan_req;
9944 struct nlattr *nest;
9945 int i;
9946
9947 if (WARN_ON(!req))
9948 return 0;
9949
9950 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9951 if (!nest)
9952 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009953 for (i = 0; i < req->n_ssids; i++) {
9954 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9955 goto nla_put_failure;
9956 }
Johannes Berg362a4152009-05-24 16:43:15 +02009957 nla_nest_end(msg, nest);
9958
9959 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9960 if (!nest)
9961 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009962 for (i = 0; i < req->n_channels; i++) {
9963 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9964 goto nla_put_failure;
9965 }
Johannes Berg362a4152009-05-24 16:43:15 +02009966 nla_nest_end(msg, nest);
9967
David S. Miller9360ffd2012-03-29 04:41:26 -04009968 if (req->ie &&
9969 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9970 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009971
Johannes Bergae917c92013-10-25 11:05:22 +02009972 if (req->flags &&
9973 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
9974 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -07009975
Johannes Berg362a4152009-05-24 16:43:15 +02009976 return 0;
9977 nla_put_failure:
9978 return -ENOBUFS;
9979}
9980
Johannes Berga538e2d2009-06-16 19:56:42 +02009981static int nl80211_send_scan_msg(struct sk_buff *msg,
9982 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009983 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009984 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009985 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009986{
9987 void *hdr;
9988
Eric W. Biederman15e47302012-09-07 20:12:54 +00009989 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009990 if (!hdr)
9991 return -1;
9992
David S. Miller9360ffd2012-03-29 04:41:26 -04009993 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009994 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9995 wdev->netdev->ifindex)) ||
9996 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009997 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009998
Johannes Berg362a4152009-05-24 16:43:15 +02009999 /* ignore errors and send incomplete event anyway */
10000 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010001
10002 return genlmsg_end(msg, hdr);
10003
10004 nla_put_failure:
10005 genlmsg_cancel(msg, hdr);
10006 return -EMSGSIZE;
10007}
10008
Luciano Coelho807f8a82011-05-11 17:09:35 +030010009static int
10010nl80211_send_sched_scan_msg(struct sk_buff *msg,
10011 struct cfg80211_registered_device *rdev,
10012 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010013 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010014{
10015 void *hdr;
10016
Eric W. Biederman15e47302012-09-07 20:12:54 +000010017 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010018 if (!hdr)
10019 return -1;
10020
David S. Miller9360ffd2012-03-29 04:41:26 -040010021 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10022 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10023 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010024
10025 return genlmsg_end(msg, hdr);
10026
10027 nla_put_failure:
10028 genlmsg_cancel(msg, hdr);
10029 return -EMSGSIZE;
10030}
10031
Johannes Berga538e2d2009-06-16 19:56:42 +020010032void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010033 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010034{
10035 struct sk_buff *msg;
10036
Thomas Graf58050fc2012-06-28 03:57:45 +000010037 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010038 if (!msg)
10039 return;
10040
Johannes Bergfd014282012-06-18 19:17:03 +020010041 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010042 NL80211_CMD_TRIGGER_SCAN) < 0) {
10043 nlmsg_free(msg);
10044 return;
10045 }
10046
Johannes Berg68eb5502013-11-19 15:19:38 +010010047 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010048 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010049}
10050
Johannes Berg2a519312009-02-10 21:25:55 +010010051void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010052 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +010010053{
10054 struct sk_buff *msg;
10055
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010056 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010057 if (!msg)
10058 return;
10059
Johannes Bergfd014282012-06-18 19:17:03 +020010060 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010061 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010062 nlmsg_free(msg);
10063 return;
10064 }
10065
Johannes Berg68eb5502013-11-19 15:19:38 +010010066 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010067 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010068}
10069
10070void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010071 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +010010072{
10073 struct sk_buff *msg;
10074
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010075 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010076 if (!msg)
10077 return;
10078
Johannes Bergfd014282012-06-18 19:17:03 +020010079 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010080 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010081 nlmsg_free(msg);
10082 return;
10083 }
10084
Johannes Berg68eb5502013-11-19 15:19:38 +010010085 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010086 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010087}
10088
Luciano Coelho807f8a82011-05-11 17:09:35 +030010089void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10090 struct net_device *netdev)
10091{
10092 struct sk_buff *msg;
10093
10094 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10095 if (!msg)
10096 return;
10097
10098 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10099 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10100 nlmsg_free(msg);
10101 return;
10102 }
10103
Johannes Berg68eb5502013-11-19 15:19:38 +010010104 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010105 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010106}
10107
10108void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10109 struct net_device *netdev, u32 cmd)
10110{
10111 struct sk_buff *msg;
10112
Thomas Graf58050fc2012-06-28 03:57:45 +000010113 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010114 if (!msg)
10115 return;
10116
10117 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10118 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_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010124}
10125
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010126/*
10127 * This can happen on global regulatory changes or device specific settings
10128 * based on custom world regulatory domains.
10129 */
10130void nl80211_send_reg_change_event(struct regulatory_request *request)
10131{
10132 struct sk_buff *msg;
10133 void *hdr;
10134
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010136 if (!msg)
10137 return;
10138
10139 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10140 if (!hdr) {
10141 nlmsg_free(msg);
10142 return;
10143 }
10144
10145 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010146 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10147 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010148
David S. Miller9360ffd2012-03-29 04:41:26 -040010149 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10150 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10151 NL80211_REGDOM_TYPE_WORLD))
10152 goto nla_put_failure;
10153 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10154 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10155 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10156 goto nla_put_failure;
10157 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10158 request->intersect) {
10159 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10160 NL80211_REGDOM_TYPE_INTERSECTION))
10161 goto nla_put_failure;
10162 } else {
10163 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10164 NL80211_REGDOM_TYPE_COUNTRY) ||
10165 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10166 request->alpha2))
10167 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010168 }
10169
Johannes Bergf4173762012-12-03 18:23:37 +010010170 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010171 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10172 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010173
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010174 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010175
Johannes Bergbc43b282009-07-25 10:54:13 +020010176 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010177 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010178 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010179 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010180
10181 return;
10182
10183nla_put_failure:
10184 genlmsg_cancel(msg, hdr);
10185 nlmsg_free(msg);
10186}
10187
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010188static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10189 struct net_device *netdev,
10190 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010191 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010192{
10193 struct sk_buff *msg;
10194 void *hdr;
10195
Johannes Berge6d6e342009-07-01 21:26:47 +020010196 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010197 if (!msg)
10198 return;
10199
10200 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10201 if (!hdr) {
10202 nlmsg_free(msg);
10203 return;
10204 }
10205
David S. Miller9360ffd2012-03-29 04:41:26 -040010206 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10207 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10208 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10209 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010210
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010211 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010212
Johannes Berg68eb5502013-11-19 15:19:38 +010010213 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010214 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010215 return;
10216
10217 nla_put_failure:
10218 genlmsg_cancel(msg, hdr);
10219 nlmsg_free(msg);
10220}
10221
10222void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010223 struct net_device *netdev, const u8 *buf,
10224 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010225{
10226 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010227 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010228}
10229
10230void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10231 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010232 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010233{
Johannes Berge6d6e342009-07-01 21:26:47 +020010234 nl80211_send_mlme_event(rdev, netdev, buf, len,
10235 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010236}
10237
Jouni Malinen53b46b82009-03-27 20:53:56 +020010238void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010239 struct net_device *netdev, const u8 *buf,
10240 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010241{
10242 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010243 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010244}
10245
Jouni Malinen53b46b82009-03-27 20:53:56 +020010246void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10247 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010248 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010249{
10250 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010251 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010252}
10253
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010254void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10255 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010256{
Johannes Berg947add32013-02-22 22:05:20 +010010257 struct wireless_dev *wdev = dev->ieee80211_ptr;
10258 struct wiphy *wiphy = wdev->wiphy;
10259 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010260 const struct ieee80211_mgmt *mgmt = (void *)buf;
10261 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010262
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010263 if (WARN_ON(len < 2))
10264 return;
10265
10266 if (ieee80211_is_deauth(mgmt->frame_control))
10267 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10268 else
10269 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10270
10271 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10272 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010273}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010274EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010275
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010276static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10277 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010278 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010279{
10280 struct sk_buff *msg;
10281 void *hdr;
10282
Johannes Berge6d6e342009-07-01 21:26:47 +020010283 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010284 if (!msg)
10285 return;
10286
10287 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10288 if (!hdr) {
10289 nlmsg_free(msg);
10290 return;
10291 }
10292
David S. Miller9360ffd2012-03-29 04:41:26 -040010293 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10294 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10295 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10296 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10297 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010298
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010299 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010300
Johannes Berg68eb5502013-11-19 15:19:38 +010010301 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010302 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010303 return;
10304
10305 nla_put_failure:
10306 genlmsg_cancel(msg, hdr);
10307 nlmsg_free(msg);
10308}
10309
10310void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010311 struct net_device *netdev, const u8 *addr,
10312 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010313{
10314 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010315 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010316}
10317
10318void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010319 struct net_device *netdev, const u8 *addr,
10320 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010321{
Johannes Berge6d6e342009-07-01 21:26:47 +020010322 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10323 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010324}
10325
Samuel Ortizb23aa672009-07-01 21:26:54 +020010326void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10327 struct net_device *netdev, const u8 *bssid,
10328 const u8 *req_ie, size_t req_ie_len,
10329 const u8 *resp_ie, size_t resp_ie_len,
10330 u16 status, gfp_t gfp)
10331{
10332 struct sk_buff *msg;
10333 void *hdr;
10334
Thomas Graf58050fc2012-06-28 03:57:45 +000010335 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010336 if (!msg)
10337 return;
10338
10339 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10340 if (!hdr) {
10341 nlmsg_free(msg);
10342 return;
10343 }
10344
David S. Miller9360ffd2012-03-29 04:41:26 -040010345 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10346 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10347 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10348 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10349 (req_ie &&
10350 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10351 (resp_ie &&
10352 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10353 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010354
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010355 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010356
Johannes Berg68eb5502013-11-19 15:19:38 +010010357 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010358 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010359 return;
10360
10361 nla_put_failure:
10362 genlmsg_cancel(msg, hdr);
10363 nlmsg_free(msg);
10364
10365}
10366
10367void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10368 struct net_device *netdev, const u8 *bssid,
10369 const u8 *req_ie, size_t req_ie_len,
10370 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10371{
10372 struct sk_buff *msg;
10373 void *hdr;
10374
Thomas Graf58050fc2012-06-28 03:57:45 +000010375 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010376 if (!msg)
10377 return;
10378
10379 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10380 if (!hdr) {
10381 nlmsg_free(msg);
10382 return;
10383 }
10384
David S. Miller9360ffd2012-03-29 04:41:26 -040010385 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10386 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10387 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10388 (req_ie &&
10389 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10390 (resp_ie &&
10391 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10392 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010393
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010394 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010395
Johannes Berg68eb5502013-11-19 15:19:38 +010010396 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010397 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010398 return;
10399
10400 nla_put_failure:
10401 genlmsg_cancel(msg, hdr);
10402 nlmsg_free(msg);
10403
10404}
10405
10406void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10407 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010408 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010409{
10410 struct sk_buff *msg;
10411 void *hdr;
10412
Thomas Graf58050fc2012-06-28 03:57:45 +000010413 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010414 if (!msg)
10415 return;
10416
10417 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10418 if (!hdr) {
10419 nlmsg_free(msg);
10420 return;
10421 }
10422
David S. Miller9360ffd2012-03-29 04:41:26 -040010423 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10424 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10425 (from_ap && reason &&
10426 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10427 (from_ap &&
10428 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10429 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10430 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010431
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010432 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010433
Johannes Berg68eb5502013-11-19 15:19:38 +010010434 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010435 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010436 return;
10437
10438 nla_put_failure:
10439 genlmsg_cancel(msg, hdr);
10440 nlmsg_free(msg);
10441
10442}
10443
Johannes Berg04a773a2009-04-19 21:24:32 +020010444void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10445 struct net_device *netdev, const u8 *bssid,
10446 gfp_t gfp)
10447{
10448 struct sk_buff *msg;
10449 void *hdr;
10450
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010451 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010452 if (!msg)
10453 return;
10454
10455 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10456 if (!hdr) {
10457 nlmsg_free(msg);
10458 return;
10459 }
10460
David S. Miller9360ffd2012-03-29 04:41:26 -040010461 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10462 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10463 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10464 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010465
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010466 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010467
Johannes Berg68eb5502013-11-19 15:19:38 +010010468 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010469 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010470 return;
10471
10472 nla_put_failure:
10473 genlmsg_cancel(msg, hdr);
10474 nlmsg_free(msg);
10475}
10476
Johannes Berg947add32013-02-22 22:05:20 +010010477void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10478 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010479{
Johannes Berg947add32013-02-22 22:05:20 +010010480 struct wireless_dev *wdev = dev->ieee80211_ptr;
10481 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010482 struct sk_buff *msg;
10483 void *hdr;
10484
Johannes Berg947add32013-02-22 22:05:20 +010010485 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10486 return;
10487
10488 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10489
Javier Cardonac93b5e72011-04-07 15:08:34 -070010490 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10491 if (!msg)
10492 return;
10493
10494 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10495 if (!hdr) {
10496 nlmsg_free(msg);
10497 return;
10498 }
10499
David S. Miller9360ffd2012-03-29 04:41:26 -040010500 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010501 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10502 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010503 (ie_len && ie &&
10504 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10505 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010506
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010507 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010508
Johannes Berg68eb5502013-11-19 15:19:38 +010010509 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010510 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010511 return;
10512
10513 nla_put_failure:
10514 genlmsg_cancel(msg, hdr);
10515 nlmsg_free(msg);
10516}
Johannes Berg947add32013-02-22 22:05:20 +010010517EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010518
Jouni Malinena3b8b052009-03-27 21:59:49 +020010519void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10520 struct net_device *netdev, const u8 *addr,
10521 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010522 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010523{
10524 struct sk_buff *msg;
10525 void *hdr;
10526
Johannes Berge6d6e342009-07-01 21:26:47 +020010527 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010528 if (!msg)
10529 return;
10530
10531 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10532 if (!hdr) {
10533 nlmsg_free(msg);
10534 return;
10535 }
10536
David S. Miller9360ffd2012-03-29 04:41:26 -040010537 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10538 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10539 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10540 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10541 (key_id != -1 &&
10542 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10543 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10544 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010545
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010546 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010547
Johannes Berg68eb5502013-11-19 15:19:38 +010010548 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010549 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010550 return;
10551
10552 nla_put_failure:
10553 genlmsg_cancel(msg, hdr);
10554 nlmsg_free(msg);
10555}
10556
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010557void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10558 struct ieee80211_channel *channel_before,
10559 struct ieee80211_channel *channel_after)
10560{
10561 struct sk_buff *msg;
10562 void *hdr;
10563 struct nlattr *nl_freq;
10564
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010565 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010566 if (!msg)
10567 return;
10568
10569 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10570 if (!hdr) {
10571 nlmsg_free(msg);
10572 return;
10573 }
10574
10575 /*
10576 * Since we are applying the beacon hint to a wiphy we know its
10577 * wiphy_idx is valid
10578 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010579 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10580 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010581
10582 /* Before */
10583 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10584 if (!nl_freq)
10585 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010586 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010587 goto nla_put_failure;
10588 nla_nest_end(msg, nl_freq);
10589
10590 /* After */
10591 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10592 if (!nl_freq)
10593 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010594 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010595 goto nla_put_failure;
10596 nla_nest_end(msg, nl_freq);
10597
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010598 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010599
Johannes Berg463d0182009-07-14 00:33:35 +020010600 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010601 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010602 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010603 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010604
10605 return;
10606
10607nla_put_failure:
10608 genlmsg_cancel(msg, hdr);
10609 nlmsg_free(msg);
10610}
10611
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010612static void nl80211_send_remain_on_chan_event(
10613 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010614 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010615 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010616 unsigned int duration, gfp_t gfp)
10617{
10618 struct sk_buff *msg;
10619 void *hdr;
10620
10621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10622 if (!msg)
10623 return;
10624
10625 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10626 if (!hdr) {
10627 nlmsg_free(msg);
10628 return;
10629 }
10630
David S. Miller9360ffd2012-03-29 04:41:26 -040010631 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010632 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10633 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010634 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010635 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010636 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10637 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010638 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10639 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010640
David S. Miller9360ffd2012-03-29 04:41:26 -040010641 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10642 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10643 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010644
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010645 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010646
Johannes Berg68eb5502013-11-19 15:19:38 +010010647 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010648 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010649 return;
10650
10651 nla_put_failure:
10652 genlmsg_cancel(msg, hdr);
10653 nlmsg_free(msg);
10654}
10655
Johannes Berg947add32013-02-22 22:05:20 +010010656void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10657 struct ieee80211_channel *chan,
10658 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010659{
Johannes Berg947add32013-02-22 22:05:20 +010010660 struct wiphy *wiphy = wdev->wiphy;
10661 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10662
10663 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010664 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010665 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010666 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010667}
Johannes Berg947add32013-02-22 22:05:20 +010010668EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010669
Johannes Berg947add32013-02-22 22:05:20 +010010670void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10671 struct ieee80211_channel *chan,
10672 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010673{
Johannes Berg947add32013-02-22 22:05:20 +010010674 struct wiphy *wiphy = wdev->wiphy;
10675 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10676
10677 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010678 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010679 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010680}
Johannes Berg947add32013-02-22 22:05:20 +010010681EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010682
Johannes Berg947add32013-02-22 22:05:20 +010010683void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10684 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010685{
Johannes Berg947add32013-02-22 22:05:20 +010010686 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10687 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010688 struct sk_buff *msg;
10689
Johannes Berg947add32013-02-22 22:05:20 +010010690 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10691
Thomas Graf58050fc2012-06-28 03:57:45 +000010692 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010693 if (!msg)
10694 return;
10695
John W. Linville66266b32012-03-15 13:25:41 -040010696 if (nl80211_send_station(msg, 0, 0, 0,
10697 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010698 nlmsg_free(msg);
10699 return;
10700 }
10701
Johannes Berg68eb5502013-11-19 15:19:38 +010010702 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010703 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010704}
Johannes Berg947add32013-02-22 22:05:20 +010010705EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010706
Johannes Berg947add32013-02-22 22:05:20 +010010707void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010708{
Johannes Berg947add32013-02-22 22:05:20 +010010709 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10710 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010711 struct sk_buff *msg;
10712 void *hdr;
10713
Johannes Berg947add32013-02-22 22:05:20 +010010714 trace_cfg80211_del_sta(dev, mac_addr);
10715
Thomas Graf58050fc2012-06-28 03:57:45 +000010716 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010717 if (!msg)
10718 return;
10719
10720 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10721 if (!hdr) {
10722 nlmsg_free(msg);
10723 return;
10724 }
10725
David S. Miller9360ffd2012-03-29 04:41:26 -040010726 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10727 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10728 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010729
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010730 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010731
Johannes Berg68eb5502013-11-19 15:19:38 +010010732 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010733 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010734 return;
10735
10736 nla_put_failure:
10737 genlmsg_cancel(msg, hdr);
10738 nlmsg_free(msg);
10739}
Johannes Berg947add32013-02-22 22:05:20 +010010740EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010741
Johannes Berg947add32013-02-22 22:05:20 +010010742void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10743 enum nl80211_connect_failed_reason reason,
10744 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010745{
Johannes Berg947add32013-02-22 22:05:20 +010010746 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10747 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010748 struct sk_buff *msg;
10749 void *hdr;
10750
10751 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10752 if (!msg)
10753 return;
10754
10755 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10756 if (!hdr) {
10757 nlmsg_free(msg);
10758 return;
10759 }
10760
10761 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10762 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10763 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10764 goto nla_put_failure;
10765
10766 genlmsg_end(msg, hdr);
10767
Johannes Berg68eb5502013-11-19 15:19:38 +010010768 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010769 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010770 return;
10771
10772 nla_put_failure:
10773 genlmsg_cancel(msg, hdr);
10774 nlmsg_free(msg);
10775}
Johannes Berg947add32013-02-22 22:05:20 +010010776EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010777
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010778static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10779 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010780{
10781 struct wireless_dev *wdev = dev->ieee80211_ptr;
10782 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10783 struct sk_buff *msg;
10784 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010785 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010786
Eric W. Biederman15e47302012-09-07 20:12:54 +000010787 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010788 return false;
10789
10790 msg = nlmsg_new(100, gfp);
10791 if (!msg)
10792 return true;
10793
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010794 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010795 if (!hdr) {
10796 nlmsg_free(msg);
10797 return true;
10798 }
10799
David S. Miller9360ffd2012-03-29 04:41:26 -040010800 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10801 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10802 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10803 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010804
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010805 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010806 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010807 return true;
10808
10809 nla_put_failure:
10810 genlmsg_cancel(msg, hdr);
10811 nlmsg_free(msg);
10812 return true;
10813}
10814
Johannes Berg947add32013-02-22 22:05:20 +010010815bool cfg80211_rx_spurious_frame(struct net_device *dev,
10816 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010817{
Johannes Berg947add32013-02-22 22:05:20 +010010818 struct wireless_dev *wdev = dev->ieee80211_ptr;
10819 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010820
Johannes Berg947add32013-02-22 22:05:20 +010010821 trace_cfg80211_rx_spurious_frame(dev, addr);
10822
10823 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10824 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10825 trace_cfg80211_return_bool(false);
10826 return false;
10827 }
10828 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10829 addr, gfp);
10830 trace_cfg80211_return_bool(ret);
10831 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010832}
Johannes Berg947add32013-02-22 22:05:20 +010010833EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10834
10835bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10836 const u8 *addr, gfp_t gfp)
10837{
10838 struct wireless_dev *wdev = dev->ieee80211_ptr;
10839 bool ret;
10840
10841 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10842
10843 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10844 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10845 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10846 trace_cfg80211_return_bool(false);
10847 return false;
10848 }
10849 ret = __nl80211_unexpected_frame(dev,
10850 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10851 addr, gfp);
10852 trace_cfg80211_return_bool(ret);
10853 return ret;
10854}
10855EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010856
Johannes Berg2e161f72010-08-12 15:38:38 +020010857int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010858 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010859 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010860 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010861{
Johannes Berg71bbc992012-06-15 15:30:18 +020010862 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010863 struct sk_buff *msg;
10864 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010865
10866 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10867 if (!msg)
10868 return -ENOMEM;
10869
Johannes Berg2e161f72010-08-12 15:38:38 +020010870 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010871 if (!hdr) {
10872 nlmsg_free(msg);
10873 return -ENOMEM;
10874 }
10875
David S. Miller9360ffd2012-03-29 04:41:26 -040010876 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010877 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10878 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010879 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010880 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10881 (sig_dbm &&
10882 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010883 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10884 (flags &&
10885 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010886 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010887
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010888 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010889
Eric W. Biederman15e47302012-09-07 20:12:54 +000010890 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010891
10892 nla_put_failure:
10893 genlmsg_cancel(msg, hdr);
10894 nlmsg_free(msg);
10895 return -ENOBUFS;
10896}
10897
Johannes Berg947add32013-02-22 22:05:20 +010010898void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10899 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010900{
Johannes Berg947add32013-02-22 22:05:20 +010010901 struct wiphy *wiphy = wdev->wiphy;
10902 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010903 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010904 struct sk_buff *msg;
10905 void *hdr;
10906
Johannes Berg947add32013-02-22 22:05:20 +010010907 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10908
Jouni Malinen026331c2010-02-15 12:53:10 +020010909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10910 if (!msg)
10911 return;
10912
Johannes Berg2e161f72010-08-12 15:38:38 +020010913 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010914 if (!hdr) {
10915 nlmsg_free(msg);
10916 return;
10917 }
10918
David S. Miller9360ffd2012-03-29 04:41:26 -040010919 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010920 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10921 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010922 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010923 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10924 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10925 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10926 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010927
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010928 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010929
Johannes Berg68eb5502013-11-19 15:19:38 +010010930 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010931 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010932 return;
10933
10934 nla_put_failure:
10935 genlmsg_cancel(msg, hdr);
10936 nlmsg_free(msg);
10937}
Johannes Berg947add32013-02-22 22:05:20 +010010938EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010939
Johannes Berg947add32013-02-22 22:05:20 +010010940void cfg80211_cqm_rssi_notify(struct net_device *dev,
10941 enum nl80211_cqm_rssi_threshold_event rssi_event,
10942 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010943{
Johannes Berg947add32013-02-22 22:05:20 +010010944 struct wireless_dev *wdev = dev->ieee80211_ptr;
10945 struct wiphy *wiphy = wdev->wiphy;
10946 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010947 struct sk_buff *msg;
10948 struct nlattr *pinfoattr;
10949 void *hdr;
10950
Johannes Berg947add32013-02-22 22:05:20 +010010951 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10952
Thomas Graf58050fc2012-06-28 03:57:45 +000010953 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010954 if (!msg)
10955 return;
10956
10957 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10958 if (!hdr) {
10959 nlmsg_free(msg);
10960 return;
10961 }
10962
David S. Miller9360ffd2012-03-29 04:41:26 -040010963 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010964 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010965 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010966
10967 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10968 if (!pinfoattr)
10969 goto nla_put_failure;
10970
David S. Miller9360ffd2012-03-29 04:41:26 -040010971 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10972 rssi_event))
10973 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010974
10975 nla_nest_end(msg, pinfoattr);
10976
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010977 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010978
Johannes Berg68eb5502013-11-19 15:19:38 +010010979 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010980 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010981 return;
10982
10983 nla_put_failure:
10984 genlmsg_cancel(msg, hdr);
10985 nlmsg_free(msg);
10986}
Johannes Berg947add32013-02-22 22:05:20 +010010987EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010988
Johannes Berg947add32013-02-22 22:05:20 +010010989static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10990 struct net_device *netdev, const u8 *bssid,
10991 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010992{
10993 struct sk_buff *msg;
10994 struct nlattr *rekey_attr;
10995 void *hdr;
10996
Thomas Graf58050fc2012-06-28 03:57:45 +000010997 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010998 if (!msg)
10999 return;
11000
11001 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11002 if (!hdr) {
11003 nlmsg_free(msg);
11004 return;
11005 }
11006
David S. Miller9360ffd2012-03-29 04:41:26 -040011007 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11008 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11009 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11010 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011011
11012 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11013 if (!rekey_attr)
11014 goto nla_put_failure;
11015
David S. Miller9360ffd2012-03-29 04:41:26 -040011016 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11017 NL80211_REPLAY_CTR_LEN, replay_ctr))
11018 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011019
11020 nla_nest_end(msg, rekey_attr);
11021
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011022 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011023
Johannes Berg68eb5502013-11-19 15:19:38 +010011024 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011025 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011026 return;
11027
11028 nla_put_failure:
11029 genlmsg_cancel(msg, hdr);
11030 nlmsg_free(msg);
11031}
11032
Johannes Berg947add32013-02-22 22:05:20 +010011033void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11034 const u8 *replay_ctr, gfp_t gfp)
11035{
11036 struct wireless_dev *wdev = dev->ieee80211_ptr;
11037 struct wiphy *wiphy = wdev->wiphy;
11038 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11039
11040 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11041 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11042}
11043EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11044
11045static void
11046nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11047 struct net_device *netdev, int index,
11048 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011049{
11050 struct sk_buff *msg;
11051 struct nlattr *attr;
11052 void *hdr;
11053
Thomas Graf58050fc2012-06-28 03:57:45 +000011054 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011055 if (!msg)
11056 return;
11057
11058 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11059 if (!hdr) {
11060 nlmsg_free(msg);
11061 return;
11062 }
11063
David S. Miller9360ffd2012-03-29 04:41:26 -040011064 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11065 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11066 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011067
11068 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11069 if (!attr)
11070 goto nla_put_failure;
11071
David S. Miller9360ffd2012-03-29 04:41:26 -040011072 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11073 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11074 (preauth &&
11075 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11076 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011077
11078 nla_nest_end(msg, attr);
11079
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011080 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011081
Johannes Berg68eb5502013-11-19 15:19:38 +010011082 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011083 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011084 return;
11085
11086 nla_put_failure:
11087 genlmsg_cancel(msg, hdr);
11088 nlmsg_free(msg);
11089}
11090
Johannes Berg947add32013-02-22 22:05:20 +010011091void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11092 const u8 *bssid, bool preauth, gfp_t gfp)
11093{
11094 struct wireless_dev *wdev = dev->ieee80211_ptr;
11095 struct wiphy *wiphy = wdev->wiphy;
11096 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11097
11098 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11099 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11100}
11101EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11102
11103static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11104 struct net_device *netdev,
11105 struct cfg80211_chan_def *chandef,
11106 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011107{
11108 struct sk_buff *msg;
11109 void *hdr;
11110
Thomas Graf58050fc2012-06-28 03:57:45 +000011111 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011112 if (!msg)
11113 return;
11114
11115 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11116 if (!hdr) {
11117 nlmsg_free(msg);
11118 return;
11119 }
11120
Johannes Berg683b6d32012-11-08 21:25:48 +010011121 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11122 goto nla_put_failure;
11123
11124 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011125 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011126
11127 genlmsg_end(msg, hdr);
11128
Johannes Berg68eb5502013-11-19 15:19:38 +010011129 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011130 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011131 return;
11132
11133 nla_put_failure:
11134 genlmsg_cancel(msg, hdr);
11135 nlmsg_free(msg);
11136}
11137
Johannes Berg947add32013-02-22 22:05:20 +010011138void cfg80211_ch_switch_notify(struct net_device *dev,
11139 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011140{
Johannes Berg947add32013-02-22 22:05:20 +010011141 struct wireless_dev *wdev = dev->ieee80211_ptr;
11142 struct wiphy *wiphy = wdev->wiphy;
11143 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11144
Simon Wunderliche487eae2013-11-21 18:19:51 +010011145 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011146
Simon Wunderliche487eae2013-11-21 18:19:51 +010011147 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011148
11149 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011150 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011151 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11152 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011153 return;
Johannes Berg947add32013-02-22 22:05:20 +010011154
11155 wdev->channel = chandef->chan;
11156 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011157}
11158EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11159
11160void cfg80211_cqm_txe_notify(struct net_device *dev,
11161 const u8 *peer, u32 num_packets,
11162 u32 rate, u32 intvl, gfp_t gfp)
11163{
11164 struct wireless_dev *wdev = dev->ieee80211_ptr;
11165 struct wiphy *wiphy = wdev->wiphy;
11166 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011167 struct sk_buff *msg;
11168 struct nlattr *pinfoattr;
11169 void *hdr;
11170
11171 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11172 if (!msg)
11173 return;
11174
11175 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11176 if (!hdr) {
11177 nlmsg_free(msg);
11178 return;
11179 }
11180
11181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011182 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011183 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11184 goto nla_put_failure;
11185
11186 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11187 if (!pinfoattr)
11188 goto nla_put_failure;
11189
11190 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11191 goto nla_put_failure;
11192
11193 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11194 goto nla_put_failure;
11195
11196 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11197 goto nla_put_failure;
11198
11199 nla_nest_end(msg, pinfoattr);
11200
11201 genlmsg_end(msg, hdr);
11202
Johannes Berg68eb5502013-11-19 15:19:38 +010011203 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011204 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011205 return;
11206
11207 nla_put_failure:
11208 genlmsg_cancel(msg, hdr);
11209 nlmsg_free(msg);
11210}
Johannes Berg947add32013-02-22 22:05:20 +010011211EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011212
11213void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011214nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011215 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011216 enum nl80211_radar_event event,
11217 struct net_device *netdev, gfp_t gfp)
11218{
11219 struct sk_buff *msg;
11220 void *hdr;
11221
11222 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11223 if (!msg)
11224 return;
11225
11226 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11227 if (!hdr) {
11228 nlmsg_free(msg);
11229 return;
11230 }
11231
11232 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11233 goto nla_put_failure;
11234
11235 /* NOP and radar events don't need a netdev parameter */
11236 if (netdev) {
11237 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11238
11239 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11240 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11241 goto nla_put_failure;
11242 }
11243
11244 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11245 goto nla_put_failure;
11246
11247 if (nl80211_send_chandef(msg, chandef))
11248 goto nla_put_failure;
11249
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011250 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011251
Johannes Berg68eb5502013-11-19 15:19:38 +010011252 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011253 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011254 return;
11255
11256 nla_put_failure:
11257 genlmsg_cancel(msg, hdr);
11258 nlmsg_free(msg);
11259}
11260
Johannes Berg947add32013-02-22 22:05:20 +010011261void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11262 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011263{
Johannes Berg947add32013-02-22 22:05:20 +010011264 struct wireless_dev *wdev = dev->ieee80211_ptr;
11265 struct wiphy *wiphy = wdev->wiphy;
11266 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011267 struct sk_buff *msg;
11268 struct nlattr *pinfoattr;
11269 void *hdr;
11270
Johannes Berg947add32013-02-22 22:05:20 +010011271 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11272
Thomas Graf58050fc2012-06-28 03:57:45 +000011273 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011274 if (!msg)
11275 return;
11276
11277 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11278 if (!hdr) {
11279 nlmsg_free(msg);
11280 return;
11281 }
11282
David S. Miller9360ffd2012-03-29 04:41:26 -040011283 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011284 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011285 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11286 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011287
11288 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11289 if (!pinfoattr)
11290 goto nla_put_failure;
11291
David S. Miller9360ffd2012-03-29 04:41:26 -040011292 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11293 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011294
11295 nla_nest_end(msg, pinfoattr);
11296
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011297 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011298
Johannes Berg68eb5502013-11-19 15:19:38 +010011299 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011300 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011301 return;
11302
11303 nla_put_failure:
11304 genlmsg_cancel(msg, hdr);
11305 nlmsg_free(msg);
11306}
Johannes Berg947add32013-02-22 22:05:20 +010011307EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011308
Johannes Berg7f6cf312011-11-04 11:18:15 +010011309void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11310 u64 cookie, bool acked, gfp_t gfp)
11311{
11312 struct wireless_dev *wdev = dev->ieee80211_ptr;
11313 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11314 struct sk_buff *msg;
11315 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011316
Beni Lev4ee3e062012-08-27 12:49:39 +030011317 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11318
Thomas Graf58050fc2012-06-28 03:57:45 +000011319 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011320
Johannes Berg7f6cf312011-11-04 11:18:15 +010011321 if (!msg)
11322 return;
11323
11324 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11325 if (!hdr) {
11326 nlmsg_free(msg);
11327 return;
11328 }
11329
David S. Miller9360ffd2012-03-29 04:41:26 -040011330 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11331 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11332 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11333 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11334 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11335 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011336
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011337 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011338
Johannes Berg68eb5502013-11-19 15:19:38 +010011339 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011340 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011341 return;
11342
11343 nla_put_failure:
11344 genlmsg_cancel(msg, hdr);
11345 nlmsg_free(msg);
11346}
11347EXPORT_SYMBOL(cfg80211_probe_status);
11348
Johannes Berg5e760232011-11-04 11:18:17 +010011349void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11350 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011351 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011352{
11353 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11354 struct sk_buff *msg;
11355 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011356 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011357
Beni Lev4ee3e062012-08-27 12:49:39 +030011358 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11359
Ben Greear37c73b52012-10-26 14:49:25 -070011360 spin_lock_bh(&rdev->beacon_registrations_lock);
11361 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11362 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11363 if (!msg) {
11364 spin_unlock_bh(&rdev->beacon_registrations_lock);
11365 return;
11366 }
Johannes Berg5e760232011-11-04 11:18:17 +010011367
Ben Greear37c73b52012-10-26 14:49:25 -070011368 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11369 if (!hdr)
11370 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011371
Ben Greear37c73b52012-10-26 14:49:25 -070011372 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11373 (freq &&
11374 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11375 (sig_dbm &&
11376 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11377 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11378 goto nla_put_failure;
11379
11380 genlmsg_end(msg, hdr);
11381
11382 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011383 }
Ben Greear37c73b52012-10-26 14:49:25 -070011384 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011385 return;
11386
11387 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011388 spin_unlock_bh(&rdev->beacon_registrations_lock);
11389 if (hdr)
11390 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011391 nlmsg_free(msg);
11392}
11393EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11394
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011395#ifdef CONFIG_PM
11396void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11397 struct cfg80211_wowlan_wakeup *wakeup,
11398 gfp_t gfp)
11399{
11400 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11401 struct sk_buff *msg;
11402 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011403 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011404
11405 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11406
11407 if (wakeup)
11408 size += wakeup->packet_present_len;
11409
11410 msg = nlmsg_new(size, gfp);
11411 if (!msg)
11412 return;
11413
11414 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11415 if (!hdr)
11416 goto free_msg;
11417
11418 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11419 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11420 goto free_msg;
11421
11422 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11423 wdev->netdev->ifindex))
11424 goto free_msg;
11425
11426 if (wakeup) {
11427 struct nlattr *reasons;
11428
11429 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011430 if (!reasons)
11431 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011432
11433 if (wakeup->disconnect &&
11434 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11435 goto free_msg;
11436 if (wakeup->magic_pkt &&
11437 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11438 goto free_msg;
11439 if (wakeup->gtk_rekey_failure &&
11440 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11441 goto free_msg;
11442 if (wakeup->eap_identity_req &&
11443 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11444 goto free_msg;
11445 if (wakeup->four_way_handshake &&
11446 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11447 goto free_msg;
11448 if (wakeup->rfkill_release &&
11449 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11450 goto free_msg;
11451
11452 if (wakeup->pattern_idx >= 0 &&
11453 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11454 wakeup->pattern_idx))
11455 goto free_msg;
11456
Johannes Bergae917c92013-10-25 11:05:22 +020011457 if (wakeup->tcp_match &&
11458 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11459 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011460
Johannes Bergae917c92013-10-25 11:05:22 +020011461 if (wakeup->tcp_connlost &&
11462 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11463 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011464
Johannes Bergae917c92013-10-25 11:05:22 +020011465 if (wakeup->tcp_nomoretokens &&
11466 nla_put_flag(msg,
11467 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11468 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011469
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011470 if (wakeup->packet) {
11471 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11472 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11473
11474 if (!wakeup->packet_80211) {
11475 pkt_attr =
11476 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11477 len_attr =
11478 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11479 }
11480
11481 if (wakeup->packet_len &&
11482 nla_put_u32(msg, len_attr, wakeup->packet_len))
11483 goto free_msg;
11484
11485 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11486 wakeup->packet))
11487 goto free_msg;
11488 }
11489
11490 nla_nest_end(msg, reasons);
11491 }
11492
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011493 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011494
Johannes Berg68eb5502013-11-19 15:19:38 +010011495 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011496 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011497 return;
11498
11499 free_msg:
11500 nlmsg_free(msg);
11501}
11502EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11503#endif
11504
Jouni Malinen3475b092012-11-16 22:49:57 +020011505void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11506 enum nl80211_tdls_operation oper,
11507 u16 reason_code, gfp_t gfp)
11508{
11509 struct wireless_dev *wdev = dev->ieee80211_ptr;
11510 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11511 struct sk_buff *msg;
11512 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011513
11514 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11515 reason_code);
11516
11517 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11518 if (!msg)
11519 return;
11520
11521 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11522 if (!hdr) {
11523 nlmsg_free(msg);
11524 return;
11525 }
11526
11527 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11528 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11529 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11530 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11531 (reason_code > 0 &&
11532 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11533 goto nla_put_failure;
11534
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011535 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011536
Johannes Berg68eb5502013-11-19 15:19:38 +010011537 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011538 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011539 return;
11540
11541 nla_put_failure:
11542 genlmsg_cancel(msg, hdr);
11543 nlmsg_free(msg);
11544}
11545EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11546
Jouni Malinen026331c2010-02-15 12:53:10 +020011547static int nl80211_netlink_notify(struct notifier_block * nb,
11548 unsigned long state,
11549 void *_notify)
11550{
11551 struct netlink_notify *notify = _notify;
11552 struct cfg80211_registered_device *rdev;
11553 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011554 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011555
11556 if (state != NETLINK_URELEASE)
11557 return NOTIFY_DONE;
11558
11559 rcu_read_lock();
11560
Johannes Berg5e760232011-11-04 11:18:17 +010011561 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011562 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011563 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011564
11565 spin_lock_bh(&rdev->beacon_registrations_lock);
11566 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11567 list) {
11568 if (reg->nlportid == notify->portid) {
11569 list_del(&reg->list);
11570 kfree(reg);
11571 break;
11572 }
11573 }
11574 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011575 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011576
11577 rcu_read_unlock();
11578
11579 return NOTIFY_DONE;
11580}
11581
11582static struct notifier_block nl80211_netlink_notifier = {
11583 .notifier_call = nl80211_netlink_notify,
11584};
11585
Jouni Malinen355199e2013-02-27 17:14:27 +020011586void cfg80211_ft_event(struct net_device *netdev,
11587 struct cfg80211_ft_event_params *ft_event)
11588{
11589 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11590 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11591 struct sk_buff *msg;
11592 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011593
11594 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11595
11596 if (!ft_event->target_ap)
11597 return;
11598
11599 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11600 if (!msg)
11601 return;
11602
11603 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011604 if (!hdr)
11605 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011606
Johannes Bergae917c92013-10-25 11:05:22 +020011607 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11608 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11609 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11610 goto out;
11611
11612 if (ft_event->ies &&
11613 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11614 goto out;
11615 if (ft_event->ric_ies &&
11616 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11617 ft_event->ric_ies))
11618 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011619
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011620 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011621
Johannes Berg68eb5502013-11-19 15:19:38 +010011622 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011623 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011624 return;
11625 out:
11626 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011627}
11628EXPORT_SYMBOL(cfg80211_ft_event);
11629
Arend van Spriel5de17982013-04-18 15:49:00 +020011630void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11631{
11632 struct cfg80211_registered_device *rdev;
11633 struct sk_buff *msg;
11634 void *hdr;
11635 u32 nlportid;
11636
11637 rdev = wiphy_to_dev(wdev->wiphy);
11638 if (!rdev->crit_proto_nlportid)
11639 return;
11640
11641 nlportid = rdev->crit_proto_nlportid;
11642 rdev->crit_proto_nlportid = 0;
11643
11644 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11645 if (!msg)
11646 return;
11647
11648 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11649 if (!hdr)
11650 goto nla_put_failure;
11651
11652 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11653 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11654 goto nla_put_failure;
11655
11656 genlmsg_end(msg, hdr);
11657
11658 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11659 return;
11660
11661 nla_put_failure:
11662 if (hdr)
11663 genlmsg_cancel(msg, hdr);
11664 nlmsg_free(msg);
11665
11666}
11667EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11668
Johannes Berg55682962007-09-20 13:09:35 -040011669/* initialisation/exit functions */
11670
11671int nl80211_init(void)
11672{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011673 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011674
Johannes Berg2a94fe42013-11-19 15:19:39 +010011675 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11676 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011677 if (err)
11678 return err;
11679
Jouni Malinen026331c2010-02-15 12:53:10 +020011680 err = netlink_register_notifier(&nl80211_netlink_notifier);
11681 if (err)
11682 goto err_out;
11683
Johannes Berg55682962007-09-20 13:09:35 -040011684 return 0;
11685 err_out:
11686 genl_unregister_family(&nl80211_fam);
11687 return err;
11688}
11689
11690void nl80211_exit(void)
11691{
Jouni Malinen026331c2010-02-15 12:53:10 +020011692 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011693 genl_unregister_family(&nl80211_fam);
11694}