blob: d0afd82ebd776276795b8657bb4fc78286a7d458 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Bergf84f7712013-11-14 17:14:45 +010033static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020034 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010035static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg2a94fe42013-11-19 15:19:39 +010050/* multicast groups */
51enum nl80211_multicast_groups {
52 NL80211_MCGRP_CONFIG,
53 NL80211_MCGRP_SCAN,
54 NL80211_MCGRP_REGULATORY,
55 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010056 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010057 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
58};
59
60static const struct genl_multicast_group nl80211_mcgrps[] = {
61 [NL80211_MCGRP_CONFIG] = { .name = "config", },
62 [NL80211_MCGRP_SCAN] = { .name = "scan", },
63 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
64 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010065 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010066#ifdef CONFIG_NL80211_TESTMODE
67 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
68#endif
69};
70
Johannes Berg89a54e42012-06-15 14:33:17 +020071/* returns ERR_PTR values */
72static struct wireless_dev *
73__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040074{
Johannes Berg89a54e42012-06-15 14:33:17 +020075 struct cfg80211_registered_device *rdev;
76 struct wireless_dev *result = NULL;
77 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
78 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
79 u64 wdev_id;
80 int wiphy_idx = -1;
81 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040082
Johannes Berg5fe231e2013-05-08 21:45:15 +020083 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg89a54e42012-06-15 14:33:17 +020085 if (!have_ifidx && !have_wdev_id)
86 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040087
Johannes Berg89a54e42012-06-15 14:33:17 +020088 if (have_ifidx)
89 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
90 if (have_wdev_id) {
91 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
92 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040093 }
94
Johannes Berg89a54e42012-06-15 14:33:17 +020095 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
96 struct wireless_dev *wdev;
97
98 if (wiphy_net(&rdev->wiphy) != netns)
99 continue;
100
101 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
102 continue;
103
Johannes Berg89a54e42012-06-15 14:33:17 +0200104 list_for_each_entry(wdev, &rdev->wdev_list, list) {
105 if (have_ifidx && wdev->netdev &&
106 wdev->netdev->ifindex == ifidx) {
107 result = wdev;
108 break;
109 }
110 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
111 result = wdev;
112 break;
113 }
114 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200115
116 if (result)
117 break;
118 }
119
120 if (result)
121 return result;
122 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400123}
124
Johannes Berga9455402012-06-15 13:32:49 +0200125static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200126__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200127{
Johannes Berg7fee47782012-06-15 14:09:58 +0200128 struct cfg80211_registered_device *rdev = NULL, *tmp;
129 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200130
Johannes Berg5fe231e2013-05-08 21:45:15 +0200131 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg878d9ec2012-06-15 14:18:32 +0200133 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200134 !attrs[NL80211_ATTR_IFINDEX] &&
135 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200136 return ERR_PTR(-EINVAL);
137
Johannes Berg878d9ec2012-06-15 14:18:32 +0200138 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200139 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200141
Johannes Berg89a54e42012-06-15 14:33:17 +0200142 if (attrs[NL80211_ATTR_WDEV]) {
143 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
144 struct wireless_dev *wdev;
145 bool found = false;
146
147 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
148 if (tmp) {
149 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200150 list_for_each_entry(wdev, &tmp->wdev_list, list) {
151 if (wdev->identifier != (u32)wdev_id)
152 continue;
153 found = true;
154 break;
155 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200156
157 if (!found)
158 tmp = NULL;
159
160 if (rdev && tmp != rdev)
161 return ERR_PTR(-EINVAL);
162 rdev = tmp;
163 }
164 }
165
Johannes Berg878d9ec2012-06-15 14:18:32 +0200166 if (attrs[NL80211_ATTR_IFINDEX]) {
167 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200168 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-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 Malinendc6382ce2009-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 Berg2e161f782010-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Berg2e161f782010-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 Berg2e161f782010-08-12 15:38:38 +02001472 goto nla_put_failure;
Johannes Berg2e161f782010-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 Berg2e161f782010-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 Berg2e161f782010-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 Karwarbe29b99a2013-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 {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005288 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005289 }
5290
5291 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5292 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5293 n_ssids++;
5294
Johannes Bergf9f47522013-03-19 15:04:07 +01005295 if (n_ssids > wiphy->max_scan_ssids) {
5296 err = -EINVAL;
5297 goto unlock;
5298 }
Johannes Berg2a519312009-02-10 21:25:55 +01005299
Jouni Malinen70692ad2009-02-16 19:39:13 +02005300 if (info->attrs[NL80211_ATTR_IE])
5301 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5302 else
5303 ie_len = 0;
5304
Johannes Bergf9f47522013-03-19 15:04:07 +01005305 if (ie_len > wiphy->max_scan_ie_len) {
5306 err = -EINVAL;
5307 goto unlock;
5308 }
Johannes Berg18a83652009-03-31 12:12:05 +02005309
Johannes Berg2a519312009-02-10 21:25:55 +01005310 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005311 + sizeof(*request->ssids) * n_ssids
5312 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005313 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005314 if (!request) {
5315 err = -ENOMEM;
5316 goto unlock;
5317 }
Johannes Berg2a519312009-02-10 21:25:55 +01005318
Johannes Berg2a519312009-02-10 21:25:55 +01005319 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005320 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005321 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005322 if (ie_len) {
5323 if (request->ssids)
5324 request->ie = (void *)(request->ssids + n_ssids);
5325 else
5326 request->ie = (void *)(request->channels + n_channels);
5327 }
Johannes Berg2a519312009-02-10 21:25:55 +01005328
Johannes Berg584991d2009-11-02 13:32:03 +01005329 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005330 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5331 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005332 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005333 struct ieee80211_channel *chan;
5334
5335 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5336
5337 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005338 err = -EINVAL;
5339 goto out_free;
5340 }
Johannes Berg584991d2009-11-02 13:32:03 +01005341
5342 /* ignore disabled channels */
5343 if (chan->flags & IEEE80211_CHAN_DISABLED)
5344 continue;
5345
5346 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005347 i++;
5348 }
5349 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005350 enum ieee80211_band band;
5351
Johannes Berg2a519312009-02-10 21:25:55 +01005352 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005353 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5354 int j;
5355 if (!wiphy->bands[band])
5356 continue;
5357 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005358 struct ieee80211_channel *chan;
5359
5360 chan = &wiphy->bands[band]->channels[j];
5361
5362 if (chan->flags & IEEE80211_CHAN_DISABLED)
5363 continue;
5364
5365 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005366 i++;
5367 }
5368 }
5369 }
5370
Johannes Berg584991d2009-11-02 13:32:03 +01005371 if (!i) {
5372 err = -EINVAL;
5373 goto out_free;
5374 }
5375
5376 request->n_channels = i;
5377
Johannes Berg2a519312009-02-10 21:25:55 +01005378 i = 0;
5379 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5380 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005381 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005382 err = -EINVAL;
5383 goto out_free;
5384 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005385 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005386 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005387 i++;
5388 }
5389 }
5390
Jouni Malinen70692ad2009-02-16 19:39:13 +02005391 if (info->attrs[NL80211_ATTR_IE]) {
5392 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02005393 memcpy((void *)request->ie,
5394 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005395 request->ie_len);
5396 }
5397
Johannes Berg34850ab2011-07-18 18:08:35 +02005398 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005399 if (wiphy->bands[i])
5400 request->rates[i] =
5401 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005402
5403 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5404 nla_for_each_nested(attr,
5405 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5406 tmp) {
5407 enum ieee80211_band band = nla_type(attr);
5408
Dan Carpenter84404622011-07-29 11:52:18 +03005409 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005410 err = -EINVAL;
5411 goto out_free;
5412 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005413
5414 if (!wiphy->bands[band])
5415 continue;
5416
Johannes Berg34850ab2011-07-18 18:08:35 +02005417 err = ieee80211_get_ratemask(wiphy->bands[band],
5418 nla_data(attr),
5419 nla_len(attr),
5420 &request->rates[band]);
5421 if (err)
5422 goto out_free;
5423 }
5424 }
5425
Sam Leffler46856bb2012-10-11 21:03:32 -07005426 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005427 request->flags = nla_get_u32(
5428 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005429 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5430 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005431 err = -EOPNOTSUPP;
5432 goto out_free;
5433 }
5434 }
Sam Lefflered4737712012-10-11 21:03:31 -07005435
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305436 request->no_cck =
5437 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5438
Johannes Bergfd014282012-06-18 19:17:03 +02005439 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005440 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005441 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005442
Johannes Berg79c97e92009-07-07 03:56:12 +02005443 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005444 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005445
Johannes Berg463d0182009-07-14 00:33:35 +02005446 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005447 nl80211_send_scan_start(rdev, wdev);
5448 if (wdev->netdev)
5449 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005450 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005451 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005452 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005453 kfree(request);
5454 }
Johannes Berg3b858752009-03-12 09:55:09 +01005455
Johannes Bergf9f47522013-03-19 15:04:07 +01005456 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005457 return err;
5458}
5459
Luciano Coelho807f8a82011-05-11 17:09:35 +03005460static int nl80211_start_sched_scan(struct sk_buff *skb,
5461 struct genl_info *info)
5462{
5463 struct cfg80211_sched_scan_request *request;
5464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5465 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005466 struct nlattr *attr;
5467 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005468 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005469 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005470 enum ieee80211_band band;
5471 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005472 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005473
5474 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5475 !rdev->ops->sched_scan_start)
5476 return -EOPNOTSUPP;
5477
5478 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5479 return -EINVAL;
5480
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005481 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5482 return -EINVAL;
5483
5484 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5485 if (interval == 0)
5486 return -EINVAL;
5487
Luciano Coelho807f8a82011-05-11 17:09:35 +03005488 wiphy = &rdev->wiphy;
5489
5490 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5491 n_channels = validate_scan_freqs(
5492 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5493 if (!n_channels)
5494 return -EINVAL;
5495 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005496 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005497 }
5498
5499 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5500 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5501 tmp)
5502 n_ssids++;
5503
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005504 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005505 return -EINVAL;
5506
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005507 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5508 nla_for_each_nested(attr,
5509 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5510 tmp)
5511 n_match_sets++;
5512
5513 if (n_match_sets > wiphy->max_match_sets)
5514 return -EINVAL;
5515
Luciano Coelho807f8a82011-05-11 17:09:35 +03005516 if (info->attrs[NL80211_ATTR_IE])
5517 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5518 else
5519 ie_len = 0;
5520
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005521 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005522 return -EINVAL;
5523
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005524 if (rdev->sched_scan_req) {
5525 err = -EINPROGRESS;
5526 goto out;
5527 }
5528
Luciano Coelho807f8a82011-05-11 17:09:35 +03005529 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005530 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005531 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005532 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005533 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005534 if (!request) {
5535 err = -ENOMEM;
5536 goto out;
5537 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005538
5539 if (n_ssids)
5540 request->ssids = (void *)&request->channels[n_channels];
5541 request->n_ssids = n_ssids;
5542 if (ie_len) {
5543 if (request->ssids)
5544 request->ie = (void *)(request->ssids + n_ssids);
5545 else
5546 request->ie = (void *)(request->channels + n_channels);
5547 }
5548
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005549 if (n_match_sets) {
5550 if (request->ie)
5551 request->match_sets = (void *)(request->ie + ie_len);
5552 else if (request->ssids)
5553 request->match_sets =
5554 (void *)(request->ssids + n_ssids);
5555 else
5556 request->match_sets =
5557 (void *)(request->channels + n_channels);
5558 }
5559 request->n_match_sets = n_match_sets;
5560
Luciano Coelho807f8a82011-05-11 17:09:35 +03005561 i = 0;
5562 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5563 /* user specified, bail out if channel not found */
5564 nla_for_each_nested(attr,
5565 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5566 tmp) {
5567 struct ieee80211_channel *chan;
5568
5569 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5570
5571 if (!chan) {
5572 err = -EINVAL;
5573 goto out_free;
5574 }
5575
5576 /* ignore disabled channels */
5577 if (chan->flags & IEEE80211_CHAN_DISABLED)
5578 continue;
5579
5580 request->channels[i] = chan;
5581 i++;
5582 }
5583 } else {
5584 /* all channels */
5585 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5586 int j;
5587 if (!wiphy->bands[band])
5588 continue;
5589 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5590 struct ieee80211_channel *chan;
5591
5592 chan = &wiphy->bands[band]->channels[j];
5593
5594 if (chan->flags & IEEE80211_CHAN_DISABLED)
5595 continue;
5596
5597 request->channels[i] = chan;
5598 i++;
5599 }
5600 }
5601 }
5602
5603 if (!i) {
5604 err = -EINVAL;
5605 goto out_free;
5606 }
5607
5608 request->n_channels = i;
5609
5610 i = 0;
5611 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5612 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5613 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005614 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005615 err = -EINVAL;
5616 goto out_free;
5617 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005618 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005619 memcpy(request->ssids[i].ssid, nla_data(attr),
5620 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005621 i++;
5622 }
5623 }
5624
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005625 i = 0;
5626 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5627 nla_for_each_nested(attr,
5628 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5629 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005630 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005631
5632 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5633 nla_data(attr), nla_len(attr),
5634 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005635 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005636 if (ssid) {
5637 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5638 err = -EINVAL;
5639 goto out_free;
5640 }
5641 memcpy(request->match_sets[i].ssid.ssid,
5642 nla_data(ssid), nla_len(ssid));
5643 request->match_sets[i].ssid.ssid_len =
5644 nla_len(ssid);
5645 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005646 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5647 if (rssi)
5648 request->rssi_thold = nla_get_u32(rssi);
5649 else
5650 request->rssi_thold =
5651 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005652 i++;
5653 }
5654 }
5655
Luciano Coelho807f8a82011-05-11 17:09:35 +03005656 if (info->attrs[NL80211_ATTR_IE]) {
5657 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5658 memcpy((void *)request->ie,
5659 nla_data(info->attrs[NL80211_ATTR_IE]),
5660 request->ie_len);
5661 }
5662
Sam Leffler46856bb2012-10-11 21:03:32 -07005663 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005664 request->flags = nla_get_u32(
5665 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005666 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5667 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005668 err = -EOPNOTSUPP;
5669 goto out_free;
5670 }
5671 }
Sam Lefflered4737712012-10-11 21:03:31 -07005672
Luciano Coelho807f8a82011-05-11 17:09:35 +03005673 request->dev = dev;
5674 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005675 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005676 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005677
Hila Gonene35e4d22012-06-27 17:19:42 +03005678 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005679 if (!err) {
5680 rdev->sched_scan_req = request;
5681 nl80211_send_sched_scan(rdev, dev,
5682 NL80211_CMD_START_SCHED_SCAN);
5683 goto out;
5684 }
5685
5686out_free:
5687 kfree(request);
5688out:
5689 return err;
5690}
5691
5692static int nl80211_stop_sched_scan(struct sk_buff *skb,
5693 struct genl_info *info)
5694{
5695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5696
5697 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5698 !rdev->ops->sched_scan_stop)
5699 return -EOPNOTSUPP;
5700
Johannes Berg5fe231e2013-05-08 21:45:15 +02005701 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005702}
5703
Simon Wunderlich04f39042013-02-08 18:16:19 +01005704static int nl80211_start_radar_detection(struct sk_buff *skb,
5705 struct genl_info *info)
5706{
5707 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5708 struct net_device *dev = info->user_ptr[1];
5709 struct wireless_dev *wdev = dev->ieee80211_ptr;
5710 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005711 enum nl80211_dfs_regions dfs_region;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005712 int err;
5713
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005714 dfs_region = reg_get_dfs_region(wdev->wiphy);
5715 if (dfs_region == NL80211_DFS_UNSET)
5716 return -EINVAL;
5717
Simon Wunderlich04f39042013-02-08 18:16:19 +01005718 err = nl80211_parse_chandef(rdev, info, &chandef);
5719 if (err)
5720 return err;
5721
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005722 if (netif_carrier_ok(dev))
5723 return -EBUSY;
5724
Simon Wunderlich04f39042013-02-08 18:16:19 +01005725 if (wdev->cac_started)
5726 return -EBUSY;
5727
5728 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5729 if (err < 0)
5730 return err;
5731
5732 if (err == 0)
5733 return -EINVAL;
5734
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005735 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005736 return -EINVAL;
5737
5738 if (!rdev->ops->start_radar_detection)
5739 return -EOPNOTSUPP;
5740
Simon Wunderlich04f39042013-02-08 18:16:19 +01005741 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5742 chandef.chan, CHAN_MODE_SHARED,
5743 BIT(chandef.width));
5744 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005745 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005746
5747 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5748 if (!err) {
5749 wdev->channel = chandef.chan;
5750 wdev->cac_started = true;
5751 wdev->cac_start_time = jiffies;
5752 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005753 return err;
5754}
5755
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005756static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5757{
5758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5759 struct net_device *dev = info->user_ptr[1];
5760 struct wireless_dev *wdev = dev->ieee80211_ptr;
5761 struct cfg80211_csa_settings params;
5762 /* csa_attrs is defined static to avoid waste of stack size - this
5763 * function is called under RTNL lock, so this should not be a problem.
5764 */
5765 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5766 u8 radar_detect_width = 0;
5767 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005768 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005769
5770 if (!rdev->ops->channel_switch ||
5771 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5772 return -EOPNOTSUPP;
5773
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005774 switch (dev->ieee80211_ptr->iftype) {
5775 case NL80211_IFTYPE_AP:
5776 case NL80211_IFTYPE_P2P_GO:
5777 need_new_beacon = true;
5778
5779 /* useless if AP is not running */
5780 if (!wdev->beacon_interval)
5781 return -EINVAL;
5782 break;
5783 case NL80211_IFTYPE_ADHOC:
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005784 case NL80211_IFTYPE_MESH_POINT:
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005785 break;
5786 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005787 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005788 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005789
5790 memset(&params, 0, sizeof(params));
5791
5792 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5793 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5794 return -EINVAL;
5795
5796 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005797 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005798 return -EINVAL;
5799
5800 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5801
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005802 if (!need_new_beacon)
5803 goto skip_beacons;
5804
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005805 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5806 if (err)
5807 return err;
5808
5809 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5810 info->attrs[NL80211_ATTR_CSA_IES],
5811 nl80211_policy);
5812 if (err)
5813 return err;
5814
5815 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5816 if (err)
5817 return err;
5818
5819 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5820 return -EINVAL;
5821
5822 params.counter_offset_beacon =
5823 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5824 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5825 return -EINVAL;
5826
5827 /* sanity check - counters should be the same */
5828 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5829 params.count)
5830 return -EINVAL;
5831
5832 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5833 params.counter_offset_presp =
5834 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5835 if (params.counter_offset_presp >=
5836 params.beacon_csa.probe_resp_len)
5837 return -EINVAL;
5838
5839 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5840 params.count)
5841 return -EINVAL;
5842 }
5843
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005844skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005845 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5846 if (err)
5847 return err;
5848
5849 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5850 return -EINVAL;
5851
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005852 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005853 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5854 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005855 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5856 &params.chandef);
5857 if (err < 0) {
5858 return err;
5859 } else if (err) {
5860 radar_detect_width = BIT(params.chandef.width);
5861 params.radar_required = true;
5862 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005863 }
5864
5865 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5866 params.chandef.chan,
5867 CHAN_MODE_SHARED,
5868 radar_detect_width);
5869 if (err)
5870 return err;
5871
5872 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5873 params.block_tx = true;
5874
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005875 wdev_lock(wdev);
5876 err = rdev_channel_switch(rdev, dev, &params);
5877 wdev_unlock(wdev);
5878
5879 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005880}
5881
Johannes Berg9720bb32011-06-21 09:45:33 +02005882static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5883 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005884 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005885 struct wireless_dev *wdev,
5886 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005887{
Johannes Berg48ab9052009-07-10 18:42:31 +02005888 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005889 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005890 void *hdr;
5891 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005892 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005893
5894 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005895
Eric W. Biederman15e47302012-09-07 20:12:54 +00005896 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005897 NL80211_CMD_NEW_SCAN_RESULTS);
5898 if (!hdr)
5899 return -1;
5900
Johannes Berg9720bb32011-06-21 09:45:33 +02005901 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5902
Johannes Berg97990a02013-04-19 01:02:55 +02005903 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5904 goto nla_put_failure;
5905 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005906 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5907 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005908 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5909 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005910
5911 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5912 if (!bss)
5913 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005914 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005915 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005916 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005917
5918 rcu_read_lock();
5919 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005920 if (ies) {
5921 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5922 goto fail_unlock_rcu;
5923 tsf = true;
5924 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5925 ies->len, ies->data))
5926 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005927 }
5928 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005929 if (ies) {
5930 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5931 goto fail_unlock_rcu;
5932 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5933 ies->len, ies->data))
5934 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005935 }
5936 rcu_read_unlock();
5937
David S. Miller9360ffd2012-03-29 04:41:26 -04005938 if (res->beacon_interval &&
5939 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5940 goto nla_put_failure;
5941 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5942 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005943 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005944 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5945 jiffies_to_msecs(jiffies - intbss->ts)))
5946 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005947
Johannes Berg77965c972009-02-18 18:45:06 +01005948 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005949 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005950 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5951 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005952 break;
5953 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005954 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5955 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005956 break;
5957 default:
5958 break;
5959 }
5960
Johannes Berg48ab9052009-07-10 18:42:31 +02005961 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005962 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005963 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005964 if (intbss == wdev->current_bss &&
5965 nla_put_u32(msg, NL80211_BSS_STATUS,
5966 NL80211_BSS_STATUS_ASSOCIATED))
5967 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005968 break;
5969 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005970 if (intbss == wdev->current_bss &&
5971 nla_put_u32(msg, NL80211_BSS_STATUS,
5972 NL80211_BSS_STATUS_IBSS_JOINED))
5973 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005974 break;
5975 default:
5976 break;
5977 }
5978
Johannes Berg2a519312009-02-10 21:25:55 +01005979 nla_nest_end(msg, bss);
5980
5981 return genlmsg_end(msg, hdr);
5982
Johannes Berg8cef2c92013-02-05 16:54:31 +01005983 fail_unlock_rcu:
5984 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005985 nla_put_failure:
5986 genlmsg_cancel(msg, hdr);
5987 return -EMSGSIZE;
5988}
5989
Johannes Berg97990a02013-04-19 01:02:55 +02005990static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005991{
Johannes Berg48ab9052009-07-10 18:42:31 +02005992 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005993 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005994 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005995 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005996 int err;
5997
Johannes Berg97990a02013-04-19 01:02:55 +02005998 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005999 if (err)
6000 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006001
Johannes Berg48ab9052009-07-10 18:42:31 +02006002 wdev_lock(wdev);
6003 spin_lock_bh(&rdev->bss_lock);
6004 cfg80211_bss_expire(rdev);
6005
Johannes Berg9720bb32011-06-21 09:45:33 +02006006 cb->seq = rdev->bss_generation;
6007
Johannes Berg48ab9052009-07-10 18:42:31 +02006008 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006009 if (++idx <= start)
6010 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006011 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006012 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006013 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006014 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006015 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006016 }
6017 }
6018
Johannes Berg48ab9052009-07-10 18:42:31 +02006019 spin_unlock_bh(&rdev->bss_lock);
6020 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006021
Johannes Berg97990a02013-04-19 01:02:55 +02006022 cb->args[2] = idx;
6023 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006024
Johannes Berg67748892010-10-04 21:14:06 +02006025 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006026}
6027
Eric W. Biederman15e47302012-09-07 20:12:54 +00006028static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006029 int flags, struct net_device *dev,
6030 struct survey_info *survey)
6031{
6032 void *hdr;
6033 struct nlattr *infoattr;
6034
Eric W. Biederman15e47302012-09-07 20:12:54 +00006035 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006036 NL80211_CMD_NEW_SURVEY_RESULTS);
6037 if (!hdr)
6038 return -ENOMEM;
6039
David S. Miller9360ffd2012-03-29 04:41:26 -04006040 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6041 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006042
6043 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6044 if (!infoattr)
6045 goto nla_put_failure;
6046
David S. Miller9360ffd2012-03-29 04:41:26 -04006047 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6048 survey->channel->center_freq))
6049 goto nla_put_failure;
6050
6051 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6052 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6053 goto nla_put_failure;
6054 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6055 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6056 goto nla_put_failure;
6057 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6058 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6059 survey->channel_time))
6060 goto nla_put_failure;
6061 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6062 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6063 survey->channel_time_busy))
6064 goto nla_put_failure;
6065 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6066 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6067 survey->channel_time_ext_busy))
6068 goto nla_put_failure;
6069 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6070 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6071 survey->channel_time_rx))
6072 goto nla_put_failure;
6073 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6074 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6075 survey->channel_time_tx))
6076 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006077
6078 nla_nest_end(msg, infoattr);
6079
6080 return genlmsg_end(msg, hdr);
6081
6082 nla_put_failure:
6083 genlmsg_cancel(msg, hdr);
6084 return -EMSGSIZE;
6085}
6086
6087static int nl80211_dump_survey(struct sk_buff *skb,
6088 struct netlink_callback *cb)
6089{
6090 struct survey_info survey;
6091 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006092 struct wireless_dev *wdev;
6093 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006094 int res;
6095
Johannes Berg97990a02013-04-19 01:02:55 +02006096 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006097 if (res)
6098 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006099
Johannes Berg97990a02013-04-19 01:02:55 +02006100 if (!wdev->netdev) {
6101 res = -EINVAL;
6102 goto out_err;
6103 }
6104
Holger Schurig61fa7132009-11-11 12:25:40 +01006105 if (!dev->ops->dump_survey) {
6106 res = -EOPNOTSUPP;
6107 goto out_err;
6108 }
6109
6110 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006111 struct ieee80211_channel *chan;
6112
Johannes Berg97990a02013-04-19 01:02:55 +02006113 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006114 if (res == -ENOENT)
6115 break;
6116 if (res)
6117 goto out_err;
6118
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006119 /* Survey without a channel doesn't make sense */
6120 if (!survey.channel) {
6121 res = -EINVAL;
6122 goto out;
6123 }
6124
6125 chan = ieee80211_get_channel(&dev->wiphy,
6126 survey.channel->center_freq);
6127 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6128 survey_idx++;
6129 continue;
6130 }
6131
Holger Schurig61fa7132009-11-11 12:25:40 +01006132 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006133 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006134 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006135 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006136 goto out;
6137 survey_idx++;
6138 }
6139
6140 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006141 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006142 res = skb->len;
6143 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006144 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006145 return res;
6146}
6147
Samuel Ortizb23aa672009-07-01 21:26:54 +02006148static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6149{
6150 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6151 NL80211_WPA_VERSION_2));
6152}
6153
Jouni Malinen636a5d32009-03-19 13:39:22 +02006154static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6155{
Johannes Berg4c476992010-10-04 21:36:35 +02006156 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6157 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006158 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006159 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6160 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006161 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006162 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006163 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006164
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006165 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6166 return -EINVAL;
6167
6168 if (!info->attrs[NL80211_ATTR_MAC])
6169 return -EINVAL;
6170
Jouni Malinen17780922009-03-27 20:52:47 +02006171 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6172 return -EINVAL;
6173
Johannes Berg19957bb2009-07-02 17:20:43 +02006174 if (!info->attrs[NL80211_ATTR_SSID])
6175 return -EINVAL;
6176
6177 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6178 return -EINVAL;
6179
Johannes Bergfffd0932009-07-08 14:22:54 +02006180 err = nl80211_parse_key(info, &key);
6181 if (err)
6182 return err;
6183
6184 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006185 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6186 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006187 if (!key.p.key || !key.p.key_len)
6188 return -EINVAL;
6189 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6190 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6191 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6192 key.p.key_len != WLAN_KEY_LEN_WEP104))
6193 return -EINVAL;
6194 if (key.idx > 4)
6195 return -EINVAL;
6196 } else {
6197 key.p.key_len = 0;
6198 key.p.key = NULL;
6199 }
6200
Johannes Bergafea0b72010-08-10 09:46:42 +02006201 if (key.idx >= 0) {
6202 int i;
6203 bool ok = false;
6204 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6205 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6206 ok = true;
6207 break;
6208 }
6209 }
Johannes Berg4c476992010-10-04 21:36:35 +02006210 if (!ok)
6211 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006212 }
6213
Johannes Berg4c476992010-10-04 21:36:35 +02006214 if (!rdev->ops->auth)
6215 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006216
Johannes Berg074ac8d2010-09-16 14:58:22 +02006217 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006218 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6219 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006220
Johannes Berg19957bb2009-07-02 17:20:43 +02006221 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006222 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006223 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006224 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6225 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006226
Johannes Berg19957bb2009-07-02 17:20:43 +02006227 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6228 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6229
6230 if (info->attrs[NL80211_ATTR_IE]) {
6231 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6232 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6233 }
6234
6235 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006236 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006237 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006238
Jouni Malinene39e5b52012-09-30 19:29:39 +03006239 if (auth_type == NL80211_AUTHTYPE_SAE &&
6240 !info->attrs[NL80211_ATTR_SAE_DATA])
6241 return -EINVAL;
6242
6243 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6244 if (auth_type != NL80211_AUTHTYPE_SAE)
6245 return -EINVAL;
6246 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6247 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6248 /* need to include at least Auth Transaction and Status Code */
6249 if (sae_data_len < 4)
6250 return -EINVAL;
6251 }
6252
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006253 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6254
Johannes Berg95de8172012-01-20 13:55:25 +01006255 /*
6256 * Since we no longer track auth state, ignore
6257 * requests to only change local state.
6258 */
6259 if (local_state_change)
6260 return 0;
6261
Johannes Berg91bf9b22013-05-15 17:44:01 +02006262 wdev_lock(dev->ieee80211_ptr);
6263 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6264 ssid, ssid_len, ie, ie_len,
6265 key.p.key, key.p.key_len, key.idx,
6266 sae_data, sae_data_len);
6267 wdev_unlock(dev->ieee80211_ptr);
6268 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006269}
6270
Johannes Bergc0692b82010-08-27 14:26:53 +03006271static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6272 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006273 struct cfg80211_crypto_settings *settings,
6274 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006275{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006276 memset(settings, 0, sizeof(*settings));
6277
Samuel Ortizb23aa672009-07-01 21:26:54 +02006278 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6279
Johannes Bergc0692b82010-08-27 14:26:53 +03006280 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6281 u16 proto;
6282 proto = nla_get_u16(
6283 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6284 settings->control_port_ethertype = cpu_to_be16(proto);
6285 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6286 proto != ETH_P_PAE)
6287 return -EINVAL;
6288 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6289 settings->control_port_no_encrypt = true;
6290 } else
6291 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6292
Samuel Ortizb23aa672009-07-01 21:26:54 +02006293 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6294 void *data;
6295 int len, i;
6296
6297 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6298 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6299 settings->n_ciphers_pairwise = len / sizeof(u32);
6300
6301 if (len % sizeof(u32))
6302 return -EINVAL;
6303
Johannes Berg3dc27d22009-07-02 21:36:37 +02006304 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006305 return -EINVAL;
6306
6307 memcpy(settings->ciphers_pairwise, data, len);
6308
6309 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006310 if (!cfg80211_supported_cipher_suite(
6311 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006312 settings->ciphers_pairwise[i]))
6313 return -EINVAL;
6314 }
6315
6316 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6317 settings->cipher_group =
6318 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006319 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6320 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006321 return -EINVAL;
6322 }
6323
6324 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6325 settings->wpa_versions =
6326 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6327 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6328 return -EINVAL;
6329 }
6330
6331 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6332 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006333 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006334
6335 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6336 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6337 settings->n_akm_suites = len / sizeof(u32);
6338
6339 if (len % sizeof(u32))
6340 return -EINVAL;
6341
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006342 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6343 return -EINVAL;
6344
Samuel Ortizb23aa672009-07-01 21:26:54 +02006345 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006346 }
6347
6348 return 0;
6349}
6350
Jouni Malinen636a5d32009-03-19 13:39:22 +02006351static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6352{
Johannes Berg4c476992010-10-04 21:36:35 +02006353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6354 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006355 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006356 struct cfg80211_assoc_request req = {};
6357 const u8 *bssid, *ssid;
6358 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006359
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006360 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6361 return -EINVAL;
6362
6363 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006364 !info->attrs[NL80211_ATTR_SSID] ||
6365 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006366 return -EINVAL;
6367
Johannes Berg4c476992010-10-04 21:36:35 +02006368 if (!rdev->ops->assoc)
6369 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006370
Johannes Berg074ac8d2010-09-16 14:58:22 +02006371 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006372 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6373 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006374
Johannes Berg19957bb2009-07-02 17:20:43 +02006375 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006376
Johannes Berg19957bb2009-07-02 17:20:43 +02006377 chan = ieee80211_get_channel(&rdev->wiphy,
6378 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006379 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6380 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006381
Johannes Berg19957bb2009-07-02 17:20:43 +02006382 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6383 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006384
6385 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006386 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6387 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006388 }
6389
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006390 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006391 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006392 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006393 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006394 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006395 else if (mfp != NL80211_MFP_NO)
6396 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006397 }
6398
Johannes Berg3e5d7642009-07-07 14:37:26 +02006399 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006400 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006401
Ben Greear7e7c8922011-11-18 11:31:59 -08006402 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006403 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006404
6405 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006406 memcpy(&req.ht_capa_mask,
6407 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6408 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006409
6410 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006411 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006412 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006413 memcpy(&req.ht_capa,
6414 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6415 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006416 }
6417
Johannes Bergee2aca32013-02-21 17:36:01 +01006418 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006419 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006420
6421 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006422 memcpy(&req.vht_capa_mask,
6423 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6424 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006425
6426 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006427 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006428 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006429 memcpy(&req.vht_capa,
6430 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6431 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006432 }
6433
Johannes Bergf62fab72013-02-21 20:09:09 +01006434 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006435 if (!err) {
6436 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006437 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6438 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006439 wdev_unlock(dev->ieee80211_ptr);
6440 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006441
Jouni Malinen636a5d32009-03-19 13:39:22 +02006442 return err;
6443}
6444
6445static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6446{
Johannes Berg4c476992010-10-04 21:36:35 +02006447 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6448 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006449 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006450 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006451 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006452 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006453
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006454 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6455 return -EINVAL;
6456
6457 if (!info->attrs[NL80211_ATTR_MAC])
6458 return -EINVAL;
6459
6460 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6461 return -EINVAL;
6462
Johannes Berg4c476992010-10-04 21:36:35 +02006463 if (!rdev->ops->deauth)
6464 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006465
Johannes Berg074ac8d2010-09-16 14:58:22 +02006466 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006467 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6468 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006469
Johannes Berg19957bb2009-07-02 17:20:43 +02006470 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006471
Johannes Berg19957bb2009-07-02 17:20:43 +02006472 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6473 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006474 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006475 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006476 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006477
6478 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006479 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6480 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006481 }
6482
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006483 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6484
Johannes Berg91bf9b22013-05-15 17:44:01 +02006485 wdev_lock(dev->ieee80211_ptr);
6486 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6487 local_state_change);
6488 wdev_unlock(dev->ieee80211_ptr);
6489 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006490}
6491
6492static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6493{
Johannes Berg4c476992010-10-04 21:36:35 +02006494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6495 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006496 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006497 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006498 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006499 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006500
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006501 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6502 return -EINVAL;
6503
6504 if (!info->attrs[NL80211_ATTR_MAC])
6505 return -EINVAL;
6506
6507 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6508 return -EINVAL;
6509
Johannes Berg4c476992010-10-04 21:36:35 +02006510 if (!rdev->ops->disassoc)
6511 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006512
Johannes Berg074ac8d2010-09-16 14:58:22 +02006513 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006514 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6515 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006516
Johannes Berg19957bb2009-07-02 17:20:43 +02006517 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006518
Johannes Berg19957bb2009-07-02 17:20:43 +02006519 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6520 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006521 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006522 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006523 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006524
6525 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006526 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6527 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006528 }
6529
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006530 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6531
Johannes Berg91bf9b22013-05-15 17:44:01 +02006532 wdev_lock(dev->ieee80211_ptr);
6533 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6534 local_state_change);
6535 wdev_unlock(dev->ieee80211_ptr);
6536 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006537}
6538
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006539static bool
6540nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6541 int mcast_rate[IEEE80211_NUM_BANDS],
6542 int rateval)
6543{
6544 struct wiphy *wiphy = &rdev->wiphy;
6545 bool found = false;
6546 int band, i;
6547
6548 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6549 struct ieee80211_supported_band *sband;
6550
6551 sband = wiphy->bands[band];
6552 if (!sband)
6553 continue;
6554
6555 for (i = 0; i < sband->n_bitrates; i++) {
6556 if (sband->bitrates[i].bitrate == rateval) {
6557 mcast_rate[band] = i + 1;
6558 found = true;
6559 break;
6560 }
6561 }
6562 }
6563
6564 return found;
6565}
6566
Johannes Berg04a773a2009-04-19 21:24:32 +02006567static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6568{
Johannes Berg4c476992010-10-04 21:36:35 +02006569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6570 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006571 struct cfg80211_ibss_params ibss;
6572 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006573 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006574 int err;
6575
Johannes Berg8e30bc52009-04-22 17:45:38 +02006576 memset(&ibss, 0, sizeof(ibss));
6577
Johannes Berg04a773a2009-04-19 21:24:32 +02006578 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6579 return -EINVAL;
6580
Johannes Berg683b6d32012-11-08 21:25:48 +01006581 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006582 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6583 return -EINVAL;
6584
Johannes Berg8e30bc52009-04-22 17:45:38 +02006585 ibss.beacon_interval = 100;
6586
6587 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6588 ibss.beacon_interval =
6589 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6590 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6591 return -EINVAL;
6592 }
6593
Johannes Berg4c476992010-10-04 21:36:35 +02006594 if (!rdev->ops->join_ibss)
6595 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006596
Johannes Berg4c476992010-10-04 21:36:35 +02006597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6598 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006599
Johannes Berg79c97e92009-07-07 03:56:12 +02006600 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006601
Johannes Berg39193492011-09-16 13:45:25 +02006602 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006603 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006604
6605 if (!is_valid_ether_addr(ibss.bssid))
6606 return -EINVAL;
6607 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006608 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6609 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6610
6611 if (info->attrs[NL80211_ATTR_IE]) {
6612 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6613 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6614 }
6615
Johannes Berg683b6d32012-11-08 21:25:48 +01006616 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6617 if (err)
6618 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006619
Johannes Berg683b6d32012-11-08 21:25:48 +01006620 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006621 return -EINVAL;
6622
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006623 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006624 case NL80211_CHAN_WIDTH_5:
6625 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006626 case NL80211_CHAN_WIDTH_20_NOHT:
6627 break;
6628 case NL80211_CHAN_WIDTH_20:
6629 case NL80211_CHAN_WIDTH_40:
6630 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6631 break;
6632 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006633 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006634 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006635
Johannes Berg04a773a2009-04-19 21:24:32 +02006636 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006637 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006638
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006639 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6640 u8 *rates =
6641 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6642 int n_rates =
6643 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6644 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006645 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006646
Johannes Berg34850ab2011-07-18 18:08:35 +02006647 err = ieee80211_get_ratemask(sband, rates, n_rates,
6648 &ibss.basic_rates);
6649 if (err)
6650 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006651 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006652
Simon Wunderlich803768f2013-06-28 10:39:58 +02006653 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6654 memcpy(&ibss.ht_capa_mask,
6655 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6656 sizeof(ibss.ht_capa_mask));
6657
6658 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6659 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6660 return -EINVAL;
6661 memcpy(&ibss.ht_capa,
6662 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6663 sizeof(ibss.ht_capa));
6664 }
6665
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006666 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6667 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6668 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6669 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006670
Johannes Berg4c476992010-10-04 21:36:35 +02006671 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306672 bool no_ht = false;
6673
Johannes Berg4c476992010-10-04 21:36:35 +02006674 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306675 info->attrs[NL80211_ATTR_KEYS],
6676 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006677 if (IS_ERR(connkeys))
6678 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306679
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006680 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6681 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306682 kfree(connkeys);
6683 return -EINVAL;
6684 }
Johannes Berg4c476992010-10-04 21:36:35 +02006685 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006686
Antonio Quartulli267335d2012-01-31 20:25:47 +01006687 ibss.control_port =
6688 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6689
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006690 ibss.userspace_handles_dfs =
6691 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6692
Johannes Berg4c476992010-10-04 21:36:35 +02006693 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006694 if (err)
6695 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006696 return err;
6697}
6698
6699static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6700{
Johannes Berg4c476992010-10-04 21:36:35 +02006701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6702 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006703
Johannes Berg4c476992010-10-04 21:36:35 +02006704 if (!rdev->ops->leave_ibss)
6705 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006706
Johannes Berg4c476992010-10-04 21:36:35 +02006707 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6708 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006709
Johannes Berg4c476992010-10-04 21:36:35 +02006710 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006711}
6712
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006713static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6714{
6715 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6716 struct net_device *dev = info->user_ptr[1];
6717 int mcast_rate[IEEE80211_NUM_BANDS];
6718 u32 nla_rate;
6719 int err;
6720
6721 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6722 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6723 return -EOPNOTSUPP;
6724
6725 if (!rdev->ops->set_mcast_rate)
6726 return -EOPNOTSUPP;
6727
6728 memset(mcast_rate, 0, sizeof(mcast_rate));
6729
6730 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6731 return -EINVAL;
6732
6733 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6734 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6735 return -EINVAL;
6736
6737 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6738
6739 return err;
6740}
6741
Johannes Bergad7e7182013-11-13 13:37:47 +01006742static struct sk_buff *
6743__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6744 int approxlen, u32 portid, u32 seq,
6745 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006746 enum nl80211_attrs attr,
6747 const struct nl80211_vendor_cmd_info *info,
6748 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006749{
6750 struct sk_buff *skb;
6751 void *hdr;
6752 struct nlattr *data;
6753
6754 skb = nlmsg_new(approxlen + 100, gfp);
6755 if (!skb)
6756 return NULL;
6757
6758 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6759 if (!hdr) {
6760 kfree_skb(skb);
6761 return NULL;
6762 }
6763
6764 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6765 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006766
6767 if (info) {
6768 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6769 info->vendor_id))
6770 goto nla_put_failure;
6771 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6772 info->subcmd))
6773 goto nla_put_failure;
6774 }
6775
Johannes Bergad7e7182013-11-13 13:37:47 +01006776 data = nla_nest_start(skb, attr);
6777
6778 ((void **)skb->cb)[0] = rdev;
6779 ((void **)skb->cb)[1] = hdr;
6780 ((void **)skb->cb)[2] = data;
6781
6782 return skb;
6783
6784 nla_put_failure:
6785 kfree_skb(skb);
6786 return NULL;
6787}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006788
Johannes Berge03ad6e2014-01-01 17:22:30 +01006789struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6790 enum nl80211_commands cmd,
6791 enum nl80211_attrs attr,
6792 int vendor_event_idx,
6793 int approxlen, gfp_t gfp)
6794{
6795 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6796 const struct nl80211_vendor_cmd_info *info;
6797
6798 switch (cmd) {
6799 case NL80211_CMD_TESTMODE:
6800 if (WARN_ON(vendor_event_idx != -1))
6801 return NULL;
6802 info = NULL;
6803 break;
6804 case NL80211_CMD_VENDOR:
6805 if (WARN_ON(vendor_event_idx < 0 ||
6806 vendor_event_idx >= wiphy->n_vendor_events))
6807 return NULL;
6808 info = &wiphy->vendor_events[vendor_event_idx];
6809 break;
6810 default:
6811 WARN_ON(1);
6812 return NULL;
6813 }
6814
6815 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6816 cmd, attr, info, gfp);
6817}
6818EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6819
6820void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6821{
6822 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6823 void *hdr = ((void **)skb->cb)[1];
6824 struct nlattr *data = ((void **)skb->cb)[2];
6825 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6826
6827 nla_nest_end(skb, data);
6828 genlmsg_end(skb, hdr);
6829
6830 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6831 mcgrp = NL80211_MCGRP_VENDOR;
6832
6833 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6834 mcgrp, gfp);
6835}
6836EXPORT_SYMBOL(__cfg80211_send_event_skb);
6837
Johannes Bergaff89a92009-07-01 21:26:51 +02006838#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006839static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6840{
Johannes Berg4c476992010-10-04 21:36:35 +02006841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006842 struct wireless_dev *wdev =
6843 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006844 int err;
6845
David Spinadelfc73f112013-07-31 18:04:15 +03006846 if (!rdev->ops->testmode_cmd)
6847 return -EOPNOTSUPP;
6848
6849 if (IS_ERR(wdev)) {
6850 err = PTR_ERR(wdev);
6851 if (err != -EINVAL)
6852 return err;
6853 wdev = NULL;
6854 } else if (wdev->wiphy != &rdev->wiphy) {
6855 return -EINVAL;
6856 }
6857
Johannes Bergaff89a92009-07-01 21:26:51 +02006858 if (!info->attrs[NL80211_ATTR_TESTDATA])
6859 return -EINVAL;
6860
Johannes Bergad7e7182013-11-13 13:37:47 +01006861 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03006862 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006863 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6864 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01006865 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006866
Johannes Bergaff89a92009-07-01 21:26:51 +02006867 return err;
6868}
6869
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006870static int nl80211_testmode_dump(struct sk_buff *skb,
6871 struct netlink_callback *cb)
6872{
Johannes Berg00918d32011-12-13 17:22:05 +01006873 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006874 int err;
6875 long phy_idx;
6876 void *data = NULL;
6877 int data_len = 0;
6878
Johannes Berg5fe231e2013-05-08 21:45:15 +02006879 rtnl_lock();
6880
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006881 if (cb->args[0]) {
6882 /*
6883 * 0 is a valid index, but not valid for args[0],
6884 * so we need to offset by 1.
6885 */
6886 phy_idx = cb->args[0] - 1;
6887 } else {
6888 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6889 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6890 nl80211_policy);
6891 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006892 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006893
Johannes Berg2bd7e352012-06-15 14:23:16 +02006894 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6895 nl80211_fam.attrbuf);
6896 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006897 err = PTR_ERR(rdev);
6898 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006899 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006900 phy_idx = rdev->wiphy_idx;
6901 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006902
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006903 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6904 cb->args[1] =
6905 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6906 }
6907
6908 if (cb->args[1]) {
6909 data = nla_data((void *)cb->args[1]);
6910 data_len = nla_len((void *)cb->args[1]);
6911 }
6912
Johannes Berg00918d32011-12-13 17:22:05 +01006913 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6914 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006915 err = -ENOENT;
6916 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006917 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006918
Johannes Berg00918d32011-12-13 17:22:05 +01006919 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006920 err = -EOPNOTSUPP;
6921 goto out_err;
6922 }
6923
6924 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006925 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006926 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6927 NL80211_CMD_TESTMODE);
6928 struct nlattr *tmdata;
6929
Dan Carpentercb35fba2013-08-14 14:50:01 +03006930 if (!hdr)
6931 break;
6932
David S. Miller9360ffd2012-03-29 04:41:26 -04006933 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006934 genlmsg_cancel(skb, hdr);
6935 break;
6936 }
6937
6938 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6939 if (!tmdata) {
6940 genlmsg_cancel(skb, hdr);
6941 break;
6942 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006943 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006944 nla_nest_end(skb, tmdata);
6945
6946 if (err == -ENOBUFS || err == -ENOENT) {
6947 genlmsg_cancel(skb, hdr);
6948 break;
6949 } else if (err) {
6950 genlmsg_cancel(skb, hdr);
6951 goto out_err;
6952 }
6953
6954 genlmsg_end(skb, hdr);
6955 }
6956
6957 err = skb->len;
6958 /* see above */
6959 cb->args[0] = phy_idx + 1;
6960 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006961 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006962 return err;
6963}
Johannes Bergaff89a92009-07-01 21:26:51 +02006964#endif
6965
Samuel Ortizb23aa672009-07-01 21:26:54 +02006966static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6967{
Johannes Berg4c476992010-10-04 21:36:35 +02006968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6969 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006970 struct cfg80211_connect_params connect;
6971 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006972 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006973 int err;
6974
6975 memset(&connect, 0, sizeof(connect));
6976
6977 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6978 return -EINVAL;
6979
6980 if (!info->attrs[NL80211_ATTR_SSID] ||
6981 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6982 return -EINVAL;
6983
6984 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6985 connect.auth_type =
6986 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006987 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6988 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006989 return -EINVAL;
6990 } else
6991 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6992
6993 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6994
Johannes Bergc0692b82010-08-27 14:26:53 +03006995 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006996 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006997 if (err)
6998 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006999
Johannes Berg074ac8d2010-09-16 14:58:22 +02007000 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007001 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7002 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007003
Johannes Berg79c97e92009-07-07 03:56:12 +02007004 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007005
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307006 connect.bg_scan_period = -1;
7007 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7008 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7009 connect.bg_scan_period =
7010 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7011 }
7012
Samuel Ortizb23aa672009-07-01 21:26:54 +02007013 if (info->attrs[NL80211_ATTR_MAC])
7014 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7015 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7016 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7017
7018 if (info->attrs[NL80211_ATTR_IE]) {
7019 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7020 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7021 }
7022
Jouni Malinencee00a92013-01-15 17:15:57 +02007023 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7024 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7025 if (connect.mfp != NL80211_MFP_REQUIRED &&
7026 connect.mfp != NL80211_MFP_NO)
7027 return -EINVAL;
7028 } else {
7029 connect.mfp = NL80211_MFP_NO;
7030 }
7031
Samuel Ortizb23aa672009-07-01 21:26:54 +02007032 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7033 connect.channel =
7034 ieee80211_get_channel(wiphy,
7035 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
7036 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02007037 connect.channel->flags & IEEE80211_CHAN_DISABLED)
7038 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007039 }
7040
Johannes Bergfffd0932009-07-08 14:22:54 +02007041 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7042 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307043 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007044 if (IS_ERR(connkeys))
7045 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007046 }
7047
Ben Greear7e7c8922011-11-18 11:31:59 -08007048 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7049 connect.flags |= ASSOC_REQ_DISABLE_HT;
7050
7051 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7052 memcpy(&connect.ht_capa_mask,
7053 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7054 sizeof(connect.ht_capa_mask));
7055
7056 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007057 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7058 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007059 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007060 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007061 memcpy(&connect.ht_capa,
7062 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7063 sizeof(connect.ht_capa));
7064 }
7065
Johannes Bergee2aca32013-02-21 17:36:01 +01007066 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7067 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7068
7069 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7070 memcpy(&connect.vht_capa_mask,
7071 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7072 sizeof(connect.vht_capa_mask));
7073
7074 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7075 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7076 kfree(connkeys);
7077 return -EINVAL;
7078 }
7079 memcpy(&connect.vht_capa,
7080 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7081 sizeof(connect.vht_capa));
7082 }
7083
Johannes Berg83739b02013-05-15 17:44:01 +02007084 wdev_lock(dev->ieee80211_ptr);
7085 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7086 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007087 if (err)
7088 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007089 return err;
7090}
7091
7092static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7093{
Johannes Berg4c476992010-10-04 21:36:35 +02007094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7095 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007096 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007097 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007098
7099 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7100 reason = WLAN_REASON_DEAUTH_LEAVING;
7101 else
7102 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7103
7104 if (reason == 0)
7105 return -EINVAL;
7106
Johannes Berg074ac8d2010-09-16 14:58:22 +02007107 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007108 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7109 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007110
Johannes Berg83739b02013-05-15 17:44:01 +02007111 wdev_lock(dev->ieee80211_ptr);
7112 ret = cfg80211_disconnect(rdev, dev, reason, true);
7113 wdev_unlock(dev->ieee80211_ptr);
7114 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007115}
7116
Johannes Berg463d0182009-07-14 00:33:35 +02007117static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7118{
Johannes Berg4c476992010-10-04 21:36:35 +02007119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007120 struct net *net;
7121 int err;
7122 u32 pid;
7123
7124 if (!info->attrs[NL80211_ATTR_PID])
7125 return -EINVAL;
7126
7127 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7128
Johannes Berg463d0182009-07-14 00:33:35 +02007129 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007130 if (IS_ERR(net))
7131 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007132
7133 err = 0;
7134
7135 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007136 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7137 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007138
Johannes Berg463d0182009-07-14 00:33:35 +02007139 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007140 return err;
7141}
7142
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007143static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7144{
Johannes Berg4c476992010-10-04 21:36:35 +02007145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007146 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7147 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007148 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007149 struct cfg80211_pmksa pmksa;
7150
7151 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7152
7153 if (!info->attrs[NL80211_ATTR_MAC])
7154 return -EINVAL;
7155
7156 if (!info->attrs[NL80211_ATTR_PMKID])
7157 return -EINVAL;
7158
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007159 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7160 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7161
Johannes Berg074ac8d2010-09-16 14:58:22 +02007162 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007163 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7164 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007165
7166 switch (info->genlhdr->cmd) {
7167 case NL80211_CMD_SET_PMKSA:
7168 rdev_ops = rdev->ops->set_pmksa;
7169 break;
7170 case NL80211_CMD_DEL_PMKSA:
7171 rdev_ops = rdev->ops->del_pmksa;
7172 break;
7173 default:
7174 WARN_ON(1);
7175 break;
7176 }
7177
Johannes Berg4c476992010-10-04 21:36:35 +02007178 if (!rdev_ops)
7179 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007180
Johannes Berg4c476992010-10-04 21:36:35 +02007181 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007182}
7183
7184static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7185{
Johannes Berg4c476992010-10-04 21:36:35 +02007186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7187 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007188
Johannes Berg074ac8d2010-09-16 14:58:22 +02007189 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007190 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7191 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007192
Johannes Berg4c476992010-10-04 21:36:35 +02007193 if (!rdev->ops->flush_pmksa)
7194 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007195
Hila Gonene35e4d22012-06-27 17:19:42 +03007196 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007197}
7198
Arik Nemtsov109086c2011-09-28 14:12:50 +03007199static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7200{
7201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7202 struct net_device *dev = info->user_ptr[1];
7203 u8 action_code, dialog_token;
7204 u16 status_code;
7205 u8 *peer;
7206
7207 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7208 !rdev->ops->tdls_mgmt)
7209 return -EOPNOTSUPP;
7210
7211 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7212 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7213 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7214 !info->attrs[NL80211_ATTR_IE] ||
7215 !info->attrs[NL80211_ATTR_MAC])
7216 return -EINVAL;
7217
7218 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7219 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7220 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7221 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7222
Hila Gonene35e4d22012-06-27 17:19:42 +03007223 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7224 dialog_token, status_code,
7225 nla_data(info->attrs[NL80211_ATTR_IE]),
7226 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007227}
7228
7229static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7230{
7231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7232 struct net_device *dev = info->user_ptr[1];
7233 enum nl80211_tdls_operation operation;
7234 u8 *peer;
7235
7236 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7237 !rdev->ops->tdls_oper)
7238 return -EOPNOTSUPP;
7239
7240 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7241 !info->attrs[NL80211_ATTR_MAC])
7242 return -EINVAL;
7243
7244 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7245 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7246
Hila Gonene35e4d22012-06-27 17:19:42 +03007247 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007248}
7249
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007250static int nl80211_remain_on_channel(struct sk_buff *skb,
7251 struct genl_info *info)
7252{
Johannes Berg4c476992010-10-04 21:36:35 +02007253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007254 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007255 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007256 struct sk_buff *msg;
7257 void *hdr;
7258 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007259 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007260 int err;
7261
7262 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7263 !info->attrs[NL80211_ATTR_DURATION])
7264 return -EINVAL;
7265
7266 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7267
Johannes Berg7c4ef712011-11-18 15:33:48 +01007268 if (!rdev->ops->remain_on_channel ||
7269 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007270 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007271
Johannes Bergebf348f2012-06-01 12:50:54 +02007272 /*
7273 * We should be on that channel for at least a minimum amount of
7274 * time (10ms) but no longer than the driver supports.
7275 */
7276 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7277 duration > rdev->wiphy.max_remain_on_channel_duration)
7278 return -EINVAL;
7279
Johannes Berg683b6d32012-11-08 21:25:48 +01007280 err = nl80211_parse_chandef(rdev, info, &chandef);
7281 if (err)
7282 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007283
7284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007285 if (!msg)
7286 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007287
Eric W. Biederman15e47302012-09-07 20:12:54 +00007288 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007289 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007290 if (!hdr) {
7291 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007292 goto free_msg;
7293 }
7294
Johannes Berg683b6d32012-11-08 21:25:48 +01007295 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7296 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007297
7298 if (err)
7299 goto free_msg;
7300
David S. Miller9360ffd2012-03-29 04:41:26 -04007301 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7302 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007303
7304 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007305
7306 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007307
7308 nla_put_failure:
7309 err = -ENOBUFS;
7310 free_msg:
7311 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007312 return err;
7313}
7314
7315static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7316 struct genl_info *info)
7317{
Johannes Berg4c476992010-10-04 21:36:35 +02007318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007319 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007320 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007321
7322 if (!info->attrs[NL80211_ATTR_COOKIE])
7323 return -EINVAL;
7324
Johannes Berg4c476992010-10-04 21:36:35 +02007325 if (!rdev->ops->cancel_remain_on_channel)
7326 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007327
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007328 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7329
Hila Gonene35e4d22012-06-27 17:19:42 +03007330 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007331}
7332
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007333static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7334 u8 *rates, u8 rates_len)
7335{
7336 u8 i;
7337 u32 mask = 0;
7338
7339 for (i = 0; i < rates_len; i++) {
7340 int rate = (rates[i] & 0x7f) * 5;
7341 int ridx;
7342 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7343 struct ieee80211_rate *srate =
7344 &sband->bitrates[ridx];
7345 if (rate == srate->bitrate) {
7346 mask |= 1 << ridx;
7347 break;
7348 }
7349 }
7350 if (ridx == sband->n_bitrates)
7351 return 0; /* rate not found */
7352 }
7353
7354 return mask;
7355}
7356
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007357static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7358 u8 *rates, u8 rates_len,
7359 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7360{
7361 u8 i;
7362
7363 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7364
7365 for (i = 0; i < rates_len; i++) {
7366 int ridx, rbit;
7367
7368 ridx = rates[i] / 8;
7369 rbit = BIT(rates[i] % 8);
7370
7371 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007372 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007373 return false;
7374
7375 /* check availability */
7376 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7377 mcs[ridx] |= rbit;
7378 else
7379 return false;
7380 }
7381
7382 return true;
7383}
7384
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007385static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7386{
7387 u16 mcs_mask = 0;
7388
7389 switch (vht_mcs_map) {
7390 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7391 break;
7392 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7393 mcs_mask = 0x00FF;
7394 break;
7395 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7396 mcs_mask = 0x01FF;
7397 break;
7398 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7399 mcs_mask = 0x03FF;
7400 break;
7401 default:
7402 break;
7403 }
7404
7405 return mcs_mask;
7406}
7407
7408static void vht_build_mcs_mask(u16 vht_mcs_map,
7409 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7410{
7411 u8 nss;
7412
7413 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7414 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7415 vht_mcs_map >>= 2;
7416 }
7417}
7418
7419static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7420 struct nl80211_txrate_vht *txrate,
7421 u16 mcs[NL80211_VHT_NSS_MAX])
7422{
7423 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7424 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7425 u8 i;
7426
7427 if (!sband->vht_cap.vht_supported)
7428 return false;
7429
7430 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7431
7432 /* Build vht_mcs_mask from VHT capabilities */
7433 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7434
7435 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7436 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7437 mcs[i] = txrate->mcs[i];
7438 else
7439 return false;
7440 }
7441
7442 return true;
7443}
7444
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007445static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007446 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7447 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007448 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7449 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007450 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007451};
7452
7453static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7454 struct genl_info *info)
7455{
7456 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007458 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007459 int rem, i;
7460 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007461 struct nlattr *tx_rates;
7462 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007463 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007464
Johannes Berg4c476992010-10-04 21:36:35 +02007465 if (!rdev->ops->set_bitrate_mask)
7466 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007467
7468 memset(&mask, 0, sizeof(mask));
7469 /* Default to all rates enabled */
7470 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7471 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007472
7473 if (!sband)
7474 continue;
7475
7476 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007477 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007478 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007479 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007480
7481 if (!sband->vht_cap.vht_supported)
7482 continue;
7483
7484 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7485 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007486 }
7487
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007488 /* if no rates are given set it back to the defaults */
7489 if (!info->attrs[NL80211_ATTR_TX_RATES])
7490 goto out;
7491
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007492 /*
7493 * The nested attribute uses enum nl80211_band as the index. This maps
7494 * directly to the enum ieee80211_band values used in cfg80211.
7495 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007496 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007497 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7498 {
7499 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007500 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7501 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007502 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007503 if (sband == NULL)
7504 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007505 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7506 nla_len(tx_rates), nl80211_txattr_policy);
7507 if (tb[NL80211_TXRATE_LEGACY]) {
7508 mask.control[band].legacy = rateset_to_mask(
7509 sband,
7510 nla_data(tb[NL80211_TXRATE_LEGACY]),
7511 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307512 if ((mask.control[band].legacy == 0) &&
7513 nla_len(tb[NL80211_TXRATE_LEGACY]))
7514 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007515 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007516 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007517 if (!ht_rateset_to_mask(
7518 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007519 nla_data(tb[NL80211_TXRATE_HT]),
7520 nla_len(tb[NL80211_TXRATE_HT]),
7521 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007522 return -EINVAL;
7523 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007524 if (tb[NL80211_TXRATE_VHT]) {
7525 if (!vht_set_mcs_mask(
7526 sband,
7527 nla_data(tb[NL80211_TXRATE_VHT]),
7528 mask.control[band].vht_mcs))
7529 return -EINVAL;
7530 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007531
7532 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007533 /* don't allow empty legacy rates if HT or VHT
7534 * are not even supported.
7535 */
7536 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7537 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007538 return -EINVAL;
7539
7540 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007541 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007542 goto out;
7543
7544 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7545 if (mask.control[band].vht_mcs[i])
7546 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007547
7548 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007549 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007550 }
7551 }
7552
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007553out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007554 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007555}
7556
Johannes Berg2e161f782010-08-12 15:38:38 +02007557static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007558{
Johannes Berg4c476992010-10-04 21:36:35 +02007559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007560 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02007561 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007562
7563 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7564 return -EINVAL;
7565
Johannes Berg2e161f782010-08-12 15:38:38 +02007566 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7567 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007568
Johannes Berg71bbc992012-06-15 15:30:18 +02007569 switch (wdev->iftype) {
7570 case NL80211_IFTYPE_STATION:
7571 case NL80211_IFTYPE_ADHOC:
7572 case NL80211_IFTYPE_P2P_CLIENT:
7573 case NL80211_IFTYPE_AP:
7574 case NL80211_IFTYPE_AP_VLAN:
7575 case NL80211_IFTYPE_MESH_POINT:
7576 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007577 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007578 break;
7579 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007580 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007581 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007582
7583 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007584 if (!rdev->ops->mgmt_tx)
7585 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007586
Eric W. Biederman15e47302012-09-07 20:12:54 +00007587 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007588 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7589 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007590}
7591
Johannes Berg2e161f782010-08-12 15:38:38 +02007592static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007593{
Johannes Berg4c476992010-10-04 21:36:35 +02007594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007595 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007596 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007597 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007598 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007599 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007600 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007601 struct cfg80211_mgmt_tx_params params = {
7602 .dont_wait_for_ack =
7603 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7604 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007605
Johannes Berg683b6d32012-11-08 21:25:48 +01007606 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007607 return -EINVAL;
7608
Johannes Berg4c476992010-10-04 21:36:35 +02007609 if (!rdev->ops->mgmt_tx)
7610 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007611
Johannes Berg71bbc992012-06-15 15:30:18 +02007612 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007613 case NL80211_IFTYPE_P2P_DEVICE:
7614 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7615 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007616 case NL80211_IFTYPE_STATION:
7617 case NL80211_IFTYPE_ADHOC:
7618 case NL80211_IFTYPE_P2P_CLIENT:
7619 case NL80211_IFTYPE_AP:
7620 case NL80211_IFTYPE_AP_VLAN:
7621 case NL80211_IFTYPE_MESH_POINT:
7622 case NL80211_IFTYPE_P2P_GO:
7623 break;
7624 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007625 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007626 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007627
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007628 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007629 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007630 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007631 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007632
7633 /*
7634 * We should wait on the channel for at least a minimum amount
7635 * of time (10ms) but no longer than the driver supports.
7636 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007637 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7638 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007639 return -EINVAL;
7640
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007641 }
7642
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007643 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007644
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007645 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007646 return -EINVAL;
7647
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007648 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307649
Antonio Quartulliea141b752013-06-11 14:20:03 +02007650 /* get the channel if any has been specified, otherwise pass NULL to
7651 * the driver. The latter will use the current one
7652 */
7653 chandef.chan = NULL;
7654 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7655 err = nl80211_parse_chandef(rdev, info, &chandef);
7656 if (err)
7657 return err;
7658 }
7659
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007660 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007661 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007662
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007663 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7665 if (!msg)
7666 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007667
Eric W. Biederman15e47302012-09-07 20:12:54 +00007668 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007669 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007670 if (!hdr) {
7671 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007672 goto free_msg;
7673 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007674 }
Johannes Berge247bd902011-11-04 11:18:21 +01007675
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007676 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7677 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7678 params.chan = chandef.chan;
7679 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007680 if (err)
7681 goto free_msg;
7682
Johannes Berge247bd902011-11-04 11:18:21 +01007683 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007684 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7685 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007686
Johannes Berge247bd902011-11-04 11:18:21 +01007687 genlmsg_end(msg, hdr);
7688 return genlmsg_reply(msg, info);
7689 }
7690
7691 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007692
7693 nla_put_failure:
7694 err = -ENOBUFS;
7695 free_msg:
7696 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007697 return err;
7698}
7699
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007700static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7701{
7702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007703 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007704 u64 cookie;
7705
7706 if (!info->attrs[NL80211_ATTR_COOKIE])
7707 return -EINVAL;
7708
7709 if (!rdev->ops->mgmt_tx_cancel_wait)
7710 return -EOPNOTSUPP;
7711
Johannes Berg71bbc992012-06-15 15:30:18 +02007712 switch (wdev->iftype) {
7713 case NL80211_IFTYPE_STATION:
7714 case NL80211_IFTYPE_ADHOC:
7715 case NL80211_IFTYPE_P2P_CLIENT:
7716 case NL80211_IFTYPE_AP:
7717 case NL80211_IFTYPE_AP_VLAN:
7718 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007719 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007720 break;
7721 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007722 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007723 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007724
7725 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7726
Hila Gonene35e4d22012-06-27 17:19:42 +03007727 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007728}
7729
Kalle Valoffb9eb32010-02-17 17:58:10 +02007730static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7731{
Johannes Berg4c476992010-10-04 21:36:35 +02007732 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007733 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007734 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007735 u8 ps_state;
7736 bool state;
7737 int err;
7738
Johannes Berg4c476992010-10-04 21:36:35 +02007739 if (!info->attrs[NL80211_ATTR_PS_STATE])
7740 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007741
7742 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7743
Johannes Berg4c476992010-10-04 21:36:35 +02007744 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7745 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007746
7747 wdev = dev->ieee80211_ptr;
7748
Johannes Berg4c476992010-10-04 21:36:35 +02007749 if (!rdev->ops->set_power_mgmt)
7750 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007751
7752 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7753
7754 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007755 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007756
Hila Gonene35e4d22012-06-27 17:19:42 +03007757 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007758 if (!err)
7759 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007760 return err;
7761}
7762
7763static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7764{
Johannes Berg4c476992010-10-04 21:36:35 +02007765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007766 enum nl80211_ps_state ps_state;
7767 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007768 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007769 struct sk_buff *msg;
7770 void *hdr;
7771 int err;
7772
Kalle Valoffb9eb32010-02-17 17:58:10 +02007773 wdev = dev->ieee80211_ptr;
7774
Johannes Berg4c476992010-10-04 21:36:35 +02007775 if (!rdev->ops->set_power_mgmt)
7776 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007777
7778 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007779 if (!msg)
7780 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007781
Eric W. Biederman15e47302012-09-07 20:12:54 +00007782 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007783 NL80211_CMD_GET_POWER_SAVE);
7784 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007785 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007786 goto free_msg;
7787 }
7788
7789 if (wdev->ps)
7790 ps_state = NL80211_PS_ENABLED;
7791 else
7792 ps_state = NL80211_PS_DISABLED;
7793
David S. Miller9360ffd2012-03-29 04:41:26 -04007794 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7795 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007796
7797 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007798 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007799
Johannes Berg4c476992010-10-04 21:36:35 +02007800 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007801 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007802 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007803 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007804 return err;
7805}
7806
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007807static struct nla_policy
7808nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7809 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7810 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7811 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007812 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7813 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7814 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007815};
7816
Thomas Pedersen84f10702012-07-12 16:17:33 -07007817static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007818 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007819{
7820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007821 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007822 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007823
Johannes Bergd9d8b012012-11-26 12:51:52 +01007824 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007825 return -EINVAL;
7826
Thomas Pedersen84f10702012-07-12 16:17:33 -07007827 if (!rdev->ops->set_cqm_txe_config)
7828 return -EOPNOTSUPP;
7829
7830 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7831 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7832 return -EOPNOTSUPP;
7833
Hila Gonene35e4d22012-06-27 17:19:42 +03007834 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007835}
7836
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007837static int nl80211_set_cqm_rssi(struct genl_info *info,
7838 s32 threshold, u32 hysteresis)
7839{
Johannes Berg4c476992010-10-04 21:36:35 +02007840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007841 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007842 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007843
7844 if (threshold > 0)
7845 return -EINVAL;
7846
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007847 /* disabling - hysteresis should also be zero then */
7848 if (threshold == 0)
7849 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007850
Johannes Berg4c476992010-10-04 21:36:35 +02007851 if (!rdev->ops->set_cqm_rssi_config)
7852 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007853
Johannes Berg074ac8d2010-09-16 14:58:22 +02007854 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007855 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7856 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007857
Hila Gonene35e4d22012-06-27 17:19:42 +03007858 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007859}
7860
7861static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7862{
7863 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7864 struct nlattr *cqm;
7865 int err;
7866
7867 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007868 if (!cqm)
7869 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007870
7871 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7872 nl80211_attr_cqm_policy);
7873 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007874 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007875
7876 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7877 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007878 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7879 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007880
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007881 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7882 }
7883
7884 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7885 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7886 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7887 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7888 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7889 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7890
7891 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7892 }
7893
7894 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007895}
7896
Johannes Berg29cbe682010-12-03 09:20:44 +01007897static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7898{
7899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7900 struct net_device *dev = info->user_ptr[1];
7901 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007902 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007903 int err;
7904
7905 /* start with default */
7906 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007907 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007908
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007909 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007910 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007911 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007912 if (err)
7913 return err;
7914 }
7915
7916 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7917 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7918 return -EINVAL;
7919
Javier Cardonac80d5452010-12-16 17:37:49 -08007920 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7921 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7922
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007923 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7924 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7925 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7926 return -EINVAL;
7927
Marco Porsch9bdbf042013-01-07 16:04:51 +01007928 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7929 setup.beacon_interval =
7930 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7931 if (setup.beacon_interval < 10 ||
7932 setup.beacon_interval > 10000)
7933 return -EINVAL;
7934 }
7935
7936 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7937 setup.dtim_period =
7938 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7939 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7940 return -EINVAL;
7941 }
7942
Javier Cardonac80d5452010-12-16 17:37:49 -08007943 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7944 /* parse additional setup parameters if given */
7945 err = nl80211_parse_mesh_setup(info, &setup);
7946 if (err)
7947 return err;
7948 }
7949
Thomas Pedersend37bb182013-03-04 13:06:13 -08007950 if (setup.user_mpm)
7951 cfg.auto_open_plinks = false;
7952
Johannes Bergcc1d2802012-05-16 23:50:20 +02007953 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007954 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7955 if (err)
7956 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007957 } else {
7958 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007959 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007960 }
7961
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007962 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7963 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7964 int n_rates =
7965 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7966 struct ieee80211_supported_band *sband;
7967
7968 if (!setup.chandef.chan)
7969 return -EINVAL;
7970
7971 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7972
7973 err = ieee80211_get_ratemask(sband, rates, n_rates,
7974 &setup.basic_rates);
7975 if (err)
7976 return err;
7977 }
7978
Javier Cardonac80d5452010-12-16 17:37:49 -08007979 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007980}
7981
7982static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7983{
7984 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7985 struct net_device *dev = info->user_ptr[1];
7986
7987 return cfg80211_leave_mesh(rdev, dev);
7988}
7989
Johannes Bergdfb89c52012-06-27 09:23:48 +02007990#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007991static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7992 struct cfg80211_registered_device *rdev)
7993{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007994 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007995 struct nlattr *nl_pats, *nl_pat;
7996 int i, pat_len;
7997
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007998 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007999 return 0;
8000
8001 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8002 if (!nl_pats)
8003 return -ENOBUFS;
8004
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008005 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008006 nl_pat = nla_nest_start(msg, i + 1);
8007 if (!nl_pat)
8008 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008009 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008010 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008011 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008012 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8013 wowlan->patterns[i].pattern) ||
8014 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008015 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008016 return -ENOBUFS;
8017 nla_nest_end(msg, nl_pat);
8018 }
8019 nla_nest_end(msg, nl_pats);
8020
8021 return 0;
8022}
8023
Johannes Berg2a0e0472013-01-23 22:57:40 +01008024static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8025 struct cfg80211_wowlan_tcp *tcp)
8026{
8027 struct nlattr *nl_tcp;
8028
8029 if (!tcp)
8030 return 0;
8031
8032 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8033 if (!nl_tcp)
8034 return -ENOBUFS;
8035
8036 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8037 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8038 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8039 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8040 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8041 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8042 tcp->payload_len, tcp->payload) ||
8043 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8044 tcp->data_interval) ||
8045 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8046 tcp->wake_len, tcp->wake_data) ||
8047 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8048 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8049 return -ENOBUFS;
8050
8051 if (tcp->payload_seq.len &&
8052 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8053 sizeof(tcp->payload_seq), &tcp->payload_seq))
8054 return -ENOBUFS;
8055
8056 if (tcp->payload_tok.len &&
8057 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8058 sizeof(tcp->payload_tok) + tcp->tokens_size,
8059 &tcp->payload_tok))
8060 return -ENOBUFS;
8061
Johannes Berge248ad32013-05-16 10:24:28 +02008062 nla_nest_end(msg, nl_tcp);
8063
Johannes Berg2a0e0472013-01-23 22:57:40 +01008064 return 0;
8065}
8066
Johannes Bergff1b6e62011-05-04 15:37:28 +02008067static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8068{
8069 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8070 struct sk_buff *msg;
8071 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008072 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008073
Johannes Berg964dc9e2013-06-03 17:25:34 +02008074 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008075 return -EOPNOTSUPP;
8076
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008077 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008078 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008079 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8080 rdev->wiphy.wowlan_config->tcp->payload_len +
8081 rdev->wiphy.wowlan_config->tcp->wake_len +
8082 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008083 }
8084
8085 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008086 if (!msg)
8087 return -ENOMEM;
8088
Eric W. Biederman15e47302012-09-07 20:12:54 +00008089 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008090 NL80211_CMD_GET_WOWLAN);
8091 if (!hdr)
8092 goto nla_put_failure;
8093
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008094 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008095 struct nlattr *nl_wowlan;
8096
8097 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8098 if (!nl_wowlan)
8099 goto nla_put_failure;
8100
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008101 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008102 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008103 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008104 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008105 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008106 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008107 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008108 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008109 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008110 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008111 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008112 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008113 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008114 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8115 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008116
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008117 if (nl80211_send_wowlan_patterns(msg, rdev))
8118 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008119
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008120 if (nl80211_send_wowlan_tcp(msg,
8121 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008122 goto nla_put_failure;
8123
Johannes Bergff1b6e62011-05-04 15:37:28 +02008124 nla_nest_end(msg, nl_wowlan);
8125 }
8126
8127 genlmsg_end(msg, hdr);
8128 return genlmsg_reply(msg, info);
8129
8130nla_put_failure:
8131 nlmsg_free(msg);
8132 return -ENOBUFS;
8133}
8134
Johannes Berg2a0e0472013-01-23 22:57:40 +01008135static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8136 struct nlattr *attr,
8137 struct cfg80211_wowlan *trig)
8138{
8139 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8140 struct cfg80211_wowlan_tcp *cfg;
8141 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8142 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8143 u32 size;
8144 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8145 int err, port;
8146
Johannes Berg964dc9e2013-06-03 17:25:34 +02008147 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008148 return -EINVAL;
8149
8150 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8151 nla_data(attr), nla_len(attr),
8152 nl80211_wowlan_tcp_policy);
8153 if (err)
8154 return err;
8155
8156 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8157 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8158 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8159 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8160 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8161 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8162 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8163 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8164 return -EINVAL;
8165
8166 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008167 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008168 return -EINVAL;
8169
8170 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008171 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008172 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008173 return -EINVAL;
8174
8175 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008176 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008177 return -EINVAL;
8178
8179 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8180 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8181 return -EINVAL;
8182
8183 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8184 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8185
8186 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8187 tokens_size = tokln - sizeof(*tok);
8188
8189 if (!tok->len || tokens_size % tok->len)
8190 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008191 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008192 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008193 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008194 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008195 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008196 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008197 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008198 return -EINVAL;
8199 if (tok->offset + tok->len > data_size)
8200 return -EINVAL;
8201 }
8202
8203 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8204 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008205 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008206 return -EINVAL;
8207 if (seq->len == 0 || seq->len > 4)
8208 return -EINVAL;
8209 if (seq->len + seq->offset > data_size)
8210 return -EINVAL;
8211 }
8212
8213 size = sizeof(*cfg);
8214 size += data_size;
8215 size += wake_size + wake_mask_size;
8216 size += tokens_size;
8217
8218 cfg = kzalloc(size, GFP_KERNEL);
8219 if (!cfg)
8220 return -ENOMEM;
8221 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8222 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8223 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8224 ETH_ALEN);
8225 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8226 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8227 else
8228 port = 0;
8229#ifdef CONFIG_INET
8230 /* allocate a socket and port for it and use it */
8231 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8232 IPPROTO_TCP, &cfg->sock, 1);
8233 if (err) {
8234 kfree(cfg);
8235 return err;
8236 }
8237 if (inet_csk_get_port(cfg->sock->sk, port)) {
8238 sock_release(cfg->sock);
8239 kfree(cfg);
8240 return -EADDRINUSE;
8241 }
8242 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8243#else
8244 if (!port) {
8245 kfree(cfg);
8246 return -EINVAL;
8247 }
8248 cfg->src_port = port;
8249#endif
8250
8251 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8252 cfg->payload_len = data_size;
8253 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8254 memcpy((void *)cfg->payload,
8255 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8256 data_size);
8257 if (seq)
8258 cfg->payload_seq = *seq;
8259 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8260 cfg->wake_len = wake_size;
8261 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8262 memcpy((void *)cfg->wake_data,
8263 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8264 wake_size);
8265 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8266 data_size + wake_size;
8267 memcpy((void *)cfg->wake_mask,
8268 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8269 wake_mask_size);
8270 if (tok) {
8271 cfg->tokens_size = tokens_size;
8272 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8273 }
8274
8275 trig->tcp = cfg;
8276
8277 return 0;
8278}
8279
Johannes Bergff1b6e62011-05-04 15:37:28 +02008280static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8281{
8282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8283 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008284 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008285 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008286 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008287 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008288 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008289
Johannes Berg964dc9e2013-06-03 17:25:34 +02008290 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008291 return -EOPNOTSUPP;
8292
Johannes Bergae33bd82012-07-12 16:25:02 +02008293 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8294 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008295 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008296 goto set_wakeup;
8297 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008298
8299 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8300 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8301 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8302 nl80211_wowlan_policy);
8303 if (err)
8304 return err;
8305
8306 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8307 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8308 return -EINVAL;
8309 new_triggers.any = true;
8310 }
8311
8312 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8313 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8314 return -EINVAL;
8315 new_triggers.disconnect = true;
8316 }
8317
8318 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8319 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8320 return -EINVAL;
8321 new_triggers.magic_pkt = true;
8322 }
8323
Johannes Berg77dbbb12011-07-13 10:48:55 +02008324 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8325 return -EINVAL;
8326
8327 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8328 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8329 return -EINVAL;
8330 new_triggers.gtk_rekey_failure = true;
8331 }
8332
8333 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8334 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8335 return -EINVAL;
8336 new_triggers.eap_identity_req = true;
8337 }
8338
8339 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8340 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8341 return -EINVAL;
8342 new_triggers.four_way_handshake = true;
8343 }
8344
8345 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8346 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8347 return -EINVAL;
8348 new_triggers.rfkill_release = true;
8349 }
8350
Johannes Bergff1b6e62011-05-04 15:37:28 +02008351 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8352 struct nlattr *pat;
8353 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008354 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008355 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008356
8357 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8358 rem)
8359 n_patterns++;
8360 if (n_patterns > wowlan->n_patterns)
8361 return -EINVAL;
8362
8363 new_triggers.patterns = kcalloc(n_patterns,
8364 sizeof(new_triggers.patterns[0]),
8365 GFP_KERNEL);
8366 if (!new_triggers.patterns)
8367 return -ENOMEM;
8368
8369 new_triggers.n_patterns = n_patterns;
8370 i = 0;
8371
8372 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8373 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008374 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8375 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008376 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008377 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8378 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008379 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008380 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008381 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008382 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008383 goto error;
8384 if (pat_len > wowlan->pattern_max_len ||
8385 pat_len < wowlan->pattern_min_len)
8386 goto error;
8387
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008388 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008389 pkt_offset = 0;
8390 else
8391 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008392 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008393 if (pkt_offset > wowlan->max_pkt_offset)
8394 goto error;
8395 new_triggers.patterns[i].pkt_offset = pkt_offset;
8396
Johannes Bergff1b6e62011-05-04 15:37:28 +02008397 new_triggers.patterns[i].mask =
8398 kmalloc(mask_len + pat_len, GFP_KERNEL);
8399 if (!new_triggers.patterns[i].mask) {
8400 err = -ENOMEM;
8401 goto error;
8402 }
8403 new_triggers.patterns[i].pattern =
8404 new_triggers.patterns[i].mask + mask_len;
8405 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008406 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008407 mask_len);
8408 new_triggers.patterns[i].pattern_len = pat_len;
8409 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008410 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008411 pat_len);
8412 i++;
8413 }
8414 }
8415
Johannes Berg2a0e0472013-01-23 22:57:40 +01008416 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8417 err = nl80211_parse_wowlan_tcp(
8418 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8419 &new_triggers);
8420 if (err)
8421 goto error;
8422 }
8423
Johannes Bergae33bd82012-07-12 16:25:02 +02008424 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8425 if (!ntrig) {
8426 err = -ENOMEM;
8427 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008428 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008429 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008430 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008431
Johannes Bergae33bd82012-07-12 16:25:02 +02008432 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008433 if (rdev->ops->set_wakeup &&
8434 prev_enabled != !!rdev->wiphy.wowlan_config)
8435 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008436
Johannes Bergff1b6e62011-05-04 15:37:28 +02008437 return 0;
8438 error:
8439 for (i = 0; i < new_triggers.n_patterns; i++)
8440 kfree(new_triggers.patterns[i].mask);
8441 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008442 if (new_triggers.tcp && new_triggers.tcp->sock)
8443 sock_release(new_triggers.tcp->sock);
8444 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008445 return err;
8446}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008447#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008448
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07008449static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8450 struct cfg80211_registered_device *rdev)
8451{
8452 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8453 int i, j, pat_len;
8454 struct cfg80211_coalesce_rules *rule;
8455
8456 if (!rdev->coalesce->n_rules)
8457 return 0;
8458
8459 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8460 if (!nl_rules)
8461 return -ENOBUFS;
8462
8463 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8464 nl_rule = nla_nest_start(msg, i + 1);
8465 if (!nl_rule)
8466 return -ENOBUFS;
8467
8468 rule = &rdev->coalesce->rules[i];
8469 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8470 rule->delay))
8471 return -ENOBUFS;
8472
8473 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8474 rule->condition))
8475 return -ENOBUFS;
8476
8477 nl_pats = nla_nest_start(msg,
8478 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8479 if (!nl_pats)
8480 return -ENOBUFS;
8481
8482 for (j = 0; j < rule->n_patterns; j++) {
8483 nl_pat = nla_nest_start(msg, j + 1);
8484 if (!nl_pat)
8485 return -ENOBUFS;
8486 pat_len = rule->patterns[j].pattern_len;
8487 if (nla_put(msg, NL80211_PKTPAT_MASK,
8488 DIV_ROUND_UP(pat_len, 8),
8489 rule->patterns[j].mask) ||
8490 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8491 rule->patterns[j].pattern) ||
8492 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8493 rule->patterns[j].pkt_offset))
8494 return -ENOBUFS;
8495 nla_nest_end(msg, nl_pat);
8496 }
8497 nla_nest_end(msg, nl_pats);
8498 nla_nest_end(msg, nl_rule);
8499 }
8500 nla_nest_end(msg, nl_rules);
8501
8502 return 0;
8503}
8504
8505static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8506{
8507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8508 struct sk_buff *msg;
8509 void *hdr;
8510
8511 if (!rdev->wiphy.coalesce)
8512 return -EOPNOTSUPP;
8513
8514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8515 if (!msg)
8516 return -ENOMEM;
8517
8518 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8519 NL80211_CMD_GET_COALESCE);
8520 if (!hdr)
8521 goto nla_put_failure;
8522
8523 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8524 goto nla_put_failure;
8525
8526 genlmsg_end(msg, hdr);
8527 return genlmsg_reply(msg, info);
8528
8529nla_put_failure:
8530 nlmsg_free(msg);
8531 return -ENOBUFS;
8532}
8533
8534void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8535{
8536 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8537 int i, j;
8538 struct cfg80211_coalesce_rules *rule;
8539
8540 if (!coalesce)
8541 return;
8542
8543 for (i = 0; i < coalesce->n_rules; i++) {
8544 rule = &coalesce->rules[i];
8545 for (j = 0; j < rule->n_patterns; j++)
8546 kfree(rule->patterns[j].mask);
8547 kfree(rule->patterns);
8548 }
8549 kfree(coalesce->rules);
8550 kfree(coalesce);
8551 rdev->coalesce = NULL;
8552}
8553
8554static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8555 struct nlattr *rule,
8556 struct cfg80211_coalesce_rules *new_rule)
8557{
8558 int err, i;
8559 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8560 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8561 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8562 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8563
8564 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8565 nla_len(rule), nl80211_coalesce_policy);
8566 if (err)
8567 return err;
8568
8569 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8570 new_rule->delay =
8571 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8572 if (new_rule->delay > coalesce->max_delay)
8573 return -EINVAL;
8574
8575 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8576 new_rule->condition =
8577 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8578 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8579 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8580 return -EINVAL;
8581
8582 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8583 return -EINVAL;
8584
8585 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8586 rem)
8587 n_patterns++;
8588 if (n_patterns > coalesce->n_patterns)
8589 return -EINVAL;
8590
8591 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8592 GFP_KERNEL);
8593 if (!new_rule->patterns)
8594 return -ENOMEM;
8595
8596 new_rule->n_patterns = n_patterns;
8597 i = 0;
8598
8599 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8600 rem) {
8601 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8602 nla_len(pat), NULL);
8603 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8604 !pat_tb[NL80211_PKTPAT_PATTERN])
8605 return -EINVAL;
8606 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8607 mask_len = DIV_ROUND_UP(pat_len, 8);
8608 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8609 return -EINVAL;
8610 if (pat_len > coalesce->pattern_max_len ||
8611 pat_len < coalesce->pattern_min_len)
8612 return -EINVAL;
8613
8614 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8615 pkt_offset = 0;
8616 else
8617 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8618 if (pkt_offset > coalesce->max_pkt_offset)
8619 return -EINVAL;
8620 new_rule->patterns[i].pkt_offset = pkt_offset;
8621
8622 new_rule->patterns[i].mask =
8623 kmalloc(mask_len + pat_len, GFP_KERNEL);
8624 if (!new_rule->patterns[i].mask)
8625 return -ENOMEM;
8626 new_rule->patterns[i].pattern =
8627 new_rule->patterns[i].mask + mask_len;
8628 memcpy(new_rule->patterns[i].mask,
8629 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8630 new_rule->patterns[i].pattern_len = pat_len;
8631 memcpy(new_rule->patterns[i].pattern,
8632 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8633 i++;
8634 }
8635
8636 return 0;
8637}
8638
8639static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8640{
8641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8642 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8643 struct cfg80211_coalesce new_coalesce = {};
8644 struct cfg80211_coalesce *n_coalesce;
8645 int err, rem_rule, n_rules = 0, i, j;
8646 struct nlattr *rule;
8647 struct cfg80211_coalesce_rules *tmp_rule;
8648
8649 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8650 return -EOPNOTSUPP;
8651
8652 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8653 cfg80211_rdev_free_coalesce(rdev);
8654 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8655 return 0;
8656 }
8657
8658 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8659 rem_rule)
8660 n_rules++;
8661 if (n_rules > coalesce->n_rules)
8662 return -EINVAL;
8663
8664 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8665 GFP_KERNEL);
8666 if (!new_coalesce.rules)
8667 return -ENOMEM;
8668
8669 new_coalesce.n_rules = n_rules;
8670 i = 0;
8671
8672 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8673 rem_rule) {
8674 err = nl80211_parse_coalesce_rule(rdev, rule,
8675 &new_coalesce.rules[i]);
8676 if (err)
8677 goto error;
8678
8679 i++;
8680 }
8681
8682 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8683 if (err)
8684 goto error;
8685
8686 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8687 if (!n_coalesce) {
8688 err = -ENOMEM;
8689 goto error;
8690 }
8691 cfg80211_rdev_free_coalesce(rdev);
8692 rdev->coalesce = n_coalesce;
8693
8694 return 0;
8695error:
8696 for (i = 0; i < new_coalesce.n_rules; i++) {
8697 tmp_rule = &new_coalesce.rules[i];
8698 for (j = 0; j < tmp_rule->n_patterns; j++)
8699 kfree(tmp_rule->patterns[j].mask);
8700 kfree(tmp_rule->patterns);
8701 }
8702 kfree(new_coalesce.rules);
8703
8704 return err;
8705}
8706
Johannes Berge5497d72011-07-05 16:35:40 +02008707static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8708{
8709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8710 struct net_device *dev = info->user_ptr[1];
8711 struct wireless_dev *wdev = dev->ieee80211_ptr;
8712 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8713 struct cfg80211_gtk_rekey_data rekey_data;
8714 int err;
8715
8716 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8717 return -EINVAL;
8718
8719 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8720 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8721 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8722 nl80211_rekey_policy);
8723 if (err)
8724 return err;
8725
8726 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8727 return -ERANGE;
8728 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8729 return -ERANGE;
8730 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8731 return -ERANGE;
8732
8733 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8734 NL80211_KEK_LEN);
8735 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8736 NL80211_KCK_LEN);
8737 memcpy(rekey_data.replay_ctr,
8738 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8739 NL80211_REPLAY_CTR_LEN);
8740
8741 wdev_lock(wdev);
8742 if (!wdev->current_bss) {
8743 err = -ENOTCONN;
8744 goto out;
8745 }
8746
8747 if (!rdev->ops->set_rekey_data) {
8748 err = -EOPNOTSUPP;
8749 goto out;
8750 }
8751
Hila Gonene35e4d22012-06-27 17:19:42 +03008752 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008753 out:
8754 wdev_unlock(wdev);
8755 return err;
8756}
8757
Johannes Berg28946da2011-11-04 11:18:12 +01008758static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8759 struct genl_info *info)
8760{
8761 struct net_device *dev = info->user_ptr[1];
8762 struct wireless_dev *wdev = dev->ieee80211_ptr;
8763
8764 if (wdev->iftype != NL80211_IFTYPE_AP &&
8765 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8766 return -EINVAL;
8767
Eric W. Biederman15e47302012-09-07 20:12:54 +00008768 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008769 return -EBUSY;
8770
Eric W. Biederman15e47302012-09-07 20:12:54 +00008771 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008772 return 0;
8773}
8774
Johannes Berg7f6cf312011-11-04 11:18:15 +01008775static int nl80211_probe_client(struct sk_buff *skb,
8776 struct genl_info *info)
8777{
8778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8779 struct net_device *dev = info->user_ptr[1];
8780 struct wireless_dev *wdev = dev->ieee80211_ptr;
8781 struct sk_buff *msg;
8782 void *hdr;
8783 const u8 *addr;
8784 u64 cookie;
8785 int err;
8786
8787 if (wdev->iftype != NL80211_IFTYPE_AP &&
8788 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8789 return -EOPNOTSUPP;
8790
8791 if (!info->attrs[NL80211_ATTR_MAC])
8792 return -EINVAL;
8793
8794 if (!rdev->ops->probe_client)
8795 return -EOPNOTSUPP;
8796
8797 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8798 if (!msg)
8799 return -ENOMEM;
8800
Eric W. Biederman15e47302012-09-07 20:12:54 +00008801 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008802 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008803 if (!hdr) {
8804 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008805 goto free_msg;
8806 }
8807
8808 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8809
Hila Gonene35e4d22012-06-27 17:19:42 +03008810 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008811 if (err)
8812 goto free_msg;
8813
David S. Miller9360ffd2012-03-29 04:41:26 -04008814 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8815 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008816
8817 genlmsg_end(msg, hdr);
8818
8819 return genlmsg_reply(msg, info);
8820
8821 nla_put_failure:
8822 err = -ENOBUFS;
8823 free_msg:
8824 nlmsg_free(msg);
8825 return err;
8826}
8827
Johannes Berg5e760232011-11-04 11:18:17 +01008828static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8829{
8830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008831 struct cfg80211_beacon_registration *reg, *nreg;
8832 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008833
8834 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8835 return -EOPNOTSUPP;
8836
Ben Greear37c73b52012-10-26 14:49:25 -07008837 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8838 if (!nreg)
8839 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008840
Ben Greear37c73b52012-10-26 14:49:25 -07008841 /* First, check if already registered. */
8842 spin_lock_bh(&rdev->beacon_registrations_lock);
8843 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8844 if (reg->nlportid == info->snd_portid) {
8845 rv = -EALREADY;
8846 goto out_err;
8847 }
8848 }
8849 /* Add it to the list */
8850 nreg->nlportid = info->snd_portid;
8851 list_add(&nreg->list, &rdev->beacon_registrations);
8852
8853 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008854
8855 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008856out_err:
8857 spin_unlock_bh(&rdev->beacon_registrations_lock);
8858 kfree(nreg);
8859 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008860}
8861
Johannes Berg98104fde2012-06-16 00:19:54 +02008862static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8863{
8864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8865 struct wireless_dev *wdev = info->user_ptr[1];
8866 int err;
8867
8868 if (!rdev->ops->start_p2p_device)
8869 return -EOPNOTSUPP;
8870
8871 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8872 return -EOPNOTSUPP;
8873
8874 if (wdev->p2p_started)
8875 return 0;
8876
Johannes Berg98104fde2012-06-16 00:19:54 +02008877 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008878 if (err)
8879 return err;
8880
Johannes Bergeeb126e2012-10-23 15:16:50 +02008881 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008882 if (err)
8883 return err;
8884
8885 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008886 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008887
8888 return 0;
8889}
8890
8891static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8892{
8893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8894 struct wireless_dev *wdev = info->user_ptr[1];
8895
8896 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8897 return -EOPNOTSUPP;
8898
8899 if (!rdev->ops->stop_p2p_device)
8900 return -EOPNOTSUPP;
8901
Johannes Bergf9f47522013-03-19 15:04:07 +01008902 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008903
8904 return 0;
8905}
8906
Johannes Berg3713b4e2013-02-14 16:19:38 +01008907static int nl80211_get_protocol_features(struct sk_buff *skb,
8908 struct genl_info *info)
8909{
8910 void *hdr;
8911 struct sk_buff *msg;
8912
8913 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8914 if (!msg)
8915 return -ENOMEM;
8916
8917 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8918 NL80211_CMD_GET_PROTOCOL_FEATURES);
8919 if (!hdr)
8920 goto nla_put_failure;
8921
8922 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8923 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8924 goto nla_put_failure;
8925
8926 genlmsg_end(msg, hdr);
8927 return genlmsg_reply(msg, info);
8928
8929 nla_put_failure:
8930 kfree_skb(msg);
8931 return -ENOBUFS;
8932}
8933
Jouni Malinen355199e2013-02-27 17:14:27 +02008934static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8935{
8936 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8937 struct cfg80211_update_ft_ies_params ft_params;
8938 struct net_device *dev = info->user_ptr[1];
8939
8940 if (!rdev->ops->update_ft_ies)
8941 return -EOPNOTSUPP;
8942
8943 if (!info->attrs[NL80211_ATTR_MDID] ||
8944 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8945 return -EINVAL;
8946
8947 memset(&ft_params, 0, sizeof(ft_params));
8948 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8949 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8950 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8951
8952 return rdev_update_ft_ies(rdev, dev, &ft_params);
8953}
8954
Arend van Spriel5de17982013-04-18 15:49:00 +02008955static int nl80211_crit_protocol_start(struct sk_buff *skb,
8956 struct genl_info *info)
8957{
8958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8959 struct wireless_dev *wdev = info->user_ptr[1];
8960 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8961 u16 duration;
8962 int ret;
8963
8964 if (!rdev->ops->crit_proto_start)
8965 return -EOPNOTSUPP;
8966
8967 if (WARN_ON(!rdev->ops->crit_proto_stop))
8968 return -EINVAL;
8969
8970 if (rdev->crit_proto_nlportid)
8971 return -EBUSY;
8972
8973 /* determine protocol if provided */
8974 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8975 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8976
8977 if (proto >= NUM_NL80211_CRIT_PROTO)
8978 return -EINVAL;
8979
8980 /* timeout must be provided */
8981 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8982 return -EINVAL;
8983
8984 duration =
8985 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8986
8987 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8988 return -ERANGE;
8989
8990 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8991 if (!ret)
8992 rdev->crit_proto_nlportid = info->snd_portid;
8993
8994 return ret;
8995}
8996
8997static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8998 struct genl_info *info)
8999{
9000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9001 struct wireless_dev *wdev = info->user_ptr[1];
9002
9003 if (!rdev->ops->crit_proto_stop)
9004 return -EOPNOTSUPP;
9005
9006 if (rdev->crit_proto_nlportid) {
9007 rdev->crit_proto_nlportid = 0;
9008 rdev_crit_proto_stop(rdev, wdev);
9009 }
9010 return 0;
9011}
9012
Johannes Bergad7e7182013-11-13 13:37:47 +01009013static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9014{
9015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9016 struct wireless_dev *wdev =
9017 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9018 int i, err;
9019 u32 vid, subcmd;
9020
9021 if (!rdev->wiphy.vendor_commands)
9022 return -EOPNOTSUPP;
9023
9024 if (IS_ERR(wdev)) {
9025 err = PTR_ERR(wdev);
9026 if (err != -EINVAL)
9027 return err;
9028 wdev = NULL;
9029 } else if (wdev->wiphy != &rdev->wiphy) {
9030 return -EINVAL;
9031 }
9032
9033 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9034 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9035 return -EINVAL;
9036
9037 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9038 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9039 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9040 const struct wiphy_vendor_command *vcmd;
9041 void *data = NULL;
9042 int len = 0;
9043
9044 vcmd = &rdev->wiphy.vendor_commands[i];
9045
9046 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9047 continue;
9048
9049 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9050 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9051 if (!wdev)
9052 return -EINVAL;
9053 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9054 !wdev->netdev)
9055 return -EINVAL;
9056
9057 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9058 if (wdev->netdev &&
9059 !netif_running(wdev->netdev))
9060 return -ENETDOWN;
9061 if (!wdev->netdev && !wdev->p2p_started)
9062 return -ENETDOWN;
9063 }
9064 } else {
9065 wdev = NULL;
9066 }
9067
9068 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9069 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9070 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9071 }
9072
9073 rdev->cur_cmd_info = info;
9074 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9075 data, len);
9076 rdev->cur_cmd_info = NULL;
9077 return err;
9078 }
9079
9080 return -EOPNOTSUPP;
9081}
9082
9083struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9084 enum nl80211_commands cmd,
9085 enum nl80211_attrs attr,
9086 int approxlen)
9087{
9088 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9089
9090 if (WARN_ON(!rdev->cur_cmd_info))
9091 return NULL;
9092
9093 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9094 rdev->cur_cmd_info->snd_portid,
9095 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009096 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009097}
9098EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9099
9100int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9101{
9102 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9103 void *hdr = ((void **)skb->cb)[1];
9104 struct nlattr *data = ((void **)skb->cb)[2];
9105
9106 if (WARN_ON(!rdev->cur_cmd_info)) {
9107 kfree_skb(skb);
9108 return -EINVAL;
9109 }
9110
9111 nla_nest_end(skb, data);
9112 genlmsg_end(skb, hdr);
9113 return genlmsg_reply(skb, rdev->cur_cmd_info);
9114}
9115EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9116
9117
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009118static int nl80211_set_qos_map(struct sk_buff *skb,
9119 struct genl_info *info)
9120{
9121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9122 struct cfg80211_qos_map *qos_map = NULL;
9123 struct net_device *dev = info->user_ptr[1];
9124 u8 *pos, len, num_des, des_len, des;
9125 int ret;
9126
9127 if (!rdev->ops->set_qos_map)
9128 return -EOPNOTSUPP;
9129
9130 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9131 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9132 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9133
9134 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9135 len > IEEE80211_QOS_MAP_LEN_MAX)
9136 return -EINVAL;
9137
9138 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9139 if (!qos_map)
9140 return -ENOMEM;
9141
9142 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9143 if (num_des) {
9144 des_len = num_des *
9145 sizeof(struct cfg80211_dscp_exception);
9146 memcpy(qos_map->dscp_exception, pos, des_len);
9147 qos_map->num_des = num_des;
9148 for (des = 0; des < num_des; des++) {
9149 if (qos_map->dscp_exception[des].up > 7) {
9150 kfree(qos_map);
9151 return -EINVAL;
9152 }
9153 }
9154 pos += des_len;
9155 }
9156 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9157 }
9158
9159 wdev_lock(dev->ieee80211_ptr);
9160 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9161 if (!ret)
9162 ret = rdev_set_qos_map(rdev, dev, qos_map);
9163 wdev_unlock(dev->ieee80211_ptr);
9164
9165 kfree(qos_map);
9166 return ret;
9167}
9168
Johannes Berg4c476992010-10-04 21:36:35 +02009169#define NL80211_FLAG_NEED_WIPHY 0x01
9170#define NL80211_FLAG_NEED_NETDEV 0x02
9171#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009172#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9173#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9174 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009175#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009176/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009177#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9178 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009179
Johannes Bergf84f7712013-11-14 17:14:45 +01009180static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009181 struct genl_info *info)
9182{
9183 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009184 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009185 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009186 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9187
9188 if (rtnl)
9189 rtnl_lock();
9190
9191 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009192 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009193 if (IS_ERR(rdev)) {
9194 if (rtnl)
9195 rtnl_unlock();
9196 return PTR_ERR(rdev);
9197 }
9198 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009199 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9200 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009201 ASSERT_RTNL();
9202
Johannes Berg89a54e42012-06-15 14:33:17 +02009203 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9204 info->attrs);
9205 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009206 if (rtnl)
9207 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009208 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009209 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009210
Johannes Berg89a54e42012-06-15 14:33:17 +02009211 dev = wdev->netdev;
9212 rdev = wiphy_to_dev(wdev->wiphy);
9213
Johannes Berg1bf614e2012-06-15 15:23:36 +02009214 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9215 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009216 if (rtnl)
9217 rtnl_unlock();
9218 return -EINVAL;
9219 }
9220
9221 info->user_ptr[1] = dev;
9222 } else {
9223 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009224 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009225
Johannes Berg1bf614e2012-06-15 15:23:36 +02009226 if (dev) {
9227 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9228 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009229 if (rtnl)
9230 rtnl_unlock();
9231 return -ENETDOWN;
9232 }
9233
9234 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009235 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9236 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009237 if (rtnl)
9238 rtnl_unlock();
9239 return -ENETDOWN;
9240 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009241 }
9242
Johannes Berg4c476992010-10-04 21:36:35 +02009243 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009244 }
9245
9246 return 0;
9247}
9248
Johannes Bergf84f7712013-11-14 17:14:45 +01009249static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009250 struct genl_info *info)
9251{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009252 if (info->user_ptr[1]) {
9253 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9254 struct wireless_dev *wdev = info->user_ptr[1];
9255
9256 if (wdev->netdev)
9257 dev_put(wdev->netdev);
9258 } else {
9259 dev_put(info->user_ptr[1]);
9260 }
9261 }
Johannes Berg4c476992010-10-04 21:36:35 +02009262 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9263 rtnl_unlock();
9264}
9265
Johannes Berg4534de82013-11-14 17:14:46 +01009266static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009267 {
9268 .cmd = NL80211_CMD_GET_WIPHY,
9269 .doit = nl80211_get_wiphy,
9270 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009271 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009272 .policy = nl80211_policy,
9273 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009274 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9275 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009276 },
9277 {
9278 .cmd = NL80211_CMD_SET_WIPHY,
9279 .doit = nl80211_set_wiphy,
9280 .policy = nl80211_policy,
9281 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009282 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009283 },
9284 {
9285 .cmd = NL80211_CMD_GET_INTERFACE,
9286 .doit = nl80211_get_interface,
9287 .dumpit = nl80211_dump_interface,
9288 .policy = nl80211_policy,
9289 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009290 .internal_flags = NL80211_FLAG_NEED_WDEV |
9291 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009292 },
9293 {
9294 .cmd = NL80211_CMD_SET_INTERFACE,
9295 .doit = nl80211_set_interface,
9296 .policy = nl80211_policy,
9297 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009298 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9299 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009300 },
9301 {
9302 .cmd = NL80211_CMD_NEW_INTERFACE,
9303 .doit = nl80211_new_interface,
9304 .policy = nl80211_policy,
9305 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009306 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9307 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009308 },
9309 {
9310 .cmd = NL80211_CMD_DEL_INTERFACE,
9311 .doit = nl80211_del_interface,
9312 .policy = nl80211_policy,
9313 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009314 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009315 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009316 },
Johannes Berg41ade002007-12-19 02:03:29 +01009317 {
9318 .cmd = NL80211_CMD_GET_KEY,
9319 .doit = nl80211_get_key,
9320 .policy = nl80211_policy,
9321 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009322 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009323 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009324 },
9325 {
9326 .cmd = NL80211_CMD_SET_KEY,
9327 .doit = nl80211_set_key,
9328 .policy = nl80211_policy,
9329 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009330 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009331 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009332 },
9333 {
9334 .cmd = NL80211_CMD_NEW_KEY,
9335 .doit = nl80211_new_key,
9336 .policy = nl80211_policy,
9337 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009338 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009339 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009340 },
9341 {
9342 .cmd = NL80211_CMD_DEL_KEY,
9343 .doit = nl80211_del_key,
9344 .policy = nl80211_policy,
9345 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009346 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009347 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009348 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009349 {
9350 .cmd = NL80211_CMD_SET_BEACON,
9351 .policy = nl80211_policy,
9352 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009353 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009355 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009356 },
9357 {
Johannes Berg88600202012-02-13 15:17:18 +01009358 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009359 .policy = nl80211_policy,
9360 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009361 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009363 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009364 },
9365 {
Johannes Berg88600202012-02-13 15:17:18 +01009366 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009367 .policy = nl80211_policy,
9368 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009369 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009371 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009372 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009373 {
9374 .cmd = NL80211_CMD_GET_STATION,
9375 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009376 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009377 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009378 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9379 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009380 },
9381 {
9382 .cmd = NL80211_CMD_SET_STATION,
9383 .doit = nl80211_set_station,
9384 .policy = nl80211_policy,
9385 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009387 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009388 },
9389 {
9390 .cmd = NL80211_CMD_NEW_STATION,
9391 .doit = nl80211_new_station,
9392 .policy = nl80211_policy,
9393 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009395 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009396 },
9397 {
9398 .cmd = NL80211_CMD_DEL_STATION,
9399 .doit = nl80211_del_station,
9400 .policy = nl80211_policy,
9401 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009403 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009404 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009405 {
9406 .cmd = NL80211_CMD_GET_MPATH,
9407 .doit = nl80211_get_mpath,
9408 .dumpit = nl80211_dump_mpath,
9409 .policy = nl80211_policy,
9410 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009412 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009413 },
9414 {
9415 .cmd = NL80211_CMD_SET_MPATH,
9416 .doit = nl80211_set_mpath,
9417 .policy = nl80211_policy,
9418 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009420 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009421 },
9422 {
9423 .cmd = NL80211_CMD_NEW_MPATH,
9424 .doit = nl80211_new_mpath,
9425 .policy = nl80211_policy,
9426 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009428 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009429 },
9430 {
9431 .cmd = NL80211_CMD_DEL_MPATH,
9432 .doit = nl80211_del_mpath,
9433 .policy = nl80211_policy,
9434 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009436 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009437 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009438 {
9439 .cmd = NL80211_CMD_SET_BSS,
9440 .doit = nl80211_set_bss,
9441 .policy = nl80211_policy,
9442 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009444 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009445 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009446 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009447 .cmd = NL80211_CMD_GET_REG,
9448 .doit = nl80211_get_reg,
9449 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009450 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009451 /* can be retrieved by unprivileged users */
9452 },
9453 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009454 .cmd = NL80211_CMD_SET_REG,
9455 .doit = nl80211_set_reg,
9456 .policy = nl80211_policy,
9457 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009458 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009459 },
9460 {
9461 .cmd = NL80211_CMD_REQ_SET_REG,
9462 .doit = nl80211_req_set_reg,
9463 .policy = nl80211_policy,
9464 .flags = GENL_ADMIN_PERM,
9465 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009466 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009467 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9468 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009469 .policy = nl80211_policy,
9470 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009472 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009473 },
9474 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009475 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9476 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009477 .policy = nl80211_policy,
9478 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009479 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009480 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009481 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009482 {
Johannes Berg2a519312009-02-10 21:25:55 +01009483 .cmd = NL80211_CMD_TRIGGER_SCAN,
9484 .doit = nl80211_trigger_scan,
9485 .policy = nl80211_policy,
9486 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009487 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009488 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009489 },
9490 {
9491 .cmd = NL80211_CMD_GET_SCAN,
9492 .policy = nl80211_policy,
9493 .dumpit = nl80211_dump_scan,
9494 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009495 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009496 .cmd = NL80211_CMD_START_SCHED_SCAN,
9497 .doit = nl80211_start_sched_scan,
9498 .policy = nl80211_policy,
9499 .flags = GENL_ADMIN_PERM,
9500 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9501 NL80211_FLAG_NEED_RTNL,
9502 },
9503 {
9504 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9505 .doit = nl80211_stop_sched_scan,
9506 .policy = nl80211_policy,
9507 .flags = GENL_ADMIN_PERM,
9508 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9509 NL80211_FLAG_NEED_RTNL,
9510 },
9511 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009512 .cmd = NL80211_CMD_AUTHENTICATE,
9513 .doit = nl80211_authenticate,
9514 .policy = nl80211_policy,
9515 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009516 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009517 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009518 },
9519 {
9520 .cmd = NL80211_CMD_ASSOCIATE,
9521 .doit = nl80211_associate,
9522 .policy = nl80211_policy,
9523 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009524 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009525 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009526 },
9527 {
9528 .cmd = NL80211_CMD_DEAUTHENTICATE,
9529 .doit = nl80211_deauthenticate,
9530 .policy = nl80211_policy,
9531 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009532 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009533 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009534 },
9535 {
9536 .cmd = NL80211_CMD_DISASSOCIATE,
9537 .doit = nl80211_disassociate,
9538 .policy = nl80211_policy,
9539 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009540 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009541 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009542 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009543 {
9544 .cmd = NL80211_CMD_JOIN_IBSS,
9545 .doit = nl80211_join_ibss,
9546 .policy = nl80211_policy,
9547 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009548 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009549 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009550 },
9551 {
9552 .cmd = NL80211_CMD_LEAVE_IBSS,
9553 .doit = nl80211_leave_ibss,
9554 .policy = nl80211_policy,
9555 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009556 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009557 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009558 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009559#ifdef CONFIG_NL80211_TESTMODE
9560 {
9561 .cmd = NL80211_CMD_TESTMODE,
9562 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009563 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009564 .policy = nl80211_policy,
9565 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009566 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9567 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009568 },
9569#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009570 {
9571 .cmd = NL80211_CMD_CONNECT,
9572 .doit = nl80211_connect,
9573 .policy = nl80211_policy,
9574 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009575 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009576 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009577 },
9578 {
9579 .cmd = NL80211_CMD_DISCONNECT,
9580 .doit = nl80211_disconnect,
9581 .policy = nl80211_policy,
9582 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009583 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009584 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009585 },
Johannes Berg463d0182009-07-14 00:33:35 +02009586 {
9587 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9588 .doit = nl80211_wiphy_netns,
9589 .policy = nl80211_policy,
9590 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009591 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9592 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009593 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009594 {
9595 .cmd = NL80211_CMD_GET_SURVEY,
9596 .policy = nl80211_policy,
9597 .dumpit = nl80211_dump_survey,
9598 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009599 {
9600 .cmd = NL80211_CMD_SET_PMKSA,
9601 .doit = nl80211_setdel_pmksa,
9602 .policy = nl80211_policy,
9603 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009604 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009605 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009606 },
9607 {
9608 .cmd = NL80211_CMD_DEL_PMKSA,
9609 .doit = nl80211_setdel_pmksa,
9610 .policy = nl80211_policy,
9611 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009612 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009613 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009614 },
9615 {
9616 .cmd = NL80211_CMD_FLUSH_PMKSA,
9617 .doit = nl80211_flush_pmksa,
9618 .policy = nl80211_policy,
9619 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009620 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009621 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009622 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009623 {
9624 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9625 .doit = nl80211_remain_on_channel,
9626 .policy = nl80211_policy,
9627 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009628 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009629 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009630 },
9631 {
9632 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9633 .doit = nl80211_cancel_remain_on_channel,
9634 .policy = nl80211_policy,
9635 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009636 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009637 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009638 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009639 {
9640 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9641 .doit = nl80211_set_tx_bitrate_mask,
9642 .policy = nl80211_policy,
9643 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009644 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9645 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009646 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009647 {
Johannes Berg2e161f782010-08-12 15:38:38 +02009648 .cmd = NL80211_CMD_REGISTER_FRAME,
9649 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009650 .policy = nl80211_policy,
9651 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009652 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009653 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009654 },
9655 {
Johannes Berg2e161f782010-08-12 15:38:38 +02009656 .cmd = NL80211_CMD_FRAME,
9657 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009658 .policy = nl80211_policy,
9659 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009660 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009661 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009662 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009663 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009664 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9665 .doit = nl80211_tx_mgmt_cancel_wait,
9666 .policy = nl80211_policy,
9667 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009668 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009669 NL80211_FLAG_NEED_RTNL,
9670 },
9671 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009672 .cmd = NL80211_CMD_SET_POWER_SAVE,
9673 .doit = nl80211_set_power_save,
9674 .policy = nl80211_policy,
9675 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009676 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9677 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009678 },
9679 {
9680 .cmd = NL80211_CMD_GET_POWER_SAVE,
9681 .doit = nl80211_get_power_save,
9682 .policy = nl80211_policy,
9683 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009684 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9685 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009686 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009687 {
9688 .cmd = NL80211_CMD_SET_CQM,
9689 .doit = nl80211_set_cqm,
9690 .policy = nl80211_policy,
9691 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009692 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9693 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009694 },
Johannes Bergf444de02010-05-05 15:25:02 +02009695 {
9696 .cmd = NL80211_CMD_SET_CHANNEL,
9697 .doit = nl80211_set_channel,
9698 .policy = nl80211_policy,
9699 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009700 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9701 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009702 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009703 {
9704 .cmd = NL80211_CMD_SET_WDS_PEER,
9705 .doit = nl80211_set_wds_peer,
9706 .policy = nl80211_policy,
9707 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009708 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9709 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009710 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009711 {
9712 .cmd = NL80211_CMD_JOIN_MESH,
9713 .doit = nl80211_join_mesh,
9714 .policy = nl80211_policy,
9715 .flags = GENL_ADMIN_PERM,
9716 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9717 NL80211_FLAG_NEED_RTNL,
9718 },
9719 {
9720 .cmd = NL80211_CMD_LEAVE_MESH,
9721 .doit = nl80211_leave_mesh,
9722 .policy = nl80211_policy,
9723 .flags = GENL_ADMIN_PERM,
9724 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9725 NL80211_FLAG_NEED_RTNL,
9726 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009727#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009728 {
9729 .cmd = NL80211_CMD_GET_WOWLAN,
9730 .doit = nl80211_get_wowlan,
9731 .policy = nl80211_policy,
9732 /* can be retrieved by unprivileged users */
9733 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9734 NL80211_FLAG_NEED_RTNL,
9735 },
9736 {
9737 .cmd = NL80211_CMD_SET_WOWLAN,
9738 .doit = nl80211_set_wowlan,
9739 .policy = nl80211_policy,
9740 .flags = GENL_ADMIN_PERM,
9741 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9742 NL80211_FLAG_NEED_RTNL,
9743 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009744#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009745 {
9746 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9747 .doit = nl80211_set_rekey_data,
9748 .policy = nl80211_policy,
9749 .flags = GENL_ADMIN_PERM,
9750 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9751 NL80211_FLAG_NEED_RTNL,
9752 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009753 {
9754 .cmd = NL80211_CMD_TDLS_MGMT,
9755 .doit = nl80211_tdls_mgmt,
9756 .policy = nl80211_policy,
9757 .flags = GENL_ADMIN_PERM,
9758 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9759 NL80211_FLAG_NEED_RTNL,
9760 },
9761 {
9762 .cmd = NL80211_CMD_TDLS_OPER,
9763 .doit = nl80211_tdls_oper,
9764 .policy = nl80211_policy,
9765 .flags = GENL_ADMIN_PERM,
9766 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9767 NL80211_FLAG_NEED_RTNL,
9768 },
Johannes Berg28946da2011-11-04 11:18:12 +01009769 {
9770 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9771 .doit = nl80211_register_unexpected_frame,
9772 .policy = nl80211_policy,
9773 .flags = GENL_ADMIN_PERM,
9774 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9775 NL80211_FLAG_NEED_RTNL,
9776 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009777 {
9778 .cmd = NL80211_CMD_PROBE_CLIENT,
9779 .doit = nl80211_probe_client,
9780 .policy = nl80211_policy,
9781 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009782 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009783 NL80211_FLAG_NEED_RTNL,
9784 },
Johannes Berg5e760232011-11-04 11:18:17 +01009785 {
9786 .cmd = NL80211_CMD_REGISTER_BEACONS,
9787 .doit = nl80211_register_beacons,
9788 .policy = nl80211_policy,
9789 .flags = GENL_ADMIN_PERM,
9790 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9791 NL80211_FLAG_NEED_RTNL,
9792 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009793 {
9794 .cmd = NL80211_CMD_SET_NOACK_MAP,
9795 .doit = nl80211_set_noack_map,
9796 .policy = nl80211_policy,
9797 .flags = GENL_ADMIN_PERM,
9798 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9799 NL80211_FLAG_NEED_RTNL,
9800 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009801 {
9802 .cmd = NL80211_CMD_START_P2P_DEVICE,
9803 .doit = nl80211_start_p2p_device,
9804 .policy = nl80211_policy,
9805 .flags = GENL_ADMIN_PERM,
9806 .internal_flags = NL80211_FLAG_NEED_WDEV |
9807 NL80211_FLAG_NEED_RTNL,
9808 },
9809 {
9810 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9811 .doit = nl80211_stop_p2p_device,
9812 .policy = nl80211_policy,
9813 .flags = GENL_ADMIN_PERM,
9814 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9815 NL80211_FLAG_NEED_RTNL,
9816 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009817 {
9818 .cmd = NL80211_CMD_SET_MCAST_RATE,
9819 .doit = nl80211_set_mcast_rate,
9820 .policy = nl80211_policy,
9821 .flags = GENL_ADMIN_PERM,
9822 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9823 NL80211_FLAG_NEED_RTNL,
9824 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309825 {
9826 .cmd = NL80211_CMD_SET_MAC_ACL,
9827 .doit = nl80211_set_mac_acl,
9828 .policy = nl80211_policy,
9829 .flags = GENL_ADMIN_PERM,
9830 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9831 NL80211_FLAG_NEED_RTNL,
9832 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009833 {
9834 .cmd = NL80211_CMD_RADAR_DETECT,
9835 .doit = nl80211_start_radar_detection,
9836 .policy = nl80211_policy,
9837 .flags = GENL_ADMIN_PERM,
9838 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9839 NL80211_FLAG_NEED_RTNL,
9840 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009841 {
9842 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9843 .doit = nl80211_get_protocol_features,
9844 .policy = nl80211_policy,
9845 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009846 {
9847 .cmd = NL80211_CMD_UPDATE_FT_IES,
9848 .doit = nl80211_update_ft_ies,
9849 .policy = nl80211_policy,
9850 .flags = GENL_ADMIN_PERM,
9851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9852 NL80211_FLAG_NEED_RTNL,
9853 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009854 {
9855 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9856 .doit = nl80211_crit_protocol_start,
9857 .policy = nl80211_policy,
9858 .flags = GENL_ADMIN_PERM,
9859 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9860 NL80211_FLAG_NEED_RTNL,
9861 },
9862 {
9863 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9864 .doit = nl80211_crit_protocol_stop,
9865 .policy = nl80211_policy,
9866 .flags = GENL_ADMIN_PERM,
9867 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9868 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009869 },
9870 {
9871 .cmd = NL80211_CMD_GET_COALESCE,
9872 .doit = nl80211_get_coalesce,
9873 .policy = nl80211_policy,
9874 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9875 NL80211_FLAG_NEED_RTNL,
9876 },
9877 {
9878 .cmd = NL80211_CMD_SET_COALESCE,
9879 .doit = nl80211_set_coalesce,
9880 .policy = nl80211_policy,
9881 .flags = GENL_ADMIN_PERM,
9882 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9883 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009884 },
9885 {
9886 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9887 .doit = nl80211_channel_switch,
9888 .policy = nl80211_policy,
9889 .flags = GENL_ADMIN_PERM,
9890 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9891 NL80211_FLAG_NEED_RTNL,
9892 },
Johannes Bergad7e7182013-11-13 13:37:47 +01009893 {
9894 .cmd = NL80211_CMD_VENDOR,
9895 .doit = nl80211_vendor_cmd,
9896 .policy = nl80211_policy,
9897 .flags = GENL_ADMIN_PERM,
9898 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9899 NL80211_FLAG_NEED_RTNL,
9900 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009901 {
9902 .cmd = NL80211_CMD_SET_QOS_MAP,
9903 .doit = nl80211_set_qos_map,
9904 .policy = nl80211_policy,
9905 .flags = GENL_ADMIN_PERM,
9906 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9907 NL80211_FLAG_NEED_RTNL,
9908 },
Johannes Berg55682962007-09-20 13:09:35 -04009909};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009910
Johannes Berg55682962007-09-20 13:09:35 -04009911/* notification functions */
9912
9913void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9914{
9915 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009916 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009917
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009918 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009919 if (!msg)
9920 return;
9921
Johannes Berg86e8cf92013-06-19 10:57:22 +02009922 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009923 nlmsg_free(msg);
9924 return;
9925 }
9926
Johannes Berg68eb5502013-11-19 15:19:38 +01009927 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009928 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009929}
9930
Johannes Berg362a4152009-05-24 16:43:15 +02009931static int nl80211_add_scan_req(struct sk_buff *msg,
9932 struct cfg80211_registered_device *rdev)
9933{
9934 struct cfg80211_scan_request *req = rdev->scan_req;
9935 struct nlattr *nest;
9936 int i;
9937
9938 if (WARN_ON(!req))
9939 return 0;
9940
9941 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9942 if (!nest)
9943 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009944 for (i = 0; i < req->n_ssids; i++) {
9945 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9946 goto nla_put_failure;
9947 }
Johannes Berg362a4152009-05-24 16:43:15 +02009948 nla_nest_end(msg, nest);
9949
9950 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9951 if (!nest)
9952 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009953 for (i = 0; i < req->n_channels; i++) {
9954 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9955 goto nla_put_failure;
9956 }
Johannes Berg362a4152009-05-24 16:43:15 +02009957 nla_nest_end(msg, nest);
9958
David S. Miller9360ffd2012-03-29 04:41:26 -04009959 if (req->ie &&
9960 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9961 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009962
Johannes Bergae917c92013-10-25 11:05:22 +02009963 if (req->flags &&
9964 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
9965 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -07009966
Johannes Berg362a4152009-05-24 16:43:15 +02009967 return 0;
9968 nla_put_failure:
9969 return -ENOBUFS;
9970}
9971
Johannes Berga538e2d2009-06-16 19:56:42 +02009972static int nl80211_send_scan_msg(struct sk_buff *msg,
9973 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009974 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009975 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009976 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009977{
9978 void *hdr;
9979
Eric W. Biederman15e47302012-09-07 20:12:54 +00009980 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009981 if (!hdr)
9982 return -1;
9983
David S. Miller9360ffd2012-03-29 04:41:26 -04009984 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009985 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9986 wdev->netdev->ifindex)) ||
9987 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009988 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009989
Johannes Berg362a4152009-05-24 16:43:15 +02009990 /* ignore errors and send incomplete event anyway */
9991 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009992
9993 return genlmsg_end(msg, hdr);
9994
9995 nla_put_failure:
9996 genlmsg_cancel(msg, hdr);
9997 return -EMSGSIZE;
9998}
9999
Luciano Coelho807f8a82011-05-11 17:09:35 +030010000static int
10001nl80211_send_sched_scan_msg(struct sk_buff *msg,
10002 struct cfg80211_registered_device *rdev,
10003 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010004 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010005{
10006 void *hdr;
10007
Eric W. Biederman15e47302012-09-07 20:12:54 +000010008 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010009 if (!hdr)
10010 return -1;
10011
David S. Miller9360ffd2012-03-29 04:41:26 -040010012 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10013 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10014 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010015
10016 return genlmsg_end(msg, hdr);
10017
10018 nla_put_failure:
10019 genlmsg_cancel(msg, hdr);
10020 return -EMSGSIZE;
10021}
10022
Johannes Berga538e2d2009-06-16 19:56:42 +020010023void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010024 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010025{
10026 struct sk_buff *msg;
10027
Thomas Graf58050fc2012-06-28 03:57:45 +000010028 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010029 if (!msg)
10030 return;
10031
Johannes Bergfd014282012-06-18 19:17:03 +020010032 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010033 NL80211_CMD_TRIGGER_SCAN) < 0) {
10034 nlmsg_free(msg);
10035 return;
10036 }
10037
Johannes Berg68eb5502013-11-19 15:19:38 +010010038 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010039 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010040}
10041
Johannes Berg2a519312009-02-10 21:25:55 +010010042void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010043 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +010010044{
10045 struct sk_buff *msg;
10046
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010047 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010048 if (!msg)
10049 return;
10050
Johannes Bergfd014282012-06-18 19:17:03 +020010051 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010052 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010053 nlmsg_free(msg);
10054 return;
10055 }
10056
Johannes Berg68eb5502013-11-19 15:19:38 +010010057 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010058 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010059}
10060
10061void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010062 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +010010063{
10064 struct sk_buff *msg;
10065
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010066 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010067 if (!msg)
10068 return;
10069
Johannes Bergfd014282012-06-18 19:17:03 +020010070 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010071 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010072 nlmsg_free(msg);
10073 return;
10074 }
10075
Johannes Berg68eb5502013-11-19 15:19:38 +010010076 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010077 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010078}
10079
Luciano Coelho807f8a82011-05-11 17:09:35 +030010080void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10081 struct net_device *netdev)
10082{
10083 struct sk_buff *msg;
10084
10085 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10086 if (!msg)
10087 return;
10088
10089 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10090 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10091 nlmsg_free(msg);
10092 return;
10093 }
10094
Johannes Berg68eb5502013-11-19 15:19:38 +010010095 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010096 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010097}
10098
10099void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10100 struct net_device *netdev, u32 cmd)
10101{
10102 struct sk_buff *msg;
10103
Thomas Graf58050fc2012-06-28 03:57:45 +000010104 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010105 if (!msg)
10106 return;
10107
10108 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10109 nlmsg_free(msg);
10110 return;
10111 }
10112
Johannes Berg68eb5502013-11-19 15:19:38 +010010113 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010114 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010115}
10116
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010117/*
10118 * This can happen on global regulatory changes or device specific settings
10119 * based on custom world regulatory domains.
10120 */
10121void nl80211_send_reg_change_event(struct regulatory_request *request)
10122{
10123 struct sk_buff *msg;
10124 void *hdr;
10125
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010126 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010127 if (!msg)
10128 return;
10129
10130 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10131 if (!hdr) {
10132 nlmsg_free(msg);
10133 return;
10134 }
10135
10136 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010137 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10138 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010139
David S. Miller9360ffd2012-03-29 04:41:26 -040010140 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10141 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10142 NL80211_REGDOM_TYPE_WORLD))
10143 goto nla_put_failure;
10144 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10145 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10146 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10147 goto nla_put_failure;
10148 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10149 request->intersect) {
10150 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10151 NL80211_REGDOM_TYPE_INTERSECTION))
10152 goto nla_put_failure;
10153 } else {
10154 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10155 NL80211_REGDOM_TYPE_COUNTRY) ||
10156 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10157 request->alpha2))
10158 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010159 }
10160
Johannes Bergf4173762012-12-03 18:23:37 +010010161 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010162 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10163 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010164
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010165 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010166
Johannes Bergbc43b282009-07-25 10:54:13 +020010167 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010168 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010169 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010170 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010171
10172 return;
10173
10174nla_put_failure:
10175 genlmsg_cancel(msg, hdr);
10176 nlmsg_free(msg);
10177}
10178
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010179static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10180 struct net_device *netdev,
10181 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010182 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010183{
10184 struct sk_buff *msg;
10185 void *hdr;
10186
Johannes Berge6d6e342009-07-01 21:26:47 +020010187 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010188 if (!msg)
10189 return;
10190
10191 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10192 if (!hdr) {
10193 nlmsg_free(msg);
10194 return;
10195 }
10196
David S. Miller9360ffd2012-03-29 04:41:26 -040010197 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10198 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10199 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10200 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010201
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010202 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010203
Johannes Berg68eb5502013-11-19 15:19:38 +010010204 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010205 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010206 return;
10207
10208 nla_put_failure:
10209 genlmsg_cancel(msg, hdr);
10210 nlmsg_free(msg);
10211}
10212
10213void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010214 struct net_device *netdev, const u8 *buf,
10215 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010216{
10217 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010218 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010219}
10220
10221void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10222 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010223 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010224{
Johannes Berge6d6e342009-07-01 21:26:47 +020010225 nl80211_send_mlme_event(rdev, netdev, buf, len,
10226 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010227}
10228
Jouni Malinen53b46b82009-03-27 20:53:56 +020010229void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010230 struct net_device *netdev, const u8 *buf,
10231 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010232{
10233 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010234 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010235}
10236
Jouni Malinen53b46b82009-03-27 20:53:56 +020010237void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10238 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010239 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010240{
10241 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010242 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010243}
10244
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010245void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10246 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010247{
Johannes Berg947add32013-02-22 22:05:20 +010010248 struct wireless_dev *wdev = dev->ieee80211_ptr;
10249 struct wiphy *wiphy = wdev->wiphy;
10250 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010251 const struct ieee80211_mgmt *mgmt = (void *)buf;
10252 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010253
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010254 if (WARN_ON(len < 2))
10255 return;
10256
10257 if (ieee80211_is_deauth(mgmt->frame_control))
10258 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10259 else
10260 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10261
10262 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10263 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010264}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010265EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010266
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010267static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10268 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010269 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010270{
10271 struct sk_buff *msg;
10272 void *hdr;
10273
Johannes Berge6d6e342009-07-01 21:26:47 +020010274 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010275 if (!msg)
10276 return;
10277
10278 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10279 if (!hdr) {
10280 nlmsg_free(msg);
10281 return;
10282 }
10283
David S. Miller9360ffd2012-03-29 04:41:26 -040010284 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10285 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10286 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10287 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10288 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010289
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010290 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010291
Johannes Berg68eb5502013-11-19 15:19:38 +010010292 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010293 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010294 return;
10295
10296 nla_put_failure:
10297 genlmsg_cancel(msg, hdr);
10298 nlmsg_free(msg);
10299}
10300
10301void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010302 struct net_device *netdev, const u8 *addr,
10303 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010304{
10305 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010306 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010307}
10308
10309void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010310 struct net_device *netdev, const u8 *addr,
10311 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010312{
Johannes Berge6d6e342009-07-01 21:26:47 +020010313 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10314 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010315}
10316
Samuel Ortizb23aa672009-07-01 21:26:54 +020010317void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10318 struct net_device *netdev, const u8 *bssid,
10319 const u8 *req_ie, size_t req_ie_len,
10320 const u8 *resp_ie, size_t resp_ie_len,
10321 u16 status, gfp_t gfp)
10322{
10323 struct sk_buff *msg;
10324 void *hdr;
10325
Thomas Graf58050fc2012-06-28 03:57:45 +000010326 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010327 if (!msg)
10328 return;
10329
10330 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10331 if (!hdr) {
10332 nlmsg_free(msg);
10333 return;
10334 }
10335
David S. Miller9360ffd2012-03-29 04:41:26 -040010336 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10337 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10338 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10339 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10340 (req_ie &&
10341 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10342 (resp_ie &&
10343 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10344 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010345
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010346 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010347
Johannes Berg68eb5502013-11-19 15:19:38 +010010348 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010349 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010350 return;
10351
10352 nla_put_failure:
10353 genlmsg_cancel(msg, hdr);
10354 nlmsg_free(msg);
10355
10356}
10357
10358void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10359 struct net_device *netdev, const u8 *bssid,
10360 const u8 *req_ie, size_t req_ie_len,
10361 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10362{
10363 struct sk_buff *msg;
10364 void *hdr;
10365
Thomas Graf58050fc2012-06-28 03:57:45 +000010366 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010367 if (!msg)
10368 return;
10369
10370 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10371 if (!hdr) {
10372 nlmsg_free(msg);
10373 return;
10374 }
10375
David S. Miller9360ffd2012-03-29 04:41:26 -040010376 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10377 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10378 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10379 (req_ie &&
10380 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10381 (resp_ie &&
10382 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10383 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010384
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010385 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010386
Johannes Berg68eb5502013-11-19 15:19:38 +010010387 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010388 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010389 return;
10390
10391 nla_put_failure:
10392 genlmsg_cancel(msg, hdr);
10393 nlmsg_free(msg);
10394
10395}
10396
10397void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10398 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020010399 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010400{
10401 struct sk_buff *msg;
10402 void *hdr;
10403
Thomas Graf58050fc2012-06-28 03:57:45 +000010404 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010405 if (!msg)
10406 return;
10407
10408 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10409 if (!hdr) {
10410 nlmsg_free(msg);
10411 return;
10412 }
10413
David S. Miller9360ffd2012-03-29 04:41:26 -040010414 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10415 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10416 (from_ap && reason &&
10417 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10418 (from_ap &&
10419 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10420 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10421 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010422
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010423 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010424
Johannes Berg68eb5502013-11-19 15:19:38 +010010425 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010426 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010427 return;
10428
10429 nla_put_failure:
10430 genlmsg_cancel(msg, hdr);
10431 nlmsg_free(msg);
10432
10433}
10434
Johannes Berg04a773a2009-04-19 21:24:32 +020010435void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10436 struct net_device *netdev, const u8 *bssid,
10437 gfp_t gfp)
10438{
10439 struct sk_buff *msg;
10440 void *hdr;
10441
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010443 if (!msg)
10444 return;
10445
10446 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10447 if (!hdr) {
10448 nlmsg_free(msg);
10449 return;
10450 }
10451
David S. Miller9360ffd2012-03-29 04:41:26 -040010452 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10453 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10454 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10455 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010456
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010457 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010458
Johannes Berg68eb5502013-11-19 15:19:38 +010010459 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010460 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010461 return;
10462
10463 nla_put_failure:
10464 genlmsg_cancel(msg, hdr);
10465 nlmsg_free(msg);
10466}
10467
Johannes Berg947add32013-02-22 22:05:20 +010010468void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10469 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010470{
Johannes Berg947add32013-02-22 22:05:20 +010010471 struct wireless_dev *wdev = dev->ieee80211_ptr;
10472 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010473 struct sk_buff *msg;
10474 void *hdr;
10475
Johannes Berg947add32013-02-22 22:05:20 +010010476 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10477 return;
10478
10479 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10480
Javier Cardonac93b5e72011-04-07 15:08:34 -070010481 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10482 if (!msg)
10483 return;
10484
10485 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10486 if (!hdr) {
10487 nlmsg_free(msg);
10488 return;
10489 }
10490
David S. Miller9360ffd2012-03-29 04:41:26 -040010491 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010492 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10493 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010494 (ie_len && ie &&
10495 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10496 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010497
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010498 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010499
Johannes Berg68eb5502013-11-19 15:19:38 +010010500 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010501 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010502 return;
10503
10504 nla_put_failure:
10505 genlmsg_cancel(msg, hdr);
10506 nlmsg_free(msg);
10507}
Johannes Berg947add32013-02-22 22:05:20 +010010508EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010509
Jouni Malinena3b8b052009-03-27 21:59:49 +020010510void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10511 struct net_device *netdev, const u8 *addr,
10512 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010513 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010514{
10515 struct sk_buff *msg;
10516 void *hdr;
10517
Johannes Berge6d6e342009-07-01 21:26:47 +020010518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010519 if (!msg)
10520 return;
10521
10522 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10523 if (!hdr) {
10524 nlmsg_free(msg);
10525 return;
10526 }
10527
David S. Miller9360ffd2012-03-29 04:41:26 -040010528 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10530 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10531 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10532 (key_id != -1 &&
10533 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10534 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10535 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010536
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010537 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010538
Johannes Berg68eb5502013-11-19 15:19:38 +010010539 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010540 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010541 return;
10542
10543 nla_put_failure:
10544 genlmsg_cancel(msg, hdr);
10545 nlmsg_free(msg);
10546}
10547
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010548void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10549 struct ieee80211_channel *channel_before,
10550 struct ieee80211_channel *channel_after)
10551{
10552 struct sk_buff *msg;
10553 void *hdr;
10554 struct nlattr *nl_freq;
10555
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010556 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010557 if (!msg)
10558 return;
10559
10560 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10561 if (!hdr) {
10562 nlmsg_free(msg);
10563 return;
10564 }
10565
10566 /*
10567 * Since we are applying the beacon hint to a wiphy we know its
10568 * wiphy_idx is valid
10569 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10571 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010572
10573 /* Before */
10574 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10575 if (!nl_freq)
10576 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010577 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010578 goto nla_put_failure;
10579 nla_nest_end(msg, nl_freq);
10580
10581 /* After */
10582 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10583 if (!nl_freq)
10584 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010585 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010586 goto nla_put_failure;
10587 nla_nest_end(msg, nl_freq);
10588
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010589 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010590
Johannes Berg463d0182009-07-14 00:33:35 +020010591 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010592 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010593 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010594 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010595
10596 return;
10597
10598nla_put_failure:
10599 genlmsg_cancel(msg, hdr);
10600 nlmsg_free(msg);
10601}
10602
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010603static void nl80211_send_remain_on_chan_event(
10604 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010605 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010606 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010607 unsigned int duration, gfp_t gfp)
10608{
10609 struct sk_buff *msg;
10610 void *hdr;
10611
10612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10613 if (!msg)
10614 return;
10615
10616 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10617 if (!hdr) {
10618 nlmsg_free(msg);
10619 return;
10620 }
10621
David S. Miller9360ffd2012-03-29 04:41:26 -040010622 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010623 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10624 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010625 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010626 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010627 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10628 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010629 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10630 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010631
David S. Miller9360ffd2012-03-29 04:41:26 -040010632 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10633 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10634 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010635
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010636 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010637
Johannes Berg68eb5502013-11-19 15:19:38 +010010638 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010639 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010640 return;
10641
10642 nla_put_failure:
10643 genlmsg_cancel(msg, hdr);
10644 nlmsg_free(msg);
10645}
10646
Johannes Berg947add32013-02-22 22:05:20 +010010647void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10648 struct ieee80211_channel *chan,
10649 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010650{
Johannes Berg947add32013-02-22 22:05:20 +010010651 struct wiphy *wiphy = wdev->wiphy;
10652 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10653
10654 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010655 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010656 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010657 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010658}
Johannes Berg947add32013-02-22 22:05:20 +010010659EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010660
Johannes Berg947add32013-02-22 22:05:20 +010010661void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10662 struct ieee80211_channel *chan,
10663 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010664{
Johannes Berg947add32013-02-22 22:05:20 +010010665 struct wiphy *wiphy = wdev->wiphy;
10666 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10667
10668 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010669 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010670 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010671}
Johannes Berg947add32013-02-22 22:05:20 +010010672EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010673
Johannes Berg947add32013-02-22 22:05:20 +010010674void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10675 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010676{
Johannes Berg947add32013-02-22 22:05:20 +010010677 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10678 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010679 struct sk_buff *msg;
10680
Johannes Berg947add32013-02-22 22:05:20 +010010681 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10682
Thomas Graf58050fc2012-06-28 03:57:45 +000010683 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010684 if (!msg)
10685 return;
10686
John W. Linville66266b32012-03-15 13:25:41 -040010687 if (nl80211_send_station(msg, 0, 0, 0,
10688 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010689 nlmsg_free(msg);
10690 return;
10691 }
10692
Johannes Berg68eb5502013-11-19 15:19:38 +010010693 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010694 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010695}
Johannes Berg947add32013-02-22 22:05:20 +010010696EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010697
Johannes Berg947add32013-02-22 22:05:20 +010010698void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010699{
Johannes Berg947add32013-02-22 22:05:20 +010010700 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10701 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010702 struct sk_buff *msg;
10703 void *hdr;
10704
Johannes Berg947add32013-02-22 22:05:20 +010010705 trace_cfg80211_del_sta(dev, mac_addr);
10706
Thomas Graf58050fc2012-06-28 03:57:45 +000010707 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010708 if (!msg)
10709 return;
10710
10711 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10712 if (!hdr) {
10713 nlmsg_free(msg);
10714 return;
10715 }
10716
David S. Miller9360ffd2012-03-29 04:41:26 -040010717 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10718 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10719 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010720
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010721 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010722
Johannes Berg68eb5502013-11-19 15:19:38 +010010723 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010724 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010725 return;
10726
10727 nla_put_failure:
10728 genlmsg_cancel(msg, hdr);
10729 nlmsg_free(msg);
10730}
Johannes Berg947add32013-02-22 22:05:20 +010010731EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010732
Johannes Berg947add32013-02-22 22:05:20 +010010733void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10734 enum nl80211_connect_failed_reason reason,
10735 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010736{
Johannes Berg947add32013-02-22 22:05:20 +010010737 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10738 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010739 struct sk_buff *msg;
10740 void *hdr;
10741
10742 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10743 if (!msg)
10744 return;
10745
10746 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10747 if (!hdr) {
10748 nlmsg_free(msg);
10749 return;
10750 }
10751
10752 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10753 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10754 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10755 goto nla_put_failure;
10756
10757 genlmsg_end(msg, hdr);
10758
Johannes Berg68eb5502013-11-19 15:19:38 +010010759 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010760 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010761 return;
10762
10763 nla_put_failure:
10764 genlmsg_cancel(msg, hdr);
10765 nlmsg_free(msg);
10766}
Johannes Berg947add32013-02-22 22:05:20 +010010767EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010768
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010769static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10770 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010771{
10772 struct wireless_dev *wdev = dev->ieee80211_ptr;
10773 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10774 struct sk_buff *msg;
10775 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010776 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010777
Eric W. Biederman15e47302012-09-07 20:12:54 +000010778 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010779 return false;
10780
10781 msg = nlmsg_new(100, gfp);
10782 if (!msg)
10783 return true;
10784
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010785 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010786 if (!hdr) {
10787 nlmsg_free(msg);
10788 return true;
10789 }
10790
David S. Miller9360ffd2012-03-29 04:41:26 -040010791 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10792 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10793 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10794 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010795
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010796 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010797 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010798 return true;
10799
10800 nla_put_failure:
10801 genlmsg_cancel(msg, hdr);
10802 nlmsg_free(msg);
10803 return true;
10804}
10805
Johannes Berg947add32013-02-22 22:05:20 +010010806bool cfg80211_rx_spurious_frame(struct net_device *dev,
10807 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010808{
Johannes Berg947add32013-02-22 22:05:20 +010010809 struct wireless_dev *wdev = dev->ieee80211_ptr;
10810 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010811
Johannes Berg947add32013-02-22 22:05:20 +010010812 trace_cfg80211_rx_spurious_frame(dev, addr);
10813
10814 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10815 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10816 trace_cfg80211_return_bool(false);
10817 return false;
10818 }
10819 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10820 addr, gfp);
10821 trace_cfg80211_return_bool(ret);
10822 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010823}
Johannes Berg947add32013-02-22 22:05:20 +010010824EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10825
10826bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10827 const u8 *addr, gfp_t gfp)
10828{
10829 struct wireless_dev *wdev = dev->ieee80211_ptr;
10830 bool ret;
10831
10832 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10833
10834 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10835 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10836 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10837 trace_cfg80211_return_bool(false);
10838 return false;
10839 }
10840 ret = __nl80211_unexpected_frame(dev,
10841 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10842 addr, gfp);
10843 trace_cfg80211_return_bool(ret);
10844 return ret;
10845}
10846EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010847
Johannes Berg2e161f782010-08-12 15:38:38 +020010848int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010849 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010850 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010851 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010852{
Johannes Berg71bbc992012-06-15 15:30:18 +020010853 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010854 struct sk_buff *msg;
10855 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010856
10857 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10858 if (!msg)
10859 return -ENOMEM;
10860
Johannes Berg2e161f782010-08-12 15:38:38 +020010861 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010862 if (!hdr) {
10863 nlmsg_free(msg);
10864 return -ENOMEM;
10865 }
10866
David S. Miller9360ffd2012-03-29 04:41:26 -040010867 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010868 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10869 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010870 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010871 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10872 (sig_dbm &&
10873 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010874 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10875 (flags &&
10876 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010877 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010878
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010879 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010880
Eric W. Biederman15e47302012-09-07 20:12:54 +000010881 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010882
10883 nla_put_failure:
10884 genlmsg_cancel(msg, hdr);
10885 nlmsg_free(msg);
10886 return -ENOBUFS;
10887}
10888
Johannes Berg947add32013-02-22 22:05:20 +010010889void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10890 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010891{
Johannes Berg947add32013-02-22 22:05:20 +010010892 struct wiphy *wiphy = wdev->wiphy;
10893 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010894 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010895 struct sk_buff *msg;
10896 void *hdr;
10897
Johannes Berg947add32013-02-22 22:05:20 +010010898 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10899
Jouni Malinen026331c2010-02-15 12:53:10 +020010900 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10901 if (!msg)
10902 return;
10903
Johannes Berg2e161f782010-08-12 15:38:38 +020010904 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010905 if (!hdr) {
10906 nlmsg_free(msg);
10907 return;
10908 }
10909
David S. Miller9360ffd2012-03-29 04:41:26 -040010910 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010911 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10912 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010913 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010914 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10915 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10916 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10917 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010918
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010919 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010920
Johannes Berg68eb5502013-11-19 15:19:38 +010010921 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010922 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010923 return;
10924
10925 nla_put_failure:
10926 genlmsg_cancel(msg, hdr);
10927 nlmsg_free(msg);
10928}
Johannes Berg947add32013-02-22 22:05:20 +010010929EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010930
Johannes Berg947add32013-02-22 22:05:20 +010010931void cfg80211_cqm_rssi_notify(struct net_device *dev,
10932 enum nl80211_cqm_rssi_threshold_event rssi_event,
10933 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010934{
Johannes Berg947add32013-02-22 22:05:20 +010010935 struct wireless_dev *wdev = dev->ieee80211_ptr;
10936 struct wiphy *wiphy = wdev->wiphy;
10937 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010938 struct sk_buff *msg;
10939 struct nlattr *pinfoattr;
10940 void *hdr;
10941
Johannes Berg947add32013-02-22 22:05:20 +010010942 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10943
Thomas Graf58050fc2012-06-28 03:57:45 +000010944 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010945 if (!msg)
10946 return;
10947
10948 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10949 if (!hdr) {
10950 nlmsg_free(msg);
10951 return;
10952 }
10953
David S. Miller9360ffd2012-03-29 04:41:26 -040010954 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010955 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010956 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010957
10958 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10959 if (!pinfoattr)
10960 goto nla_put_failure;
10961
David S. Miller9360ffd2012-03-29 04:41:26 -040010962 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10963 rssi_event))
10964 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010965
10966 nla_nest_end(msg, pinfoattr);
10967
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010968 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010969
Johannes Berg68eb5502013-11-19 15:19:38 +010010970 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010971 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010972 return;
10973
10974 nla_put_failure:
10975 genlmsg_cancel(msg, hdr);
10976 nlmsg_free(msg);
10977}
Johannes Berg947add32013-02-22 22:05:20 +010010978EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010979
Johannes Berg947add32013-02-22 22:05:20 +010010980static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10981 struct net_device *netdev, const u8 *bssid,
10982 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010983{
10984 struct sk_buff *msg;
10985 struct nlattr *rekey_attr;
10986 void *hdr;
10987
Thomas Graf58050fc2012-06-28 03:57:45 +000010988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010989 if (!msg)
10990 return;
10991
10992 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10993 if (!hdr) {
10994 nlmsg_free(msg);
10995 return;
10996 }
10997
David S. Miller9360ffd2012-03-29 04:41:26 -040010998 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10999 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11000 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11001 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011002
11003 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11004 if (!rekey_attr)
11005 goto nla_put_failure;
11006
David S. Miller9360ffd2012-03-29 04:41:26 -040011007 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11008 NL80211_REPLAY_CTR_LEN, replay_ctr))
11009 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011010
11011 nla_nest_end(msg, rekey_attr);
11012
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011013 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011014
Johannes Berg68eb5502013-11-19 15:19:38 +010011015 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011016 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011017 return;
11018
11019 nla_put_failure:
11020 genlmsg_cancel(msg, hdr);
11021 nlmsg_free(msg);
11022}
11023
Johannes Berg947add32013-02-22 22:05:20 +010011024void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11025 const u8 *replay_ctr, gfp_t gfp)
11026{
11027 struct wireless_dev *wdev = dev->ieee80211_ptr;
11028 struct wiphy *wiphy = wdev->wiphy;
11029 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11030
11031 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11032 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11033}
11034EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11035
11036static void
11037nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11038 struct net_device *netdev, int index,
11039 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011040{
11041 struct sk_buff *msg;
11042 struct nlattr *attr;
11043 void *hdr;
11044
Thomas Graf58050fc2012-06-28 03:57:45 +000011045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011046 if (!msg)
11047 return;
11048
11049 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11050 if (!hdr) {
11051 nlmsg_free(msg);
11052 return;
11053 }
11054
David S. Miller9360ffd2012-03-29 04:41:26 -040011055 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11057 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011058
11059 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11060 if (!attr)
11061 goto nla_put_failure;
11062
David S. Miller9360ffd2012-03-29 04:41:26 -040011063 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11064 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11065 (preauth &&
11066 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11067 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011068
11069 nla_nest_end(msg, attr);
11070
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011071 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011072
Johannes Berg68eb5502013-11-19 15:19:38 +010011073 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011074 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011075 return;
11076
11077 nla_put_failure:
11078 genlmsg_cancel(msg, hdr);
11079 nlmsg_free(msg);
11080}
11081
Johannes Berg947add32013-02-22 22:05:20 +010011082void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11083 const u8 *bssid, bool preauth, gfp_t gfp)
11084{
11085 struct wireless_dev *wdev = dev->ieee80211_ptr;
11086 struct wiphy *wiphy = wdev->wiphy;
11087 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11088
11089 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11090 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11091}
11092EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11093
11094static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11095 struct net_device *netdev,
11096 struct cfg80211_chan_def *chandef,
11097 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011098{
11099 struct sk_buff *msg;
11100 void *hdr;
11101
Thomas Graf58050fc2012-06-28 03:57:45 +000011102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011103 if (!msg)
11104 return;
11105
11106 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11107 if (!hdr) {
11108 nlmsg_free(msg);
11109 return;
11110 }
11111
Johannes Berg683b6d32012-11-08 21:25:48 +010011112 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11113 goto nla_put_failure;
11114
11115 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011116 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011117
11118 genlmsg_end(msg, hdr);
11119
Johannes Berg68eb5502013-11-19 15:19:38 +010011120 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011121 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011122 return;
11123
11124 nla_put_failure:
11125 genlmsg_cancel(msg, hdr);
11126 nlmsg_free(msg);
11127}
11128
Johannes Berg947add32013-02-22 22:05:20 +010011129void cfg80211_ch_switch_notify(struct net_device *dev,
11130 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011131{
Johannes Berg947add32013-02-22 22:05:20 +010011132 struct wireless_dev *wdev = dev->ieee80211_ptr;
11133 struct wiphy *wiphy = wdev->wiphy;
11134 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11135
Simon Wunderliche487eae2013-11-21 18:19:51 +010011136 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011137
Simon Wunderliche487eae2013-11-21 18:19:51 +010011138 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011139
11140 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011141 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011142 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11143 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011144 return;
Johannes Berg947add32013-02-22 22:05:20 +010011145
11146 wdev->channel = chandef->chan;
11147 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011148}
11149EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11150
11151void cfg80211_cqm_txe_notify(struct net_device *dev,
11152 const u8 *peer, u32 num_packets,
11153 u32 rate, u32 intvl, gfp_t gfp)
11154{
11155 struct wireless_dev *wdev = dev->ieee80211_ptr;
11156 struct wiphy *wiphy = wdev->wiphy;
11157 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011158 struct sk_buff *msg;
11159 struct nlattr *pinfoattr;
11160 void *hdr;
11161
11162 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11163 if (!msg)
11164 return;
11165
11166 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11167 if (!hdr) {
11168 nlmsg_free(msg);
11169 return;
11170 }
11171
11172 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011173 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011174 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11175 goto nla_put_failure;
11176
11177 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11178 if (!pinfoattr)
11179 goto nla_put_failure;
11180
11181 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11182 goto nla_put_failure;
11183
11184 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11185 goto nla_put_failure;
11186
11187 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11188 goto nla_put_failure;
11189
11190 nla_nest_end(msg, pinfoattr);
11191
11192 genlmsg_end(msg, hdr);
11193
Johannes Berg68eb5502013-11-19 15:19:38 +010011194 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011195 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011196 return;
11197
11198 nla_put_failure:
11199 genlmsg_cancel(msg, hdr);
11200 nlmsg_free(msg);
11201}
Johannes Berg947add32013-02-22 22:05:20 +010011202EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011203
11204void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011205nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011206 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011207 enum nl80211_radar_event event,
11208 struct net_device *netdev, gfp_t gfp)
11209{
11210 struct sk_buff *msg;
11211 void *hdr;
11212
11213 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11214 if (!msg)
11215 return;
11216
11217 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11218 if (!hdr) {
11219 nlmsg_free(msg);
11220 return;
11221 }
11222
11223 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11224 goto nla_put_failure;
11225
11226 /* NOP and radar events don't need a netdev parameter */
11227 if (netdev) {
11228 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11229
11230 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11231 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11232 goto nla_put_failure;
11233 }
11234
11235 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11236 goto nla_put_failure;
11237
11238 if (nl80211_send_chandef(msg, chandef))
11239 goto nla_put_failure;
11240
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011241 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011242
Johannes Berg68eb5502013-11-19 15:19:38 +010011243 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011244 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011245 return;
11246
11247 nla_put_failure:
11248 genlmsg_cancel(msg, hdr);
11249 nlmsg_free(msg);
11250}
11251
Johannes Berg947add32013-02-22 22:05:20 +010011252void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11253 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011254{
Johannes Berg947add32013-02-22 22:05:20 +010011255 struct wireless_dev *wdev = dev->ieee80211_ptr;
11256 struct wiphy *wiphy = wdev->wiphy;
11257 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011258 struct sk_buff *msg;
11259 struct nlattr *pinfoattr;
11260 void *hdr;
11261
Johannes Berg947add32013-02-22 22:05:20 +010011262 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11263
Thomas Graf58050fc2012-06-28 03:57:45 +000011264 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011265 if (!msg)
11266 return;
11267
11268 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11269 if (!hdr) {
11270 nlmsg_free(msg);
11271 return;
11272 }
11273
David S. Miller9360ffd2012-03-29 04:41:26 -040011274 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011275 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011276 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11277 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011278
11279 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11280 if (!pinfoattr)
11281 goto nla_put_failure;
11282
David S. Miller9360ffd2012-03-29 04:41:26 -040011283 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11284 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011285
11286 nla_nest_end(msg, pinfoattr);
11287
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011288 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011289
Johannes Berg68eb5502013-11-19 15:19:38 +010011290 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011291 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011292 return;
11293
11294 nla_put_failure:
11295 genlmsg_cancel(msg, hdr);
11296 nlmsg_free(msg);
11297}
Johannes Berg947add32013-02-22 22:05:20 +010011298EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011299
Johannes Berg7f6cf312011-11-04 11:18:15 +010011300void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11301 u64 cookie, bool acked, gfp_t gfp)
11302{
11303 struct wireless_dev *wdev = dev->ieee80211_ptr;
11304 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11305 struct sk_buff *msg;
11306 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011307
Beni Lev4ee3e062012-08-27 12:49:39 +030011308 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11309
Thomas Graf58050fc2012-06-28 03:57:45 +000011310 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011311
Johannes Berg7f6cf312011-11-04 11:18:15 +010011312 if (!msg)
11313 return;
11314
11315 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11316 if (!hdr) {
11317 nlmsg_free(msg);
11318 return;
11319 }
11320
David S. Miller9360ffd2012-03-29 04:41:26 -040011321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11322 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11323 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11324 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11325 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11326 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011327
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011328 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011329
Johannes Berg68eb5502013-11-19 15:19:38 +010011330 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011331 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011332 return;
11333
11334 nla_put_failure:
11335 genlmsg_cancel(msg, hdr);
11336 nlmsg_free(msg);
11337}
11338EXPORT_SYMBOL(cfg80211_probe_status);
11339
Johannes Berg5e760232011-11-04 11:18:17 +010011340void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11341 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011342 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011343{
11344 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11345 struct sk_buff *msg;
11346 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011347 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011348
Beni Lev4ee3e062012-08-27 12:49:39 +030011349 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11350
Ben Greear37c73b52012-10-26 14:49:25 -070011351 spin_lock_bh(&rdev->beacon_registrations_lock);
11352 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11353 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11354 if (!msg) {
11355 spin_unlock_bh(&rdev->beacon_registrations_lock);
11356 return;
11357 }
Johannes Berg5e760232011-11-04 11:18:17 +010011358
Ben Greear37c73b52012-10-26 14:49:25 -070011359 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11360 if (!hdr)
11361 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011362
Ben Greear37c73b52012-10-26 14:49:25 -070011363 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11364 (freq &&
11365 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11366 (sig_dbm &&
11367 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11368 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11369 goto nla_put_failure;
11370
11371 genlmsg_end(msg, hdr);
11372
11373 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011374 }
Ben Greear37c73b52012-10-26 14:49:25 -070011375 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011376 return;
11377
11378 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011379 spin_unlock_bh(&rdev->beacon_registrations_lock);
11380 if (hdr)
11381 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011382 nlmsg_free(msg);
11383}
11384EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11385
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011386#ifdef CONFIG_PM
11387void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11388 struct cfg80211_wowlan_wakeup *wakeup,
11389 gfp_t gfp)
11390{
11391 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11392 struct sk_buff *msg;
11393 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011394 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011395
11396 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11397
11398 if (wakeup)
11399 size += wakeup->packet_present_len;
11400
11401 msg = nlmsg_new(size, gfp);
11402 if (!msg)
11403 return;
11404
11405 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11406 if (!hdr)
11407 goto free_msg;
11408
11409 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11410 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11411 goto free_msg;
11412
11413 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11414 wdev->netdev->ifindex))
11415 goto free_msg;
11416
11417 if (wakeup) {
11418 struct nlattr *reasons;
11419
11420 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011421 if (!reasons)
11422 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011423
11424 if (wakeup->disconnect &&
11425 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11426 goto free_msg;
11427 if (wakeup->magic_pkt &&
11428 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11429 goto free_msg;
11430 if (wakeup->gtk_rekey_failure &&
11431 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11432 goto free_msg;
11433 if (wakeup->eap_identity_req &&
11434 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11435 goto free_msg;
11436 if (wakeup->four_way_handshake &&
11437 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11438 goto free_msg;
11439 if (wakeup->rfkill_release &&
11440 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11441 goto free_msg;
11442
11443 if (wakeup->pattern_idx >= 0 &&
11444 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11445 wakeup->pattern_idx))
11446 goto free_msg;
11447
Johannes Bergae917c92013-10-25 11:05:22 +020011448 if (wakeup->tcp_match &&
11449 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11450 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011451
Johannes Bergae917c92013-10-25 11:05:22 +020011452 if (wakeup->tcp_connlost &&
11453 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11454 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011455
Johannes Bergae917c92013-10-25 11:05:22 +020011456 if (wakeup->tcp_nomoretokens &&
11457 nla_put_flag(msg,
11458 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11459 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011460
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011461 if (wakeup->packet) {
11462 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11463 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11464
11465 if (!wakeup->packet_80211) {
11466 pkt_attr =
11467 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11468 len_attr =
11469 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11470 }
11471
11472 if (wakeup->packet_len &&
11473 nla_put_u32(msg, len_attr, wakeup->packet_len))
11474 goto free_msg;
11475
11476 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11477 wakeup->packet))
11478 goto free_msg;
11479 }
11480
11481 nla_nest_end(msg, reasons);
11482 }
11483
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011484 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011485
Johannes Berg68eb5502013-11-19 15:19:38 +010011486 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011487 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011488 return;
11489
11490 free_msg:
11491 nlmsg_free(msg);
11492}
11493EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11494#endif
11495
Jouni Malinen3475b092012-11-16 22:49:57 +020011496void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11497 enum nl80211_tdls_operation oper,
11498 u16 reason_code, gfp_t gfp)
11499{
11500 struct wireless_dev *wdev = dev->ieee80211_ptr;
11501 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11502 struct sk_buff *msg;
11503 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011504
11505 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11506 reason_code);
11507
11508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11509 if (!msg)
11510 return;
11511
11512 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11513 if (!hdr) {
11514 nlmsg_free(msg);
11515 return;
11516 }
11517
11518 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11519 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11520 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11521 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11522 (reason_code > 0 &&
11523 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11524 goto nla_put_failure;
11525
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011526 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011527
Johannes Berg68eb5502013-11-19 15:19:38 +010011528 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011529 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011530 return;
11531
11532 nla_put_failure:
11533 genlmsg_cancel(msg, hdr);
11534 nlmsg_free(msg);
11535}
11536EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11537
Jouni Malinen026331c2010-02-15 12:53:10 +020011538static int nl80211_netlink_notify(struct notifier_block * nb,
11539 unsigned long state,
11540 void *_notify)
11541{
11542 struct netlink_notify *notify = _notify;
11543 struct cfg80211_registered_device *rdev;
11544 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011545 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011546
11547 if (state != NETLINK_URELEASE)
11548 return NOTIFY_DONE;
11549
11550 rcu_read_lock();
11551
Johannes Berg5e760232011-11-04 11:18:17 +010011552 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011553 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011554 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011555
11556 spin_lock_bh(&rdev->beacon_registrations_lock);
11557 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11558 list) {
11559 if (reg->nlportid == notify->portid) {
11560 list_del(&reg->list);
11561 kfree(reg);
11562 break;
11563 }
11564 }
11565 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011566 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011567
11568 rcu_read_unlock();
11569
11570 return NOTIFY_DONE;
11571}
11572
11573static struct notifier_block nl80211_netlink_notifier = {
11574 .notifier_call = nl80211_netlink_notify,
11575};
11576
Jouni Malinen355199e2013-02-27 17:14:27 +020011577void cfg80211_ft_event(struct net_device *netdev,
11578 struct cfg80211_ft_event_params *ft_event)
11579{
11580 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11581 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11582 struct sk_buff *msg;
11583 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011584
11585 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11586
11587 if (!ft_event->target_ap)
11588 return;
11589
11590 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11591 if (!msg)
11592 return;
11593
11594 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011595 if (!hdr)
11596 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011597
Johannes Bergae917c92013-10-25 11:05:22 +020011598 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11599 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11600 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11601 goto out;
11602
11603 if (ft_event->ies &&
11604 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11605 goto out;
11606 if (ft_event->ric_ies &&
11607 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11608 ft_event->ric_ies))
11609 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011610
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011611 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011612
Johannes Berg68eb5502013-11-19 15:19:38 +010011613 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011614 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011615 return;
11616 out:
11617 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011618}
11619EXPORT_SYMBOL(cfg80211_ft_event);
11620
Arend van Spriel5de17982013-04-18 15:49:00 +020011621void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11622{
11623 struct cfg80211_registered_device *rdev;
11624 struct sk_buff *msg;
11625 void *hdr;
11626 u32 nlportid;
11627
11628 rdev = wiphy_to_dev(wdev->wiphy);
11629 if (!rdev->crit_proto_nlportid)
11630 return;
11631
11632 nlportid = rdev->crit_proto_nlportid;
11633 rdev->crit_proto_nlportid = 0;
11634
11635 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11636 if (!msg)
11637 return;
11638
11639 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11640 if (!hdr)
11641 goto nla_put_failure;
11642
11643 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11644 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11645 goto nla_put_failure;
11646
11647 genlmsg_end(msg, hdr);
11648
11649 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11650 return;
11651
11652 nla_put_failure:
11653 if (hdr)
11654 genlmsg_cancel(msg, hdr);
11655 nlmsg_free(msg);
11656
11657}
11658EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11659
Johannes Berg55682962007-09-20 13:09:35 -040011660/* initialisation/exit functions */
11661
11662int nl80211_init(void)
11663{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011664 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011665
Johannes Berg2a94fe42013-11-19 15:19:39 +010011666 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11667 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011668 if (err)
11669 return err;
11670
Jouni Malinen026331c2010-02-15 12:53:10 +020011671 err = netlink_register_notifier(&nl80211_netlink_notifier);
11672 if (err)
11673 goto err_out;
11674
Johannes Berg55682962007-09-20 13:09:35 -040011675 return 0;
11676 err_out:
11677 genl_unregister_family(&nl80211_fam);
11678 return err;
11679}
11680
11681void nl80211_exit(void)
11682{
Jouni Malinen026331c2010-02-15 12:53:10 +020011683 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011684 genl_unregister_family(&nl80211_fam);
11685}