blob: a8bd453d22b946cb39e2f65a95996aa92a2a2180 [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 },
Johannes Berg55682962007-09-20 13:09:35 -0400378};
379
Johannes Berge31b8212010-10-05 19:39:30 +0200380/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000381static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200382 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200383 [NL80211_KEY_IDX] = { .type = NLA_U8 },
384 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200385 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200386 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
387 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200388 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100389 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
390};
391
392/* policy for the key default flags */
393static const struct nla_policy
394nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
395 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
396 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200397};
398
Johannes Bergff1b6e62011-05-04 15:37:28 +0200399/* policy for WoWLAN attributes */
400static const struct nla_policy
401nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
402 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
403 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
404 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
405 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb132011-07-13 10:48:55 +0200406 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
407 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
408 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
409 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100410 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
411};
412
413static const struct nla_policy
414nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
415 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
416 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
417 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
418 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
419 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
420 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
421 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
422 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
423 },
424 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
425 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
426 },
427 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
428 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
429 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200430};
431
Johannes Berge5497d72011-07-05 16:35:40 +0200432/* policy for GTK rekey offload attributes */
433static const struct nla_policy
434nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
435 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
436 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
437 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
438};
439
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300440static const struct nla_policy
441nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200442 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300443 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700444 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300445};
446
Holger Schuriga0438972009-11-11 11:30:02 +0100447/* ifidx get helper */
448static int nl80211_get_ifidx(struct netlink_callback *cb)
449{
450 int res;
451
452 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
453 nl80211_fam.attrbuf, nl80211_fam.maxattr,
454 nl80211_policy);
455 if (res)
456 return res;
457
458 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
459 return -EINVAL;
460
461 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
462 if (!res)
463 return -EINVAL;
464 return res;
465}
466
Johannes Berg67748892010-10-04 21:14:06 +0200467static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
468 struct netlink_callback *cb,
469 struct cfg80211_registered_device **rdev,
470 struct net_device **dev)
471{
472 int ifidx = cb->args[0];
473 int err;
474
475 if (!ifidx)
476 ifidx = nl80211_get_ifidx(cb);
477 if (ifidx < 0)
478 return ifidx;
479
480 cb->args[0] = ifidx;
481
482 rtnl_lock();
483
484 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
485 if (!*dev) {
486 err = -ENODEV;
487 goto out_rtnl;
488 }
489
490 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100491 if (IS_ERR(*rdev)) {
492 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200493 goto out_rtnl;
494 }
495
496 return 0;
497 out_rtnl:
498 rtnl_unlock();
499 return err;
500}
501
502static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
503{
504 cfg80211_unlock_rdev(rdev);
505 rtnl_unlock();
506}
507
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100508/* IE validation */
509static bool is_valid_ie_attr(const struct nlattr *attr)
510{
511 const u8 *pos;
512 int len;
513
514 if (!attr)
515 return true;
516
517 pos = nla_data(attr);
518 len = nla_len(attr);
519
520 while (len) {
521 u8 elemlen;
522
523 if (len < 2)
524 return false;
525 len -= 2;
526
527 elemlen = pos[1];
528 if (elemlen > len)
529 return false;
530
531 len -= elemlen;
532 pos += 2 + elemlen;
533 }
534
535 return true;
536}
537
Johannes Berg55682962007-09-20 13:09:35 -0400538/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000539static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400540 int flags, u8 cmd)
541{
542 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000543 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400544}
545
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400546static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100547 struct ieee80211_channel *chan,
548 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400549{
David S. Miller9360ffd2012-03-29 04:41:26 -0400550 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
551 chan->center_freq))
552 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400553
David S. Miller9360ffd2012-03-29 04:41:26 -0400554 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
555 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
556 goto nla_put_failure;
557 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
562 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100563 if (chan->flags & IEEE80211_CHAN_RADAR) {
564 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
565 goto nla_put_failure;
566 if (large) {
567 u32 time;
568
569 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
570
571 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
572 chan->dfs_state))
573 goto nla_put_failure;
574 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
575 time))
576 goto nla_put_failure;
577 }
578 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400579
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100580 if (large) {
581 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
582 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
583 goto nla_put_failure;
584 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
585 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
586 goto nla_put_failure;
587 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
588 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
589 goto nla_put_failure;
590 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
591 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
592 goto nla_put_failure;
593 }
594
David S. Miller9360ffd2012-03-29 04:41:26 -0400595 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
596 DBM_TO_MBM(chan->max_power)))
597 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400598
599 return 0;
600
601 nla_put_failure:
602 return -ENOBUFS;
603}
604
Johannes Berg55682962007-09-20 13:09:35 -0400605/* netlink command implementations */
606
Johannes Bergb9454e82009-07-08 13:29:08 +0200607struct key_parse {
608 struct key_params p;
609 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200610 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200611 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100612 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200613};
614
615static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
616{
617 struct nlattr *tb[NL80211_KEY_MAX + 1];
618 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
619 nl80211_key_policy);
620 if (err)
621 return err;
622
623 k->def = !!tb[NL80211_KEY_DEFAULT];
624 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
625
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100626 if (k->def) {
627 k->def_uni = true;
628 k->def_multi = true;
629 }
630 if (k->defmgmt)
631 k->def_multi = true;
632
Johannes Bergb9454e82009-07-08 13:29:08 +0200633 if (tb[NL80211_KEY_IDX])
634 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
635
636 if (tb[NL80211_KEY_DATA]) {
637 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
638 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
639 }
640
641 if (tb[NL80211_KEY_SEQ]) {
642 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
643 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
644 }
645
646 if (tb[NL80211_KEY_CIPHER])
647 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
648
Johannes Berge31b8212010-10-05 19:39:30 +0200649 if (tb[NL80211_KEY_TYPE]) {
650 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
651 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
652 return -EINVAL;
653 }
654
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100655 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
656 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100657 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
658 tb[NL80211_KEY_DEFAULT_TYPES],
659 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100660 if (err)
661 return err;
662
663 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
664 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
665 }
666
Johannes Bergb9454e82009-07-08 13:29:08 +0200667 return 0;
668}
669
670static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
671{
672 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
673 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
674 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
675 }
676
677 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
678 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
679 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
680 }
681
682 if (info->attrs[NL80211_ATTR_KEY_IDX])
683 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
684
685 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
686 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
687
688 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
689 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
690
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100691 if (k->def) {
692 k->def_uni = true;
693 k->def_multi = true;
694 }
695 if (k->defmgmt)
696 k->def_multi = true;
697
Johannes Berge31b8212010-10-05 19:39:30 +0200698 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
699 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
700 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
701 return -EINVAL;
702 }
703
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100704 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
705 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
706 int err = nla_parse_nested(
707 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
708 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
709 nl80211_key_default_policy);
710 if (err)
711 return err;
712
713 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
714 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
715 }
716
Johannes Bergb9454e82009-07-08 13:29:08 +0200717 return 0;
718}
719
720static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
721{
722 int err;
723
724 memset(k, 0, sizeof(*k));
725 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200726 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200727
728 if (info->attrs[NL80211_ATTR_KEY])
729 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
730 else
731 err = nl80211_parse_key_old(info, k);
732
733 if (err)
734 return err;
735
736 if (k->def && k->defmgmt)
737 return -EINVAL;
738
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100739 if (k->defmgmt) {
740 if (k->def_uni || !k->def_multi)
741 return -EINVAL;
742 }
743
Johannes Bergb9454e82009-07-08 13:29:08 +0200744 if (k->idx != -1) {
745 if (k->defmgmt) {
746 if (k->idx < 4 || k->idx > 5)
747 return -EINVAL;
748 } else if (k->def) {
749 if (k->idx < 0 || k->idx > 3)
750 return -EINVAL;
751 } else {
752 if (k->idx < 0 || k->idx > 5)
753 return -EINVAL;
754 }
755 }
756
757 return 0;
758}
759
Johannes Bergfffd0932009-07-08 14:22:54 +0200760static struct cfg80211_cached_keys *
761nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530762 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200763{
764 struct key_parse parse;
765 struct nlattr *key;
766 struct cfg80211_cached_keys *result;
767 int rem, err, def = 0;
768
769 result = kzalloc(sizeof(*result), GFP_KERNEL);
770 if (!result)
771 return ERR_PTR(-ENOMEM);
772
773 result->def = -1;
774 result->defmgmt = -1;
775
776 nla_for_each_nested(key, keys, rem) {
777 memset(&parse, 0, sizeof(parse));
778 parse.idx = -1;
779
780 err = nl80211_parse_key_new(key, &parse);
781 if (err)
782 goto error;
783 err = -EINVAL;
784 if (!parse.p.key)
785 goto error;
786 if (parse.idx < 0 || parse.idx > 4)
787 goto error;
788 if (parse.def) {
789 if (def)
790 goto error;
791 def = 1;
792 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100793 if (!parse.def_uni || !parse.def_multi)
794 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200795 } else if (parse.defmgmt)
796 goto error;
797 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200798 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200799 if (err)
800 goto error;
801 result->params[parse.idx].cipher = parse.p.cipher;
802 result->params[parse.idx].key_len = parse.p.key_len;
803 result->params[parse.idx].key = result->data[parse.idx];
804 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530805
806 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
807 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
808 if (no_ht)
809 *no_ht = true;
810 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200811 }
812
813 return result;
814 error:
815 kfree(result);
816 return ERR_PTR(err);
817}
818
819static int nl80211_key_allowed(struct wireless_dev *wdev)
820{
821 ASSERT_WDEV_LOCK(wdev);
822
Johannes Bergfffd0932009-07-08 14:22:54 +0200823 switch (wdev->iftype) {
824 case NL80211_IFTYPE_AP:
825 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200826 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700827 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200828 break;
829 case NL80211_IFTYPE_ADHOC:
830 if (!wdev->current_bss)
831 return -ENOLINK;
832 break;
833 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200834 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200835 if (wdev->sme_state != CFG80211_SME_CONNECTED)
836 return -ENOLINK;
837 break;
838 default:
839 return -EINVAL;
840 }
841
842 return 0;
843}
844
Johannes Berg7527a782011-05-13 10:58:57 +0200845static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
846{
847 struct nlattr *nl_modes = nla_nest_start(msg, attr);
848 int i;
849
850 if (!nl_modes)
851 goto nla_put_failure;
852
853 i = 0;
854 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400855 if ((ifmodes & 1) && nla_put_flag(msg, i))
856 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200857 ifmodes >>= 1;
858 i++;
859 }
860
861 nla_nest_end(msg, nl_modes);
862 return 0;
863
864nla_put_failure:
865 return -ENOBUFS;
866}
867
868static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100869 struct sk_buff *msg,
870 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200871{
872 struct nlattr *nl_combis;
873 int i, j;
874
875 nl_combis = nla_nest_start(msg,
876 NL80211_ATTR_INTERFACE_COMBINATIONS);
877 if (!nl_combis)
878 goto nla_put_failure;
879
880 for (i = 0; i < wiphy->n_iface_combinations; i++) {
881 const struct ieee80211_iface_combination *c;
882 struct nlattr *nl_combi, *nl_limits;
883
884 c = &wiphy->iface_combinations[i];
885
886 nl_combi = nla_nest_start(msg, i + 1);
887 if (!nl_combi)
888 goto nla_put_failure;
889
890 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
891 if (!nl_limits)
892 goto nla_put_failure;
893
894 for (j = 0; j < c->n_limits; j++) {
895 struct nlattr *nl_limit;
896
897 nl_limit = nla_nest_start(msg, j + 1);
898 if (!nl_limit)
899 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400900 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
901 c->limits[j].max))
902 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200903 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
904 c->limits[j].types))
905 goto nla_put_failure;
906 nla_nest_end(msg, nl_limit);
907 }
908
909 nla_nest_end(msg, nl_limits);
910
David S. Miller9360ffd2012-03-29 04:41:26 -0400911 if (c->beacon_int_infra_match &&
912 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
913 goto nla_put_failure;
914 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
915 c->num_different_channels) ||
916 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
917 c->max_interfaces))
918 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100919 if (large &&
920 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
921 c->radar_detect_widths))
922 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200923
924 nla_nest_end(msg, nl_combi);
925 }
926
927 nla_nest_end(msg, nl_combis);
928
929 return 0;
930nla_put_failure:
931 return -ENOBUFS;
932}
933
Johannes Berg3713b4e2013-02-14 16:19:38 +0100934#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100935static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
936 struct sk_buff *msg)
937{
938 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
939 struct nlattr *nl_tcp;
940
941 if (!tcp)
942 return 0;
943
944 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
945 if (!nl_tcp)
946 return -ENOBUFS;
947
948 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
949 tcp->data_payload_max))
950 return -ENOBUFS;
951
952 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
953 tcp->data_payload_max))
954 return -ENOBUFS;
955
956 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
957 return -ENOBUFS;
958
959 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
960 sizeof(*tcp->tok), tcp->tok))
961 return -ENOBUFS;
962
963 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
964 tcp->data_interval_max))
965 return -ENOBUFS;
966
967 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
968 tcp->wake_payload_max))
969 return -ENOBUFS;
970
971 nla_nest_end(msg, nl_tcp);
972 return 0;
973}
974
Johannes Berg3713b4e2013-02-14 16:19:38 +0100975static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100976 struct cfg80211_registered_device *dev,
977 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100978{
979 struct nlattr *nl_wowlan;
980
981 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
982 return 0;
983
984 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
985 if (!nl_wowlan)
986 return -ENOBUFS;
987
988 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
989 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
990 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
991 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
992 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
993 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
994 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
995 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
996 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
997 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
998 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
999 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1000 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1001 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1002 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1003 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1004 return -ENOBUFS;
1005
1006 if (dev->wiphy.wowlan.n_patterns) {
1007 struct nl80211_wowlan_pattern_support pat = {
1008 .max_patterns = dev->wiphy.wowlan.n_patterns,
1009 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
1010 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
1011 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
1012 };
1013
1014 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1015 sizeof(pat), &pat))
1016 return -ENOBUFS;
1017 }
1018
Johannes Bergb56cf722013-02-20 01:02:38 +01001019 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1020 return -ENOBUFS;
1021
Johannes Berg3713b4e2013-02-14 16:19:38 +01001022 nla_nest_end(msg, nl_wowlan);
1023
1024 return 0;
1025}
1026#endif
1027
1028static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1029 struct ieee80211_supported_band *sband)
1030{
1031 struct nlattr *nl_rates, *nl_rate;
1032 struct ieee80211_rate *rate;
1033 int i;
1034
1035 /* add HT info */
1036 if (sband->ht_cap.ht_supported &&
1037 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1038 sizeof(sband->ht_cap.mcs),
1039 &sband->ht_cap.mcs) ||
1040 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1041 sband->ht_cap.cap) ||
1042 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1043 sband->ht_cap.ampdu_factor) ||
1044 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1045 sband->ht_cap.ampdu_density)))
1046 return -ENOBUFS;
1047
1048 /* add VHT info */
1049 if (sband->vht_cap.vht_supported &&
1050 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1051 sizeof(sband->vht_cap.vht_mcs),
1052 &sband->vht_cap.vht_mcs) ||
1053 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1054 sband->vht_cap.cap)))
1055 return -ENOBUFS;
1056
1057 /* add bitrates */
1058 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1059 if (!nl_rates)
1060 return -ENOBUFS;
1061
1062 for (i = 0; i < sband->n_bitrates; i++) {
1063 nl_rate = nla_nest_start(msg, i);
1064 if (!nl_rate)
1065 return -ENOBUFS;
1066
1067 rate = &sband->bitrates[i];
1068 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1069 rate->bitrate))
1070 return -ENOBUFS;
1071 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1072 nla_put_flag(msg,
1073 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1074 return -ENOBUFS;
1075
1076 nla_nest_end(msg, nl_rate);
1077 }
1078
1079 nla_nest_end(msg, nl_rates);
1080
1081 return 0;
1082}
1083
1084static int
1085nl80211_send_mgmt_stypes(struct sk_buff *msg,
1086 const struct ieee80211_txrx_stypes *mgmt_stypes)
1087{
1088 u16 stypes;
1089 struct nlattr *nl_ftypes, *nl_ifs;
1090 enum nl80211_iftype ift;
1091 int i;
1092
1093 if (!mgmt_stypes)
1094 return 0;
1095
1096 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1097 if (!nl_ifs)
1098 return -ENOBUFS;
1099
1100 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1101 nl_ftypes = nla_nest_start(msg, ift);
1102 if (!nl_ftypes)
1103 return -ENOBUFS;
1104 i = 0;
1105 stypes = mgmt_stypes[ift].tx;
1106 while (stypes) {
1107 if ((stypes & 1) &&
1108 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1109 (i << 4) | IEEE80211_FTYPE_MGMT))
1110 return -ENOBUFS;
1111 stypes >>= 1;
1112 i++;
1113 }
1114 nla_nest_end(msg, nl_ftypes);
1115 }
1116
1117 nla_nest_end(msg, nl_ifs);
1118
1119 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1120 if (!nl_ifs)
1121 return -ENOBUFS;
1122
1123 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1124 nl_ftypes = nla_nest_start(msg, ift);
1125 if (!nl_ftypes)
1126 return -ENOBUFS;
1127 i = 0;
1128 stypes = mgmt_stypes[ift].rx;
1129 while (stypes) {
1130 if ((stypes & 1) &&
1131 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1132 (i << 4) | IEEE80211_FTYPE_MGMT))
1133 return -ENOBUFS;
1134 stypes >>= 1;
1135 i++;
1136 }
1137 nla_nest_end(msg, nl_ftypes);
1138 }
1139 nla_nest_end(msg, nl_ifs);
1140
1141 return 0;
1142}
1143
1144static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1145 struct sk_buff *msg, u32 portid, u32 seq,
1146 int flags, bool split, long *split_start,
1147 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001148{
1149 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001150 struct nlattr *nl_bands, *nl_band;
1151 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001152 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001153 enum ieee80211_band band;
1154 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001155 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001156 const struct ieee80211_txrx_stypes *mgmt_stypes =
1157 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001158 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001159 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001160
Eric W. Biederman15e47302012-09-07 20:12:54 +00001161 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001162 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001163 return -ENOBUFS;
1164
1165 /* allow always using the variables */
1166 if (!split) {
1167 split_start = &start;
1168 band_start = &start_band;
1169 chan_start = &start_chan;
1170 }
Johannes Berg55682962007-09-20 13:09:35 -04001171
David S. Miller9360ffd2012-03-29 04:41:26 -04001172 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1174 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001175 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001177 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001178
Johannes Berg3713b4e2013-02-14 16:19:38 +01001179 switch (*split_start) {
1180 case 0:
1181 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1182 dev->wiphy.retry_short) ||
1183 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1184 dev->wiphy.retry_long) ||
1185 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1186 dev->wiphy.frag_threshold) ||
1187 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1188 dev->wiphy.rts_threshold) ||
1189 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1190 dev->wiphy.coverage_class) ||
1191 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1192 dev->wiphy.max_scan_ssids) ||
1193 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1194 dev->wiphy.max_sched_scan_ssids) ||
1195 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1196 dev->wiphy.max_scan_ie_len) ||
1197 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1198 dev->wiphy.max_sched_scan_ie_len) ||
1199 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1200 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001201 goto nla_put_failure;
1202
Johannes Berg3713b4e2013-02-14 16:19:38 +01001203 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1204 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1205 goto nla_put_failure;
1206 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1207 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1208 goto nla_put_failure;
1209 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1210 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1211 goto nla_put_failure;
1212 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1213 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1216 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1219 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001220 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001221
Johannes Berg3713b4e2013-02-14 16:19:38 +01001222 (*split_start)++;
1223 if (split)
1224 break;
1225 case 1:
1226 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1227 sizeof(u32) * dev->wiphy.n_cipher_suites,
1228 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001229 goto nla_put_failure;
1230
Johannes Berg3713b4e2013-02-14 16:19:38 +01001231 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1232 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001233 goto nla_put_failure;
1234
Johannes Berg3713b4e2013-02-14 16:19:38 +01001235 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1236 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1237 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001238
Johannes Berg3713b4e2013-02-14 16:19:38 +01001239 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1240 dev->wiphy.available_antennas_tx) ||
1241 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1242 dev->wiphy.available_antennas_rx))
1243 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001244
Johannes Berg3713b4e2013-02-14 16:19:38 +01001245 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1246 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1247 dev->wiphy.probe_resp_offload))
1248 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001249
Johannes Berg3713b4e2013-02-14 16:19:38 +01001250 if ((dev->wiphy.available_antennas_tx ||
1251 dev->wiphy.available_antennas_rx) &&
1252 dev->ops->get_antenna) {
1253 u32 tx_ant = 0, rx_ant = 0;
1254 int res;
1255 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1256 if (!res) {
1257 if (nla_put_u32(msg,
1258 NL80211_ATTR_WIPHY_ANTENNA_TX,
1259 tx_ant) ||
1260 nla_put_u32(msg,
1261 NL80211_ATTR_WIPHY_ANTENNA_RX,
1262 rx_ant))
1263 goto nla_put_failure;
1264 }
Johannes Bergee688b002008-01-24 19:38:39 +01001265 }
1266
Johannes Berg3713b4e2013-02-14 16:19:38 +01001267 (*split_start)++;
1268 if (split)
1269 break;
1270 case 2:
1271 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1272 dev->wiphy.interface_modes))
1273 goto nla_put_failure;
1274 (*split_start)++;
1275 if (split)
1276 break;
1277 case 3:
1278 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1279 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001280 goto nla_put_failure;
1281
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1283 struct ieee80211_supported_band *sband;
1284
1285 sband = dev->wiphy.bands[band];
1286
1287 if (!sband)
1288 continue;
1289
1290 nl_band = nla_nest_start(msg, band);
1291 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001292 goto nla_put_failure;
1293
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 switch (*chan_start) {
1295 case 0:
1296 if (nl80211_send_band_rateinfo(msg, sband))
1297 goto nla_put_failure;
1298 (*chan_start)++;
1299 if (split)
1300 break;
1301 default:
1302 /* add frequencies */
1303 nl_freqs = nla_nest_start(
1304 msg, NL80211_BAND_ATTR_FREQS);
1305 if (!nl_freqs)
1306 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001307
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 for (i = *chan_start - 1;
1309 i < sband->n_channels;
1310 i++) {
1311 nl_freq = nla_nest_start(msg, i);
1312 if (!nl_freq)
1313 goto nla_put_failure;
1314
1315 chan = &sband->channels[i];
1316
Johannes Bergcdc89b92013-02-18 23:54:36 +01001317 if (nl80211_msg_put_channel(msg, chan,
1318 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001319 goto nla_put_failure;
1320
1321 nla_nest_end(msg, nl_freq);
1322 if (split)
1323 break;
1324 }
1325 if (i < sband->n_channels)
1326 *chan_start = i + 2;
1327 else
1328 *chan_start = 0;
1329 nla_nest_end(msg, nl_freqs);
1330 }
1331
1332 nla_nest_end(msg, nl_band);
1333
1334 if (split) {
1335 /* start again here */
1336 if (*chan_start)
1337 band--;
1338 break;
1339 }
Johannes Bergee688b002008-01-24 19:38:39 +01001340 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001342
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 if (band < IEEE80211_NUM_BANDS)
1344 *band_start = band + 1;
1345 else
1346 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001347
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 /* if bands & channels are done, continue outside */
1349 if (*band_start == 0 && *chan_start == 0)
1350 (*split_start)++;
1351 if (split)
1352 break;
1353 case 4:
1354 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1355 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001356 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357
1358 i = 0;
1359#define CMD(op, n) \
1360 do { \
1361 if (dev->ops->op) { \
1362 i++; \
1363 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1364 goto nla_put_failure; \
1365 } \
1366 } while (0)
1367
1368 CMD(add_virtual_intf, NEW_INTERFACE);
1369 CMD(change_virtual_intf, SET_INTERFACE);
1370 CMD(add_key, NEW_KEY);
1371 CMD(start_ap, START_AP);
1372 CMD(add_station, NEW_STATION);
1373 CMD(add_mpath, NEW_MPATH);
1374 CMD(update_mesh_config, SET_MESH_CONFIG);
1375 CMD(change_bss, SET_BSS);
1376 CMD(auth, AUTHENTICATE);
1377 CMD(assoc, ASSOCIATE);
1378 CMD(deauth, DEAUTHENTICATE);
1379 CMD(disassoc, DISASSOCIATE);
1380 CMD(join_ibss, JOIN_IBSS);
1381 CMD(join_mesh, JOIN_MESH);
1382 CMD(set_pmksa, SET_PMKSA);
1383 CMD(del_pmksa, DEL_PMKSA);
1384 CMD(flush_pmksa, FLUSH_PMKSA);
1385 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1386 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1387 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1388 CMD(mgmt_tx, FRAME);
1389 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1390 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1391 i++;
1392 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1393 goto nla_put_failure;
1394 }
1395 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1396 dev->ops->join_mesh) {
1397 i++;
1398 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1399 goto nla_put_failure;
1400 }
1401 CMD(set_wds_peer, SET_WDS_PEER);
1402 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1403 CMD(tdls_mgmt, TDLS_MGMT);
1404 CMD(tdls_oper, TDLS_OPER);
1405 }
1406 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1407 CMD(sched_scan_start, START_SCHED_SCAN);
1408 CMD(probe_client, PROBE_CLIENT);
1409 CMD(set_noack_map, SET_NOACK_MAP);
1410 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1411 i++;
1412 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1413 goto nla_put_failure;
1414 }
1415 CMD(start_p2p_device, START_P2P_DEVICE);
1416 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001417
Kalle Valo4745fc02011-11-17 19:06:10 +02001418#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001420#endif
1421
Johannes Berg8fdc6212009-03-14 09:34:01 +01001422#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001423
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424 if (dev->ops->connect || dev->ops->auth) {
1425 i++;
1426 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001427 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001428 }
1429
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 if (dev->ops->disconnect || dev->ops->deauth) {
1431 i++;
1432 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1433 goto nla_put_failure;
1434 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001435
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 nla_nest_end(msg, nl_cmds);
1437 (*split_start)++;
1438 if (split)
1439 break;
1440 case 5:
1441 if (dev->ops->remain_on_channel &&
1442 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1443 nla_put_u32(msg,
1444 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1445 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001446 goto nla_put_failure;
1447
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1449 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1450 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001451
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1453 goto nla_put_failure;
1454 (*split_start)++;
1455 if (split)
1456 break;
1457 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001458#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001459 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001460 goto nla_put_failure;
1461 (*split_start)++;
1462 if (split)
1463 break;
1464#else
1465 (*split_start)++;
1466#endif
1467 case 7:
1468 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1469 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001470 goto nla_put_failure;
1471
Johannes Bergcdc89b92013-02-18 23:54:36 +01001472 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001474
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475 (*split_start)++;
1476 if (split)
1477 break;
1478 case 8:
1479 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1480 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1481 dev->wiphy.ap_sme_capa))
1482 goto nla_put_failure;
1483
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001484 features = dev->wiphy.features;
1485 /*
1486 * We can only add the per-channel limit information if the
1487 * dump is split, otherwise it makes it too big. Therefore
1488 * only advertise it in that case.
1489 */
1490 if (split)
1491 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1492 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 goto nla_put_failure;
1494
1495 if (dev->wiphy.ht_capa_mod_mask &&
1496 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1497 sizeof(*dev->wiphy.ht_capa_mod_mask),
1498 dev->wiphy.ht_capa_mod_mask))
1499 goto nla_put_failure;
1500
1501 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1502 dev->wiphy.max_acl_mac_addrs &&
1503 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1504 dev->wiphy.max_acl_mac_addrs))
1505 goto nla_put_failure;
1506
1507 /*
1508 * Any information below this point is only available to
1509 * applications that can deal with it being split. This
1510 * helps ensure that newly added capabilities don't break
1511 * older tools by overrunning their buffers.
1512 *
1513 * We still increment split_start so that in the split
1514 * case we'll continue with more data in the next round,
1515 * but break unconditionally so unsplit data stops here.
1516 */
1517 (*split_start)++;
1518 break;
1519 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001520 if (dev->wiphy.extended_capabilities &&
1521 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1522 dev->wiphy.extended_capabilities_len,
1523 dev->wiphy.extended_capabilities) ||
1524 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1525 dev->wiphy.extended_capabilities_len,
1526 dev->wiphy.extended_capabilities_mask)))
1527 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528
Johannes Bergee2aca32013-02-21 17:36:01 +01001529 if (dev->wiphy.vht_capa_mod_mask &&
1530 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1531 sizeof(*dev->wiphy.vht_capa_mod_mask),
1532 dev->wiphy.vht_capa_mod_mask))
1533 goto nla_put_failure;
1534
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 /* done */
1536 *split_start = 0;
1537 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001538 }
Johannes Berg55682962007-09-20 13:09:35 -04001539 return genlmsg_end(msg, hdr);
1540
1541 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001542 genlmsg_cancel(msg, hdr);
1543 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001544}
1545
1546static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1547{
Johannes Berg645e77d2013-03-01 14:03:49 +01001548 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001549 int start = cb->args[0];
1550 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001551 s64 filter_wiphy = -1;
1552 bool split = false;
1553 struct nlattr **tb = nl80211_fam.attrbuf;
1554 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001555
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001556 mutex_lock(&cfg80211_mutex);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1558 tb, nl80211_fam.maxattr, nl80211_policy);
1559 if (res == 0) {
1560 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1561 if (tb[NL80211_ATTR_WIPHY])
1562 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1563 if (tb[NL80211_ATTR_WDEV])
1564 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1565 if (tb[NL80211_ATTR_IFINDEX]) {
1566 struct net_device *netdev;
1567 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1568
1569 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1570 if (!netdev) {
1571 mutex_unlock(&cfg80211_mutex);
1572 return -ENODEV;
1573 }
1574 if (netdev->ieee80211_ptr) {
1575 dev = wiphy_to_dev(
1576 netdev->ieee80211_ptr->wiphy);
1577 filter_wiphy = dev->wiphy_idx;
1578 }
1579 dev_put(netdev);
1580 }
1581 }
1582
Johannes Berg79c97e92009-07-07 03:56:12 +02001583 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001584 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1585 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001586 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001587 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001588 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1589 continue;
1590 /* attempt to fit multiple wiphy data chunks into the skb */
1591 do {
1592 ret = nl80211_send_wiphy(dev, skb,
1593 NETLINK_CB(cb->skb).portid,
1594 cb->nlh->nlmsg_seq,
1595 NLM_F_MULTI,
1596 split, &cb->args[1],
1597 &cb->args[2],
1598 &cb->args[3]);
1599 if (ret < 0) {
1600 /*
1601 * If sending the wiphy data didn't fit (ENOBUFS
1602 * or EMSGSIZE returned), this SKB is still
1603 * empty (so it's not too big because another
1604 * wiphy dataset is already in the skb) and
1605 * we've not tried to adjust the dump allocation
1606 * yet ... then adjust the alloc size to be
1607 * bigger, and return 1 but with the empty skb.
1608 * This results in an empty message being RX'ed
1609 * in userspace, but that is ignored.
1610 *
1611 * We can then retry with the larger buffer.
1612 */
1613 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1614 !skb->len &&
1615 cb->min_dump_alloc < 4096) {
1616 cb->min_dump_alloc = 4096;
1617 mutex_unlock(&cfg80211_mutex);
1618 return 1;
1619 }
1620 idx--;
1621 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001622 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 } while (cb->args[1] > 0);
1624 break;
Johannes Berg55682962007-09-20 13:09:35 -04001625 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001626 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001627
1628 cb->args[0] = idx;
1629
1630 return skb->len;
1631}
1632
1633static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1634{
1635 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001636 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001637
Johannes Berg645e77d2013-03-01 14:03:49 +01001638 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001639 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001640 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001641
Johannes Berg3713b4e2013-02-14 16:19:38 +01001642 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1643 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001644 nlmsg_free(msg);
1645 return -ENOBUFS;
1646 }
Johannes Berg55682962007-09-20 13:09:35 -04001647
Johannes Berg134e6372009-07-10 09:51:34 +00001648 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001649}
1650
Jouni Malinen31888482008-10-30 16:59:24 +02001651static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1652 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1653 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1654 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1655 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1656 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1657};
1658
1659static int parse_txq_params(struct nlattr *tb[],
1660 struct ieee80211_txq_params *txq_params)
1661{
Johannes Berga3304b02012-03-28 11:04:24 +02001662 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001663 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1664 !tb[NL80211_TXQ_ATTR_AIFS])
1665 return -EINVAL;
1666
Johannes Berga3304b02012-03-28 11:04:24 +02001667 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001668 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1669 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1670 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1671 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1672
Johannes Berga3304b02012-03-28 11:04:24 +02001673 if (txq_params->ac >= NL80211_NUM_ACS)
1674 return -EINVAL;
1675
Jouni Malinen31888482008-10-30 16:59:24 +02001676 return 0;
1677}
1678
Johannes Bergf444de02010-05-05 15:25:02 +02001679static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1680{
1681 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001682 * You can only set the channel explicitly for WDS interfaces,
1683 * all others have their channel managed via their respective
1684 * "establish a connection" command (connect, join, ...)
1685 *
1686 * For AP/GO and mesh mode, the channel can be set with the
1687 * channel userspace API, but is only stored and passed to the
1688 * low-level driver when the AP starts or the mesh is joined.
1689 * This is for backward compatibility, userspace can also give
1690 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001691 *
1692 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001693 * whatever else is going on, so they have their own special
1694 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001695 */
1696 return !wdev ||
1697 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001698 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001699 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1700 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001701}
1702
Johannes Berg683b6d32012-11-08 21:25:48 +01001703static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1704 struct genl_info *info,
1705 struct cfg80211_chan_def *chandef)
1706{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301707 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001708
1709 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1710 return -EINVAL;
1711
1712 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1713
1714 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001715 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1716 chandef->center_freq1 = control_freq;
1717 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001718
1719 /* Primary channel not allowed */
1720 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1721 return -EINVAL;
1722
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001723 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1724 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001725
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001726 chantype = nla_get_u32(
1727 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1728
1729 switch (chantype) {
1730 case NL80211_CHAN_NO_HT:
1731 case NL80211_CHAN_HT20:
1732 case NL80211_CHAN_HT40PLUS:
1733 case NL80211_CHAN_HT40MINUS:
1734 cfg80211_chandef_create(chandef, chandef->chan,
1735 chantype);
1736 break;
1737 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001738 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001739 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001740 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1741 chandef->width =
1742 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1743 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1744 chandef->center_freq1 =
1745 nla_get_u32(
1746 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1747 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1748 chandef->center_freq2 =
1749 nla_get_u32(
1750 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1751 }
1752
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001753 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001754 return -EINVAL;
1755
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001756 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1757 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001758 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001759
Johannes Berg683b6d32012-11-08 21:25:48 +01001760 return 0;
1761}
1762
Johannes Bergf444de02010-05-05 15:25:02 +02001763static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1764 struct wireless_dev *wdev,
1765 struct genl_info *info)
1766{
Johannes Berg683b6d32012-11-08 21:25:48 +01001767 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001768 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001769 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1770
1771 if (wdev)
1772 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001773
Johannes Bergf444de02010-05-05 15:25:02 +02001774 if (!nl80211_can_set_dev_channel(wdev))
1775 return -EOPNOTSUPP;
1776
Johannes Berg683b6d32012-11-08 21:25:48 +01001777 result = nl80211_parse_chandef(rdev, info, &chandef);
1778 if (result)
1779 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001780
1781 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001782 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001783 case NL80211_IFTYPE_AP:
1784 case NL80211_IFTYPE_P2P_GO:
1785 if (wdev->beacon_interval) {
1786 result = -EBUSY;
1787 break;
1788 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001789 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001790 result = -EINVAL;
1791 break;
1792 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001793 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001794 result = 0;
1795 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001796 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001797 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001798 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001799 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001800 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001801 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001802 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001803 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001804 }
1805 mutex_unlock(&rdev->devlist_mtx);
1806
1807 return result;
1808}
1809
1810static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1811{
Johannes Berg4c476992010-10-04 21:36:35 +02001812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1813 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001814
Johannes Berg4c476992010-10-04 21:36:35 +02001815 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001816}
1817
Bill Jordane8347eb2010-10-01 13:54:28 -04001818static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1819{
Johannes Berg43b19952010-10-07 13:10:30 +02001820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1821 struct net_device *dev = info->user_ptr[1];
1822 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001823 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001824
1825 if (!info->attrs[NL80211_ATTR_MAC])
1826 return -EINVAL;
1827
Johannes Berg43b19952010-10-07 13:10:30 +02001828 if (netif_running(dev))
1829 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001830
Johannes Berg43b19952010-10-07 13:10:30 +02001831 if (!rdev->ops->set_wds_peer)
1832 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001833
Johannes Berg43b19952010-10-07 13:10:30 +02001834 if (wdev->iftype != NL80211_IFTYPE_WDS)
1835 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001836
1837 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001838 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001839}
1840
1841
Johannes Berg55682962007-09-20 13:09:35 -04001842static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1843{
1844 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001845 struct net_device *netdev = NULL;
1846 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001847 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001848 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001849 u32 changed;
1850 u8 retry_short = 0, retry_long = 0;
1851 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001852 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001853
Johannes Bergf444de02010-05-05 15:25:02 +02001854 /*
1855 * Try to find the wiphy and netdev. Normally this
1856 * function shouldn't need the netdev, but this is
1857 * done for backward compatibility -- previously
1858 * setting the channel was done per wiphy, but now
1859 * it is per netdev. Previous userland like hostapd
1860 * also passed a netdev to set_wiphy, so that it is
1861 * possible to let that go to the right netdev!
1862 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001863 mutex_lock(&cfg80211_mutex);
1864
Johannes Bergf444de02010-05-05 15:25:02 +02001865 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1866 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1867
1868 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1869 if (netdev && netdev->ieee80211_ptr) {
1870 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1871 mutex_lock(&rdev->mtx);
1872 } else
1873 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001874 }
1875
Johannes Bergf444de02010-05-05 15:25:02 +02001876 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001877 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1878 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001879 if (IS_ERR(rdev)) {
1880 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001881 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001882 }
1883 wdev = NULL;
1884 netdev = NULL;
1885 result = 0;
1886
1887 mutex_lock(&rdev->mtx);
Johannes Berg71fe96b2012-10-24 10:04:58 +02001888 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001889 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001890
1891 /*
1892 * end workaround code, by now the rdev is available
1893 * and locked, and wdev may or may not be NULL.
1894 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001895
1896 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001897 result = cfg80211_dev_rename(
1898 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001899
1900 mutex_unlock(&cfg80211_mutex);
1901
1902 if (result)
1903 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001904
Jouni Malinen31888482008-10-30 16:59:24 +02001905 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1906 struct ieee80211_txq_params txq_params;
1907 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1908
1909 if (!rdev->ops->set_txq_params) {
1910 result = -EOPNOTSUPP;
1911 goto bad_res;
1912 }
1913
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001914 if (!netdev) {
1915 result = -EINVAL;
1916 goto bad_res;
1917 }
1918
Johannes Berg133a3ff2011-11-03 14:50:13 +01001919 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1920 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1921 result = -EINVAL;
1922 goto bad_res;
1923 }
1924
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001925 if (!netif_running(netdev)) {
1926 result = -ENETDOWN;
1927 goto bad_res;
1928 }
1929
Jouni Malinen31888482008-10-30 16:59:24 +02001930 nla_for_each_nested(nl_txq_params,
1931 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1932 rem_txq_params) {
1933 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1934 nla_data(nl_txq_params),
1935 nla_len(nl_txq_params),
1936 txq_params_policy);
1937 result = parse_txq_params(tb, &txq_params);
1938 if (result)
1939 goto bad_res;
1940
Hila Gonene35e4d22012-06-27 17:19:42 +03001941 result = rdev_set_txq_params(rdev, netdev,
1942 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001943 if (result)
1944 goto bad_res;
1945 }
1946 }
1947
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001948 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001949 result = __nl80211_set_channel(rdev,
1950 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1951 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001952 if (result)
1953 goto bad_res;
1954 }
1955
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001956 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001957 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001958 enum nl80211_tx_power_setting type;
1959 int idx, mbm = 0;
1960
Johannes Bergc8442112012-10-24 10:17:18 +02001961 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1962 txp_wdev = NULL;
1963
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001964 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001965 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001966 goto bad_res;
1967 }
1968
1969 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1970 type = nla_get_u32(info->attrs[idx]);
1971
1972 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1973 (type != NL80211_TX_POWER_AUTOMATIC)) {
1974 result = -EINVAL;
1975 goto bad_res;
1976 }
1977
1978 if (type != NL80211_TX_POWER_AUTOMATIC) {
1979 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1980 mbm = nla_get_u32(info->attrs[idx]);
1981 }
1982
Johannes Bergc8442112012-10-24 10:17:18 +02001983 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001984 if (result)
1985 goto bad_res;
1986 }
1987
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001988 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1989 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1990 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001991 if ((!rdev->wiphy.available_antennas_tx &&
1992 !rdev->wiphy.available_antennas_rx) ||
1993 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001994 result = -EOPNOTSUPP;
1995 goto bad_res;
1996 }
1997
1998 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1999 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2000
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002001 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002002 * available antenna masks, except for the "all" mask */
2003 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2004 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002005 result = -EINVAL;
2006 goto bad_res;
2007 }
2008
Bruno Randolf7f531e02010-12-16 11:30:22 +09002009 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2010 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002011
Hila Gonene35e4d22012-06-27 17:19:42 +03002012 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002013 if (result)
2014 goto bad_res;
2015 }
2016
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002017 changed = 0;
2018
2019 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2020 retry_short = nla_get_u8(
2021 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2022 if (retry_short == 0) {
2023 result = -EINVAL;
2024 goto bad_res;
2025 }
2026 changed |= WIPHY_PARAM_RETRY_SHORT;
2027 }
2028
2029 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2030 retry_long = nla_get_u8(
2031 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2032 if (retry_long == 0) {
2033 result = -EINVAL;
2034 goto bad_res;
2035 }
2036 changed |= WIPHY_PARAM_RETRY_LONG;
2037 }
2038
2039 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2040 frag_threshold = nla_get_u32(
2041 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2042 if (frag_threshold < 256) {
2043 result = -EINVAL;
2044 goto bad_res;
2045 }
2046 if (frag_threshold != (u32) -1) {
2047 /*
2048 * Fragments (apart from the last one) are required to
2049 * have even length. Make the fragmentation code
2050 * simpler by stripping LSB should someone try to use
2051 * odd threshold value.
2052 */
2053 frag_threshold &= ~0x1;
2054 }
2055 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2056 }
2057
2058 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2059 rts_threshold = nla_get_u32(
2060 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2061 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2062 }
2063
Lukáš Turek81077e82009-12-21 22:50:47 +01002064 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2065 coverage_class = nla_get_u8(
2066 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2067 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2068 }
2069
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002070 if (changed) {
2071 u8 old_retry_short, old_retry_long;
2072 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002073 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002074
2075 if (!rdev->ops->set_wiphy_params) {
2076 result = -EOPNOTSUPP;
2077 goto bad_res;
2078 }
2079
2080 old_retry_short = rdev->wiphy.retry_short;
2081 old_retry_long = rdev->wiphy.retry_long;
2082 old_frag_threshold = rdev->wiphy.frag_threshold;
2083 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002084 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002085
2086 if (changed & WIPHY_PARAM_RETRY_SHORT)
2087 rdev->wiphy.retry_short = retry_short;
2088 if (changed & WIPHY_PARAM_RETRY_LONG)
2089 rdev->wiphy.retry_long = retry_long;
2090 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2091 rdev->wiphy.frag_threshold = frag_threshold;
2092 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2093 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002094 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2095 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002096
Hila Gonene35e4d22012-06-27 17:19:42 +03002097 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002098 if (result) {
2099 rdev->wiphy.retry_short = old_retry_short;
2100 rdev->wiphy.retry_long = old_retry_long;
2101 rdev->wiphy.frag_threshold = old_frag_threshold;
2102 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002103 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002104 }
2105 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002106
Johannes Berg306d6112008-12-08 12:39:04 +01002107 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002108 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02002109 if (netdev)
2110 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002111 return result;
2112}
2113
Johannes Berg71bbc992012-06-15 15:30:18 +02002114static inline u64 wdev_id(struct wireless_dev *wdev)
2115{
2116 return (u64)wdev->identifier |
2117 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2118}
Johannes Berg55682962007-09-20 13:09:35 -04002119
Johannes Berg683b6d32012-11-08 21:25:48 +01002120static int nl80211_send_chandef(struct sk_buff *msg,
2121 struct cfg80211_chan_def *chandef)
2122{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002123 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002124
Johannes Berg683b6d32012-11-08 21:25:48 +01002125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2126 chandef->chan->center_freq))
2127 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002128 switch (chandef->width) {
2129 case NL80211_CHAN_WIDTH_20_NOHT:
2130 case NL80211_CHAN_WIDTH_20:
2131 case NL80211_CHAN_WIDTH_40:
2132 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2133 cfg80211_get_chandef_type(chandef)))
2134 return -ENOBUFS;
2135 break;
2136 default:
2137 break;
2138 }
2139 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2140 return -ENOBUFS;
2141 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2142 return -ENOBUFS;
2143 if (chandef->center_freq2 &&
2144 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002145 return -ENOBUFS;
2146 return 0;
2147}
2148
Eric W. Biederman15e47302012-09-07 20:12:54 +00002149static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002150 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002151 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002152{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002153 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002154 void *hdr;
2155
Eric W. Biederman15e47302012-09-07 20:12:54 +00002156 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002157 if (!hdr)
2158 return -1;
2159
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002160 if (dev &&
2161 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002162 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002163 goto nla_put_failure;
2164
2165 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2166 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002167 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002168 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002169 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2170 rdev->devlist_generation ^
2171 (cfg80211_rdev_list_generation << 2)))
2172 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002173
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002174 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002175 int ret;
2176 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002177
Johannes Berg683b6d32012-11-08 21:25:48 +01002178 ret = rdev_get_channel(rdev, wdev, &chandef);
2179 if (ret == 0) {
2180 if (nl80211_send_chandef(msg, &chandef))
2181 goto nla_put_failure;
2182 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002183 }
2184
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002185 if (wdev->ssid_len) {
2186 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2187 goto nla_put_failure;
2188 }
2189
Johannes Berg55682962007-09-20 13:09:35 -04002190 return genlmsg_end(msg, hdr);
2191
2192 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002193 genlmsg_cancel(msg, hdr);
2194 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002195}
2196
2197static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2198{
2199 int wp_idx = 0;
2200 int if_idx = 0;
2201 int wp_start = cb->args[0];
2202 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002203 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002204 struct wireless_dev *wdev;
2205
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002206 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02002207 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2208 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002209 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002210 if (wp_idx < wp_start) {
2211 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002212 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002213 }
Johannes Berg55682962007-09-20 13:09:35 -04002214 if_idx = 0;
2215
Johannes Bergf5ea9122009-08-07 16:17:38 +02002216 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02002217 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002218 if (if_idx < if_start) {
2219 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002220 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002221 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002222 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002223 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002224 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02002225 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002226 goto out;
2227 }
2228 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002229 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02002230 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002231
2232 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002233 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002234 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002235 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04002236
2237 cb->args[0] = wp_idx;
2238 cb->args[1] = if_idx;
2239
2240 return skb->len;
2241}
2242
2243static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2244{
2245 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002246 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002247 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002248
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002249 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002250 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002251 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002252
Eric W. Biederman15e47302012-09-07 20:12:54 +00002253 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002254 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002255 nlmsg_free(msg);
2256 return -ENOBUFS;
2257 }
Johannes Berg55682962007-09-20 13:09:35 -04002258
Johannes Berg134e6372009-07-10 09:51:34 +00002259 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002260}
2261
Michael Wu66f7ac52008-01-31 19:48:22 +01002262static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2263 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2264 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2265 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2266 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2267 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2268};
2269
2270static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2271{
2272 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2273 int flag;
2274
2275 *mntrflags = 0;
2276
2277 if (!nla)
2278 return -EINVAL;
2279
2280 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2281 nla, mntr_flags_policy))
2282 return -EINVAL;
2283
2284 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2285 if (flags[flag])
2286 *mntrflags |= (1<<flag);
2287
2288 return 0;
2289}
2290
Johannes Berg9bc383d2009-11-19 11:55:19 +01002291static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002292 struct net_device *netdev, u8 use_4addr,
2293 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002294{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002295 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002296 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002297 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002298 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002299 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002300
2301 switch (iftype) {
2302 case NL80211_IFTYPE_AP_VLAN:
2303 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2304 return 0;
2305 break;
2306 case NL80211_IFTYPE_STATION:
2307 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2308 return 0;
2309 break;
2310 default:
2311 break;
2312 }
2313
2314 return -EOPNOTSUPP;
2315}
2316
Johannes Berg55682962007-09-20 13:09:35 -04002317static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2318{
Johannes Berg4c476992010-10-04 21:36:35 +02002319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002320 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002321 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002322 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002323 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002324 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002325 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002326
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002327 memset(&params, 0, sizeof(params));
2328
Johannes Berg04a773a2009-04-19 21:24:32 +02002329 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002330
Johannes Berg723b0382008-09-16 20:22:09 +02002331 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002332 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002333 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002334 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002335 if (ntype > NL80211_IFTYPE_MAX)
2336 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002337 }
2338
Johannes Berg92ffe052008-09-16 20:39:36 +02002339 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002340 struct wireless_dev *wdev = dev->ieee80211_ptr;
2341
Johannes Berg4c476992010-10-04 21:36:35 +02002342 if (ntype != NL80211_IFTYPE_MESH_POINT)
2343 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002344 if (netif_running(dev))
2345 return -EBUSY;
2346
2347 wdev_lock(wdev);
2348 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2349 IEEE80211_MAX_MESH_ID_LEN);
2350 wdev->mesh_id_up_len =
2351 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2352 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2353 wdev->mesh_id_up_len);
2354 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002355 }
2356
Felix Fietkau8b787642009-11-10 18:53:10 +01002357 if (info->attrs[NL80211_ATTR_4ADDR]) {
2358 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2359 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002360 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002361 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002362 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002363 } else {
2364 params.use_4addr = -1;
2365 }
2366
Johannes Berg92ffe052008-09-16 20:39:36 +02002367 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002368 if (ntype != NL80211_IFTYPE_MONITOR)
2369 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002370 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2371 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002372 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002373 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002374
2375 flags = &_flags;
2376 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002377 }
Johannes Berg3b858752009-03-12 09:55:09 +01002378
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002379 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002380 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002381 else
2382 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002383
Johannes Berg9bc383d2009-11-19 11:55:19 +01002384 if (!err && params.use_4addr != -1)
2385 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2386
Johannes Berg55682962007-09-20 13:09:35 -04002387 return err;
2388}
2389
2390static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2391{
Johannes Berg4c476992010-10-04 21:36:35 +02002392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002393 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002394 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002395 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002396 int err;
2397 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002398 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002399
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002400 memset(&params, 0, sizeof(params));
2401
Johannes Berg55682962007-09-20 13:09:35 -04002402 if (!info->attrs[NL80211_ATTR_IFNAME])
2403 return -EINVAL;
2404
2405 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2406 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2407 if (type > NL80211_IFTYPE_MAX)
2408 return -EINVAL;
2409 }
2410
Johannes Berg79c97e92009-07-07 03:56:12 +02002411 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002412 !(rdev->wiphy.interface_modes & (1 << type)))
2413 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002414
Arend van Spriel1c18f142013-01-08 10:17:27 +01002415 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2416 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2417 ETH_ALEN);
2418 if (!is_valid_ether_addr(params.macaddr))
2419 return -EADDRNOTAVAIL;
2420 }
2421
Johannes Berg9bc383d2009-11-19 11:55:19 +01002422 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002423 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002424 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002425 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002426 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002427 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002428
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2430 if (!msg)
2431 return -ENOMEM;
2432
Michael Wu66f7ac52008-01-31 19:48:22 +01002433 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2434 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2435 &flags);
Hila Gonene35e4d22012-06-27 17:19:42 +03002436 wdev = rdev_add_virtual_intf(rdev,
2437 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2438 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002439 if (IS_ERR(wdev)) {
2440 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002441 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002442 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002443
Johannes Berg98104fde2012-06-16 00:19:54 +02002444 switch (type) {
2445 case NL80211_IFTYPE_MESH_POINT:
2446 if (!info->attrs[NL80211_ATTR_MESH_ID])
2447 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002448 wdev_lock(wdev);
2449 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2450 IEEE80211_MAX_MESH_ID_LEN);
2451 wdev->mesh_id_up_len =
2452 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2453 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2454 wdev->mesh_id_up_len);
2455 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002456 break;
2457 case NL80211_IFTYPE_P2P_DEVICE:
2458 /*
2459 * P2P Device doesn't have a netdev, so doesn't go
2460 * through the netdev notifier and must be added here
2461 */
2462 mutex_init(&wdev->mtx);
2463 INIT_LIST_HEAD(&wdev->event_list);
2464 spin_lock_init(&wdev->event_lock);
2465 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2466 spin_lock_init(&wdev->mgmt_registrations_lock);
2467
2468 mutex_lock(&rdev->devlist_mtx);
2469 wdev->identifier = ++rdev->wdev_id;
2470 list_add_rcu(&wdev->list, &rdev->wdev_list);
2471 rdev->devlist_generation++;
2472 mutex_unlock(&rdev->devlist_mtx);
2473 break;
2474 default:
2475 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002476 }
2477
Eric W. Biederman15e47302012-09-07 20:12:54 +00002478 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002479 rdev, wdev) < 0) {
2480 nlmsg_free(msg);
2481 return -ENOBUFS;
2482 }
2483
2484 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002485}
2486
2487static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2488{
Johannes Berg4c476992010-10-04 21:36:35 +02002489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002490 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002491
Johannes Berg4c476992010-10-04 21:36:35 +02002492 if (!rdev->ops->del_virtual_intf)
2493 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002494
Johannes Berg84efbb82012-06-16 00:00:26 +02002495 /*
2496 * If we remove a wireless device without a netdev then clear
2497 * user_ptr[1] so that nl80211_post_doit won't dereference it
2498 * to check if it needs to do dev_put(). Otherwise it crashes
2499 * since the wdev has been freed, unlike with a netdev where
2500 * we need the dev_put() for the netdev to really be freed.
2501 */
2502 if (!wdev->netdev)
2503 info->user_ptr[1] = NULL;
2504
Hila Gonene35e4d22012-06-27 17:19:42 +03002505 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002506}
2507
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002508static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2509{
2510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2511 struct net_device *dev = info->user_ptr[1];
2512 u16 noack_map;
2513
2514 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2515 return -EINVAL;
2516
2517 if (!rdev->ops->set_noack_map)
2518 return -EOPNOTSUPP;
2519
2520 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2521
Hila Gonene35e4d22012-06-27 17:19:42 +03002522 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002523}
2524
Johannes Berg41ade002007-12-19 02:03:29 +01002525struct get_key_cookie {
2526 struct sk_buff *msg;
2527 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002528 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002529};
2530
2531static void get_key_callback(void *c, struct key_params *params)
2532{
Johannes Bergb9454e82009-07-08 13:29:08 +02002533 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002534 struct get_key_cookie *cookie = c;
2535
David S. Miller9360ffd2012-03-29 04:41:26 -04002536 if ((params->key &&
2537 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2538 params->key_len, params->key)) ||
2539 (params->seq &&
2540 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2541 params->seq_len, params->seq)) ||
2542 (params->cipher &&
2543 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2544 params->cipher)))
2545 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002546
Johannes Bergb9454e82009-07-08 13:29:08 +02002547 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2548 if (!key)
2549 goto nla_put_failure;
2550
David S. Miller9360ffd2012-03-29 04:41:26 -04002551 if ((params->key &&
2552 nla_put(cookie->msg, NL80211_KEY_DATA,
2553 params->key_len, params->key)) ||
2554 (params->seq &&
2555 nla_put(cookie->msg, NL80211_KEY_SEQ,
2556 params->seq_len, params->seq)) ||
2557 (params->cipher &&
2558 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2559 params->cipher)))
2560 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002561
David S. Miller9360ffd2012-03-29 04:41:26 -04002562 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2563 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002564
2565 nla_nest_end(cookie->msg, key);
2566
Johannes Berg41ade002007-12-19 02:03:29 +01002567 return;
2568 nla_put_failure:
2569 cookie->error = 1;
2570}
2571
2572static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2573{
Johannes Berg4c476992010-10-04 21:36:35 +02002574 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002575 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002576 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002577 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002578 const u8 *mac_addr = NULL;
2579 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002580 struct get_key_cookie cookie = {
2581 .error = 0,
2582 };
2583 void *hdr;
2584 struct sk_buff *msg;
2585
2586 if (info->attrs[NL80211_ATTR_KEY_IDX])
2587 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2588
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002589 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002590 return -EINVAL;
2591
2592 if (info->attrs[NL80211_ATTR_MAC])
2593 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2594
Johannes Berge31b8212010-10-05 19:39:30 +02002595 pairwise = !!mac_addr;
2596 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2597 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2598 if (kt >= NUM_NL80211_KEYTYPES)
2599 return -EINVAL;
2600 if (kt != NL80211_KEYTYPE_GROUP &&
2601 kt != NL80211_KEYTYPE_PAIRWISE)
2602 return -EINVAL;
2603 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2604 }
2605
Johannes Berg4c476992010-10-04 21:36:35 +02002606 if (!rdev->ops->get_key)
2607 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002608
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002609 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002610 if (!msg)
2611 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002612
Eric W. Biederman15e47302012-09-07 20:12:54 +00002613 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002614 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002615 if (IS_ERR(hdr))
2616 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002617
2618 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002619 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002620
David S. Miller9360ffd2012-03-29 04:41:26 -04002621 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2622 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2623 goto nla_put_failure;
2624 if (mac_addr &&
2625 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2626 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002627
Johannes Berge31b8212010-10-05 19:39:30 +02002628 if (pairwise && mac_addr &&
2629 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2630 return -ENOENT;
2631
Hila Gonene35e4d22012-06-27 17:19:42 +03002632 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2633 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002634
2635 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002636 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002637
2638 if (cookie.error)
2639 goto nla_put_failure;
2640
2641 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002642 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002643
2644 nla_put_failure:
2645 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002646 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002647 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002648 return err;
2649}
2650
2651static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2652{
Johannes Berg4c476992010-10-04 21:36:35 +02002653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002654 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002655 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002656 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002657
Johannes Bergb9454e82009-07-08 13:29:08 +02002658 err = nl80211_parse_key(info, &key);
2659 if (err)
2660 return err;
2661
2662 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002663 return -EINVAL;
2664
Johannes Bergb9454e82009-07-08 13:29:08 +02002665 /* only support setting default key */
2666 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002667 return -EINVAL;
2668
Johannes Bergfffd0932009-07-08 14:22:54 +02002669 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002670
2671 if (key.def) {
2672 if (!rdev->ops->set_default_key) {
2673 err = -EOPNOTSUPP;
2674 goto out;
2675 }
2676
2677 err = nl80211_key_allowed(dev->ieee80211_ptr);
2678 if (err)
2679 goto out;
2680
Hila Gonene35e4d22012-06-27 17:19:42 +03002681 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002682 key.def_uni, key.def_multi);
2683
2684 if (err)
2685 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002686
Johannes Berg3d23e342009-09-29 23:27:28 +02002687#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002688 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002689#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002690 } else {
2691 if (key.def_uni || !key.def_multi) {
2692 err = -EINVAL;
2693 goto out;
2694 }
2695
2696 if (!rdev->ops->set_default_mgmt_key) {
2697 err = -EOPNOTSUPP;
2698 goto out;
2699 }
2700
2701 err = nl80211_key_allowed(dev->ieee80211_ptr);
2702 if (err)
2703 goto out;
2704
Hila Gonene35e4d22012-06-27 17:19:42 +03002705 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002706 if (err)
2707 goto out;
2708
2709#ifdef CONFIG_CFG80211_WEXT
2710 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2711#endif
2712 }
2713
2714 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002715 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002716
Johannes Berg41ade002007-12-19 02:03:29 +01002717 return err;
2718}
2719
2720static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2721{
Johannes Berg4c476992010-10-04 21:36:35 +02002722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002723 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002724 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002725 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002726 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002727
Johannes Bergb9454e82009-07-08 13:29:08 +02002728 err = nl80211_parse_key(info, &key);
2729 if (err)
2730 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002731
Johannes Bergb9454e82009-07-08 13:29:08 +02002732 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002733 return -EINVAL;
2734
Johannes Berg41ade002007-12-19 02:03:29 +01002735 if (info->attrs[NL80211_ATTR_MAC])
2736 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2737
Johannes Berge31b8212010-10-05 19:39:30 +02002738 if (key.type == -1) {
2739 if (mac_addr)
2740 key.type = NL80211_KEYTYPE_PAIRWISE;
2741 else
2742 key.type = NL80211_KEYTYPE_GROUP;
2743 }
2744
2745 /* for now */
2746 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2747 key.type != NL80211_KEYTYPE_GROUP)
2748 return -EINVAL;
2749
Johannes Berg4c476992010-10-04 21:36:35 +02002750 if (!rdev->ops->add_key)
2751 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002752
Johannes Berge31b8212010-10-05 19:39:30 +02002753 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2754 key.type == NL80211_KEYTYPE_PAIRWISE,
2755 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002756 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002757
2758 wdev_lock(dev->ieee80211_ptr);
2759 err = nl80211_key_allowed(dev->ieee80211_ptr);
2760 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002761 err = rdev_add_key(rdev, dev, key.idx,
2762 key.type == NL80211_KEYTYPE_PAIRWISE,
2763 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002764 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002765
Johannes Berg41ade002007-12-19 02:03:29 +01002766 return err;
2767}
2768
2769static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2770{
Johannes Berg4c476992010-10-04 21:36:35 +02002771 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002772 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002773 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002774 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002775 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002776
Johannes Bergb9454e82009-07-08 13:29:08 +02002777 err = nl80211_parse_key(info, &key);
2778 if (err)
2779 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002780
2781 if (info->attrs[NL80211_ATTR_MAC])
2782 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2783
Johannes Berge31b8212010-10-05 19:39:30 +02002784 if (key.type == -1) {
2785 if (mac_addr)
2786 key.type = NL80211_KEYTYPE_PAIRWISE;
2787 else
2788 key.type = NL80211_KEYTYPE_GROUP;
2789 }
2790
2791 /* for now */
2792 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2793 key.type != NL80211_KEYTYPE_GROUP)
2794 return -EINVAL;
2795
Johannes Berg4c476992010-10-04 21:36:35 +02002796 if (!rdev->ops->del_key)
2797 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002798
Johannes Bergfffd0932009-07-08 14:22:54 +02002799 wdev_lock(dev->ieee80211_ptr);
2800 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002801
2802 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2803 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2804 err = -ENOENT;
2805
Johannes Bergfffd0932009-07-08 14:22:54 +02002806 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002807 err = rdev_del_key(rdev, dev, key.idx,
2808 key.type == NL80211_KEYTYPE_PAIRWISE,
2809 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002810
Johannes Berg3d23e342009-09-29 23:27:28 +02002811#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002812 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002813 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002814 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002815 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002816 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2817 }
2818#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002819 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002820
Johannes Berg41ade002007-12-19 02:03:29 +01002821 return err;
2822}
2823
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302824/* This function returns an error or the number of nested attributes */
2825static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2826{
2827 struct nlattr *attr;
2828 int n_entries = 0, tmp;
2829
2830 nla_for_each_nested(attr, nl_attr, tmp) {
2831 if (nla_len(attr) != ETH_ALEN)
2832 return -EINVAL;
2833
2834 n_entries++;
2835 }
2836
2837 return n_entries;
2838}
2839
2840/*
2841 * This function parses ACL information and allocates memory for ACL data.
2842 * On successful return, the calling function is responsible to free the
2843 * ACL buffer returned by this function.
2844 */
2845static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2846 struct genl_info *info)
2847{
2848 enum nl80211_acl_policy acl_policy;
2849 struct nlattr *attr;
2850 struct cfg80211_acl_data *acl;
2851 int i = 0, n_entries, tmp;
2852
2853 if (!wiphy->max_acl_mac_addrs)
2854 return ERR_PTR(-EOPNOTSUPP);
2855
2856 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2857 return ERR_PTR(-EINVAL);
2858
2859 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2860 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2861 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2862 return ERR_PTR(-EINVAL);
2863
2864 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2865 return ERR_PTR(-EINVAL);
2866
2867 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2868 if (n_entries < 0)
2869 return ERR_PTR(n_entries);
2870
2871 if (n_entries > wiphy->max_acl_mac_addrs)
2872 return ERR_PTR(-ENOTSUPP);
2873
2874 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2875 GFP_KERNEL);
2876 if (!acl)
2877 return ERR_PTR(-ENOMEM);
2878
2879 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2880 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2881 i++;
2882 }
2883
2884 acl->n_acl_entries = n_entries;
2885 acl->acl_policy = acl_policy;
2886
2887 return acl;
2888}
2889
2890static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2891{
2892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2893 struct net_device *dev = info->user_ptr[1];
2894 struct cfg80211_acl_data *acl;
2895 int err;
2896
2897 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2898 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2899 return -EOPNOTSUPP;
2900
2901 if (!dev->ieee80211_ptr->beacon_interval)
2902 return -EINVAL;
2903
2904 acl = parse_acl_data(&rdev->wiphy, info);
2905 if (IS_ERR(acl))
2906 return PTR_ERR(acl);
2907
2908 err = rdev_set_mac_acl(rdev, dev, acl);
2909
2910 kfree(acl);
2911
2912 return err;
2913}
2914
Johannes Berg88600202012-02-13 15:17:18 +01002915static int nl80211_parse_beacon(struct genl_info *info,
2916 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002917{
Johannes Berg88600202012-02-13 15:17:18 +01002918 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002919
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002920 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2921 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2922 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2923 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002924 return -EINVAL;
2925
Johannes Berg88600202012-02-13 15:17:18 +01002926 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002927
Johannes Berged1b6cc2007-12-19 02:03:32 +01002928 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002929 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2930 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2931 if (!bcn->head_len)
2932 return -EINVAL;
2933 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002934 }
2935
2936 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002937 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2938 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002939 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002940 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002941 }
2942
Johannes Berg4c476992010-10-04 21:36:35 +02002943 if (!haveinfo)
2944 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002945
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002946 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002947 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2948 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002949 }
2950
2951 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002952 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002953 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002954 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002955 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2956 }
2957
2958 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002959 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002960 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002961 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002962 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2963 }
2964
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002965 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002966 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002967 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002968 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002969 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2970 }
2971
Johannes Berg88600202012-02-13 15:17:18 +01002972 return 0;
2973}
2974
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002975static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2976 struct cfg80211_ap_settings *params)
2977{
2978 struct wireless_dev *wdev;
2979 bool ret = false;
2980
2981 mutex_lock(&rdev->devlist_mtx);
2982
Johannes Berg89a54e42012-06-15 14:33:17 +02002983 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002984 if (wdev->iftype != NL80211_IFTYPE_AP &&
2985 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2986 continue;
2987
Johannes Berg683b6d32012-11-08 21:25:48 +01002988 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002989 continue;
2990
Johannes Berg683b6d32012-11-08 21:25:48 +01002991 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002992 ret = true;
2993 break;
2994 }
2995
2996 mutex_unlock(&rdev->devlist_mtx);
2997
2998 return ret;
2999}
3000
Jouni Malinene39e5b52012-09-30 19:29:39 +03003001static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3002 enum nl80211_auth_type auth_type,
3003 enum nl80211_commands cmd)
3004{
3005 if (auth_type > NL80211_AUTHTYPE_MAX)
3006 return false;
3007
3008 switch (cmd) {
3009 case NL80211_CMD_AUTHENTICATE:
3010 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3011 auth_type == NL80211_AUTHTYPE_SAE)
3012 return false;
3013 return true;
3014 case NL80211_CMD_CONNECT:
3015 case NL80211_CMD_START_AP:
3016 /* SAE not supported yet */
3017 if (auth_type == NL80211_AUTHTYPE_SAE)
3018 return false;
3019 return true;
3020 default:
3021 return false;
3022 }
3023}
3024
Johannes Berg88600202012-02-13 15:17:18 +01003025static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3026{
3027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3028 struct net_device *dev = info->user_ptr[1];
3029 struct wireless_dev *wdev = dev->ieee80211_ptr;
3030 struct cfg80211_ap_settings params;
3031 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003032 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003033
3034 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3035 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3036 return -EOPNOTSUPP;
3037
3038 if (!rdev->ops->start_ap)
3039 return -EOPNOTSUPP;
3040
3041 if (wdev->beacon_interval)
3042 return -EALREADY;
3043
3044 memset(&params, 0, sizeof(params));
3045
3046 /* these are required for START_AP */
3047 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3048 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3049 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3050 return -EINVAL;
3051
3052 err = nl80211_parse_beacon(info, &params.beacon);
3053 if (err)
3054 return err;
3055
3056 params.beacon_interval =
3057 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3058 params.dtim_period =
3059 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3060
3061 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3062 if (err)
3063 return err;
3064
3065 /*
3066 * In theory, some of these attributes should be required here
3067 * but since they were not used when the command was originally
3068 * added, keep them optional for old user space programs to let
3069 * them continue to work with drivers that do not need the
3070 * additional information -- drivers must check!
3071 */
3072 if (info->attrs[NL80211_ATTR_SSID]) {
3073 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3074 params.ssid_len =
3075 nla_len(info->attrs[NL80211_ATTR_SSID]);
3076 if (params.ssid_len == 0 ||
3077 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3078 return -EINVAL;
3079 }
3080
3081 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3082 params.hidden_ssid = nla_get_u32(
3083 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3084 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3085 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3086 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3087 return -EINVAL;
3088 }
3089
3090 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3091
3092 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3093 params.auth_type = nla_get_u32(
3094 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003095 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3096 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003097 return -EINVAL;
3098 } else
3099 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3100
3101 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3102 NL80211_MAX_NR_CIPHER_SUITES);
3103 if (err)
3104 return err;
3105
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303106 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3107 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3108 return -EOPNOTSUPP;
3109 params.inactivity_timeout = nla_get_u16(
3110 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3111 }
3112
Johannes Berg53cabad2012-11-14 15:17:28 +01003113 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3114 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3115 return -EINVAL;
3116 params.p2p_ctwindow =
3117 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3118 if (params.p2p_ctwindow > 127)
3119 return -EINVAL;
3120 if (params.p2p_ctwindow != 0 &&
3121 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3122 return -EINVAL;
3123 }
3124
3125 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3126 u8 tmp;
3127
3128 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3129 return -EINVAL;
3130 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3131 if (tmp > 1)
3132 return -EINVAL;
3133 params.p2p_opp_ps = tmp;
3134 if (params.p2p_opp_ps != 0 &&
3135 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3136 return -EINVAL;
3137 }
3138
Johannes Bergaa430da2012-05-16 23:50:18 +02003139 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003140 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3141 if (err)
3142 return err;
3143 } else if (wdev->preset_chandef.chan) {
3144 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003145 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003146 return -EINVAL;
3147
Johannes Berg683b6d32012-11-08 21:25:48 +01003148 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003149 return -EINVAL;
3150
Simon Wunderlich04f39042013-02-08 18:16:19 +01003151 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3152 if (err < 0)
3153 return err;
3154 if (err) {
3155 radar_detect_width = BIT(params.chandef.width);
3156 params.radar_required = true;
3157 }
3158
Michal Kaziore4e32452012-06-29 12:47:08 +02003159 mutex_lock(&rdev->devlist_mtx);
Simon Wunderlich04f39042013-02-08 18:16:19 +01003160 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3161 params.chandef.chan,
3162 CHAN_MODE_SHARED,
3163 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003164 mutex_unlock(&rdev->devlist_mtx);
3165
3166 if (err)
3167 return err;
3168
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303169 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3170 params.acl = parse_acl_data(&rdev->wiphy, info);
3171 if (IS_ERR(params.acl))
3172 return PTR_ERR(params.acl);
3173 }
3174
Hila Gonene35e4d22012-06-27 17:19:42 +03003175 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003176 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003177 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003178 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003179 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003180 wdev->ssid_len = params.ssid_len;
3181 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003182 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303183
3184 kfree(params.acl);
3185
Johannes Berg56d18932011-05-09 18:41:15 +02003186 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003187}
3188
Johannes Berg88600202012-02-13 15:17:18 +01003189static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3190{
3191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3192 struct net_device *dev = info->user_ptr[1];
3193 struct wireless_dev *wdev = dev->ieee80211_ptr;
3194 struct cfg80211_beacon_data params;
3195 int err;
3196
3197 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3198 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3199 return -EOPNOTSUPP;
3200
3201 if (!rdev->ops->change_beacon)
3202 return -EOPNOTSUPP;
3203
3204 if (!wdev->beacon_interval)
3205 return -EINVAL;
3206
3207 err = nl80211_parse_beacon(info, &params);
3208 if (err)
3209 return err;
3210
Hila Gonene35e4d22012-06-27 17:19:42 +03003211 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003212}
3213
3214static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003215{
Johannes Berg4c476992010-10-04 21:36:35 +02003216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3217 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003218
Michal Kazior60771782012-06-29 12:46:56 +02003219 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003220}
3221
Johannes Berg5727ef12007-12-19 02:03:34 +01003222static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3223 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3224 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3225 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003226 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003227 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003228 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003229};
3230
Johannes Bergeccb8e82009-05-11 21:57:56 +03003231static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003232 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003233 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003234{
3235 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003236 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003237 int flag;
3238
Johannes Bergeccb8e82009-05-11 21:57:56 +03003239 /*
3240 * Try parsing the new attribute first so userspace
3241 * can specify both for older kernels.
3242 */
3243 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3244 if (nla) {
3245 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003246
Johannes Bergeccb8e82009-05-11 21:57:56 +03003247 sta_flags = nla_data(nla);
3248 params->sta_flags_mask = sta_flags->mask;
3249 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003250 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003251 if ((params->sta_flags_mask |
3252 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3253 return -EINVAL;
3254 return 0;
3255 }
3256
3257 /* if present, parse the old attribute */
3258
3259 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003260 if (!nla)
3261 return 0;
3262
3263 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3264 nla, sta_flags_policy))
3265 return -EINVAL;
3266
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003267 /*
3268 * Only allow certain flags for interface types so that
3269 * other attributes are silently ignored. Remember that
3270 * this is backward compatibility code with old userspace
3271 * and shouldn't be hit in other cases anyway.
3272 */
3273 switch (iftype) {
3274 case NL80211_IFTYPE_AP:
3275 case NL80211_IFTYPE_AP_VLAN:
3276 case NL80211_IFTYPE_P2P_GO:
3277 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3278 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3279 BIT(NL80211_STA_FLAG_WME) |
3280 BIT(NL80211_STA_FLAG_MFP);
3281 break;
3282 case NL80211_IFTYPE_P2P_CLIENT:
3283 case NL80211_IFTYPE_STATION:
3284 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3285 BIT(NL80211_STA_FLAG_TDLS_PEER);
3286 break;
3287 case NL80211_IFTYPE_MESH_POINT:
3288 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3289 BIT(NL80211_STA_FLAG_MFP) |
3290 BIT(NL80211_STA_FLAG_AUTHORIZED);
3291 default:
3292 return -EINVAL;
3293 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003294
Johannes Berg3383b5a2012-05-10 20:14:43 +02003295 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3296 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003297 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003298
Johannes Berg3383b5a2012-05-10 20:14:43 +02003299 /* no longer support new API additions in old API */
3300 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3301 return -EINVAL;
3302 }
3303 }
3304
Johannes Berg5727ef12007-12-19 02:03:34 +01003305 return 0;
3306}
3307
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003308static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3309 int attr)
3310{
3311 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003312 u32 bitrate;
3313 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003314
3315 rate = nla_nest_start(msg, attr);
3316 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003317 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003318
3319 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3320 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003321 /* report 16-bit bitrate only if we can */
3322 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003323 if (bitrate > 0 &&
3324 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3325 return false;
3326 if (bitrate_compat > 0 &&
3327 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3328 return false;
3329
3330 if (info->flags & RATE_INFO_FLAGS_MCS) {
3331 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3332 return false;
3333 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3334 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3335 return false;
3336 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3337 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3338 return false;
3339 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3340 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3341 return false;
3342 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3343 return false;
3344 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3345 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3346 return false;
3347 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3348 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3349 return false;
3350 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3351 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3352 return false;
3353 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3354 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3355 return false;
3356 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3357 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3358 return false;
3359 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003360
3361 nla_nest_end(msg, rate);
3362 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003363}
3364
Eric W. Biederman15e47302012-09-07 20:12:54 +00003365static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003366 int flags,
3367 struct cfg80211_registered_device *rdev,
3368 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003369 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003370{
3371 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003372 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003373
Eric W. Biederman15e47302012-09-07 20:12:54 +00003374 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003375 if (!hdr)
3376 return -1;
3377
David S. Miller9360ffd2012-03-29 04:41:26 -04003378 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3379 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3380 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3381 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003382
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003383 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3384 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003385 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003386 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3387 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3388 sinfo->connected_time))
3389 goto nla_put_failure;
3390 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3391 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3392 sinfo->inactive_time))
3393 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003394 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3395 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003396 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003397 (u32)sinfo->rx_bytes))
3398 goto nla_put_failure;
3399 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3400 NL80211_STA_INFO_TX_BYTES64)) &&
3401 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3402 (u32)sinfo->tx_bytes))
3403 goto nla_put_failure;
3404 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3405 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003406 sinfo->rx_bytes))
3407 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003408 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3409 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003410 sinfo->tx_bytes))
3411 goto nla_put_failure;
3412 if ((sinfo->filled & STATION_INFO_LLID) &&
3413 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3414 goto nla_put_failure;
3415 if ((sinfo->filled & STATION_INFO_PLID) &&
3416 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3417 goto nla_put_failure;
3418 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3419 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3420 sinfo->plink_state))
3421 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003422 switch (rdev->wiphy.signal_type) {
3423 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003424 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3425 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3426 sinfo->signal))
3427 goto nla_put_failure;
3428 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3429 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3430 sinfo->signal_avg))
3431 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003432 break;
3433 default:
3434 break;
3435 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003436 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003437 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3438 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003439 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003440 }
3441 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3442 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3443 NL80211_STA_INFO_RX_BITRATE))
3444 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003445 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003446 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3447 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3448 sinfo->rx_packets))
3449 goto nla_put_failure;
3450 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3451 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3452 sinfo->tx_packets))
3453 goto nla_put_failure;
3454 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3455 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3456 sinfo->tx_retries))
3457 goto nla_put_failure;
3458 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3459 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3460 sinfo->tx_failed))
3461 goto nla_put_failure;
3462 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3463 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3464 sinfo->beacon_loss_count))
3465 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003466 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3467 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3468 sinfo->local_pm))
3469 goto nla_put_failure;
3470 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3471 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3472 sinfo->peer_pm))
3473 goto nla_put_failure;
3474 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3475 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3476 sinfo->nonpeer_pm))
3477 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003478 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3479 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3480 if (!bss_param)
3481 goto nla_put_failure;
3482
David S. Miller9360ffd2012-03-29 04:41:26 -04003483 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3484 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3485 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3486 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3487 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3488 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3489 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3490 sinfo->bss_param.dtim_period) ||
3491 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3492 sinfo->bss_param.beacon_interval))
3493 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003494
3495 nla_nest_end(msg, bss_param);
3496 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003497 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3498 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3499 sizeof(struct nl80211_sta_flag_update),
3500 &sinfo->sta_flags))
3501 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003502 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3503 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3504 sinfo->t_offset))
3505 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003506 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003507
David S. Miller9360ffd2012-03-29 04:41:26 -04003508 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3509 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3510 sinfo->assoc_req_ies))
3511 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003512
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003513 return genlmsg_end(msg, hdr);
3514
3515 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003516 genlmsg_cancel(msg, hdr);
3517 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003518}
3519
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003520static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003521 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003522{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003523 struct station_info sinfo;
3524 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003525 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003527 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003528 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003529
Johannes Berg67748892010-10-04 21:14:06 +02003530 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3531 if (err)
3532 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003533
3534 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003535 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003536 goto out_err;
3537 }
3538
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003540 memset(&sinfo, 0, sizeof(sinfo));
Hila Gonene35e4d22012-06-27 17:19:42 +03003541 err = rdev_dump_station(dev, netdev, sta_idx,
3542 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003543 if (err == -ENOENT)
3544 break;
3545 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003546 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003547
3548 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003549 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003550 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04003551 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003552 &sinfo) < 0)
3553 goto out;
3554
3555 sta_idx++;
3556 }
3557
3558
3559 out:
3560 cb->args[1] = sta_idx;
3561 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003562 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003563 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003564
3565 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003566}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003567
Johannes Berg5727ef12007-12-19 02:03:34 +01003568static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3569{
Johannes Berg4c476992010-10-04 21:36:35 +02003570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3571 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003572 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003573 struct sk_buff *msg;
3574 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003575 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003576
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003577 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003578
3579 if (!info->attrs[NL80211_ATTR_MAC])
3580 return -EINVAL;
3581
3582 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3583
Johannes Berg4c476992010-10-04 21:36:35 +02003584 if (!rdev->ops->get_station)
3585 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003586
Hila Gonene35e4d22012-06-27 17:19:42 +03003587 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003588 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003589 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003590
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003592 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003593 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003594
Eric W. Biederman15e47302012-09-07 20:12:54 +00003595 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003596 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003597 nlmsg_free(msg);
3598 return -ENOBUFS;
3599 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003600
Johannes Berg4c476992010-10-04 21:36:35 +02003601 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003602}
3603
Johannes Berg77ee7c82013-02-15 00:48:33 +01003604int cfg80211_check_station_change(struct wiphy *wiphy,
3605 struct station_parameters *params,
3606 enum cfg80211_station_type statype)
3607{
3608 if (params->listen_interval != -1)
3609 return -EINVAL;
3610 if (params->aid)
3611 return -EINVAL;
3612
3613 /* When you run into this, adjust the code below for the new flag */
3614 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3615
3616 switch (statype) {
3617 case CFG80211_STA_MESH_PEER_NONSEC:
3618 case CFG80211_STA_MESH_PEER_SECURE:
3619 /*
3620 * No ignoring the TDLS flag here -- the userspace mesh
3621 * code doesn't have the bug of including TDLS in the
3622 * mask everywhere.
3623 */
3624 if (params->sta_flags_mask &
3625 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3626 BIT(NL80211_STA_FLAG_MFP) |
3627 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3628 return -EINVAL;
3629 break;
3630 case CFG80211_STA_TDLS_PEER_SETUP:
3631 case CFG80211_STA_TDLS_PEER_ACTIVE:
3632 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3633 return -EINVAL;
3634 /* ignore since it can't change */
3635 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3636 break;
3637 default:
3638 /* disallow mesh-specific things */
3639 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3640 return -EINVAL;
3641 if (params->local_pm)
3642 return -EINVAL;
3643 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3644 return -EINVAL;
3645 }
3646
3647 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3648 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3649 /* TDLS can't be set, ... */
3650 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3651 return -EINVAL;
3652 /*
3653 * ... but don't bother the driver with it. This works around
3654 * a hostapd/wpa_supplicant issue -- it always includes the
3655 * TLDS_PEER flag in the mask even for AP mode.
3656 */
3657 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3658 }
3659
3660 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3661 /* reject other things that can't change */
3662 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3663 return -EINVAL;
3664 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3665 return -EINVAL;
3666 if (params->supported_rates)
3667 return -EINVAL;
3668 if (params->ext_capab || params->ht_capa || params->vht_capa)
3669 return -EINVAL;
3670 }
3671
3672 if (statype != CFG80211_STA_AP_CLIENT) {
3673 if (params->vlan)
3674 return -EINVAL;
3675 }
3676
3677 switch (statype) {
3678 case CFG80211_STA_AP_MLME_CLIENT:
3679 /* Use this only for authorizing/unauthorizing a station */
3680 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3681 return -EOPNOTSUPP;
3682 break;
3683 case CFG80211_STA_AP_CLIENT:
3684 /* accept only the listed bits */
3685 if (params->sta_flags_mask &
3686 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3687 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3688 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3689 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3690 BIT(NL80211_STA_FLAG_WME) |
3691 BIT(NL80211_STA_FLAG_MFP)))
3692 return -EINVAL;
3693
3694 /* but authenticated/associated only if driver handles it */
3695 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3696 params->sta_flags_mask &
3697 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3698 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3699 return -EINVAL;
3700 break;
3701 case CFG80211_STA_IBSS:
3702 case CFG80211_STA_AP_STA:
3703 /* reject any changes other than AUTHORIZED */
3704 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3705 return -EINVAL;
3706 break;
3707 case CFG80211_STA_TDLS_PEER_SETUP:
3708 /* reject any changes other than AUTHORIZED or WME */
3709 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3710 BIT(NL80211_STA_FLAG_WME)))
3711 return -EINVAL;
3712 /* force (at least) rates when authorizing */
3713 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3714 !params->supported_rates)
3715 return -EINVAL;
3716 break;
3717 case CFG80211_STA_TDLS_PEER_ACTIVE:
3718 /* reject any changes */
3719 return -EINVAL;
3720 case CFG80211_STA_MESH_PEER_NONSEC:
3721 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3722 return -EINVAL;
3723 break;
3724 case CFG80211_STA_MESH_PEER_SECURE:
3725 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3726 return -EINVAL;
3727 break;
3728 }
3729
3730 return 0;
3731}
3732EXPORT_SYMBOL(cfg80211_check_station_change);
3733
Johannes Berg5727ef12007-12-19 02:03:34 +01003734/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003735 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003736 */
Johannes Berg80b99892011-11-18 16:23:01 +01003737static struct net_device *get_vlan(struct genl_info *info,
3738 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003739{
Johannes Berg463d0182009-07-14 00:33:35 +02003740 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003741 struct net_device *v;
3742 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003743
Johannes Berg80b99892011-11-18 16:23:01 +01003744 if (!vlanattr)
3745 return NULL;
3746
3747 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3748 if (!v)
3749 return ERR_PTR(-ENODEV);
3750
3751 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3752 ret = -EINVAL;
3753 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003754 }
Johannes Berg80b99892011-11-18 16:23:01 +01003755
Johannes Berg77ee7c82013-02-15 00:48:33 +01003756 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3757 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3758 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3759 ret = -EINVAL;
3760 goto error;
3761 }
3762
Johannes Berg80b99892011-11-18 16:23:01 +01003763 if (!netif_running(v)) {
3764 ret = -ENETDOWN;
3765 goto error;
3766 }
3767
3768 return v;
3769 error:
3770 dev_put(v);
3771 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003772}
3773
Jouni Malinendf881292013-02-14 21:10:54 +02003774static struct nla_policy
3775nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3776 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3777 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3778};
3779
Johannes Bergff276692013-02-15 00:09:01 +01003780static int nl80211_parse_sta_wme(struct genl_info *info,
3781 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003782{
Jouni Malinendf881292013-02-14 21:10:54 +02003783 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3784 struct nlattr *nla;
3785 int err;
3786
Jouni Malinendf881292013-02-14 21:10:54 +02003787 /* parse WME attributes if present */
3788 if (!info->attrs[NL80211_ATTR_STA_WME])
3789 return 0;
3790
3791 nla = info->attrs[NL80211_ATTR_STA_WME];
3792 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3793 nl80211_sta_wme_policy);
3794 if (err)
3795 return err;
3796
3797 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3798 params->uapsd_queues = nla_get_u8(
3799 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3800 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3801 return -EINVAL;
3802
3803 if (tb[NL80211_STA_WME_MAX_SP])
3804 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3805
3806 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3807 return -EINVAL;
3808
3809 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3810
3811 return 0;
3812}
3813
Johannes Bergff276692013-02-15 00:09:01 +01003814static int nl80211_set_station_tdls(struct genl_info *info,
3815 struct station_parameters *params)
3816{
3817 /* Dummy STA entry gets updated once the peer capabilities are known */
3818 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3819 params->ht_capa =
3820 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3821 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3822 params->vht_capa =
3823 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3824
3825 return nl80211_parse_sta_wme(info, params);
3826}
3827
Johannes Berg5727ef12007-12-19 02:03:34 +01003828static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3829{
Johannes Berg4c476992010-10-04 21:36:35 +02003830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003831 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003832 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003833 u8 *mac_addr;
3834 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003835
3836 memset(&params, 0, sizeof(params));
3837
3838 params.listen_interval = -1;
3839
Johannes Berg77ee7c82013-02-15 00:48:33 +01003840 if (!rdev->ops->change_station)
3841 return -EOPNOTSUPP;
3842
Johannes Berg5727ef12007-12-19 02:03:34 +01003843 if (info->attrs[NL80211_ATTR_STA_AID])
3844 return -EINVAL;
3845
3846 if (!info->attrs[NL80211_ATTR_MAC])
3847 return -EINVAL;
3848
3849 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3850
3851 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3852 params.supported_rates =
3853 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3854 params.supported_rates_len =
3855 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3856 }
3857
Jouni Malinen9d62a982013-02-14 21:10:13 +02003858 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3859 params.capability =
3860 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3861 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3862 }
3863
3864 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3865 params.ext_capab =
3866 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3867 params.ext_capab_len =
3868 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3869 }
3870
Jouni Malinendf881292013-02-14 21:10:54 +02003871 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003872 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003873
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003874 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003875 return -EINVAL;
3876
Johannes Bergf8bacc22013-02-14 23:27:01 +01003877 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003878 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003879 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3880 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3881 return -EINVAL;
3882 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003883
Johannes Bergf8bacc22013-02-14 23:27:01 +01003884 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003885 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003886 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3887 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3888 return -EINVAL;
3889 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3890 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003891
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003892 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3893 enum nl80211_mesh_power_mode pm = nla_get_u32(
3894 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3895
3896 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3897 pm > NL80211_MESH_POWER_MAX)
3898 return -EINVAL;
3899
3900 params.local_pm = pm;
3901 }
3902
Johannes Berg77ee7c82013-02-15 00:48:33 +01003903 /* Include parameters for TDLS peer (will check later) */
3904 err = nl80211_set_station_tdls(info, &params);
3905 if (err)
3906 return err;
3907
3908 params.vlan = get_vlan(info, rdev);
3909 if (IS_ERR(params.vlan))
3910 return PTR_ERR(params.vlan);
3911
Johannes Berga97f4422009-06-18 17:23:43 +02003912 switch (dev->ieee80211_ptr->iftype) {
3913 case NL80211_IFTYPE_AP:
3914 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003915 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003916 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003917 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003918 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003919 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003920 break;
3921 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003922 err = -EOPNOTSUPP;
3923 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003924 }
3925
Johannes Berg77ee7c82013-02-15 00:48:33 +01003926 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003927 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003928
Johannes Berg77ee7c82013-02-15 00:48:33 +01003929 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003930 if (params.vlan)
3931 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003932
Johannes Berg5727ef12007-12-19 02:03:34 +01003933 return err;
3934}
3935
3936static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3937{
Johannes Berg4c476992010-10-04 21:36:35 +02003938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003939 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003940 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003941 struct station_parameters params;
3942 u8 *mac_addr = NULL;
3943
3944 memset(&params, 0, sizeof(params));
3945
Johannes Berg984c3112013-02-14 23:43:25 +01003946 if (!rdev->ops->add_station)
3947 return -EOPNOTSUPP;
3948
Johannes Berg5727ef12007-12-19 02:03:34 +01003949 if (!info->attrs[NL80211_ATTR_MAC])
3950 return -EINVAL;
3951
Johannes Berg5727ef12007-12-19 02:03:34 +01003952 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3953 return -EINVAL;
3954
3955 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3956 return -EINVAL;
3957
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003958 if (!info->attrs[NL80211_ATTR_STA_AID])
3959 return -EINVAL;
3960
Johannes Berg5727ef12007-12-19 02:03:34 +01003961 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3962 params.supported_rates =
3963 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3964 params.supported_rates_len =
3965 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3966 params.listen_interval =
3967 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003968
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003969 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3970 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3971 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003972
Jouni Malinen9d62a982013-02-14 21:10:13 +02003973 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3974 params.capability =
3975 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3976 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3977 }
3978
3979 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3980 params.ext_capab =
3981 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3982 params.ext_capab_len =
3983 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3984 }
3985
Jouni Malinen36aedc92008-08-25 11:58:58 +03003986 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3987 params.ht_capa =
3988 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003989
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003990 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3991 params.vht_capa =
3992 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3993
Johannes Bergf8bacc22013-02-14 23:27:01 +01003994 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07003995 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003996 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3997 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3998 return -EINVAL;
3999 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004000
Johannes Bergff276692013-02-15 00:09:01 +01004001 err = nl80211_parse_sta_wme(info, &params);
4002 if (err)
4003 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004004
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004005 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004006 return -EINVAL;
4007
Johannes Berg77ee7c82013-02-15 00:48:33 +01004008 /* When you run into this, adjust the code below for the new flag */
4009 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4010
Johannes Bergbdd90d52011-12-14 12:20:27 +01004011 switch (dev->ieee80211_ptr->iftype) {
4012 case NL80211_IFTYPE_AP:
4013 case NL80211_IFTYPE_AP_VLAN:
4014 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004015 /* ignore WME attributes if iface/sta is not capable */
4016 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4017 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4018 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004019
Johannes Bergbdd90d52011-12-14 12:20:27 +01004020 /* TDLS peers cannot be added */
4021 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004022 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004023 /* but don't bother the driver with it */
4024 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004025
Johannes Bergd582cff2012-10-26 17:53:44 +02004026 /* allow authenticated/associated only if driver handles it */
4027 if (!(rdev->wiphy.features &
4028 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4029 params.sta_flags_mask &
4030 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4031 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4032 return -EINVAL;
4033
Johannes Bergbdd90d52011-12-14 12:20:27 +01004034 /* must be last in here for error handling */
4035 params.vlan = get_vlan(info, rdev);
4036 if (IS_ERR(params.vlan))
4037 return PTR_ERR(params.vlan);
4038 break;
4039 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004040 /* ignore uAPSD data */
4041 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4042
Johannes Bergd582cff2012-10-26 17:53:44 +02004043 /* associated is disallowed */
4044 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4045 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004046 /* TDLS peers cannot be added */
4047 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004048 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004049 break;
4050 case NL80211_IFTYPE_STATION:
Johannes Berg984c3112013-02-14 23:43:25 +01004051 /* ignore uAPSD data */
4052 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4053
Johannes Berg77ee7c82013-02-15 00:48:33 +01004054 /* these are disallowed */
4055 if (params.sta_flags_mask &
4056 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4057 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004058 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004059 /* Only TDLS peers can be added */
4060 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4061 return -EINVAL;
4062 /* Can only add if TDLS ... */
4063 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4064 return -EOPNOTSUPP;
4065 /* ... with external setup is supported */
4066 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4067 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004068 /*
4069 * Older wpa_supplicant versions always mark the TDLS peer
4070 * as authorized, but it shouldn't yet be.
4071 */
4072 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004073 break;
4074 default:
4075 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004076 }
4077
Johannes Bergbdd90d52011-12-14 12:20:27 +01004078 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004079
Hila Gonene35e4d22012-06-27 17:19:42 +03004080 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004081
Johannes Berg5727ef12007-12-19 02:03:34 +01004082 if (params.vlan)
4083 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004084 return err;
4085}
4086
4087static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4088{
Johannes Berg4c476992010-10-04 21:36:35 +02004089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4090 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004091 u8 *mac_addr = NULL;
4092
4093 if (info->attrs[NL80211_ATTR_MAC])
4094 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4095
Johannes Berge80cf852009-05-11 14:43:13 +02004096 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004097 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004098 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004099 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4100 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004101
Johannes Berg4c476992010-10-04 21:36:35 +02004102 if (!rdev->ops->del_station)
4103 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004104
Hila Gonene35e4d22012-06-27 17:19:42 +03004105 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004106}
4107
Eric W. Biederman15e47302012-09-07 20:12:54 +00004108static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004109 int flags, struct net_device *dev,
4110 u8 *dst, u8 *next_hop,
4111 struct mpath_info *pinfo)
4112{
4113 void *hdr;
4114 struct nlattr *pinfoattr;
4115
Eric W. Biederman15e47302012-09-07 20:12:54 +00004116 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004117 if (!hdr)
4118 return -1;
4119
David S. Miller9360ffd2012-03-29 04:41:26 -04004120 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4121 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4122 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4123 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4124 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004125
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004126 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4127 if (!pinfoattr)
4128 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004129 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4130 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4131 pinfo->frame_qlen))
4132 goto nla_put_failure;
4133 if (((pinfo->filled & MPATH_INFO_SN) &&
4134 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4135 ((pinfo->filled & MPATH_INFO_METRIC) &&
4136 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4137 pinfo->metric)) ||
4138 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4139 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4140 pinfo->exptime)) ||
4141 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4142 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4143 pinfo->flags)) ||
4144 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4145 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4146 pinfo->discovery_timeout)) ||
4147 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4148 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4149 pinfo->discovery_retries)))
4150 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004151
4152 nla_nest_end(msg, pinfoattr);
4153
4154 return genlmsg_end(msg, hdr);
4155
4156 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004157 genlmsg_cancel(msg, hdr);
4158 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004159}
4160
4161static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004162 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004163{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004164 struct mpath_info pinfo;
4165 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004166 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004167 u8 dst[ETH_ALEN];
4168 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02004169 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004170 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004171
Johannes Berg67748892010-10-04 21:14:06 +02004172 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4173 if (err)
4174 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004175
4176 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004177 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004178 goto out_err;
4179 }
4180
Jouni Malineneec60b02009-03-20 21:21:19 +02004181 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
4182 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004183 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004184 }
4185
Johannes Bergbba95fe2008-07-29 13:22:51 +02004186 while (1) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004187 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
4188 &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004189 if (err == -ENOENT)
4190 break;
4191 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004192 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004193
Eric W. Biederman15e47302012-09-07 20:12:54 +00004194 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004195 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4196 netdev, dst, next_hop,
4197 &pinfo) < 0)
4198 goto out;
4199
4200 path_idx++;
4201 }
4202
4203
4204 out:
4205 cb->args[1] = path_idx;
4206 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004207 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004208 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004209 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004210}
4211
4212static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4213{
Johannes Berg4c476992010-10-04 21:36:35 +02004214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004215 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004216 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004217 struct mpath_info pinfo;
4218 struct sk_buff *msg;
4219 u8 *dst = NULL;
4220 u8 next_hop[ETH_ALEN];
4221
4222 memset(&pinfo, 0, sizeof(pinfo));
4223
4224 if (!info->attrs[NL80211_ATTR_MAC])
4225 return -EINVAL;
4226
4227 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4228
Johannes Berg4c476992010-10-04 21:36:35 +02004229 if (!rdev->ops->get_mpath)
4230 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004231
Johannes Berg4c476992010-10-04 21:36:35 +02004232 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4233 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004234
Hila Gonene35e4d22012-06-27 17:19:42 +03004235 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004236 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004237 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004238
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004240 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004241 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004242
Eric W. Biederman15e47302012-09-07 20:12:54 +00004243 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004244 dev, dst, next_hop, &pinfo) < 0) {
4245 nlmsg_free(msg);
4246 return -ENOBUFS;
4247 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004248
Johannes Berg4c476992010-10-04 21:36:35 +02004249 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004250}
4251
4252static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4253{
Johannes Berg4c476992010-10-04 21:36:35 +02004254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4255 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004256 u8 *dst = NULL;
4257 u8 *next_hop = NULL;
4258
4259 if (!info->attrs[NL80211_ATTR_MAC])
4260 return -EINVAL;
4261
4262 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4263 return -EINVAL;
4264
4265 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4266 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4267
Johannes Berg4c476992010-10-04 21:36:35 +02004268 if (!rdev->ops->change_mpath)
4269 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004270
Johannes Berg4c476992010-10-04 21:36:35 +02004271 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4272 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004273
Hila Gonene35e4d22012-06-27 17:19:42 +03004274 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004275}
Johannes Berg4c476992010-10-04 21:36:35 +02004276
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004277static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4278{
Johannes Berg4c476992010-10-04 21:36:35 +02004279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4280 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004281 u8 *dst = NULL;
4282 u8 *next_hop = NULL;
4283
4284 if (!info->attrs[NL80211_ATTR_MAC])
4285 return -EINVAL;
4286
4287 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4288 return -EINVAL;
4289
4290 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4291 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4292
Johannes Berg4c476992010-10-04 21:36:35 +02004293 if (!rdev->ops->add_mpath)
4294 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004295
Johannes Berg4c476992010-10-04 21:36:35 +02004296 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4297 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004298
Hila Gonene35e4d22012-06-27 17:19:42 +03004299 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004300}
4301
4302static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4303{
Johannes Berg4c476992010-10-04 21:36:35 +02004304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4305 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004306 u8 *dst = NULL;
4307
4308 if (info->attrs[NL80211_ATTR_MAC])
4309 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4310
Johannes Berg4c476992010-10-04 21:36:35 +02004311 if (!rdev->ops->del_mpath)
4312 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004313
Hila Gonene35e4d22012-06-27 17:19:42 +03004314 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004315}
4316
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004317static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4318{
Johannes Berg4c476992010-10-04 21:36:35 +02004319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4320 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004321 struct bss_parameters params;
4322
4323 memset(&params, 0, sizeof(params));
4324 /* default to not changing parameters */
4325 params.use_cts_prot = -1;
4326 params.use_short_preamble = -1;
4327 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004328 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004329 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004330 params.p2p_ctwindow = -1;
4331 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004332
4333 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4334 params.use_cts_prot =
4335 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4336 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4337 params.use_short_preamble =
4338 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4339 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4340 params.use_short_slot_time =
4341 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004342 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4343 params.basic_rates =
4344 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4345 params.basic_rates_len =
4346 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4347 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004348 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4349 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004350 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4351 params.ht_opmode =
4352 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004353
Johannes Berg53cabad2012-11-14 15:17:28 +01004354 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4355 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4356 return -EINVAL;
4357 params.p2p_ctwindow =
4358 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4359 if (params.p2p_ctwindow < 0)
4360 return -EINVAL;
4361 if (params.p2p_ctwindow != 0 &&
4362 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4363 return -EINVAL;
4364 }
4365
4366 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4367 u8 tmp;
4368
4369 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4370 return -EINVAL;
4371 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4372 if (tmp > 1)
4373 return -EINVAL;
4374 params.p2p_opp_ps = tmp;
4375 if (params.p2p_opp_ps &&
4376 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4377 return -EINVAL;
4378 }
4379
Johannes Berg4c476992010-10-04 21:36:35 +02004380 if (!rdev->ops->change_bss)
4381 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004382
Johannes Berg074ac8d2010-09-16 14:58:22 +02004383 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004384 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4385 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004386
Hila Gonene35e4d22012-06-27 17:19:42 +03004387 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004388}
4389
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004390static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004391 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4392 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4393 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4394 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4395 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4396 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4397};
4398
4399static int parse_reg_rule(struct nlattr *tb[],
4400 struct ieee80211_reg_rule *reg_rule)
4401{
4402 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4403 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4404
4405 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4406 return -EINVAL;
4407 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4408 return -EINVAL;
4409 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4410 return -EINVAL;
4411 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4412 return -EINVAL;
4413 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4414 return -EINVAL;
4415
4416 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4417
4418 freq_range->start_freq_khz =
4419 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4420 freq_range->end_freq_khz =
4421 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4422 freq_range->max_bandwidth_khz =
4423 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4424
4425 power_rule->max_eirp =
4426 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4427
4428 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4429 power_rule->max_antenna_gain =
4430 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4431
4432 return 0;
4433}
4434
4435static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4436{
4437 int r;
4438 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004439 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004440
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004441 /*
4442 * You should only get this when cfg80211 hasn't yet initialized
4443 * completely when built-in to the kernel right between the time
4444 * window between nl80211_init() and regulatory_init(), if that is
4445 * even possible.
4446 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004447 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004448 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004449
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004450 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4451 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004452
4453 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4454
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004455 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4456 user_reg_hint_type =
4457 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4458 else
4459 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4460
4461 switch (user_reg_hint_type) {
4462 case NL80211_USER_REG_HINT_USER:
4463 case NL80211_USER_REG_HINT_CELL_BASE:
4464 break;
4465 default:
4466 return -EINVAL;
4467 }
4468
4469 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004470
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004471 return r;
4472}
4473
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004474static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004475 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004476{
Johannes Berg4c476992010-10-04 21:36:35 +02004477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004478 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004479 struct wireless_dev *wdev = dev->ieee80211_ptr;
4480 struct mesh_config cur_params;
4481 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004482 void *hdr;
4483 struct nlattr *pinfoattr;
4484 struct sk_buff *msg;
4485
Johannes Berg29cbe682010-12-03 09:20:44 +01004486 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4487 return -EOPNOTSUPP;
4488
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004489 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004490 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004491
Johannes Berg29cbe682010-12-03 09:20:44 +01004492 wdev_lock(wdev);
4493 /* If not connected, get default parameters */
4494 if (!wdev->mesh_id_len)
4495 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4496 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004497 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004498 wdev_unlock(wdev);
4499
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004500 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004501 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004502
4503 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004504 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004505 if (!msg)
4506 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004507 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004508 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004509 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004510 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004511 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004512 if (!pinfoattr)
4513 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004514 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4515 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4516 cur_params.dot11MeshRetryTimeout) ||
4517 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4518 cur_params.dot11MeshConfirmTimeout) ||
4519 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4520 cur_params.dot11MeshHoldingTimeout) ||
4521 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4522 cur_params.dot11MeshMaxPeerLinks) ||
4523 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4524 cur_params.dot11MeshMaxRetries) ||
4525 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4526 cur_params.dot11MeshTTL) ||
4527 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4528 cur_params.element_ttl) ||
4529 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4530 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004531 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4532 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004533 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4534 cur_params.dot11MeshHWMPmaxPREQretries) ||
4535 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4536 cur_params.path_refresh_time) ||
4537 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4538 cur_params.min_discovery_timeout) ||
4539 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4540 cur_params.dot11MeshHWMPactivePathTimeout) ||
4541 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4542 cur_params.dot11MeshHWMPpreqMinInterval) ||
4543 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4544 cur_params.dot11MeshHWMPperrMinInterval) ||
4545 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4546 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4547 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4548 cur_params.dot11MeshHWMPRootMode) ||
4549 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4550 cur_params.dot11MeshHWMPRannInterval) ||
4551 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4552 cur_params.dot11MeshGateAnnouncementProtocol) ||
4553 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4554 cur_params.dot11MeshForwarding) ||
4555 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004556 cur_params.rssi_threshold) ||
4557 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004558 cur_params.ht_opmode) ||
4559 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4560 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4561 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004562 cur_params.dot11MeshHWMProotInterval) ||
4563 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004564 cur_params.dot11MeshHWMPconfirmationInterval) ||
4565 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4566 cur_params.power_mode) ||
4567 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4568 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004569 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004570 nla_nest_end(msg, pinfoattr);
4571 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004572 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004573
Johannes Berg3b858752009-03-12 09:55:09 +01004574 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004575 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004576 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004577 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004578 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004579}
4580
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004581static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004582 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4583 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4584 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4585 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4586 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4587 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004588 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004589 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004590 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004591 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4592 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4593 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4594 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4595 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004596 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004597 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004598 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004599 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004600 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004601 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004602 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4603 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004604 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4605 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004606 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004607 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4608 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004609};
4610
Javier Cardonac80d5452010-12-16 17:37:49 -08004611static const struct nla_policy
4612 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004613 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004614 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4615 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004616 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004617 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004618 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004619 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004620};
4621
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004622static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004623 struct mesh_config *cfg,
4624 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004625{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004626 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004627 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004628
Marco Porschea54fba2013-01-07 16:04:48 +01004629#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4630do { \
4631 if (tb[attr]) { \
4632 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4633 return -EINVAL; \
4634 cfg->param = fn(tb[attr]); \
4635 mask |= (1 << (attr - 1)); \
4636 } \
4637} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004638
4639
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004640 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004641 return -EINVAL;
4642 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004643 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004644 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004645 return -EINVAL;
4646
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004647 /* This makes sure that there aren't more than 32 mesh config
4648 * parameters (otherwise our bitfield scheme would not work.) */
4649 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4650
4651 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004652 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004653 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4654 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004655 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004656 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4657 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004658 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004659 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4660 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004661 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004662 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4663 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004664 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004665 mask, NL80211_MESHCONF_MAX_RETRIES,
4666 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004667 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004668 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004669 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004670 mask, NL80211_MESHCONF_ELEMENT_TTL,
4671 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004673 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4674 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4676 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004677 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4678 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004679 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004680 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4681 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004682 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004683 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4684 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004685 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004686 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4687 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004688 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4689 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004690 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4691 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004693 1, 65535, mask,
4694 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004695 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004696 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004697 1, 65535, mask,
4698 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004699 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004701 dot11MeshHWMPnetDiameterTraversalTime,
4702 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004703 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4704 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4706 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4707 nla_get_u8);
4708 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4709 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004710 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004711 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004712 dot11MeshGateAnnouncementProtocol, 0, 1,
4713 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004714 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004715 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004716 mask, NL80211_MESHCONF_FORWARDING,
4717 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004719 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4720 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004721 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004722 mask, NL80211_MESHCONF_HT_OPMODE,
4723 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004724 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004725 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004726 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4727 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004728 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004729 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4730 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004731 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004732 dot11MeshHWMPconfirmationInterval,
4733 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004734 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4735 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004736 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4737 NL80211_MESH_POWER_ACTIVE,
4738 NL80211_MESH_POWER_MAX,
4739 mask, NL80211_MESHCONF_POWER_MODE,
4740 nla_get_u32);
4741 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4742 0, 65535, mask,
4743 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004744 if (mask_out)
4745 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004746
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004747 return 0;
4748
4749#undef FILL_IN_MESH_PARAM_IF_SET
4750}
4751
Javier Cardonac80d5452010-12-16 17:37:49 -08004752static int nl80211_parse_mesh_setup(struct genl_info *info,
4753 struct mesh_setup *setup)
4754{
4755 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4756
4757 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4758 return -EINVAL;
4759 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4760 info->attrs[NL80211_ATTR_MESH_SETUP],
4761 nl80211_mesh_setup_params_policy))
4762 return -EINVAL;
4763
Javier Cardonad299a1f2012-03-31 11:31:33 -07004764 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4765 setup->sync_method =
4766 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4767 IEEE80211_SYNC_METHOD_VENDOR :
4768 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4769
Javier Cardonac80d5452010-12-16 17:37:49 -08004770 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4771 setup->path_sel_proto =
4772 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4773 IEEE80211_PATH_PROTOCOL_VENDOR :
4774 IEEE80211_PATH_PROTOCOL_HWMP;
4775
4776 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4777 setup->path_metric =
4778 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4779 IEEE80211_PATH_METRIC_VENDOR :
4780 IEEE80211_PATH_METRIC_AIRTIME;
4781
Javier Cardona581a8b02011-04-07 15:08:27 -07004782
4783 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004784 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004785 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004786 if (!is_valid_ie_attr(ieattr))
4787 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004788 setup->ie = nla_data(ieattr);
4789 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004790 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07004791 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4792 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08004793
4794 return 0;
4795}
4796
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004797static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004798 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004799{
4800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4801 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004802 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004803 struct mesh_config cfg;
4804 u32 mask;
4805 int err;
4806
Johannes Berg29cbe682010-12-03 09:20:44 +01004807 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4808 return -EOPNOTSUPP;
4809
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004810 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004811 return -EOPNOTSUPP;
4812
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004813 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004814 if (err)
4815 return err;
4816
Johannes Berg29cbe682010-12-03 09:20:44 +01004817 wdev_lock(wdev);
4818 if (!wdev->mesh_id_len)
4819 err = -ENOLINK;
4820
4821 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004822 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004823
4824 wdev_unlock(wdev);
4825
4826 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004827}
4828
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004829static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4830{
Johannes Berg458f4f92012-12-06 15:47:38 +01004831 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004832 struct sk_buff *msg;
4833 void *hdr = NULL;
4834 struct nlattr *nl_reg_rules;
4835 unsigned int i;
4836 int err = -EINVAL;
4837
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004838 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004839
4840 if (!cfg80211_regdomain)
4841 goto out;
4842
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004843 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004844 if (!msg) {
4845 err = -ENOBUFS;
4846 goto out;
4847 }
4848
Eric W. Biederman15e47302012-09-07 20:12:54 +00004849 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004850 NL80211_CMD_GET_REG);
4851 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004852 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004853
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004854 if (reg_last_request_cell_base() &&
4855 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4856 NL80211_USER_REG_HINT_CELL_BASE))
4857 goto nla_put_failure;
4858
Johannes Berg458f4f92012-12-06 15:47:38 +01004859 rcu_read_lock();
4860 regdom = rcu_dereference(cfg80211_regdomain);
4861
4862 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4863 (regdom->dfs_region &&
4864 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4865 goto nla_put_failure_rcu;
4866
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004867 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4868 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004869 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004870
Johannes Berg458f4f92012-12-06 15:47:38 +01004871 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004872 struct nlattr *nl_reg_rule;
4873 const struct ieee80211_reg_rule *reg_rule;
4874 const struct ieee80211_freq_range *freq_range;
4875 const struct ieee80211_power_rule *power_rule;
4876
Johannes Berg458f4f92012-12-06 15:47:38 +01004877 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004878 freq_range = &reg_rule->freq_range;
4879 power_rule = &reg_rule->power_rule;
4880
4881 nl_reg_rule = nla_nest_start(msg, i);
4882 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004883 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004884
David S. Miller9360ffd2012-03-29 04:41:26 -04004885 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4886 reg_rule->flags) ||
4887 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4888 freq_range->start_freq_khz) ||
4889 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4890 freq_range->end_freq_khz) ||
4891 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4892 freq_range->max_bandwidth_khz) ||
4893 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4894 power_rule->max_antenna_gain) ||
4895 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4896 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004897 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004898
4899 nla_nest_end(msg, nl_reg_rule);
4900 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004901 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004902
4903 nla_nest_end(msg, nl_reg_rules);
4904
4905 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004906 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004907 goto out;
4908
Johannes Berg458f4f92012-12-06 15:47:38 +01004909nla_put_failure_rcu:
4910 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004911nla_put_failure:
4912 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004913put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004914 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004915 err = -EMSGSIZE;
4916out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004917 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004918 return err;
4919}
4920
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004921static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4922{
4923 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4924 struct nlattr *nl_reg_rule;
4925 char *alpha2 = NULL;
4926 int rem_reg_rules = 0, r = 0;
4927 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004928 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004929 struct ieee80211_regdomain *rd = NULL;
4930
4931 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4932 return -EINVAL;
4933
4934 if (!info->attrs[NL80211_ATTR_REG_RULES])
4935 return -EINVAL;
4936
4937 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4938
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004939 if (info->attrs[NL80211_ATTR_DFS_REGION])
4940 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4941
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004942 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004943 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004944 num_rules++;
4945 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004946 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004947 }
4948
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004949 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004950 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004951
4952 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004953 if (!rd)
4954 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004955
4956 rd->n_reg_rules = num_rules;
4957 rd->alpha2[0] = alpha2[0];
4958 rd->alpha2[1] = alpha2[1];
4959
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004960 /*
4961 * Disable DFS master mode if the DFS region was
4962 * not supported or known on this kernel.
4963 */
4964 if (reg_supported_dfs_region(dfs_region))
4965 rd->dfs_region = dfs_region;
4966
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004967 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004968 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004969 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004970 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4971 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004972 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4973 if (r)
4974 goto bad_reg;
4975
4976 rule_idx++;
4977
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004978 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4979 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004980 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004981 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004982 }
4983
Johannes Berg6913b492012-12-04 00:48:59 +01004984 mutex_lock(&cfg80211_mutex);
4985
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004986 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01004987 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01004988 rd = NULL;
Johannes Berg6913b492012-12-04 00:48:59 +01004989 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004990
Johannes Bergd2372b32008-10-24 20:32:20 +02004991 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004992 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004993 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004994}
4995
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004996static int validate_scan_freqs(struct nlattr *freqs)
4997{
4998 struct nlattr *attr1, *attr2;
4999 int n_channels = 0, tmp1, tmp2;
5000
5001 nla_for_each_nested(attr1, freqs, tmp1) {
5002 n_channels++;
5003 /*
5004 * Some hardware has a limited channel list for
5005 * scanning, and it is pretty much nonsensical
5006 * to scan for a channel twice, so disallow that
5007 * and don't require drivers to check that the
5008 * channel list they get isn't longer than what
5009 * they can scan, as long as they can scan all
5010 * the channels they registered at once.
5011 */
5012 nla_for_each_nested(attr2, freqs, tmp2)
5013 if (attr1 != attr2 &&
5014 nla_get_u32(attr1) == nla_get_u32(attr2))
5015 return 0;
5016 }
5017
5018 return n_channels;
5019}
5020
Johannes Berg2a519312009-02-10 21:25:55 +01005021static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5022{
Johannes Berg4c476992010-10-04 21:36:35 +02005023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005024 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005025 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005026 struct nlattr *attr;
5027 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005028 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005029 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005030
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005031 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5032 return -EINVAL;
5033
Johannes Berg79c97e92009-07-07 03:56:12 +02005034 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005035
Johannes Berg4c476992010-10-04 21:36:35 +02005036 if (!rdev->ops->scan)
5037 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005038
Johannes Berg4c476992010-10-04 21:36:35 +02005039 if (rdev->scan_req)
5040 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01005041
5042 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005043 n_channels = validate_scan_freqs(
5044 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02005045 if (!n_channels)
5046 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005047 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005048 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005049 n_channels = 0;
5050
Johannes Berg2a519312009-02-10 21:25:55 +01005051 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5052 if (wiphy->bands[band])
5053 n_channels += wiphy->bands[band]->n_channels;
5054 }
5055
5056 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5057 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5058 n_ssids++;
5059
Johannes Berg4c476992010-10-04 21:36:35 +02005060 if (n_ssids > wiphy->max_scan_ssids)
5061 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005062
Jouni Malinen70692ad2009-02-16 19:39:13 +02005063 if (info->attrs[NL80211_ATTR_IE])
5064 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5065 else
5066 ie_len = 0;
5067
Johannes Berg4c476992010-10-04 21:36:35 +02005068 if (ie_len > wiphy->max_scan_ie_len)
5069 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02005070
Johannes Berg2a519312009-02-10 21:25:55 +01005071 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005072 + sizeof(*request->ssids) * n_ssids
5073 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005074 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005075 if (!request)
5076 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01005077
Johannes Berg2a519312009-02-10 21:25:55 +01005078 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005079 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005080 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005081 if (ie_len) {
5082 if (request->ssids)
5083 request->ie = (void *)(request->ssids + n_ssids);
5084 else
5085 request->ie = (void *)(request->channels + n_channels);
5086 }
Johannes Berg2a519312009-02-10 21:25:55 +01005087
Johannes Berg584991d2009-11-02 13:32:03 +01005088 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005089 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5090 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005091 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005092 struct ieee80211_channel *chan;
5093
5094 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5095
5096 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005097 err = -EINVAL;
5098 goto out_free;
5099 }
Johannes Berg584991d2009-11-02 13:32:03 +01005100
5101 /* ignore disabled channels */
5102 if (chan->flags & IEEE80211_CHAN_DISABLED)
5103 continue;
5104
5105 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005106 i++;
5107 }
5108 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005109 enum ieee80211_band band;
5110
Johannes Berg2a519312009-02-10 21:25:55 +01005111 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005112 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5113 int j;
5114 if (!wiphy->bands[band])
5115 continue;
5116 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005117 struct ieee80211_channel *chan;
5118
5119 chan = &wiphy->bands[band]->channels[j];
5120
5121 if (chan->flags & IEEE80211_CHAN_DISABLED)
5122 continue;
5123
5124 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005125 i++;
5126 }
5127 }
5128 }
5129
Johannes Berg584991d2009-11-02 13:32:03 +01005130 if (!i) {
5131 err = -EINVAL;
5132 goto out_free;
5133 }
5134
5135 request->n_channels = i;
5136
Johannes Berg2a519312009-02-10 21:25:55 +01005137 i = 0;
5138 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5139 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005140 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005141 err = -EINVAL;
5142 goto out_free;
5143 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005144 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005145 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005146 i++;
5147 }
5148 }
5149
Jouni Malinen70692ad2009-02-16 19:39:13 +02005150 if (info->attrs[NL80211_ATTR_IE]) {
5151 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005152 memcpy((void *)request->ie,
5153 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005154 request->ie_len);
5155 }
5156
Johannes Berg34850ab2011-07-18 18:08:35 +02005157 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005158 if (wiphy->bands[i])
5159 request->rates[i] =
5160 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005161
5162 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5163 nla_for_each_nested(attr,
5164 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5165 tmp) {
5166 enum ieee80211_band band = nla_type(attr);
5167
Dan Carpenter84404622011-07-29 11:52:18 +03005168 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005169 err = -EINVAL;
5170 goto out_free;
5171 }
5172 err = ieee80211_get_ratemask(wiphy->bands[band],
5173 nla_data(attr),
5174 nla_len(attr),
5175 &request->rates[band]);
5176 if (err)
5177 goto out_free;
5178 }
5179 }
5180
Sam Leffler46856bb2012-10-11 21:03:32 -07005181 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005182 request->flags = nla_get_u32(
5183 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005184 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5185 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5186 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5187 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005188 err = -EOPNOTSUPP;
5189 goto out_free;
5190 }
5191 }
Sam Lefflered4737712012-10-11 21:03:31 -07005192
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305193 request->no_cck =
5194 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5195
Johannes Bergfd014282012-06-18 19:17:03 +02005196 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005197 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005198 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005199
Johannes Berg79c97e92009-07-07 03:56:12 +02005200 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005201 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005202
Johannes Berg463d0182009-07-14 00:33:35 +02005203 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005204 nl80211_send_scan_start(rdev, wdev);
5205 if (wdev->netdev)
5206 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005207 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005208 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005209 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005210 kfree(request);
5211 }
Johannes Berg3b858752009-03-12 09:55:09 +01005212
Johannes Berg2a519312009-02-10 21:25:55 +01005213 return err;
5214}
5215
Luciano Coelho807f8a82011-05-11 17:09:35 +03005216static int nl80211_start_sched_scan(struct sk_buff *skb,
5217 struct genl_info *info)
5218{
5219 struct cfg80211_sched_scan_request *request;
5220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5221 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005222 struct nlattr *attr;
5223 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005224 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005225 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005226 enum ieee80211_band band;
5227 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005228 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005229
5230 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5231 !rdev->ops->sched_scan_start)
5232 return -EOPNOTSUPP;
5233
5234 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5235 return -EINVAL;
5236
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005237 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5238 return -EINVAL;
5239
5240 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5241 if (interval == 0)
5242 return -EINVAL;
5243
Luciano Coelho807f8a82011-05-11 17:09:35 +03005244 wiphy = &rdev->wiphy;
5245
5246 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5247 n_channels = validate_scan_freqs(
5248 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5249 if (!n_channels)
5250 return -EINVAL;
5251 } else {
5252 n_channels = 0;
5253
5254 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5255 if (wiphy->bands[band])
5256 n_channels += wiphy->bands[band]->n_channels;
5257 }
5258
5259 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5260 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5261 tmp)
5262 n_ssids++;
5263
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005264 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005265 return -EINVAL;
5266
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005267 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5268 nla_for_each_nested(attr,
5269 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5270 tmp)
5271 n_match_sets++;
5272
5273 if (n_match_sets > wiphy->max_match_sets)
5274 return -EINVAL;
5275
Luciano Coelho807f8a82011-05-11 17:09:35 +03005276 if (info->attrs[NL80211_ATTR_IE])
5277 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5278 else
5279 ie_len = 0;
5280
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005281 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005282 return -EINVAL;
5283
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005284 mutex_lock(&rdev->sched_scan_mtx);
5285
5286 if (rdev->sched_scan_req) {
5287 err = -EINPROGRESS;
5288 goto out;
5289 }
5290
Luciano Coelho807f8a82011-05-11 17:09:35 +03005291 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005292 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005293 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005294 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005295 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005296 if (!request) {
5297 err = -ENOMEM;
5298 goto out;
5299 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005300
5301 if (n_ssids)
5302 request->ssids = (void *)&request->channels[n_channels];
5303 request->n_ssids = n_ssids;
5304 if (ie_len) {
5305 if (request->ssids)
5306 request->ie = (void *)(request->ssids + n_ssids);
5307 else
5308 request->ie = (void *)(request->channels + n_channels);
5309 }
5310
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005311 if (n_match_sets) {
5312 if (request->ie)
5313 request->match_sets = (void *)(request->ie + ie_len);
5314 else if (request->ssids)
5315 request->match_sets =
5316 (void *)(request->ssids + n_ssids);
5317 else
5318 request->match_sets =
5319 (void *)(request->channels + n_channels);
5320 }
5321 request->n_match_sets = n_match_sets;
5322
Luciano Coelho807f8a82011-05-11 17:09:35 +03005323 i = 0;
5324 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5325 /* user specified, bail out if channel not found */
5326 nla_for_each_nested(attr,
5327 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5328 tmp) {
5329 struct ieee80211_channel *chan;
5330
5331 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5332
5333 if (!chan) {
5334 err = -EINVAL;
5335 goto out_free;
5336 }
5337
5338 /* ignore disabled channels */
5339 if (chan->flags & IEEE80211_CHAN_DISABLED)
5340 continue;
5341
5342 request->channels[i] = chan;
5343 i++;
5344 }
5345 } else {
5346 /* all channels */
5347 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5348 int j;
5349 if (!wiphy->bands[band])
5350 continue;
5351 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5352 struct ieee80211_channel *chan;
5353
5354 chan = &wiphy->bands[band]->channels[j];
5355
5356 if (chan->flags & IEEE80211_CHAN_DISABLED)
5357 continue;
5358
5359 request->channels[i] = chan;
5360 i++;
5361 }
5362 }
5363 }
5364
5365 if (!i) {
5366 err = -EINVAL;
5367 goto out_free;
5368 }
5369
5370 request->n_channels = i;
5371
5372 i = 0;
5373 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5374 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5375 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005376 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005377 err = -EINVAL;
5378 goto out_free;
5379 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005380 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005381 memcpy(request->ssids[i].ssid, nla_data(attr),
5382 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005383 i++;
5384 }
5385 }
5386
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005387 i = 0;
5388 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5389 nla_for_each_nested(attr,
5390 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5391 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005392 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005393
5394 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5395 nla_data(attr), nla_len(attr),
5396 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005397 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005398 if (ssid) {
5399 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5400 err = -EINVAL;
5401 goto out_free;
5402 }
5403 memcpy(request->match_sets[i].ssid.ssid,
5404 nla_data(ssid), nla_len(ssid));
5405 request->match_sets[i].ssid.ssid_len =
5406 nla_len(ssid);
5407 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005408 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5409 if (rssi)
5410 request->rssi_thold = nla_get_u32(rssi);
5411 else
5412 request->rssi_thold =
5413 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005414 i++;
5415 }
5416 }
5417
Luciano Coelho807f8a82011-05-11 17:09:35 +03005418 if (info->attrs[NL80211_ATTR_IE]) {
5419 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5420 memcpy((void *)request->ie,
5421 nla_data(info->attrs[NL80211_ATTR_IE]),
5422 request->ie_len);
5423 }
5424
Sam Leffler46856bb2012-10-11 21:03:32 -07005425 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005426 request->flags = nla_get_u32(
5427 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005428 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5429 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5430 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5431 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005432 err = -EOPNOTSUPP;
5433 goto out_free;
5434 }
5435 }
Sam Lefflered4737712012-10-11 21:03:31 -07005436
Luciano Coelho807f8a82011-05-11 17:09:35 +03005437 request->dev = dev;
5438 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005439 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005440 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005441
Hila Gonene35e4d22012-06-27 17:19:42 +03005442 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005443 if (!err) {
5444 rdev->sched_scan_req = request;
5445 nl80211_send_sched_scan(rdev, dev,
5446 NL80211_CMD_START_SCHED_SCAN);
5447 goto out;
5448 }
5449
5450out_free:
5451 kfree(request);
5452out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005453 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005454 return err;
5455}
5456
5457static int nl80211_stop_sched_scan(struct sk_buff *skb,
5458 struct genl_info *info)
5459{
5460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005461 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005462
5463 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5464 !rdev->ops->sched_scan_stop)
5465 return -EOPNOTSUPP;
5466
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005467 mutex_lock(&rdev->sched_scan_mtx);
5468 err = __cfg80211_stop_sched_scan(rdev, false);
5469 mutex_unlock(&rdev->sched_scan_mtx);
5470
5471 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005472}
5473
Simon Wunderlich04f39042013-02-08 18:16:19 +01005474static int nl80211_start_radar_detection(struct sk_buff *skb,
5475 struct genl_info *info)
5476{
5477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5478 struct net_device *dev = info->user_ptr[1];
5479 struct wireless_dev *wdev = dev->ieee80211_ptr;
5480 struct cfg80211_chan_def chandef;
5481 int err;
5482
5483 err = nl80211_parse_chandef(rdev, info, &chandef);
5484 if (err)
5485 return err;
5486
5487 if (wdev->cac_started)
5488 return -EBUSY;
5489
5490 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5491 if (err < 0)
5492 return err;
5493
5494 if (err == 0)
5495 return -EINVAL;
5496
5497 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5498 return -EINVAL;
5499
5500 if (!rdev->ops->start_radar_detection)
5501 return -EOPNOTSUPP;
5502
5503 mutex_lock(&rdev->devlist_mtx);
5504 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5505 chandef.chan, CHAN_MODE_SHARED,
5506 BIT(chandef.width));
5507 if (err)
5508 goto err_locked;
5509
5510 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5511 if (!err) {
5512 wdev->channel = chandef.chan;
5513 wdev->cac_started = true;
5514 wdev->cac_start_time = jiffies;
5515 }
5516err_locked:
5517 mutex_unlock(&rdev->devlist_mtx);
5518
5519 return err;
5520}
5521
Johannes Berg9720bb32011-06-21 09:45:33 +02005522static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5523 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005524 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005525 struct wireless_dev *wdev,
5526 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005527{
Johannes Berg48ab9052009-07-10 18:42:31 +02005528 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005529 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005530 void *hdr;
5531 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005532 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005533
5534 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005535
Eric W. Biederman15e47302012-09-07 20:12:54 +00005536 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005537 NL80211_CMD_NEW_SCAN_RESULTS);
5538 if (!hdr)
5539 return -1;
5540
Johannes Berg9720bb32011-06-21 09:45:33 +02005541 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5542
David S. Miller9360ffd2012-03-29 04:41:26 -04005543 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5544 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5545 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005546
5547 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5548 if (!bss)
5549 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005550 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005551 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005552 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005553
5554 rcu_read_lock();
5555 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005556 if (ies) {
5557 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5558 goto fail_unlock_rcu;
5559 tsf = true;
5560 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5561 ies->len, ies->data))
5562 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005563 }
5564 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005565 if (ies) {
5566 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5567 goto fail_unlock_rcu;
5568 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5569 ies->len, ies->data))
5570 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005571 }
5572 rcu_read_unlock();
5573
David S. Miller9360ffd2012-03-29 04:41:26 -04005574 if (res->beacon_interval &&
5575 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5576 goto nla_put_failure;
5577 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5578 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5579 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5580 jiffies_to_msecs(jiffies - intbss->ts)))
5581 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005582
Johannes Berg77965c92009-02-18 18:45:06 +01005583 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005584 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005585 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5586 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005587 break;
5588 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005589 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5590 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005591 break;
5592 default:
5593 break;
5594 }
5595
Johannes Berg48ab9052009-07-10 18:42:31 +02005596 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005597 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005598 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005599 if (intbss == wdev->current_bss &&
5600 nla_put_u32(msg, NL80211_BSS_STATUS,
5601 NL80211_BSS_STATUS_ASSOCIATED))
5602 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005603 break;
5604 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005605 if (intbss == wdev->current_bss &&
5606 nla_put_u32(msg, NL80211_BSS_STATUS,
5607 NL80211_BSS_STATUS_IBSS_JOINED))
5608 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005609 break;
5610 default:
5611 break;
5612 }
5613
Johannes Berg2a519312009-02-10 21:25:55 +01005614 nla_nest_end(msg, bss);
5615
5616 return genlmsg_end(msg, hdr);
5617
Johannes Berg8cef2c92013-02-05 16:54:31 +01005618 fail_unlock_rcu:
5619 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005620 nla_put_failure:
5621 genlmsg_cancel(msg, hdr);
5622 return -EMSGSIZE;
5623}
5624
5625static int nl80211_dump_scan(struct sk_buff *skb,
5626 struct netlink_callback *cb)
5627{
Johannes Berg48ab9052009-07-10 18:42:31 +02005628 struct cfg80211_registered_device *rdev;
5629 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01005630 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005631 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005632 int start = cb->args[1], idx = 0;
5633 int err;
5634
Johannes Berg67748892010-10-04 21:14:06 +02005635 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5636 if (err)
5637 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005638
Johannes Berg48ab9052009-07-10 18:42:31 +02005639 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01005640
Johannes Berg48ab9052009-07-10 18:42:31 +02005641 wdev_lock(wdev);
5642 spin_lock_bh(&rdev->bss_lock);
5643 cfg80211_bss_expire(rdev);
5644
Johannes Berg9720bb32011-06-21 09:45:33 +02005645 cb->seq = rdev->bss_generation;
5646
Johannes Berg48ab9052009-07-10 18:42:31 +02005647 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005648 if (++idx <= start)
5649 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005650 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005651 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005652 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005653 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005654 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005655 }
5656 }
5657
Johannes Berg48ab9052009-07-10 18:42:31 +02005658 spin_unlock_bh(&rdev->bss_lock);
5659 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005660
5661 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02005662 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005663
Johannes Berg67748892010-10-04 21:14:06 +02005664 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005665}
5666
Eric W. Biederman15e47302012-09-07 20:12:54 +00005667static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005668 int flags, struct net_device *dev,
5669 struct survey_info *survey)
5670{
5671 void *hdr;
5672 struct nlattr *infoattr;
5673
Eric W. Biederman15e47302012-09-07 20:12:54 +00005674 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005675 NL80211_CMD_NEW_SURVEY_RESULTS);
5676 if (!hdr)
5677 return -ENOMEM;
5678
David S. Miller9360ffd2012-03-29 04:41:26 -04005679 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5680 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005681
5682 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5683 if (!infoattr)
5684 goto nla_put_failure;
5685
David S. Miller9360ffd2012-03-29 04:41:26 -04005686 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5687 survey->channel->center_freq))
5688 goto nla_put_failure;
5689
5690 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5691 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5692 goto nla_put_failure;
5693 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5694 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5695 goto nla_put_failure;
5696 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5697 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5698 survey->channel_time))
5699 goto nla_put_failure;
5700 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5701 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5702 survey->channel_time_busy))
5703 goto nla_put_failure;
5704 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5705 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5706 survey->channel_time_ext_busy))
5707 goto nla_put_failure;
5708 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5709 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5710 survey->channel_time_rx))
5711 goto nla_put_failure;
5712 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5713 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5714 survey->channel_time_tx))
5715 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005716
5717 nla_nest_end(msg, infoattr);
5718
5719 return genlmsg_end(msg, hdr);
5720
5721 nla_put_failure:
5722 genlmsg_cancel(msg, hdr);
5723 return -EMSGSIZE;
5724}
5725
5726static int nl80211_dump_survey(struct sk_buff *skb,
5727 struct netlink_callback *cb)
5728{
5729 struct survey_info survey;
5730 struct cfg80211_registered_device *dev;
5731 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01005732 int survey_idx = cb->args[1];
5733 int res;
5734
Johannes Berg67748892010-10-04 21:14:06 +02005735 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5736 if (res)
5737 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005738
5739 if (!dev->ops->dump_survey) {
5740 res = -EOPNOTSUPP;
5741 goto out_err;
5742 }
5743
5744 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005745 struct ieee80211_channel *chan;
5746
Hila Gonene35e4d22012-06-27 17:19:42 +03005747 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005748 if (res == -ENOENT)
5749 break;
5750 if (res)
5751 goto out_err;
5752
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005753 /* Survey without a channel doesn't make sense */
5754 if (!survey.channel) {
5755 res = -EINVAL;
5756 goto out;
5757 }
5758
5759 chan = ieee80211_get_channel(&dev->wiphy,
5760 survey.channel->center_freq);
5761 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5762 survey_idx++;
5763 continue;
5764 }
5765
Holger Schurig61fa7132009-11-11 12:25:40 +01005766 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005767 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005768 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5769 netdev,
5770 &survey) < 0)
5771 goto out;
5772 survey_idx++;
5773 }
5774
5775 out:
5776 cb->args[1] = survey_idx;
5777 res = skb->len;
5778 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02005779 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005780 return res;
5781}
5782
Samuel Ortizb23aa672009-07-01 21:26:54 +02005783static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5784{
5785 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5786 NL80211_WPA_VERSION_2));
5787}
5788
Jouni Malinen636a5d32009-03-19 13:39:22 +02005789static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5790{
Johannes Berg4c476992010-10-04 21:36:35 +02005791 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5792 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005793 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005794 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5795 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005796 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005797 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005798 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005799
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005800 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5801 return -EINVAL;
5802
5803 if (!info->attrs[NL80211_ATTR_MAC])
5804 return -EINVAL;
5805
Jouni Malinen17780922009-03-27 20:52:47 +02005806 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5807 return -EINVAL;
5808
Johannes Berg19957bb2009-07-02 17:20:43 +02005809 if (!info->attrs[NL80211_ATTR_SSID])
5810 return -EINVAL;
5811
5812 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5813 return -EINVAL;
5814
Johannes Bergfffd0932009-07-08 14:22:54 +02005815 err = nl80211_parse_key(info, &key);
5816 if (err)
5817 return err;
5818
5819 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005820 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5821 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005822 if (!key.p.key || !key.p.key_len)
5823 return -EINVAL;
5824 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5825 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5826 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5827 key.p.key_len != WLAN_KEY_LEN_WEP104))
5828 return -EINVAL;
5829 if (key.idx > 4)
5830 return -EINVAL;
5831 } else {
5832 key.p.key_len = 0;
5833 key.p.key = NULL;
5834 }
5835
Johannes Bergafea0b72010-08-10 09:46:42 +02005836 if (key.idx >= 0) {
5837 int i;
5838 bool ok = false;
5839 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5840 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5841 ok = true;
5842 break;
5843 }
5844 }
Johannes Berg4c476992010-10-04 21:36:35 +02005845 if (!ok)
5846 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005847 }
5848
Johannes Berg4c476992010-10-04 21:36:35 +02005849 if (!rdev->ops->auth)
5850 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005851
Johannes Berg074ac8d2010-09-16 14:58:22 +02005852 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005853 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5854 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005855
Johannes Berg19957bb2009-07-02 17:20:43 +02005856 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005857 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005858 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005859 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5860 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005861
Johannes Berg19957bb2009-07-02 17:20:43 +02005862 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5863 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5864
5865 if (info->attrs[NL80211_ATTR_IE]) {
5866 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5867 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5868 }
5869
5870 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005871 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005872 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005873
Jouni Malinene39e5b52012-09-30 19:29:39 +03005874 if (auth_type == NL80211_AUTHTYPE_SAE &&
5875 !info->attrs[NL80211_ATTR_SAE_DATA])
5876 return -EINVAL;
5877
5878 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5879 if (auth_type != NL80211_AUTHTYPE_SAE)
5880 return -EINVAL;
5881 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5882 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5883 /* need to include at least Auth Transaction and Status Code */
5884 if (sae_data_len < 4)
5885 return -EINVAL;
5886 }
5887
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005888 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5889
Johannes Berg95de8172012-01-20 13:55:25 +01005890 /*
5891 * Since we no longer track auth state, ignore
5892 * requests to only change local state.
5893 */
5894 if (local_state_change)
5895 return 0;
5896
Johannes Berg4c476992010-10-04 21:36:35 +02005897 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5898 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005899 key.p.key, key.p.key_len, key.idx,
5900 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005901}
5902
Johannes Bergc0692b82010-08-27 14:26:53 +03005903static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5904 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005905 struct cfg80211_crypto_settings *settings,
5906 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005907{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005908 memset(settings, 0, sizeof(*settings));
5909
Samuel Ortizb23aa672009-07-01 21:26:54 +02005910 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5911
Johannes Bergc0692b82010-08-27 14:26:53 +03005912 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5913 u16 proto;
5914 proto = nla_get_u16(
5915 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5916 settings->control_port_ethertype = cpu_to_be16(proto);
5917 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5918 proto != ETH_P_PAE)
5919 return -EINVAL;
5920 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5921 settings->control_port_no_encrypt = true;
5922 } else
5923 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5924
Samuel Ortizb23aa672009-07-01 21:26:54 +02005925 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5926 void *data;
5927 int len, i;
5928
5929 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5930 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5931 settings->n_ciphers_pairwise = len / sizeof(u32);
5932
5933 if (len % sizeof(u32))
5934 return -EINVAL;
5935
Johannes Berg3dc27d22009-07-02 21:36:37 +02005936 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005937 return -EINVAL;
5938
5939 memcpy(settings->ciphers_pairwise, data, len);
5940
5941 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005942 if (!cfg80211_supported_cipher_suite(
5943 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005944 settings->ciphers_pairwise[i]))
5945 return -EINVAL;
5946 }
5947
5948 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5949 settings->cipher_group =
5950 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005951 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5952 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005953 return -EINVAL;
5954 }
5955
5956 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5957 settings->wpa_versions =
5958 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5959 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5960 return -EINVAL;
5961 }
5962
5963 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5964 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005965 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005966
5967 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5968 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5969 settings->n_akm_suites = len / sizeof(u32);
5970
5971 if (len % sizeof(u32))
5972 return -EINVAL;
5973
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005974 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5975 return -EINVAL;
5976
Samuel Ortizb23aa672009-07-01 21:26:54 +02005977 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005978 }
5979
5980 return 0;
5981}
5982
Jouni Malinen636a5d32009-03-19 13:39:22 +02005983static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5984{
Johannes Berg4c476992010-10-04 21:36:35 +02005985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5986 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02005987 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01005988 struct cfg80211_assoc_request req = {};
5989 const u8 *bssid, *ssid;
5990 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005991
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005992 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5993 return -EINVAL;
5994
5995 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005996 !info->attrs[NL80211_ATTR_SSID] ||
5997 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005998 return -EINVAL;
5999
Johannes Berg4c476992010-10-04 21:36:35 +02006000 if (!rdev->ops->assoc)
6001 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006002
Johannes Berg074ac8d2010-09-16 14:58:22 +02006003 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006004 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6005 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006006
Johannes Berg19957bb2009-07-02 17:20:43 +02006007 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006008
Johannes Berg19957bb2009-07-02 17:20:43 +02006009 chan = ieee80211_get_channel(&rdev->wiphy,
6010 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006011 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6012 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006013
Johannes Berg19957bb2009-07-02 17:20:43 +02006014 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6015 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006016
6017 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006018 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6019 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006020 }
6021
Jouni Malinendc6382c2009-05-06 22:09:37 +03006022 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006023 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006024 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006025 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006026 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006027 else if (mfp != NL80211_MFP_NO)
6028 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006029 }
6030
Johannes Berg3e5d7642009-07-07 14:37:26 +02006031 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006032 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006033
Ben Greear7e7c8922011-11-18 11:31:59 -08006034 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006035 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006036
6037 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006038 memcpy(&req.ht_capa_mask,
6039 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6040 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006041
6042 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006043 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006044 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006045 memcpy(&req.ht_capa,
6046 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6047 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006048 }
6049
Johannes Bergee2aca32013-02-21 17:36:01 +01006050 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006051 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006052
6053 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006054 memcpy(&req.vht_capa_mask,
6055 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6056 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006057
6058 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006059 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006060 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006061 memcpy(&req.vht_capa,
6062 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6063 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006064 }
6065
Johannes Bergf62fab72013-02-21 20:09:09 +01006066 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006067 if (!err)
Johannes Bergf62fab72013-02-21 20:09:09 +01006068 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6069 ssid, ssid_len, &req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006070
Jouni Malinen636a5d32009-03-19 13:39:22 +02006071 return err;
6072}
6073
6074static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6075{
Johannes Berg4c476992010-10-04 21:36:35 +02006076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6077 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006078 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006079 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006080 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006081 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006082
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006083 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6084 return -EINVAL;
6085
6086 if (!info->attrs[NL80211_ATTR_MAC])
6087 return -EINVAL;
6088
6089 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6090 return -EINVAL;
6091
Johannes Berg4c476992010-10-04 21:36:35 +02006092 if (!rdev->ops->deauth)
6093 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006094
Johannes Berg074ac8d2010-09-16 14:58:22 +02006095 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006096 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6097 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006098
Johannes Berg19957bb2009-07-02 17:20:43 +02006099 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006100
Johannes Berg19957bb2009-07-02 17:20:43 +02006101 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6102 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006103 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006104 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006105 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006106
6107 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006108 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6109 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006110 }
6111
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006112 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6113
Johannes Berg4c476992010-10-04 21:36:35 +02006114 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6115 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006116}
6117
6118static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6119{
Johannes Berg4c476992010-10-04 21:36:35 +02006120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6121 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006122 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006123 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006124 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006125 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006126
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006127 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6128 return -EINVAL;
6129
6130 if (!info->attrs[NL80211_ATTR_MAC])
6131 return -EINVAL;
6132
6133 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6134 return -EINVAL;
6135
Johannes Berg4c476992010-10-04 21:36:35 +02006136 if (!rdev->ops->disassoc)
6137 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006138
Johannes Berg074ac8d2010-09-16 14:58:22 +02006139 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006140 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6141 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006142
Johannes Berg19957bb2009-07-02 17:20:43 +02006143 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006144
Johannes Berg19957bb2009-07-02 17:20:43 +02006145 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6146 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006147 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006148 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006149 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006150
6151 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006152 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6153 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006154 }
6155
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006156 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6157
Johannes Berg4c476992010-10-04 21:36:35 +02006158 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6159 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006160}
6161
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006162static bool
6163nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6164 int mcast_rate[IEEE80211_NUM_BANDS],
6165 int rateval)
6166{
6167 struct wiphy *wiphy = &rdev->wiphy;
6168 bool found = false;
6169 int band, i;
6170
6171 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6172 struct ieee80211_supported_band *sband;
6173
6174 sband = wiphy->bands[band];
6175 if (!sband)
6176 continue;
6177
6178 for (i = 0; i < sband->n_bitrates; i++) {
6179 if (sband->bitrates[i].bitrate == rateval) {
6180 mcast_rate[band] = i + 1;
6181 found = true;
6182 break;
6183 }
6184 }
6185 }
6186
6187 return found;
6188}
6189
Johannes Berg04a773a2009-04-19 21:24:32 +02006190static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6191{
Johannes Berg4c476992010-10-04 21:36:35 +02006192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6193 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006194 struct cfg80211_ibss_params ibss;
6195 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006196 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006197 int err;
6198
Johannes Berg8e30bc52009-04-22 17:45:38 +02006199 memset(&ibss, 0, sizeof(ibss));
6200
Johannes Berg04a773a2009-04-19 21:24:32 +02006201 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6202 return -EINVAL;
6203
Johannes Berg683b6d32012-11-08 21:25:48 +01006204 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006205 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6206 return -EINVAL;
6207
Johannes Berg8e30bc52009-04-22 17:45:38 +02006208 ibss.beacon_interval = 100;
6209
6210 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6211 ibss.beacon_interval =
6212 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6213 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6214 return -EINVAL;
6215 }
6216
Johannes Berg4c476992010-10-04 21:36:35 +02006217 if (!rdev->ops->join_ibss)
6218 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006219
Johannes Berg4c476992010-10-04 21:36:35 +02006220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6221 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006222
Johannes Berg79c97e92009-07-07 03:56:12 +02006223 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006224
Johannes Berg39193492011-09-16 13:45:25 +02006225 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006226 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006227
6228 if (!is_valid_ether_addr(ibss.bssid))
6229 return -EINVAL;
6230 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006231 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6232 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6233
6234 if (info->attrs[NL80211_ATTR_IE]) {
6235 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6236 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6237 }
6238
Johannes Berg683b6d32012-11-08 21:25:48 +01006239 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6240 if (err)
6241 return err;
Alexander Simon54858ee2011-11-30 16:56:32 +01006242
Johannes Berg683b6d32012-11-08 21:25:48 +01006243 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee2011-11-30 16:56:32 +01006244 return -EINVAL;
6245
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006246 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6247 return -EINVAL;
6248 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6249 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006250 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006251
Johannes Berg04a773a2009-04-19 21:24:32 +02006252 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006253 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006254
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006255 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6256 u8 *rates =
6257 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6258 int n_rates =
6259 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6260 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006261 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006262
Johannes Berg34850ab2011-07-18 18:08:35 +02006263 err = ieee80211_get_ratemask(sband, rates, n_rates,
6264 &ibss.basic_rates);
6265 if (err)
6266 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006267 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006268
6269 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6270 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6271 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6272 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006273
Johannes Berg4c476992010-10-04 21:36:35 +02006274 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306275 bool no_ht = false;
6276
Johannes Berg4c476992010-10-04 21:36:35 +02006277 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306278 info->attrs[NL80211_ATTR_KEYS],
6279 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006280 if (IS_ERR(connkeys))
6281 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306282
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006283 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6284 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306285 kfree(connkeys);
6286 return -EINVAL;
6287 }
Johannes Berg4c476992010-10-04 21:36:35 +02006288 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006289
Antonio Quartulli267335d2012-01-31 20:25:47 +01006290 ibss.control_port =
6291 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6292
Johannes Berg4c476992010-10-04 21:36:35 +02006293 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006294 if (err)
6295 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006296 return err;
6297}
6298
6299static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6300{
Johannes Berg4c476992010-10-04 21:36:35 +02006301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6302 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006303
Johannes Berg4c476992010-10-04 21:36:35 +02006304 if (!rdev->ops->leave_ibss)
6305 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006306
Johannes Berg4c476992010-10-04 21:36:35 +02006307 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6308 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006309
Johannes Berg4c476992010-10-04 21:36:35 +02006310 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006311}
6312
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006313static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6314{
6315 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6316 struct net_device *dev = info->user_ptr[1];
6317 int mcast_rate[IEEE80211_NUM_BANDS];
6318 u32 nla_rate;
6319 int err;
6320
6321 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6322 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6323 return -EOPNOTSUPP;
6324
6325 if (!rdev->ops->set_mcast_rate)
6326 return -EOPNOTSUPP;
6327
6328 memset(mcast_rate, 0, sizeof(mcast_rate));
6329
6330 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6331 return -EINVAL;
6332
6333 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6334 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6335 return -EINVAL;
6336
6337 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6338
6339 return err;
6340}
6341
6342
Johannes Bergaff89a92009-07-01 21:26:51 +02006343#ifdef CONFIG_NL80211_TESTMODE
6344static struct genl_multicast_group nl80211_testmode_mcgrp = {
6345 .name = "testmode",
6346};
6347
6348static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6349{
Johannes Berg4c476992010-10-04 21:36:35 +02006350 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006351 int err;
6352
6353 if (!info->attrs[NL80211_ATTR_TESTDATA])
6354 return -EINVAL;
6355
Johannes Bergaff89a92009-07-01 21:26:51 +02006356 err = -EOPNOTSUPP;
6357 if (rdev->ops->testmode_cmd) {
6358 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006359 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006360 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6361 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6362 rdev->testmode_info = NULL;
6363 }
6364
Johannes Bergaff89a92009-07-01 21:26:51 +02006365 return err;
6366}
6367
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006368static int nl80211_testmode_dump(struct sk_buff *skb,
6369 struct netlink_callback *cb)
6370{
Johannes Berg00918d32011-12-13 17:22:05 +01006371 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006372 int err;
6373 long phy_idx;
6374 void *data = NULL;
6375 int data_len = 0;
6376
6377 if (cb->args[0]) {
6378 /*
6379 * 0 is a valid index, but not valid for args[0],
6380 * so we need to offset by 1.
6381 */
6382 phy_idx = cb->args[0] - 1;
6383 } else {
6384 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6385 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6386 nl80211_policy);
6387 if (err)
6388 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01006389
Johannes Berg2bd7e352012-06-15 14:23:16 +02006390 mutex_lock(&cfg80211_mutex);
6391 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6392 nl80211_fam.attrbuf);
6393 if (IS_ERR(rdev)) {
6394 mutex_unlock(&cfg80211_mutex);
6395 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01006396 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006397 phy_idx = rdev->wiphy_idx;
6398 rdev = NULL;
6399 mutex_unlock(&cfg80211_mutex);
6400
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006401 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6402 cb->args[1] =
6403 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6404 }
6405
6406 if (cb->args[1]) {
6407 data = nla_data((void *)cb->args[1]);
6408 data_len = nla_len((void *)cb->args[1]);
6409 }
6410
6411 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01006412 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6413 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006414 mutex_unlock(&cfg80211_mutex);
6415 return -ENOENT;
6416 }
Johannes Berg00918d32011-12-13 17:22:05 +01006417 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006418 mutex_unlock(&cfg80211_mutex);
6419
Johannes Berg00918d32011-12-13 17:22:05 +01006420 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006421 err = -EOPNOTSUPP;
6422 goto out_err;
6423 }
6424
6425 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006426 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006427 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6428 NL80211_CMD_TESTMODE);
6429 struct nlattr *tmdata;
6430
David S. Miller9360ffd2012-03-29 04:41:26 -04006431 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006432 genlmsg_cancel(skb, hdr);
6433 break;
6434 }
6435
6436 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6437 if (!tmdata) {
6438 genlmsg_cancel(skb, hdr);
6439 break;
6440 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006441 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006442 nla_nest_end(skb, tmdata);
6443
6444 if (err == -ENOBUFS || err == -ENOENT) {
6445 genlmsg_cancel(skb, hdr);
6446 break;
6447 } else if (err) {
6448 genlmsg_cancel(skb, hdr);
6449 goto out_err;
6450 }
6451
6452 genlmsg_end(skb, hdr);
6453 }
6454
6455 err = skb->len;
6456 /* see above */
6457 cb->args[0] = phy_idx + 1;
6458 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01006459 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006460 return err;
6461}
6462
Johannes Bergaff89a92009-07-01 21:26:51 +02006463static struct sk_buff *
6464__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006465 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006466{
6467 struct sk_buff *skb;
6468 void *hdr;
6469 struct nlattr *data;
6470
6471 skb = nlmsg_new(approxlen + 100, gfp);
6472 if (!skb)
6473 return NULL;
6474
Eric W. Biederman15e47302012-09-07 20:12:54 +00006475 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006476 if (!hdr) {
6477 kfree_skb(skb);
6478 return NULL;
6479 }
6480
David S. Miller9360ffd2012-03-29 04:41:26 -04006481 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6482 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006483 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6484
6485 ((void **)skb->cb)[0] = rdev;
6486 ((void **)skb->cb)[1] = hdr;
6487 ((void **)skb->cb)[2] = data;
6488
6489 return skb;
6490
6491 nla_put_failure:
6492 kfree_skb(skb);
6493 return NULL;
6494}
6495
6496struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6497 int approxlen)
6498{
6499 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6500
6501 if (WARN_ON(!rdev->testmode_info))
6502 return NULL;
6503
6504 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006505 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006506 rdev->testmode_info->snd_seq,
6507 GFP_KERNEL);
6508}
6509EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6510
6511int cfg80211_testmode_reply(struct sk_buff *skb)
6512{
6513 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6514 void *hdr = ((void **)skb->cb)[1];
6515 struct nlattr *data = ((void **)skb->cb)[2];
6516
6517 if (WARN_ON(!rdev->testmode_info)) {
6518 kfree_skb(skb);
6519 return -EINVAL;
6520 }
6521
6522 nla_nest_end(skb, data);
6523 genlmsg_end(skb, hdr);
6524 return genlmsg_reply(skb, rdev->testmode_info);
6525}
6526EXPORT_SYMBOL(cfg80211_testmode_reply);
6527
6528struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6529 int approxlen, gfp_t gfp)
6530{
6531 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6532
6533 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6534}
6535EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6536
6537void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6538{
6539 void *hdr = ((void **)skb->cb)[1];
6540 struct nlattr *data = ((void **)skb->cb)[2];
6541
6542 nla_nest_end(skb, data);
6543 genlmsg_end(skb, hdr);
6544 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6545}
6546EXPORT_SYMBOL(cfg80211_testmode_event);
6547#endif
6548
Samuel Ortizb23aa672009-07-01 21:26:54 +02006549static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6550{
Johannes Berg4c476992010-10-04 21:36:35 +02006551 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6552 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006553 struct cfg80211_connect_params connect;
6554 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006555 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006556 int err;
6557
6558 memset(&connect, 0, sizeof(connect));
6559
6560 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6561 return -EINVAL;
6562
6563 if (!info->attrs[NL80211_ATTR_SSID] ||
6564 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6565 return -EINVAL;
6566
6567 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6568 connect.auth_type =
6569 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006570 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6571 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006572 return -EINVAL;
6573 } else
6574 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6575
6576 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6577
Johannes Bergc0692b82010-08-27 14:26:53 +03006578 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006579 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006580 if (err)
6581 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006582
Johannes Berg074ac8d2010-09-16 14:58:22 +02006583 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006584 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6585 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006586
Johannes Berg79c97e92009-07-07 03:56:12 +02006587 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006588
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306589 connect.bg_scan_period = -1;
6590 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6591 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6592 connect.bg_scan_period =
6593 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6594 }
6595
Samuel Ortizb23aa672009-07-01 21:26:54 +02006596 if (info->attrs[NL80211_ATTR_MAC])
6597 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6598 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6599 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6600
6601 if (info->attrs[NL80211_ATTR_IE]) {
6602 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6603 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6604 }
6605
Jouni Malinencee00a92013-01-15 17:15:57 +02006606 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6607 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6608 if (connect.mfp != NL80211_MFP_REQUIRED &&
6609 connect.mfp != NL80211_MFP_NO)
6610 return -EINVAL;
6611 } else {
6612 connect.mfp = NL80211_MFP_NO;
6613 }
6614
Samuel Ortizb23aa672009-07-01 21:26:54 +02006615 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6616 connect.channel =
6617 ieee80211_get_channel(wiphy,
6618 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6619 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006620 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6621 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006622 }
6623
Johannes Bergfffd0932009-07-08 14:22:54 +02006624 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6625 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306626 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006627 if (IS_ERR(connkeys))
6628 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006629 }
6630
Ben Greear7e7c8922011-11-18 11:31:59 -08006631 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6632 connect.flags |= ASSOC_REQ_DISABLE_HT;
6633
6634 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6635 memcpy(&connect.ht_capa_mask,
6636 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6637 sizeof(connect.ht_capa_mask));
6638
6639 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006640 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6641 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006642 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006643 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006644 memcpy(&connect.ht_capa,
6645 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6646 sizeof(connect.ht_capa));
6647 }
6648
Johannes Bergee2aca32013-02-21 17:36:01 +01006649 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6650 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6651
6652 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6653 memcpy(&connect.vht_capa_mask,
6654 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6655 sizeof(connect.vht_capa_mask));
6656
6657 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6658 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6659 kfree(connkeys);
6660 return -EINVAL;
6661 }
6662 memcpy(&connect.vht_capa,
6663 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6664 sizeof(connect.vht_capa));
6665 }
6666
Johannes Bergfffd0932009-07-08 14:22:54 +02006667 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006668 if (err)
6669 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006670 return err;
6671}
6672
6673static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6674{
Johannes Berg4c476992010-10-04 21:36:35 +02006675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6676 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006677 u16 reason;
6678
6679 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6680 reason = WLAN_REASON_DEAUTH_LEAVING;
6681 else
6682 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6683
6684 if (reason == 0)
6685 return -EINVAL;
6686
Johannes Berg074ac8d2010-09-16 14:58:22 +02006687 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006688 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6689 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006690
Johannes Berg4c476992010-10-04 21:36:35 +02006691 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006692}
6693
Johannes Berg463d0182009-07-14 00:33:35 +02006694static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6695{
Johannes Berg4c476992010-10-04 21:36:35 +02006696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006697 struct net *net;
6698 int err;
6699 u32 pid;
6700
6701 if (!info->attrs[NL80211_ATTR_PID])
6702 return -EINVAL;
6703
6704 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6705
Johannes Berg463d0182009-07-14 00:33:35 +02006706 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006707 if (IS_ERR(net))
6708 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006709
6710 err = 0;
6711
6712 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006713 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6714 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006715
Johannes Berg463d0182009-07-14 00:33:35 +02006716 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006717 return err;
6718}
6719
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006720static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6721{
Johannes Berg4c476992010-10-04 21:36:35 +02006722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006723 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6724 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006725 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006726 struct cfg80211_pmksa pmksa;
6727
6728 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6729
6730 if (!info->attrs[NL80211_ATTR_MAC])
6731 return -EINVAL;
6732
6733 if (!info->attrs[NL80211_ATTR_PMKID])
6734 return -EINVAL;
6735
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006736 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6737 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6738
Johannes Berg074ac8d2010-09-16 14:58:22 +02006739 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006740 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6741 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006742
6743 switch (info->genlhdr->cmd) {
6744 case NL80211_CMD_SET_PMKSA:
6745 rdev_ops = rdev->ops->set_pmksa;
6746 break;
6747 case NL80211_CMD_DEL_PMKSA:
6748 rdev_ops = rdev->ops->del_pmksa;
6749 break;
6750 default:
6751 WARN_ON(1);
6752 break;
6753 }
6754
Johannes Berg4c476992010-10-04 21:36:35 +02006755 if (!rdev_ops)
6756 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006757
Johannes Berg4c476992010-10-04 21:36:35 +02006758 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006759}
6760
6761static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6762{
Johannes Berg4c476992010-10-04 21:36:35 +02006763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6764 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006765
Johannes Berg074ac8d2010-09-16 14:58:22 +02006766 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006767 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6768 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006769
Johannes Berg4c476992010-10-04 21:36:35 +02006770 if (!rdev->ops->flush_pmksa)
6771 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006772
Hila Gonene35e4d22012-06-27 17:19:42 +03006773 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006774}
6775
Arik Nemtsov109086c2011-09-28 14:12:50 +03006776static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6777{
6778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6779 struct net_device *dev = info->user_ptr[1];
6780 u8 action_code, dialog_token;
6781 u16 status_code;
6782 u8 *peer;
6783
6784 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6785 !rdev->ops->tdls_mgmt)
6786 return -EOPNOTSUPP;
6787
6788 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6789 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6790 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6791 !info->attrs[NL80211_ATTR_IE] ||
6792 !info->attrs[NL80211_ATTR_MAC])
6793 return -EINVAL;
6794
6795 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6796 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6797 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6798 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6799
Hila Gonene35e4d22012-06-27 17:19:42 +03006800 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6801 dialog_token, status_code,
6802 nla_data(info->attrs[NL80211_ATTR_IE]),
6803 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006804}
6805
6806static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6807{
6808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6809 struct net_device *dev = info->user_ptr[1];
6810 enum nl80211_tdls_operation operation;
6811 u8 *peer;
6812
6813 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6814 !rdev->ops->tdls_oper)
6815 return -EOPNOTSUPP;
6816
6817 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6818 !info->attrs[NL80211_ATTR_MAC])
6819 return -EINVAL;
6820
6821 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6822 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6823
Hila Gonene35e4d22012-06-27 17:19:42 +03006824 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006825}
6826
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006827static int nl80211_remain_on_channel(struct sk_buff *skb,
6828 struct genl_info *info)
6829{
Johannes Berg4c476992010-10-04 21:36:35 +02006830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006831 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006832 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006833 struct sk_buff *msg;
6834 void *hdr;
6835 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006836 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006837 int err;
6838
6839 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6840 !info->attrs[NL80211_ATTR_DURATION])
6841 return -EINVAL;
6842
6843 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6844
Johannes Berg7c4ef712011-11-18 15:33:48 +01006845 if (!rdev->ops->remain_on_channel ||
6846 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006847 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006848
Johannes Bergebf348f2012-06-01 12:50:54 +02006849 /*
6850 * We should be on that channel for at least a minimum amount of
6851 * time (10ms) but no longer than the driver supports.
6852 */
6853 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6854 duration > rdev->wiphy.max_remain_on_channel_duration)
6855 return -EINVAL;
6856
Johannes Berg683b6d32012-11-08 21:25:48 +01006857 err = nl80211_parse_chandef(rdev, info, &chandef);
6858 if (err)
6859 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006860
6861 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006862 if (!msg)
6863 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006864
Eric W. Biederman15e47302012-09-07 20:12:54 +00006865 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006866 NL80211_CMD_REMAIN_ON_CHANNEL);
6867
6868 if (IS_ERR(hdr)) {
6869 err = PTR_ERR(hdr);
6870 goto free_msg;
6871 }
6872
Johannes Berg683b6d32012-11-08 21:25:48 +01006873 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6874 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006875
6876 if (err)
6877 goto free_msg;
6878
David S. Miller9360ffd2012-03-29 04:41:26 -04006879 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6880 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006881
6882 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006883
6884 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006885
6886 nla_put_failure:
6887 err = -ENOBUFS;
6888 free_msg:
6889 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006890 return err;
6891}
6892
6893static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6894 struct genl_info *info)
6895{
Johannes Berg4c476992010-10-04 21:36:35 +02006896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006897 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006898 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006899
6900 if (!info->attrs[NL80211_ATTR_COOKIE])
6901 return -EINVAL;
6902
Johannes Berg4c476992010-10-04 21:36:35 +02006903 if (!rdev->ops->cancel_remain_on_channel)
6904 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006905
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006906 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6907
Hila Gonene35e4d22012-06-27 17:19:42 +03006908 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006909}
6910
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006911static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6912 u8 *rates, u8 rates_len)
6913{
6914 u8 i;
6915 u32 mask = 0;
6916
6917 for (i = 0; i < rates_len; i++) {
6918 int rate = (rates[i] & 0x7f) * 5;
6919 int ridx;
6920 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6921 struct ieee80211_rate *srate =
6922 &sband->bitrates[ridx];
6923 if (rate == srate->bitrate) {
6924 mask |= 1 << ridx;
6925 break;
6926 }
6927 }
6928 if (ridx == sband->n_bitrates)
6929 return 0; /* rate not found */
6930 }
6931
6932 return mask;
6933}
6934
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006935static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6936 u8 *rates, u8 rates_len,
6937 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6938{
6939 u8 i;
6940
6941 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6942
6943 for (i = 0; i < rates_len; i++) {
6944 int ridx, rbit;
6945
6946 ridx = rates[i] / 8;
6947 rbit = BIT(rates[i] % 8);
6948
6949 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006950 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006951 return false;
6952
6953 /* check availability */
6954 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6955 mcs[ridx] |= rbit;
6956 else
6957 return false;
6958 }
6959
6960 return true;
6961}
6962
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006963static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006964 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6965 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006966 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6967 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006968};
6969
6970static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6971 struct genl_info *info)
6972{
6973 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006974 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006975 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006976 int rem, i;
6977 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006978 struct nlattr *tx_rates;
6979 struct ieee80211_supported_band *sband;
6980
6981 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6982 return -EINVAL;
6983
Johannes Berg4c476992010-10-04 21:36:35 +02006984 if (!rdev->ops->set_bitrate_mask)
6985 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006986
6987 memset(&mask, 0, sizeof(mask));
6988 /* Default to all rates enabled */
6989 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6990 sband = rdev->wiphy.bands[i];
6991 mask.control[i].legacy =
6992 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006993 if (sband)
6994 memcpy(mask.control[i].mcs,
6995 sband->ht_cap.mcs.rx_mask,
6996 sizeof(mask.control[i].mcs));
6997 else
6998 memset(mask.control[i].mcs, 0,
6999 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007000 }
7001
7002 /*
7003 * The nested attribute uses enum nl80211_band as the index. This maps
7004 * directly to the enum ieee80211_band values used in cfg80211.
7005 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007006 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007007 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7008 {
7009 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007010 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7011 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007012 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007013 if (sband == NULL)
7014 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007015 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7016 nla_len(tx_rates), nl80211_txattr_policy);
7017 if (tb[NL80211_TXRATE_LEGACY]) {
7018 mask.control[band].legacy = rateset_to_mask(
7019 sband,
7020 nla_data(tb[NL80211_TXRATE_LEGACY]),
7021 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307022 if ((mask.control[band].legacy == 0) &&
7023 nla_len(tb[NL80211_TXRATE_LEGACY]))
7024 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007025 }
7026 if (tb[NL80211_TXRATE_MCS]) {
7027 if (!ht_rateset_to_mask(
7028 sband,
7029 nla_data(tb[NL80211_TXRATE_MCS]),
7030 nla_len(tb[NL80211_TXRATE_MCS]),
7031 mask.control[band].mcs))
7032 return -EINVAL;
7033 }
7034
7035 if (mask.control[band].legacy == 0) {
7036 /* don't allow empty legacy rates if HT
7037 * is not even supported. */
7038 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7039 return -EINVAL;
7040
7041 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7042 if (mask.control[band].mcs[i])
7043 break;
7044
7045 /* legacy and mcs rates may not be both empty */
7046 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007047 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007048 }
7049 }
7050
Hila Gonene35e4d22012-06-27 17:19:42 +03007051 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007052}
7053
Johannes Berg2e161f72010-08-12 15:38:38 +02007054static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007055{
Johannes Berg4c476992010-10-04 21:36:35 +02007056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007057 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007058 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007059
7060 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7061 return -EINVAL;
7062
Johannes Berg2e161f72010-08-12 15:38:38 +02007063 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7064 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007065
Johannes Berg71bbc992012-06-15 15:30:18 +02007066 switch (wdev->iftype) {
7067 case NL80211_IFTYPE_STATION:
7068 case NL80211_IFTYPE_ADHOC:
7069 case NL80211_IFTYPE_P2P_CLIENT:
7070 case NL80211_IFTYPE_AP:
7071 case NL80211_IFTYPE_AP_VLAN:
7072 case NL80211_IFTYPE_MESH_POINT:
7073 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007074 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007075 break;
7076 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007077 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007078 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007079
7080 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007081 if (!rdev->ops->mgmt_tx)
7082 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007083
Eric W. Biederman15e47302012-09-07 20:12:54 +00007084 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007085 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7086 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007087}
7088
Johannes Berg2e161f72010-08-12 15:38:38 +02007089static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007090{
Johannes Berg4c476992010-10-04 21:36:35 +02007091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007092 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007093 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007094 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007095 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007096 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007097 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007098 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007099 bool offchan, no_cck, dont_wait_for_ack;
7100
7101 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007102
Johannes Berg683b6d32012-11-08 21:25:48 +01007103 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007104 return -EINVAL;
7105
Johannes Berg4c476992010-10-04 21:36:35 +02007106 if (!rdev->ops->mgmt_tx)
7107 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007108
Johannes Berg71bbc992012-06-15 15:30:18 +02007109 switch (wdev->iftype) {
7110 case NL80211_IFTYPE_STATION:
7111 case NL80211_IFTYPE_ADHOC:
7112 case NL80211_IFTYPE_P2P_CLIENT:
7113 case NL80211_IFTYPE_AP:
7114 case NL80211_IFTYPE_AP_VLAN:
7115 case NL80211_IFTYPE_MESH_POINT:
7116 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007117 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007118 break;
7119 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007120 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007121 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007122
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007123 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007124 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007125 return -EINVAL;
7126 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007127
7128 /*
7129 * We should wait on the channel for at least a minimum amount
7130 * of time (10ms) but no longer than the driver supports.
7131 */
7132 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7133 wait > rdev->wiphy.max_remain_on_channel_duration)
7134 return -EINVAL;
7135
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007136 }
7137
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007138 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7139
Johannes Berg7c4ef712011-11-18 15:33:48 +01007140 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7141 return -EINVAL;
7142
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307143 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7144
Johannes Berg683b6d32012-11-08 21:25:48 +01007145 err = nl80211_parse_chandef(rdev, info, &chandef);
7146 if (err)
7147 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007148
Johannes Berge247bd902011-11-04 11:18:21 +01007149 if (!dont_wait_for_ack) {
7150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7151 if (!msg)
7152 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007153
Eric W. Biederman15e47302012-09-07 20:12:54 +00007154 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007155 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007156
Johannes Berge247bd902011-11-04 11:18:21 +01007157 if (IS_ERR(hdr)) {
7158 err = PTR_ERR(hdr);
7159 goto free_msg;
7160 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007161 }
Johannes Berge247bd902011-11-04 11:18:21 +01007162
Johannes Berg683b6d32012-11-08 21:25:48 +01007163 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007164 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7165 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007166 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007167 if (err)
7168 goto free_msg;
7169
Johannes Berge247bd902011-11-04 11:18:21 +01007170 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007171 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7172 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007173
Johannes Berge247bd902011-11-04 11:18:21 +01007174 genlmsg_end(msg, hdr);
7175 return genlmsg_reply(msg, info);
7176 }
7177
7178 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007179
7180 nla_put_failure:
7181 err = -ENOBUFS;
7182 free_msg:
7183 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007184 return err;
7185}
7186
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007187static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7188{
7189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007190 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007191 u64 cookie;
7192
7193 if (!info->attrs[NL80211_ATTR_COOKIE])
7194 return -EINVAL;
7195
7196 if (!rdev->ops->mgmt_tx_cancel_wait)
7197 return -EOPNOTSUPP;
7198
Johannes Berg71bbc992012-06-15 15:30:18 +02007199 switch (wdev->iftype) {
7200 case NL80211_IFTYPE_STATION:
7201 case NL80211_IFTYPE_ADHOC:
7202 case NL80211_IFTYPE_P2P_CLIENT:
7203 case NL80211_IFTYPE_AP:
7204 case NL80211_IFTYPE_AP_VLAN:
7205 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007206 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007207 break;
7208 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007209 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007210 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007211
7212 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7213
Hila Gonene35e4d22012-06-27 17:19:42 +03007214 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007215}
7216
Kalle Valoffb9eb32010-02-17 17:58:10 +02007217static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7218{
Johannes Berg4c476992010-10-04 21:36:35 +02007219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007220 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007221 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007222 u8 ps_state;
7223 bool state;
7224 int err;
7225
Johannes Berg4c476992010-10-04 21:36:35 +02007226 if (!info->attrs[NL80211_ATTR_PS_STATE])
7227 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007228
7229 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7230
Johannes Berg4c476992010-10-04 21:36:35 +02007231 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7232 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007233
7234 wdev = dev->ieee80211_ptr;
7235
Johannes Berg4c476992010-10-04 21:36:35 +02007236 if (!rdev->ops->set_power_mgmt)
7237 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007238
7239 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7240
7241 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007242 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007243
Hila Gonene35e4d22012-06-27 17:19:42 +03007244 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007245 if (!err)
7246 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007247 return err;
7248}
7249
7250static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7251{
Johannes Berg4c476992010-10-04 21:36:35 +02007252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007253 enum nl80211_ps_state ps_state;
7254 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007255 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007256 struct sk_buff *msg;
7257 void *hdr;
7258 int err;
7259
Kalle Valoffb9eb32010-02-17 17:58:10 +02007260 wdev = dev->ieee80211_ptr;
7261
Johannes Berg4c476992010-10-04 21:36:35 +02007262 if (!rdev->ops->set_power_mgmt)
7263 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007264
7265 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007266 if (!msg)
7267 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007268
Eric W. Biederman15e47302012-09-07 20:12:54 +00007269 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007270 NL80211_CMD_GET_POWER_SAVE);
7271 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007272 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007273 goto free_msg;
7274 }
7275
7276 if (wdev->ps)
7277 ps_state = NL80211_PS_ENABLED;
7278 else
7279 ps_state = NL80211_PS_DISABLED;
7280
David S. Miller9360ffd2012-03-29 04:41:26 -04007281 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7282 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007283
7284 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007285 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007286
Johannes Berg4c476992010-10-04 21:36:35 +02007287 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007288 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007289 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007290 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007291 return err;
7292}
7293
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007294static struct nla_policy
7295nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7296 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7297 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7298 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007299 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7300 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7301 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007302};
7303
Thomas Pedersen84f10702012-07-12 16:17:33 -07007304static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007305 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007306{
7307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7308 struct wireless_dev *wdev;
7309 struct net_device *dev = info->user_ptr[1];
7310
Johannes Bergd9d8b012012-11-26 12:51:52 +01007311 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007312 return -EINVAL;
7313
7314 wdev = dev->ieee80211_ptr;
7315
7316 if (!rdev->ops->set_cqm_txe_config)
7317 return -EOPNOTSUPP;
7318
7319 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7320 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7321 return -EOPNOTSUPP;
7322
Hila Gonene35e4d22012-06-27 17:19:42 +03007323 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007324}
7325
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007326static int nl80211_set_cqm_rssi(struct genl_info *info,
7327 s32 threshold, u32 hysteresis)
7328{
Johannes Berg4c476992010-10-04 21:36:35 +02007329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007330 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007331 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007332
7333 if (threshold > 0)
7334 return -EINVAL;
7335
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007336 wdev = dev->ieee80211_ptr;
7337
Johannes Berg4c476992010-10-04 21:36:35 +02007338 if (!rdev->ops->set_cqm_rssi_config)
7339 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007340
Johannes Berg074ac8d2010-09-16 14:58:22 +02007341 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007342 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7343 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007344
Hila Gonene35e4d22012-06-27 17:19:42 +03007345 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007346}
7347
7348static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7349{
7350 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7351 struct nlattr *cqm;
7352 int err;
7353
7354 cqm = info->attrs[NL80211_ATTR_CQM];
7355 if (!cqm) {
7356 err = -EINVAL;
7357 goto out;
7358 }
7359
7360 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7361 nl80211_attr_cqm_policy);
7362 if (err)
7363 goto out;
7364
7365 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7366 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7367 s32 threshold;
7368 u32 hysteresis;
7369 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7370 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7371 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007372 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7373 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7374 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7375 u32 rate, pkts, intvl;
7376 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7377 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7378 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7379 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007380 } else
7381 err = -EINVAL;
7382
7383out:
7384 return err;
7385}
7386
Johannes Berg29cbe682010-12-03 09:20:44 +01007387static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7388{
7389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7390 struct net_device *dev = info->user_ptr[1];
7391 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007392 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007393 int err;
7394
7395 /* start with default */
7396 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007397 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007398
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007399 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007400 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007401 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007402 if (err)
7403 return err;
7404 }
7405
7406 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7407 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7408 return -EINVAL;
7409
Javier Cardonac80d5452010-12-16 17:37:49 -08007410 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7411 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7412
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007413 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7414 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7415 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7416 return -EINVAL;
7417
Marco Porsch9bdbf042013-01-07 16:04:51 +01007418 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7419 setup.beacon_interval =
7420 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7421 if (setup.beacon_interval < 10 ||
7422 setup.beacon_interval > 10000)
7423 return -EINVAL;
7424 }
7425
7426 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7427 setup.dtim_period =
7428 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7429 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7430 return -EINVAL;
7431 }
7432
Javier Cardonac80d5452010-12-16 17:37:49 -08007433 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7434 /* parse additional setup parameters if given */
7435 err = nl80211_parse_mesh_setup(info, &setup);
7436 if (err)
7437 return err;
7438 }
7439
Johannes Bergcc1d2802012-05-16 23:50:20 +02007440 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007441 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7442 if (err)
7443 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007444 } else {
7445 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007446 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007447 }
7448
Javier Cardonac80d5452010-12-16 17:37:49 -08007449 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007450}
7451
7452static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7453{
7454 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7455 struct net_device *dev = info->user_ptr[1];
7456
7457 return cfg80211_leave_mesh(rdev, dev);
7458}
7459
Johannes Bergdfb89c52012-06-27 09:23:48 +02007460#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007461static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7462 struct cfg80211_registered_device *rdev)
7463{
7464 struct nlattr *nl_pats, *nl_pat;
7465 int i, pat_len;
7466
7467 if (!rdev->wowlan->n_patterns)
7468 return 0;
7469
7470 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7471 if (!nl_pats)
7472 return -ENOBUFS;
7473
7474 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7475 nl_pat = nla_nest_start(msg, i + 1);
7476 if (!nl_pat)
7477 return -ENOBUFS;
7478 pat_len = rdev->wowlan->patterns[i].pattern_len;
7479 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7480 DIV_ROUND_UP(pat_len, 8),
7481 rdev->wowlan->patterns[i].mask) ||
7482 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7483 pat_len, rdev->wowlan->patterns[i].pattern) ||
7484 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7485 rdev->wowlan->patterns[i].pkt_offset))
7486 return -ENOBUFS;
7487 nla_nest_end(msg, nl_pat);
7488 }
7489 nla_nest_end(msg, nl_pats);
7490
7491 return 0;
7492}
7493
Johannes Berg2a0e0472013-01-23 22:57:40 +01007494static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7495 struct cfg80211_wowlan_tcp *tcp)
7496{
7497 struct nlattr *nl_tcp;
7498
7499 if (!tcp)
7500 return 0;
7501
7502 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7503 if (!nl_tcp)
7504 return -ENOBUFS;
7505
7506 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7507 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7508 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7509 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7510 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7511 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7512 tcp->payload_len, tcp->payload) ||
7513 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7514 tcp->data_interval) ||
7515 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7516 tcp->wake_len, tcp->wake_data) ||
7517 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7518 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7519 return -ENOBUFS;
7520
7521 if (tcp->payload_seq.len &&
7522 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7523 sizeof(tcp->payload_seq), &tcp->payload_seq))
7524 return -ENOBUFS;
7525
7526 if (tcp->payload_tok.len &&
7527 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7528 sizeof(tcp->payload_tok) + tcp->tokens_size,
7529 &tcp->payload_tok))
7530 return -ENOBUFS;
7531
7532 return 0;
7533}
7534
Johannes Bergff1b6e62011-05-04 15:37:28 +02007535static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7536{
7537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7538 struct sk_buff *msg;
7539 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007540 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007541
Johannes Berg2a0e0472013-01-23 22:57:40 +01007542 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7543 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007544 return -EOPNOTSUPP;
7545
Johannes Berg2a0e0472013-01-23 22:57:40 +01007546 if (rdev->wowlan && rdev->wowlan->tcp) {
7547 /* adjust size to have room for all the data */
7548 size += rdev->wowlan->tcp->tokens_size +
7549 rdev->wowlan->tcp->payload_len +
7550 rdev->wowlan->tcp->wake_len +
7551 rdev->wowlan->tcp->wake_len / 8;
7552 }
7553
7554 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007555 if (!msg)
7556 return -ENOMEM;
7557
Eric W. Biederman15e47302012-09-07 20:12:54 +00007558 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007559 NL80211_CMD_GET_WOWLAN);
7560 if (!hdr)
7561 goto nla_put_failure;
7562
7563 if (rdev->wowlan) {
7564 struct nlattr *nl_wowlan;
7565
7566 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7567 if (!nl_wowlan)
7568 goto nla_put_failure;
7569
David S. Miller9360ffd2012-03-29 04:41:26 -04007570 if ((rdev->wowlan->any &&
7571 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7572 (rdev->wowlan->disconnect &&
7573 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7574 (rdev->wowlan->magic_pkt &&
7575 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7576 (rdev->wowlan->gtk_rekey_failure &&
7577 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7578 (rdev->wowlan->eap_identity_req &&
7579 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7580 (rdev->wowlan->four_way_handshake &&
7581 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7582 (rdev->wowlan->rfkill_release &&
7583 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7584 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007585
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007586 if (nl80211_send_wowlan_patterns(msg, rdev))
7587 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007588
7589 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7590 goto nla_put_failure;
7591
Johannes Bergff1b6e62011-05-04 15:37:28 +02007592 nla_nest_end(msg, nl_wowlan);
7593 }
7594
7595 genlmsg_end(msg, hdr);
7596 return genlmsg_reply(msg, info);
7597
7598nla_put_failure:
7599 nlmsg_free(msg);
7600 return -ENOBUFS;
7601}
7602
Johannes Berg2a0e0472013-01-23 22:57:40 +01007603static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7604 struct nlattr *attr,
7605 struct cfg80211_wowlan *trig)
7606{
7607 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7608 struct cfg80211_wowlan_tcp *cfg;
7609 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7610 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7611 u32 size;
7612 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7613 int err, port;
7614
7615 if (!rdev->wiphy.wowlan.tcp)
7616 return -EINVAL;
7617
7618 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7619 nla_data(attr), nla_len(attr),
7620 nl80211_wowlan_tcp_policy);
7621 if (err)
7622 return err;
7623
7624 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7625 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7626 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7627 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7628 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7629 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7630 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7631 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7632 return -EINVAL;
7633
7634 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7635 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7636 return -EINVAL;
7637
7638 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg723d5682013-02-26 13:56:40 +01007639 rdev->wiphy.wowlan.tcp->data_interval_max ||
7640 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007641 return -EINVAL;
7642
7643 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7644 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7645 return -EINVAL;
7646
7647 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7648 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7649 return -EINVAL;
7650
7651 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7652 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7653
7654 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7655 tokens_size = tokln - sizeof(*tok);
7656
7657 if (!tok->len || tokens_size % tok->len)
7658 return -EINVAL;
7659 if (!rdev->wiphy.wowlan.tcp->tok)
7660 return -EINVAL;
7661 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7662 return -EINVAL;
7663 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7664 return -EINVAL;
7665 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7666 return -EINVAL;
7667 if (tok->offset + tok->len > data_size)
7668 return -EINVAL;
7669 }
7670
7671 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7672 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7673 if (!rdev->wiphy.wowlan.tcp->seq)
7674 return -EINVAL;
7675 if (seq->len == 0 || seq->len > 4)
7676 return -EINVAL;
7677 if (seq->len + seq->offset > data_size)
7678 return -EINVAL;
7679 }
7680
7681 size = sizeof(*cfg);
7682 size += data_size;
7683 size += wake_size + wake_mask_size;
7684 size += tokens_size;
7685
7686 cfg = kzalloc(size, GFP_KERNEL);
7687 if (!cfg)
7688 return -ENOMEM;
7689 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7690 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7691 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7692 ETH_ALEN);
7693 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7694 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7695 else
7696 port = 0;
7697#ifdef CONFIG_INET
7698 /* allocate a socket and port for it and use it */
7699 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7700 IPPROTO_TCP, &cfg->sock, 1);
7701 if (err) {
7702 kfree(cfg);
7703 return err;
7704 }
7705 if (inet_csk_get_port(cfg->sock->sk, port)) {
7706 sock_release(cfg->sock);
7707 kfree(cfg);
7708 return -EADDRINUSE;
7709 }
7710 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7711#else
7712 if (!port) {
7713 kfree(cfg);
7714 return -EINVAL;
7715 }
7716 cfg->src_port = port;
7717#endif
7718
7719 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7720 cfg->payload_len = data_size;
7721 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7722 memcpy((void *)cfg->payload,
7723 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7724 data_size);
7725 if (seq)
7726 cfg->payload_seq = *seq;
7727 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7728 cfg->wake_len = wake_size;
7729 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7730 memcpy((void *)cfg->wake_data,
7731 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7732 wake_size);
7733 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7734 data_size + wake_size;
7735 memcpy((void *)cfg->wake_mask,
7736 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7737 wake_mask_size);
7738 if (tok) {
7739 cfg->tokens_size = tokens_size;
7740 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7741 }
7742
7743 trig->tcp = cfg;
7744
7745 return 0;
7746}
7747
Johannes Bergff1b6e62011-05-04 15:37:28 +02007748static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7749{
7750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7751 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007752 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007753 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007754 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7755 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007756 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007757
Johannes Berg2a0e0472013-01-23 22:57:40 +01007758 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7759 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007760 return -EOPNOTSUPP;
7761
Johannes Bergae33bd82012-07-12 16:25:02 +02007762 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7763 cfg80211_rdev_free_wowlan(rdev);
7764 rdev->wowlan = NULL;
7765 goto set_wakeup;
7766 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007767
7768 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7769 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7770 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7771 nl80211_wowlan_policy);
7772 if (err)
7773 return err;
7774
7775 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7776 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7777 return -EINVAL;
7778 new_triggers.any = true;
7779 }
7780
7781 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7782 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7783 return -EINVAL;
7784 new_triggers.disconnect = true;
7785 }
7786
7787 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7788 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7789 return -EINVAL;
7790 new_triggers.magic_pkt = true;
7791 }
7792
Johannes Berg77dbbb132011-07-13 10:48:55 +02007793 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7794 return -EINVAL;
7795
7796 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7797 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7798 return -EINVAL;
7799 new_triggers.gtk_rekey_failure = true;
7800 }
7801
7802 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7803 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7804 return -EINVAL;
7805 new_triggers.eap_identity_req = true;
7806 }
7807
7808 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7809 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7810 return -EINVAL;
7811 new_triggers.four_way_handshake = true;
7812 }
7813
7814 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7815 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7816 return -EINVAL;
7817 new_triggers.rfkill_release = true;
7818 }
7819
Johannes Bergff1b6e62011-05-04 15:37:28 +02007820 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7821 struct nlattr *pat;
7822 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007823 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007824 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7825
7826 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7827 rem)
7828 n_patterns++;
7829 if (n_patterns > wowlan->n_patterns)
7830 return -EINVAL;
7831
7832 new_triggers.patterns = kcalloc(n_patterns,
7833 sizeof(new_triggers.patterns[0]),
7834 GFP_KERNEL);
7835 if (!new_triggers.patterns)
7836 return -ENOMEM;
7837
7838 new_triggers.n_patterns = n_patterns;
7839 i = 0;
7840
7841 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7842 rem) {
7843 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7844 nla_data(pat), nla_len(pat), NULL);
7845 err = -EINVAL;
7846 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7847 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7848 goto error;
7849 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7850 mask_len = DIV_ROUND_UP(pat_len, 8);
7851 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7852 mask_len)
7853 goto error;
7854 if (pat_len > wowlan->pattern_max_len ||
7855 pat_len < wowlan->pattern_min_len)
7856 goto error;
7857
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007858 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7859 pkt_offset = 0;
7860 else
7861 pkt_offset = nla_get_u32(
7862 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7863 if (pkt_offset > wowlan->max_pkt_offset)
7864 goto error;
7865 new_triggers.patterns[i].pkt_offset = pkt_offset;
7866
Johannes Bergff1b6e62011-05-04 15:37:28 +02007867 new_triggers.patterns[i].mask =
7868 kmalloc(mask_len + pat_len, GFP_KERNEL);
7869 if (!new_triggers.patterns[i].mask) {
7870 err = -ENOMEM;
7871 goto error;
7872 }
7873 new_triggers.patterns[i].pattern =
7874 new_triggers.patterns[i].mask + mask_len;
7875 memcpy(new_triggers.patterns[i].mask,
7876 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7877 mask_len);
7878 new_triggers.patterns[i].pattern_len = pat_len;
7879 memcpy(new_triggers.patterns[i].pattern,
7880 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7881 pat_len);
7882 i++;
7883 }
7884 }
7885
Johannes Berg2a0e0472013-01-23 22:57:40 +01007886 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7887 err = nl80211_parse_wowlan_tcp(
7888 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7889 &new_triggers);
7890 if (err)
7891 goto error;
7892 }
7893
Johannes Bergae33bd82012-07-12 16:25:02 +02007894 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7895 if (!ntrig) {
7896 err = -ENOMEM;
7897 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007898 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007899 cfg80211_rdev_free_wowlan(rdev);
7900 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007901
Johannes Bergae33bd82012-07-12 16:25:02 +02007902 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007903 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007904 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007905
Johannes Bergff1b6e62011-05-04 15:37:28 +02007906 return 0;
7907 error:
7908 for (i = 0; i < new_triggers.n_patterns; i++)
7909 kfree(new_triggers.patterns[i].mask);
7910 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007911 if (new_triggers.tcp && new_triggers.tcp->sock)
7912 sock_release(new_triggers.tcp->sock);
7913 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007914 return err;
7915}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007916#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007917
Johannes Berge5497d72011-07-05 16:35:40 +02007918static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7919{
7920 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7921 struct net_device *dev = info->user_ptr[1];
7922 struct wireless_dev *wdev = dev->ieee80211_ptr;
7923 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7924 struct cfg80211_gtk_rekey_data rekey_data;
7925 int err;
7926
7927 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7928 return -EINVAL;
7929
7930 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7931 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7932 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7933 nl80211_rekey_policy);
7934 if (err)
7935 return err;
7936
7937 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7938 return -ERANGE;
7939 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7940 return -ERANGE;
7941 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7942 return -ERANGE;
7943
7944 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7945 NL80211_KEK_LEN);
7946 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7947 NL80211_KCK_LEN);
7948 memcpy(rekey_data.replay_ctr,
7949 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7950 NL80211_REPLAY_CTR_LEN);
7951
7952 wdev_lock(wdev);
7953 if (!wdev->current_bss) {
7954 err = -ENOTCONN;
7955 goto out;
7956 }
7957
7958 if (!rdev->ops->set_rekey_data) {
7959 err = -EOPNOTSUPP;
7960 goto out;
7961 }
7962
Hila Gonene35e4d22012-06-27 17:19:42 +03007963 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007964 out:
7965 wdev_unlock(wdev);
7966 return err;
7967}
7968
Johannes Berg28946da2011-11-04 11:18:12 +01007969static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7970 struct genl_info *info)
7971{
7972 struct net_device *dev = info->user_ptr[1];
7973 struct wireless_dev *wdev = dev->ieee80211_ptr;
7974
7975 if (wdev->iftype != NL80211_IFTYPE_AP &&
7976 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7977 return -EINVAL;
7978
Eric W. Biederman15e47302012-09-07 20:12:54 +00007979 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01007980 return -EBUSY;
7981
Eric W. Biederman15e47302012-09-07 20:12:54 +00007982 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01007983 return 0;
7984}
7985
Johannes Berg7f6cf312011-11-04 11:18:15 +01007986static int nl80211_probe_client(struct sk_buff *skb,
7987 struct genl_info *info)
7988{
7989 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7990 struct net_device *dev = info->user_ptr[1];
7991 struct wireless_dev *wdev = dev->ieee80211_ptr;
7992 struct sk_buff *msg;
7993 void *hdr;
7994 const u8 *addr;
7995 u64 cookie;
7996 int err;
7997
7998 if (wdev->iftype != NL80211_IFTYPE_AP &&
7999 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8000 return -EOPNOTSUPP;
8001
8002 if (!info->attrs[NL80211_ATTR_MAC])
8003 return -EINVAL;
8004
8005 if (!rdev->ops->probe_client)
8006 return -EOPNOTSUPP;
8007
8008 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8009 if (!msg)
8010 return -ENOMEM;
8011
Eric W. Biederman15e47302012-09-07 20:12:54 +00008012 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008013 NL80211_CMD_PROBE_CLIENT);
8014
8015 if (IS_ERR(hdr)) {
8016 err = PTR_ERR(hdr);
8017 goto free_msg;
8018 }
8019
8020 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8021
Hila Gonene35e4d22012-06-27 17:19:42 +03008022 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008023 if (err)
8024 goto free_msg;
8025
David S. Miller9360ffd2012-03-29 04:41:26 -04008026 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8027 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008028
8029 genlmsg_end(msg, hdr);
8030
8031 return genlmsg_reply(msg, info);
8032
8033 nla_put_failure:
8034 err = -ENOBUFS;
8035 free_msg:
8036 nlmsg_free(msg);
8037 return err;
8038}
8039
Johannes Berg5e760232011-11-04 11:18:17 +01008040static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8041{
8042 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008043 struct cfg80211_beacon_registration *reg, *nreg;
8044 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008045
8046 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8047 return -EOPNOTSUPP;
8048
Ben Greear37c73b52012-10-26 14:49:25 -07008049 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8050 if (!nreg)
8051 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008052
Ben Greear37c73b52012-10-26 14:49:25 -07008053 /* First, check if already registered. */
8054 spin_lock_bh(&rdev->beacon_registrations_lock);
8055 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8056 if (reg->nlportid == info->snd_portid) {
8057 rv = -EALREADY;
8058 goto out_err;
8059 }
8060 }
8061 /* Add it to the list */
8062 nreg->nlportid = info->snd_portid;
8063 list_add(&nreg->list, &rdev->beacon_registrations);
8064
8065 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008066
8067 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008068out_err:
8069 spin_unlock_bh(&rdev->beacon_registrations_lock);
8070 kfree(nreg);
8071 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008072}
8073
Johannes Berg98104fde2012-06-16 00:19:54 +02008074static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8075{
8076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8077 struct wireless_dev *wdev = info->user_ptr[1];
8078 int err;
8079
8080 if (!rdev->ops->start_p2p_device)
8081 return -EOPNOTSUPP;
8082
8083 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8084 return -EOPNOTSUPP;
8085
8086 if (wdev->p2p_started)
8087 return 0;
8088
8089 mutex_lock(&rdev->devlist_mtx);
8090 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8091 mutex_unlock(&rdev->devlist_mtx);
8092 if (err)
8093 return err;
8094
Johannes Bergeeb126e2012-10-23 15:16:50 +02008095 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008096 if (err)
8097 return err;
8098
8099 wdev->p2p_started = true;
8100 mutex_lock(&rdev->devlist_mtx);
8101 rdev->opencount++;
8102 mutex_unlock(&rdev->devlist_mtx);
8103
8104 return 0;
8105}
8106
8107static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8108{
8109 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8110 struct wireless_dev *wdev = info->user_ptr[1];
8111
8112 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8113 return -EOPNOTSUPP;
8114
8115 if (!rdev->ops->stop_p2p_device)
8116 return -EOPNOTSUPP;
8117
8118 if (!wdev->p2p_started)
8119 return 0;
8120
Johannes Bergeeb126e2012-10-23 15:16:50 +02008121 rdev_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008122 wdev->p2p_started = false;
8123
8124 mutex_lock(&rdev->devlist_mtx);
8125 rdev->opencount--;
8126 mutex_unlock(&rdev->devlist_mtx);
8127
8128 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
8129 rdev->scan_req->aborted = true;
8130 ___cfg80211_scan_done(rdev, true);
8131 }
8132
8133 return 0;
8134}
8135
Johannes Berg3713b4e2013-02-14 16:19:38 +01008136static int nl80211_get_protocol_features(struct sk_buff *skb,
8137 struct genl_info *info)
8138{
8139 void *hdr;
8140 struct sk_buff *msg;
8141
8142 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8143 if (!msg)
8144 return -ENOMEM;
8145
8146 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8147 NL80211_CMD_GET_PROTOCOL_FEATURES);
8148 if (!hdr)
8149 goto nla_put_failure;
8150
8151 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8152 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8153 goto nla_put_failure;
8154
8155 genlmsg_end(msg, hdr);
8156 return genlmsg_reply(msg, info);
8157
8158 nla_put_failure:
8159 kfree_skb(msg);
8160 return -ENOBUFS;
8161}
8162
Johannes Berg4c476992010-10-04 21:36:35 +02008163#define NL80211_FLAG_NEED_WIPHY 0x01
8164#define NL80211_FLAG_NEED_NETDEV 0x02
8165#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008166#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8167#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8168 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008169#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008170/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008171#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8172 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008173
8174static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8175 struct genl_info *info)
8176{
8177 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008178 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008179 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008180 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8181
8182 if (rtnl)
8183 rtnl_lock();
8184
8185 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008186 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008187 if (IS_ERR(rdev)) {
8188 if (rtnl)
8189 rtnl_unlock();
8190 return PTR_ERR(rdev);
8191 }
8192 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008193 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8194 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008195 mutex_lock(&cfg80211_mutex);
8196 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8197 info->attrs);
8198 if (IS_ERR(wdev)) {
8199 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02008200 if (rtnl)
8201 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008202 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008203 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008204
Johannes Berg89a54e42012-06-15 14:33:17 +02008205 dev = wdev->netdev;
8206 rdev = wiphy_to_dev(wdev->wiphy);
8207
Johannes Berg1bf614e2012-06-15 15:23:36 +02008208 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8209 if (!dev) {
8210 mutex_unlock(&cfg80211_mutex);
8211 if (rtnl)
8212 rtnl_unlock();
8213 return -EINVAL;
8214 }
8215
8216 info->user_ptr[1] = dev;
8217 } else {
8218 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008219 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008220
Johannes Berg1bf614e2012-06-15 15:23:36 +02008221 if (dev) {
8222 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8223 !netif_running(dev)) {
8224 mutex_unlock(&cfg80211_mutex);
8225 if (rtnl)
8226 rtnl_unlock();
8227 return -ENETDOWN;
8228 }
8229
8230 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008231 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8232 if (!wdev->p2p_started) {
8233 mutex_unlock(&cfg80211_mutex);
8234 if (rtnl)
8235 rtnl_unlock();
8236 return -ENETDOWN;
8237 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008238 }
8239
Johannes Berg89a54e42012-06-15 14:33:17 +02008240 cfg80211_lock_rdev(rdev);
8241
8242 mutex_unlock(&cfg80211_mutex);
8243
Johannes Berg4c476992010-10-04 21:36:35 +02008244 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008245 }
8246
8247 return 0;
8248}
8249
8250static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8251 struct genl_info *info)
8252{
8253 if (info->user_ptr[0])
8254 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02008255 if (info->user_ptr[1]) {
8256 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8257 struct wireless_dev *wdev = info->user_ptr[1];
8258
8259 if (wdev->netdev)
8260 dev_put(wdev->netdev);
8261 } else {
8262 dev_put(info->user_ptr[1]);
8263 }
8264 }
Johannes Berg4c476992010-10-04 21:36:35 +02008265 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8266 rtnl_unlock();
8267}
8268
Johannes Berg55682962007-09-20 13:09:35 -04008269static struct genl_ops nl80211_ops[] = {
8270 {
8271 .cmd = NL80211_CMD_GET_WIPHY,
8272 .doit = nl80211_get_wiphy,
8273 .dumpit = nl80211_dump_wiphy,
8274 .policy = nl80211_policy,
8275 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008276 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04008277 },
8278 {
8279 .cmd = NL80211_CMD_SET_WIPHY,
8280 .doit = nl80211_set_wiphy,
8281 .policy = nl80211_policy,
8282 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008283 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008284 },
8285 {
8286 .cmd = NL80211_CMD_GET_INTERFACE,
8287 .doit = nl80211_get_interface,
8288 .dumpit = nl80211_dump_interface,
8289 .policy = nl80211_policy,
8290 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02008291 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04008292 },
8293 {
8294 .cmd = NL80211_CMD_SET_INTERFACE,
8295 .doit = nl80211_set_interface,
8296 .policy = nl80211_policy,
8297 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008298 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8299 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008300 },
8301 {
8302 .cmd = NL80211_CMD_NEW_INTERFACE,
8303 .doit = nl80211_new_interface,
8304 .policy = nl80211_policy,
8305 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008306 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8307 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008308 },
8309 {
8310 .cmd = NL80211_CMD_DEL_INTERFACE,
8311 .doit = nl80211_del_interface,
8312 .policy = nl80211_policy,
8313 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008314 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008315 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008316 },
Johannes Berg41ade002007-12-19 02:03:29 +01008317 {
8318 .cmd = NL80211_CMD_GET_KEY,
8319 .doit = nl80211_get_key,
8320 .policy = nl80211_policy,
8321 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008322 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008323 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008324 },
8325 {
8326 .cmd = NL80211_CMD_SET_KEY,
8327 .doit = nl80211_set_key,
8328 .policy = nl80211_policy,
8329 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008330 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008331 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008332 },
8333 {
8334 .cmd = NL80211_CMD_NEW_KEY,
8335 .doit = nl80211_new_key,
8336 .policy = nl80211_policy,
8337 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008338 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008339 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008340 },
8341 {
8342 .cmd = NL80211_CMD_DEL_KEY,
8343 .doit = nl80211_del_key,
8344 .policy = nl80211_policy,
8345 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008346 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008347 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008348 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008349 {
8350 .cmd = NL80211_CMD_SET_BEACON,
8351 .policy = nl80211_policy,
8352 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008353 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008355 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008356 },
8357 {
Johannes Berg88600202012-02-13 15:17:18 +01008358 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008359 .policy = nl80211_policy,
8360 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008361 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008363 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008364 },
8365 {
Johannes Berg88600202012-02-13 15:17:18 +01008366 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008367 .policy = nl80211_policy,
8368 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008369 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008371 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008372 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008373 {
8374 .cmd = NL80211_CMD_GET_STATION,
8375 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008376 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008377 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008378 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8379 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008380 },
8381 {
8382 .cmd = NL80211_CMD_SET_STATION,
8383 .doit = nl80211_set_station,
8384 .policy = nl80211_policy,
8385 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008387 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008388 },
8389 {
8390 .cmd = NL80211_CMD_NEW_STATION,
8391 .doit = nl80211_new_station,
8392 .policy = nl80211_policy,
8393 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008395 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008396 },
8397 {
8398 .cmd = NL80211_CMD_DEL_STATION,
8399 .doit = nl80211_del_station,
8400 .policy = nl80211_policy,
8401 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008403 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008404 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008405 {
8406 .cmd = NL80211_CMD_GET_MPATH,
8407 .doit = nl80211_get_mpath,
8408 .dumpit = nl80211_dump_mpath,
8409 .policy = nl80211_policy,
8410 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008412 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008413 },
8414 {
8415 .cmd = NL80211_CMD_SET_MPATH,
8416 .doit = nl80211_set_mpath,
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,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008421 },
8422 {
8423 .cmd = NL80211_CMD_NEW_MPATH,
8424 .doit = nl80211_new_mpath,
8425 .policy = nl80211_policy,
8426 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008428 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008429 },
8430 {
8431 .cmd = NL80211_CMD_DEL_MPATH,
8432 .doit = nl80211_del_mpath,
8433 .policy = nl80211_policy,
8434 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008436 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008437 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008438 {
8439 .cmd = NL80211_CMD_SET_BSS,
8440 .doit = nl80211_set_bss,
8441 .policy = nl80211_policy,
8442 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008444 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008445 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008446 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008447 .cmd = NL80211_CMD_GET_REG,
8448 .doit = nl80211_get_reg,
8449 .policy = nl80211_policy,
8450 /* can be retrieved by unprivileged users */
8451 },
8452 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008453 .cmd = NL80211_CMD_SET_REG,
8454 .doit = nl80211_set_reg,
8455 .policy = nl80211_policy,
8456 .flags = GENL_ADMIN_PERM,
8457 },
8458 {
8459 .cmd = NL80211_CMD_REQ_SET_REG,
8460 .doit = nl80211_req_set_reg,
8461 .policy = nl80211_policy,
8462 .flags = GENL_ADMIN_PERM,
8463 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008464 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008465 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8466 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008467 .policy = nl80211_policy,
8468 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008470 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008471 },
8472 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008473 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8474 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008475 .policy = nl80211_policy,
8476 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008477 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008478 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008479 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008480 {
Johannes Berg2a519312009-02-10 21:25:55 +01008481 .cmd = NL80211_CMD_TRIGGER_SCAN,
8482 .doit = nl80211_trigger_scan,
8483 .policy = nl80211_policy,
8484 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008485 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008486 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008487 },
8488 {
8489 .cmd = NL80211_CMD_GET_SCAN,
8490 .policy = nl80211_policy,
8491 .dumpit = nl80211_dump_scan,
8492 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008493 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008494 .cmd = NL80211_CMD_START_SCHED_SCAN,
8495 .doit = nl80211_start_sched_scan,
8496 .policy = nl80211_policy,
8497 .flags = GENL_ADMIN_PERM,
8498 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8499 NL80211_FLAG_NEED_RTNL,
8500 },
8501 {
8502 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8503 .doit = nl80211_stop_sched_scan,
8504 .policy = nl80211_policy,
8505 .flags = GENL_ADMIN_PERM,
8506 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8507 NL80211_FLAG_NEED_RTNL,
8508 },
8509 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008510 .cmd = NL80211_CMD_AUTHENTICATE,
8511 .doit = nl80211_authenticate,
8512 .policy = nl80211_policy,
8513 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008514 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008515 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008516 },
8517 {
8518 .cmd = NL80211_CMD_ASSOCIATE,
8519 .doit = nl80211_associate,
8520 .policy = nl80211_policy,
8521 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008523 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008524 },
8525 {
8526 .cmd = NL80211_CMD_DEAUTHENTICATE,
8527 .doit = nl80211_deauthenticate,
8528 .policy = nl80211_policy,
8529 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008531 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008532 },
8533 {
8534 .cmd = NL80211_CMD_DISASSOCIATE,
8535 .doit = nl80211_disassociate,
8536 .policy = nl80211_policy,
8537 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008539 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008540 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008541 {
8542 .cmd = NL80211_CMD_JOIN_IBSS,
8543 .doit = nl80211_join_ibss,
8544 .policy = nl80211_policy,
8545 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008547 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008548 },
8549 {
8550 .cmd = NL80211_CMD_LEAVE_IBSS,
8551 .doit = nl80211_leave_ibss,
8552 .policy = nl80211_policy,
8553 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008555 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008556 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008557#ifdef CONFIG_NL80211_TESTMODE
8558 {
8559 .cmd = NL80211_CMD_TESTMODE,
8560 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008561 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008562 .policy = nl80211_policy,
8563 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008564 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8565 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008566 },
8567#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008568 {
8569 .cmd = NL80211_CMD_CONNECT,
8570 .doit = nl80211_connect,
8571 .policy = nl80211_policy,
8572 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008573 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008574 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008575 },
8576 {
8577 .cmd = NL80211_CMD_DISCONNECT,
8578 .doit = nl80211_disconnect,
8579 .policy = nl80211_policy,
8580 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008581 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008582 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008583 },
Johannes Berg463d0182009-07-14 00:33:35 +02008584 {
8585 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8586 .doit = nl80211_wiphy_netns,
8587 .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 Berg463d0182009-07-14 00:33:35 +02008591 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008592 {
8593 .cmd = NL80211_CMD_GET_SURVEY,
8594 .policy = nl80211_policy,
8595 .dumpit = nl80211_dump_survey,
8596 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008597 {
8598 .cmd = NL80211_CMD_SET_PMKSA,
8599 .doit = nl80211_setdel_pmksa,
8600 .policy = nl80211_policy,
8601 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008603 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008604 },
8605 {
8606 .cmd = NL80211_CMD_DEL_PMKSA,
8607 .doit = nl80211_setdel_pmksa,
8608 .policy = nl80211_policy,
8609 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008611 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008612 },
8613 {
8614 .cmd = NL80211_CMD_FLUSH_PMKSA,
8615 .doit = nl80211_flush_pmksa,
8616 .policy = nl80211_policy,
8617 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008618 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008619 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008620 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008621 {
8622 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8623 .doit = nl80211_remain_on_channel,
8624 .policy = nl80211_policy,
8625 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008626 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008627 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008628 },
8629 {
8630 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8631 .doit = nl80211_cancel_remain_on_channel,
8632 .policy = nl80211_policy,
8633 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008634 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008635 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008636 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008637 {
8638 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8639 .doit = nl80211_set_tx_bitrate_mask,
8640 .policy = nl80211_policy,
8641 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008642 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8643 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008644 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008645 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008646 .cmd = NL80211_CMD_REGISTER_FRAME,
8647 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008648 .policy = nl80211_policy,
8649 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008650 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008651 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008652 },
8653 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008654 .cmd = NL80211_CMD_FRAME,
8655 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008656 .policy = nl80211_policy,
8657 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008658 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008659 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008660 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008661 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008662 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8663 .doit = nl80211_tx_mgmt_cancel_wait,
8664 .policy = nl80211_policy,
8665 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008666 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008667 NL80211_FLAG_NEED_RTNL,
8668 },
8669 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008670 .cmd = NL80211_CMD_SET_POWER_SAVE,
8671 .doit = nl80211_set_power_save,
8672 .policy = nl80211_policy,
8673 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008674 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8675 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008676 },
8677 {
8678 .cmd = NL80211_CMD_GET_POWER_SAVE,
8679 .doit = nl80211_get_power_save,
8680 .policy = nl80211_policy,
8681 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008682 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8683 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008684 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008685 {
8686 .cmd = NL80211_CMD_SET_CQM,
8687 .doit = nl80211_set_cqm,
8688 .policy = nl80211_policy,
8689 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008690 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8691 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008692 },
Johannes Bergf444de02010-05-05 15:25:02 +02008693 {
8694 .cmd = NL80211_CMD_SET_CHANNEL,
8695 .doit = nl80211_set_channel,
8696 .policy = nl80211_policy,
8697 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008698 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8699 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008700 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008701 {
8702 .cmd = NL80211_CMD_SET_WDS_PEER,
8703 .doit = nl80211_set_wds_peer,
8704 .policy = nl80211_policy,
8705 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008706 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8707 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008708 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008709 {
8710 .cmd = NL80211_CMD_JOIN_MESH,
8711 .doit = nl80211_join_mesh,
8712 .policy = nl80211_policy,
8713 .flags = GENL_ADMIN_PERM,
8714 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8715 NL80211_FLAG_NEED_RTNL,
8716 },
8717 {
8718 .cmd = NL80211_CMD_LEAVE_MESH,
8719 .doit = nl80211_leave_mesh,
8720 .policy = nl80211_policy,
8721 .flags = GENL_ADMIN_PERM,
8722 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8723 NL80211_FLAG_NEED_RTNL,
8724 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008725#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008726 {
8727 .cmd = NL80211_CMD_GET_WOWLAN,
8728 .doit = nl80211_get_wowlan,
8729 .policy = nl80211_policy,
8730 /* can be retrieved by unprivileged users */
8731 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8732 NL80211_FLAG_NEED_RTNL,
8733 },
8734 {
8735 .cmd = NL80211_CMD_SET_WOWLAN,
8736 .doit = nl80211_set_wowlan,
8737 .policy = nl80211_policy,
8738 .flags = GENL_ADMIN_PERM,
8739 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8740 NL80211_FLAG_NEED_RTNL,
8741 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008742#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008743 {
8744 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8745 .doit = nl80211_set_rekey_data,
8746 .policy = nl80211_policy,
8747 .flags = GENL_ADMIN_PERM,
8748 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8749 NL80211_FLAG_NEED_RTNL,
8750 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008751 {
8752 .cmd = NL80211_CMD_TDLS_MGMT,
8753 .doit = nl80211_tdls_mgmt,
8754 .policy = nl80211_policy,
8755 .flags = GENL_ADMIN_PERM,
8756 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8757 NL80211_FLAG_NEED_RTNL,
8758 },
8759 {
8760 .cmd = NL80211_CMD_TDLS_OPER,
8761 .doit = nl80211_tdls_oper,
8762 .policy = nl80211_policy,
8763 .flags = GENL_ADMIN_PERM,
8764 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8765 NL80211_FLAG_NEED_RTNL,
8766 },
Johannes Berg28946da2011-11-04 11:18:12 +01008767 {
8768 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8769 .doit = nl80211_register_unexpected_frame,
8770 .policy = nl80211_policy,
8771 .flags = GENL_ADMIN_PERM,
8772 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8773 NL80211_FLAG_NEED_RTNL,
8774 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008775 {
8776 .cmd = NL80211_CMD_PROBE_CLIENT,
8777 .doit = nl80211_probe_client,
8778 .policy = nl80211_policy,
8779 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008780 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008781 NL80211_FLAG_NEED_RTNL,
8782 },
Johannes Berg5e760232011-11-04 11:18:17 +01008783 {
8784 .cmd = NL80211_CMD_REGISTER_BEACONS,
8785 .doit = nl80211_register_beacons,
8786 .policy = nl80211_policy,
8787 .flags = GENL_ADMIN_PERM,
8788 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8789 NL80211_FLAG_NEED_RTNL,
8790 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008791 {
8792 .cmd = NL80211_CMD_SET_NOACK_MAP,
8793 .doit = nl80211_set_noack_map,
8794 .policy = nl80211_policy,
8795 .flags = GENL_ADMIN_PERM,
8796 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8797 NL80211_FLAG_NEED_RTNL,
8798 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008799 {
8800 .cmd = NL80211_CMD_START_P2P_DEVICE,
8801 .doit = nl80211_start_p2p_device,
8802 .policy = nl80211_policy,
8803 .flags = GENL_ADMIN_PERM,
8804 .internal_flags = NL80211_FLAG_NEED_WDEV |
8805 NL80211_FLAG_NEED_RTNL,
8806 },
8807 {
8808 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8809 .doit = nl80211_stop_p2p_device,
8810 .policy = nl80211_policy,
8811 .flags = GENL_ADMIN_PERM,
8812 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8813 NL80211_FLAG_NEED_RTNL,
8814 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008815 {
8816 .cmd = NL80211_CMD_SET_MCAST_RATE,
8817 .doit = nl80211_set_mcast_rate,
8818 .policy = nl80211_policy,
8819 .flags = GENL_ADMIN_PERM,
8820 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8821 NL80211_FLAG_NEED_RTNL,
8822 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308823 {
8824 .cmd = NL80211_CMD_SET_MAC_ACL,
8825 .doit = nl80211_set_mac_acl,
8826 .policy = nl80211_policy,
8827 .flags = GENL_ADMIN_PERM,
8828 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8829 NL80211_FLAG_NEED_RTNL,
8830 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008831 {
8832 .cmd = NL80211_CMD_RADAR_DETECT,
8833 .doit = nl80211_start_radar_detection,
8834 .policy = nl80211_policy,
8835 .flags = GENL_ADMIN_PERM,
8836 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8837 NL80211_FLAG_NEED_RTNL,
8838 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008839 {
8840 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8841 .doit = nl80211_get_protocol_features,
8842 .policy = nl80211_policy,
8843 },
Johannes Berg55682962007-09-20 13:09:35 -04008844};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008845
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008846static struct genl_multicast_group nl80211_mlme_mcgrp = {
8847 .name = "mlme",
8848};
Johannes Berg55682962007-09-20 13:09:35 -04008849
8850/* multicast groups */
8851static struct genl_multicast_group nl80211_config_mcgrp = {
8852 .name = "config",
8853};
Johannes Berg2a519312009-02-10 21:25:55 +01008854static struct genl_multicast_group nl80211_scan_mcgrp = {
8855 .name = "scan",
8856};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008857static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8858 .name = "regulatory",
8859};
Johannes Berg55682962007-09-20 13:09:35 -04008860
8861/* notification functions */
8862
8863void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8864{
8865 struct sk_buff *msg;
8866
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008867 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008868 if (!msg)
8869 return;
8870
Johannes Berg3713b4e2013-02-14 16:19:38 +01008871 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8872 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008873 nlmsg_free(msg);
8874 return;
8875 }
8876
Johannes Berg463d0182009-07-14 00:33:35 +02008877 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8878 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008879}
8880
Johannes Berg362a4152009-05-24 16:43:15 +02008881static int nl80211_add_scan_req(struct sk_buff *msg,
8882 struct cfg80211_registered_device *rdev)
8883{
8884 struct cfg80211_scan_request *req = rdev->scan_req;
8885 struct nlattr *nest;
8886 int i;
8887
Johannes Berg667503d2009-07-07 03:56:11 +02008888 ASSERT_RDEV_LOCK(rdev);
8889
Johannes Berg362a4152009-05-24 16:43:15 +02008890 if (WARN_ON(!req))
8891 return 0;
8892
8893 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8894 if (!nest)
8895 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008896 for (i = 0; i < req->n_ssids; i++) {
8897 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8898 goto nla_put_failure;
8899 }
Johannes Berg362a4152009-05-24 16:43:15 +02008900 nla_nest_end(msg, nest);
8901
8902 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8903 if (!nest)
8904 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008905 for (i = 0; i < req->n_channels; i++) {
8906 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8907 goto nla_put_failure;
8908 }
Johannes Berg362a4152009-05-24 16:43:15 +02008909 nla_nest_end(msg, nest);
8910
David S. Miller9360ffd2012-03-29 04:41:26 -04008911 if (req->ie &&
8912 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8913 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008914
Sam Lefflered4737712012-10-11 21:03:31 -07008915 if (req->flags)
8916 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8917
Johannes Berg362a4152009-05-24 16:43:15 +02008918 return 0;
8919 nla_put_failure:
8920 return -ENOBUFS;
8921}
8922
Johannes Berga538e2d2009-06-16 19:56:42 +02008923static int nl80211_send_scan_msg(struct sk_buff *msg,
8924 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008925 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008926 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008927 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008928{
8929 void *hdr;
8930
Eric W. Biederman15e47302012-09-07 20:12:54 +00008931 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008932 if (!hdr)
8933 return -1;
8934
David S. Miller9360ffd2012-03-29 04:41:26 -04008935 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008936 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8937 wdev->netdev->ifindex)) ||
8938 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008939 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008940
Johannes Berg362a4152009-05-24 16:43:15 +02008941 /* ignore errors and send incomplete event anyway */
8942 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008943
8944 return genlmsg_end(msg, hdr);
8945
8946 nla_put_failure:
8947 genlmsg_cancel(msg, hdr);
8948 return -EMSGSIZE;
8949}
8950
Luciano Coelho807f8a82011-05-11 17:09:35 +03008951static int
8952nl80211_send_sched_scan_msg(struct sk_buff *msg,
8953 struct cfg80211_registered_device *rdev,
8954 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008955 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008956{
8957 void *hdr;
8958
Eric W. Biederman15e47302012-09-07 20:12:54 +00008959 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008960 if (!hdr)
8961 return -1;
8962
David S. Miller9360ffd2012-03-29 04:41:26 -04008963 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8964 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8965 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008966
8967 return genlmsg_end(msg, hdr);
8968
8969 nla_put_failure:
8970 genlmsg_cancel(msg, hdr);
8971 return -EMSGSIZE;
8972}
8973
Johannes Berga538e2d2009-06-16 19:56:42 +02008974void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008975 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02008976{
8977 struct sk_buff *msg;
8978
Thomas Graf58050fc2012-06-28 03:57:45 +00008979 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008980 if (!msg)
8981 return;
8982
Johannes Bergfd014282012-06-18 19:17:03 +02008983 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008984 NL80211_CMD_TRIGGER_SCAN) < 0) {
8985 nlmsg_free(msg);
8986 return;
8987 }
8988
Johannes Berg463d0182009-07-14 00:33:35 +02008989 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8990 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008991}
8992
Johannes Berg2a519312009-02-10 21:25:55 +01008993void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008994 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01008995{
8996 struct sk_buff *msg;
8997
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008998 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008999 if (!msg)
9000 return;
9001
Johannes Bergfd014282012-06-18 19:17:03 +02009002 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009003 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009004 nlmsg_free(msg);
9005 return;
9006 }
9007
Johannes Berg463d0182009-07-14 00:33:35 +02009008 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9009 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009010}
9011
9012void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009013 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009014{
9015 struct sk_buff *msg;
9016
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009017 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009018 if (!msg)
9019 return;
9020
Johannes Bergfd014282012-06-18 19:17:03 +02009021 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009022 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009023 nlmsg_free(msg);
9024 return;
9025 }
9026
Johannes Berg463d0182009-07-14 00:33:35 +02009027 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9028 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009029}
9030
Luciano Coelho807f8a82011-05-11 17:09:35 +03009031void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9032 struct net_device *netdev)
9033{
9034 struct sk_buff *msg;
9035
9036 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9037 if (!msg)
9038 return;
9039
9040 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9041 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9042 nlmsg_free(msg);
9043 return;
9044 }
9045
9046 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9047 nl80211_scan_mcgrp.id, GFP_KERNEL);
9048}
9049
9050void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9051 struct net_device *netdev, u32 cmd)
9052{
9053 struct sk_buff *msg;
9054
Thomas Graf58050fc2012-06-28 03:57:45 +00009055 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009056 if (!msg)
9057 return;
9058
9059 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9060 nlmsg_free(msg);
9061 return;
9062 }
9063
9064 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9065 nl80211_scan_mcgrp.id, GFP_KERNEL);
9066}
9067
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009068/*
9069 * This can happen on global regulatory changes or device specific settings
9070 * based on custom world regulatory domains.
9071 */
9072void nl80211_send_reg_change_event(struct regulatory_request *request)
9073{
9074 struct sk_buff *msg;
9075 void *hdr;
9076
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009077 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009078 if (!msg)
9079 return;
9080
9081 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9082 if (!hdr) {
9083 nlmsg_free(msg);
9084 return;
9085 }
9086
9087 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009088 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9089 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009090
David S. Miller9360ffd2012-03-29 04:41:26 -04009091 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9092 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9093 NL80211_REGDOM_TYPE_WORLD))
9094 goto nla_put_failure;
9095 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9096 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9097 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9098 goto nla_put_failure;
9099 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9100 request->intersect) {
9101 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9102 NL80211_REGDOM_TYPE_INTERSECTION))
9103 goto nla_put_failure;
9104 } else {
9105 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9106 NL80211_REGDOM_TYPE_COUNTRY) ||
9107 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9108 request->alpha2))
9109 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009110 }
9111
Johannes Bergf4173762012-12-03 18:23:37 +01009112 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009113 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9114 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009115
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009116 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009117
Johannes Bergbc43b282009-07-25 10:54:13 +02009118 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009119 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009120 GFP_ATOMIC);
9121 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009122
9123 return;
9124
9125nla_put_failure:
9126 genlmsg_cancel(msg, hdr);
9127 nlmsg_free(msg);
9128}
9129
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009130static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9131 struct net_device *netdev,
9132 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009133 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009134{
9135 struct sk_buff *msg;
9136 void *hdr;
9137
Johannes Berge6d6e342009-07-01 21:26:47 +02009138 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009139 if (!msg)
9140 return;
9141
9142 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9143 if (!hdr) {
9144 nlmsg_free(msg);
9145 return;
9146 }
9147
David S. Miller9360ffd2012-03-29 04:41:26 -04009148 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9149 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9150 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9151 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009152
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009153 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009154
Johannes Berg463d0182009-07-14 00:33:35 +02009155 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9156 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009157 return;
9158
9159 nla_put_failure:
9160 genlmsg_cancel(msg, hdr);
9161 nlmsg_free(msg);
9162}
9163
9164void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009165 struct net_device *netdev, const u8 *buf,
9166 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009167{
9168 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009169 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009170}
9171
9172void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9173 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009174 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009175{
Johannes Berge6d6e342009-07-01 21:26:47 +02009176 nl80211_send_mlme_event(rdev, netdev, buf, len,
9177 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009178}
9179
Jouni Malinen53b46b82009-03-27 20:53:56 +02009180void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009181 struct net_device *netdev, const u8 *buf,
9182 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009183{
9184 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009185 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009186}
9187
Jouni Malinen53b46b82009-03-27 20:53:56 +02009188void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9189 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009190 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009191{
9192 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009193 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009194}
9195
Johannes Berg947add32013-02-22 22:05:20 +01009196void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9197 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009198{
Johannes Berg947add32013-02-22 22:05:20 +01009199 struct wireless_dev *wdev = dev->ieee80211_ptr;
9200 struct wiphy *wiphy = wdev->wiphy;
9201 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009202
Johannes Berg947add32013-02-22 22:05:20 +01009203 trace_cfg80211_send_unprot_deauth(dev);
9204 nl80211_send_mlme_event(rdev, dev, buf, len,
9205 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009206}
Johannes Berg947add32013-02-22 22:05:20 +01009207EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9208
9209void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9210 size_t len)
9211{
9212 struct wireless_dev *wdev = dev->ieee80211_ptr;
9213 struct wiphy *wiphy = wdev->wiphy;
9214 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9215
9216 trace_cfg80211_send_unprot_disassoc(dev);
9217 nl80211_send_mlme_event(rdev, dev, buf, len,
9218 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9219}
9220EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009221
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009222static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9223 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009224 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009225{
9226 struct sk_buff *msg;
9227 void *hdr;
9228
Johannes Berge6d6e342009-07-01 21:26:47 +02009229 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009230 if (!msg)
9231 return;
9232
9233 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9234 if (!hdr) {
9235 nlmsg_free(msg);
9236 return;
9237 }
9238
David S. Miller9360ffd2012-03-29 04:41:26 -04009239 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9240 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9241 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9242 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9243 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009244
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009245 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009246
Johannes Berg463d0182009-07-14 00:33:35 +02009247 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9248 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009249 return;
9250
9251 nla_put_failure:
9252 genlmsg_cancel(msg, hdr);
9253 nlmsg_free(msg);
9254}
9255
9256void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009257 struct net_device *netdev, const u8 *addr,
9258 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009259{
9260 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009261 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009262}
9263
9264void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009265 struct net_device *netdev, const u8 *addr,
9266 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009267{
Johannes Berge6d6e342009-07-01 21:26:47 +02009268 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9269 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009270}
9271
Samuel Ortizb23aa672009-07-01 21:26:54 +02009272void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9273 struct net_device *netdev, const u8 *bssid,
9274 const u8 *req_ie, size_t req_ie_len,
9275 const u8 *resp_ie, size_t resp_ie_len,
9276 u16 status, gfp_t gfp)
9277{
9278 struct sk_buff *msg;
9279 void *hdr;
9280
Thomas Graf58050fc2012-06-28 03:57:45 +00009281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009282 if (!msg)
9283 return;
9284
9285 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9286 if (!hdr) {
9287 nlmsg_free(msg);
9288 return;
9289 }
9290
David S. Miller9360ffd2012-03-29 04:41:26 -04009291 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9292 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9293 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9294 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9295 (req_ie &&
9296 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9297 (resp_ie &&
9298 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9299 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009300
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009301 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009302
Johannes Berg463d0182009-07-14 00:33:35 +02009303 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9304 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009305 return;
9306
9307 nla_put_failure:
9308 genlmsg_cancel(msg, hdr);
9309 nlmsg_free(msg);
9310
9311}
9312
9313void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9314 struct net_device *netdev, const u8 *bssid,
9315 const u8 *req_ie, size_t req_ie_len,
9316 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9317{
9318 struct sk_buff *msg;
9319 void *hdr;
9320
Thomas Graf58050fc2012-06-28 03:57:45 +00009321 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009322 if (!msg)
9323 return;
9324
9325 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9326 if (!hdr) {
9327 nlmsg_free(msg);
9328 return;
9329 }
9330
David S. Miller9360ffd2012-03-29 04:41:26 -04009331 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9332 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9333 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9334 (req_ie &&
9335 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9336 (resp_ie &&
9337 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9338 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009339
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009340 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009341
Johannes Berg463d0182009-07-14 00:33:35 +02009342 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9343 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009344 return;
9345
9346 nla_put_failure:
9347 genlmsg_cancel(msg, hdr);
9348 nlmsg_free(msg);
9349
9350}
9351
9352void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9353 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009354 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009355{
9356 struct sk_buff *msg;
9357 void *hdr;
9358
Thomas Graf58050fc2012-06-28 03:57:45 +00009359 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009360 if (!msg)
9361 return;
9362
9363 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9364 if (!hdr) {
9365 nlmsg_free(msg);
9366 return;
9367 }
9368
David S. Miller9360ffd2012-03-29 04:41:26 -04009369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9370 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9371 (from_ap && reason &&
9372 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9373 (from_ap &&
9374 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9375 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9376 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009377
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009378 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009379
Johannes Berg463d0182009-07-14 00:33:35 +02009380 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9381 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009382 return;
9383
9384 nla_put_failure:
9385 genlmsg_cancel(msg, hdr);
9386 nlmsg_free(msg);
9387
9388}
9389
Johannes Berg04a773a2009-04-19 21:24:32 +02009390void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9391 struct net_device *netdev, const u8 *bssid,
9392 gfp_t gfp)
9393{
9394 struct sk_buff *msg;
9395 void *hdr;
9396
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009397 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009398 if (!msg)
9399 return;
9400
9401 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9402 if (!hdr) {
9403 nlmsg_free(msg);
9404 return;
9405 }
9406
David S. Miller9360ffd2012-03-29 04:41:26 -04009407 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9408 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9409 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9410 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009411
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009412 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009413
Johannes Berg463d0182009-07-14 00:33:35 +02009414 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9415 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009416 return;
9417
9418 nla_put_failure:
9419 genlmsg_cancel(msg, hdr);
9420 nlmsg_free(msg);
9421}
9422
Johannes Berg947add32013-02-22 22:05:20 +01009423void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9424 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009425{
Johannes Berg947add32013-02-22 22:05:20 +01009426 struct wireless_dev *wdev = dev->ieee80211_ptr;
9427 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009428 struct sk_buff *msg;
9429 void *hdr;
9430
Johannes Berg947add32013-02-22 22:05:20 +01009431 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9432 return;
9433
9434 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9435
Javier Cardonac93b5e72011-04-07 15:08:34 -07009436 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9437 if (!msg)
9438 return;
9439
9440 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9441 if (!hdr) {
9442 nlmsg_free(msg);
9443 return;
9444 }
9445
David S. Miller9360ffd2012-03-29 04:41:26 -04009446 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009447 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9448 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009449 (ie_len && ie &&
9450 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9451 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009452
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009453 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009454
9455 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9456 nl80211_mlme_mcgrp.id, gfp);
9457 return;
9458
9459 nla_put_failure:
9460 genlmsg_cancel(msg, hdr);
9461 nlmsg_free(msg);
9462}
Johannes Berg947add32013-02-22 22:05:20 +01009463EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009464
Jouni Malinena3b8b052009-03-27 21:59:49 +02009465void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9466 struct net_device *netdev, const u8 *addr,
9467 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009468 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009469{
9470 struct sk_buff *msg;
9471 void *hdr;
9472
Johannes Berge6d6e342009-07-01 21:26:47 +02009473 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009474 if (!msg)
9475 return;
9476
9477 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9478 if (!hdr) {
9479 nlmsg_free(msg);
9480 return;
9481 }
9482
David S. Miller9360ffd2012-03-29 04:41:26 -04009483 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9484 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9485 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9486 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9487 (key_id != -1 &&
9488 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9489 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9490 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009491
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009492 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009493
Johannes Berg463d0182009-07-14 00:33:35 +02009494 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9495 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009496 return;
9497
9498 nla_put_failure:
9499 genlmsg_cancel(msg, hdr);
9500 nlmsg_free(msg);
9501}
9502
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009503void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9504 struct ieee80211_channel *channel_before,
9505 struct ieee80211_channel *channel_after)
9506{
9507 struct sk_buff *msg;
9508 void *hdr;
9509 struct nlattr *nl_freq;
9510
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009511 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009512 if (!msg)
9513 return;
9514
9515 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9516 if (!hdr) {
9517 nlmsg_free(msg);
9518 return;
9519 }
9520
9521 /*
9522 * Since we are applying the beacon hint to a wiphy we know its
9523 * wiphy_idx is valid
9524 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009525 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9526 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009527
9528 /* Before */
9529 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9530 if (!nl_freq)
9531 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009532 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009533 goto nla_put_failure;
9534 nla_nest_end(msg, nl_freq);
9535
9536 /* After */
9537 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9538 if (!nl_freq)
9539 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009540 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009541 goto nla_put_failure;
9542 nla_nest_end(msg, nl_freq);
9543
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009544 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009545
Johannes Berg463d0182009-07-14 00:33:35 +02009546 rcu_read_lock();
9547 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9548 GFP_ATOMIC);
9549 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009550
9551 return;
9552
9553nla_put_failure:
9554 genlmsg_cancel(msg, hdr);
9555 nlmsg_free(msg);
9556}
9557
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009558static void nl80211_send_remain_on_chan_event(
9559 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009560 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009561 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009562 unsigned int duration, gfp_t gfp)
9563{
9564 struct sk_buff *msg;
9565 void *hdr;
9566
9567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9568 if (!msg)
9569 return;
9570
9571 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9572 if (!hdr) {
9573 nlmsg_free(msg);
9574 return;
9575 }
9576
David S. Miller9360ffd2012-03-29 04:41:26 -04009577 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009578 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9579 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009580 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009581 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009582 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9583 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009584 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9585 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009586
David S. Miller9360ffd2012-03-29 04:41:26 -04009587 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9588 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9589 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009590
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009591 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009592
9593 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9594 nl80211_mlme_mcgrp.id, gfp);
9595 return;
9596
9597 nla_put_failure:
9598 genlmsg_cancel(msg, hdr);
9599 nlmsg_free(msg);
9600}
9601
Johannes Berg947add32013-02-22 22:05:20 +01009602void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9603 struct ieee80211_channel *chan,
9604 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009605{
Johannes Berg947add32013-02-22 22:05:20 +01009606 struct wiphy *wiphy = wdev->wiphy;
9607 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9608
9609 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009610 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009611 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009612 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009613}
Johannes Berg947add32013-02-22 22:05:20 +01009614EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009615
Johannes Berg947add32013-02-22 22:05:20 +01009616void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9617 struct ieee80211_channel *chan,
9618 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009619{
Johannes Berg947add32013-02-22 22:05:20 +01009620 struct wiphy *wiphy = wdev->wiphy;
9621 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9622
9623 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009624 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009625 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009626}
Johannes Berg947add32013-02-22 22:05:20 +01009627EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009628
Johannes Berg947add32013-02-22 22:05:20 +01009629void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9630 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009631{
Johannes Berg947add32013-02-22 22:05:20 +01009632 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9633 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009634 struct sk_buff *msg;
9635
Johannes Berg947add32013-02-22 22:05:20 +01009636 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9637
Thomas Graf58050fc2012-06-28 03:57:45 +00009638 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009639 if (!msg)
9640 return;
9641
John W. Linville66266b32012-03-15 13:25:41 -04009642 if (nl80211_send_station(msg, 0, 0, 0,
9643 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009644 nlmsg_free(msg);
9645 return;
9646 }
9647
9648 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9649 nl80211_mlme_mcgrp.id, gfp);
9650}
Johannes Berg947add32013-02-22 22:05:20 +01009651EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009652
Johannes Berg947add32013-02-22 22:05:20 +01009653void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009654{
Johannes Berg947add32013-02-22 22:05:20 +01009655 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9656 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009657 struct sk_buff *msg;
9658 void *hdr;
9659
Johannes Berg947add32013-02-22 22:05:20 +01009660 trace_cfg80211_del_sta(dev, mac_addr);
9661
Thomas Graf58050fc2012-06-28 03:57:45 +00009662 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009663 if (!msg)
9664 return;
9665
9666 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9667 if (!hdr) {
9668 nlmsg_free(msg);
9669 return;
9670 }
9671
David S. Miller9360ffd2012-03-29 04:41:26 -04009672 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9673 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9674 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009675
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009676 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009677
9678 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9679 nl80211_mlme_mcgrp.id, gfp);
9680 return;
9681
9682 nla_put_failure:
9683 genlmsg_cancel(msg, hdr);
9684 nlmsg_free(msg);
9685}
Johannes Berg947add32013-02-22 22:05:20 +01009686EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009687
Johannes Berg947add32013-02-22 22:05:20 +01009688void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9689 enum nl80211_connect_failed_reason reason,
9690 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309691{
Johannes Berg947add32013-02-22 22:05:20 +01009692 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9693 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309694 struct sk_buff *msg;
9695 void *hdr;
9696
9697 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9698 if (!msg)
9699 return;
9700
9701 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9702 if (!hdr) {
9703 nlmsg_free(msg);
9704 return;
9705 }
9706
9707 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9708 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9709 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9710 goto nla_put_failure;
9711
9712 genlmsg_end(msg, hdr);
9713
9714 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9715 nl80211_mlme_mcgrp.id, gfp);
9716 return;
9717
9718 nla_put_failure:
9719 genlmsg_cancel(msg, hdr);
9720 nlmsg_free(msg);
9721}
Johannes Berg947add32013-02-22 22:05:20 +01009722EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309723
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009724static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9725 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009726{
9727 struct wireless_dev *wdev = dev->ieee80211_ptr;
9728 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9729 struct sk_buff *msg;
9730 void *hdr;
9731 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009732 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009733
Eric W. Biederman15e47302012-09-07 20:12:54 +00009734 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009735 return false;
9736
9737 msg = nlmsg_new(100, gfp);
9738 if (!msg)
9739 return true;
9740
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009741 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009742 if (!hdr) {
9743 nlmsg_free(msg);
9744 return true;
9745 }
9746
David S. Miller9360ffd2012-03-29 04:41:26 -04009747 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9748 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9750 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009751
9752 err = genlmsg_end(msg, hdr);
9753 if (err < 0) {
9754 nlmsg_free(msg);
9755 return true;
9756 }
9757
Eric W. Biederman15e47302012-09-07 20:12:54 +00009758 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009759 return true;
9760
9761 nla_put_failure:
9762 genlmsg_cancel(msg, hdr);
9763 nlmsg_free(msg);
9764 return true;
9765}
9766
Johannes Berg947add32013-02-22 22:05:20 +01009767bool cfg80211_rx_spurious_frame(struct net_device *dev,
9768 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009769{
Johannes Berg947add32013-02-22 22:05:20 +01009770 struct wireless_dev *wdev = dev->ieee80211_ptr;
9771 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009772
Johannes Berg947add32013-02-22 22:05:20 +01009773 trace_cfg80211_rx_spurious_frame(dev, addr);
9774
9775 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9776 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9777 trace_cfg80211_return_bool(false);
9778 return false;
9779 }
9780 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9781 addr, gfp);
9782 trace_cfg80211_return_bool(ret);
9783 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009784}
Johannes Berg947add32013-02-22 22:05:20 +01009785EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9786
9787bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9788 const u8 *addr, gfp_t gfp)
9789{
9790 struct wireless_dev *wdev = dev->ieee80211_ptr;
9791 bool ret;
9792
9793 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9794
9795 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9796 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9797 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9798 trace_cfg80211_return_bool(false);
9799 return false;
9800 }
9801 ret = __nl80211_unexpected_frame(dev,
9802 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9803 addr, gfp);
9804 trace_cfg80211_return_bool(ret);
9805 return ret;
9806}
9807EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009808
Johannes Berg2e161f72010-08-12 15:38:38 +02009809int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009810 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009811 int freq, int sig_dbm,
9812 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009813{
Johannes Berg71bbc992012-06-15 15:30:18 +02009814 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009815 struct sk_buff *msg;
9816 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009817
9818 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9819 if (!msg)
9820 return -ENOMEM;
9821
Johannes Berg2e161f72010-08-12 15:38:38 +02009822 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009823 if (!hdr) {
9824 nlmsg_free(msg);
9825 return -ENOMEM;
9826 }
9827
David S. Miller9360ffd2012-03-29 04:41:26 -04009828 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009829 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9830 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009831 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9832 (sig_dbm &&
9833 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9834 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9835 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009836
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009837 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009838
Eric W. Biederman15e47302012-09-07 20:12:54 +00009839 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009840
9841 nla_put_failure:
9842 genlmsg_cancel(msg, hdr);
9843 nlmsg_free(msg);
9844 return -ENOBUFS;
9845}
9846
Johannes Berg947add32013-02-22 22:05:20 +01009847void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9848 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009849{
Johannes Berg947add32013-02-22 22:05:20 +01009850 struct wiphy *wiphy = wdev->wiphy;
9851 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009852 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009853 struct sk_buff *msg;
9854 void *hdr;
9855
Johannes Berg947add32013-02-22 22:05:20 +01009856 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9857
Jouni Malinen026331c2010-02-15 12:53:10 +02009858 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9859 if (!msg)
9860 return;
9861
Johannes Berg2e161f72010-08-12 15:38:38 +02009862 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009863 if (!hdr) {
9864 nlmsg_free(msg);
9865 return;
9866 }
9867
David S. Miller9360ffd2012-03-29 04:41:26 -04009868 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009869 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9870 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009871 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9872 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9873 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9874 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009875
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009876 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009877
9878 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9879 return;
9880
9881 nla_put_failure:
9882 genlmsg_cancel(msg, hdr);
9883 nlmsg_free(msg);
9884}
Johannes Berg947add32013-02-22 22:05:20 +01009885EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009886
Johannes Berg947add32013-02-22 22:05:20 +01009887void cfg80211_cqm_rssi_notify(struct net_device *dev,
9888 enum nl80211_cqm_rssi_threshold_event rssi_event,
9889 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009890{
Johannes Berg947add32013-02-22 22:05:20 +01009891 struct wireless_dev *wdev = dev->ieee80211_ptr;
9892 struct wiphy *wiphy = wdev->wiphy;
9893 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009894 struct sk_buff *msg;
9895 struct nlattr *pinfoattr;
9896 void *hdr;
9897
Johannes Berg947add32013-02-22 22:05:20 +01009898 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
9899
Thomas Graf58050fc2012-06-28 03:57:45 +00009900 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009901 if (!msg)
9902 return;
9903
9904 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9905 if (!hdr) {
9906 nlmsg_free(msg);
9907 return;
9908 }
9909
David S. Miller9360ffd2012-03-29 04:41:26 -04009910 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009911 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -04009912 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009913
9914 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9915 if (!pinfoattr)
9916 goto nla_put_failure;
9917
David S. Miller9360ffd2012-03-29 04:41:26 -04009918 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9919 rssi_event))
9920 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009921
9922 nla_nest_end(msg, pinfoattr);
9923
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009924 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009925
9926 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9927 nl80211_mlme_mcgrp.id, gfp);
9928 return;
9929
9930 nla_put_failure:
9931 genlmsg_cancel(msg, hdr);
9932 nlmsg_free(msg);
9933}
Johannes Berg947add32013-02-22 22:05:20 +01009934EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009935
Johannes Berg947add32013-02-22 22:05:20 +01009936static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9937 struct net_device *netdev, const u8 *bssid,
9938 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +02009939{
9940 struct sk_buff *msg;
9941 struct nlattr *rekey_attr;
9942 void *hdr;
9943
Thomas Graf58050fc2012-06-28 03:57:45 +00009944 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009945 if (!msg)
9946 return;
9947
9948 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9949 if (!hdr) {
9950 nlmsg_free(msg);
9951 return;
9952 }
9953
David S. Miller9360ffd2012-03-29 04:41:26 -04009954 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9955 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9956 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9957 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009958
9959 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9960 if (!rekey_attr)
9961 goto nla_put_failure;
9962
David S. Miller9360ffd2012-03-29 04:41:26 -04009963 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9964 NL80211_REPLAY_CTR_LEN, replay_ctr))
9965 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009966
9967 nla_nest_end(msg, rekey_attr);
9968
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009969 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02009970
9971 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9972 nl80211_mlme_mcgrp.id, gfp);
9973 return;
9974
9975 nla_put_failure:
9976 genlmsg_cancel(msg, hdr);
9977 nlmsg_free(msg);
9978}
9979
Johannes Berg947add32013-02-22 22:05:20 +01009980void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
9981 const u8 *replay_ctr, gfp_t gfp)
9982{
9983 struct wireless_dev *wdev = dev->ieee80211_ptr;
9984 struct wiphy *wiphy = wdev->wiphy;
9985 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9986
9987 trace_cfg80211_gtk_rekey_notify(dev, bssid);
9988 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
9989}
9990EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
9991
9992static void
9993nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
9994 struct net_device *netdev, int index,
9995 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009996{
9997 struct sk_buff *msg;
9998 struct nlattr *attr;
9999 void *hdr;
10000
Thomas Graf58050fc2012-06-28 03:57:45 +000010001 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010002 if (!msg)
10003 return;
10004
10005 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10006 if (!hdr) {
10007 nlmsg_free(msg);
10008 return;
10009 }
10010
David S. Miller9360ffd2012-03-29 04:41:26 -040010011 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10012 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10013 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010014
10015 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10016 if (!attr)
10017 goto nla_put_failure;
10018
David S. Miller9360ffd2012-03-29 04:41:26 -040010019 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10020 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10021 (preauth &&
10022 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10023 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010024
10025 nla_nest_end(msg, attr);
10026
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010027 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010028
10029 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10030 nl80211_mlme_mcgrp.id, gfp);
10031 return;
10032
10033 nla_put_failure:
10034 genlmsg_cancel(msg, hdr);
10035 nlmsg_free(msg);
10036}
10037
Johannes Berg947add32013-02-22 22:05:20 +010010038void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10039 const u8 *bssid, bool preauth, gfp_t gfp)
10040{
10041 struct wireless_dev *wdev = dev->ieee80211_ptr;
10042 struct wiphy *wiphy = wdev->wiphy;
10043 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10044
10045 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10046 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10047}
10048EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10049
10050static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10051 struct net_device *netdev,
10052 struct cfg80211_chan_def *chandef,
10053 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010054{
10055 struct sk_buff *msg;
10056 void *hdr;
10057
Thomas Graf58050fc2012-06-28 03:57:45 +000010058 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010059 if (!msg)
10060 return;
10061
10062 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10063 if (!hdr) {
10064 nlmsg_free(msg);
10065 return;
10066 }
10067
Johannes Berg683b6d32012-11-08 21:25:48 +010010068 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10069 goto nla_put_failure;
10070
10071 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010072 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010073
10074 genlmsg_end(msg, hdr);
10075
10076 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10077 nl80211_mlme_mcgrp.id, gfp);
10078 return;
10079
10080 nla_put_failure:
10081 genlmsg_cancel(msg, hdr);
10082 nlmsg_free(msg);
10083}
10084
Johannes Berg947add32013-02-22 22:05:20 +010010085void cfg80211_ch_switch_notify(struct net_device *dev,
10086 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010087{
Johannes Berg947add32013-02-22 22:05:20 +010010088 struct wireless_dev *wdev = dev->ieee80211_ptr;
10089 struct wiphy *wiphy = wdev->wiphy;
10090 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10091
10092 trace_cfg80211_ch_switch_notify(dev, chandef);
10093
10094 wdev_lock(wdev);
10095
10096 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10097 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10098 goto out;
10099
10100 wdev->channel = chandef->chan;
10101 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10102out:
10103 wdev_unlock(wdev);
10104 return;
10105}
10106EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10107
10108void cfg80211_cqm_txe_notify(struct net_device *dev,
10109 const u8 *peer, u32 num_packets,
10110 u32 rate, u32 intvl, gfp_t gfp)
10111{
10112 struct wireless_dev *wdev = dev->ieee80211_ptr;
10113 struct wiphy *wiphy = wdev->wiphy;
10114 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010115 struct sk_buff *msg;
10116 struct nlattr *pinfoattr;
10117 void *hdr;
10118
10119 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10120 if (!msg)
10121 return;
10122
10123 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10124 if (!hdr) {
10125 nlmsg_free(msg);
10126 return;
10127 }
10128
10129 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010130 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010131 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10132 goto nla_put_failure;
10133
10134 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10135 if (!pinfoattr)
10136 goto nla_put_failure;
10137
10138 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10139 goto nla_put_failure;
10140
10141 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10142 goto nla_put_failure;
10143
10144 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10145 goto nla_put_failure;
10146
10147 nla_nest_end(msg, pinfoattr);
10148
10149 genlmsg_end(msg, hdr);
10150
10151 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10152 nl80211_mlme_mcgrp.id, gfp);
10153 return;
10154
10155 nla_put_failure:
10156 genlmsg_cancel(msg, hdr);
10157 nlmsg_free(msg);
10158}
Johannes Berg947add32013-02-22 22:05:20 +010010159EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010160
10161void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010162nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10163 struct cfg80211_chan_def *chandef,
10164 enum nl80211_radar_event event,
10165 struct net_device *netdev, gfp_t gfp)
10166{
10167 struct sk_buff *msg;
10168 void *hdr;
10169
10170 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10171 if (!msg)
10172 return;
10173
10174 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10175 if (!hdr) {
10176 nlmsg_free(msg);
10177 return;
10178 }
10179
10180 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10181 goto nla_put_failure;
10182
10183 /* NOP and radar events don't need a netdev parameter */
10184 if (netdev) {
10185 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10186
10187 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10188 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10189 goto nla_put_failure;
10190 }
10191
10192 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10193 goto nla_put_failure;
10194
10195 if (nl80211_send_chandef(msg, chandef))
10196 goto nla_put_failure;
10197
10198 if (genlmsg_end(msg, hdr) < 0) {
10199 nlmsg_free(msg);
10200 return;
10201 }
10202
10203 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10204 nl80211_mlme_mcgrp.id, gfp);
10205 return;
10206
10207 nla_put_failure:
10208 genlmsg_cancel(msg, hdr);
10209 nlmsg_free(msg);
10210}
10211
Johannes Berg947add32013-02-22 22:05:20 +010010212void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10213 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010214{
Johannes Berg947add32013-02-22 22:05:20 +010010215 struct wireless_dev *wdev = dev->ieee80211_ptr;
10216 struct wiphy *wiphy = wdev->wiphy;
10217 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010218 struct sk_buff *msg;
10219 struct nlattr *pinfoattr;
10220 void *hdr;
10221
Johannes Berg947add32013-02-22 22:05:20 +010010222 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10223
Thomas Graf58050fc2012-06-28 03:57:45 +000010224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010225 if (!msg)
10226 return;
10227
10228 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10229 if (!hdr) {
10230 nlmsg_free(msg);
10231 return;
10232 }
10233
David S. Miller9360ffd2012-03-29 04:41:26 -040010234 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010235 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010236 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10237 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010238
10239 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10240 if (!pinfoattr)
10241 goto nla_put_failure;
10242
David S. Miller9360ffd2012-03-29 04:41:26 -040010243 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10244 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010245
10246 nla_nest_end(msg, pinfoattr);
10247
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010248 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010249
10250 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10251 nl80211_mlme_mcgrp.id, gfp);
10252 return;
10253
10254 nla_put_failure:
10255 genlmsg_cancel(msg, hdr);
10256 nlmsg_free(msg);
10257}
Johannes Berg947add32013-02-22 22:05:20 +010010258EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010259
Johannes Berg7f6cf312011-11-04 11:18:15 +010010260void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10261 u64 cookie, bool acked, gfp_t gfp)
10262{
10263 struct wireless_dev *wdev = dev->ieee80211_ptr;
10264 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10265 struct sk_buff *msg;
10266 void *hdr;
10267 int err;
10268
Beni Lev4ee3e062012-08-27 12:49:39 +030010269 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10270
Thomas Graf58050fc2012-06-28 03:57:45 +000010271 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010272
Johannes Berg7f6cf312011-11-04 11:18:15 +010010273 if (!msg)
10274 return;
10275
10276 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10277 if (!hdr) {
10278 nlmsg_free(msg);
10279 return;
10280 }
10281
David S. Miller9360ffd2012-03-29 04:41:26 -040010282 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10283 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10284 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10285 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10286 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10287 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010288
10289 err = genlmsg_end(msg, hdr);
10290 if (err < 0) {
10291 nlmsg_free(msg);
10292 return;
10293 }
10294
10295 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10296 nl80211_mlme_mcgrp.id, gfp);
10297 return;
10298
10299 nla_put_failure:
10300 genlmsg_cancel(msg, hdr);
10301 nlmsg_free(msg);
10302}
10303EXPORT_SYMBOL(cfg80211_probe_status);
10304
Johannes Berg5e760232011-11-04 11:18:17 +010010305void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10306 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010307 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010308{
10309 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10310 struct sk_buff *msg;
10311 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010312 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010313
Beni Lev4ee3e062012-08-27 12:49:39 +030010314 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10315
Ben Greear37c73b52012-10-26 14:49:25 -070010316 spin_lock_bh(&rdev->beacon_registrations_lock);
10317 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10318 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10319 if (!msg) {
10320 spin_unlock_bh(&rdev->beacon_registrations_lock);
10321 return;
10322 }
Johannes Berg5e760232011-11-04 11:18:17 +010010323
Ben Greear37c73b52012-10-26 14:49:25 -070010324 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10325 if (!hdr)
10326 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010327
Ben Greear37c73b52012-10-26 14:49:25 -070010328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10329 (freq &&
10330 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10331 (sig_dbm &&
10332 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10333 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10334 goto nla_put_failure;
10335
10336 genlmsg_end(msg, hdr);
10337
10338 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010339 }
Ben Greear37c73b52012-10-26 14:49:25 -070010340 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010341 return;
10342
10343 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010344 spin_unlock_bh(&rdev->beacon_registrations_lock);
10345 if (hdr)
10346 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010347 nlmsg_free(msg);
10348}
10349EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10350
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010351#ifdef CONFIG_PM
10352void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10353 struct cfg80211_wowlan_wakeup *wakeup,
10354 gfp_t gfp)
10355{
10356 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10357 struct sk_buff *msg;
10358 void *hdr;
10359 int err, size = 200;
10360
10361 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10362
10363 if (wakeup)
10364 size += wakeup->packet_present_len;
10365
10366 msg = nlmsg_new(size, gfp);
10367 if (!msg)
10368 return;
10369
10370 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10371 if (!hdr)
10372 goto free_msg;
10373
10374 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10375 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10376 goto free_msg;
10377
10378 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10379 wdev->netdev->ifindex))
10380 goto free_msg;
10381
10382 if (wakeup) {
10383 struct nlattr *reasons;
10384
10385 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10386
10387 if (wakeup->disconnect &&
10388 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10389 goto free_msg;
10390 if (wakeup->magic_pkt &&
10391 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10392 goto free_msg;
10393 if (wakeup->gtk_rekey_failure &&
10394 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10395 goto free_msg;
10396 if (wakeup->eap_identity_req &&
10397 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10398 goto free_msg;
10399 if (wakeup->four_way_handshake &&
10400 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10401 goto free_msg;
10402 if (wakeup->rfkill_release &&
10403 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10404 goto free_msg;
10405
10406 if (wakeup->pattern_idx >= 0 &&
10407 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10408 wakeup->pattern_idx))
10409 goto free_msg;
10410
Johannes Berg2a0e0472013-01-23 22:57:40 +010010411 if (wakeup->tcp_match)
10412 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10413
10414 if (wakeup->tcp_connlost)
10415 nla_put_flag(msg,
10416 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10417
10418 if (wakeup->tcp_nomoretokens)
10419 nla_put_flag(msg,
10420 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10421
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010422 if (wakeup->packet) {
10423 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10424 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10425
10426 if (!wakeup->packet_80211) {
10427 pkt_attr =
10428 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10429 len_attr =
10430 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10431 }
10432
10433 if (wakeup->packet_len &&
10434 nla_put_u32(msg, len_attr, wakeup->packet_len))
10435 goto free_msg;
10436
10437 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10438 wakeup->packet))
10439 goto free_msg;
10440 }
10441
10442 nla_nest_end(msg, reasons);
10443 }
10444
10445 err = genlmsg_end(msg, hdr);
10446 if (err < 0)
10447 goto free_msg;
10448
10449 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10450 nl80211_mlme_mcgrp.id, gfp);
10451 return;
10452
10453 free_msg:
10454 nlmsg_free(msg);
10455}
10456EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10457#endif
10458
Jouni Malinen3475b092012-11-16 22:49:57 +020010459void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10460 enum nl80211_tdls_operation oper,
10461 u16 reason_code, gfp_t gfp)
10462{
10463 struct wireless_dev *wdev = dev->ieee80211_ptr;
10464 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10465 struct sk_buff *msg;
10466 void *hdr;
10467 int err;
10468
10469 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10470 reason_code);
10471
10472 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10473 if (!msg)
10474 return;
10475
10476 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10477 if (!hdr) {
10478 nlmsg_free(msg);
10479 return;
10480 }
10481
10482 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10483 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10484 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10485 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10486 (reason_code > 0 &&
10487 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10488 goto nla_put_failure;
10489
10490 err = genlmsg_end(msg, hdr);
10491 if (err < 0) {
10492 nlmsg_free(msg);
10493 return;
10494 }
10495
10496 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10497 nl80211_mlme_mcgrp.id, gfp);
10498 return;
10499
10500 nla_put_failure:
10501 genlmsg_cancel(msg, hdr);
10502 nlmsg_free(msg);
10503}
10504EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10505
Jouni Malinen026331c2010-02-15 12:53:10 +020010506static int nl80211_netlink_notify(struct notifier_block * nb,
10507 unsigned long state,
10508 void *_notify)
10509{
10510 struct netlink_notify *notify = _notify;
10511 struct cfg80211_registered_device *rdev;
10512 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010513 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010514
10515 if (state != NETLINK_URELEASE)
10516 return NOTIFY_DONE;
10517
10518 rcu_read_lock();
10519
Johannes Berg5e760232011-11-04 11:18:17 +010010520 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010521 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010522 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010523
10524 spin_lock_bh(&rdev->beacon_registrations_lock);
10525 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10526 list) {
10527 if (reg->nlportid == notify->portid) {
10528 list_del(&reg->list);
10529 kfree(reg);
10530 break;
10531 }
10532 }
10533 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010534 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010535
10536 rcu_read_unlock();
10537
10538 return NOTIFY_DONE;
10539}
10540
10541static struct notifier_block nl80211_netlink_notifier = {
10542 .notifier_call = nl80211_netlink_notify,
10543};
10544
Johannes Berg55682962007-09-20 13:09:35 -040010545/* initialisation/exit functions */
10546
10547int nl80211_init(void)
10548{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010549 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010550
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010551 err = genl_register_family_with_ops(&nl80211_fam,
10552 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010553 if (err)
10554 return err;
10555
Johannes Berg55682962007-09-20 13:09:35 -040010556 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10557 if (err)
10558 goto err_out;
10559
Johannes Berg2a519312009-02-10 21:25:55 +010010560 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10561 if (err)
10562 goto err_out;
10563
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010564 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10565 if (err)
10566 goto err_out;
10567
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010568 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10569 if (err)
10570 goto err_out;
10571
Johannes Bergaff89a92009-07-01 21:26:51 +020010572#ifdef CONFIG_NL80211_TESTMODE
10573 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10574 if (err)
10575 goto err_out;
10576#endif
10577
Jouni Malinen026331c2010-02-15 12:53:10 +020010578 err = netlink_register_notifier(&nl80211_netlink_notifier);
10579 if (err)
10580 goto err_out;
10581
Johannes Berg55682962007-09-20 13:09:35 -040010582 return 0;
10583 err_out:
10584 genl_unregister_family(&nl80211_fam);
10585 return err;
10586}
10587
10588void nl80211_exit(void)
10589{
Jouni Malinen026331c2010-02-15 12:53:10 +020010590 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010591 genl_unregister_family(&nl80211_fam);
10592}