blob: 7469020175d5bde8b1e5e9921b141bcc3c113e3b [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 Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
40 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = "nl80211", /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
44 .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 Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg89a54e42012-06-15 14:33:17 +020062 assert_cfg80211_lock();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
83 mutex_lock(&rdev->devlist_mtx);
84 list_for_each_entry(wdev, &rdev->wdev_list, list) {
85 if (have_ifidx && wdev->netdev &&
86 wdev->netdev->ifindex == ifidx) {
87 result = wdev;
88 break;
89 }
90 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
91 result = wdev;
92 break;
93 }
94 }
95 mutex_unlock(&rdev->devlist_mtx);
96
97 if (result)
98 break;
99 }
100
101 if (result)
102 return result;
103 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400104}
105
Johannes Berga9455402012-06-15 13:32:49 +0200106static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200107__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200108{
Johannes Berg7fee4772012-06-15 14:09:58 +0200109 struct cfg80211_registered_device *rdev = NULL, *tmp;
110 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200111
112 assert_cfg80211_lock();
113
Johannes Berg878d9ec2012-06-15 14:18:32 +0200114 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200115 !attrs[NL80211_ATTR_IFINDEX] &&
116 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200117 return ERR_PTR(-EINVAL);
118
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200120 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200121 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg89a54e42012-06-15 14:33:17 +0200123 if (attrs[NL80211_ATTR_WDEV]) {
124 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
125 struct wireless_dev *wdev;
126 bool found = false;
127
128 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
129 if (tmp) {
130 /* make sure wdev exists */
131 mutex_lock(&tmp->devlist_mtx);
132 list_for_each_entry(wdev, &tmp->wdev_list, list) {
133 if (wdev->identifier != (u32)wdev_id)
134 continue;
135 found = true;
136 break;
137 }
138 mutex_unlock(&tmp->devlist_mtx);
139
140 if (!found)
141 tmp = NULL;
142
143 if (rdev && tmp != rdev)
144 return ERR_PTR(-EINVAL);
145 rdev = tmp;
146 }
147 }
148
Johannes Berg878d9ec2012-06-15 14:18:32 +0200149 if (attrs[NL80211_ATTR_IFINDEX]) {
150 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200151 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200152 if (netdev) {
153 if (netdev->ieee80211_ptr)
154 tmp = wiphy_to_dev(
155 netdev->ieee80211_ptr->wiphy);
156 else
157 tmp = NULL;
158
159 dev_put(netdev);
160
161 /* not wireless device -- return error */
162 if (!tmp)
163 return ERR_PTR(-EINVAL);
164
165 /* mismatch -- return error */
166 if (rdev && tmp != rdev)
167 return ERR_PTR(-EINVAL);
168
169 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200170 }
Johannes Berga9455402012-06-15 13:32:49 +0200171 }
172
Johannes Berg4f7eff12012-06-15 14:14:22 +0200173 if (!rdev)
174 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200175
Johannes Berg4f7eff12012-06-15 14:14:22 +0200176 if (netns != wiphy_net(&rdev->wiphy))
177 return ERR_PTR(-ENODEV);
178
179 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200180}
181
182/*
183 * This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 * If successful, it returns non-NULL and also locks
186 * the driver's mutex!
187 *
188 * This means that you need to call cfg80211_unlock_rdev()
189 * before being allowed to acquire &cfg80211_mutex!
190 *
191 * This is necessary because we need to lock the global
192 * mutex to get an item off the list safely, and then
193 * we lock the rdev mutex so it doesn't go away under us.
194 *
195 * We don't want to keep cfg80211_mutex locked
196 * for all the time in order to allow requests on
197 * other interfaces to go through at the same time.
198 *
199 * The result of this can be a PTR_ERR and hence must
200 * be checked with IS_ERR() for errors.
201 */
202static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200203cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200204{
205 struct cfg80211_registered_device *rdev;
206
207 mutex_lock(&cfg80211_mutex);
Johannes Berg878d9ec2012-06-15 14:18:32 +0200208 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209
210 /* if it is not an error we grab the lock on
211 * it to assure it won't be going away while
212 * we operate on it */
213 if (!IS_ERR(rdev))
214 mutex_lock(&rdev->mtx);
215
216 mutex_unlock(&cfg80211_mutex);
217
218 return rdev;
219}
220
Johannes Berg55682962007-09-20 13:09:35 -0400221/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000222static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400223 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
224 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700225 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200226 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100227
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200228 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530229 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100230 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
231 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
232 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
233
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200234 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
235 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
236 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
237 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100238 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400239
240 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
241 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
242 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100243
Eliad Pellere007b852011-11-24 18:13:56 +0200244 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
245 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100246
Johannes Bergb9454e82009-07-08 13:29:08 +0200247 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100248 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
249 .len = WLAN_MAX_KEY_LEN },
250 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
251 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
252 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200253 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200254 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100255
256 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
257 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
258 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
259 .len = IEEE80211_MAX_DATA_LEN },
260 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100262 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
263 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
264 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
265 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
266 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100267 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100268 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200269 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100270 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800271 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100272 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300273
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700274 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
275 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
276
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300277 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
278 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
279 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200280 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
281 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100282 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300283
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800284 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700285 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700286
Johannes Berg6c739412011-11-03 09:27:01 +0100287 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200288
289 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
290 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
291 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100292 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
293 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200294
295 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
296 .len = IEEE80211_MAX_SSID_LEN },
297 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
298 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200299 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300300 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300301 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300302 [NL80211_ATTR_STA_FLAGS2] = {
303 .len = sizeof(struct nl80211_sta_flag_update),
304 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300305 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200308 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
309 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
310 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200311 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100312 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100313 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
314 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100315 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
316 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200317 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200318 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
319 .len = IEEE80211_MAX_DATA_LEN },
320 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200321 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200322 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300323 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200324 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200327 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900328 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
329 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100330 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100331 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100332 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200333 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700334 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300335 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200336 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200337 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300338 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300339 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
340 .len = IEEE80211_MAX_DATA_LEN },
341 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530343 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300344 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530345 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300346 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
348 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
349 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100351 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200352 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
353 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700354 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800355 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
356 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
357 .len = NL80211_HT_CAPABILITY_LEN
358 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100359 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530360 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530361 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200362 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700363 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300364 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000365 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700366 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100367 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
368 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530369 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
370 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200371 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
372 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100373 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100374 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
375 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
376 .len = NL80211_VHT_CAPABILITY_LEN,
377 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200378 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
379 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
380 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg55682962007-09-20 13:09:35 -0400381};
382
Johannes Berge31b8212010-10-05 19:39:30 +0200383/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000384static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200385 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200386 [NL80211_KEY_IDX] = { .type = NLA_U8 },
387 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200388 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200389 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
390 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200391 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100392 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
393};
394
395/* policy for the key default flags */
396static const struct nla_policy
397nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
398 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
399 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200400};
401
Johannes Bergff1b6e62011-05-04 15:37:28 +0200402/* policy for WoWLAN attributes */
403static const struct nla_policy
404nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
405 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
406 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
407 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
408 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200409 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
410 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
411 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
412 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100413 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
414};
415
416static const struct nla_policy
417nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
418 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
419 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
420 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
421 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
422 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
423 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
424 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
425 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
426 },
427 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
428 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
429 },
430 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
431 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
432 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200433};
434
Johannes Berge5497d72011-07-05 16:35:40 +0200435/* policy for GTK rekey offload attributes */
436static const struct nla_policy
437nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
438 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
439 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
440 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
441};
442
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300443static const struct nla_policy
444nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200445 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300446 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700447 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300448};
449
Holger Schuriga0438972009-11-11 11:30:02 +0100450/* ifidx get helper */
451static int nl80211_get_ifidx(struct netlink_callback *cb)
452{
453 int res;
454
455 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
456 nl80211_fam.attrbuf, nl80211_fam.maxattr,
457 nl80211_policy);
458 if (res)
459 return res;
460
461 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
462 return -EINVAL;
463
464 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
465 if (!res)
466 return -EINVAL;
467 return res;
468}
469
Johannes Berg67748892010-10-04 21:14:06 +0200470static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
471 struct netlink_callback *cb,
472 struct cfg80211_registered_device **rdev,
473 struct net_device **dev)
474{
475 int ifidx = cb->args[0];
476 int err;
477
478 if (!ifidx)
479 ifidx = nl80211_get_ifidx(cb);
480 if (ifidx < 0)
481 return ifidx;
482
483 cb->args[0] = ifidx;
484
485 rtnl_lock();
486
487 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
488 if (!*dev) {
489 err = -ENODEV;
490 goto out_rtnl;
491 }
492
493 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100494 if (IS_ERR(*rdev)) {
495 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200496 goto out_rtnl;
497 }
498
499 return 0;
500 out_rtnl:
501 rtnl_unlock();
502 return err;
503}
504
505static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
506{
507 cfg80211_unlock_rdev(rdev);
508 rtnl_unlock();
509}
510
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100511/* IE validation */
512static bool is_valid_ie_attr(const struct nlattr *attr)
513{
514 const u8 *pos;
515 int len;
516
517 if (!attr)
518 return true;
519
520 pos = nla_data(attr);
521 len = nla_len(attr);
522
523 while (len) {
524 u8 elemlen;
525
526 if (len < 2)
527 return false;
528 len -= 2;
529
530 elemlen = pos[1];
531 if (elemlen > len)
532 return false;
533
534 len -= elemlen;
535 pos += 2 + elemlen;
536 }
537
538 return true;
539}
540
Johannes Berg55682962007-09-20 13:09:35 -0400541/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000542static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400543 int flags, u8 cmd)
544{
545 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000546 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400547}
548
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400549static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100550 struct ieee80211_channel *chan,
551 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400552{
David S. Miller9360ffd2012-03-29 04:41:26 -0400553 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
554 chan->center_freq))
555 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400556
David S. Miller9360ffd2012-03-29 04:41:26 -0400557 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
565 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100566 if (chan->flags & IEEE80211_CHAN_RADAR) {
567 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
568 goto nla_put_failure;
569 if (large) {
570 u32 time;
571
572 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
573
574 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
575 chan->dfs_state))
576 goto nla_put_failure;
577 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
578 time))
579 goto nla_put_failure;
580 }
581 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400582
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100583 if (large) {
584 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
585 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
586 goto nla_put_failure;
587 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
588 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
589 goto nla_put_failure;
590 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
591 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
592 goto nla_put_failure;
593 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
594 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
595 goto nla_put_failure;
596 }
597
David S. Miller9360ffd2012-03-29 04:41:26 -0400598 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
599 DBM_TO_MBM(chan->max_power)))
600 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400601
602 return 0;
603
604 nla_put_failure:
605 return -ENOBUFS;
606}
607
Johannes Berg55682962007-09-20 13:09:35 -0400608/* netlink command implementations */
609
Johannes Bergb9454e82009-07-08 13:29:08 +0200610struct key_parse {
611 struct key_params p;
612 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200613 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100615 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200616};
617
618static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
619{
620 struct nlattr *tb[NL80211_KEY_MAX + 1];
621 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
622 nl80211_key_policy);
623 if (err)
624 return err;
625
626 k->def = !!tb[NL80211_KEY_DEFAULT];
627 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
628
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100629 if (k->def) {
630 k->def_uni = true;
631 k->def_multi = true;
632 }
633 if (k->defmgmt)
634 k->def_multi = true;
635
Johannes Bergb9454e82009-07-08 13:29:08 +0200636 if (tb[NL80211_KEY_IDX])
637 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
638
639 if (tb[NL80211_KEY_DATA]) {
640 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
641 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
642 }
643
644 if (tb[NL80211_KEY_SEQ]) {
645 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
646 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
647 }
648
649 if (tb[NL80211_KEY_CIPHER])
650 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
651
Johannes Berge31b8212010-10-05 19:39:30 +0200652 if (tb[NL80211_KEY_TYPE]) {
653 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
654 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
655 return -EINVAL;
656 }
657
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100658 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
659 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100660 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
661 tb[NL80211_KEY_DEFAULT_TYPES],
662 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100663 if (err)
664 return err;
665
666 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
667 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
668 }
669
Johannes Bergb9454e82009-07-08 13:29:08 +0200670 return 0;
671}
672
673static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
674{
675 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
676 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
677 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
678 }
679
680 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
681 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
682 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
683 }
684
685 if (info->attrs[NL80211_ATTR_KEY_IDX])
686 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
687
688 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
689 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
690
691 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
692 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
693
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100694 if (k->def) {
695 k->def_uni = true;
696 k->def_multi = true;
697 }
698 if (k->defmgmt)
699 k->def_multi = true;
700
Johannes Berge31b8212010-10-05 19:39:30 +0200701 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
702 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
703 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
704 return -EINVAL;
705 }
706
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100707 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
708 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
709 int err = nla_parse_nested(
710 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
711 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
712 nl80211_key_default_policy);
713 if (err)
714 return err;
715
716 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
717 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
718 }
719
Johannes Bergb9454e82009-07-08 13:29:08 +0200720 return 0;
721}
722
723static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
724{
725 int err;
726
727 memset(k, 0, sizeof(*k));
728 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200729 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200730
731 if (info->attrs[NL80211_ATTR_KEY])
732 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
733 else
734 err = nl80211_parse_key_old(info, k);
735
736 if (err)
737 return err;
738
739 if (k->def && k->defmgmt)
740 return -EINVAL;
741
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100742 if (k->defmgmt) {
743 if (k->def_uni || !k->def_multi)
744 return -EINVAL;
745 }
746
Johannes Bergb9454e82009-07-08 13:29:08 +0200747 if (k->idx != -1) {
748 if (k->defmgmt) {
749 if (k->idx < 4 || k->idx > 5)
750 return -EINVAL;
751 } else if (k->def) {
752 if (k->idx < 0 || k->idx > 3)
753 return -EINVAL;
754 } else {
755 if (k->idx < 0 || k->idx > 5)
756 return -EINVAL;
757 }
758 }
759
760 return 0;
761}
762
Johannes Bergfffd0932009-07-08 14:22:54 +0200763static struct cfg80211_cached_keys *
764nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530765 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200766{
767 struct key_parse parse;
768 struct nlattr *key;
769 struct cfg80211_cached_keys *result;
770 int rem, err, def = 0;
771
772 result = kzalloc(sizeof(*result), GFP_KERNEL);
773 if (!result)
774 return ERR_PTR(-ENOMEM);
775
776 result->def = -1;
777 result->defmgmt = -1;
778
779 nla_for_each_nested(key, keys, rem) {
780 memset(&parse, 0, sizeof(parse));
781 parse.idx = -1;
782
783 err = nl80211_parse_key_new(key, &parse);
784 if (err)
785 goto error;
786 err = -EINVAL;
787 if (!parse.p.key)
788 goto error;
789 if (parse.idx < 0 || parse.idx > 4)
790 goto error;
791 if (parse.def) {
792 if (def)
793 goto error;
794 def = 1;
795 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100796 if (!parse.def_uni || !parse.def_multi)
797 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200798 } else if (parse.defmgmt)
799 goto error;
800 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200801 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200802 if (err)
803 goto error;
804 result->params[parse.idx].cipher = parse.p.cipher;
805 result->params[parse.idx].key_len = parse.p.key_len;
806 result->params[parse.idx].key = result->data[parse.idx];
807 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530808
809 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
810 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
811 if (no_ht)
812 *no_ht = true;
813 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200814 }
815
816 return result;
817 error:
818 kfree(result);
819 return ERR_PTR(err);
820}
821
822static int nl80211_key_allowed(struct wireless_dev *wdev)
823{
824 ASSERT_WDEV_LOCK(wdev);
825
Johannes Bergfffd0932009-07-08 14:22:54 +0200826 switch (wdev->iftype) {
827 case NL80211_IFTYPE_AP:
828 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200829 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700830 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200831 break;
832 case NL80211_IFTYPE_ADHOC:
833 if (!wdev->current_bss)
834 return -ENOLINK;
835 break;
836 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200837 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200838 if (wdev->sme_state != CFG80211_SME_CONNECTED)
839 return -ENOLINK;
840 break;
841 default:
842 return -EINVAL;
843 }
844
845 return 0;
846}
847
Johannes Berg7527a782011-05-13 10:58:57 +0200848static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
849{
850 struct nlattr *nl_modes = nla_nest_start(msg, attr);
851 int i;
852
853 if (!nl_modes)
854 goto nla_put_failure;
855
856 i = 0;
857 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400858 if ((ifmodes & 1) && nla_put_flag(msg, i))
859 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200860 ifmodes >>= 1;
861 i++;
862 }
863
864 nla_nest_end(msg, nl_modes);
865 return 0;
866
867nla_put_failure:
868 return -ENOBUFS;
869}
870
871static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100872 struct sk_buff *msg,
873 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200874{
875 struct nlattr *nl_combis;
876 int i, j;
877
878 nl_combis = nla_nest_start(msg,
879 NL80211_ATTR_INTERFACE_COMBINATIONS);
880 if (!nl_combis)
881 goto nla_put_failure;
882
883 for (i = 0; i < wiphy->n_iface_combinations; i++) {
884 const struct ieee80211_iface_combination *c;
885 struct nlattr *nl_combi, *nl_limits;
886
887 c = &wiphy->iface_combinations[i];
888
889 nl_combi = nla_nest_start(msg, i + 1);
890 if (!nl_combi)
891 goto nla_put_failure;
892
893 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
894 if (!nl_limits)
895 goto nla_put_failure;
896
897 for (j = 0; j < c->n_limits; j++) {
898 struct nlattr *nl_limit;
899
900 nl_limit = nla_nest_start(msg, j + 1);
901 if (!nl_limit)
902 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400903 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
904 c->limits[j].max))
905 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200906 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
907 c->limits[j].types))
908 goto nla_put_failure;
909 nla_nest_end(msg, nl_limit);
910 }
911
912 nla_nest_end(msg, nl_limits);
913
David S. Miller9360ffd2012-03-29 04:41:26 -0400914 if (c->beacon_int_infra_match &&
915 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
916 goto nla_put_failure;
917 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
918 c->num_different_channels) ||
919 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
920 c->max_interfaces))
921 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100922 if (large &&
923 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
924 c->radar_detect_widths))
925 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200926
927 nla_nest_end(msg, nl_combi);
928 }
929
930 nla_nest_end(msg, nl_combis);
931
932 return 0;
933nla_put_failure:
934 return -ENOBUFS;
935}
936
Johannes Berg3713b4e2013-02-14 16:19:38 +0100937#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100938static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
939 struct sk_buff *msg)
940{
941 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
942 struct nlattr *nl_tcp;
943
944 if (!tcp)
945 return 0;
946
947 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
948 if (!nl_tcp)
949 return -ENOBUFS;
950
951 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
952 tcp->data_payload_max))
953 return -ENOBUFS;
954
955 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
956 tcp->data_payload_max))
957 return -ENOBUFS;
958
959 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
960 return -ENOBUFS;
961
962 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
963 sizeof(*tcp->tok), tcp->tok))
964 return -ENOBUFS;
965
966 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
967 tcp->data_interval_max))
968 return -ENOBUFS;
969
970 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
971 tcp->wake_payload_max))
972 return -ENOBUFS;
973
974 nla_nest_end(msg, nl_tcp);
975 return 0;
976}
977
Johannes Berg3713b4e2013-02-14 16:19:38 +0100978static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100979 struct cfg80211_registered_device *dev,
980 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100981{
982 struct nlattr *nl_wowlan;
983
984 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
985 return 0;
986
987 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
988 if (!nl_wowlan)
989 return -ENOBUFS;
990
991 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
992 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
993 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
994 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
995 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
996 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
997 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
998 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
999 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1000 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1001 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1002 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1003 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1005 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1007 return -ENOBUFS;
1008
1009 if (dev->wiphy.wowlan.n_patterns) {
1010 struct nl80211_wowlan_pattern_support pat = {
1011 .max_patterns = dev->wiphy.wowlan.n_patterns,
1012 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
1013 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
1014 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
1015 };
1016
1017 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1018 sizeof(pat), &pat))
1019 return -ENOBUFS;
1020 }
1021
Johannes Bergb56cf722013-02-20 01:02:38 +01001022 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1023 return -ENOBUFS;
1024
Johannes Berg3713b4e2013-02-14 16:19:38 +01001025 nla_nest_end(msg, nl_wowlan);
1026
1027 return 0;
1028}
1029#endif
1030
1031static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1032 struct ieee80211_supported_band *sband)
1033{
1034 struct nlattr *nl_rates, *nl_rate;
1035 struct ieee80211_rate *rate;
1036 int i;
1037
1038 /* add HT info */
1039 if (sband->ht_cap.ht_supported &&
1040 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1041 sizeof(sband->ht_cap.mcs),
1042 &sband->ht_cap.mcs) ||
1043 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1044 sband->ht_cap.cap) ||
1045 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1046 sband->ht_cap.ampdu_factor) ||
1047 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1048 sband->ht_cap.ampdu_density)))
1049 return -ENOBUFS;
1050
1051 /* add VHT info */
1052 if (sband->vht_cap.vht_supported &&
1053 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1054 sizeof(sband->vht_cap.vht_mcs),
1055 &sband->vht_cap.vht_mcs) ||
1056 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1057 sband->vht_cap.cap)))
1058 return -ENOBUFS;
1059
1060 /* add bitrates */
1061 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1062 if (!nl_rates)
1063 return -ENOBUFS;
1064
1065 for (i = 0; i < sband->n_bitrates; i++) {
1066 nl_rate = nla_nest_start(msg, i);
1067 if (!nl_rate)
1068 return -ENOBUFS;
1069
1070 rate = &sband->bitrates[i];
1071 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1072 rate->bitrate))
1073 return -ENOBUFS;
1074 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1075 nla_put_flag(msg,
1076 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1077 return -ENOBUFS;
1078
1079 nla_nest_end(msg, nl_rate);
1080 }
1081
1082 nla_nest_end(msg, nl_rates);
1083
1084 return 0;
1085}
1086
1087static int
1088nl80211_send_mgmt_stypes(struct sk_buff *msg,
1089 const struct ieee80211_txrx_stypes *mgmt_stypes)
1090{
1091 u16 stypes;
1092 struct nlattr *nl_ftypes, *nl_ifs;
1093 enum nl80211_iftype ift;
1094 int i;
1095
1096 if (!mgmt_stypes)
1097 return 0;
1098
1099 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1100 if (!nl_ifs)
1101 return -ENOBUFS;
1102
1103 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1104 nl_ftypes = nla_nest_start(msg, ift);
1105 if (!nl_ftypes)
1106 return -ENOBUFS;
1107 i = 0;
1108 stypes = mgmt_stypes[ift].tx;
1109 while (stypes) {
1110 if ((stypes & 1) &&
1111 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1112 (i << 4) | IEEE80211_FTYPE_MGMT))
1113 return -ENOBUFS;
1114 stypes >>= 1;
1115 i++;
1116 }
1117 nla_nest_end(msg, nl_ftypes);
1118 }
1119
1120 nla_nest_end(msg, nl_ifs);
1121
1122 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1123 if (!nl_ifs)
1124 return -ENOBUFS;
1125
1126 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1127 nl_ftypes = nla_nest_start(msg, ift);
1128 if (!nl_ftypes)
1129 return -ENOBUFS;
1130 i = 0;
1131 stypes = mgmt_stypes[ift].rx;
1132 while (stypes) {
1133 if ((stypes & 1) &&
1134 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1135 (i << 4) | IEEE80211_FTYPE_MGMT))
1136 return -ENOBUFS;
1137 stypes >>= 1;
1138 i++;
1139 }
1140 nla_nest_end(msg, nl_ftypes);
1141 }
1142 nla_nest_end(msg, nl_ifs);
1143
1144 return 0;
1145}
1146
1147static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1148 struct sk_buff *msg, u32 portid, u32 seq,
1149 int flags, bool split, long *split_start,
1150 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001151{
1152 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001153 struct nlattr *nl_bands, *nl_band;
1154 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001155 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001156 enum ieee80211_band band;
1157 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001158 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001159 const struct ieee80211_txrx_stypes *mgmt_stypes =
1160 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001161 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001162 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001163
Eric W. Biederman15e47302012-09-07 20:12:54 +00001164 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001165 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001166 return -ENOBUFS;
1167
1168 /* allow always using the variables */
1169 if (!split) {
1170 split_start = &start;
1171 band_start = &start_band;
1172 chan_start = &start_chan;
1173 }
Johannes Berg55682962007-09-20 13:09:35 -04001174
David S. Miller9360ffd2012-03-29 04:41:26 -04001175 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1177 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001178 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001179 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001180 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001181
Johannes Berg3713b4e2013-02-14 16:19:38 +01001182 switch (*split_start) {
1183 case 0:
1184 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1185 dev->wiphy.retry_short) ||
1186 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1187 dev->wiphy.retry_long) ||
1188 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1189 dev->wiphy.frag_threshold) ||
1190 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1191 dev->wiphy.rts_threshold) ||
1192 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1193 dev->wiphy.coverage_class) ||
1194 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1195 dev->wiphy.max_scan_ssids) ||
1196 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1197 dev->wiphy.max_sched_scan_ssids) ||
1198 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1199 dev->wiphy.max_scan_ie_len) ||
1200 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1201 dev->wiphy.max_sched_scan_ie_len) ||
1202 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1203 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001204 goto nla_put_failure;
1205
Johannes Berg3713b4e2013-02-14 16:19:38 +01001206 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1207 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1208 goto nla_put_failure;
1209 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1210 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1211 goto nla_put_failure;
1212 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1213 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1216 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1219 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1220 goto nla_put_failure;
1221 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1222 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001223 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001224
Johannes Berg3713b4e2013-02-14 16:19:38 +01001225 (*split_start)++;
1226 if (split)
1227 break;
1228 case 1:
1229 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1230 sizeof(u32) * dev->wiphy.n_cipher_suites,
1231 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001232 goto nla_put_failure;
1233
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1235 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001236 goto nla_put_failure;
1237
Johannes Berg3713b4e2013-02-14 16:19:38 +01001238 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1239 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1240 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001241
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1243 dev->wiphy.available_antennas_tx) ||
1244 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1245 dev->wiphy.available_antennas_rx))
1246 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001247
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1249 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1250 dev->wiphy.probe_resp_offload))
1251 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.available_antennas_tx ||
1254 dev->wiphy.available_antennas_rx) &&
1255 dev->ops->get_antenna) {
1256 u32 tx_ant = 0, rx_ant = 0;
1257 int res;
1258 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1259 if (!res) {
1260 if (nla_put_u32(msg,
1261 NL80211_ATTR_WIPHY_ANTENNA_TX,
1262 tx_ant) ||
1263 nla_put_u32(msg,
1264 NL80211_ATTR_WIPHY_ANTENNA_RX,
1265 rx_ant))
1266 goto nla_put_failure;
1267 }
Johannes Bergee688b002008-01-24 19:38:39 +01001268 }
1269
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 (*split_start)++;
1271 if (split)
1272 break;
1273 case 2:
1274 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1275 dev->wiphy.interface_modes))
1276 goto nla_put_failure;
1277 (*split_start)++;
1278 if (split)
1279 break;
1280 case 3:
1281 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1282 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001283 goto nla_put_failure;
1284
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1286 struct ieee80211_supported_band *sband;
1287
1288 sband = dev->wiphy.bands[band];
1289
1290 if (!sband)
1291 continue;
1292
1293 nl_band = nla_nest_start(msg, band);
1294 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001295 goto nla_put_failure;
1296
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 switch (*chan_start) {
1298 case 0:
1299 if (nl80211_send_band_rateinfo(msg, sband))
1300 goto nla_put_failure;
1301 (*chan_start)++;
1302 if (split)
1303 break;
1304 default:
1305 /* add frequencies */
1306 nl_freqs = nla_nest_start(
1307 msg, NL80211_BAND_ATTR_FREQS);
1308 if (!nl_freqs)
1309 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001310
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 for (i = *chan_start - 1;
1312 i < sband->n_channels;
1313 i++) {
1314 nl_freq = nla_nest_start(msg, i);
1315 if (!nl_freq)
1316 goto nla_put_failure;
1317
1318 chan = &sband->channels[i];
1319
Johannes Bergcdc89b92013-02-18 23:54:36 +01001320 if (nl80211_msg_put_channel(msg, chan,
1321 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 goto nla_put_failure;
1323
1324 nla_nest_end(msg, nl_freq);
1325 if (split)
1326 break;
1327 }
1328 if (i < sband->n_channels)
1329 *chan_start = i + 2;
1330 else
1331 *chan_start = 0;
1332 nla_nest_end(msg, nl_freqs);
1333 }
1334
1335 nla_nest_end(msg, nl_band);
1336
1337 if (split) {
1338 /* start again here */
1339 if (*chan_start)
1340 band--;
1341 break;
1342 }
Johannes Bergee688b002008-01-24 19:38:39 +01001343 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001345
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 if (band < IEEE80211_NUM_BANDS)
1347 *band_start = band + 1;
1348 else
1349 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001350
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 /* if bands & channels are done, continue outside */
1352 if (*band_start == 0 && *chan_start == 0)
1353 (*split_start)++;
1354 if (split)
1355 break;
1356 case 4:
1357 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1358 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001359 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360
1361 i = 0;
1362#define CMD(op, n) \
1363 do { \
1364 if (dev->ops->op) { \
1365 i++; \
1366 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1367 goto nla_put_failure; \
1368 } \
1369 } while (0)
1370
1371 CMD(add_virtual_intf, NEW_INTERFACE);
1372 CMD(change_virtual_intf, SET_INTERFACE);
1373 CMD(add_key, NEW_KEY);
1374 CMD(start_ap, START_AP);
1375 CMD(add_station, NEW_STATION);
1376 CMD(add_mpath, NEW_MPATH);
1377 CMD(update_mesh_config, SET_MESH_CONFIG);
1378 CMD(change_bss, SET_BSS);
1379 CMD(auth, AUTHENTICATE);
1380 CMD(assoc, ASSOCIATE);
1381 CMD(deauth, DEAUTHENTICATE);
1382 CMD(disassoc, DISASSOCIATE);
1383 CMD(join_ibss, JOIN_IBSS);
1384 CMD(join_mesh, JOIN_MESH);
1385 CMD(set_pmksa, SET_PMKSA);
1386 CMD(del_pmksa, DEL_PMKSA);
1387 CMD(flush_pmksa, FLUSH_PMKSA);
1388 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1389 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1390 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1391 CMD(mgmt_tx, FRAME);
1392 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1393 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1394 i++;
1395 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1396 goto nla_put_failure;
1397 }
1398 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1399 dev->ops->join_mesh) {
1400 i++;
1401 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1402 goto nla_put_failure;
1403 }
1404 CMD(set_wds_peer, SET_WDS_PEER);
1405 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1406 CMD(tdls_mgmt, TDLS_MGMT);
1407 CMD(tdls_oper, TDLS_OPER);
1408 }
1409 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1410 CMD(sched_scan_start, START_SCHED_SCAN);
1411 CMD(probe_client, PROBE_CLIENT);
1412 CMD(set_noack_map, SET_NOACK_MAP);
1413 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1414 i++;
1415 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1416 goto nla_put_failure;
1417 }
1418 CMD(start_p2p_device, START_P2P_DEVICE);
1419 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001420
Kalle Valo4745fc02011-11-17 19:06:10 +02001421#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001423#endif
1424
Johannes Berg8fdc6212009-03-14 09:34:01 +01001425#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001426
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 if (dev->ops->connect || dev->ops->auth) {
1428 i++;
1429 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001430 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001431 }
1432
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 if (dev->ops->disconnect || dev->ops->deauth) {
1434 i++;
1435 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1436 goto nla_put_failure;
1437 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 nla_nest_end(msg, nl_cmds);
1440 (*split_start)++;
1441 if (split)
1442 break;
1443 case 5:
1444 if (dev->ops->remain_on_channel &&
1445 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1446 nla_put_u32(msg,
1447 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1448 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001449 goto nla_put_failure;
1450
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1452 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1453 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001454
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1456 goto nla_put_failure;
1457 (*split_start)++;
1458 if (split)
1459 break;
1460 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001461#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001462 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 goto nla_put_failure;
1464 (*split_start)++;
1465 if (split)
1466 break;
1467#else
1468 (*split_start)++;
1469#endif
1470 case 7:
1471 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1472 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001473 goto nla_put_failure;
1474
Johannes Bergcdc89b92013-02-18 23:54:36 +01001475 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001477
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 (*split_start)++;
1479 if (split)
1480 break;
1481 case 8:
1482 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1483 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1484 dev->wiphy.ap_sme_capa))
1485 goto nla_put_failure;
1486
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001487 features = dev->wiphy.features;
1488 /*
1489 * We can only add the per-channel limit information if the
1490 * dump is split, otherwise it makes it too big. Therefore
1491 * only advertise it in that case.
1492 */
1493 if (split)
1494 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1495 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 goto nla_put_failure;
1497
1498 if (dev->wiphy.ht_capa_mod_mask &&
1499 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1500 sizeof(*dev->wiphy.ht_capa_mod_mask),
1501 dev->wiphy.ht_capa_mod_mask))
1502 goto nla_put_failure;
1503
1504 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1505 dev->wiphy.max_acl_mac_addrs &&
1506 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1507 dev->wiphy.max_acl_mac_addrs))
1508 goto nla_put_failure;
1509
1510 /*
1511 * Any information below this point is only available to
1512 * applications that can deal with it being split. This
1513 * helps ensure that newly added capabilities don't break
1514 * older tools by overrunning their buffers.
1515 *
1516 * We still increment split_start so that in the split
1517 * case we'll continue with more data in the next round,
1518 * but break unconditionally so unsplit data stops here.
1519 */
1520 (*split_start)++;
1521 break;
1522 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001523 if (dev->wiphy.extended_capabilities &&
1524 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1525 dev->wiphy.extended_capabilities_len,
1526 dev->wiphy.extended_capabilities) ||
1527 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1528 dev->wiphy.extended_capabilities_len,
1529 dev->wiphy.extended_capabilities_mask)))
1530 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531
Johannes Bergee2aca32013-02-21 17:36:01 +01001532 if (dev->wiphy.vht_capa_mod_mask &&
1533 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1534 sizeof(*dev->wiphy.vht_capa_mod_mask),
1535 dev->wiphy.vht_capa_mod_mask))
1536 goto nla_put_failure;
1537
Johannes Berg3713b4e2013-02-14 16:19:38 +01001538 /* done */
1539 *split_start = 0;
1540 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001541 }
Johannes Berg55682962007-09-20 13:09:35 -04001542 return genlmsg_end(msg, hdr);
1543
1544 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001545 genlmsg_cancel(msg, hdr);
1546 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001547}
1548
1549static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1550{
Johannes Berg645e77d2013-03-01 14:03:49 +01001551 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001552 int start = cb->args[0];
1553 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 s64 filter_wiphy = -1;
1555 bool split = false;
1556 struct nlattr **tb = nl80211_fam.attrbuf;
1557 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001558
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001559 mutex_lock(&cfg80211_mutex);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1561 tb, nl80211_fam.maxattr, nl80211_policy);
1562 if (res == 0) {
1563 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1564 if (tb[NL80211_ATTR_WIPHY])
1565 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1566 if (tb[NL80211_ATTR_WDEV])
1567 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1568 if (tb[NL80211_ATTR_IFINDEX]) {
1569 struct net_device *netdev;
1570 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1571
1572 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1573 if (!netdev) {
1574 mutex_unlock(&cfg80211_mutex);
1575 return -ENODEV;
1576 }
1577 if (netdev->ieee80211_ptr) {
1578 dev = wiphy_to_dev(
1579 netdev->ieee80211_ptr->wiphy);
1580 filter_wiphy = dev->wiphy_idx;
1581 }
1582 dev_put(netdev);
1583 }
1584 }
1585
Johannes Berg79c97e92009-07-07 03:56:12 +02001586 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001587 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1588 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001589 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001590 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1592 continue;
1593 /* attempt to fit multiple wiphy data chunks into the skb */
1594 do {
1595 ret = nl80211_send_wiphy(dev, skb,
1596 NETLINK_CB(cb->skb).portid,
1597 cb->nlh->nlmsg_seq,
1598 NLM_F_MULTI,
1599 split, &cb->args[1],
1600 &cb->args[2],
1601 &cb->args[3]);
1602 if (ret < 0) {
1603 /*
1604 * If sending the wiphy data didn't fit (ENOBUFS
1605 * or EMSGSIZE returned), this SKB is still
1606 * empty (so it's not too big because another
1607 * wiphy dataset is already in the skb) and
1608 * we've not tried to adjust the dump allocation
1609 * yet ... then adjust the alloc size to be
1610 * bigger, and return 1 but with the empty skb.
1611 * This results in an empty message being RX'ed
1612 * in userspace, but that is ignored.
1613 *
1614 * We can then retry with the larger buffer.
1615 */
1616 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1617 !skb->len &&
1618 cb->min_dump_alloc < 4096) {
1619 cb->min_dump_alloc = 4096;
1620 mutex_unlock(&cfg80211_mutex);
1621 return 1;
1622 }
1623 idx--;
1624 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001625 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 } while (cb->args[1] > 0);
1627 break;
Johannes Berg55682962007-09-20 13:09:35 -04001628 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001629 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001630
1631 cb->args[0] = idx;
1632
1633 return skb->len;
1634}
1635
1636static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1637{
1638 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001639 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001640
Johannes Berg645e77d2013-03-01 14:03:49 +01001641 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001642 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001643 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001644
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1646 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001647 nlmsg_free(msg);
1648 return -ENOBUFS;
1649 }
Johannes Berg55682962007-09-20 13:09:35 -04001650
Johannes Berg134e6372009-07-10 09:51:34 +00001651 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001652}
1653
Jouni Malinen31888482008-10-30 16:59:24 +02001654static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1655 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1656 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1657 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1658 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1659 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1660};
1661
1662static int parse_txq_params(struct nlattr *tb[],
1663 struct ieee80211_txq_params *txq_params)
1664{
Johannes Berga3304b02012-03-28 11:04:24 +02001665 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001666 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1667 !tb[NL80211_TXQ_ATTR_AIFS])
1668 return -EINVAL;
1669
Johannes Berga3304b02012-03-28 11:04:24 +02001670 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001671 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1672 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1673 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1674 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1675
Johannes Berga3304b02012-03-28 11:04:24 +02001676 if (txq_params->ac >= NL80211_NUM_ACS)
1677 return -EINVAL;
1678
Jouni Malinen31888482008-10-30 16:59:24 +02001679 return 0;
1680}
1681
Johannes Bergf444de02010-05-05 15:25:02 +02001682static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1683{
1684 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001685 * You can only set the channel explicitly for WDS interfaces,
1686 * all others have their channel managed via their respective
1687 * "establish a connection" command (connect, join, ...)
1688 *
1689 * For AP/GO and mesh mode, the channel can be set with the
1690 * channel userspace API, but is only stored and passed to the
1691 * low-level driver when the AP starts or the mesh is joined.
1692 * This is for backward compatibility, userspace can also give
1693 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001694 *
1695 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001696 * whatever else is going on, so they have their own special
1697 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001698 */
1699 return !wdev ||
1700 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001701 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001702 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1703 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001704}
1705
Johannes Berg683b6d32012-11-08 21:25:48 +01001706static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1707 struct genl_info *info,
1708 struct cfg80211_chan_def *chandef)
1709{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301710 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001711
1712 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1713 return -EINVAL;
1714
1715 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1716
1717 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001718 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1719 chandef->center_freq1 = control_freq;
1720 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001721
1722 /* Primary channel not allowed */
1723 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1724 return -EINVAL;
1725
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001726 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1727 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001728
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001729 chantype = nla_get_u32(
1730 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1731
1732 switch (chantype) {
1733 case NL80211_CHAN_NO_HT:
1734 case NL80211_CHAN_HT20:
1735 case NL80211_CHAN_HT40PLUS:
1736 case NL80211_CHAN_HT40MINUS:
1737 cfg80211_chandef_create(chandef, chandef->chan,
1738 chantype);
1739 break;
1740 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001741 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001742 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001743 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1744 chandef->width =
1745 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1746 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1747 chandef->center_freq1 =
1748 nla_get_u32(
1749 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1750 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1751 chandef->center_freq2 =
1752 nla_get_u32(
1753 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1754 }
1755
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001756 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001757 return -EINVAL;
1758
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001759 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1760 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001761 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001762
Johannes Berg683b6d32012-11-08 21:25:48 +01001763 return 0;
1764}
1765
Johannes Bergf444de02010-05-05 15:25:02 +02001766static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1767 struct wireless_dev *wdev,
1768 struct genl_info *info)
1769{
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001771 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001772 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1773
1774 if (wdev)
1775 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001776
Johannes Bergf444de02010-05-05 15:25:02 +02001777 if (!nl80211_can_set_dev_channel(wdev))
1778 return -EOPNOTSUPP;
1779
Johannes Berg683b6d32012-11-08 21:25:48 +01001780 result = nl80211_parse_chandef(rdev, info, &chandef);
1781 if (result)
1782 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001783
1784 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001785 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001786 case NL80211_IFTYPE_AP:
1787 case NL80211_IFTYPE_P2P_GO:
1788 if (wdev->beacon_interval) {
1789 result = -EBUSY;
1790 break;
1791 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001792 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001793 result = -EINVAL;
1794 break;
1795 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001796 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001797 result = 0;
1798 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001799 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001800 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001801 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001802 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001803 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001804 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001805 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001806 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001807 }
1808 mutex_unlock(&rdev->devlist_mtx);
1809
1810 return result;
1811}
1812
1813static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1814{
Johannes Berg4c476992010-10-04 21:36:35 +02001815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1816 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001817
Johannes Berg4c476992010-10-04 21:36:35 +02001818 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001819}
1820
Bill Jordane8347eb2010-10-01 13:54:28 -04001821static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1822{
Johannes Berg43b19952010-10-07 13:10:30 +02001823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1824 struct net_device *dev = info->user_ptr[1];
1825 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001826 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001827
1828 if (!info->attrs[NL80211_ATTR_MAC])
1829 return -EINVAL;
1830
Johannes Berg43b19952010-10-07 13:10:30 +02001831 if (netif_running(dev))
1832 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001833
Johannes Berg43b19952010-10-07 13:10:30 +02001834 if (!rdev->ops->set_wds_peer)
1835 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001836
Johannes Berg43b19952010-10-07 13:10:30 +02001837 if (wdev->iftype != NL80211_IFTYPE_WDS)
1838 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001839
1840 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001841 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001842}
1843
1844
Johannes Berg55682962007-09-20 13:09:35 -04001845static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1846{
1847 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001848 struct net_device *netdev = NULL;
1849 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001850 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001851 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001852 u32 changed;
1853 u8 retry_short = 0, retry_long = 0;
1854 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001855 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001856
Johannes Bergf444de02010-05-05 15:25:02 +02001857 /*
1858 * Try to find the wiphy and netdev. Normally this
1859 * function shouldn't need the netdev, but this is
1860 * done for backward compatibility -- previously
1861 * setting the channel was done per wiphy, but now
1862 * it is per netdev. Previous userland like hostapd
1863 * also passed a netdev to set_wiphy, so that it is
1864 * possible to let that go to the right netdev!
1865 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001866 mutex_lock(&cfg80211_mutex);
1867
Johannes Bergf444de02010-05-05 15:25:02 +02001868 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1869 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1870
1871 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1872 if (netdev && netdev->ieee80211_ptr) {
1873 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1874 mutex_lock(&rdev->mtx);
1875 } else
1876 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001877 }
1878
Johannes Bergf444de02010-05-05 15:25:02 +02001879 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001880 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1881 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001882 if (IS_ERR(rdev)) {
1883 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001884 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001885 }
1886 wdev = NULL;
1887 netdev = NULL;
1888 result = 0;
1889
1890 mutex_lock(&rdev->mtx);
Johannes Berg71fe96b2012-10-24 10:04:58 +02001891 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001892 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001893
1894 /*
1895 * end workaround code, by now the rdev is available
1896 * and locked, and wdev may or may not be NULL.
1897 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001898
1899 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001900 result = cfg80211_dev_rename(
1901 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001902
1903 mutex_unlock(&cfg80211_mutex);
1904
1905 if (result)
1906 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001907
Jouni Malinen31888482008-10-30 16:59:24 +02001908 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1909 struct ieee80211_txq_params txq_params;
1910 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1911
1912 if (!rdev->ops->set_txq_params) {
1913 result = -EOPNOTSUPP;
1914 goto bad_res;
1915 }
1916
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001917 if (!netdev) {
1918 result = -EINVAL;
1919 goto bad_res;
1920 }
1921
Johannes Berg133a3ff2011-11-03 14:50:13 +01001922 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1923 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1924 result = -EINVAL;
1925 goto bad_res;
1926 }
1927
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001928 if (!netif_running(netdev)) {
1929 result = -ENETDOWN;
1930 goto bad_res;
1931 }
1932
Jouni Malinen31888482008-10-30 16:59:24 +02001933 nla_for_each_nested(nl_txq_params,
1934 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1935 rem_txq_params) {
1936 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1937 nla_data(nl_txq_params),
1938 nla_len(nl_txq_params),
1939 txq_params_policy);
1940 result = parse_txq_params(tb, &txq_params);
1941 if (result)
1942 goto bad_res;
1943
Hila Gonene35e4d22012-06-27 17:19:42 +03001944 result = rdev_set_txq_params(rdev, netdev,
1945 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001946 if (result)
1947 goto bad_res;
1948 }
1949 }
1950
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001951 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001952 result = __nl80211_set_channel(rdev,
1953 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1954 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001955 if (result)
1956 goto bad_res;
1957 }
1958
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001959 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001960 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001961 enum nl80211_tx_power_setting type;
1962 int idx, mbm = 0;
1963
Johannes Bergc8442112012-10-24 10:17:18 +02001964 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1965 txp_wdev = NULL;
1966
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001967 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001968 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001969 goto bad_res;
1970 }
1971
1972 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1973 type = nla_get_u32(info->attrs[idx]);
1974
1975 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1976 (type != NL80211_TX_POWER_AUTOMATIC)) {
1977 result = -EINVAL;
1978 goto bad_res;
1979 }
1980
1981 if (type != NL80211_TX_POWER_AUTOMATIC) {
1982 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1983 mbm = nla_get_u32(info->attrs[idx]);
1984 }
1985
Johannes Bergc8442112012-10-24 10:17:18 +02001986 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001987 if (result)
1988 goto bad_res;
1989 }
1990
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001991 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1992 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1993 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001994 if ((!rdev->wiphy.available_antennas_tx &&
1995 !rdev->wiphy.available_antennas_rx) ||
1996 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001997 result = -EOPNOTSUPP;
1998 goto bad_res;
1999 }
2000
2001 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2002 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2003
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002004 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002005 * available antenna masks, except for the "all" mask */
2006 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2007 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002008 result = -EINVAL;
2009 goto bad_res;
2010 }
2011
Bruno Randolf7f531e02010-12-16 11:30:22 +09002012 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2013 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002014
Hila Gonene35e4d22012-06-27 17:19:42 +03002015 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002016 if (result)
2017 goto bad_res;
2018 }
2019
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002020 changed = 0;
2021
2022 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2023 retry_short = nla_get_u8(
2024 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2025 if (retry_short == 0) {
2026 result = -EINVAL;
2027 goto bad_res;
2028 }
2029 changed |= WIPHY_PARAM_RETRY_SHORT;
2030 }
2031
2032 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2033 retry_long = nla_get_u8(
2034 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2035 if (retry_long == 0) {
2036 result = -EINVAL;
2037 goto bad_res;
2038 }
2039 changed |= WIPHY_PARAM_RETRY_LONG;
2040 }
2041
2042 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2043 frag_threshold = nla_get_u32(
2044 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2045 if (frag_threshold < 256) {
2046 result = -EINVAL;
2047 goto bad_res;
2048 }
2049 if (frag_threshold != (u32) -1) {
2050 /*
2051 * Fragments (apart from the last one) are required to
2052 * have even length. Make the fragmentation code
2053 * simpler by stripping LSB should someone try to use
2054 * odd threshold value.
2055 */
2056 frag_threshold &= ~0x1;
2057 }
2058 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2059 }
2060
2061 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2062 rts_threshold = nla_get_u32(
2063 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2064 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2065 }
2066
Lukáš Turek81077e82009-12-21 22:50:47 +01002067 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2068 coverage_class = nla_get_u8(
2069 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2070 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2071 }
2072
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002073 if (changed) {
2074 u8 old_retry_short, old_retry_long;
2075 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002076 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002077
2078 if (!rdev->ops->set_wiphy_params) {
2079 result = -EOPNOTSUPP;
2080 goto bad_res;
2081 }
2082
2083 old_retry_short = rdev->wiphy.retry_short;
2084 old_retry_long = rdev->wiphy.retry_long;
2085 old_frag_threshold = rdev->wiphy.frag_threshold;
2086 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002087 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002088
2089 if (changed & WIPHY_PARAM_RETRY_SHORT)
2090 rdev->wiphy.retry_short = retry_short;
2091 if (changed & WIPHY_PARAM_RETRY_LONG)
2092 rdev->wiphy.retry_long = retry_long;
2093 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2094 rdev->wiphy.frag_threshold = frag_threshold;
2095 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2096 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002097 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2098 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002099
Hila Gonene35e4d22012-06-27 17:19:42 +03002100 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002101 if (result) {
2102 rdev->wiphy.retry_short = old_retry_short;
2103 rdev->wiphy.retry_long = old_retry_long;
2104 rdev->wiphy.frag_threshold = old_frag_threshold;
2105 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002106 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002107 }
2108 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002109
Johannes Berg306d6112008-12-08 12:39:04 +01002110 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002111 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02002112 if (netdev)
2113 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002114 return result;
2115}
2116
Johannes Berg71bbc992012-06-15 15:30:18 +02002117static inline u64 wdev_id(struct wireless_dev *wdev)
2118{
2119 return (u64)wdev->identifier |
2120 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2121}
Johannes Berg55682962007-09-20 13:09:35 -04002122
Johannes Berg683b6d32012-11-08 21:25:48 +01002123static int nl80211_send_chandef(struct sk_buff *msg,
2124 struct cfg80211_chan_def *chandef)
2125{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002126 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002127
Johannes Berg683b6d32012-11-08 21:25:48 +01002128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2129 chandef->chan->center_freq))
2130 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002131 switch (chandef->width) {
2132 case NL80211_CHAN_WIDTH_20_NOHT:
2133 case NL80211_CHAN_WIDTH_20:
2134 case NL80211_CHAN_WIDTH_40:
2135 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2136 cfg80211_get_chandef_type(chandef)))
2137 return -ENOBUFS;
2138 break;
2139 default:
2140 break;
2141 }
2142 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2143 return -ENOBUFS;
2144 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2145 return -ENOBUFS;
2146 if (chandef->center_freq2 &&
2147 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002148 return -ENOBUFS;
2149 return 0;
2150}
2151
Eric W. Biederman15e47302012-09-07 20:12:54 +00002152static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002153 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002154 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002155{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002156 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002157 void *hdr;
2158
Eric W. Biederman15e47302012-09-07 20:12:54 +00002159 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002160 if (!hdr)
2161 return -1;
2162
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002163 if (dev &&
2164 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002165 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002166 goto nla_put_failure;
2167
2168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2169 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002170 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002171 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002172 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2173 rdev->devlist_generation ^
2174 (cfg80211_rdev_list_generation << 2)))
2175 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002176
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002177 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002178 int ret;
2179 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002180
Johannes Berg683b6d32012-11-08 21:25:48 +01002181 ret = rdev_get_channel(rdev, wdev, &chandef);
2182 if (ret == 0) {
2183 if (nl80211_send_chandef(msg, &chandef))
2184 goto nla_put_failure;
2185 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002186 }
2187
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002188 if (wdev->ssid_len) {
2189 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2190 goto nla_put_failure;
2191 }
2192
Johannes Berg55682962007-09-20 13:09:35 -04002193 return genlmsg_end(msg, hdr);
2194
2195 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002196 genlmsg_cancel(msg, hdr);
2197 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002198}
2199
2200static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2201{
2202 int wp_idx = 0;
2203 int if_idx = 0;
2204 int wp_start = cb->args[0];
2205 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002206 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002207 struct wireless_dev *wdev;
2208
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002209 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02002210 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2211 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002212 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002213 if (wp_idx < wp_start) {
2214 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002215 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002216 }
Johannes Berg55682962007-09-20 13:09:35 -04002217 if_idx = 0;
2218
Johannes Bergf5ea9122009-08-07 16:17:38 +02002219 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02002220 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002221 if (if_idx < if_start) {
2222 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002223 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002224 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002225 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002226 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002227 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02002228 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002229 goto out;
2230 }
2231 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002232 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02002233 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002234
2235 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002236 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002237 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002238 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04002239
2240 cb->args[0] = wp_idx;
2241 cb->args[1] = if_idx;
2242
2243 return skb->len;
2244}
2245
2246static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2247{
2248 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002249 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002250 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002251
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002253 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002254 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002255
Eric W. Biederman15e47302012-09-07 20:12:54 +00002256 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002257 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002258 nlmsg_free(msg);
2259 return -ENOBUFS;
2260 }
Johannes Berg55682962007-09-20 13:09:35 -04002261
Johannes Berg134e6372009-07-10 09:51:34 +00002262 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002263}
2264
Michael Wu66f7ac52008-01-31 19:48:22 +01002265static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2266 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2267 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2268 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2269 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2270 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2271};
2272
2273static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2274{
2275 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2276 int flag;
2277
2278 *mntrflags = 0;
2279
2280 if (!nla)
2281 return -EINVAL;
2282
2283 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2284 nla, mntr_flags_policy))
2285 return -EINVAL;
2286
2287 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2288 if (flags[flag])
2289 *mntrflags |= (1<<flag);
2290
2291 return 0;
2292}
2293
Johannes Berg9bc383d2009-11-19 11:55:19 +01002294static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002295 struct net_device *netdev, u8 use_4addr,
2296 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002297{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002298 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002299 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002300 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002301 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002302 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002303
2304 switch (iftype) {
2305 case NL80211_IFTYPE_AP_VLAN:
2306 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2307 return 0;
2308 break;
2309 case NL80211_IFTYPE_STATION:
2310 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2311 return 0;
2312 break;
2313 default:
2314 break;
2315 }
2316
2317 return -EOPNOTSUPP;
2318}
2319
Johannes Berg55682962007-09-20 13:09:35 -04002320static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2321{
Johannes Berg4c476992010-10-04 21:36:35 +02002322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002323 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002324 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002325 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002326 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002327 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002328 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002329
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002330 memset(&params, 0, sizeof(params));
2331
Johannes Berg04a773a2009-04-19 21:24:32 +02002332 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002333
Johannes Berg723b0382008-09-16 20:22:09 +02002334 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002335 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002336 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002337 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002338 if (ntype > NL80211_IFTYPE_MAX)
2339 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002340 }
2341
Johannes Berg92ffe052008-09-16 20:39:36 +02002342 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002343 struct wireless_dev *wdev = dev->ieee80211_ptr;
2344
Johannes Berg4c476992010-10-04 21:36:35 +02002345 if (ntype != NL80211_IFTYPE_MESH_POINT)
2346 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002347 if (netif_running(dev))
2348 return -EBUSY;
2349
2350 wdev_lock(wdev);
2351 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2352 IEEE80211_MAX_MESH_ID_LEN);
2353 wdev->mesh_id_up_len =
2354 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2355 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2356 wdev->mesh_id_up_len);
2357 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002358 }
2359
Felix Fietkau8b787642009-11-10 18:53:10 +01002360 if (info->attrs[NL80211_ATTR_4ADDR]) {
2361 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2362 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002363 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002364 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002365 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002366 } else {
2367 params.use_4addr = -1;
2368 }
2369
Johannes Berg92ffe052008-09-16 20:39:36 +02002370 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002371 if (ntype != NL80211_IFTYPE_MONITOR)
2372 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002373 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2374 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002375 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002376 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002377
2378 flags = &_flags;
2379 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002380 }
Johannes Berg3b858752009-03-12 09:55:09 +01002381
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002382 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002383 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002384 else
2385 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002386
Johannes Berg9bc383d2009-11-19 11:55:19 +01002387 if (!err && params.use_4addr != -1)
2388 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2389
Johannes Berg55682962007-09-20 13:09:35 -04002390 return err;
2391}
2392
2393static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2394{
Johannes Berg4c476992010-10-04 21:36:35 +02002395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002396 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002397 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002398 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002399 int err;
2400 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002401 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002402
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002403 memset(&params, 0, sizeof(params));
2404
Johannes Berg55682962007-09-20 13:09:35 -04002405 if (!info->attrs[NL80211_ATTR_IFNAME])
2406 return -EINVAL;
2407
2408 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2409 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2410 if (type > NL80211_IFTYPE_MAX)
2411 return -EINVAL;
2412 }
2413
Johannes Berg79c97e92009-07-07 03:56:12 +02002414 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002415 !(rdev->wiphy.interface_modes & (1 << type)))
2416 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002417
Arend van Spriel1c18f142013-01-08 10:17:27 +01002418 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2419 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2420 ETH_ALEN);
2421 if (!is_valid_ether_addr(params.macaddr))
2422 return -EADDRNOTAVAIL;
2423 }
2424
Johannes Berg9bc383d2009-11-19 11:55:19 +01002425 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002426 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002427 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002428 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002429 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002430 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002431
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2433 if (!msg)
2434 return -ENOMEM;
2435
Michael Wu66f7ac52008-01-31 19:48:22 +01002436 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2437 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2438 &flags);
Hila Gonene35e4d22012-06-27 17:19:42 +03002439 wdev = rdev_add_virtual_intf(rdev,
2440 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2441 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002442 if (IS_ERR(wdev)) {
2443 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002444 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002445 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002446
Johannes Berg98104fde2012-06-16 00:19:54 +02002447 switch (type) {
2448 case NL80211_IFTYPE_MESH_POINT:
2449 if (!info->attrs[NL80211_ATTR_MESH_ID])
2450 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002451 wdev_lock(wdev);
2452 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2453 IEEE80211_MAX_MESH_ID_LEN);
2454 wdev->mesh_id_up_len =
2455 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2456 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2457 wdev->mesh_id_up_len);
2458 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002459 break;
2460 case NL80211_IFTYPE_P2P_DEVICE:
2461 /*
2462 * P2P Device doesn't have a netdev, so doesn't go
2463 * through the netdev notifier and must be added here
2464 */
2465 mutex_init(&wdev->mtx);
2466 INIT_LIST_HEAD(&wdev->event_list);
2467 spin_lock_init(&wdev->event_lock);
2468 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2469 spin_lock_init(&wdev->mgmt_registrations_lock);
2470
2471 mutex_lock(&rdev->devlist_mtx);
2472 wdev->identifier = ++rdev->wdev_id;
2473 list_add_rcu(&wdev->list, &rdev->wdev_list);
2474 rdev->devlist_generation++;
2475 mutex_unlock(&rdev->devlist_mtx);
2476 break;
2477 default:
2478 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002479 }
2480
Eric W. Biederman15e47302012-09-07 20:12:54 +00002481 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002482 rdev, wdev) < 0) {
2483 nlmsg_free(msg);
2484 return -ENOBUFS;
2485 }
2486
2487 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002488}
2489
2490static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2491{
Johannes Berg4c476992010-10-04 21:36:35 +02002492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002493 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002494
Johannes Berg4c476992010-10-04 21:36:35 +02002495 if (!rdev->ops->del_virtual_intf)
2496 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002497
Johannes Berg84efbb82012-06-16 00:00:26 +02002498 /*
2499 * If we remove a wireless device without a netdev then clear
2500 * user_ptr[1] so that nl80211_post_doit won't dereference it
2501 * to check if it needs to do dev_put(). Otherwise it crashes
2502 * since the wdev has been freed, unlike with a netdev where
2503 * we need the dev_put() for the netdev to really be freed.
2504 */
2505 if (!wdev->netdev)
2506 info->user_ptr[1] = NULL;
2507
Hila Gonene35e4d22012-06-27 17:19:42 +03002508 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002509}
2510
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002511static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2512{
2513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2514 struct net_device *dev = info->user_ptr[1];
2515 u16 noack_map;
2516
2517 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2518 return -EINVAL;
2519
2520 if (!rdev->ops->set_noack_map)
2521 return -EOPNOTSUPP;
2522
2523 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2524
Hila Gonene35e4d22012-06-27 17:19:42 +03002525 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002526}
2527
Johannes Berg41ade002007-12-19 02:03:29 +01002528struct get_key_cookie {
2529 struct sk_buff *msg;
2530 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002531 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002532};
2533
2534static void get_key_callback(void *c, struct key_params *params)
2535{
Johannes Bergb9454e82009-07-08 13:29:08 +02002536 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002537 struct get_key_cookie *cookie = c;
2538
David S. Miller9360ffd2012-03-29 04:41:26 -04002539 if ((params->key &&
2540 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2541 params->key_len, params->key)) ||
2542 (params->seq &&
2543 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2544 params->seq_len, params->seq)) ||
2545 (params->cipher &&
2546 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2547 params->cipher)))
2548 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002549
Johannes Bergb9454e82009-07-08 13:29:08 +02002550 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2551 if (!key)
2552 goto nla_put_failure;
2553
David S. Miller9360ffd2012-03-29 04:41:26 -04002554 if ((params->key &&
2555 nla_put(cookie->msg, NL80211_KEY_DATA,
2556 params->key_len, params->key)) ||
2557 (params->seq &&
2558 nla_put(cookie->msg, NL80211_KEY_SEQ,
2559 params->seq_len, params->seq)) ||
2560 (params->cipher &&
2561 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2562 params->cipher)))
2563 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002564
David S. Miller9360ffd2012-03-29 04:41:26 -04002565 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2566 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002567
2568 nla_nest_end(cookie->msg, key);
2569
Johannes Berg41ade002007-12-19 02:03:29 +01002570 return;
2571 nla_put_failure:
2572 cookie->error = 1;
2573}
2574
2575static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2576{
Johannes Berg4c476992010-10-04 21:36:35 +02002577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002578 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002579 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002580 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002581 const u8 *mac_addr = NULL;
2582 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002583 struct get_key_cookie cookie = {
2584 .error = 0,
2585 };
2586 void *hdr;
2587 struct sk_buff *msg;
2588
2589 if (info->attrs[NL80211_ATTR_KEY_IDX])
2590 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2591
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002592 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002593 return -EINVAL;
2594
2595 if (info->attrs[NL80211_ATTR_MAC])
2596 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2597
Johannes Berge31b8212010-10-05 19:39:30 +02002598 pairwise = !!mac_addr;
2599 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2600 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2601 if (kt >= NUM_NL80211_KEYTYPES)
2602 return -EINVAL;
2603 if (kt != NL80211_KEYTYPE_GROUP &&
2604 kt != NL80211_KEYTYPE_PAIRWISE)
2605 return -EINVAL;
2606 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2607 }
2608
Johannes Berg4c476992010-10-04 21:36:35 +02002609 if (!rdev->ops->get_key)
2610 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002611
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002613 if (!msg)
2614 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002615
Eric W. Biederman15e47302012-09-07 20:12:54 +00002616 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002617 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002618 if (IS_ERR(hdr))
2619 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002620
2621 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002622 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002623
David S. Miller9360ffd2012-03-29 04:41:26 -04002624 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2625 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2626 goto nla_put_failure;
2627 if (mac_addr &&
2628 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2629 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002630
Johannes Berge31b8212010-10-05 19:39:30 +02002631 if (pairwise && mac_addr &&
2632 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2633 return -ENOENT;
2634
Hila Gonene35e4d22012-06-27 17:19:42 +03002635 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2636 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002637
2638 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002639 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002640
2641 if (cookie.error)
2642 goto nla_put_failure;
2643
2644 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002645 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002646
2647 nla_put_failure:
2648 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002649 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002650 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002651 return err;
2652}
2653
2654static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2655{
Johannes Berg4c476992010-10-04 21:36:35 +02002656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002657 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002658 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002659 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002660
Johannes Bergb9454e82009-07-08 13:29:08 +02002661 err = nl80211_parse_key(info, &key);
2662 if (err)
2663 return err;
2664
2665 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002666 return -EINVAL;
2667
Johannes Bergb9454e82009-07-08 13:29:08 +02002668 /* only support setting default key */
2669 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002670 return -EINVAL;
2671
Johannes Bergfffd0932009-07-08 14:22:54 +02002672 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002673
2674 if (key.def) {
2675 if (!rdev->ops->set_default_key) {
2676 err = -EOPNOTSUPP;
2677 goto out;
2678 }
2679
2680 err = nl80211_key_allowed(dev->ieee80211_ptr);
2681 if (err)
2682 goto out;
2683
Hila Gonene35e4d22012-06-27 17:19:42 +03002684 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002685 key.def_uni, key.def_multi);
2686
2687 if (err)
2688 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002689
Johannes Berg3d23e342009-09-29 23:27:28 +02002690#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002691 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002692#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002693 } else {
2694 if (key.def_uni || !key.def_multi) {
2695 err = -EINVAL;
2696 goto out;
2697 }
2698
2699 if (!rdev->ops->set_default_mgmt_key) {
2700 err = -EOPNOTSUPP;
2701 goto out;
2702 }
2703
2704 err = nl80211_key_allowed(dev->ieee80211_ptr);
2705 if (err)
2706 goto out;
2707
Hila Gonene35e4d22012-06-27 17:19:42 +03002708 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002709 if (err)
2710 goto out;
2711
2712#ifdef CONFIG_CFG80211_WEXT
2713 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2714#endif
2715 }
2716
2717 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002718 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002719
Johannes Berg41ade002007-12-19 02:03:29 +01002720 return err;
2721}
2722
2723static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2724{
Johannes Berg4c476992010-10-04 21:36:35 +02002725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002726 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002727 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002728 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002729 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002730
Johannes Bergb9454e82009-07-08 13:29:08 +02002731 err = nl80211_parse_key(info, &key);
2732 if (err)
2733 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002734
Johannes Bergb9454e82009-07-08 13:29:08 +02002735 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002736 return -EINVAL;
2737
Johannes Berg41ade002007-12-19 02:03:29 +01002738 if (info->attrs[NL80211_ATTR_MAC])
2739 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2740
Johannes Berge31b8212010-10-05 19:39:30 +02002741 if (key.type == -1) {
2742 if (mac_addr)
2743 key.type = NL80211_KEYTYPE_PAIRWISE;
2744 else
2745 key.type = NL80211_KEYTYPE_GROUP;
2746 }
2747
2748 /* for now */
2749 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2750 key.type != NL80211_KEYTYPE_GROUP)
2751 return -EINVAL;
2752
Johannes Berg4c476992010-10-04 21:36:35 +02002753 if (!rdev->ops->add_key)
2754 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002755
Johannes Berge31b8212010-10-05 19:39:30 +02002756 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2757 key.type == NL80211_KEYTYPE_PAIRWISE,
2758 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002759 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002760
2761 wdev_lock(dev->ieee80211_ptr);
2762 err = nl80211_key_allowed(dev->ieee80211_ptr);
2763 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002764 err = rdev_add_key(rdev, dev, key.idx,
2765 key.type == NL80211_KEYTYPE_PAIRWISE,
2766 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002767 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002768
Johannes Berg41ade002007-12-19 02:03:29 +01002769 return err;
2770}
2771
2772static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2773{
Johannes Berg4c476992010-10-04 21:36:35 +02002774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002775 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002776 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002777 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002778 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002779
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 err = nl80211_parse_key(info, &key);
2781 if (err)
2782 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002783
2784 if (info->attrs[NL80211_ATTR_MAC])
2785 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2786
Johannes Berge31b8212010-10-05 19:39:30 +02002787 if (key.type == -1) {
2788 if (mac_addr)
2789 key.type = NL80211_KEYTYPE_PAIRWISE;
2790 else
2791 key.type = NL80211_KEYTYPE_GROUP;
2792 }
2793
2794 /* for now */
2795 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2796 key.type != NL80211_KEYTYPE_GROUP)
2797 return -EINVAL;
2798
Johannes Berg4c476992010-10-04 21:36:35 +02002799 if (!rdev->ops->del_key)
2800 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002801
Johannes Bergfffd0932009-07-08 14:22:54 +02002802 wdev_lock(dev->ieee80211_ptr);
2803 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002804
2805 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2806 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2807 err = -ENOENT;
2808
Johannes Bergfffd0932009-07-08 14:22:54 +02002809 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002810 err = rdev_del_key(rdev, dev, key.idx,
2811 key.type == NL80211_KEYTYPE_PAIRWISE,
2812 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002813
Johannes Berg3d23e342009-09-29 23:27:28 +02002814#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002815 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002816 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002817 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002819 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2820 }
2821#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002822 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002823
Johannes Berg41ade002007-12-19 02:03:29 +01002824 return err;
2825}
2826
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302827/* This function returns an error or the number of nested attributes */
2828static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2829{
2830 struct nlattr *attr;
2831 int n_entries = 0, tmp;
2832
2833 nla_for_each_nested(attr, nl_attr, tmp) {
2834 if (nla_len(attr) != ETH_ALEN)
2835 return -EINVAL;
2836
2837 n_entries++;
2838 }
2839
2840 return n_entries;
2841}
2842
2843/*
2844 * This function parses ACL information and allocates memory for ACL data.
2845 * On successful return, the calling function is responsible to free the
2846 * ACL buffer returned by this function.
2847 */
2848static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2849 struct genl_info *info)
2850{
2851 enum nl80211_acl_policy acl_policy;
2852 struct nlattr *attr;
2853 struct cfg80211_acl_data *acl;
2854 int i = 0, n_entries, tmp;
2855
2856 if (!wiphy->max_acl_mac_addrs)
2857 return ERR_PTR(-EOPNOTSUPP);
2858
2859 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2860 return ERR_PTR(-EINVAL);
2861
2862 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2863 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2864 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2865 return ERR_PTR(-EINVAL);
2866
2867 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2868 return ERR_PTR(-EINVAL);
2869
2870 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2871 if (n_entries < 0)
2872 return ERR_PTR(n_entries);
2873
2874 if (n_entries > wiphy->max_acl_mac_addrs)
2875 return ERR_PTR(-ENOTSUPP);
2876
2877 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2878 GFP_KERNEL);
2879 if (!acl)
2880 return ERR_PTR(-ENOMEM);
2881
2882 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2883 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2884 i++;
2885 }
2886
2887 acl->n_acl_entries = n_entries;
2888 acl->acl_policy = acl_policy;
2889
2890 return acl;
2891}
2892
2893static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2894{
2895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2896 struct net_device *dev = info->user_ptr[1];
2897 struct cfg80211_acl_data *acl;
2898 int err;
2899
2900 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2901 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2902 return -EOPNOTSUPP;
2903
2904 if (!dev->ieee80211_ptr->beacon_interval)
2905 return -EINVAL;
2906
2907 acl = parse_acl_data(&rdev->wiphy, info);
2908 if (IS_ERR(acl))
2909 return PTR_ERR(acl);
2910
2911 err = rdev_set_mac_acl(rdev, dev, acl);
2912
2913 kfree(acl);
2914
2915 return err;
2916}
2917
Johannes Berg88600202012-02-13 15:17:18 +01002918static int nl80211_parse_beacon(struct genl_info *info,
2919 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002920{
Johannes Berg88600202012-02-13 15:17:18 +01002921 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002922
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002923 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2924 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2925 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2926 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002927 return -EINVAL;
2928
Johannes Berg88600202012-02-13 15:17:18 +01002929 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002930
Johannes Berged1b6cc2007-12-19 02:03:32 +01002931 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002932 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2933 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2934 if (!bcn->head_len)
2935 return -EINVAL;
2936 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002937 }
2938
2939 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002940 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2941 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002942 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002943 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002944 }
2945
Johannes Berg4c476992010-10-04 21:36:35 +02002946 if (!haveinfo)
2947 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002948
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002949 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002950 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2951 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002952 }
2953
2954 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002955 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002956 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002957 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002958 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2959 }
2960
2961 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002962 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002963 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002964 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002965 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2966 }
2967
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002968 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002969 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002970 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002971 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002972 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2973 }
2974
Johannes Berg88600202012-02-13 15:17:18 +01002975 return 0;
2976}
2977
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002978static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2979 struct cfg80211_ap_settings *params)
2980{
2981 struct wireless_dev *wdev;
2982 bool ret = false;
2983
2984 mutex_lock(&rdev->devlist_mtx);
2985
Johannes Berg89a54e42012-06-15 14:33:17 +02002986 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002987 if (wdev->iftype != NL80211_IFTYPE_AP &&
2988 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2989 continue;
2990
Johannes Berg683b6d32012-11-08 21:25:48 +01002991 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002992 continue;
2993
Johannes Berg683b6d32012-11-08 21:25:48 +01002994 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002995 ret = true;
2996 break;
2997 }
2998
2999 mutex_unlock(&rdev->devlist_mtx);
3000
3001 return ret;
3002}
3003
Jouni Malinene39e5b52012-09-30 19:29:39 +03003004static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3005 enum nl80211_auth_type auth_type,
3006 enum nl80211_commands cmd)
3007{
3008 if (auth_type > NL80211_AUTHTYPE_MAX)
3009 return false;
3010
3011 switch (cmd) {
3012 case NL80211_CMD_AUTHENTICATE:
3013 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3014 auth_type == NL80211_AUTHTYPE_SAE)
3015 return false;
3016 return true;
3017 case NL80211_CMD_CONNECT:
3018 case NL80211_CMD_START_AP:
3019 /* SAE not supported yet */
3020 if (auth_type == NL80211_AUTHTYPE_SAE)
3021 return false;
3022 return true;
3023 default:
3024 return false;
3025 }
3026}
3027
Johannes Berg88600202012-02-13 15:17:18 +01003028static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3029{
3030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3031 struct net_device *dev = info->user_ptr[1];
3032 struct wireless_dev *wdev = dev->ieee80211_ptr;
3033 struct cfg80211_ap_settings params;
3034 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003035 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003036
3037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3038 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3039 return -EOPNOTSUPP;
3040
3041 if (!rdev->ops->start_ap)
3042 return -EOPNOTSUPP;
3043
3044 if (wdev->beacon_interval)
3045 return -EALREADY;
3046
3047 memset(&params, 0, sizeof(params));
3048
3049 /* these are required for START_AP */
3050 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3051 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3052 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3053 return -EINVAL;
3054
3055 err = nl80211_parse_beacon(info, &params.beacon);
3056 if (err)
3057 return err;
3058
3059 params.beacon_interval =
3060 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3061 params.dtim_period =
3062 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3063
3064 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3065 if (err)
3066 return err;
3067
3068 /*
3069 * In theory, some of these attributes should be required here
3070 * but since they were not used when the command was originally
3071 * added, keep them optional for old user space programs to let
3072 * them continue to work with drivers that do not need the
3073 * additional information -- drivers must check!
3074 */
3075 if (info->attrs[NL80211_ATTR_SSID]) {
3076 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3077 params.ssid_len =
3078 nla_len(info->attrs[NL80211_ATTR_SSID]);
3079 if (params.ssid_len == 0 ||
3080 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3081 return -EINVAL;
3082 }
3083
3084 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3085 params.hidden_ssid = nla_get_u32(
3086 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3087 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3088 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3089 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3090 return -EINVAL;
3091 }
3092
3093 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3094
3095 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3096 params.auth_type = nla_get_u32(
3097 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003098 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3099 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003100 return -EINVAL;
3101 } else
3102 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3103
3104 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3105 NL80211_MAX_NR_CIPHER_SUITES);
3106 if (err)
3107 return err;
3108
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303109 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3110 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3111 return -EOPNOTSUPP;
3112 params.inactivity_timeout = nla_get_u16(
3113 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3114 }
3115
Johannes Berg53cabad2012-11-14 15:17:28 +01003116 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3117 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3118 return -EINVAL;
3119 params.p2p_ctwindow =
3120 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3121 if (params.p2p_ctwindow > 127)
3122 return -EINVAL;
3123 if (params.p2p_ctwindow != 0 &&
3124 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3125 return -EINVAL;
3126 }
3127
3128 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3129 u8 tmp;
3130
3131 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3132 return -EINVAL;
3133 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3134 if (tmp > 1)
3135 return -EINVAL;
3136 params.p2p_opp_ps = tmp;
3137 if (params.p2p_opp_ps != 0 &&
3138 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3139 return -EINVAL;
3140 }
3141
Johannes Bergaa430da2012-05-16 23:50:18 +02003142 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003143 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3144 if (err)
3145 return err;
3146 } else if (wdev->preset_chandef.chan) {
3147 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003148 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003149 return -EINVAL;
3150
Johannes Berg683b6d32012-11-08 21:25:48 +01003151 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003152 return -EINVAL;
3153
Simon Wunderlich04f39042013-02-08 18:16:19 +01003154 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3155 if (err < 0)
3156 return err;
3157 if (err) {
3158 radar_detect_width = BIT(params.chandef.width);
3159 params.radar_required = true;
3160 }
3161
Michal Kaziore4e32452012-06-29 12:47:08 +02003162 mutex_lock(&rdev->devlist_mtx);
Simon Wunderlich04f39042013-02-08 18:16:19 +01003163 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3164 params.chandef.chan,
3165 CHAN_MODE_SHARED,
3166 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003167 mutex_unlock(&rdev->devlist_mtx);
3168
3169 if (err)
3170 return err;
3171
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303172 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3173 params.acl = parse_acl_data(&rdev->wiphy, info);
3174 if (IS_ERR(params.acl))
3175 return PTR_ERR(params.acl);
3176 }
3177
Hila Gonene35e4d22012-06-27 17:19:42 +03003178 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003179 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003180 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003181 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003182 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003183 wdev->ssid_len = params.ssid_len;
3184 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003185 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303186
3187 kfree(params.acl);
3188
Johannes Berg56d18932011-05-09 18:41:15 +02003189 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003190}
3191
Johannes Berg88600202012-02-13 15:17:18 +01003192static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3193{
3194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3195 struct net_device *dev = info->user_ptr[1];
3196 struct wireless_dev *wdev = dev->ieee80211_ptr;
3197 struct cfg80211_beacon_data params;
3198 int err;
3199
3200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3202 return -EOPNOTSUPP;
3203
3204 if (!rdev->ops->change_beacon)
3205 return -EOPNOTSUPP;
3206
3207 if (!wdev->beacon_interval)
3208 return -EINVAL;
3209
3210 err = nl80211_parse_beacon(info, &params);
3211 if (err)
3212 return err;
3213
Hila Gonene35e4d22012-06-27 17:19:42 +03003214 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003215}
3216
3217static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003218{
Johannes Berg4c476992010-10-04 21:36:35 +02003219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3220 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003221
Michal Kazior60771782012-06-29 12:46:56 +02003222 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003223}
3224
Johannes Berg5727ef12007-12-19 02:03:34 +01003225static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3226 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3227 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3228 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003229 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003230 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003231 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003232};
3233
Johannes Bergeccb8e82009-05-11 21:57:56 +03003234static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003235 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003236 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003237{
3238 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003239 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003240 int flag;
3241
Johannes Bergeccb8e82009-05-11 21:57:56 +03003242 /*
3243 * Try parsing the new attribute first so userspace
3244 * can specify both for older kernels.
3245 */
3246 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3247 if (nla) {
3248 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003249
Johannes Bergeccb8e82009-05-11 21:57:56 +03003250 sta_flags = nla_data(nla);
3251 params->sta_flags_mask = sta_flags->mask;
3252 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003253 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003254 if ((params->sta_flags_mask |
3255 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3256 return -EINVAL;
3257 return 0;
3258 }
3259
3260 /* if present, parse the old attribute */
3261
3262 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003263 if (!nla)
3264 return 0;
3265
3266 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3267 nla, sta_flags_policy))
3268 return -EINVAL;
3269
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003270 /*
3271 * Only allow certain flags for interface types so that
3272 * other attributes are silently ignored. Remember that
3273 * this is backward compatibility code with old userspace
3274 * and shouldn't be hit in other cases anyway.
3275 */
3276 switch (iftype) {
3277 case NL80211_IFTYPE_AP:
3278 case NL80211_IFTYPE_AP_VLAN:
3279 case NL80211_IFTYPE_P2P_GO:
3280 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3281 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3282 BIT(NL80211_STA_FLAG_WME) |
3283 BIT(NL80211_STA_FLAG_MFP);
3284 break;
3285 case NL80211_IFTYPE_P2P_CLIENT:
3286 case NL80211_IFTYPE_STATION:
3287 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3288 BIT(NL80211_STA_FLAG_TDLS_PEER);
3289 break;
3290 case NL80211_IFTYPE_MESH_POINT:
3291 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3292 BIT(NL80211_STA_FLAG_MFP) |
3293 BIT(NL80211_STA_FLAG_AUTHORIZED);
3294 default:
3295 return -EINVAL;
3296 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003297
Johannes Berg3383b5a2012-05-10 20:14:43 +02003298 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3299 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003300 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003301
Johannes Berg3383b5a2012-05-10 20:14:43 +02003302 /* no longer support new API additions in old API */
3303 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3304 return -EINVAL;
3305 }
3306 }
3307
Johannes Berg5727ef12007-12-19 02:03:34 +01003308 return 0;
3309}
3310
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003311static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3312 int attr)
3313{
3314 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003315 u32 bitrate;
3316 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003317
3318 rate = nla_nest_start(msg, attr);
3319 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003320 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003321
3322 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3323 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003324 /* report 16-bit bitrate only if we can */
3325 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003326 if (bitrate > 0 &&
3327 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3328 return false;
3329 if (bitrate_compat > 0 &&
3330 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3331 return false;
3332
3333 if (info->flags & RATE_INFO_FLAGS_MCS) {
3334 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3335 return false;
3336 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3337 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3338 return false;
3339 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3340 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3341 return false;
3342 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3343 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3344 return false;
3345 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3346 return false;
3347 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3348 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3349 return false;
3350 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3351 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3352 return false;
3353 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3354 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3355 return false;
3356 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3357 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3358 return false;
3359 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3360 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3361 return false;
3362 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003363
3364 nla_nest_end(msg, rate);
3365 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003366}
3367
Eric W. Biederman15e47302012-09-07 20:12:54 +00003368static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003369 int flags,
3370 struct cfg80211_registered_device *rdev,
3371 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003372 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003373{
3374 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003375 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003376
Eric W. Biederman15e47302012-09-07 20:12:54 +00003377 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003378 if (!hdr)
3379 return -1;
3380
David S. Miller9360ffd2012-03-29 04:41:26 -04003381 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3382 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3383 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3384 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003385
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003386 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3387 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003388 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003389 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3390 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3391 sinfo->connected_time))
3392 goto nla_put_failure;
3393 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3394 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3395 sinfo->inactive_time))
3396 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003397 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3398 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003399 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003400 (u32)sinfo->rx_bytes))
3401 goto nla_put_failure;
3402 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3403 NL80211_STA_INFO_TX_BYTES64)) &&
3404 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3405 (u32)sinfo->tx_bytes))
3406 goto nla_put_failure;
3407 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3408 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003409 sinfo->rx_bytes))
3410 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003411 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3412 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003413 sinfo->tx_bytes))
3414 goto nla_put_failure;
3415 if ((sinfo->filled & STATION_INFO_LLID) &&
3416 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3417 goto nla_put_failure;
3418 if ((sinfo->filled & STATION_INFO_PLID) &&
3419 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3420 goto nla_put_failure;
3421 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3422 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3423 sinfo->plink_state))
3424 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003425 switch (rdev->wiphy.signal_type) {
3426 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003427 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3428 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3429 sinfo->signal))
3430 goto nla_put_failure;
3431 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3432 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3433 sinfo->signal_avg))
3434 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003435 break;
3436 default:
3437 break;
3438 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003439 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003440 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3441 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003442 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003443 }
3444 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3445 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3446 NL80211_STA_INFO_RX_BITRATE))
3447 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003448 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003449 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3450 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3451 sinfo->rx_packets))
3452 goto nla_put_failure;
3453 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3454 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3455 sinfo->tx_packets))
3456 goto nla_put_failure;
3457 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3458 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3459 sinfo->tx_retries))
3460 goto nla_put_failure;
3461 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3462 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3463 sinfo->tx_failed))
3464 goto nla_put_failure;
3465 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3466 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3467 sinfo->beacon_loss_count))
3468 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003469 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3470 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3471 sinfo->local_pm))
3472 goto nla_put_failure;
3473 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3474 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3475 sinfo->peer_pm))
3476 goto nla_put_failure;
3477 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3478 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3479 sinfo->nonpeer_pm))
3480 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003481 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3482 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3483 if (!bss_param)
3484 goto nla_put_failure;
3485
David S. Miller9360ffd2012-03-29 04:41:26 -04003486 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3487 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3488 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3489 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3490 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3491 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3492 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3493 sinfo->bss_param.dtim_period) ||
3494 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3495 sinfo->bss_param.beacon_interval))
3496 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003497
3498 nla_nest_end(msg, bss_param);
3499 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003500 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3501 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3502 sizeof(struct nl80211_sta_flag_update),
3503 &sinfo->sta_flags))
3504 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003505 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3506 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3507 sinfo->t_offset))
3508 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003509 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003510
David S. Miller9360ffd2012-03-29 04:41:26 -04003511 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3512 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3513 sinfo->assoc_req_ies))
3514 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003515
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003516 return genlmsg_end(msg, hdr);
3517
3518 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003519 genlmsg_cancel(msg, hdr);
3520 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003521}
3522
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003523static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003524 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003525{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526 struct station_info sinfo;
3527 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003528 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003529 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003530 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003531 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003532
Johannes Berg67748892010-10-04 21:14:06 +02003533 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3534 if (err)
3535 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003536
3537 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003538 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 goto out_err;
3540 }
3541
Johannes Bergbba95fe2008-07-29 13:22:51 +02003542 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003543 memset(&sinfo, 0, sizeof(sinfo));
Hila Gonene35e4d22012-06-27 17:19:42 +03003544 err = rdev_dump_station(dev, netdev, sta_idx,
3545 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003546 if (err == -ENOENT)
3547 break;
3548 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003549 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003550
3551 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003552 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04003554 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003555 &sinfo) < 0)
3556 goto out;
3557
3558 sta_idx++;
3559 }
3560
3561
3562 out:
3563 cb->args[1] = sta_idx;
3564 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003565 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003566 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003567
3568 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003570
Johannes Berg5727ef12007-12-19 02:03:34 +01003571static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3572{
Johannes Berg4c476992010-10-04 21:36:35 +02003573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3574 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003575 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003576 struct sk_buff *msg;
3577 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003578 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003579
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003580 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003581
3582 if (!info->attrs[NL80211_ATTR_MAC])
3583 return -EINVAL;
3584
3585 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3586
Johannes Berg4c476992010-10-04 21:36:35 +02003587 if (!rdev->ops->get_station)
3588 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589
Hila Gonene35e4d22012-06-27 17:19:42 +03003590 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003592 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003595 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003596 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003597
Eric W. Biederman15e47302012-09-07 20:12:54 +00003598 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003599 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003600 nlmsg_free(msg);
3601 return -ENOBUFS;
3602 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003603
Johannes Berg4c476992010-10-04 21:36:35 +02003604 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003605}
3606
Johannes Berg77ee7c82013-02-15 00:48:33 +01003607int cfg80211_check_station_change(struct wiphy *wiphy,
3608 struct station_parameters *params,
3609 enum cfg80211_station_type statype)
3610{
3611 if (params->listen_interval != -1)
3612 return -EINVAL;
3613 if (params->aid)
3614 return -EINVAL;
3615
3616 /* When you run into this, adjust the code below for the new flag */
3617 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3618
3619 switch (statype) {
3620 case CFG80211_STA_MESH_PEER_NONSEC:
3621 case CFG80211_STA_MESH_PEER_SECURE:
3622 /*
3623 * No ignoring the TDLS flag here -- the userspace mesh
3624 * code doesn't have the bug of including TDLS in the
3625 * mask everywhere.
3626 */
3627 if (params->sta_flags_mask &
3628 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3629 BIT(NL80211_STA_FLAG_MFP) |
3630 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3631 return -EINVAL;
3632 break;
3633 case CFG80211_STA_TDLS_PEER_SETUP:
3634 case CFG80211_STA_TDLS_PEER_ACTIVE:
3635 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3636 return -EINVAL;
3637 /* ignore since it can't change */
3638 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3639 break;
3640 default:
3641 /* disallow mesh-specific things */
3642 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3643 return -EINVAL;
3644 if (params->local_pm)
3645 return -EINVAL;
3646 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3647 return -EINVAL;
3648 }
3649
3650 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3651 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3652 /* TDLS can't be set, ... */
3653 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3654 return -EINVAL;
3655 /*
3656 * ... but don't bother the driver with it. This works around
3657 * a hostapd/wpa_supplicant issue -- it always includes the
3658 * TLDS_PEER flag in the mask even for AP mode.
3659 */
3660 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3661 }
3662
3663 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3664 /* reject other things that can't change */
3665 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3666 return -EINVAL;
3667 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3668 return -EINVAL;
3669 if (params->supported_rates)
3670 return -EINVAL;
3671 if (params->ext_capab || params->ht_capa || params->vht_capa)
3672 return -EINVAL;
3673 }
3674
3675 if (statype != CFG80211_STA_AP_CLIENT) {
3676 if (params->vlan)
3677 return -EINVAL;
3678 }
3679
3680 switch (statype) {
3681 case CFG80211_STA_AP_MLME_CLIENT:
3682 /* Use this only for authorizing/unauthorizing a station */
3683 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3684 return -EOPNOTSUPP;
3685 break;
3686 case CFG80211_STA_AP_CLIENT:
3687 /* accept only the listed bits */
3688 if (params->sta_flags_mask &
3689 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3690 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3691 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3692 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3693 BIT(NL80211_STA_FLAG_WME) |
3694 BIT(NL80211_STA_FLAG_MFP)))
3695 return -EINVAL;
3696
3697 /* but authenticated/associated only if driver handles it */
3698 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3699 params->sta_flags_mask &
3700 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3701 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3702 return -EINVAL;
3703 break;
3704 case CFG80211_STA_IBSS:
3705 case CFG80211_STA_AP_STA:
3706 /* reject any changes other than AUTHORIZED */
3707 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3708 return -EINVAL;
3709 break;
3710 case CFG80211_STA_TDLS_PEER_SETUP:
3711 /* reject any changes other than AUTHORIZED or WME */
3712 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3713 BIT(NL80211_STA_FLAG_WME)))
3714 return -EINVAL;
3715 /* force (at least) rates when authorizing */
3716 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3717 !params->supported_rates)
3718 return -EINVAL;
3719 break;
3720 case CFG80211_STA_TDLS_PEER_ACTIVE:
3721 /* reject any changes */
3722 return -EINVAL;
3723 case CFG80211_STA_MESH_PEER_NONSEC:
3724 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3725 return -EINVAL;
3726 break;
3727 case CFG80211_STA_MESH_PEER_SECURE:
3728 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3729 return -EINVAL;
3730 break;
3731 }
3732
3733 return 0;
3734}
3735EXPORT_SYMBOL(cfg80211_check_station_change);
3736
Johannes Berg5727ef12007-12-19 02:03:34 +01003737/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003738 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003739 */
Johannes Berg80b99892011-11-18 16:23:01 +01003740static struct net_device *get_vlan(struct genl_info *info,
3741 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003742{
Johannes Berg463d0182009-07-14 00:33:35 +02003743 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003744 struct net_device *v;
3745 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003746
Johannes Berg80b99892011-11-18 16:23:01 +01003747 if (!vlanattr)
3748 return NULL;
3749
3750 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3751 if (!v)
3752 return ERR_PTR(-ENODEV);
3753
3754 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3755 ret = -EINVAL;
3756 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003757 }
Johannes Berg80b99892011-11-18 16:23:01 +01003758
Johannes Berg77ee7c82013-02-15 00:48:33 +01003759 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3760 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3761 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3762 ret = -EINVAL;
3763 goto error;
3764 }
3765
Johannes Berg80b99892011-11-18 16:23:01 +01003766 if (!netif_running(v)) {
3767 ret = -ENETDOWN;
3768 goto error;
3769 }
3770
3771 return v;
3772 error:
3773 dev_put(v);
3774 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003775}
3776
Jouni Malinendf881292013-02-14 21:10:54 +02003777static struct nla_policy
3778nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3779 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3780 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3781};
3782
Johannes Bergff276692013-02-15 00:09:01 +01003783static int nl80211_parse_sta_wme(struct genl_info *info,
3784 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003785{
Jouni Malinendf881292013-02-14 21:10:54 +02003786 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3787 struct nlattr *nla;
3788 int err;
3789
Jouni Malinendf881292013-02-14 21:10:54 +02003790 /* parse WME attributes if present */
3791 if (!info->attrs[NL80211_ATTR_STA_WME])
3792 return 0;
3793
3794 nla = info->attrs[NL80211_ATTR_STA_WME];
3795 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3796 nl80211_sta_wme_policy);
3797 if (err)
3798 return err;
3799
3800 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3801 params->uapsd_queues = nla_get_u8(
3802 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3803 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3804 return -EINVAL;
3805
3806 if (tb[NL80211_STA_WME_MAX_SP])
3807 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3808
3809 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3810 return -EINVAL;
3811
3812 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3813
3814 return 0;
3815}
3816
Johannes Bergff276692013-02-15 00:09:01 +01003817static int nl80211_set_station_tdls(struct genl_info *info,
3818 struct station_parameters *params)
3819{
3820 /* Dummy STA entry gets updated once the peer capabilities are known */
3821 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3822 params->ht_capa =
3823 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3824 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3825 params->vht_capa =
3826 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3827
3828 return nl80211_parse_sta_wme(info, params);
3829}
3830
Johannes Berg5727ef12007-12-19 02:03:34 +01003831static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3832{
Johannes Berg4c476992010-10-04 21:36:35 +02003833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003834 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003835 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003836 u8 *mac_addr;
3837 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003838
3839 memset(&params, 0, sizeof(params));
3840
3841 params.listen_interval = -1;
3842
Johannes Berg77ee7c82013-02-15 00:48:33 +01003843 if (!rdev->ops->change_station)
3844 return -EOPNOTSUPP;
3845
Johannes Berg5727ef12007-12-19 02:03:34 +01003846 if (info->attrs[NL80211_ATTR_STA_AID])
3847 return -EINVAL;
3848
3849 if (!info->attrs[NL80211_ATTR_MAC])
3850 return -EINVAL;
3851
3852 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3853
3854 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3855 params.supported_rates =
3856 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3857 params.supported_rates_len =
3858 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3859 }
3860
Jouni Malinen9d62a982013-02-14 21:10:13 +02003861 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3862 params.capability =
3863 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3864 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3865 }
3866
3867 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3868 params.ext_capab =
3869 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3870 params.ext_capab_len =
3871 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3872 }
3873
Jouni Malinendf881292013-02-14 21:10:54 +02003874 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003875 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003876
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003877 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003878 return -EINVAL;
3879
Johannes Bergf8bacc22013-02-14 23:27:01 +01003880 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003881 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003882 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3883 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3884 return -EINVAL;
3885 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003886
Johannes Bergf8bacc22013-02-14 23:27:01 +01003887 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003888 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003889 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3890 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3891 return -EINVAL;
3892 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3893 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003894
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003895 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3896 enum nl80211_mesh_power_mode pm = nla_get_u32(
3897 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3898
3899 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3900 pm > NL80211_MESH_POWER_MAX)
3901 return -EINVAL;
3902
3903 params.local_pm = pm;
3904 }
3905
Johannes Berg77ee7c82013-02-15 00:48:33 +01003906 /* Include parameters for TDLS peer (will check later) */
3907 err = nl80211_set_station_tdls(info, &params);
3908 if (err)
3909 return err;
3910
3911 params.vlan = get_vlan(info, rdev);
3912 if (IS_ERR(params.vlan))
3913 return PTR_ERR(params.vlan);
3914
Johannes Berga97f4422009-06-18 17:23:43 +02003915 switch (dev->ieee80211_ptr->iftype) {
3916 case NL80211_IFTYPE_AP:
3917 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003918 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003919 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003920 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003921 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003922 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003923 break;
3924 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003925 err = -EOPNOTSUPP;
3926 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003927 }
3928
Johannes Berg77ee7c82013-02-15 00:48:33 +01003929 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003930 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003931
Johannes Berg77ee7c82013-02-15 00:48:33 +01003932 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003933 if (params.vlan)
3934 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003935
Johannes Berg5727ef12007-12-19 02:03:34 +01003936 return err;
3937}
3938
3939static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3940{
Johannes Berg4c476992010-10-04 21:36:35 +02003941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003942 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003943 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003944 struct station_parameters params;
3945 u8 *mac_addr = NULL;
3946
3947 memset(&params, 0, sizeof(params));
3948
Johannes Berg984c3112013-02-14 23:43:25 +01003949 if (!rdev->ops->add_station)
3950 return -EOPNOTSUPP;
3951
Johannes Berg5727ef12007-12-19 02:03:34 +01003952 if (!info->attrs[NL80211_ATTR_MAC])
3953 return -EINVAL;
3954
Johannes Berg5727ef12007-12-19 02:03:34 +01003955 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3956 return -EINVAL;
3957
3958 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3959 return -EINVAL;
3960
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003961 if (!info->attrs[NL80211_ATTR_STA_AID])
3962 return -EINVAL;
3963
Johannes Berg5727ef12007-12-19 02:03:34 +01003964 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3965 params.supported_rates =
3966 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3967 params.supported_rates_len =
3968 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3969 params.listen_interval =
3970 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003971
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003972 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3973 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3974 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003975
Jouni Malinen9d62a982013-02-14 21:10:13 +02003976 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3977 params.capability =
3978 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3979 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3980 }
3981
3982 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3983 params.ext_capab =
3984 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3985 params.ext_capab_len =
3986 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3987 }
3988
Jouni Malinen36aedc92008-08-25 11:58:58 +03003989 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3990 params.ht_capa =
3991 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003992
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003993 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3994 params.vht_capa =
3995 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3996
Johannes Bergf8bacc22013-02-14 23:27:01 +01003997 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07003998 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003999 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4000 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4001 return -EINVAL;
4002 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004003
Johannes Bergff276692013-02-15 00:09:01 +01004004 err = nl80211_parse_sta_wme(info, &params);
4005 if (err)
4006 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004007
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004008 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004009 return -EINVAL;
4010
Johannes Berg77ee7c82013-02-15 00:48:33 +01004011 /* When you run into this, adjust the code below for the new flag */
4012 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4013
Johannes Bergbdd90d52011-12-14 12:20:27 +01004014 switch (dev->ieee80211_ptr->iftype) {
4015 case NL80211_IFTYPE_AP:
4016 case NL80211_IFTYPE_AP_VLAN:
4017 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004018 /* ignore WME attributes if iface/sta is not capable */
4019 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4020 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4021 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004022
Johannes Bergbdd90d52011-12-14 12:20:27 +01004023 /* TDLS peers cannot be added */
4024 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004025 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004026 /* but don't bother the driver with it */
4027 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004028
Johannes Bergd582cff2012-10-26 17:53:44 +02004029 /* allow authenticated/associated only if driver handles it */
4030 if (!(rdev->wiphy.features &
4031 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4032 params.sta_flags_mask &
4033 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4034 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4035 return -EINVAL;
4036
Johannes Bergbdd90d52011-12-14 12:20:27 +01004037 /* must be last in here for error handling */
4038 params.vlan = get_vlan(info, rdev);
4039 if (IS_ERR(params.vlan))
4040 return PTR_ERR(params.vlan);
4041 break;
4042 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004043 /* ignore uAPSD data */
4044 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4045
Johannes Bergd582cff2012-10-26 17:53:44 +02004046 /* associated is disallowed */
4047 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4048 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004049 /* TDLS peers cannot be added */
4050 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004051 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004052 break;
4053 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004054 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004055 /* ignore uAPSD data */
4056 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4057
Johannes Berg77ee7c82013-02-15 00:48:33 +01004058 /* these are disallowed */
4059 if (params.sta_flags_mask &
4060 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4061 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004062 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004063 /* Only TDLS peers can be added */
4064 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4065 return -EINVAL;
4066 /* Can only add if TDLS ... */
4067 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4068 return -EOPNOTSUPP;
4069 /* ... with external setup is supported */
4070 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4071 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004072 /*
4073 * Older wpa_supplicant versions always mark the TDLS peer
4074 * as authorized, but it shouldn't yet be.
4075 */
4076 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004077 break;
4078 default:
4079 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004080 }
4081
Johannes Bergbdd90d52011-12-14 12:20:27 +01004082 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004083
Hila Gonene35e4d22012-06-27 17:19:42 +03004084 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004085
Johannes Berg5727ef12007-12-19 02:03:34 +01004086 if (params.vlan)
4087 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004088 return err;
4089}
4090
4091static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4092{
Johannes Berg4c476992010-10-04 21:36:35 +02004093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4094 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004095 u8 *mac_addr = NULL;
4096
4097 if (info->attrs[NL80211_ATTR_MAC])
4098 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4099
Johannes Berge80cf852009-05-11 14:43:13 +02004100 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004101 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004103 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4104 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004105
Johannes Berg4c476992010-10-04 21:36:35 +02004106 if (!rdev->ops->del_station)
4107 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004108
Hila Gonene35e4d22012-06-27 17:19:42 +03004109 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004110}
4111
Eric W. Biederman15e47302012-09-07 20:12:54 +00004112static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004113 int flags, struct net_device *dev,
4114 u8 *dst, u8 *next_hop,
4115 struct mpath_info *pinfo)
4116{
4117 void *hdr;
4118 struct nlattr *pinfoattr;
4119
Eric W. Biederman15e47302012-09-07 20:12:54 +00004120 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004121 if (!hdr)
4122 return -1;
4123
David S. Miller9360ffd2012-03-29 04:41:26 -04004124 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4125 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4126 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4127 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4128 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004129
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004130 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4131 if (!pinfoattr)
4132 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004133 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4134 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4135 pinfo->frame_qlen))
4136 goto nla_put_failure;
4137 if (((pinfo->filled & MPATH_INFO_SN) &&
4138 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4139 ((pinfo->filled & MPATH_INFO_METRIC) &&
4140 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4141 pinfo->metric)) ||
4142 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4143 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4144 pinfo->exptime)) ||
4145 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4146 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4147 pinfo->flags)) ||
4148 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4149 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4150 pinfo->discovery_timeout)) ||
4151 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4152 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4153 pinfo->discovery_retries)))
4154 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004155
4156 nla_nest_end(msg, pinfoattr);
4157
4158 return genlmsg_end(msg, hdr);
4159
4160 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004161 genlmsg_cancel(msg, hdr);
4162 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004163}
4164
4165static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004166 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004167{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004168 struct mpath_info pinfo;
4169 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004170 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004171 u8 dst[ETH_ALEN];
4172 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02004173 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004174 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004175
Johannes Berg67748892010-10-04 21:14:06 +02004176 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4177 if (err)
4178 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004179
4180 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004181 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004182 goto out_err;
4183 }
4184
Jouni Malineneec60b02009-03-20 21:21:19 +02004185 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
4186 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004187 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004188 }
4189
Johannes Bergbba95fe2008-07-29 13:22:51 +02004190 while (1) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004191 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
4192 &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004193 if (err == -ENOENT)
4194 break;
4195 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004196 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004197
Eric W. Biederman15e47302012-09-07 20:12:54 +00004198 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004199 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4200 netdev, dst, next_hop,
4201 &pinfo) < 0)
4202 goto out;
4203
4204 path_idx++;
4205 }
4206
4207
4208 out:
4209 cb->args[1] = path_idx;
4210 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004211 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004212 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004213 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004214}
4215
4216static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4217{
Johannes Berg4c476992010-10-04 21:36:35 +02004218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004219 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004220 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004221 struct mpath_info pinfo;
4222 struct sk_buff *msg;
4223 u8 *dst = NULL;
4224 u8 next_hop[ETH_ALEN];
4225
4226 memset(&pinfo, 0, sizeof(pinfo));
4227
4228 if (!info->attrs[NL80211_ATTR_MAC])
4229 return -EINVAL;
4230
4231 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4232
Johannes Berg4c476992010-10-04 21:36:35 +02004233 if (!rdev->ops->get_mpath)
4234 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004235
Johannes Berg4c476992010-10-04 21:36:35 +02004236 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4237 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004238
Hila Gonene35e4d22012-06-27 17:19:42 +03004239 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004240 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004241 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004242
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004244 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004245 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004246
Eric W. Biederman15e47302012-09-07 20:12:54 +00004247 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004248 dev, dst, next_hop, &pinfo) < 0) {
4249 nlmsg_free(msg);
4250 return -ENOBUFS;
4251 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004252
Johannes Berg4c476992010-10-04 21:36:35 +02004253 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004254}
4255
4256static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4257{
Johannes Berg4c476992010-10-04 21:36:35 +02004258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4259 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260 u8 *dst = NULL;
4261 u8 *next_hop = NULL;
4262
4263 if (!info->attrs[NL80211_ATTR_MAC])
4264 return -EINVAL;
4265
4266 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4267 return -EINVAL;
4268
4269 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4270 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4271
Johannes Berg4c476992010-10-04 21:36:35 +02004272 if (!rdev->ops->change_mpath)
4273 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004274
Johannes Berg4c476992010-10-04 21:36:35 +02004275 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4276 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004277
Hila Gonene35e4d22012-06-27 17:19:42 +03004278 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004279}
Johannes Berg4c476992010-10-04 21:36:35 +02004280
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004281static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4282{
Johannes Berg4c476992010-10-04 21:36:35 +02004283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4284 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004285 u8 *dst = NULL;
4286 u8 *next_hop = NULL;
4287
4288 if (!info->attrs[NL80211_ATTR_MAC])
4289 return -EINVAL;
4290
4291 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4292 return -EINVAL;
4293
4294 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4295 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4296
Johannes Berg4c476992010-10-04 21:36:35 +02004297 if (!rdev->ops->add_mpath)
4298 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004299
Johannes Berg4c476992010-10-04 21:36:35 +02004300 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4301 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004302
Hila Gonene35e4d22012-06-27 17:19:42 +03004303 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004304}
4305
4306static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4307{
Johannes Berg4c476992010-10-04 21:36:35 +02004308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4309 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004310 u8 *dst = NULL;
4311
4312 if (info->attrs[NL80211_ATTR_MAC])
4313 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4314
Johannes Berg4c476992010-10-04 21:36:35 +02004315 if (!rdev->ops->del_mpath)
4316 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004317
Hila Gonene35e4d22012-06-27 17:19:42 +03004318 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004319}
4320
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004321static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4322{
Johannes Berg4c476992010-10-04 21:36:35 +02004323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4324 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004325 struct bss_parameters params;
4326
4327 memset(&params, 0, sizeof(params));
4328 /* default to not changing parameters */
4329 params.use_cts_prot = -1;
4330 params.use_short_preamble = -1;
4331 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004332 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004333 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004334 params.p2p_ctwindow = -1;
4335 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004336
4337 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4338 params.use_cts_prot =
4339 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4340 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4341 params.use_short_preamble =
4342 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4343 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4344 params.use_short_slot_time =
4345 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004346 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4347 params.basic_rates =
4348 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4349 params.basic_rates_len =
4350 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4351 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004352 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4353 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004354 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4355 params.ht_opmode =
4356 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004357
Johannes Berg53cabad2012-11-14 15:17:28 +01004358 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4359 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4360 return -EINVAL;
4361 params.p2p_ctwindow =
4362 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4363 if (params.p2p_ctwindow < 0)
4364 return -EINVAL;
4365 if (params.p2p_ctwindow != 0 &&
4366 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4367 return -EINVAL;
4368 }
4369
4370 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4371 u8 tmp;
4372
4373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4374 return -EINVAL;
4375 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4376 if (tmp > 1)
4377 return -EINVAL;
4378 params.p2p_opp_ps = tmp;
4379 if (params.p2p_opp_ps &&
4380 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4381 return -EINVAL;
4382 }
4383
Johannes Berg4c476992010-10-04 21:36:35 +02004384 if (!rdev->ops->change_bss)
4385 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004386
Johannes Berg074ac8d2010-09-16 14:58:22 +02004387 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004388 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4389 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004390
Hila Gonene35e4d22012-06-27 17:19:42 +03004391 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004392}
4393
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004394static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004395 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4396 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4397 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4398 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4399 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4400 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4401};
4402
4403static int parse_reg_rule(struct nlattr *tb[],
4404 struct ieee80211_reg_rule *reg_rule)
4405{
4406 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4407 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4408
4409 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4410 return -EINVAL;
4411 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4412 return -EINVAL;
4413 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4414 return -EINVAL;
4415 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4416 return -EINVAL;
4417 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4418 return -EINVAL;
4419
4420 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4421
4422 freq_range->start_freq_khz =
4423 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4424 freq_range->end_freq_khz =
4425 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4426 freq_range->max_bandwidth_khz =
4427 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4428
4429 power_rule->max_eirp =
4430 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4431
4432 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4433 power_rule->max_antenna_gain =
4434 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4435
4436 return 0;
4437}
4438
4439static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4440{
4441 int r;
4442 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004443 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004444
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004445 /*
4446 * You should only get this when cfg80211 hasn't yet initialized
4447 * completely when built-in to the kernel right between the time
4448 * window between nl80211_init() and regulatory_init(), if that is
4449 * even possible.
4450 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004451 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004452 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004453
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004454 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4455 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004456
4457 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4458
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004459 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4460 user_reg_hint_type =
4461 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4462 else
4463 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4464
4465 switch (user_reg_hint_type) {
4466 case NL80211_USER_REG_HINT_USER:
4467 case NL80211_USER_REG_HINT_CELL_BASE:
4468 break;
4469 default:
4470 return -EINVAL;
4471 }
4472
4473 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004474
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004475 return r;
4476}
4477
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004478static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004479 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004480{
Johannes Berg4c476992010-10-04 21:36:35 +02004481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004482 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004483 struct wireless_dev *wdev = dev->ieee80211_ptr;
4484 struct mesh_config cur_params;
4485 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004486 void *hdr;
4487 struct nlattr *pinfoattr;
4488 struct sk_buff *msg;
4489
Johannes Berg29cbe682010-12-03 09:20:44 +01004490 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4491 return -EOPNOTSUPP;
4492
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004493 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004494 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004495
Johannes Berg29cbe682010-12-03 09:20:44 +01004496 wdev_lock(wdev);
4497 /* If not connected, get default parameters */
4498 if (!wdev->mesh_id_len)
4499 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4500 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004501 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004502 wdev_unlock(wdev);
4503
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004504 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004505 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004506
4507 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004509 if (!msg)
4510 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004511 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004512 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004513 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004514 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004515 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004516 if (!pinfoattr)
4517 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004518 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4519 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4520 cur_params.dot11MeshRetryTimeout) ||
4521 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4522 cur_params.dot11MeshConfirmTimeout) ||
4523 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4524 cur_params.dot11MeshHoldingTimeout) ||
4525 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4526 cur_params.dot11MeshMaxPeerLinks) ||
4527 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4528 cur_params.dot11MeshMaxRetries) ||
4529 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4530 cur_params.dot11MeshTTL) ||
4531 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4532 cur_params.element_ttl) ||
4533 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4534 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004535 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4536 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004537 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4538 cur_params.dot11MeshHWMPmaxPREQretries) ||
4539 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4540 cur_params.path_refresh_time) ||
4541 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4542 cur_params.min_discovery_timeout) ||
4543 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4544 cur_params.dot11MeshHWMPactivePathTimeout) ||
4545 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4546 cur_params.dot11MeshHWMPpreqMinInterval) ||
4547 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4548 cur_params.dot11MeshHWMPperrMinInterval) ||
4549 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4550 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4551 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4552 cur_params.dot11MeshHWMPRootMode) ||
4553 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4554 cur_params.dot11MeshHWMPRannInterval) ||
4555 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4556 cur_params.dot11MeshGateAnnouncementProtocol) ||
4557 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4558 cur_params.dot11MeshForwarding) ||
4559 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004560 cur_params.rssi_threshold) ||
4561 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004562 cur_params.ht_opmode) ||
4563 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4564 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4565 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004566 cur_params.dot11MeshHWMProotInterval) ||
4567 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004568 cur_params.dot11MeshHWMPconfirmationInterval) ||
4569 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4570 cur_params.power_mode) ||
4571 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4572 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004573 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004574 nla_nest_end(msg, pinfoattr);
4575 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004576 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004577
Johannes Berg3b858752009-03-12 09:55:09 +01004578 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004579 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004580 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004581 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004582 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004583}
4584
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004585static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004586 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4587 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4588 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4589 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4590 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4591 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004592 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004593 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004594 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004595 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4596 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4597 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4598 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4599 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004600 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004601 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004602 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004603 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004604 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004605 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004606 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4607 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004608 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4609 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004610 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004611 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4612 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004613};
4614
Javier Cardonac80d5452010-12-16 17:37:49 -08004615static const struct nla_policy
4616 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004617 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004618 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4619 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004620 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004621 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004622 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004623 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004624};
4625
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004626static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004627 struct mesh_config *cfg,
4628 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004629{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004630 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004631 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004632
Marco Porschea54fba2013-01-07 16:04:48 +01004633#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4634do { \
4635 if (tb[attr]) { \
4636 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4637 return -EINVAL; \
4638 cfg->param = fn(tb[attr]); \
4639 mask |= (1 << (attr - 1)); \
4640 } \
4641} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004642
4643
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004644 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004645 return -EINVAL;
4646 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004647 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004648 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004649 return -EINVAL;
4650
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004651 /* This makes sure that there aren't more than 32 mesh config
4652 * parameters (otherwise our bitfield scheme would not work.) */
4653 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4654
4655 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004656 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004657 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4658 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004659 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004660 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4661 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004662 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004663 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4664 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004665 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004666 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4667 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004668 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004669 mask, NL80211_MESHCONF_MAX_RETRIES,
4670 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004671 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004672 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004673 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004674 mask, NL80211_MESHCONF_ELEMENT_TTL,
4675 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004676 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004677 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4678 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004679 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4680 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004681 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4682 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004683 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004684 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4685 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004686 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004687 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4688 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004689 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004690 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4691 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4693 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004694 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4695 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004696 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004697 1, 65535, mask,
4698 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004699 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004701 1, 65535, mask,
4702 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004703 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004704 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004705 dot11MeshHWMPnetDiameterTraversalTime,
4706 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004707 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4708 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004709 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4710 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4711 nla_get_u8);
4712 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4713 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004714 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004715 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004716 dot11MeshGateAnnouncementProtocol, 0, 1,
4717 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004718 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004719 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004720 mask, NL80211_MESHCONF_FORWARDING,
4721 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004722 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004723 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4724 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004725 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004726 mask, NL80211_MESHCONF_HT_OPMODE,
4727 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004728 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004729 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004730 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4731 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004732 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004733 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4734 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004735 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004736 dot11MeshHWMPconfirmationInterval,
4737 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004738 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4739 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004740 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4741 NL80211_MESH_POWER_ACTIVE,
4742 NL80211_MESH_POWER_MAX,
4743 mask, NL80211_MESHCONF_POWER_MODE,
4744 nla_get_u32);
4745 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4746 0, 65535, mask,
4747 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004748 if (mask_out)
4749 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004750
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004751 return 0;
4752
4753#undef FILL_IN_MESH_PARAM_IF_SET
4754}
4755
Javier Cardonac80d5452010-12-16 17:37:49 -08004756static int nl80211_parse_mesh_setup(struct genl_info *info,
4757 struct mesh_setup *setup)
4758{
4759 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4760
4761 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4762 return -EINVAL;
4763 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4764 info->attrs[NL80211_ATTR_MESH_SETUP],
4765 nl80211_mesh_setup_params_policy))
4766 return -EINVAL;
4767
Javier Cardonad299a1f2012-03-31 11:31:33 -07004768 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4769 setup->sync_method =
4770 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4771 IEEE80211_SYNC_METHOD_VENDOR :
4772 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4773
Javier Cardonac80d5452010-12-16 17:37:49 -08004774 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4775 setup->path_sel_proto =
4776 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4777 IEEE80211_PATH_PROTOCOL_VENDOR :
4778 IEEE80211_PATH_PROTOCOL_HWMP;
4779
4780 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4781 setup->path_metric =
4782 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4783 IEEE80211_PATH_METRIC_VENDOR :
4784 IEEE80211_PATH_METRIC_AIRTIME;
4785
Javier Cardona581a8b02011-04-07 15:08:27 -07004786
4787 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004788 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004789 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004790 if (!is_valid_ie_attr(ieattr))
4791 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004792 setup->ie = nla_data(ieattr);
4793 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004794 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07004795 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4796 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08004797
4798 return 0;
4799}
4800
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004801static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004802 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004803{
4804 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4805 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004806 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004807 struct mesh_config cfg;
4808 u32 mask;
4809 int err;
4810
Johannes Berg29cbe682010-12-03 09:20:44 +01004811 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4812 return -EOPNOTSUPP;
4813
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004814 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004815 return -EOPNOTSUPP;
4816
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004817 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004818 if (err)
4819 return err;
4820
Johannes Berg29cbe682010-12-03 09:20:44 +01004821 wdev_lock(wdev);
4822 if (!wdev->mesh_id_len)
4823 err = -ENOLINK;
4824
4825 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004826 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004827
4828 wdev_unlock(wdev);
4829
4830 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004831}
4832
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004833static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4834{
Johannes Berg458f4f92012-12-06 15:47:38 +01004835 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004836 struct sk_buff *msg;
4837 void *hdr = NULL;
4838 struct nlattr *nl_reg_rules;
4839 unsigned int i;
4840 int err = -EINVAL;
4841
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004842 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004843
4844 if (!cfg80211_regdomain)
4845 goto out;
4846
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004847 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004848 if (!msg) {
4849 err = -ENOBUFS;
4850 goto out;
4851 }
4852
Eric W. Biederman15e47302012-09-07 20:12:54 +00004853 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004854 NL80211_CMD_GET_REG);
4855 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004856 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004857
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004858 if (reg_last_request_cell_base() &&
4859 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4860 NL80211_USER_REG_HINT_CELL_BASE))
4861 goto nla_put_failure;
4862
Johannes Berg458f4f92012-12-06 15:47:38 +01004863 rcu_read_lock();
4864 regdom = rcu_dereference(cfg80211_regdomain);
4865
4866 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4867 (regdom->dfs_region &&
4868 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4869 goto nla_put_failure_rcu;
4870
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004871 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4872 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004873 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004874
Johannes Berg458f4f92012-12-06 15:47:38 +01004875 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004876 struct nlattr *nl_reg_rule;
4877 const struct ieee80211_reg_rule *reg_rule;
4878 const struct ieee80211_freq_range *freq_range;
4879 const struct ieee80211_power_rule *power_rule;
4880
Johannes Berg458f4f92012-12-06 15:47:38 +01004881 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004882 freq_range = &reg_rule->freq_range;
4883 power_rule = &reg_rule->power_rule;
4884
4885 nl_reg_rule = nla_nest_start(msg, i);
4886 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004887 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004888
David S. Miller9360ffd2012-03-29 04:41:26 -04004889 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4890 reg_rule->flags) ||
4891 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4892 freq_range->start_freq_khz) ||
4893 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4894 freq_range->end_freq_khz) ||
4895 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4896 freq_range->max_bandwidth_khz) ||
4897 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4898 power_rule->max_antenna_gain) ||
4899 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4900 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004901 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004902
4903 nla_nest_end(msg, nl_reg_rule);
4904 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004905 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004906
4907 nla_nest_end(msg, nl_reg_rules);
4908
4909 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004910 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004911 goto out;
4912
Johannes Berg458f4f92012-12-06 15:47:38 +01004913nla_put_failure_rcu:
4914 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004915nla_put_failure:
4916 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004917put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004918 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004919 err = -EMSGSIZE;
4920out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004921 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004922 return err;
4923}
4924
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004925static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4926{
4927 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4928 struct nlattr *nl_reg_rule;
4929 char *alpha2 = NULL;
4930 int rem_reg_rules = 0, r = 0;
4931 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004932 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004933 struct ieee80211_regdomain *rd = NULL;
4934
4935 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4936 return -EINVAL;
4937
4938 if (!info->attrs[NL80211_ATTR_REG_RULES])
4939 return -EINVAL;
4940
4941 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4942
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004943 if (info->attrs[NL80211_ATTR_DFS_REGION])
4944 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4945
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004946 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004947 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004948 num_rules++;
4949 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004950 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004951 }
4952
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004953 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004954 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004955
4956 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004957 if (!rd)
4958 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004959
4960 rd->n_reg_rules = num_rules;
4961 rd->alpha2[0] = alpha2[0];
4962 rd->alpha2[1] = alpha2[1];
4963
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004964 /*
4965 * Disable DFS master mode if the DFS region was
4966 * not supported or known on this kernel.
4967 */
4968 if (reg_supported_dfs_region(dfs_region))
4969 rd->dfs_region = dfs_region;
4970
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004971 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004972 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004973 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004974 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4975 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004976 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4977 if (r)
4978 goto bad_reg;
4979
4980 rule_idx++;
4981
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004982 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4983 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004984 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004985 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004986 }
4987
Johannes Berg6913b492012-12-04 00:48:59 +01004988 mutex_lock(&cfg80211_mutex);
4989
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004990 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01004991 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01004992 rd = NULL;
Johannes Berg6913b492012-12-04 00:48:59 +01004993 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004994
Johannes Bergd2372b32008-10-24 20:32:20 +02004995 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004996 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004997 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004998}
4999
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005000static int validate_scan_freqs(struct nlattr *freqs)
5001{
5002 struct nlattr *attr1, *attr2;
5003 int n_channels = 0, tmp1, tmp2;
5004
5005 nla_for_each_nested(attr1, freqs, tmp1) {
5006 n_channels++;
5007 /*
5008 * Some hardware has a limited channel list for
5009 * scanning, and it is pretty much nonsensical
5010 * to scan for a channel twice, so disallow that
5011 * and don't require drivers to check that the
5012 * channel list they get isn't longer than what
5013 * they can scan, as long as they can scan all
5014 * the channels they registered at once.
5015 */
5016 nla_for_each_nested(attr2, freqs, tmp2)
5017 if (attr1 != attr2 &&
5018 nla_get_u32(attr1) == nla_get_u32(attr2))
5019 return 0;
5020 }
5021
5022 return n_channels;
5023}
5024
Johannes Berg2a519312009-02-10 21:25:55 +01005025static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5026{
Johannes Berg4c476992010-10-04 21:36:35 +02005027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005028 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005029 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005030 struct nlattr *attr;
5031 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005032 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005033 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005034
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005035 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5036 return -EINVAL;
5037
Johannes Berg79c97e92009-07-07 03:56:12 +02005038 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005039
Johannes Berg4c476992010-10-04 21:36:35 +02005040 if (!rdev->ops->scan)
5041 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005042
Johannes Berg4c476992010-10-04 21:36:35 +02005043 if (rdev->scan_req)
5044 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01005045
5046 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005047 n_channels = validate_scan_freqs(
5048 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02005049 if (!n_channels)
5050 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005051 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005052 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005053 n_channels = 0;
5054
Johannes Berg2a519312009-02-10 21:25:55 +01005055 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5056 if (wiphy->bands[band])
5057 n_channels += wiphy->bands[band]->n_channels;
5058 }
5059
5060 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5061 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5062 n_ssids++;
5063
Johannes Berg4c476992010-10-04 21:36:35 +02005064 if (n_ssids > wiphy->max_scan_ssids)
5065 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005066
Jouni Malinen70692ad2009-02-16 19:39:13 +02005067 if (info->attrs[NL80211_ATTR_IE])
5068 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5069 else
5070 ie_len = 0;
5071
Johannes Berg4c476992010-10-04 21:36:35 +02005072 if (ie_len > wiphy->max_scan_ie_len)
5073 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02005074
Johannes Berg2a519312009-02-10 21:25:55 +01005075 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005076 + sizeof(*request->ssids) * n_ssids
5077 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005078 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005079 if (!request)
5080 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01005081
Johannes Berg2a519312009-02-10 21:25:55 +01005082 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005083 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005084 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005085 if (ie_len) {
5086 if (request->ssids)
5087 request->ie = (void *)(request->ssids + n_ssids);
5088 else
5089 request->ie = (void *)(request->channels + n_channels);
5090 }
Johannes Berg2a519312009-02-10 21:25:55 +01005091
Johannes Berg584991d2009-11-02 13:32:03 +01005092 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005093 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5094 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005095 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005096 struct ieee80211_channel *chan;
5097
5098 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5099
5100 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005101 err = -EINVAL;
5102 goto out_free;
5103 }
Johannes Berg584991d2009-11-02 13:32:03 +01005104
5105 /* ignore disabled channels */
5106 if (chan->flags & IEEE80211_CHAN_DISABLED)
5107 continue;
5108
5109 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005110 i++;
5111 }
5112 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005113 enum ieee80211_band band;
5114
Johannes Berg2a519312009-02-10 21:25:55 +01005115 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005116 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5117 int j;
5118 if (!wiphy->bands[band])
5119 continue;
5120 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005121 struct ieee80211_channel *chan;
5122
5123 chan = &wiphy->bands[band]->channels[j];
5124
5125 if (chan->flags & IEEE80211_CHAN_DISABLED)
5126 continue;
5127
5128 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005129 i++;
5130 }
5131 }
5132 }
5133
Johannes Berg584991d2009-11-02 13:32:03 +01005134 if (!i) {
5135 err = -EINVAL;
5136 goto out_free;
5137 }
5138
5139 request->n_channels = i;
5140
Johannes Berg2a519312009-02-10 21:25:55 +01005141 i = 0;
5142 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5143 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005144 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005145 err = -EINVAL;
5146 goto out_free;
5147 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005148 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005149 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005150 i++;
5151 }
5152 }
5153
Jouni Malinen70692ad2009-02-16 19:39:13 +02005154 if (info->attrs[NL80211_ATTR_IE]) {
5155 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005156 memcpy((void *)request->ie,
5157 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005158 request->ie_len);
5159 }
5160
Johannes Berg34850ab2011-07-18 18:08:35 +02005161 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005162 if (wiphy->bands[i])
5163 request->rates[i] =
5164 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005165
5166 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5167 nla_for_each_nested(attr,
5168 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5169 tmp) {
5170 enum ieee80211_band band = nla_type(attr);
5171
Dan Carpenter84404622011-07-29 11:52:18 +03005172 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005173 err = -EINVAL;
5174 goto out_free;
5175 }
5176 err = ieee80211_get_ratemask(wiphy->bands[band],
5177 nla_data(attr),
5178 nla_len(attr),
5179 &request->rates[band]);
5180 if (err)
5181 goto out_free;
5182 }
5183 }
5184
Sam Leffler46856bb2012-10-11 21:03:32 -07005185 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005186 request->flags = nla_get_u32(
5187 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005188 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5189 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5190 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5191 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005192 err = -EOPNOTSUPP;
5193 goto out_free;
5194 }
5195 }
Sam Lefflered4737712012-10-11 21:03:31 -07005196
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305197 request->no_cck =
5198 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5199
Johannes Bergfd014282012-06-18 19:17:03 +02005200 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005201 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005202 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005203
Johannes Berg79c97e92009-07-07 03:56:12 +02005204 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005205 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005206
Johannes Berg463d0182009-07-14 00:33:35 +02005207 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005208 nl80211_send_scan_start(rdev, wdev);
5209 if (wdev->netdev)
5210 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005211 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005212 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005213 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005214 kfree(request);
5215 }
Johannes Berg3b858752009-03-12 09:55:09 +01005216
Johannes Berg2a519312009-02-10 21:25:55 +01005217 return err;
5218}
5219
Luciano Coelho807f8a82011-05-11 17:09:35 +03005220static int nl80211_start_sched_scan(struct sk_buff *skb,
5221 struct genl_info *info)
5222{
5223 struct cfg80211_sched_scan_request *request;
5224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5225 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005226 struct nlattr *attr;
5227 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005228 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005229 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005230 enum ieee80211_band band;
5231 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005232 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005233
5234 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5235 !rdev->ops->sched_scan_start)
5236 return -EOPNOTSUPP;
5237
5238 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5239 return -EINVAL;
5240
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005241 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5242 return -EINVAL;
5243
5244 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5245 if (interval == 0)
5246 return -EINVAL;
5247
Luciano Coelho807f8a82011-05-11 17:09:35 +03005248 wiphy = &rdev->wiphy;
5249
5250 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5251 n_channels = validate_scan_freqs(
5252 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5253 if (!n_channels)
5254 return -EINVAL;
5255 } else {
5256 n_channels = 0;
5257
5258 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5259 if (wiphy->bands[band])
5260 n_channels += wiphy->bands[band]->n_channels;
5261 }
5262
5263 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5264 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5265 tmp)
5266 n_ssids++;
5267
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005268 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005269 return -EINVAL;
5270
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005271 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5272 nla_for_each_nested(attr,
5273 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5274 tmp)
5275 n_match_sets++;
5276
5277 if (n_match_sets > wiphy->max_match_sets)
5278 return -EINVAL;
5279
Luciano Coelho807f8a82011-05-11 17:09:35 +03005280 if (info->attrs[NL80211_ATTR_IE])
5281 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5282 else
5283 ie_len = 0;
5284
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005285 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005286 return -EINVAL;
5287
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005288 mutex_lock(&rdev->sched_scan_mtx);
5289
5290 if (rdev->sched_scan_req) {
5291 err = -EINPROGRESS;
5292 goto out;
5293 }
5294
Luciano Coelho807f8a82011-05-11 17:09:35 +03005295 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005296 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005297 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005298 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005299 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005300 if (!request) {
5301 err = -ENOMEM;
5302 goto out;
5303 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005304
5305 if (n_ssids)
5306 request->ssids = (void *)&request->channels[n_channels];
5307 request->n_ssids = n_ssids;
5308 if (ie_len) {
5309 if (request->ssids)
5310 request->ie = (void *)(request->ssids + n_ssids);
5311 else
5312 request->ie = (void *)(request->channels + n_channels);
5313 }
5314
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005315 if (n_match_sets) {
5316 if (request->ie)
5317 request->match_sets = (void *)(request->ie + ie_len);
5318 else if (request->ssids)
5319 request->match_sets =
5320 (void *)(request->ssids + n_ssids);
5321 else
5322 request->match_sets =
5323 (void *)(request->channels + n_channels);
5324 }
5325 request->n_match_sets = n_match_sets;
5326
Luciano Coelho807f8a82011-05-11 17:09:35 +03005327 i = 0;
5328 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5329 /* user specified, bail out if channel not found */
5330 nla_for_each_nested(attr,
5331 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5332 tmp) {
5333 struct ieee80211_channel *chan;
5334
5335 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5336
5337 if (!chan) {
5338 err = -EINVAL;
5339 goto out_free;
5340 }
5341
5342 /* ignore disabled channels */
5343 if (chan->flags & IEEE80211_CHAN_DISABLED)
5344 continue;
5345
5346 request->channels[i] = chan;
5347 i++;
5348 }
5349 } else {
5350 /* all channels */
5351 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5352 int j;
5353 if (!wiphy->bands[band])
5354 continue;
5355 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5356 struct ieee80211_channel *chan;
5357
5358 chan = &wiphy->bands[band]->channels[j];
5359
5360 if (chan->flags & IEEE80211_CHAN_DISABLED)
5361 continue;
5362
5363 request->channels[i] = chan;
5364 i++;
5365 }
5366 }
5367 }
5368
5369 if (!i) {
5370 err = -EINVAL;
5371 goto out_free;
5372 }
5373
5374 request->n_channels = i;
5375
5376 i = 0;
5377 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5378 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5379 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005380 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005381 err = -EINVAL;
5382 goto out_free;
5383 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005384 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005385 memcpy(request->ssids[i].ssid, nla_data(attr),
5386 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005387 i++;
5388 }
5389 }
5390
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005391 i = 0;
5392 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5393 nla_for_each_nested(attr,
5394 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5395 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005396 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005397
5398 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5399 nla_data(attr), nla_len(attr),
5400 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005401 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005402 if (ssid) {
5403 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5404 err = -EINVAL;
5405 goto out_free;
5406 }
5407 memcpy(request->match_sets[i].ssid.ssid,
5408 nla_data(ssid), nla_len(ssid));
5409 request->match_sets[i].ssid.ssid_len =
5410 nla_len(ssid);
5411 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005412 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5413 if (rssi)
5414 request->rssi_thold = nla_get_u32(rssi);
5415 else
5416 request->rssi_thold =
5417 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005418 i++;
5419 }
5420 }
5421
Luciano Coelho807f8a82011-05-11 17:09:35 +03005422 if (info->attrs[NL80211_ATTR_IE]) {
5423 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5424 memcpy((void *)request->ie,
5425 nla_data(info->attrs[NL80211_ATTR_IE]),
5426 request->ie_len);
5427 }
5428
Sam Leffler46856bb2012-10-11 21:03:32 -07005429 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005430 request->flags = nla_get_u32(
5431 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005432 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5433 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5434 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5435 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005436 err = -EOPNOTSUPP;
5437 goto out_free;
5438 }
5439 }
Sam Lefflered4737712012-10-11 21:03:31 -07005440
Luciano Coelho807f8a82011-05-11 17:09:35 +03005441 request->dev = dev;
5442 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005443 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005444 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005445
Hila Gonene35e4d22012-06-27 17:19:42 +03005446 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005447 if (!err) {
5448 rdev->sched_scan_req = request;
5449 nl80211_send_sched_scan(rdev, dev,
5450 NL80211_CMD_START_SCHED_SCAN);
5451 goto out;
5452 }
5453
5454out_free:
5455 kfree(request);
5456out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005457 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005458 return err;
5459}
5460
5461static int nl80211_stop_sched_scan(struct sk_buff *skb,
5462 struct genl_info *info)
5463{
5464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005465 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005466
5467 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5468 !rdev->ops->sched_scan_stop)
5469 return -EOPNOTSUPP;
5470
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005471 mutex_lock(&rdev->sched_scan_mtx);
5472 err = __cfg80211_stop_sched_scan(rdev, false);
5473 mutex_unlock(&rdev->sched_scan_mtx);
5474
5475 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005476}
5477
Simon Wunderlich04f39042013-02-08 18:16:19 +01005478static int nl80211_start_radar_detection(struct sk_buff *skb,
5479 struct genl_info *info)
5480{
5481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5482 struct net_device *dev = info->user_ptr[1];
5483 struct wireless_dev *wdev = dev->ieee80211_ptr;
5484 struct cfg80211_chan_def chandef;
5485 int err;
5486
5487 err = nl80211_parse_chandef(rdev, info, &chandef);
5488 if (err)
5489 return err;
5490
5491 if (wdev->cac_started)
5492 return -EBUSY;
5493
5494 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5495 if (err < 0)
5496 return err;
5497
5498 if (err == 0)
5499 return -EINVAL;
5500
5501 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5502 return -EINVAL;
5503
5504 if (!rdev->ops->start_radar_detection)
5505 return -EOPNOTSUPP;
5506
5507 mutex_lock(&rdev->devlist_mtx);
5508 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5509 chandef.chan, CHAN_MODE_SHARED,
5510 BIT(chandef.width));
5511 if (err)
5512 goto err_locked;
5513
5514 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5515 if (!err) {
5516 wdev->channel = chandef.chan;
5517 wdev->cac_started = true;
5518 wdev->cac_start_time = jiffies;
5519 }
5520err_locked:
5521 mutex_unlock(&rdev->devlist_mtx);
5522
5523 return err;
5524}
5525
Johannes Berg9720bb32011-06-21 09:45:33 +02005526static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5527 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005528 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005529 struct wireless_dev *wdev,
5530 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005531{
Johannes Berg48ab9052009-07-10 18:42:31 +02005532 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005533 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005534 void *hdr;
5535 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005536 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005537
5538 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005539
Eric W. Biederman15e47302012-09-07 20:12:54 +00005540 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005541 NL80211_CMD_NEW_SCAN_RESULTS);
5542 if (!hdr)
5543 return -1;
5544
Johannes Berg9720bb32011-06-21 09:45:33 +02005545 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5546
David S. Miller9360ffd2012-03-29 04:41:26 -04005547 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5548 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5549 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005550
5551 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5552 if (!bss)
5553 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005554 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005555 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005556 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005557
5558 rcu_read_lock();
5559 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005560 if (ies) {
5561 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5562 goto fail_unlock_rcu;
5563 tsf = true;
5564 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5565 ies->len, ies->data))
5566 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005567 }
5568 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005569 if (ies) {
5570 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5571 goto fail_unlock_rcu;
5572 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5573 ies->len, ies->data))
5574 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005575 }
5576 rcu_read_unlock();
5577
David S. Miller9360ffd2012-03-29 04:41:26 -04005578 if (res->beacon_interval &&
5579 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5580 goto nla_put_failure;
5581 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5582 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5583 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5584 jiffies_to_msecs(jiffies - intbss->ts)))
5585 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005586
Johannes Berg77965c92009-02-18 18:45:06 +01005587 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005588 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005589 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5590 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005591 break;
5592 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005593 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5594 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005595 break;
5596 default:
5597 break;
5598 }
5599
Johannes Berg48ab9052009-07-10 18:42:31 +02005600 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005601 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005602 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005603 if (intbss == wdev->current_bss &&
5604 nla_put_u32(msg, NL80211_BSS_STATUS,
5605 NL80211_BSS_STATUS_ASSOCIATED))
5606 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005607 break;
5608 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005609 if (intbss == wdev->current_bss &&
5610 nla_put_u32(msg, NL80211_BSS_STATUS,
5611 NL80211_BSS_STATUS_IBSS_JOINED))
5612 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005613 break;
5614 default:
5615 break;
5616 }
5617
Johannes Berg2a519312009-02-10 21:25:55 +01005618 nla_nest_end(msg, bss);
5619
5620 return genlmsg_end(msg, hdr);
5621
Johannes Berg8cef2c92013-02-05 16:54:31 +01005622 fail_unlock_rcu:
5623 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005624 nla_put_failure:
5625 genlmsg_cancel(msg, hdr);
5626 return -EMSGSIZE;
5627}
5628
5629static int nl80211_dump_scan(struct sk_buff *skb,
5630 struct netlink_callback *cb)
5631{
Johannes Berg48ab9052009-07-10 18:42:31 +02005632 struct cfg80211_registered_device *rdev;
5633 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01005634 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005635 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005636 int start = cb->args[1], idx = 0;
5637 int err;
5638
Johannes Berg67748892010-10-04 21:14:06 +02005639 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5640 if (err)
5641 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005642
Johannes Berg48ab9052009-07-10 18:42:31 +02005643 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01005644
Johannes Berg48ab9052009-07-10 18:42:31 +02005645 wdev_lock(wdev);
5646 spin_lock_bh(&rdev->bss_lock);
5647 cfg80211_bss_expire(rdev);
5648
Johannes Berg9720bb32011-06-21 09:45:33 +02005649 cb->seq = rdev->bss_generation;
5650
Johannes Berg48ab9052009-07-10 18:42:31 +02005651 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005652 if (++idx <= start)
5653 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005654 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005655 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005656 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005657 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005658 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005659 }
5660 }
5661
Johannes Berg48ab9052009-07-10 18:42:31 +02005662 spin_unlock_bh(&rdev->bss_lock);
5663 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005664
5665 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02005666 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005667
Johannes Berg67748892010-10-04 21:14:06 +02005668 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005669}
5670
Eric W. Biederman15e47302012-09-07 20:12:54 +00005671static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005672 int flags, struct net_device *dev,
5673 struct survey_info *survey)
5674{
5675 void *hdr;
5676 struct nlattr *infoattr;
5677
Eric W. Biederman15e47302012-09-07 20:12:54 +00005678 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005679 NL80211_CMD_NEW_SURVEY_RESULTS);
5680 if (!hdr)
5681 return -ENOMEM;
5682
David S. Miller9360ffd2012-03-29 04:41:26 -04005683 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5684 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005685
5686 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5687 if (!infoattr)
5688 goto nla_put_failure;
5689
David S. Miller9360ffd2012-03-29 04:41:26 -04005690 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5691 survey->channel->center_freq))
5692 goto nla_put_failure;
5693
5694 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5695 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5696 goto nla_put_failure;
5697 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5698 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5699 goto nla_put_failure;
5700 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5701 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5702 survey->channel_time))
5703 goto nla_put_failure;
5704 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5705 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5706 survey->channel_time_busy))
5707 goto nla_put_failure;
5708 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5709 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5710 survey->channel_time_ext_busy))
5711 goto nla_put_failure;
5712 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5713 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5714 survey->channel_time_rx))
5715 goto nla_put_failure;
5716 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5717 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5718 survey->channel_time_tx))
5719 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005720
5721 nla_nest_end(msg, infoattr);
5722
5723 return genlmsg_end(msg, hdr);
5724
5725 nla_put_failure:
5726 genlmsg_cancel(msg, hdr);
5727 return -EMSGSIZE;
5728}
5729
5730static int nl80211_dump_survey(struct sk_buff *skb,
5731 struct netlink_callback *cb)
5732{
5733 struct survey_info survey;
5734 struct cfg80211_registered_device *dev;
5735 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01005736 int survey_idx = cb->args[1];
5737 int res;
5738
Johannes Berg67748892010-10-04 21:14:06 +02005739 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5740 if (res)
5741 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005742
5743 if (!dev->ops->dump_survey) {
5744 res = -EOPNOTSUPP;
5745 goto out_err;
5746 }
5747
5748 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005749 struct ieee80211_channel *chan;
5750
Hila Gonene35e4d22012-06-27 17:19:42 +03005751 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005752 if (res == -ENOENT)
5753 break;
5754 if (res)
5755 goto out_err;
5756
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005757 /* Survey without a channel doesn't make sense */
5758 if (!survey.channel) {
5759 res = -EINVAL;
5760 goto out;
5761 }
5762
5763 chan = ieee80211_get_channel(&dev->wiphy,
5764 survey.channel->center_freq);
5765 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5766 survey_idx++;
5767 continue;
5768 }
5769
Holger Schurig61fa7132009-11-11 12:25:40 +01005770 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005771 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005772 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5773 netdev,
5774 &survey) < 0)
5775 goto out;
5776 survey_idx++;
5777 }
5778
5779 out:
5780 cb->args[1] = survey_idx;
5781 res = skb->len;
5782 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02005783 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005784 return res;
5785}
5786
Samuel Ortizb23aa672009-07-01 21:26:54 +02005787static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5788{
5789 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5790 NL80211_WPA_VERSION_2));
5791}
5792
Jouni Malinen636a5d32009-03-19 13:39:22 +02005793static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5794{
Johannes Berg4c476992010-10-04 21:36:35 +02005795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5796 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005797 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005798 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5799 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005800 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005801 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005802 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005803
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005804 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5805 return -EINVAL;
5806
5807 if (!info->attrs[NL80211_ATTR_MAC])
5808 return -EINVAL;
5809
Jouni Malinen17780922009-03-27 20:52:47 +02005810 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5811 return -EINVAL;
5812
Johannes Berg19957bb2009-07-02 17:20:43 +02005813 if (!info->attrs[NL80211_ATTR_SSID])
5814 return -EINVAL;
5815
5816 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5817 return -EINVAL;
5818
Johannes Bergfffd0932009-07-08 14:22:54 +02005819 err = nl80211_parse_key(info, &key);
5820 if (err)
5821 return err;
5822
5823 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005824 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5825 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005826 if (!key.p.key || !key.p.key_len)
5827 return -EINVAL;
5828 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5829 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5830 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5831 key.p.key_len != WLAN_KEY_LEN_WEP104))
5832 return -EINVAL;
5833 if (key.idx > 4)
5834 return -EINVAL;
5835 } else {
5836 key.p.key_len = 0;
5837 key.p.key = NULL;
5838 }
5839
Johannes Bergafea0b72010-08-10 09:46:42 +02005840 if (key.idx >= 0) {
5841 int i;
5842 bool ok = false;
5843 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5844 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5845 ok = true;
5846 break;
5847 }
5848 }
Johannes Berg4c476992010-10-04 21:36:35 +02005849 if (!ok)
5850 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005851 }
5852
Johannes Berg4c476992010-10-04 21:36:35 +02005853 if (!rdev->ops->auth)
5854 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005855
Johannes Berg074ac8d2010-09-16 14:58:22 +02005856 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005857 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5858 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005859
Johannes Berg19957bb2009-07-02 17:20:43 +02005860 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005861 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005862 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005863 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5864 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005865
Johannes Berg19957bb2009-07-02 17:20:43 +02005866 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5867 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5868
5869 if (info->attrs[NL80211_ATTR_IE]) {
5870 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5871 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5872 }
5873
5874 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005875 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005876 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005877
Jouni Malinene39e5b52012-09-30 19:29:39 +03005878 if (auth_type == NL80211_AUTHTYPE_SAE &&
5879 !info->attrs[NL80211_ATTR_SAE_DATA])
5880 return -EINVAL;
5881
5882 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5883 if (auth_type != NL80211_AUTHTYPE_SAE)
5884 return -EINVAL;
5885 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5886 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5887 /* need to include at least Auth Transaction and Status Code */
5888 if (sae_data_len < 4)
5889 return -EINVAL;
5890 }
5891
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005892 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5893
Johannes Berg95de8172012-01-20 13:55:25 +01005894 /*
5895 * Since we no longer track auth state, ignore
5896 * requests to only change local state.
5897 */
5898 if (local_state_change)
5899 return 0;
5900
Johannes Berg4c476992010-10-04 21:36:35 +02005901 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5902 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005903 key.p.key, key.p.key_len, key.idx,
5904 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005905}
5906
Johannes Bergc0692b82010-08-27 14:26:53 +03005907static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5908 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005909 struct cfg80211_crypto_settings *settings,
5910 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005911{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005912 memset(settings, 0, sizeof(*settings));
5913
Samuel Ortizb23aa672009-07-01 21:26:54 +02005914 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5915
Johannes Bergc0692b82010-08-27 14:26:53 +03005916 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5917 u16 proto;
5918 proto = nla_get_u16(
5919 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5920 settings->control_port_ethertype = cpu_to_be16(proto);
5921 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5922 proto != ETH_P_PAE)
5923 return -EINVAL;
5924 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5925 settings->control_port_no_encrypt = true;
5926 } else
5927 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5928
Samuel Ortizb23aa672009-07-01 21:26:54 +02005929 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5930 void *data;
5931 int len, i;
5932
5933 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5934 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5935 settings->n_ciphers_pairwise = len / sizeof(u32);
5936
5937 if (len % sizeof(u32))
5938 return -EINVAL;
5939
Johannes Berg3dc27d22009-07-02 21:36:37 +02005940 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005941 return -EINVAL;
5942
5943 memcpy(settings->ciphers_pairwise, data, len);
5944
5945 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005946 if (!cfg80211_supported_cipher_suite(
5947 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005948 settings->ciphers_pairwise[i]))
5949 return -EINVAL;
5950 }
5951
5952 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5953 settings->cipher_group =
5954 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005955 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5956 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005957 return -EINVAL;
5958 }
5959
5960 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5961 settings->wpa_versions =
5962 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5963 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5964 return -EINVAL;
5965 }
5966
5967 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5968 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005969 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005970
5971 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5972 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5973 settings->n_akm_suites = len / sizeof(u32);
5974
5975 if (len % sizeof(u32))
5976 return -EINVAL;
5977
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005978 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5979 return -EINVAL;
5980
Samuel Ortizb23aa672009-07-01 21:26:54 +02005981 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005982 }
5983
5984 return 0;
5985}
5986
Jouni Malinen636a5d32009-03-19 13:39:22 +02005987static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5988{
Johannes Berg4c476992010-10-04 21:36:35 +02005989 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5990 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02005991 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01005992 struct cfg80211_assoc_request req = {};
5993 const u8 *bssid, *ssid;
5994 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005995
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005996 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5997 return -EINVAL;
5998
5999 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006000 !info->attrs[NL80211_ATTR_SSID] ||
6001 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006002 return -EINVAL;
6003
Johannes Berg4c476992010-10-04 21:36:35 +02006004 if (!rdev->ops->assoc)
6005 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006006
Johannes Berg074ac8d2010-09-16 14:58:22 +02006007 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006008 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6009 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006010
Johannes Berg19957bb2009-07-02 17:20:43 +02006011 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006012
Johannes Berg19957bb2009-07-02 17:20:43 +02006013 chan = ieee80211_get_channel(&rdev->wiphy,
6014 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006015 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6016 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006017
Johannes Berg19957bb2009-07-02 17:20:43 +02006018 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6019 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006020
6021 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006022 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6023 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006024 }
6025
Jouni Malinendc6382c2009-05-06 22:09:37 +03006026 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006027 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006028 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006029 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006030 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006031 else if (mfp != NL80211_MFP_NO)
6032 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006033 }
6034
Johannes Berg3e5d7642009-07-07 14:37:26 +02006035 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006036 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006037
Ben Greear7e7c8922011-11-18 11:31:59 -08006038 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006039 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006040
6041 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006042 memcpy(&req.ht_capa_mask,
6043 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6044 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006045
6046 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006047 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006048 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006049 memcpy(&req.ht_capa,
6050 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6051 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006052 }
6053
Johannes Bergee2aca32013-02-21 17:36:01 +01006054 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006055 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006056
6057 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006058 memcpy(&req.vht_capa_mask,
6059 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6060 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006061
6062 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006063 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006064 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006065 memcpy(&req.vht_capa,
6066 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6067 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006068 }
6069
Johannes Bergf62fab72013-02-21 20:09:09 +01006070 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006071 if (!err)
Johannes Bergf62fab72013-02-21 20:09:09 +01006072 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6073 ssid, ssid_len, &req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006074
Jouni Malinen636a5d32009-03-19 13:39:22 +02006075 return err;
6076}
6077
6078static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6079{
Johannes Berg4c476992010-10-04 21:36:35 +02006080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6081 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006082 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006083 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006084 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006085 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006086
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006087 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6088 return -EINVAL;
6089
6090 if (!info->attrs[NL80211_ATTR_MAC])
6091 return -EINVAL;
6092
6093 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6094 return -EINVAL;
6095
Johannes Berg4c476992010-10-04 21:36:35 +02006096 if (!rdev->ops->deauth)
6097 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006098
Johannes Berg074ac8d2010-09-16 14:58:22 +02006099 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006100 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6101 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006102
Johannes Berg19957bb2009-07-02 17:20:43 +02006103 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006104
Johannes Berg19957bb2009-07-02 17:20:43 +02006105 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6106 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006107 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006108 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006109 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006110
6111 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006112 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6113 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006114 }
6115
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006116 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6117
Johannes Berg4c476992010-10-04 21:36:35 +02006118 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6119 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006120}
6121
6122static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6123{
Johannes Berg4c476992010-10-04 21:36:35 +02006124 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6125 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006126 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006127 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006128 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006129 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006130
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006131 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6132 return -EINVAL;
6133
6134 if (!info->attrs[NL80211_ATTR_MAC])
6135 return -EINVAL;
6136
6137 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6138 return -EINVAL;
6139
Johannes Berg4c476992010-10-04 21:36:35 +02006140 if (!rdev->ops->disassoc)
6141 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006142
Johannes Berg074ac8d2010-09-16 14:58:22 +02006143 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006144 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6145 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006146
Johannes Berg19957bb2009-07-02 17:20:43 +02006147 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006148
Johannes Berg19957bb2009-07-02 17:20:43 +02006149 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6150 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006151 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006152 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006153 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006154
6155 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006156 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6157 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006158 }
6159
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006160 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6161
Johannes Berg4c476992010-10-04 21:36:35 +02006162 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6163 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006164}
6165
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006166static bool
6167nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6168 int mcast_rate[IEEE80211_NUM_BANDS],
6169 int rateval)
6170{
6171 struct wiphy *wiphy = &rdev->wiphy;
6172 bool found = false;
6173 int band, i;
6174
6175 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6176 struct ieee80211_supported_band *sband;
6177
6178 sband = wiphy->bands[band];
6179 if (!sband)
6180 continue;
6181
6182 for (i = 0; i < sband->n_bitrates; i++) {
6183 if (sband->bitrates[i].bitrate == rateval) {
6184 mcast_rate[band] = i + 1;
6185 found = true;
6186 break;
6187 }
6188 }
6189 }
6190
6191 return found;
6192}
6193
Johannes Berg04a773a2009-04-19 21:24:32 +02006194static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6195{
Johannes Berg4c476992010-10-04 21:36:35 +02006196 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6197 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006198 struct cfg80211_ibss_params ibss;
6199 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006200 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006201 int err;
6202
Johannes Berg8e30bc52009-04-22 17:45:38 +02006203 memset(&ibss, 0, sizeof(ibss));
6204
Johannes Berg04a773a2009-04-19 21:24:32 +02006205 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6206 return -EINVAL;
6207
Johannes Berg683b6d32012-11-08 21:25:48 +01006208 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006209 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6210 return -EINVAL;
6211
Johannes Berg8e30bc52009-04-22 17:45:38 +02006212 ibss.beacon_interval = 100;
6213
6214 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6215 ibss.beacon_interval =
6216 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6217 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6218 return -EINVAL;
6219 }
6220
Johannes Berg4c476992010-10-04 21:36:35 +02006221 if (!rdev->ops->join_ibss)
6222 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006223
Johannes Berg4c476992010-10-04 21:36:35 +02006224 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6225 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006226
Johannes Berg79c97e92009-07-07 03:56:12 +02006227 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006228
Johannes Berg39193492011-09-16 13:45:25 +02006229 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006230 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006231
6232 if (!is_valid_ether_addr(ibss.bssid))
6233 return -EINVAL;
6234 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006235 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6236 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6237
6238 if (info->attrs[NL80211_ATTR_IE]) {
6239 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6240 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6241 }
6242
Johannes Berg683b6d32012-11-08 21:25:48 +01006243 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6244 if (err)
6245 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006246
Johannes Berg683b6d32012-11-08 21:25:48 +01006247 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006248 return -EINVAL;
6249
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006250 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6251 return -EINVAL;
6252 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6253 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006254 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006255
Johannes Berg04a773a2009-04-19 21:24:32 +02006256 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006257 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006258
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006259 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6260 u8 *rates =
6261 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6262 int n_rates =
6263 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6264 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006265 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006266
Johannes Berg34850ab2011-07-18 18:08:35 +02006267 err = ieee80211_get_ratemask(sband, rates, n_rates,
6268 &ibss.basic_rates);
6269 if (err)
6270 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006271 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006272
6273 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6274 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6275 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6276 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006277
Johannes Berg4c476992010-10-04 21:36:35 +02006278 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306279 bool no_ht = false;
6280
Johannes Berg4c476992010-10-04 21:36:35 +02006281 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306282 info->attrs[NL80211_ATTR_KEYS],
6283 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006284 if (IS_ERR(connkeys))
6285 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306286
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006287 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6288 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306289 kfree(connkeys);
6290 return -EINVAL;
6291 }
Johannes Berg4c476992010-10-04 21:36:35 +02006292 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006293
Antonio Quartulli267335d2012-01-31 20:25:47 +01006294 ibss.control_port =
6295 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6296
Johannes Berg4c476992010-10-04 21:36:35 +02006297 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006298 if (err)
6299 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006300 return err;
6301}
6302
6303static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6304{
Johannes Berg4c476992010-10-04 21:36:35 +02006305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6306 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006307
Johannes Berg4c476992010-10-04 21:36:35 +02006308 if (!rdev->ops->leave_ibss)
6309 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006310
Johannes Berg4c476992010-10-04 21:36:35 +02006311 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6312 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006313
Johannes Berg4c476992010-10-04 21:36:35 +02006314 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006315}
6316
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006317static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6318{
6319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6320 struct net_device *dev = info->user_ptr[1];
6321 int mcast_rate[IEEE80211_NUM_BANDS];
6322 u32 nla_rate;
6323 int err;
6324
6325 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6326 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6327 return -EOPNOTSUPP;
6328
6329 if (!rdev->ops->set_mcast_rate)
6330 return -EOPNOTSUPP;
6331
6332 memset(mcast_rate, 0, sizeof(mcast_rate));
6333
6334 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6335 return -EINVAL;
6336
6337 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6338 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6339 return -EINVAL;
6340
6341 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6342
6343 return err;
6344}
6345
6346
Johannes Bergaff89a92009-07-01 21:26:51 +02006347#ifdef CONFIG_NL80211_TESTMODE
6348static struct genl_multicast_group nl80211_testmode_mcgrp = {
6349 .name = "testmode",
6350};
6351
6352static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6353{
Johannes Berg4c476992010-10-04 21:36:35 +02006354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006355 int err;
6356
6357 if (!info->attrs[NL80211_ATTR_TESTDATA])
6358 return -EINVAL;
6359
Johannes Bergaff89a92009-07-01 21:26:51 +02006360 err = -EOPNOTSUPP;
6361 if (rdev->ops->testmode_cmd) {
6362 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006363 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006364 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6365 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6366 rdev->testmode_info = NULL;
6367 }
6368
Johannes Bergaff89a92009-07-01 21:26:51 +02006369 return err;
6370}
6371
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006372static int nl80211_testmode_dump(struct sk_buff *skb,
6373 struct netlink_callback *cb)
6374{
Johannes Berg00918d32011-12-13 17:22:05 +01006375 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006376 int err;
6377 long phy_idx;
6378 void *data = NULL;
6379 int data_len = 0;
6380
6381 if (cb->args[0]) {
6382 /*
6383 * 0 is a valid index, but not valid for args[0],
6384 * so we need to offset by 1.
6385 */
6386 phy_idx = cb->args[0] - 1;
6387 } else {
6388 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6389 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6390 nl80211_policy);
6391 if (err)
6392 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01006393
Johannes Berg2bd7e352012-06-15 14:23:16 +02006394 mutex_lock(&cfg80211_mutex);
6395 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6396 nl80211_fam.attrbuf);
6397 if (IS_ERR(rdev)) {
6398 mutex_unlock(&cfg80211_mutex);
6399 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01006400 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006401 phy_idx = rdev->wiphy_idx;
6402 rdev = NULL;
6403 mutex_unlock(&cfg80211_mutex);
6404
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006405 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6406 cb->args[1] =
6407 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6408 }
6409
6410 if (cb->args[1]) {
6411 data = nla_data((void *)cb->args[1]);
6412 data_len = nla_len((void *)cb->args[1]);
6413 }
6414
6415 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01006416 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6417 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006418 mutex_unlock(&cfg80211_mutex);
6419 return -ENOENT;
6420 }
Johannes Berg00918d32011-12-13 17:22:05 +01006421 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006422 mutex_unlock(&cfg80211_mutex);
6423
Johannes Berg00918d32011-12-13 17:22:05 +01006424 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006425 err = -EOPNOTSUPP;
6426 goto out_err;
6427 }
6428
6429 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006430 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006431 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6432 NL80211_CMD_TESTMODE);
6433 struct nlattr *tmdata;
6434
David S. Miller9360ffd2012-03-29 04:41:26 -04006435 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006436 genlmsg_cancel(skb, hdr);
6437 break;
6438 }
6439
6440 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6441 if (!tmdata) {
6442 genlmsg_cancel(skb, hdr);
6443 break;
6444 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006445 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006446 nla_nest_end(skb, tmdata);
6447
6448 if (err == -ENOBUFS || err == -ENOENT) {
6449 genlmsg_cancel(skb, hdr);
6450 break;
6451 } else if (err) {
6452 genlmsg_cancel(skb, hdr);
6453 goto out_err;
6454 }
6455
6456 genlmsg_end(skb, hdr);
6457 }
6458
6459 err = skb->len;
6460 /* see above */
6461 cb->args[0] = phy_idx + 1;
6462 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01006463 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006464 return err;
6465}
6466
Johannes Bergaff89a92009-07-01 21:26:51 +02006467static struct sk_buff *
6468__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006469 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006470{
6471 struct sk_buff *skb;
6472 void *hdr;
6473 struct nlattr *data;
6474
6475 skb = nlmsg_new(approxlen + 100, gfp);
6476 if (!skb)
6477 return NULL;
6478
Eric W. Biederman15e47302012-09-07 20:12:54 +00006479 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006480 if (!hdr) {
6481 kfree_skb(skb);
6482 return NULL;
6483 }
6484
David S. Miller9360ffd2012-03-29 04:41:26 -04006485 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6486 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006487 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6488
6489 ((void **)skb->cb)[0] = rdev;
6490 ((void **)skb->cb)[1] = hdr;
6491 ((void **)skb->cb)[2] = data;
6492
6493 return skb;
6494
6495 nla_put_failure:
6496 kfree_skb(skb);
6497 return NULL;
6498}
6499
6500struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6501 int approxlen)
6502{
6503 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6504
6505 if (WARN_ON(!rdev->testmode_info))
6506 return NULL;
6507
6508 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006509 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006510 rdev->testmode_info->snd_seq,
6511 GFP_KERNEL);
6512}
6513EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6514
6515int cfg80211_testmode_reply(struct sk_buff *skb)
6516{
6517 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6518 void *hdr = ((void **)skb->cb)[1];
6519 struct nlattr *data = ((void **)skb->cb)[2];
6520
6521 if (WARN_ON(!rdev->testmode_info)) {
6522 kfree_skb(skb);
6523 return -EINVAL;
6524 }
6525
6526 nla_nest_end(skb, data);
6527 genlmsg_end(skb, hdr);
6528 return genlmsg_reply(skb, rdev->testmode_info);
6529}
6530EXPORT_SYMBOL(cfg80211_testmode_reply);
6531
6532struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6533 int approxlen, gfp_t gfp)
6534{
6535 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6536
6537 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6538}
6539EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6540
6541void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6542{
6543 void *hdr = ((void **)skb->cb)[1];
6544 struct nlattr *data = ((void **)skb->cb)[2];
6545
6546 nla_nest_end(skb, data);
6547 genlmsg_end(skb, hdr);
6548 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6549}
6550EXPORT_SYMBOL(cfg80211_testmode_event);
6551#endif
6552
Samuel Ortizb23aa672009-07-01 21:26:54 +02006553static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6554{
Johannes Berg4c476992010-10-04 21:36:35 +02006555 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6556 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006557 struct cfg80211_connect_params connect;
6558 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006559 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006560 int err;
6561
6562 memset(&connect, 0, sizeof(connect));
6563
6564 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6565 return -EINVAL;
6566
6567 if (!info->attrs[NL80211_ATTR_SSID] ||
6568 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6569 return -EINVAL;
6570
6571 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6572 connect.auth_type =
6573 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006574 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6575 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006576 return -EINVAL;
6577 } else
6578 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6579
6580 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6581
Johannes Bergc0692b82010-08-27 14:26:53 +03006582 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006583 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006584 if (err)
6585 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006586
Johannes Berg074ac8d2010-09-16 14:58:22 +02006587 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006588 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6589 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006590
Johannes Berg79c97e92009-07-07 03:56:12 +02006591 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006592
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306593 connect.bg_scan_period = -1;
6594 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6595 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6596 connect.bg_scan_period =
6597 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6598 }
6599
Samuel Ortizb23aa672009-07-01 21:26:54 +02006600 if (info->attrs[NL80211_ATTR_MAC])
6601 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6602 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6603 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6604
6605 if (info->attrs[NL80211_ATTR_IE]) {
6606 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6607 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6608 }
6609
Jouni Malinencee00a92013-01-15 17:15:57 +02006610 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6611 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6612 if (connect.mfp != NL80211_MFP_REQUIRED &&
6613 connect.mfp != NL80211_MFP_NO)
6614 return -EINVAL;
6615 } else {
6616 connect.mfp = NL80211_MFP_NO;
6617 }
6618
Samuel Ortizb23aa672009-07-01 21:26:54 +02006619 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6620 connect.channel =
6621 ieee80211_get_channel(wiphy,
6622 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6623 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006624 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6625 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006626 }
6627
Johannes Bergfffd0932009-07-08 14:22:54 +02006628 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6629 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306630 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006631 if (IS_ERR(connkeys))
6632 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006633 }
6634
Ben Greear7e7c8922011-11-18 11:31:59 -08006635 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6636 connect.flags |= ASSOC_REQ_DISABLE_HT;
6637
6638 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6639 memcpy(&connect.ht_capa_mask,
6640 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6641 sizeof(connect.ht_capa_mask));
6642
6643 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006644 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6645 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006646 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006647 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006648 memcpy(&connect.ht_capa,
6649 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6650 sizeof(connect.ht_capa));
6651 }
6652
Johannes Bergee2aca32013-02-21 17:36:01 +01006653 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6654 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6655
6656 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6657 memcpy(&connect.vht_capa_mask,
6658 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6659 sizeof(connect.vht_capa_mask));
6660
6661 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6662 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6663 kfree(connkeys);
6664 return -EINVAL;
6665 }
6666 memcpy(&connect.vht_capa,
6667 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6668 sizeof(connect.vht_capa));
6669 }
6670
Johannes Bergfffd0932009-07-08 14:22:54 +02006671 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006672 if (err)
6673 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006674 return err;
6675}
6676
6677static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6678{
Johannes Berg4c476992010-10-04 21:36:35 +02006679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6680 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006681 u16 reason;
6682
6683 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6684 reason = WLAN_REASON_DEAUTH_LEAVING;
6685 else
6686 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6687
6688 if (reason == 0)
6689 return -EINVAL;
6690
Johannes Berg074ac8d2010-09-16 14:58:22 +02006691 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006692 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6693 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006694
Johannes Berg4c476992010-10-04 21:36:35 +02006695 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006696}
6697
Johannes Berg463d0182009-07-14 00:33:35 +02006698static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6699{
Johannes Berg4c476992010-10-04 21:36:35 +02006700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006701 struct net *net;
6702 int err;
6703 u32 pid;
6704
6705 if (!info->attrs[NL80211_ATTR_PID])
6706 return -EINVAL;
6707
6708 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6709
Johannes Berg463d0182009-07-14 00:33:35 +02006710 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006711 if (IS_ERR(net))
6712 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006713
6714 err = 0;
6715
6716 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006717 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6718 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006719
Johannes Berg463d0182009-07-14 00:33:35 +02006720 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006721 return err;
6722}
6723
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006724static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6725{
Johannes Berg4c476992010-10-04 21:36:35 +02006726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006727 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6728 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006729 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006730 struct cfg80211_pmksa pmksa;
6731
6732 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6733
6734 if (!info->attrs[NL80211_ATTR_MAC])
6735 return -EINVAL;
6736
6737 if (!info->attrs[NL80211_ATTR_PMKID])
6738 return -EINVAL;
6739
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006740 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6741 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6742
Johannes Berg074ac8d2010-09-16 14:58:22 +02006743 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006744 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6745 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006746
6747 switch (info->genlhdr->cmd) {
6748 case NL80211_CMD_SET_PMKSA:
6749 rdev_ops = rdev->ops->set_pmksa;
6750 break;
6751 case NL80211_CMD_DEL_PMKSA:
6752 rdev_ops = rdev->ops->del_pmksa;
6753 break;
6754 default:
6755 WARN_ON(1);
6756 break;
6757 }
6758
Johannes Berg4c476992010-10-04 21:36:35 +02006759 if (!rdev_ops)
6760 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006761
Johannes Berg4c476992010-10-04 21:36:35 +02006762 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006763}
6764
6765static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6766{
Johannes Berg4c476992010-10-04 21:36:35 +02006767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6768 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006769
Johannes Berg074ac8d2010-09-16 14:58:22 +02006770 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006771 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6772 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006773
Johannes Berg4c476992010-10-04 21:36:35 +02006774 if (!rdev->ops->flush_pmksa)
6775 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006776
Hila Gonene35e4d22012-06-27 17:19:42 +03006777 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006778}
6779
Arik Nemtsov109086c2011-09-28 14:12:50 +03006780static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6781{
6782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6783 struct net_device *dev = info->user_ptr[1];
6784 u8 action_code, dialog_token;
6785 u16 status_code;
6786 u8 *peer;
6787
6788 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6789 !rdev->ops->tdls_mgmt)
6790 return -EOPNOTSUPP;
6791
6792 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6793 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6794 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6795 !info->attrs[NL80211_ATTR_IE] ||
6796 !info->attrs[NL80211_ATTR_MAC])
6797 return -EINVAL;
6798
6799 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6800 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6801 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6802 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6803
Hila Gonene35e4d22012-06-27 17:19:42 +03006804 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6805 dialog_token, status_code,
6806 nla_data(info->attrs[NL80211_ATTR_IE]),
6807 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006808}
6809
6810static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6811{
6812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6813 struct net_device *dev = info->user_ptr[1];
6814 enum nl80211_tdls_operation operation;
6815 u8 *peer;
6816
6817 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6818 !rdev->ops->tdls_oper)
6819 return -EOPNOTSUPP;
6820
6821 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6822 !info->attrs[NL80211_ATTR_MAC])
6823 return -EINVAL;
6824
6825 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6826 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6827
Hila Gonene35e4d22012-06-27 17:19:42 +03006828 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006829}
6830
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006831static int nl80211_remain_on_channel(struct sk_buff *skb,
6832 struct genl_info *info)
6833{
Johannes Berg4c476992010-10-04 21:36:35 +02006834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006835 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006836 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006837 struct sk_buff *msg;
6838 void *hdr;
6839 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006840 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006841 int err;
6842
6843 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6844 !info->attrs[NL80211_ATTR_DURATION])
6845 return -EINVAL;
6846
6847 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6848
Johannes Berg7c4ef712011-11-18 15:33:48 +01006849 if (!rdev->ops->remain_on_channel ||
6850 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006851 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006852
Johannes Bergebf348f2012-06-01 12:50:54 +02006853 /*
6854 * We should be on that channel for at least a minimum amount of
6855 * time (10ms) but no longer than the driver supports.
6856 */
6857 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6858 duration > rdev->wiphy.max_remain_on_channel_duration)
6859 return -EINVAL;
6860
Johannes Berg683b6d32012-11-08 21:25:48 +01006861 err = nl80211_parse_chandef(rdev, info, &chandef);
6862 if (err)
6863 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006864
6865 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006866 if (!msg)
6867 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006868
Eric W. Biederman15e47302012-09-07 20:12:54 +00006869 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006870 NL80211_CMD_REMAIN_ON_CHANNEL);
6871
6872 if (IS_ERR(hdr)) {
6873 err = PTR_ERR(hdr);
6874 goto free_msg;
6875 }
6876
Johannes Berg683b6d32012-11-08 21:25:48 +01006877 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6878 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006879
6880 if (err)
6881 goto free_msg;
6882
David S. Miller9360ffd2012-03-29 04:41:26 -04006883 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6884 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006885
6886 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006887
6888 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006889
6890 nla_put_failure:
6891 err = -ENOBUFS;
6892 free_msg:
6893 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006894 return err;
6895}
6896
6897static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6898 struct genl_info *info)
6899{
Johannes Berg4c476992010-10-04 21:36:35 +02006900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006901 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006902 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006903
6904 if (!info->attrs[NL80211_ATTR_COOKIE])
6905 return -EINVAL;
6906
Johannes Berg4c476992010-10-04 21:36:35 +02006907 if (!rdev->ops->cancel_remain_on_channel)
6908 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006909
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006910 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6911
Hila Gonene35e4d22012-06-27 17:19:42 +03006912 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006913}
6914
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006915static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6916 u8 *rates, u8 rates_len)
6917{
6918 u8 i;
6919 u32 mask = 0;
6920
6921 for (i = 0; i < rates_len; i++) {
6922 int rate = (rates[i] & 0x7f) * 5;
6923 int ridx;
6924 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6925 struct ieee80211_rate *srate =
6926 &sband->bitrates[ridx];
6927 if (rate == srate->bitrate) {
6928 mask |= 1 << ridx;
6929 break;
6930 }
6931 }
6932 if (ridx == sband->n_bitrates)
6933 return 0; /* rate not found */
6934 }
6935
6936 return mask;
6937}
6938
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006939static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6940 u8 *rates, u8 rates_len,
6941 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6942{
6943 u8 i;
6944
6945 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6946
6947 for (i = 0; i < rates_len; i++) {
6948 int ridx, rbit;
6949
6950 ridx = rates[i] / 8;
6951 rbit = BIT(rates[i] % 8);
6952
6953 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006954 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006955 return false;
6956
6957 /* check availability */
6958 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6959 mcs[ridx] |= rbit;
6960 else
6961 return false;
6962 }
6963
6964 return true;
6965}
6966
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006967static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006968 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6969 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006970 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6971 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006972};
6973
6974static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6975 struct genl_info *info)
6976{
6977 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006979 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006980 int rem, i;
6981 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006982 struct nlattr *tx_rates;
6983 struct ieee80211_supported_band *sband;
6984
6985 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6986 return -EINVAL;
6987
Johannes Berg4c476992010-10-04 21:36:35 +02006988 if (!rdev->ops->set_bitrate_mask)
6989 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006990
6991 memset(&mask, 0, sizeof(mask));
6992 /* Default to all rates enabled */
6993 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6994 sband = rdev->wiphy.bands[i];
6995 mask.control[i].legacy =
6996 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006997 if (sband)
6998 memcpy(mask.control[i].mcs,
6999 sband->ht_cap.mcs.rx_mask,
7000 sizeof(mask.control[i].mcs));
7001 else
7002 memset(mask.control[i].mcs, 0,
7003 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007004 }
7005
7006 /*
7007 * The nested attribute uses enum nl80211_band as the index. This maps
7008 * directly to the enum ieee80211_band values used in cfg80211.
7009 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007010 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007011 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7012 {
7013 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007014 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7015 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007016 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007017 if (sband == NULL)
7018 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007019 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7020 nla_len(tx_rates), nl80211_txattr_policy);
7021 if (tb[NL80211_TXRATE_LEGACY]) {
7022 mask.control[band].legacy = rateset_to_mask(
7023 sband,
7024 nla_data(tb[NL80211_TXRATE_LEGACY]),
7025 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307026 if ((mask.control[band].legacy == 0) &&
7027 nla_len(tb[NL80211_TXRATE_LEGACY]))
7028 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007029 }
7030 if (tb[NL80211_TXRATE_MCS]) {
7031 if (!ht_rateset_to_mask(
7032 sband,
7033 nla_data(tb[NL80211_TXRATE_MCS]),
7034 nla_len(tb[NL80211_TXRATE_MCS]),
7035 mask.control[band].mcs))
7036 return -EINVAL;
7037 }
7038
7039 if (mask.control[band].legacy == 0) {
7040 /* don't allow empty legacy rates if HT
7041 * is not even supported. */
7042 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7043 return -EINVAL;
7044
7045 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7046 if (mask.control[band].mcs[i])
7047 break;
7048
7049 /* legacy and mcs rates may not be both empty */
7050 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007051 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007052 }
7053 }
7054
Hila Gonene35e4d22012-06-27 17:19:42 +03007055 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007056}
7057
Johannes Berg2e161f72010-08-12 15:38:38 +02007058static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007059{
Johannes Berg4c476992010-10-04 21:36:35 +02007060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007061 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007062 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007063
7064 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7065 return -EINVAL;
7066
Johannes Berg2e161f72010-08-12 15:38:38 +02007067 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7068 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007069
Johannes Berg71bbc992012-06-15 15:30:18 +02007070 switch (wdev->iftype) {
7071 case NL80211_IFTYPE_STATION:
7072 case NL80211_IFTYPE_ADHOC:
7073 case NL80211_IFTYPE_P2P_CLIENT:
7074 case NL80211_IFTYPE_AP:
7075 case NL80211_IFTYPE_AP_VLAN:
7076 case NL80211_IFTYPE_MESH_POINT:
7077 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007078 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007079 break;
7080 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007081 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007082 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007083
7084 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007085 if (!rdev->ops->mgmt_tx)
7086 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007087
Eric W. Biederman15e47302012-09-07 20:12:54 +00007088 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007089 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7090 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007091}
7092
Johannes Berg2e161f72010-08-12 15:38:38 +02007093static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007094{
Johannes Berg4c476992010-10-04 21:36:35 +02007095 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007096 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007097 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007098 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007099 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007100 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007101 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007102 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007103 bool offchan, no_cck, dont_wait_for_ack;
7104
7105 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007106
Johannes Berg683b6d32012-11-08 21:25:48 +01007107 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007108 return -EINVAL;
7109
Johannes Berg4c476992010-10-04 21:36:35 +02007110 if (!rdev->ops->mgmt_tx)
7111 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007112
Johannes Berg71bbc992012-06-15 15:30:18 +02007113 switch (wdev->iftype) {
7114 case NL80211_IFTYPE_STATION:
7115 case NL80211_IFTYPE_ADHOC:
7116 case NL80211_IFTYPE_P2P_CLIENT:
7117 case NL80211_IFTYPE_AP:
7118 case NL80211_IFTYPE_AP_VLAN:
7119 case NL80211_IFTYPE_MESH_POINT:
7120 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007121 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007122 break;
7123 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007124 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007125 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007126
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007127 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007128 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007129 return -EINVAL;
7130 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007131
7132 /*
7133 * We should wait on the channel for at least a minimum amount
7134 * of time (10ms) but no longer than the driver supports.
7135 */
7136 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7137 wait > rdev->wiphy.max_remain_on_channel_duration)
7138 return -EINVAL;
7139
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007140 }
7141
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007142 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7143
Johannes Berg7c4ef712011-11-18 15:33:48 +01007144 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7145 return -EINVAL;
7146
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307147 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7148
Johannes Berg683b6d32012-11-08 21:25:48 +01007149 err = nl80211_parse_chandef(rdev, info, &chandef);
7150 if (err)
7151 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007152
Johannes Berge247bd902011-11-04 11:18:21 +01007153 if (!dont_wait_for_ack) {
7154 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7155 if (!msg)
7156 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007157
Eric W. Biederman15e47302012-09-07 20:12:54 +00007158 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007159 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007160
Johannes Berge247bd902011-11-04 11:18:21 +01007161 if (IS_ERR(hdr)) {
7162 err = PTR_ERR(hdr);
7163 goto free_msg;
7164 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007165 }
Johannes Berge247bd902011-11-04 11:18:21 +01007166
Johannes Berg683b6d32012-11-08 21:25:48 +01007167 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007168 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7169 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007170 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007171 if (err)
7172 goto free_msg;
7173
Johannes Berge247bd902011-11-04 11:18:21 +01007174 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007175 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7176 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007177
Johannes Berge247bd902011-11-04 11:18:21 +01007178 genlmsg_end(msg, hdr);
7179 return genlmsg_reply(msg, info);
7180 }
7181
7182 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007183
7184 nla_put_failure:
7185 err = -ENOBUFS;
7186 free_msg:
7187 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007188 return err;
7189}
7190
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007191static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7192{
7193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007194 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007195 u64 cookie;
7196
7197 if (!info->attrs[NL80211_ATTR_COOKIE])
7198 return -EINVAL;
7199
7200 if (!rdev->ops->mgmt_tx_cancel_wait)
7201 return -EOPNOTSUPP;
7202
Johannes Berg71bbc992012-06-15 15:30:18 +02007203 switch (wdev->iftype) {
7204 case NL80211_IFTYPE_STATION:
7205 case NL80211_IFTYPE_ADHOC:
7206 case NL80211_IFTYPE_P2P_CLIENT:
7207 case NL80211_IFTYPE_AP:
7208 case NL80211_IFTYPE_AP_VLAN:
7209 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007210 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007211 break;
7212 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007213 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007214 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007215
7216 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7217
Hila Gonene35e4d22012-06-27 17:19:42 +03007218 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007219}
7220
Kalle Valoffb9eb32010-02-17 17:58:10 +02007221static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7222{
Johannes Berg4c476992010-10-04 21:36:35 +02007223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007224 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007225 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007226 u8 ps_state;
7227 bool state;
7228 int err;
7229
Johannes Berg4c476992010-10-04 21:36:35 +02007230 if (!info->attrs[NL80211_ATTR_PS_STATE])
7231 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007232
7233 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7234
Johannes Berg4c476992010-10-04 21:36:35 +02007235 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7236 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007237
7238 wdev = dev->ieee80211_ptr;
7239
Johannes Berg4c476992010-10-04 21:36:35 +02007240 if (!rdev->ops->set_power_mgmt)
7241 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007242
7243 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7244
7245 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007246 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007247
Hila Gonene35e4d22012-06-27 17:19:42 +03007248 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007249 if (!err)
7250 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007251 return err;
7252}
7253
7254static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7255{
Johannes Berg4c476992010-10-04 21:36:35 +02007256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007257 enum nl80211_ps_state ps_state;
7258 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007259 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007260 struct sk_buff *msg;
7261 void *hdr;
7262 int err;
7263
Kalle Valoffb9eb32010-02-17 17:58:10 +02007264 wdev = dev->ieee80211_ptr;
7265
Johannes Berg4c476992010-10-04 21:36:35 +02007266 if (!rdev->ops->set_power_mgmt)
7267 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007268
7269 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007270 if (!msg)
7271 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007272
Eric W. Biederman15e47302012-09-07 20:12:54 +00007273 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007274 NL80211_CMD_GET_POWER_SAVE);
7275 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007276 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007277 goto free_msg;
7278 }
7279
7280 if (wdev->ps)
7281 ps_state = NL80211_PS_ENABLED;
7282 else
7283 ps_state = NL80211_PS_DISABLED;
7284
David S. Miller9360ffd2012-03-29 04:41:26 -04007285 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7286 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007287
7288 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007289 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007290
Johannes Berg4c476992010-10-04 21:36:35 +02007291 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007292 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007293 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007294 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007295 return err;
7296}
7297
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007298static struct nla_policy
7299nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7300 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7301 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7302 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007303 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7304 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7305 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007306};
7307
Thomas Pedersen84f10702012-07-12 16:17:33 -07007308static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007309 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007310{
7311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7312 struct wireless_dev *wdev;
7313 struct net_device *dev = info->user_ptr[1];
7314
Johannes Bergd9d8b012012-11-26 12:51:52 +01007315 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007316 return -EINVAL;
7317
7318 wdev = dev->ieee80211_ptr;
7319
7320 if (!rdev->ops->set_cqm_txe_config)
7321 return -EOPNOTSUPP;
7322
7323 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7324 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7325 return -EOPNOTSUPP;
7326
Hila Gonene35e4d22012-06-27 17:19:42 +03007327 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007328}
7329
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007330static int nl80211_set_cqm_rssi(struct genl_info *info,
7331 s32 threshold, u32 hysteresis)
7332{
Johannes Berg4c476992010-10-04 21:36:35 +02007333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007334 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007335 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007336
7337 if (threshold > 0)
7338 return -EINVAL;
7339
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007340 wdev = dev->ieee80211_ptr;
7341
Johannes Berg4c476992010-10-04 21:36:35 +02007342 if (!rdev->ops->set_cqm_rssi_config)
7343 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007344
Johannes Berg074ac8d2010-09-16 14:58:22 +02007345 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007346 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7347 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007348
Hila Gonene35e4d22012-06-27 17:19:42 +03007349 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007350}
7351
7352static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7353{
7354 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7355 struct nlattr *cqm;
7356 int err;
7357
7358 cqm = info->attrs[NL80211_ATTR_CQM];
7359 if (!cqm) {
7360 err = -EINVAL;
7361 goto out;
7362 }
7363
7364 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7365 nl80211_attr_cqm_policy);
7366 if (err)
7367 goto out;
7368
7369 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7370 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7371 s32 threshold;
7372 u32 hysteresis;
7373 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7374 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7375 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007376 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7377 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7378 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7379 u32 rate, pkts, intvl;
7380 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7381 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7382 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7383 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007384 } else
7385 err = -EINVAL;
7386
7387out:
7388 return err;
7389}
7390
Johannes Berg29cbe682010-12-03 09:20:44 +01007391static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7392{
7393 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7394 struct net_device *dev = info->user_ptr[1];
7395 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007396 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007397 int err;
7398
7399 /* start with default */
7400 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007401 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007402
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007403 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007404 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007405 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007406 if (err)
7407 return err;
7408 }
7409
7410 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7411 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7412 return -EINVAL;
7413
Javier Cardonac80d5452010-12-16 17:37:49 -08007414 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7415 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7416
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007417 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7418 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7419 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7420 return -EINVAL;
7421
Marco Porsch9bdbf042013-01-07 16:04:51 +01007422 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7423 setup.beacon_interval =
7424 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7425 if (setup.beacon_interval < 10 ||
7426 setup.beacon_interval > 10000)
7427 return -EINVAL;
7428 }
7429
7430 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7431 setup.dtim_period =
7432 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7433 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7434 return -EINVAL;
7435 }
7436
Javier Cardonac80d5452010-12-16 17:37:49 -08007437 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7438 /* parse additional setup parameters if given */
7439 err = nl80211_parse_mesh_setup(info, &setup);
7440 if (err)
7441 return err;
7442 }
7443
Johannes Bergcc1d2802012-05-16 23:50:20 +02007444 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007445 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7446 if (err)
7447 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007448 } else {
7449 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007450 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007451 }
7452
Javier Cardonac80d5452010-12-16 17:37:49 -08007453 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007454}
7455
7456static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7457{
7458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7459 struct net_device *dev = info->user_ptr[1];
7460
7461 return cfg80211_leave_mesh(rdev, dev);
7462}
7463
Johannes Bergdfb89c52012-06-27 09:23:48 +02007464#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007465static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7466 struct cfg80211_registered_device *rdev)
7467{
7468 struct nlattr *nl_pats, *nl_pat;
7469 int i, pat_len;
7470
7471 if (!rdev->wowlan->n_patterns)
7472 return 0;
7473
7474 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7475 if (!nl_pats)
7476 return -ENOBUFS;
7477
7478 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7479 nl_pat = nla_nest_start(msg, i + 1);
7480 if (!nl_pat)
7481 return -ENOBUFS;
7482 pat_len = rdev->wowlan->patterns[i].pattern_len;
7483 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7484 DIV_ROUND_UP(pat_len, 8),
7485 rdev->wowlan->patterns[i].mask) ||
7486 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7487 pat_len, rdev->wowlan->patterns[i].pattern) ||
7488 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7489 rdev->wowlan->patterns[i].pkt_offset))
7490 return -ENOBUFS;
7491 nla_nest_end(msg, nl_pat);
7492 }
7493 nla_nest_end(msg, nl_pats);
7494
7495 return 0;
7496}
7497
Johannes Berg2a0e0472013-01-23 22:57:40 +01007498static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7499 struct cfg80211_wowlan_tcp *tcp)
7500{
7501 struct nlattr *nl_tcp;
7502
7503 if (!tcp)
7504 return 0;
7505
7506 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7507 if (!nl_tcp)
7508 return -ENOBUFS;
7509
7510 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7511 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7512 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7513 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7514 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7515 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7516 tcp->payload_len, tcp->payload) ||
7517 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7518 tcp->data_interval) ||
7519 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7520 tcp->wake_len, tcp->wake_data) ||
7521 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7522 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7523 return -ENOBUFS;
7524
7525 if (tcp->payload_seq.len &&
7526 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7527 sizeof(tcp->payload_seq), &tcp->payload_seq))
7528 return -ENOBUFS;
7529
7530 if (tcp->payload_tok.len &&
7531 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7532 sizeof(tcp->payload_tok) + tcp->tokens_size,
7533 &tcp->payload_tok))
7534 return -ENOBUFS;
7535
7536 return 0;
7537}
7538
Johannes Bergff1b6e62011-05-04 15:37:28 +02007539static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7540{
7541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7542 struct sk_buff *msg;
7543 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007544 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007545
Johannes Berg2a0e0472013-01-23 22:57:40 +01007546 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7547 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007548 return -EOPNOTSUPP;
7549
Johannes Berg2a0e0472013-01-23 22:57:40 +01007550 if (rdev->wowlan && rdev->wowlan->tcp) {
7551 /* adjust size to have room for all the data */
7552 size += rdev->wowlan->tcp->tokens_size +
7553 rdev->wowlan->tcp->payload_len +
7554 rdev->wowlan->tcp->wake_len +
7555 rdev->wowlan->tcp->wake_len / 8;
7556 }
7557
7558 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007559 if (!msg)
7560 return -ENOMEM;
7561
Eric W. Biederman15e47302012-09-07 20:12:54 +00007562 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007563 NL80211_CMD_GET_WOWLAN);
7564 if (!hdr)
7565 goto nla_put_failure;
7566
7567 if (rdev->wowlan) {
7568 struct nlattr *nl_wowlan;
7569
7570 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7571 if (!nl_wowlan)
7572 goto nla_put_failure;
7573
David S. Miller9360ffd2012-03-29 04:41:26 -04007574 if ((rdev->wowlan->any &&
7575 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7576 (rdev->wowlan->disconnect &&
7577 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7578 (rdev->wowlan->magic_pkt &&
7579 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7580 (rdev->wowlan->gtk_rekey_failure &&
7581 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7582 (rdev->wowlan->eap_identity_req &&
7583 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7584 (rdev->wowlan->four_way_handshake &&
7585 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7586 (rdev->wowlan->rfkill_release &&
7587 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7588 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007589
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007590 if (nl80211_send_wowlan_patterns(msg, rdev))
7591 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007592
7593 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7594 goto nla_put_failure;
7595
Johannes Bergff1b6e62011-05-04 15:37:28 +02007596 nla_nest_end(msg, nl_wowlan);
7597 }
7598
7599 genlmsg_end(msg, hdr);
7600 return genlmsg_reply(msg, info);
7601
7602nla_put_failure:
7603 nlmsg_free(msg);
7604 return -ENOBUFS;
7605}
7606
Johannes Berg2a0e0472013-01-23 22:57:40 +01007607static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7608 struct nlattr *attr,
7609 struct cfg80211_wowlan *trig)
7610{
7611 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7612 struct cfg80211_wowlan_tcp *cfg;
7613 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7614 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7615 u32 size;
7616 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7617 int err, port;
7618
7619 if (!rdev->wiphy.wowlan.tcp)
7620 return -EINVAL;
7621
7622 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7623 nla_data(attr), nla_len(attr),
7624 nl80211_wowlan_tcp_policy);
7625 if (err)
7626 return err;
7627
7628 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7629 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7630 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7631 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7632 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7633 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7634 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7635 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7636 return -EINVAL;
7637
7638 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7639 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7640 return -EINVAL;
7641
7642 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg723d5682013-02-26 13:56:40 +01007643 rdev->wiphy.wowlan.tcp->data_interval_max ||
7644 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007645 return -EINVAL;
7646
7647 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7648 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7649 return -EINVAL;
7650
7651 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7652 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7653 return -EINVAL;
7654
7655 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7656 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7657
7658 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7659 tokens_size = tokln - sizeof(*tok);
7660
7661 if (!tok->len || tokens_size % tok->len)
7662 return -EINVAL;
7663 if (!rdev->wiphy.wowlan.tcp->tok)
7664 return -EINVAL;
7665 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7666 return -EINVAL;
7667 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7668 return -EINVAL;
7669 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7670 return -EINVAL;
7671 if (tok->offset + tok->len > data_size)
7672 return -EINVAL;
7673 }
7674
7675 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7676 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7677 if (!rdev->wiphy.wowlan.tcp->seq)
7678 return -EINVAL;
7679 if (seq->len == 0 || seq->len > 4)
7680 return -EINVAL;
7681 if (seq->len + seq->offset > data_size)
7682 return -EINVAL;
7683 }
7684
7685 size = sizeof(*cfg);
7686 size += data_size;
7687 size += wake_size + wake_mask_size;
7688 size += tokens_size;
7689
7690 cfg = kzalloc(size, GFP_KERNEL);
7691 if (!cfg)
7692 return -ENOMEM;
7693 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7694 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7695 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7696 ETH_ALEN);
7697 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7698 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7699 else
7700 port = 0;
7701#ifdef CONFIG_INET
7702 /* allocate a socket and port for it and use it */
7703 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7704 IPPROTO_TCP, &cfg->sock, 1);
7705 if (err) {
7706 kfree(cfg);
7707 return err;
7708 }
7709 if (inet_csk_get_port(cfg->sock->sk, port)) {
7710 sock_release(cfg->sock);
7711 kfree(cfg);
7712 return -EADDRINUSE;
7713 }
7714 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7715#else
7716 if (!port) {
7717 kfree(cfg);
7718 return -EINVAL;
7719 }
7720 cfg->src_port = port;
7721#endif
7722
7723 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7724 cfg->payload_len = data_size;
7725 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7726 memcpy((void *)cfg->payload,
7727 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7728 data_size);
7729 if (seq)
7730 cfg->payload_seq = *seq;
7731 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7732 cfg->wake_len = wake_size;
7733 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7734 memcpy((void *)cfg->wake_data,
7735 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7736 wake_size);
7737 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7738 data_size + wake_size;
7739 memcpy((void *)cfg->wake_mask,
7740 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7741 wake_mask_size);
7742 if (tok) {
7743 cfg->tokens_size = tokens_size;
7744 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7745 }
7746
7747 trig->tcp = cfg;
7748
7749 return 0;
7750}
7751
Johannes Bergff1b6e62011-05-04 15:37:28 +02007752static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7753{
7754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7755 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007756 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007757 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007758 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7759 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007760 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007761
Johannes Berg2a0e0472013-01-23 22:57:40 +01007762 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7763 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007764 return -EOPNOTSUPP;
7765
Johannes Bergae33bd82012-07-12 16:25:02 +02007766 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7767 cfg80211_rdev_free_wowlan(rdev);
7768 rdev->wowlan = NULL;
7769 goto set_wakeup;
7770 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007771
7772 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7773 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7774 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7775 nl80211_wowlan_policy);
7776 if (err)
7777 return err;
7778
7779 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7780 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7781 return -EINVAL;
7782 new_triggers.any = true;
7783 }
7784
7785 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7786 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7787 return -EINVAL;
7788 new_triggers.disconnect = true;
7789 }
7790
7791 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7792 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7793 return -EINVAL;
7794 new_triggers.magic_pkt = true;
7795 }
7796
Johannes Berg77dbbb12011-07-13 10:48:55 +02007797 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7798 return -EINVAL;
7799
7800 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7801 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7802 return -EINVAL;
7803 new_triggers.gtk_rekey_failure = true;
7804 }
7805
7806 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7807 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7808 return -EINVAL;
7809 new_triggers.eap_identity_req = true;
7810 }
7811
7812 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7813 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7814 return -EINVAL;
7815 new_triggers.four_way_handshake = true;
7816 }
7817
7818 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7819 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7820 return -EINVAL;
7821 new_triggers.rfkill_release = true;
7822 }
7823
Johannes Bergff1b6e62011-05-04 15:37:28 +02007824 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7825 struct nlattr *pat;
7826 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007827 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007828 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7829
7830 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7831 rem)
7832 n_patterns++;
7833 if (n_patterns > wowlan->n_patterns)
7834 return -EINVAL;
7835
7836 new_triggers.patterns = kcalloc(n_patterns,
7837 sizeof(new_triggers.patterns[0]),
7838 GFP_KERNEL);
7839 if (!new_triggers.patterns)
7840 return -ENOMEM;
7841
7842 new_triggers.n_patterns = n_patterns;
7843 i = 0;
7844
7845 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7846 rem) {
7847 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7848 nla_data(pat), nla_len(pat), NULL);
7849 err = -EINVAL;
7850 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7851 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7852 goto error;
7853 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7854 mask_len = DIV_ROUND_UP(pat_len, 8);
7855 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7856 mask_len)
7857 goto error;
7858 if (pat_len > wowlan->pattern_max_len ||
7859 pat_len < wowlan->pattern_min_len)
7860 goto error;
7861
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007862 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7863 pkt_offset = 0;
7864 else
7865 pkt_offset = nla_get_u32(
7866 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7867 if (pkt_offset > wowlan->max_pkt_offset)
7868 goto error;
7869 new_triggers.patterns[i].pkt_offset = pkt_offset;
7870
Johannes Bergff1b6e62011-05-04 15:37:28 +02007871 new_triggers.patterns[i].mask =
7872 kmalloc(mask_len + pat_len, GFP_KERNEL);
7873 if (!new_triggers.patterns[i].mask) {
7874 err = -ENOMEM;
7875 goto error;
7876 }
7877 new_triggers.patterns[i].pattern =
7878 new_triggers.patterns[i].mask + mask_len;
7879 memcpy(new_triggers.patterns[i].mask,
7880 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7881 mask_len);
7882 new_triggers.patterns[i].pattern_len = pat_len;
7883 memcpy(new_triggers.patterns[i].pattern,
7884 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7885 pat_len);
7886 i++;
7887 }
7888 }
7889
Johannes Berg2a0e0472013-01-23 22:57:40 +01007890 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7891 err = nl80211_parse_wowlan_tcp(
7892 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7893 &new_triggers);
7894 if (err)
7895 goto error;
7896 }
7897
Johannes Bergae33bd82012-07-12 16:25:02 +02007898 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7899 if (!ntrig) {
7900 err = -ENOMEM;
7901 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007902 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007903 cfg80211_rdev_free_wowlan(rdev);
7904 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007905
Johannes Bergae33bd82012-07-12 16:25:02 +02007906 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007907 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007908 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007909
Johannes Bergff1b6e62011-05-04 15:37:28 +02007910 return 0;
7911 error:
7912 for (i = 0; i < new_triggers.n_patterns; i++)
7913 kfree(new_triggers.patterns[i].mask);
7914 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007915 if (new_triggers.tcp && new_triggers.tcp->sock)
7916 sock_release(new_triggers.tcp->sock);
7917 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007918 return err;
7919}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007920#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007921
Johannes Berge5497d72011-07-05 16:35:40 +02007922static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7923{
7924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7925 struct net_device *dev = info->user_ptr[1];
7926 struct wireless_dev *wdev = dev->ieee80211_ptr;
7927 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7928 struct cfg80211_gtk_rekey_data rekey_data;
7929 int err;
7930
7931 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7932 return -EINVAL;
7933
7934 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7935 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7936 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7937 nl80211_rekey_policy);
7938 if (err)
7939 return err;
7940
7941 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7942 return -ERANGE;
7943 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7944 return -ERANGE;
7945 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7946 return -ERANGE;
7947
7948 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7949 NL80211_KEK_LEN);
7950 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7951 NL80211_KCK_LEN);
7952 memcpy(rekey_data.replay_ctr,
7953 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7954 NL80211_REPLAY_CTR_LEN);
7955
7956 wdev_lock(wdev);
7957 if (!wdev->current_bss) {
7958 err = -ENOTCONN;
7959 goto out;
7960 }
7961
7962 if (!rdev->ops->set_rekey_data) {
7963 err = -EOPNOTSUPP;
7964 goto out;
7965 }
7966
Hila Gonene35e4d22012-06-27 17:19:42 +03007967 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007968 out:
7969 wdev_unlock(wdev);
7970 return err;
7971}
7972
Johannes Berg28946da2011-11-04 11:18:12 +01007973static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7974 struct genl_info *info)
7975{
7976 struct net_device *dev = info->user_ptr[1];
7977 struct wireless_dev *wdev = dev->ieee80211_ptr;
7978
7979 if (wdev->iftype != NL80211_IFTYPE_AP &&
7980 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7981 return -EINVAL;
7982
Eric W. Biederman15e47302012-09-07 20:12:54 +00007983 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01007984 return -EBUSY;
7985
Eric W. Biederman15e47302012-09-07 20:12:54 +00007986 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01007987 return 0;
7988}
7989
Johannes Berg7f6cf312011-11-04 11:18:15 +01007990static int nl80211_probe_client(struct sk_buff *skb,
7991 struct genl_info *info)
7992{
7993 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7994 struct net_device *dev = info->user_ptr[1];
7995 struct wireless_dev *wdev = dev->ieee80211_ptr;
7996 struct sk_buff *msg;
7997 void *hdr;
7998 const u8 *addr;
7999 u64 cookie;
8000 int err;
8001
8002 if (wdev->iftype != NL80211_IFTYPE_AP &&
8003 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8004 return -EOPNOTSUPP;
8005
8006 if (!info->attrs[NL80211_ATTR_MAC])
8007 return -EINVAL;
8008
8009 if (!rdev->ops->probe_client)
8010 return -EOPNOTSUPP;
8011
8012 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8013 if (!msg)
8014 return -ENOMEM;
8015
Eric W. Biederman15e47302012-09-07 20:12:54 +00008016 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008017 NL80211_CMD_PROBE_CLIENT);
8018
8019 if (IS_ERR(hdr)) {
8020 err = PTR_ERR(hdr);
8021 goto free_msg;
8022 }
8023
8024 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8025
Hila Gonene35e4d22012-06-27 17:19:42 +03008026 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008027 if (err)
8028 goto free_msg;
8029
David S. Miller9360ffd2012-03-29 04:41:26 -04008030 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8031 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008032
8033 genlmsg_end(msg, hdr);
8034
8035 return genlmsg_reply(msg, info);
8036
8037 nla_put_failure:
8038 err = -ENOBUFS;
8039 free_msg:
8040 nlmsg_free(msg);
8041 return err;
8042}
8043
Johannes Berg5e760232011-11-04 11:18:17 +01008044static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8045{
8046 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008047 struct cfg80211_beacon_registration *reg, *nreg;
8048 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008049
8050 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8051 return -EOPNOTSUPP;
8052
Ben Greear37c73b52012-10-26 14:49:25 -07008053 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8054 if (!nreg)
8055 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008056
Ben Greear37c73b52012-10-26 14:49:25 -07008057 /* First, check if already registered. */
8058 spin_lock_bh(&rdev->beacon_registrations_lock);
8059 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8060 if (reg->nlportid == info->snd_portid) {
8061 rv = -EALREADY;
8062 goto out_err;
8063 }
8064 }
8065 /* Add it to the list */
8066 nreg->nlportid = info->snd_portid;
8067 list_add(&nreg->list, &rdev->beacon_registrations);
8068
8069 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008070
8071 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008072out_err:
8073 spin_unlock_bh(&rdev->beacon_registrations_lock);
8074 kfree(nreg);
8075 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008076}
8077
Johannes Berg98104fde2012-06-16 00:19:54 +02008078static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8079{
8080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8081 struct wireless_dev *wdev = info->user_ptr[1];
8082 int err;
8083
8084 if (!rdev->ops->start_p2p_device)
8085 return -EOPNOTSUPP;
8086
8087 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8088 return -EOPNOTSUPP;
8089
8090 if (wdev->p2p_started)
8091 return 0;
8092
8093 mutex_lock(&rdev->devlist_mtx);
8094 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8095 mutex_unlock(&rdev->devlist_mtx);
8096 if (err)
8097 return err;
8098
Johannes Bergeeb126e2012-10-23 15:16:50 +02008099 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008100 if (err)
8101 return err;
8102
8103 wdev->p2p_started = true;
8104 mutex_lock(&rdev->devlist_mtx);
8105 rdev->opencount++;
8106 mutex_unlock(&rdev->devlist_mtx);
8107
8108 return 0;
8109}
8110
8111static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8112{
8113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8114 struct wireless_dev *wdev = info->user_ptr[1];
8115
8116 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8117 return -EOPNOTSUPP;
8118
8119 if (!rdev->ops->stop_p2p_device)
8120 return -EOPNOTSUPP;
8121
8122 if (!wdev->p2p_started)
8123 return 0;
8124
Johannes Bergeeb126e2012-10-23 15:16:50 +02008125 rdev_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008126 wdev->p2p_started = false;
8127
8128 mutex_lock(&rdev->devlist_mtx);
8129 rdev->opencount--;
8130 mutex_unlock(&rdev->devlist_mtx);
8131
8132 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
8133 rdev->scan_req->aborted = true;
8134 ___cfg80211_scan_done(rdev, true);
8135 }
8136
8137 return 0;
8138}
8139
Johannes Berg3713b4e2013-02-14 16:19:38 +01008140static int nl80211_get_protocol_features(struct sk_buff *skb,
8141 struct genl_info *info)
8142{
8143 void *hdr;
8144 struct sk_buff *msg;
8145
8146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8147 if (!msg)
8148 return -ENOMEM;
8149
8150 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8151 NL80211_CMD_GET_PROTOCOL_FEATURES);
8152 if (!hdr)
8153 goto nla_put_failure;
8154
8155 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8156 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8157 goto nla_put_failure;
8158
8159 genlmsg_end(msg, hdr);
8160 return genlmsg_reply(msg, info);
8161
8162 nla_put_failure:
8163 kfree_skb(msg);
8164 return -ENOBUFS;
8165}
8166
Jouni Malinen355199e2013-02-27 17:14:27 +02008167static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8168{
8169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8170 struct cfg80211_update_ft_ies_params ft_params;
8171 struct net_device *dev = info->user_ptr[1];
8172
8173 if (!rdev->ops->update_ft_ies)
8174 return -EOPNOTSUPP;
8175
8176 if (!info->attrs[NL80211_ATTR_MDID] ||
8177 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8178 return -EINVAL;
8179
8180 memset(&ft_params, 0, sizeof(ft_params));
8181 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8182 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8183 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8184
8185 return rdev_update_ft_ies(rdev, dev, &ft_params);
8186}
8187
Johannes Berg4c476992010-10-04 21:36:35 +02008188#define NL80211_FLAG_NEED_WIPHY 0x01
8189#define NL80211_FLAG_NEED_NETDEV 0x02
8190#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008191#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8192#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8193 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008194#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008195/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008196#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8197 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008198
8199static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8200 struct genl_info *info)
8201{
8202 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008203 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008204 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008205 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8206
8207 if (rtnl)
8208 rtnl_lock();
8209
8210 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008211 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008212 if (IS_ERR(rdev)) {
8213 if (rtnl)
8214 rtnl_unlock();
8215 return PTR_ERR(rdev);
8216 }
8217 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008218 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8219 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008220 mutex_lock(&cfg80211_mutex);
8221 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8222 info->attrs);
8223 if (IS_ERR(wdev)) {
8224 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02008225 if (rtnl)
8226 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008227 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008228 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008229
Johannes Berg89a54e42012-06-15 14:33:17 +02008230 dev = wdev->netdev;
8231 rdev = wiphy_to_dev(wdev->wiphy);
8232
Johannes Berg1bf614e2012-06-15 15:23:36 +02008233 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8234 if (!dev) {
8235 mutex_unlock(&cfg80211_mutex);
8236 if (rtnl)
8237 rtnl_unlock();
8238 return -EINVAL;
8239 }
8240
8241 info->user_ptr[1] = dev;
8242 } else {
8243 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008244 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008245
Johannes Berg1bf614e2012-06-15 15:23:36 +02008246 if (dev) {
8247 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8248 !netif_running(dev)) {
8249 mutex_unlock(&cfg80211_mutex);
8250 if (rtnl)
8251 rtnl_unlock();
8252 return -ENETDOWN;
8253 }
8254
8255 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008256 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8257 if (!wdev->p2p_started) {
8258 mutex_unlock(&cfg80211_mutex);
8259 if (rtnl)
8260 rtnl_unlock();
8261 return -ENETDOWN;
8262 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008263 }
8264
Johannes Berg89a54e42012-06-15 14:33:17 +02008265 cfg80211_lock_rdev(rdev);
8266
8267 mutex_unlock(&cfg80211_mutex);
8268
Johannes Berg4c476992010-10-04 21:36:35 +02008269 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008270 }
8271
8272 return 0;
8273}
8274
8275static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8276 struct genl_info *info)
8277{
8278 if (info->user_ptr[0])
8279 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02008280 if (info->user_ptr[1]) {
8281 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8282 struct wireless_dev *wdev = info->user_ptr[1];
8283
8284 if (wdev->netdev)
8285 dev_put(wdev->netdev);
8286 } else {
8287 dev_put(info->user_ptr[1]);
8288 }
8289 }
Johannes Berg4c476992010-10-04 21:36:35 +02008290 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8291 rtnl_unlock();
8292}
8293
Johannes Berg55682962007-09-20 13:09:35 -04008294static struct genl_ops nl80211_ops[] = {
8295 {
8296 .cmd = NL80211_CMD_GET_WIPHY,
8297 .doit = nl80211_get_wiphy,
8298 .dumpit = nl80211_dump_wiphy,
8299 .policy = nl80211_policy,
8300 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008301 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04008302 },
8303 {
8304 .cmd = NL80211_CMD_SET_WIPHY,
8305 .doit = nl80211_set_wiphy,
8306 .policy = nl80211_policy,
8307 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008308 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008309 },
8310 {
8311 .cmd = NL80211_CMD_GET_INTERFACE,
8312 .doit = nl80211_get_interface,
8313 .dumpit = nl80211_dump_interface,
8314 .policy = nl80211_policy,
8315 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02008316 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04008317 },
8318 {
8319 .cmd = NL80211_CMD_SET_INTERFACE,
8320 .doit = nl80211_set_interface,
8321 .policy = nl80211_policy,
8322 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008323 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8324 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008325 },
8326 {
8327 .cmd = NL80211_CMD_NEW_INTERFACE,
8328 .doit = nl80211_new_interface,
8329 .policy = nl80211_policy,
8330 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008331 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8332 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008333 },
8334 {
8335 .cmd = NL80211_CMD_DEL_INTERFACE,
8336 .doit = nl80211_del_interface,
8337 .policy = nl80211_policy,
8338 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008339 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008340 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008341 },
Johannes Berg41ade002007-12-19 02:03:29 +01008342 {
8343 .cmd = NL80211_CMD_GET_KEY,
8344 .doit = nl80211_get_key,
8345 .policy = nl80211_policy,
8346 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008347 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008348 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008349 },
8350 {
8351 .cmd = NL80211_CMD_SET_KEY,
8352 .doit = nl80211_set_key,
8353 .policy = nl80211_policy,
8354 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008356 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008357 },
8358 {
8359 .cmd = NL80211_CMD_NEW_KEY,
8360 .doit = nl80211_new_key,
8361 .policy = nl80211_policy,
8362 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008364 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008365 },
8366 {
8367 .cmd = NL80211_CMD_DEL_KEY,
8368 .doit = nl80211_del_key,
8369 .policy = nl80211_policy,
8370 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008372 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008373 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008374 {
8375 .cmd = NL80211_CMD_SET_BEACON,
8376 .policy = nl80211_policy,
8377 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008378 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008379 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008380 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008381 },
8382 {
Johannes Berg88600202012-02-13 15:17:18 +01008383 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008384 .policy = nl80211_policy,
8385 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008386 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008388 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008389 },
8390 {
Johannes Berg88600202012-02-13 15:17:18 +01008391 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008392 .policy = nl80211_policy,
8393 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008394 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008396 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008397 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008398 {
8399 .cmd = NL80211_CMD_GET_STATION,
8400 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008401 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008402 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008403 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8404 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008405 },
8406 {
8407 .cmd = NL80211_CMD_SET_STATION,
8408 .doit = nl80211_set_station,
8409 .policy = nl80211_policy,
8410 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008412 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008413 },
8414 {
8415 .cmd = NL80211_CMD_NEW_STATION,
8416 .doit = nl80211_new_station,
8417 .policy = nl80211_policy,
8418 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008420 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008421 },
8422 {
8423 .cmd = NL80211_CMD_DEL_STATION,
8424 .doit = nl80211_del_station,
8425 .policy = nl80211_policy,
8426 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008428 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008429 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008430 {
8431 .cmd = NL80211_CMD_GET_MPATH,
8432 .doit = nl80211_get_mpath,
8433 .dumpit = nl80211_dump_mpath,
8434 .policy = nl80211_policy,
8435 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008436 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008437 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008438 },
8439 {
8440 .cmd = NL80211_CMD_SET_MPATH,
8441 .doit = nl80211_set_mpath,
8442 .policy = nl80211_policy,
8443 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008444 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008445 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008446 },
8447 {
8448 .cmd = NL80211_CMD_NEW_MPATH,
8449 .doit = nl80211_new_mpath,
8450 .policy = nl80211_policy,
8451 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008452 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008453 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008454 },
8455 {
8456 .cmd = NL80211_CMD_DEL_MPATH,
8457 .doit = nl80211_del_mpath,
8458 .policy = nl80211_policy,
8459 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008460 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008461 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008462 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008463 {
8464 .cmd = NL80211_CMD_SET_BSS,
8465 .doit = nl80211_set_bss,
8466 .policy = nl80211_policy,
8467 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008468 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008469 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008470 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008471 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008472 .cmd = NL80211_CMD_GET_REG,
8473 .doit = nl80211_get_reg,
8474 .policy = nl80211_policy,
8475 /* can be retrieved by unprivileged users */
8476 },
8477 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008478 .cmd = NL80211_CMD_SET_REG,
8479 .doit = nl80211_set_reg,
8480 .policy = nl80211_policy,
8481 .flags = GENL_ADMIN_PERM,
8482 },
8483 {
8484 .cmd = NL80211_CMD_REQ_SET_REG,
8485 .doit = nl80211_req_set_reg,
8486 .policy = nl80211_policy,
8487 .flags = GENL_ADMIN_PERM,
8488 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008489 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008490 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8491 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008492 .policy = nl80211_policy,
8493 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008494 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008495 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008496 },
8497 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008498 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8499 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008500 .policy = nl80211_policy,
8501 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008502 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008503 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008504 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008505 {
Johannes Berg2a519312009-02-10 21:25:55 +01008506 .cmd = NL80211_CMD_TRIGGER_SCAN,
8507 .doit = nl80211_trigger_scan,
8508 .policy = nl80211_policy,
8509 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008510 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008511 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008512 },
8513 {
8514 .cmd = NL80211_CMD_GET_SCAN,
8515 .policy = nl80211_policy,
8516 .dumpit = nl80211_dump_scan,
8517 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008518 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008519 .cmd = NL80211_CMD_START_SCHED_SCAN,
8520 .doit = nl80211_start_sched_scan,
8521 .policy = nl80211_policy,
8522 .flags = GENL_ADMIN_PERM,
8523 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8524 NL80211_FLAG_NEED_RTNL,
8525 },
8526 {
8527 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8528 .doit = nl80211_stop_sched_scan,
8529 .policy = nl80211_policy,
8530 .flags = GENL_ADMIN_PERM,
8531 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8532 NL80211_FLAG_NEED_RTNL,
8533 },
8534 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008535 .cmd = NL80211_CMD_AUTHENTICATE,
8536 .doit = nl80211_authenticate,
8537 .policy = nl80211_policy,
8538 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008539 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008540 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008541 },
8542 {
8543 .cmd = NL80211_CMD_ASSOCIATE,
8544 .doit = nl80211_associate,
8545 .policy = nl80211_policy,
8546 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008547 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008548 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008549 },
8550 {
8551 .cmd = NL80211_CMD_DEAUTHENTICATE,
8552 .doit = nl80211_deauthenticate,
8553 .policy = nl80211_policy,
8554 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008556 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008557 },
8558 {
8559 .cmd = NL80211_CMD_DISASSOCIATE,
8560 .doit = nl80211_disassociate,
8561 .policy = nl80211_policy,
8562 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008563 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008564 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008565 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008566 {
8567 .cmd = NL80211_CMD_JOIN_IBSS,
8568 .doit = nl80211_join_ibss,
8569 .policy = nl80211_policy,
8570 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008571 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008572 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008573 },
8574 {
8575 .cmd = NL80211_CMD_LEAVE_IBSS,
8576 .doit = nl80211_leave_ibss,
8577 .policy = nl80211_policy,
8578 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008579 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008580 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008581 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008582#ifdef CONFIG_NL80211_TESTMODE
8583 {
8584 .cmd = NL80211_CMD_TESTMODE,
8585 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008586 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008587 .policy = nl80211_policy,
8588 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008589 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8590 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008591 },
8592#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008593 {
8594 .cmd = NL80211_CMD_CONNECT,
8595 .doit = nl80211_connect,
8596 .policy = nl80211_policy,
8597 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008599 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008600 },
8601 {
8602 .cmd = NL80211_CMD_DISCONNECT,
8603 .doit = nl80211_disconnect,
8604 .policy = nl80211_policy,
8605 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008607 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008608 },
Johannes Berg463d0182009-07-14 00:33:35 +02008609 {
8610 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8611 .doit = nl80211_wiphy_netns,
8612 .policy = nl80211_policy,
8613 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008614 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8615 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008616 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008617 {
8618 .cmd = NL80211_CMD_GET_SURVEY,
8619 .policy = nl80211_policy,
8620 .dumpit = nl80211_dump_survey,
8621 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008622 {
8623 .cmd = NL80211_CMD_SET_PMKSA,
8624 .doit = nl80211_setdel_pmksa,
8625 .policy = nl80211_policy,
8626 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008627 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008628 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008629 },
8630 {
8631 .cmd = NL80211_CMD_DEL_PMKSA,
8632 .doit = nl80211_setdel_pmksa,
8633 .policy = nl80211_policy,
8634 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008635 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008636 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008637 },
8638 {
8639 .cmd = NL80211_CMD_FLUSH_PMKSA,
8640 .doit = nl80211_flush_pmksa,
8641 .policy = nl80211_policy,
8642 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008643 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008644 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008645 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008646 {
8647 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8648 .doit = nl80211_remain_on_channel,
8649 .policy = nl80211_policy,
8650 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008651 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008652 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008653 },
8654 {
8655 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8656 .doit = nl80211_cancel_remain_on_channel,
8657 .policy = nl80211_policy,
8658 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008659 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008660 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008661 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008662 {
8663 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8664 .doit = nl80211_set_tx_bitrate_mask,
8665 .policy = nl80211_policy,
8666 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008667 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8668 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008669 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008670 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008671 .cmd = NL80211_CMD_REGISTER_FRAME,
8672 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008673 .policy = nl80211_policy,
8674 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008675 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008676 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008677 },
8678 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008679 .cmd = NL80211_CMD_FRAME,
8680 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008681 .policy = nl80211_policy,
8682 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008683 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008684 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008685 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008686 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008687 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8688 .doit = nl80211_tx_mgmt_cancel_wait,
8689 .policy = nl80211_policy,
8690 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008691 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008692 NL80211_FLAG_NEED_RTNL,
8693 },
8694 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008695 .cmd = NL80211_CMD_SET_POWER_SAVE,
8696 .doit = nl80211_set_power_save,
8697 .policy = nl80211_policy,
8698 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008699 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8700 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008701 },
8702 {
8703 .cmd = NL80211_CMD_GET_POWER_SAVE,
8704 .doit = nl80211_get_power_save,
8705 .policy = nl80211_policy,
8706 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008707 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8708 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008709 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008710 {
8711 .cmd = NL80211_CMD_SET_CQM,
8712 .doit = nl80211_set_cqm,
8713 .policy = nl80211_policy,
8714 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008715 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8716 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008717 },
Johannes Bergf444de02010-05-05 15:25:02 +02008718 {
8719 .cmd = NL80211_CMD_SET_CHANNEL,
8720 .doit = nl80211_set_channel,
8721 .policy = nl80211_policy,
8722 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008723 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8724 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008725 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008726 {
8727 .cmd = NL80211_CMD_SET_WDS_PEER,
8728 .doit = nl80211_set_wds_peer,
8729 .policy = nl80211_policy,
8730 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008731 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8732 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008733 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008734 {
8735 .cmd = NL80211_CMD_JOIN_MESH,
8736 .doit = nl80211_join_mesh,
8737 .policy = nl80211_policy,
8738 .flags = GENL_ADMIN_PERM,
8739 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8740 NL80211_FLAG_NEED_RTNL,
8741 },
8742 {
8743 .cmd = NL80211_CMD_LEAVE_MESH,
8744 .doit = nl80211_leave_mesh,
8745 .policy = nl80211_policy,
8746 .flags = GENL_ADMIN_PERM,
8747 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8748 NL80211_FLAG_NEED_RTNL,
8749 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008750#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008751 {
8752 .cmd = NL80211_CMD_GET_WOWLAN,
8753 .doit = nl80211_get_wowlan,
8754 .policy = nl80211_policy,
8755 /* can be retrieved by unprivileged users */
8756 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8757 NL80211_FLAG_NEED_RTNL,
8758 },
8759 {
8760 .cmd = NL80211_CMD_SET_WOWLAN,
8761 .doit = nl80211_set_wowlan,
8762 .policy = nl80211_policy,
8763 .flags = GENL_ADMIN_PERM,
8764 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8765 NL80211_FLAG_NEED_RTNL,
8766 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008767#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008768 {
8769 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8770 .doit = nl80211_set_rekey_data,
8771 .policy = nl80211_policy,
8772 .flags = GENL_ADMIN_PERM,
8773 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8774 NL80211_FLAG_NEED_RTNL,
8775 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008776 {
8777 .cmd = NL80211_CMD_TDLS_MGMT,
8778 .doit = nl80211_tdls_mgmt,
8779 .policy = nl80211_policy,
8780 .flags = GENL_ADMIN_PERM,
8781 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8782 NL80211_FLAG_NEED_RTNL,
8783 },
8784 {
8785 .cmd = NL80211_CMD_TDLS_OPER,
8786 .doit = nl80211_tdls_oper,
8787 .policy = nl80211_policy,
8788 .flags = GENL_ADMIN_PERM,
8789 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8790 NL80211_FLAG_NEED_RTNL,
8791 },
Johannes Berg28946da2011-11-04 11:18:12 +01008792 {
8793 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8794 .doit = nl80211_register_unexpected_frame,
8795 .policy = nl80211_policy,
8796 .flags = GENL_ADMIN_PERM,
8797 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8798 NL80211_FLAG_NEED_RTNL,
8799 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008800 {
8801 .cmd = NL80211_CMD_PROBE_CLIENT,
8802 .doit = nl80211_probe_client,
8803 .policy = nl80211_policy,
8804 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008805 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008806 NL80211_FLAG_NEED_RTNL,
8807 },
Johannes Berg5e760232011-11-04 11:18:17 +01008808 {
8809 .cmd = NL80211_CMD_REGISTER_BEACONS,
8810 .doit = nl80211_register_beacons,
8811 .policy = nl80211_policy,
8812 .flags = GENL_ADMIN_PERM,
8813 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8814 NL80211_FLAG_NEED_RTNL,
8815 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008816 {
8817 .cmd = NL80211_CMD_SET_NOACK_MAP,
8818 .doit = nl80211_set_noack_map,
8819 .policy = nl80211_policy,
8820 .flags = GENL_ADMIN_PERM,
8821 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8822 NL80211_FLAG_NEED_RTNL,
8823 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008824 {
8825 .cmd = NL80211_CMD_START_P2P_DEVICE,
8826 .doit = nl80211_start_p2p_device,
8827 .policy = nl80211_policy,
8828 .flags = GENL_ADMIN_PERM,
8829 .internal_flags = NL80211_FLAG_NEED_WDEV |
8830 NL80211_FLAG_NEED_RTNL,
8831 },
8832 {
8833 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8834 .doit = nl80211_stop_p2p_device,
8835 .policy = nl80211_policy,
8836 .flags = GENL_ADMIN_PERM,
8837 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8838 NL80211_FLAG_NEED_RTNL,
8839 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008840 {
8841 .cmd = NL80211_CMD_SET_MCAST_RATE,
8842 .doit = nl80211_set_mcast_rate,
8843 .policy = nl80211_policy,
8844 .flags = GENL_ADMIN_PERM,
8845 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8846 NL80211_FLAG_NEED_RTNL,
8847 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308848 {
8849 .cmd = NL80211_CMD_SET_MAC_ACL,
8850 .doit = nl80211_set_mac_acl,
8851 .policy = nl80211_policy,
8852 .flags = GENL_ADMIN_PERM,
8853 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8854 NL80211_FLAG_NEED_RTNL,
8855 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008856 {
8857 .cmd = NL80211_CMD_RADAR_DETECT,
8858 .doit = nl80211_start_radar_detection,
8859 .policy = nl80211_policy,
8860 .flags = GENL_ADMIN_PERM,
8861 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8862 NL80211_FLAG_NEED_RTNL,
8863 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008864 {
8865 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8866 .doit = nl80211_get_protocol_features,
8867 .policy = nl80211_policy,
8868 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008869 {
8870 .cmd = NL80211_CMD_UPDATE_FT_IES,
8871 .doit = nl80211_update_ft_ies,
8872 .policy = nl80211_policy,
8873 .flags = GENL_ADMIN_PERM,
8874 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8875 NL80211_FLAG_NEED_RTNL,
8876 },
Johannes Berg55682962007-09-20 13:09:35 -04008877};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008878
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008879static struct genl_multicast_group nl80211_mlme_mcgrp = {
8880 .name = "mlme",
8881};
Johannes Berg55682962007-09-20 13:09:35 -04008882
8883/* multicast groups */
8884static struct genl_multicast_group nl80211_config_mcgrp = {
8885 .name = "config",
8886};
Johannes Berg2a519312009-02-10 21:25:55 +01008887static struct genl_multicast_group nl80211_scan_mcgrp = {
8888 .name = "scan",
8889};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008890static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8891 .name = "regulatory",
8892};
Johannes Berg55682962007-09-20 13:09:35 -04008893
8894/* notification functions */
8895
8896void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8897{
8898 struct sk_buff *msg;
8899
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008900 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008901 if (!msg)
8902 return;
8903
Johannes Berg3713b4e2013-02-14 16:19:38 +01008904 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8905 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008906 nlmsg_free(msg);
8907 return;
8908 }
8909
Johannes Berg463d0182009-07-14 00:33:35 +02008910 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8911 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008912}
8913
Johannes Berg362a4152009-05-24 16:43:15 +02008914static int nl80211_add_scan_req(struct sk_buff *msg,
8915 struct cfg80211_registered_device *rdev)
8916{
8917 struct cfg80211_scan_request *req = rdev->scan_req;
8918 struct nlattr *nest;
8919 int i;
8920
Johannes Berg667503dd2009-07-07 03:56:11 +02008921 ASSERT_RDEV_LOCK(rdev);
8922
Johannes Berg362a4152009-05-24 16:43:15 +02008923 if (WARN_ON(!req))
8924 return 0;
8925
8926 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8927 if (!nest)
8928 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008929 for (i = 0; i < req->n_ssids; i++) {
8930 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8931 goto nla_put_failure;
8932 }
Johannes Berg362a4152009-05-24 16:43:15 +02008933 nla_nest_end(msg, nest);
8934
8935 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8936 if (!nest)
8937 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008938 for (i = 0; i < req->n_channels; i++) {
8939 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8940 goto nla_put_failure;
8941 }
Johannes Berg362a4152009-05-24 16:43:15 +02008942 nla_nest_end(msg, nest);
8943
David S. Miller9360ffd2012-03-29 04:41:26 -04008944 if (req->ie &&
8945 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8946 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008947
Sam Lefflered4737712012-10-11 21:03:31 -07008948 if (req->flags)
8949 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8950
Johannes Berg362a4152009-05-24 16:43:15 +02008951 return 0;
8952 nla_put_failure:
8953 return -ENOBUFS;
8954}
8955
Johannes Berga538e2d2009-06-16 19:56:42 +02008956static int nl80211_send_scan_msg(struct sk_buff *msg,
8957 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008958 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008959 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008960 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008961{
8962 void *hdr;
8963
Eric W. Biederman15e47302012-09-07 20:12:54 +00008964 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008965 if (!hdr)
8966 return -1;
8967
David S. Miller9360ffd2012-03-29 04:41:26 -04008968 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008969 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8970 wdev->netdev->ifindex)) ||
8971 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008972 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008973
Johannes Berg362a4152009-05-24 16:43:15 +02008974 /* ignore errors and send incomplete event anyway */
8975 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008976
8977 return genlmsg_end(msg, hdr);
8978
8979 nla_put_failure:
8980 genlmsg_cancel(msg, hdr);
8981 return -EMSGSIZE;
8982}
8983
Luciano Coelho807f8a82011-05-11 17:09:35 +03008984static int
8985nl80211_send_sched_scan_msg(struct sk_buff *msg,
8986 struct cfg80211_registered_device *rdev,
8987 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008988 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008989{
8990 void *hdr;
8991
Eric W. Biederman15e47302012-09-07 20:12:54 +00008992 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008993 if (!hdr)
8994 return -1;
8995
David S. Miller9360ffd2012-03-29 04:41:26 -04008996 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8997 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8998 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008999
9000 return genlmsg_end(msg, hdr);
9001
9002 nla_put_failure:
9003 genlmsg_cancel(msg, hdr);
9004 return -EMSGSIZE;
9005}
9006
Johannes Berga538e2d2009-06-16 19:56:42 +02009007void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009008 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009009{
9010 struct sk_buff *msg;
9011
Thomas Graf58050fc2012-06-28 03:57:45 +00009012 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009013 if (!msg)
9014 return;
9015
Johannes Bergfd014282012-06-18 19:17:03 +02009016 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009017 NL80211_CMD_TRIGGER_SCAN) < 0) {
9018 nlmsg_free(msg);
9019 return;
9020 }
9021
Johannes Berg463d0182009-07-14 00:33:35 +02009022 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9023 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009024}
9025
Johannes Berg2a519312009-02-10 21:25:55 +01009026void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009027 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009028{
9029 struct sk_buff *msg;
9030
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009031 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009032 if (!msg)
9033 return;
9034
Johannes Bergfd014282012-06-18 19:17:03 +02009035 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009036 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009037 nlmsg_free(msg);
9038 return;
9039 }
9040
Johannes Berg463d0182009-07-14 00:33:35 +02009041 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9042 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009043}
9044
9045void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009046 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009047{
9048 struct sk_buff *msg;
9049
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009050 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009051 if (!msg)
9052 return;
9053
Johannes Bergfd014282012-06-18 19:17:03 +02009054 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009055 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009056 nlmsg_free(msg);
9057 return;
9058 }
9059
Johannes Berg463d0182009-07-14 00:33:35 +02009060 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9061 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009062}
9063
Luciano Coelho807f8a82011-05-11 17:09:35 +03009064void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9065 struct net_device *netdev)
9066{
9067 struct sk_buff *msg;
9068
9069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9070 if (!msg)
9071 return;
9072
9073 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9074 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9075 nlmsg_free(msg);
9076 return;
9077 }
9078
9079 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9080 nl80211_scan_mcgrp.id, GFP_KERNEL);
9081}
9082
9083void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9084 struct net_device *netdev, u32 cmd)
9085{
9086 struct sk_buff *msg;
9087
Thomas Graf58050fc2012-06-28 03:57:45 +00009088 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009089 if (!msg)
9090 return;
9091
9092 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9093 nlmsg_free(msg);
9094 return;
9095 }
9096
9097 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9098 nl80211_scan_mcgrp.id, GFP_KERNEL);
9099}
9100
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009101/*
9102 * This can happen on global regulatory changes or device specific settings
9103 * based on custom world regulatory domains.
9104 */
9105void nl80211_send_reg_change_event(struct regulatory_request *request)
9106{
9107 struct sk_buff *msg;
9108 void *hdr;
9109
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009110 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009111 if (!msg)
9112 return;
9113
9114 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9115 if (!hdr) {
9116 nlmsg_free(msg);
9117 return;
9118 }
9119
9120 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009121 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9122 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009123
David S. Miller9360ffd2012-03-29 04:41:26 -04009124 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9125 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9126 NL80211_REGDOM_TYPE_WORLD))
9127 goto nla_put_failure;
9128 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9129 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9130 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9131 goto nla_put_failure;
9132 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9133 request->intersect) {
9134 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9135 NL80211_REGDOM_TYPE_INTERSECTION))
9136 goto nla_put_failure;
9137 } else {
9138 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9139 NL80211_REGDOM_TYPE_COUNTRY) ||
9140 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9141 request->alpha2))
9142 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009143 }
9144
Johannes Bergf4173762012-12-03 18:23:37 +01009145 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009146 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9147 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009148
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009149 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009150
Johannes Bergbc43b282009-07-25 10:54:13 +02009151 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009152 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009153 GFP_ATOMIC);
9154 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009155
9156 return;
9157
9158nla_put_failure:
9159 genlmsg_cancel(msg, hdr);
9160 nlmsg_free(msg);
9161}
9162
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009163static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9164 struct net_device *netdev,
9165 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009166 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009167{
9168 struct sk_buff *msg;
9169 void *hdr;
9170
Johannes Berge6d6e342009-07-01 21:26:47 +02009171 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009172 if (!msg)
9173 return;
9174
9175 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9176 if (!hdr) {
9177 nlmsg_free(msg);
9178 return;
9179 }
9180
David S. Miller9360ffd2012-03-29 04:41:26 -04009181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9182 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9183 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9184 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009185
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009186 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009187
Johannes Berg463d0182009-07-14 00:33:35 +02009188 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9189 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009190 return;
9191
9192 nla_put_failure:
9193 genlmsg_cancel(msg, hdr);
9194 nlmsg_free(msg);
9195}
9196
9197void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009198 struct net_device *netdev, const u8 *buf,
9199 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009200{
9201 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009202 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009203}
9204
9205void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9206 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009207 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009208{
Johannes Berge6d6e342009-07-01 21:26:47 +02009209 nl80211_send_mlme_event(rdev, netdev, buf, len,
9210 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009211}
9212
Jouni Malinen53b46b82009-03-27 20:53:56 +02009213void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009214 struct net_device *netdev, const u8 *buf,
9215 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009216{
9217 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009218 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009219}
9220
Jouni Malinen53b46b82009-03-27 20:53:56 +02009221void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9222 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009223 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009224{
9225 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009226 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009227}
9228
Johannes Berg947add32013-02-22 22:05:20 +01009229void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9230 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009231{
Johannes Berg947add32013-02-22 22:05:20 +01009232 struct wireless_dev *wdev = dev->ieee80211_ptr;
9233 struct wiphy *wiphy = wdev->wiphy;
9234 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009235
Johannes Berg947add32013-02-22 22:05:20 +01009236 trace_cfg80211_send_unprot_deauth(dev);
9237 nl80211_send_mlme_event(rdev, dev, buf, len,
9238 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009239}
Johannes Berg947add32013-02-22 22:05:20 +01009240EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9241
9242void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9243 size_t len)
9244{
9245 struct wireless_dev *wdev = dev->ieee80211_ptr;
9246 struct wiphy *wiphy = wdev->wiphy;
9247 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9248
9249 trace_cfg80211_send_unprot_disassoc(dev);
9250 nl80211_send_mlme_event(rdev, dev, buf, len,
9251 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9252}
9253EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009254
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009255static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9256 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009257 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009258{
9259 struct sk_buff *msg;
9260 void *hdr;
9261
Johannes Berge6d6e342009-07-01 21:26:47 +02009262 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009263 if (!msg)
9264 return;
9265
9266 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9267 if (!hdr) {
9268 nlmsg_free(msg);
9269 return;
9270 }
9271
David S. Miller9360ffd2012-03-29 04:41:26 -04009272 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9273 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9274 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9275 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9276 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009277
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009278 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009279
Johannes Berg463d0182009-07-14 00:33:35 +02009280 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9281 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009282 return;
9283
9284 nla_put_failure:
9285 genlmsg_cancel(msg, hdr);
9286 nlmsg_free(msg);
9287}
9288
9289void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009290 struct net_device *netdev, const u8 *addr,
9291 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009292{
9293 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009294 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009295}
9296
9297void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009298 struct net_device *netdev, const u8 *addr,
9299 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009300{
Johannes Berge6d6e342009-07-01 21:26:47 +02009301 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9302 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009303}
9304
Samuel Ortizb23aa672009-07-01 21:26:54 +02009305void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9306 struct net_device *netdev, const u8 *bssid,
9307 const u8 *req_ie, size_t req_ie_len,
9308 const u8 *resp_ie, size_t resp_ie_len,
9309 u16 status, gfp_t gfp)
9310{
9311 struct sk_buff *msg;
9312 void *hdr;
9313
Thomas Graf58050fc2012-06-28 03:57:45 +00009314 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009315 if (!msg)
9316 return;
9317
9318 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9319 if (!hdr) {
9320 nlmsg_free(msg);
9321 return;
9322 }
9323
David S. Miller9360ffd2012-03-29 04:41:26 -04009324 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9325 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9326 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9327 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9328 (req_ie &&
9329 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9330 (resp_ie &&
9331 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9332 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009333
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009334 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009335
Johannes Berg463d0182009-07-14 00:33:35 +02009336 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9337 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009338 return;
9339
9340 nla_put_failure:
9341 genlmsg_cancel(msg, hdr);
9342 nlmsg_free(msg);
9343
9344}
9345
9346void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9347 struct net_device *netdev, const u8 *bssid,
9348 const u8 *req_ie, size_t req_ie_len,
9349 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9350{
9351 struct sk_buff *msg;
9352 void *hdr;
9353
Thomas Graf58050fc2012-06-28 03:57:45 +00009354 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009355 if (!msg)
9356 return;
9357
9358 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9359 if (!hdr) {
9360 nlmsg_free(msg);
9361 return;
9362 }
9363
David S. Miller9360ffd2012-03-29 04:41:26 -04009364 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9365 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9366 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9367 (req_ie &&
9368 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9369 (resp_ie &&
9370 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9371 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009372
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009373 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009374
Johannes Berg463d0182009-07-14 00:33:35 +02009375 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9376 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009377 return;
9378
9379 nla_put_failure:
9380 genlmsg_cancel(msg, hdr);
9381 nlmsg_free(msg);
9382
9383}
9384
9385void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9386 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009387 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009388{
9389 struct sk_buff *msg;
9390 void *hdr;
9391
Thomas Graf58050fc2012-06-28 03:57:45 +00009392 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009393 if (!msg)
9394 return;
9395
9396 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9397 if (!hdr) {
9398 nlmsg_free(msg);
9399 return;
9400 }
9401
David S. Miller9360ffd2012-03-29 04:41:26 -04009402 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9403 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9404 (from_ap && reason &&
9405 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9406 (from_ap &&
9407 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9408 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9409 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009410
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009411 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009412
Johannes Berg463d0182009-07-14 00:33:35 +02009413 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9414 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009415 return;
9416
9417 nla_put_failure:
9418 genlmsg_cancel(msg, hdr);
9419 nlmsg_free(msg);
9420
9421}
9422
Johannes Berg04a773a2009-04-19 21:24:32 +02009423void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9424 struct net_device *netdev, const u8 *bssid,
9425 gfp_t gfp)
9426{
9427 struct sk_buff *msg;
9428 void *hdr;
9429
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009431 if (!msg)
9432 return;
9433
9434 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9435 if (!hdr) {
9436 nlmsg_free(msg);
9437 return;
9438 }
9439
David S. Miller9360ffd2012-03-29 04:41:26 -04009440 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9441 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9442 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9443 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009444
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009445 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009446
Johannes Berg463d0182009-07-14 00:33:35 +02009447 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9448 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009449 return;
9450
9451 nla_put_failure:
9452 genlmsg_cancel(msg, hdr);
9453 nlmsg_free(msg);
9454}
9455
Johannes Berg947add32013-02-22 22:05:20 +01009456void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9457 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009458{
Johannes Berg947add32013-02-22 22:05:20 +01009459 struct wireless_dev *wdev = dev->ieee80211_ptr;
9460 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009461 struct sk_buff *msg;
9462 void *hdr;
9463
Johannes Berg947add32013-02-22 22:05:20 +01009464 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9465 return;
9466
9467 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9468
Javier Cardonac93b5e72011-04-07 15:08:34 -07009469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9470 if (!msg)
9471 return;
9472
9473 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9474 if (!hdr) {
9475 nlmsg_free(msg);
9476 return;
9477 }
9478
David S. Miller9360ffd2012-03-29 04:41:26 -04009479 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009480 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9481 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009482 (ie_len && ie &&
9483 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9484 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009485
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009486 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009487
9488 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9489 nl80211_mlme_mcgrp.id, gfp);
9490 return;
9491
9492 nla_put_failure:
9493 genlmsg_cancel(msg, hdr);
9494 nlmsg_free(msg);
9495}
Johannes Berg947add32013-02-22 22:05:20 +01009496EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009497
Jouni Malinena3b8b052009-03-27 21:59:49 +02009498void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9499 struct net_device *netdev, const u8 *addr,
9500 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009501 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009502{
9503 struct sk_buff *msg;
9504 void *hdr;
9505
Johannes Berge6d6e342009-07-01 21:26:47 +02009506 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009507 if (!msg)
9508 return;
9509
9510 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9511 if (!hdr) {
9512 nlmsg_free(msg);
9513 return;
9514 }
9515
David S. Miller9360ffd2012-03-29 04:41:26 -04009516 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9517 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9518 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9519 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9520 (key_id != -1 &&
9521 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9522 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9523 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009524
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009525 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009526
Johannes Berg463d0182009-07-14 00:33:35 +02009527 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9528 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009529 return;
9530
9531 nla_put_failure:
9532 genlmsg_cancel(msg, hdr);
9533 nlmsg_free(msg);
9534}
9535
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009536void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9537 struct ieee80211_channel *channel_before,
9538 struct ieee80211_channel *channel_after)
9539{
9540 struct sk_buff *msg;
9541 void *hdr;
9542 struct nlattr *nl_freq;
9543
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009544 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009545 if (!msg)
9546 return;
9547
9548 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9549 if (!hdr) {
9550 nlmsg_free(msg);
9551 return;
9552 }
9553
9554 /*
9555 * Since we are applying the beacon hint to a wiphy we know its
9556 * wiphy_idx is valid
9557 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009558 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9559 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009560
9561 /* Before */
9562 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9563 if (!nl_freq)
9564 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009565 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009566 goto nla_put_failure;
9567 nla_nest_end(msg, nl_freq);
9568
9569 /* After */
9570 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9571 if (!nl_freq)
9572 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009573 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009574 goto nla_put_failure;
9575 nla_nest_end(msg, nl_freq);
9576
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009577 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009578
Johannes Berg463d0182009-07-14 00:33:35 +02009579 rcu_read_lock();
9580 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9581 GFP_ATOMIC);
9582 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009583
9584 return;
9585
9586nla_put_failure:
9587 genlmsg_cancel(msg, hdr);
9588 nlmsg_free(msg);
9589}
9590
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009591static void nl80211_send_remain_on_chan_event(
9592 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009593 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009594 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009595 unsigned int duration, gfp_t gfp)
9596{
9597 struct sk_buff *msg;
9598 void *hdr;
9599
9600 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9601 if (!msg)
9602 return;
9603
9604 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9605 if (!hdr) {
9606 nlmsg_free(msg);
9607 return;
9608 }
9609
David S. Miller9360ffd2012-03-29 04:41:26 -04009610 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009611 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9612 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009613 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009614 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009615 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9616 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009617 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9618 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009619
David S. Miller9360ffd2012-03-29 04:41:26 -04009620 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9621 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9622 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009623
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009624 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009625
9626 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9627 nl80211_mlme_mcgrp.id, gfp);
9628 return;
9629
9630 nla_put_failure:
9631 genlmsg_cancel(msg, hdr);
9632 nlmsg_free(msg);
9633}
9634
Johannes Berg947add32013-02-22 22:05:20 +01009635void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9636 struct ieee80211_channel *chan,
9637 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009638{
Johannes Berg947add32013-02-22 22:05:20 +01009639 struct wiphy *wiphy = wdev->wiphy;
9640 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9641
9642 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009643 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009644 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009645 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009646}
Johannes Berg947add32013-02-22 22:05:20 +01009647EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009648
Johannes Berg947add32013-02-22 22:05:20 +01009649void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9650 struct ieee80211_channel *chan,
9651 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009652{
Johannes Berg947add32013-02-22 22:05:20 +01009653 struct wiphy *wiphy = wdev->wiphy;
9654 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9655
9656 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009657 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009658 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009659}
Johannes Berg947add32013-02-22 22:05:20 +01009660EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009661
Johannes Berg947add32013-02-22 22:05:20 +01009662void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9663 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009664{
Johannes Berg947add32013-02-22 22:05:20 +01009665 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9666 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009667 struct sk_buff *msg;
9668
Johannes Berg947add32013-02-22 22:05:20 +01009669 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9670
Thomas Graf58050fc2012-06-28 03:57:45 +00009671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009672 if (!msg)
9673 return;
9674
John W. Linville66266b32012-03-15 13:25:41 -04009675 if (nl80211_send_station(msg, 0, 0, 0,
9676 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009677 nlmsg_free(msg);
9678 return;
9679 }
9680
9681 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9682 nl80211_mlme_mcgrp.id, gfp);
9683}
Johannes Berg947add32013-02-22 22:05:20 +01009684EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009685
Johannes Berg947add32013-02-22 22:05:20 +01009686void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009687{
Johannes Berg947add32013-02-22 22:05:20 +01009688 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9689 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009690 struct sk_buff *msg;
9691 void *hdr;
9692
Johannes Berg947add32013-02-22 22:05:20 +01009693 trace_cfg80211_del_sta(dev, mac_addr);
9694
Thomas Graf58050fc2012-06-28 03:57:45 +00009695 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009696 if (!msg)
9697 return;
9698
9699 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9700 if (!hdr) {
9701 nlmsg_free(msg);
9702 return;
9703 }
9704
David S. Miller9360ffd2012-03-29 04:41:26 -04009705 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9706 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9707 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009708
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009709 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009710
9711 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9712 nl80211_mlme_mcgrp.id, gfp);
9713 return;
9714
9715 nla_put_failure:
9716 genlmsg_cancel(msg, hdr);
9717 nlmsg_free(msg);
9718}
Johannes Berg947add32013-02-22 22:05:20 +01009719EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009720
Johannes Berg947add32013-02-22 22:05:20 +01009721void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9722 enum nl80211_connect_failed_reason reason,
9723 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309724{
Johannes Berg947add32013-02-22 22:05:20 +01009725 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9726 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309727 struct sk_buff *msg;
9728 void *hdr;
9729
9730 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9731 if (!msg)
9732 return;
9733
9734 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9735 if (!hdr) {
9736 nlmsg_free(msg);
9737 return;
9738 }
9739
9740 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9741 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9742 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9743 goto nla_put_failure;
9744
9745 genlmsg_end(msg, hdr);
9746
9747 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9748 nl80211_mlme_mcgrp.id, gfp);
9749 return;
9750
9751 nla_put_failure:
9752 genlmsg_cancel(msg, hdr);
9753 nlmsg_free(msg);
9754}
Johannes Berg947add32013-02-22 22:05:20 +01009755EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309756
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009757static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9758 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009759{
9760 struct wireless_dev *wdev = dev->ieee80211_ptr;
9761 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9762 struct sk_buff *msg;
9763 void *hdr;
9764 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009765 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009766
Eric W. Biederman15e47302012-09-07 20:12:54 +00009767 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009768 return false;
9769
9770 msg = nlmsg_new(100, gfp);
9771 if (!msg)
9772 return true;
9773
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009774 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009775 if (!hdr) {
9776 nlmsg_free(msg);
9777 return true;
9778 }
9779
David S. Miller9360ffd2012-03-29 04:41:26 -04009780 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9781 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9782 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9783 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009784
9785 err = genlmsg_end(msg, hdr);
9786 if (err < 0) {
9787 nlmsg_free(msg);
9788 return true;
9789 }
9790
Eric W. Biederman15e47302012-09-07 20:12:54 +00009791 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009792 return true;
9793
9794 nla_put_failure:
9795 genlmsg_cancel(msg, hdr);
9796 nlmsg_free(msg);
9797 return true;
9798}
9799
Johannes Berg947add32013-02-22 22:05:20 +01009800bool cfg80211_rx_spurious_frame(struct net_device *dev,
9801 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009802{
Johannes Berg947add32013-02-22 22:05:20 +01009803 struct wireless_dev *wdev = dev->ieee80211_ptr;
9804 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009805
Johannes Berg947add32013-02-22 22:05:20 +01009806 trace_cfg80211_rx_spurious_frame(dev, addr);
9807
9808 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9809 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9810 trace_cfg80211_return_bool(false);
9811 return false;
9812 }
9813 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9814 addr, gfp);
9815 trace_cfg80211_return_bool(ret);
9816 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009817}
Johannes Berg947add32013-02-22 22:05:20 +01009818EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9819
9820bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9821 const u8 *addr, gfp_t gfp)
9822{
9823 struct wireless_dev *wdev = dev->ieee80211_ptr;
9824 bool ret;
9825
9826 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9827
9828 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9829 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9830 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9831 trace_cfg80211_return_bool(false);
9832 return false;
9833 }
9834 ret = __nl80211_unexpected_frame(dev,
9835 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9836 addr, gfp);
9837 trace_cfg80211_return_bool(ret);
9838 return ret;
9839}
9840EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009841
Johannes Berg2e161f72010-08-12 15:38:38 +02009842int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009843 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009844 int freq, int sig_dbm,
9845 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009846{
Johannes Berg71bbc992012-06-15 15:30:18 +02009847 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009848 struct sk_buff *msg;
9849 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009850
9851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9852 if (!msg)
9853 return -ENOMEM;
9854
Johannes Berg2e161f72010-08-12 15:38:38 +02009855 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009856 if (!hdr) {
9857 nlmsg_free(msg);
9858 return -ENOMEM;
9859 }
9860
David S. Miller9360ffd2012-03-29 04:41:26 -04009861 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009862 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9863 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009864 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9865 (sig_dbm &&
9866 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9867 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9868 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009869
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009870 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009871
Eric W. Biederman15e47302012-09-07 20:12:54 +00009872 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009873
9874 nla_put_failure:
9875 genlmsg_cancel(msg, hdr);
9876 nlmsg_free(msg);
9877 return -ENOBUFS;
9878}
9879
Johannes Berg947add32013-02-22 22:05:20 +01009880void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9881 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009882{
Johannes Berg947add32013-02-22 22:05:20 +01009883 struct wiphy *wiphy = wdev->wiphy;
9884 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009885 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009886 struct sk_buff *msg;
9887 void *hdr;
9888
Johannes Berg947add32013-02-22 22:05:20 +01009889 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9890
Jouni Malinen026331c2010-02-15 12:53:10 +02009891 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9892 if (!msg)
9893 return;
9894
Johannes Berg2e161f72010-08-12 15:38:38 +02009895 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009896 if (!hdr) {
9897 nlmsg_free(msg);
9898 return;
9899 }
9900
David S. Miller9360ffd2012-03-29 04:41:26 -04009901 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009902 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9903 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009904 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9905 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9906 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9907 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009908
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009909 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009910
9911 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9912 return;
9913
9914 nla_put_failure:
9915 genlmsg_cancel(msg, hdr);
9916 nlmsg_free(msg);
9917}
Johannes Berg947add32013-02-22 22:05:20 +01009918EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009919
Johannes Berg947add32013-02-22 22:05:20 +01009920void cfg80211_cqm_rssi_notify(struct net_device *dev,
9921 enum nl80211_cqm_rssi_threshold_event rssi_event,
9922 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009923{
Johannes Berg947add32013-02-22 22:05:20 +01009924 struct wireless_dev *wdev = dev->ieee80211_ptr;
9925 struct wiphy *wiphy = wdev->wiphy;
9926 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009927 struct sk_buff *msg;
9928 struct nlattr *pinfoattr;
9929 void *hdr;
9930
Johannes Berg947add32013-02-22 22:05:20 +01009931 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
9932
Thomas Graf58050fc2012-06-28 03:57:45 +00009933 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009934 if (!msg)
9935 return;
9936
9937 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9938 if (!hdr) {
9939 nlmsg_free(msg);
9940 return;
9941 }
9942
David S. Miller9360ffd2012-03-29 04:41:26 -04009943 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009944 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -04009945 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009946
9947 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9948 if (!pinfoattr)
9949 goto nla_put_failure;
9950
David S. Miller9360ffd2012-03-29 04:41:26 -04009951 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9952 rssi_event))
9953 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009954
9955 nla_nest_end(msg, pinfoattr);
9956
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009957 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009958
9959 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9960 nl80211_mlme_mcgrp.id, gfp);
9961 return;
9962
9963 nla_put_failure:
9964 genlmsg_cancel(msg, hdr);
9965 nlmsg_free(msg);
9966}
Johannes Berg947add32013-02-22 22:05:20 +01009967EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009968
Johannes Berg947add32013-02-22 22:05:20 +01009969static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9970 struct net_device *netdev, const u8 *bssid,
9971 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +02009972{
9973 struct sk_buff *msg;
9974 struct nlattr *rekey_attr;
9975 void *hdr;
9976
Thomas Graf58050fc2012-06-28 03:57:45 +00009977 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009978 if (!msg)
9979 return;
9980
9981 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9982 if (!hdr) {
9983 nlmsg_free(msg);
9984 return;
9985 }
9986
David S. Miller9360ffd2012-03-29 04:41:26 -04009987 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9988 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9989 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9990 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009991
9992 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9993 if (!rekey_attr)
9994 goto nla_put_failure;
9995
David S. Miller9360ffd2012-03-29 04:41:26 -04009996 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9997 NL80211_REPLAY_CTR_LEN, replay_ctr))
9998 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009999
10000 nla_nest_end(msg, rekey_attr);
10001
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010002 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010003
10004 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10005 nl80211_mlme_mcgrp.id, gfp);
10006 return;
10007
10008 nla_put_failure:
10009 genlmsg_cancel(msg, hdr);
10010 nlmsg_free(msg);
10011}
10012
Johannes Berg947add32013-02-22 22:05:20 +010010013void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10014 const u8 *replay_ctr, gfp_t gfp)
10015{
10016 struct wireless_dev *wdev = dev->ieee80211_ptr;
10017 struct wiphy *wiphy = wdev->wiphy;
10018 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10019
10020 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10021 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10022}
10023EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10024
10025static void
10026nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10027 struct net_device *netdev, int index,
10028 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010029{
10030 struct sk_buff *msg;
10031 struct nlattr *attr;
10032 void *hdr;
10033
Thomas Graf58050fc2012-06-28 03:57:45 +000010034 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010035 if (!msg)
10036 return;
10037
10038 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10039 if (!hdr) {
10040 nlmsg_free(msg);
10041 return;
10042 }
10043
David S. Miller9360ffd2012-03-29 04:41:26 -040010044 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10045 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10046 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010047
10048 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10049 if (!attr)
10050 goto nla_put_failure;
10051
David S. Miller9360ffd2012-03-29 04:41:26 -040010052 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10053 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10054 (preauth &&
10055 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10056 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010057
10058 nla_nest_end(msg, attr);
10059
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010060 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010061
10062 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10063 nl80211_mlme_mcgrp.id, gfp);
10064 return;
10065
10066 nla_put_failure:
10067 genlmsg_cancel(msg, hdr);
10068 nlmsg_free(msg);
10069}
10070
Johannes Berg947add32013-02-22 22:05:20 +010010071void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10072 const u8 *bssid, bool preauth, gfp_t gfp)
10073{
10074 struct wireless_dev *wdev = dev->ieee80211_ptr;
10075 struct wiphy *wiphy = wdev->wiphy;
10076 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10077
10078 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10079 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10080}
10081EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10082
10083static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10084 struct net_device *netdev,
10085 struct cfg80211_chan_def *chandef,
10086 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010087{
10088 struct sk_buff *msg;
10089 void *hdr;
10090
Thomas Graf58050fc2012-06-28 03:57:45 +000010091 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010092 if (!msg)
10093 return;
10094
10095 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10096 if (!hdr) {
10097 nlmsg_free(msg);
10098 return;
10099 }
10100
Johannes Berg683b6d32012-11-08 21:25:48 +010010101 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10102 goto nla_put_failure;
10103
10104 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010105 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010106
10107 genlmsg_end(msg, hdr);
10108
10109 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10110 nl80211_mlme_mcgrp.id, gfp);
10111 return;
10112
10113 nla_put_failure:
10114 genlmsg_cancel(msg, hdr);
10115 nlmsg_free(msg);
10116}
10117
Johannes Berg947add32013-02-22 22:05:20 +010010118void cfg80211_ch_switch_notify(struct net_device *dev,
10119 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010120{
Johannes Berg947add32013-02-22 22:05:20 +010010121 struct wireless_dev *wdev = dev->ieee80211_ptr;
10122 struct wiphy *wiphy = wdev->wiphy;
10123 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10124
10125 trace_cfg80211_ch_switch_notify(dev, chandef);
10126
10127 wdev_lock(wdev);
10128
10129 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10130 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10131 goto out;
10132
10133 wdev->channel = chandef->chan;
10134 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10135out:
10136 wdev_unlock(wdev);
10137 return;
10138}
10139EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10140
10141void cfg80211_cqm_txe_notify(struct net_device *dev,
10142 const u8 *peer, u32 num_packets,
10143 u32 rate, u32 intvl, gfp_t gfp)
10144{
10145 struct wireless_dev *wdev = dev->ieee80211_ptr;
10146 struct wiphy *wiphy = wdev->wiphy;
10147 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010148 struct sk_buff *msg;
10149 struct nlattr *pinfoattr;
10150 void *hdr;
10151
10152 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10153 if (!msg)
10154 return;
10155
10156 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10157 if (!hdr) {
10158 nlmsg_free(msg);
10159 return;
10160 }
10161
10162 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010163 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010164 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10165 goto nla_put_failure;
10166
10167 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10168 if (!pinfoattr)
10169 goto nla_put_failure;
10170
10171 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10172 goto nla_put_failure;
10173
10174 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10175 goto nla_put_failure;
10176
10177 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10178 goto nla_put_failure;
10179
10180 nla_nest_end(msg, pinfoattr);
10181
10182 genlmsg_end(msg, hdr);
10183
10184 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10185 nl80211_mlme_mcgrp.id, gfp);
10186 return;
10187
10188 nla_put_failure:
10189 genlmsg_cancel(msg, hdr);
10190 nlmsg_free(msg);
10191}
Johannes Berg947add32013-02-22 22:05:20 +010010192EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010193
10194void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010195nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10196 struct cfg80211_chan_def *chandef,
10197 enum nl80211_radar_event event,
10198 struct net_device *netdev, gfp_t gfp)
10199{
10200 struct sk_buff *msg;
10201 void *hdr;
10202
10203 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10204 if (!msg)
10205 return;
10206
10207 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10208 if (!hdr) {
10209 nlmsg_free(msg);
10210 return;
10211 }
10212
10213 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10214 goto nla_put_failure;
10215
10216 /* NOP and radar events don't need a netdev parameter */
10217 if (netdev) {
10218 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10219
10220 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10221 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10222 goto nla_put_failure;
10223 }
10224
10225 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10226 goto nla_put_failure;
10227
10228 if (nl80211_send_chandef(msg, chandef))
10229 goto nla_put_failure;
10230
10231 if (genlmsg_end(msg, hdr) < 0) {
10232 nlmsg_free(msg);
10233 return;
10234 }
10235
10236 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10237 nl80211_mlme_mcgrp.id, gfp);
10238 return;
10239
10240 nla_put_failure:
10241 genlmsg_cancel(msg, hdr);
10242 nlmsg_free(msg);
10243}
10244
Johannes Berg947add32013-02-22 22:05:20 +010010245void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10246 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010247{
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 Bergc063dbf2010-11-24 08:10:05 +010010251 struct sk_buff *msg;
10252 struct nlattr *pinfoattr;
10253 void *hdr;
10254
Johannes Berg947add32013-02-22 22:05:20 +010010255 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10256
Thomas Graf58050fc2012-06-28 03:57:45 +000010257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010258 if (!msg)
10259 return;
10260
10261 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10262 if (!hdr) {
10263 nlmsg_free(msg);
10264 return;
10265 }
10266
David S. Miller9360ffd2012-03-29 04:41:26 -040010267 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010268 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010269 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10270 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010271
10272 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10273 if (!pinfoattr)
10274 goto nla_put_failure;
10275
David S. Miller9360ffd2012-03-29 04:41:26 -040010276 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10277 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010278
10279 nla_nest_end(msg, pinfoattr);
10280
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010281 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010282
10283 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10284 nl80211_mlme_mcgrp.id, gfp);
10285 return;
10286
10287 nla_put_failure:
10288 genlmsg_cancel(msg, hdr);
10289 nlmsg_free(msg);
10290}
Johannes Berg947add32013-02-22 22:05:20 +010010291EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010292
Johannes Berg7f6cf312011-11-04 11:18:15 +010010293void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10294 u64 cookie, bool acked, gfp_t gfp)
10295{
10296 struct wireless_dev *wdev = dev->ieee80211_ptr;
10297 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10298 struct sk_buff *msg;
10299 void *hdr;
10300 int err;
10301
Beni Lev4ee3e062012-08-27 12:49:39 +030010302 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10303
Thomas Graf58050fc2012-06-28 03:57:45 +000010304 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010305
Johannes Berg7f6cf312011-11-04 11:18:15 +010010306 if (!msg)
10307 return;
10308
10309 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10310 if (!hdr) {
10311 nlmsg_free(msg);
10312 return;
10313 }
10314
David S. Miller9360ffd2012-03-29 04:41:26 -040010315 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10316 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10317 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10318 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10319 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10320 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010321
10322 err = genlmsg_end(msg, hdr);
10323 if (err < 0) {
10324 nlmsg_free(msg);
10325 return;
10326 }
10327
10328 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10329 nl80211_mlme_mcgrp.id, gfp);
10330 return;
10331
10332 nla_put_failure:
10333 genlmsg_cancel(msg, hdr);
10334 nlmsg_free(msg);
10335}
10336EXPORT_SYMBOL(cfg80211_probe_status);
10337
Johannes Berg5e760232011-11-04 11:18:17 +010010338void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10339 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010340 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010341{
10342 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10343 struct sk_buff *msg;
10344 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010345 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010346
Beni Lev4ee3e062012-08-27 12:49:39 +030010347 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10348
Ben Greear37c73b52012-10-26 14:49:25 -070010349 spin_lock_bh(&rdev->beacon_registrations_lock);
10350 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10351 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10352 if (!msg) {
10353 spin_unlock_bh(&rdev->beacon_registrations_lock);
10354 return;
10355 }
Johannes Berg5e760232011-11-04 11:18:17 +010010356
Ben Greear37c73b52012-10-26 14:49:25 -070010357 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10358 if (!hdr)
10359 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010360
Ben Greear37c73b52012-10-26 14:49:25 -070010361 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10362 (freq &&
10363 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10364 (sig_dbm &&
10365 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10366 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10367 goto nla_put_failure;
10368
10369 genlmsg_end(msg, hdr);
10370
10371 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010372 }
Ben Greear37c73b52012-10-26 14:49:25 -070010373 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010374 return;
10375
10376 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010377 spin_unlock_bh(&rdev->beacon_registrations_lock);
10378 if (hdr)
10379 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010380 nlmsg_free(msg);
10381}
10382EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10383
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010384#ifdef CONFIG_PM
10385void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10386 struct cfg80211_wowlan_wakeup *wakeup,
10387 gfp_t gfp)
10388{
10389 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10390 struct sk_buff *msg;
10391 void *hdr;
10392 int err, size = 200;
10393
10394 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10395
10396 if (wakeup)
10397 size += wakeup->packet_present_len;
10398
10399 msg = nlmsg_new(size, gfp);
10400 if (!msg)
10401 return;
10402
10403 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10404 if (!hdr)
10405 goto free_msg;
10406
10407 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10408 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10409 goto free_msg;
10410
10411 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10412 wdev->netdev->ifindex))
10413 goto free_msg;
10414
10415 if (wakeup) {
10416 struct nlattr *reasons;
10417
10418 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10419
10420 if (wakeup->disconnect &&
10421 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10422 goto free_msg;
10423 if (wakeup->magic_pkt &&
10424 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10425 goto free_msg;
10426 if (wakeup->gtk_rekey_failure &&
10427 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10428 goto free_msg;
10429 if (wakeup->eap_identity_req &&
10430 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10431 goto free_msg;
10432 if (wakeup->four_way_handshake &&
10433 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10434 goto free_msg;
10435 if (wakeup->rfkill_release &&
10436 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10437 goto free_msg;
10438
10439 if (wakeup->pattern_idx >= 0 &&
10440 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10441 wakeup->pattern_idx))
10442 goto free_msg;
10443
Johannes Berg2a0e0472013-01-23 22:57:40 +010010444 if (wakeup->tcp_match)
10445 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10446
10447 if (wakeup->tcp_connlost)
10448 nla_put_flag(msg,
10449 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10450
10451 if (wakeup->tcp_nomoretokens)
10452 nla_put_flag(msg,
10453 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10454
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010455 if (wakeup->packet) {
10456 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10457 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10458
10459 if (!wakeup->packet_80211) {
10460 pkt_attr =
10461 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10462 len_attr =
10463 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10464 }
10465
10466 if (wakeup->packet_len &&
10467 nla_put_u32(msg, len_attr, wakeup->packet_len))
10468 goto free_msg;
10469
10470 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10471 wakeup->packet))
10472 goto free_msg;
10473 }
10474
10475 nla_nest_end(msg, reasons);
10476 }
10477
10478 err = genlmsg_end(msg, hdr);
10479 if (err < 0)
10480 goto free_msg;
10481
10482 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10483 nl80211_mlme_mcgrp.id, gfp);
10484 return;
10485
10486 free_msg:
10487 nlmsg_free(msg);
10488}
10489EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10490#endif
10491
Jouni Malinen3475b092012-11-16 22:49:57 +020010492void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10493 enum nl80211_tdls_operation oper,
10494 u16 reason_code, gfp_t gfp)
10495{
10496 struct wireless_dev *wdev = dev->ieee80211_ptr;
10497 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10498 struct sk_buff *msg;
10499 void *hdr;
10500 int err;
10501
10502 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10503 reason_code);
10504
10505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10506 if (!msg)
10507 return;
10508
10509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10510 if (!hdr) {
10511 nlmsg_free(msg);
10512 return;
10513 }
10514
10515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10517 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10518 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10519 (reason_code > 0 &&
10520 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10521 goto nla_put_failure;
10522
10523 err = genlmsg_end(msg, hdr);
10524 if (err < 0) {
10525 nlmsg_free(msg);
10526 return;
10527 }
10528
10529 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10530 nl80211_mlme_mcgrp.id, gfp);
10531 return;
10532
10533 nla_put_failure:
10534 genlmsg_cancel(msg, hdr);
10535 nlmsg_free(msg);
10536}
10537EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10538
Jouni Malinen026331c2010-02-15 12:53:10 +020010539static int nl80211_netlink_notify(struct notifier_block * nb,
10540 unsigned long state,
10541 void *_notify)
10542{
10543 struct netlink_notify *notify = _notify;
10544 struct cfg80211_registered_device *rdev;
10545 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010546 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010547
10548 if (state != NETLINK_URELEASE)
10549 return NOTIFY_DONE;
10550
10551 rcu_read_lock();
10552
Johannes Berg5e760232011-11-04 11:18:17 +010010553 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010554 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010555 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010556
10557 spin_lock_bh(&rdev->beacon_registrations_lock);
10558 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10559 list) {
10560 if (reg->nlportid == notify->portid) {
10561 list_del(&reg->list);
10562 kfree(reg);
10563 break;
10564 }
10565 }
10566 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010567 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010568
10569 rcu_read_unlock();
10570
10571 return NOTIFY_DONE;
10572}
10573
10574static struct notifier_block nl80211_netlink_notifier = {
10575 .notifier_call = nl80211_netlink_notify,
10576};
10577
Jouni Malinen355199e2013-02-27 17:14:27 +020010578void cfg80211_ft_event(struct net_device *netdev,
10579 struct cfg80211_ft_event_params *ft_event)
10580{
10581 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10582 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10583 struct sk_buff *msg;
10584 void *hdr;
10585 int err;
10586
10587 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10588
10589 if (!ft_event->target_ap)
10590 return;
10591
10592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10593 if (!msg)
10594 return;
10595
10596 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10597 if (!hdr) {
10598 nlmsg_free(msg);
10599 return;
10600 }
10601
10602 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10603 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10604 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10605 if (ft_event->ies)
10606 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10607 if (ft_event->ric_ies)
10608 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10609 ft_event->ric_ies);
10610
10611 err = genlmsg_end(msg, hdr);
10612 if (err < 0) {
10613 nlmsg_free(msg);
10614 return;
10615 }
10616
10617 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10618 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10619}
10620EXPORT_SYMBOL(cfg80211_ft_event);
10621
Johannes Berg55682962007-09-20 13:09:35 -040010622/* initialisation/exit functions */
10623
10624int nl80211_init(void)
10625{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010626 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010627
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010628 err = genl_register_family_with_ops(&nl80211_fam,
10629 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010630 if (err)
10631 return err;
10632
Johannes Berg55682962007-09-20 13:09:35 -040010633 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10634 if (err)
10635 goto err_out;
10636
Johannes Berg2a519312009-02-10 21:25:55 +010010637 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10638 if (err)
10639 goto err_out;
10640
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010641 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10642 if (err)
10643 goto err_out;
10644
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010645 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10646 if (err)
10647 goto err_out;
10648
Johannes Bergaff89a92009-07-01 21:26:51 +020010649#ifdef CONFIG_NL80211_TESTMODE
10650 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10651 if (err)
10652 goto err_out;
10653#endif
10654
Jouni Malinen026331c2010-02-15 12:53:10 +020010655 err = netlink_register_notifier(&nl80211_netlink_notifier);
10656 if (err)
10657 goto err_out;
10658
Johannes Berg55682962007-09-20 13:09:35 -040010659 return 0;
10660 err_out:
10661 genl_unregister_family(&nl80211_fam);
10662 return err;
10663}
10664
10665void nl80211_exit(void)
10666{
Jouni Malinen026331c2010-02-15 12:53:10 +020010667 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010668 genl_unregister_family(&nl80211_fam);
10669}