blob: 6a5893f5e48142b7f11de2eb9a61221cc3251deb [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 Berg19957bb2009-07-02 17:20:43 +02005987 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02005988 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02005989 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005990 int err, ssid_len, ie_len = 0;
5991 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08005992 u32 flags = 0;
5993 struct ieee80211_ht_cap *ht_capa = NULL;
5994 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Johannes Bergee2aca32013-02-21 17:36:01 +01005995 struct ieee80211_vht_cap *vht_capa = NULL;
5996 struct ieee80211_vht_cap *vht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005997
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005998 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5999 return -EINVAL;
6000
6001 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006002 !info->attrs[NL80211_ATTR_SSID] ||
6003 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006004 return -EINVAL;
6005
Johannes Berg4c476992010-10-04 21:36:35 +02006006 if (!rdev->ops->assoc)
6007 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006008
Johannes Berg074ac8d2010-09-16 14:58:22 +02006009 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006010 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6011 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006012
Johannes Berg19957bb2009-07-02 17:20:43 +02006013 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006014
Johannes Berg19957bb2009-07-02 17:20:43 +02006015 chan = ieee80211_get_channel(&rdev->wiphy,
6016 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006017 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6018 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006019
Johannes Berg19957bb2009-07-02 17:20:43 +02006020 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6021 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006022
6023 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006024 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6025 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006026 }
6027
Jouni Malinendc6382c2009-05-06 22:09:37 +03006028 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006029 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006030 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006031 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02006032 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006033 else if (mfp != NL80211_MFP_NO)
6034 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006035 }
6036
Johannes Berg3e5d7642009-07-07 14:37:26 +02006037 if (info->attrs[NL80211_ATTR_PREV_BSSID])
6038 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
6039
Ben Greear7e7c8922011-11-18 11:31:59 -08006040 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6041 flags |= ASSOC_REQ_DISABLE_HT;
6042
6043 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6044 ht_capa_mask =
6045 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
6046
6047 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6048 if (!ht_capa_mask)
6049 return -EINVAL;
6050 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6051 }
6052
Johannes Bergee2aca32013-02-21 17:36:01 +01006053 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6054 flags |= ASSOC_REQ_DISABLE_VHT;
6055
6056 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6057 vht_capa_mask =
6058 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]);
6059
6060 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6061 if (!vht_capa_mask)
6062 return -EINVAL;
6063 vht_capa = nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6064 }
6065
Johannes Bergc0692b82010-08-27 14:26:53 +03006066 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006067 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02006068 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
6069 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Bergee2aca32013-02-21 17:36:01 +01006070 &crypto, flags, ht_capa, ht_capa_mask,
6071 vht_capa, vht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006072
Jouni Malinen636a5d32009-03-19 13:39:22 +02006073 return err;
6074}
6075
6076static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6077{
Johannes Berg4c476992010-10-04 21:36:35 +02006078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6079 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006080 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006081 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006082 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006083 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006084
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006085 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6086 return -EINVAL;
6087
6088 if (!info->attrs[NL80211_ATTR_MAC])
6089 return -EINVAL;
6090
6091 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6092 return -EINVAL;
6093
Johannes Berg4c476992010-10-04 21:36:35 +02006094 if (!rdev->ops->deauth)
6095 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006096
Johannes Berg074ac8d2010-09-16 14:58:22 +02006097 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006098 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6099 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006100
Johannes Berg19957bb2009-07-02 17:20:43 +02006101 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006102
Johannes Berg19957bb2009-07-02 17:20:43 +02006103 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6104 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006105 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006106 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006107 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006108
6109 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006110 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6111 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006112 }
6113
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006114 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6115
Johannes Berg4c476992010-10-04 21:36:35 +02006116 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6117 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006118}
6119
6120static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6121{
Johannes Berg4c476992010-10-04 21:36:35 +02006122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6123 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006124 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006125 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006126 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006127 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006128
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006129 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6130 return -EINVAL;
6131
6132 if (!info->attrs[NL80211_ATTR_MAC])
6133 return -EINVAL;
6134
6135 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6136 return -EINVAL;
6137
Johannes Berg4c476992010-10-04 21:36:35 +02006138 if (!rdev->ops->disassoc)
6139 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006140
Johannes Berg074ac8d2010-09-16 14:58:22 +02006141 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006142 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6143 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006144
Johannes Berg19957bb2009-07-02 17:20:43 +02006145 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006146
Johannes Berg19957bb2009-07-02 17:20:43 +02006147 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6148 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006149 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006150 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006151 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006152
6153 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006154 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6155 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006156 }
6157
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006158 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6159
Johannes Berg4c476992010-10-04 21:36:35 +02006160 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6161 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006162}
6163
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006164static bool
6165nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6166 int mcast_rate[IEEE80211_NUM_BANDS],
6167 int rateval)
6168{
6169 struct wiphy *wiphy = &rdev->wiphy;
6170 bool found = false;
6171 int band, i;
6172
6173 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6174 struct ieee80211_supported_band *sband;
6175
6176 sband = wiphy->bands[band];
6177 if (!sband)
6178 continue;
6179
6180 for (i = 0; i < sband->n_bitrates; i++) {
6181 if (sband->bitrates[i].bitrate == rateval) {
6182 mcast_rate[band] = i + 1;
6183 found = true;
6184 break;
6185 }
6186 }
6187 }
6188
6189 return found;
6190}
6191
Johannes Berg04a773a2009-04-19 21:24:32 +02006192static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6193{
Johannes Berg4c476992010-10-04 21:36:35 +02006194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6195 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006196 struct cfg80211_ibss_params ibss;
6197 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006198 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006199 int err;
6200
Johannes Berg8e30bc52009-04-22 17:45:38 +02006201 memset(&ibss, 0, sizeof(ibss));
6202
Johannes Berg04a773a2009-04-19 21:24:32 +02006203 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6204 return -EINVAL;
6205
Johannes Berg683b6d32012-11-08 21:25:48 +01006206 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006207 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6208 return -EINVAL;
6209
Johannes Berg8e30bc52009-04-22 17:45:38 +02006210 ibss.beacon_interval = 100;
6211
6212 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6213 ibss.beacon_interval =
6214 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6215 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6216 return -EINVAL;
6217 }
6218
Johannes Berg4c476992010-10-04 21:36:35 +02006219 if (!rdev->ops->join_ibss)
6220 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006221
Johannes Berg4c476992010-10-04 21:36:35 +02006222 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6223 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006224
Johannes Berg79c97e92009-07-07 03:56:12 +02006225 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006226
Johannes Berg39193492011-09-16 13:45:25 +02006227 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006228 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006229
6230 if (!is_valid_ether_addr(ibss.bssid))
6231 return -EINVAL;
6232 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006233 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6234 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6235
6236 if (info->attrs[NL80211_ATTR_IE]) {
6237 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6238 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6239 }
6240
Johannes Berg683b6d32012-11-08 21:25:48 +01006241 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6242 if (err)
6243 return err;
Alexander Simon54858ee2011-11-30 16:56:32 +01006244
Johannes Berg683b6d32012-11-08 21:25:48 +01006245 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee2011-11-30 16:56:32 +01006246 return -EINVAL;
6247
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006248 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6249 return -EINVAL;
6250 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6251 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006252 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006253
Johannes Berg04a773a2009-04-19 21:24:32 +02006254 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006255 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006256
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006257 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6258 u8 *rates =
6259 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6260 int n_rates =
6261 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6262 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006263 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006264
Johannes Berg34850ab2011-07-18 18:08:35 +02006265 err = ieee80211_get_ratemask(sband, rates, n_rates,
6266 &ibss.basic_rates);
6267 if (err)
6268 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006269 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006270
6271 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6272 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6273 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6274 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006275
Johannes Berg4c476992010-10-04 21:36:35 +02006276 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306277 bool no_ht = false;
6278
Johannes Berg4c476992010-10-04 21:36:35 +02006279 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306280 info->attrs[NL80211_ATTR_KEYS],
6281 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006282 if (IS_ERR(connkeys))
6283 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306284
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006285 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6286 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306287 kfree(connkeys);
6288 return -EINVAL;
6289 }
Johannes Berg4c476992010-10-04 21:36:35 +02006290 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006291
Antonio Quartulli267335d2012-01-31 20:25:47 +01006292 ibss.control_port =
6293 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6294
Johannes Berg4c476992010-10-04 21:36:35 +02006295 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006296 if (err)
6297 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006298 return err;
6299}
6300
6301static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6302{
Johannes Berg4c476992010-10-04 21:36:35 +02006303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6304 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006305
Johannes Berg4c476992010-10-04 21:36:35 +02006306 if (!rdev->ops->leave_ibss)
6307 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006308
Johannes Berg4c476992010-10-04 21:36:35 +02006309 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6310 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006311
Johannes Berg4c476992010-10-04 21:36:35 +02006312 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006313}
6314
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006315static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6316{
6317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6318 struct net_device *dev = info->user_ptr[1];
6319 int mcast_rate[IEEE80211_NUM_BANDS];
6320 u32 nla_rate;
6321 int err;
6322
6323 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6324 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6325 return -EOPNOTSUPP;
6326
6327 if (!rdev->ops->set_mcast_rate)
6328 return -EOPNOTSUPP;
6329
6330 memset(mcast_rate, 0, sizeof(mcast_rate));
6331
6332 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6333 return -EINVAL;
6334
6335 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6336 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6337 return -EINVAL;
6338
6339 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6340
6341 return err;
6342}
6343
6344
Johannes Bergaff89a92009-07-01 21:26:51 +02006345#ifdef CONFIG_NL80211_TESTMODE
6346static struct genl_multicast_group nl80211_testmode_mcgrp = {
6347 .name = "testmode",
6348};
6349
6350static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6351{
Johannes Berg4c476992010-10-04 21:36:35 +02006352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006353 int err;
6354
6355 if (!info->attrs[NL80211_ATTR_TESTDATA])
6356 return -EINVAL;
6357
Johannes Bergaff89a92009-07-01 21:26:51 +02006358 err = -EOPNOTSUPP;
6359 if (rdev->ops->testmode_cmd) {
6360 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006361 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006362 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6363 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6364 rdev->testmode_info = NULL;
6365 }
6366
Johannes Bergaff89a92009-07-01 21:26:51 +02006367 return err;
6368}
6369
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006370static int nl80211_testmode_dump(struct sk_buff *skb,
6371 struct netlink_callback *cb)
6372{
Johannes Berg00918d32011-12-13 17:22:05 +01006373 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006374 int err;
6375 long phy_idx;
6376 void *data = NULL;
6377 int data_len = 0;
6378
6379 if (cb->args[0]) {
6380 /*
6381 * 0 is a valid index, but not valid for args[0],
6382 * so we need to offset by 1.
6383 */
6384 phy_idx = cb->args[0] - 1;
6385 } else {
6386 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6387 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6388 nl80211_policy);
6389 if (err)
6390 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01006391
Johannes Berg2bd7e352012-06-15 14:23:16 +02006392 mutex_lock(&cfg80211_mutex);
6393 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6394 nl80211_fam.attrbuf);
6395 if (IS_ERR(rdev)) {
6396 mutex_unlock(&cfg80211_mutex);
6397 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01006398 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006399 phy_idx = rdev->wiphy_idx;
6400 rdev = NULL;
6401 mutex_unlock(&cfg80211_mutex);
6402
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006403 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6404 cb->args[1] =
6405 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6406 }
6407
6408 if (cb->args[1]) {
6409 data = nla_data((void *)cb->args[1]);
6410 data_len = nla_len((void *)cb->args[1]);
6411 }
6412
6413 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01006414 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6415 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006416 mutex_unlock(&cfg80211_mutex);
6417 return -ENOENT;
6418 }
Johannes Berg00918d32011-12-13 17:22:05 +01006419 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006420 mutex_unlock(&cfg80211_mutex);
6421
Johannes Berg00918d32011-12-13 17:22:05 +01006422 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006423 err = -EOPNOTSUPP;
6424 goto out_err;
6425 }
6426
6427 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006428 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006429 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6430 NL80211_CMD_TESTMODE);
6431 struct nlattr *tmdata;
6432
David S. Miller9360ffd2012-03-29 04:41:26 -04006433 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006434 genlmsg_cancel(skb, hdr);
6435 break;
6436 }
6437
6438 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6439 if (!tmdata) {
6440 genlmsg_cancel(skb, hdr);
6441 break;
6442 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006443 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006444 nla_nest_end(skb, tmdata);
6445
6446 if (err == -ENOBUFS || err == -ENOENT) {
6447 genlmsg_cancel(skb, hdr);
6448 break;
6449 } else if (err) {
6450 genlmsg_cancel(skb, hdr);
6451 goto out_err;
6452 }
6453
6454 genlmsg_end(skb, hdr);
6455 }
6456
6457 err = skb->len;
6458 /* see above */
6459 cb->args[0] = phy_idx + 1;
6460 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01006461 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006462 return err;
6463}
6464
Johannes Bergaff89a92009-07-01 21:26:51 +02006465static struct sk_buff *
6466__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006467 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006468{
6469 struct sk_buff *skb;
6470 void *hdr;
6471 struct nlattr *data;
6472
6473 skb = nlmsg_new(approxlen + 100, gfp);
6474 if (!skb)
6475 return NULL;
6476
Eric W. Biederman15e47302012-09-07 20:12:54 +00006477 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006478 if (!hdr) {
6479 kfree_skb(skb);
6480 return NULL;
6481 }
6482
David S. Miller9360ffd2012-03-29 04:41:26 -04006483 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6484 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006485 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6486
6487 ((void **)skb->cb)[0] = rdev;
6488 ((void **)skb->cb)[1] = hdr;
6489 ((void **)skb->cb)[2] = data;
6490
6491 return skb;
6492
6493 nla_put_failure:
6494 kfree_skb(skb);
6495 return NULL;
6496}
6497
6498struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6499 int approxlen)
6500{
6501 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6502
6503 if (WARN_ON(!rdev->testmode_info))
6504 return NULL;
6505
6506 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006507 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006508 rdev->testmode_info->snd_seq,
6509 GFP_KERNEL);
6510}
6511EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6512
6513int cfg80211_testmode_reply(struct sk_buff *skb)
6514{
6515 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6516 void *hdr = ((void **)skb->cb)[1];
6517 struct nlattr *data = ((void **)skb->cb)[2];
6518
6519 if (WARN_ON(!rdev->testmode_info)) {
6520 kfree_skb(skb);
6521 return -EINVAL;
6522 }
6523
6524 nla_nest_end(skb, data);
6525 genlmsg_end(skb, hdr);
6526 return genlmsg_reply(skb, rdev->testmode_info);
6527}
6528EXPORT_SYMBOL(cfg80211_testmode_reply);
6529
6530struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6531 int approxlen, gfp_t gfp)
6532{
6533 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6534
6535 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6536}
6537EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6538
6539void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6540{
6541 void *hdr = ((void **)skb->cb)[1];
6542 struct nlattr *data = ((void **)skb->cb)[2];
6543
6544 nla_nest_end(skb, data);
6545 genlmsg_end(skb, hdr);
6546 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6547}
6548EXPORT_SYMBOL(cfg80211_testmode_event);
6549#endif
6550
Samuel Ortizb23aa672009-07-01 21:26:54 +02006551static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6552{
Johannes Berg4c476992010-10-04 21:36:35 +02006553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6554 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006555 struct cfg80211_connect_params connect;
6556 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006557 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006558 int err;
6559
6560 memset(&connect, 0, sizeof(connect));
6561
6562 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6563 return -EINVAL;
6564
6565 if (!info->attrs[NL80211_ATTR_SSID] ||
6566 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6567 return -EINVAL;
6568
6569 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6570 connect.auth_type =
6571 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006572 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6573 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006574 return -EINVAL;
6575 } else
6576 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6577
6578 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6579
Johannes Bergc0692b82010-08-27 14:26:53 +03006580 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006581 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006582 if (err)
6583 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006584
Johannes Berg074ac8d2010-09-16 14:58:22 +02006585 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006586 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6587 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006588
Johannes Berg79c97e92009-07-07 03:56:12 +02006589 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006590
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306591 connect.bg_scan_period = -1;
6592 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6593 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6594 connect.bg_scan_period =
6595 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6596 }
6597
Samuel Ortizb23aa672009-07-01 21:26:54 +02006598 if (info->attrs[NL80211_ATTR_MAC])
6599 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6600 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6601 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6602
6603 if (info->attrs[NL80211_ATTR_IE]) {
6604 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6605 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6606 }
6607
Jouni Malinencee00a92013-01-15 17:15:57 +02006608 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6609 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6610 if (connect.mfp != NL80211_MFP_REQUIRED &&
6611 connect.mfp != NL80211_MFP_NO)
6612 return -EINVAL;
6613 } else {
6614 connect.mfp = NL80211_MFP_NO;
6615 }
6616
Samuel Ortizb23aa672009-07-01 21:26:54 +02006617 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6618 connect.channel =
6619 ieee80211_get_channel(wiphy,
6620 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6621 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006622 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6623 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006624 }
6625
Johannes Bergfffd0932009-07-08 14:22:54 +02006626 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6627 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306628 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006629 if (IS_ERR(connkeys))
6630 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006631 }
6632
Ben Greear7e7c8922011-11-18 11:31:59 -08006633 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6634 connect.flags |= ASSOC_REQ_DISABLE_HT;
6635
6636 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6637 memcpy(&connect.ht_capa_mask,
6638 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6639 sizeof(connect.ht_capa_mask));
6640
6641 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006642 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6643 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006644 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006645 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006646 memcpy(&connect.ht_capa,
6647 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6648 sizeof(connect.ht_capa));
6649 }
6650
Johannes Bergee2aca32013-02-21 17:36:01 +01006651 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6652 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6653
6654 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6655 memcpy(&connect.vht_capa_mask,
6656 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6657 sizeof(connect.vht_capa_mask));
6658
6659 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6660 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6661 kfree(connkeys);
6662 return -EINVAL;
6663 }
6664 memcpy(&connect.vht_capa,
6665 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6666 sizeof(connect.vht_capa));
6667 }
6668
Johannes Bergfffd0932009-07-08 14:22:54 +02006669 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006670 if (err)
6671 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006672 return err;
6673}
6674
6675static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6676{
Johannes Berg4c476992010-10-04 21:36:35 +02006677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6678 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006679 u16 reason;
6680
6681 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6682 reason = WLAN_REASON_DEAUTH_LEAVING;
6683 else
6684 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6685
6686 if (reason == 0)
6687 return -EINVAL;
6688
Johannes Berg074ac8d2010-09-16 14:58:22 +02006689 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006690 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6691 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006692
Johannes Berg4c476992010-10-04 21:36:35 +02006693 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006694}
6695
Johannes Berg463d0182009-07-14 00:33:35 +02006696static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6697{
Johannes Berg4c476992010-10-04 21:36:35 +02006698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006699 struct net *net;
6700 int err;
6701 u32 pid;
6702
6703 if (!info->attrs[NL80211_ATTR_PID])
6704 return -EINVAL;
6705
6706 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6707
Johannes Berg463d0182009-07-14 00:33:35 +02006708 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006709 if (IS_ERR(net))
6710 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006711
6712 err = 0;
6713
6714 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006715 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6716 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006717
Johannes Berg463d0182009-07-14 00:33:35 +02006718 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006719 return err;
6720}
6721
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006722static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6723{
Johannes Berg4c476992010-10-04 21:36:35 +02006724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006725 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6726 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006727 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006728 struct cfg80211_pmksa pmksa;
6729
6730 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6731
6732 if (!info->attrs[NL80211_ATTR_MAC])
6733 return -EINVAL;
6734
6735 if (!info->attrs[NL80211_ATTR_PMKID])
6736 return -EINVAL;
6737
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006738 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6739 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6740
Johannes Berg074ac8d2010-09-16 14:58:22 +02006741 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006742 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6743 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006744
6745 switch (info->genlhdr->cmd) {
6746 case NL80211_CMD_SET_PMKSA:
6747 rdev_ops = rdev->ops->set_pmksa;
6748 break;
6749 case NL80211_CMD_DEL_PMKSA:
6750 rdev_ops = rdev->ops->del_pmksa;
6751 break;
6752 default:
6753 WARN_ON(1);
6754 break;
6755 }
6756
Johannes Berg4c476992010-10-04 21:36:35 +02006757 if (!rdev_ops)
6758 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006759
Johannes Berg4c476992010-10-04 21:36:35 +02006760 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006761}
6762
6763static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6764{
Johannes Berg4c476992010-10-04 21:36:35 +02006765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6766 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006767
Johannes Berg074ac8d2010-09-16 14:58:22 +02006768 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006769 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6770 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006771
Johannes Berg4c476992010-10-04 21:36:35 +02006772 if (!rdev->ops->flush_pmksa)
6773 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006774
Hila Gonene35e4d22012-06-27 17:19:42 +03006775 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006776}
6777
Arik Nemtsov109086c2011-09-28 14:12:50 +03006778static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6779{
6780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6781 struct net_device *dev = info->user_ptr[1];
6782 u8 action_code, dialog_token;
6783 u16 status_code;
6784 u8 *peer;
6785
6786 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6787 !rdev->ops->tdls_mgmt)
6788 return -EOPNOTSUPP;
6789
6790 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6791 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6792 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6793 !info->attrs[NL80211_ATTR_IE] ||
6794 !info->attrs[NL80211_ATTR_MAC])
6795 return -EINVAL;
6796
6797 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6798 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6799 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6800 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6801
Hila Gonene35e4d22012-06-27 17:19:42 +03006802 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6803 dialog_token, status_code,
6804 nla_data(info->attrs[NL80211_ATTR_IE]),
6805 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006806}
6807
6808static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6809{
6810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6811 struct net_device *dev = info->user_ptr[1];
6812 enum nl80211_tdls_operation operation;
6813 u8 *peer;
6814
6815 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6816 !rdev->ops->tdls_oper)
6817 return -EOPNOTSUPP;
6818
6819 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6820 !info->attrs[NL80211_ATTR_MAC])
6821 return -EINVAL;
6822
6823 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6824 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6825
Hila Gonene35e4d22012-06-27 17:19:42 +03006826 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006827}
6828
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006829static int nl80211_remain_on_channel(struct sk_buff *skb,
6830 struct genl_info *info)
6831{
Johannes Berg4c476992010-10-04 21:36:35 +02006832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006833 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006834 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006835 struct sk_buff *msg;
6836 void *hdr;
6837 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006838 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006839 int err;
6840
6841 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6842 !info->attrs[NL80211_ATTR_DURATION])
6843 return -EINVAL;
6844
6845 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6846
Johannes Berg7c4ef712011-11-18 15:33:48 +01006847 if (!rdev->ops->remain_on_channel ||
6848 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006849 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006850
Johannes Bergebf348f2012-06-01 12:50:54 +02006851 /*
6852 * We should be on that channel for at least a minimum amount of
6853 * time (10ms) but no longer than the driver supports.
6854 */
6855 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6856 duration > rdev->wiphy.max_remain_on_channel_duration)
6857 return -EINVAL;
6858
Johannes Berg683b6d32012-11-08 21:25:48 +01006859 err = nl80211_parse_chandef(rdev, info, &chandef);
6860 if (err)
6861 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006862
6863 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006864 if (!msg)
6865 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006866
Eric W. Biederman15e47302012-09-07 20:12:54 +00006867 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006868 NL80211_CMD_REMAIN_ON_CHANNEL);
6869
6870 if (IS_ERR(hdr)) {
6871 err = PTR_ERR(hdr);
6872 goto free_msg;
6873 }
6874
Johannes Berg683b6d32012-11-08 21:25:48 +01006875 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6876 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006877
6878 if (err)
6879 goto free_msg;
6880
David S. Miller9360ffd2012-03-29 04:41:26 -04006881 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6882 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006883
6884 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006885
6886 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006887
6888 nla_put_failure:
6889 err = -ENOBUFS;
6890 free_msg:
6891 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006892 return err;
6893}
6894
6895static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6896 struct genl_info *info)
6897{
Johannes Berg4c476992010-10-04 21:36:35 +02006898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006899 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006900 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006901
6902 if (!info->attrs[NL80211_ATTR_COOKIE])
6903 return -EINVAL;
6904
Johannes Berg4c476992010-10-04 21:36:35 +02006905 if (!rdev->ops->cancel_remain_on_channel)
6906 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006907
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006908 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6909
Hila Gonene35e4d22012-06-27 17:19:42 +03006910 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006911}
6912
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006913static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6914 u8 *rates, u8 rates_len)
6915{
6916 u8 i;
6917 u32 mask = 0;
6918
6919 for (i = 0; i < rates_len; i++) {
6920 int rate = (rates[i] & 0x7f) * 5;
6921 int ridx;
6922 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6923 struct ieee80211_rate *srate =
6924 &sband->bitrates[ridx];
6925 if (rate == srate->bitrate) {
6926 mask |= 1 << ridx;
6927 break;
6928 }
6929 }
6930 if (ridx == sband->n_bitrates)
6931 return 0; /* rate not found */
6932 }
6933
6934 return mask;
6935}
6936
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006937static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6938 u8 *rates, u8 rates_len,
6939 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6940{
6941 u8 i;
6942
6943 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6944
6945 for (i = 0; i < rates_len; i++) {
6946 int ridx, rbit;
6947
6948 ridx = rates[i] / 8;
6949 rbit = BIT(rates[i] % 8);
6950
6951 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006952 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006953 return false;
6954
6955 /* check availability */
6956 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6957 mcs[ridx] |= rbit;
6958 else
6959 return false;
6960 }
6961
6962 return true;
6963}
6964
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006965static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006966 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6967 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006968 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6969 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006970};
6971
6972static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6973 struct genl_info *info)
6974{
6975 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006977 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006978 int rem, i;
6979 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006980 struct nlattr *tx_rates;
6981 struct ieee80211_supported_band *sband;
6982
6983 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6984 return -EINVAL;
6985
Johannes Berg4c476992010-10-04 21:36:35 +02006986 if (!rdev->ops->set_bitrate_mask)
6987 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006988
6989 memset(&mask, 0, sizeof(mask));
6990 /* Default to all rates enabled */
6991 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6992 sband = rdev->wiphy.bands[i];
6993 mask.control[i].legacy =
6994 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006995 if (sband)
6996 memcpy(mask.control[i].mcs,
6997 sband->ht_cap.mcs.rx_mask,
6998 sizeof(mask.control[i].mcs));
6999 else
7000 memset(mask.control[i].mcs, 0,
7001 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007002 }
7003
7004 /*
7005 * The nested attribute uses enum nl80211_band as the index. This maps
7006 * directly to the enum ieee80211_band values used in cfg80211.
7007 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007008 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007009 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7010 {
7011 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007012 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7013 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007014 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007015 if (sband == NULL)
7016 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007017 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7018 nla_len(tx_rates), nl80211_txattr_policy);
7019 if (tb[NL80211_TXRATE_LEGACY]) {
7020 mask.control[band].legacy = rateset_to_mask(
7021 sband,
7022 nla_data(tb[NL80211_TXRATE_LEGACY]),
7023 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307024 if ((mask.control[band].legacy == 0) &&
7025 nla_len(tb[NL80211_TXRATE_LEGACY]))
7026 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007027 }
7028 if (tb[NL80211_TXRATE_MCS]) {
7029 if (!ht_rateset_to_mask(
7030 sband,
7031 nla_data(tb[NL80211_TXRATE_MCS]),
7032 nla_len(tb[NL80211_TXRATE_MCS]),
7033 mask.control[band].mcs))
7034 return -EINVAL;
7035 }
7036
7037 if (mask.control[band].legacy == 0) {
7038 /* don't allow empty legacy rates if HT
7039 * is not even supported. */
7040 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7041 return -EINVAL;
7042
7043 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7044 if (mask.control[band].mcs[i])
7045 break;
7046
7047 /* legacy and mcs rates may not be both empty */
7048 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007049 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007050 }
7051 }
7052
Hila Gonene35e4d22012-06-27 17:19:42 +03007053 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007054}
7055
Johannes Berg2e161f72010-08-12 15:38:38 +02007056static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007057{
Johannes Berg4c476992010-10-04 21:36:35 +02007058 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007059 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007060 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007061
7062 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7063 return -EINVAL;
7064
Johannes Berg2e161f72010-08-12 15:38:38 +02007065 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7066 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007067
Johannes Berg71bbc992012-06-15 15:30:18 +02007068 switch (wdev->iftype) {
7069 case NL80211_IFTYPE_STATION:
7070 case NL80211_IFTYPE_ADHOC:
7071 case NL80211_IFTYPE_P2P_CLIENT:
7072 case NL80211_IFTYPE_AP:
7073 case NL80211_IFTYPE_AP_VLAN:
7074 case NL80211_IFTYPE_MESH_POINT:
7075 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007076 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007077 break;
7078 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007079 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007080 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007081
7082 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007083 if (!rdev->ops->mgmt_tx)
7084 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007085
Eric W. Biederman15e47302012-09-07 20:12:54 +00007086 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007087 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7088 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007089}
7090
Johannes Berg2e161f72010-08-12 15:38:38 +02007091static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007092{
Johannes Berg4c476992010-10-04 21:36:35 +02007093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007094 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007095 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007096 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007097 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007098 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007099 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007100 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007101 bool offchan, no_cck, dont_wait_for_ack;
7102
7103 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007104
Johannes Berg683b6d32012-11-08 21:25:48 +01007105 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007106 return -EINVAL;
7107
Johannes Berg4c476992010-10-04 21:36:35 +02007108 if (!rdev->ops->mgmt_tx)
7109 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007110
Johannes Berg71bbc992012-06-15 15:30:18 +02007111 switch (wdev->iftype) {
7112 case NL80211_IFTYPE_STATION:
7113 case NL80211_IFTYPE_ADHOC:
7114 case NL80211_IFTYPE_P2P_CLIENT:
7115 case NL80211_IFTYPE_AP:
7116 case NL80211_IFTYPE_AP_VLAN:
7117 case NL80211_IFTYPE_MESH_POINT:
7118 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007119 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007120 break;
7121 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007122 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007123 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007124
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007125 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007126 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007127 return -EINVAL;
7128 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007129
7130 /*
7131 * We should wait on the channel for at least a minimum amount
7132 * of time (10ms) but no longer than the driver supports.
7133 */
7134 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7135 wait > rdev->wiphy.max_remain_on_channel_duration)
7136 return -EINVAL;
7137
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007138 }
7139
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007140 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7141
Johannes Berg7c4ef712011-11-18 15:33:48 +01007142 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7143 return -EINVAL;
7144
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307145 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7146
Johannes Berg683b6d32012-11-08 21:25:48 +01007147 err = nl80211_parse_chandef(rdev, info, &chandef);
7148 if (err)
7149 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007150
Johannes Berge247bd902011-11-04 11:18:21 +01007151 if (!dont_wait_for_ack) {
7152 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7153 if (!msg)
7154 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007155
Eric W. Biederman15e47302012-09-07 20:12:54 +00007156 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007157 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007158
Johannes Berge247bd902011-11-04 11:18:21 +01007159 if (IS_ERR(hdr)) {
7160 err = PTR_ERR(hdr);
7161 goto free_msg;
7162 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007163 }
Johannes Berge247bd902011-11-04 11:18:21 +01007164
Johannes Berg683b6d32012-11-08 21:25:48 +01007165 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007166 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7167 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007168 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007169 if (err)
7170 goto free_msg;
7171
Johannes Berge247bd902011-11-04 11:18:21 +01007172 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007173 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7174 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007175
Johannes Berge247bd902011-11-04 11:18:21 +01007176 genlmsg_end(msg, hdr);
7177 return genlmsg_reply(msg, info);
7178 }
7179
7180 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007181
7182 nla_put_failure:
7183 err = -ENOBUFS;
7184 free_msg:
7185 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007186 return err;
7187}
7188
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007189static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7190{
7191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007192 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007193 u64 cookie;
7194
7195 if (!info->attrs[NL80211_ATTR_COOKIE])
7196 return -EINVAL;
7197
7198 if (!rdev->ops->mgmt_tx_cancel_wait)
7199 return -EOPNOTSUPP;
7200
Johannes Berg71bbc992012-06-15 15:30:18 +02007201 switch (wdev->iftype) {
7202 case NL80211_IFTYPE_STATION:
7203 case NL80211_IFTYPE_ADHOC:
7204 case NL80211_IFTYPE_P2P_CLIENT:
7205 case NL80211_IFTYPE_AP:
7206 case NL80211_IFTYPE_AP_VLAN:
7207 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007208 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007209 break;
7210 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007211 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007212 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007213
7214 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7215
Hila Gonene35e4d22012-06-27 17:19:42 +03007216 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007217}
7218
Kalle Valoffb9eb32010-02-17 17:58:10 +02007219static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7220{
Johannes Berg4c476992010-10-04 21:36:35 +02007221 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007222 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007223 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007224 u8 ps_state;
7225 bool state;
7226 int err;
7227
Johannes Berg4c476992010-10-04 21:36:35 +02007228 if (!info->attrs[NL80211_ATTR_PS_STATE])
7229 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007230
7231 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7232
Johannes Berg4c476992010-10-04 21:36:35 +02007233 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7234 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007235
7236 wdev = dev->ieee80211_ptr;
7237
Johannes Berg4c476992010-10-04 21:36:35 +02007238 if (!rdev->ops->set_power_mgmt)
7239 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007240
7241 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7242
7243 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007244 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007245
Hila Gonene35e4d22012-06-27 17:19:42 +03007246 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007247 if (!err)
7248 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007249 return err;
7250}
7251
7252static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7253{
Johannes Berg4c476992010-10-04 21:36:35 +02007254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007255 enum nl80211_ps_state ps_state;
7256 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007257 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007258 struct sk_buff *msg;
7259 void *hdr;
7260 int err;
7261
Kalle Valoffb9eb32010-02-17 17:58:10 +02007262 wdev = dev->ieee80211_ptr;
7263
Johannes Berg4c476992010-10-04 21:36:35 +02007264 if (!rdev->ops->set_power_mgmt)
7265 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007266
7267 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007268 if (!msg)
7269 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007270
Eric W. Biederman15e47302012-09-07 20:12:54 +00007271 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007272 NL80211_CMD_GET_POWER_SAVE);
7273 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007274 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007275 goto free_msg;
7276 }
7277
7278 if (wdev->ps)
7279 ps_state = NL80211_PS_ENABLED;
7280 else
7281 ps_state = NL80211_PS_DISABLED;
7282
David S. Miller9360ffd2012-03-29 04:41:26 -04007283 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7284 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007285
7286 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007287 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007288
Johannes Berg4c476992010-10-04 21:36:35 +02007289 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007290 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007291 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007292 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007293 return err;
7294}
7295
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007296static struct nla_policy
7297nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7298 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7299 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7300 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007301 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7302 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7303 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007304};
7305
Thomas Pedersen84f10702012-07-12 16:17:33 -07007306static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007307 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007308{
7309 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7310 struct wireless_dev *wdev;
7311 struct net_device *dev = info->user_ptr[1];
7312
Johannes Bergd9d8b012012-11-26 12:51:52 +01007313 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007314 return -EINVAL;
7315
7316 wdev = dev->ieee80211_ptr;
7317
7318 if (!rdev->ops->set_cqm_txe_config)
7319 return -EOPNOTSUPP;
7320
7321 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7322 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7323 return -EOPNOTSUPP;
7324
Hila Gonene35e4d22012-06-27 17:19:42 +03007325 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007326}
7327
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007328static int nl80211_set_cqm_rssi(struct genl_info *info,
7329 s32 threshold, u32 hysteresis)
7330{
Johannes Berg4c476992010-10-04 21:36:35 +02007331 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007332 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007333 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007334
7335 if (threshold > 0)
7336 return -EINVAL;
7337
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007338 wdev = dev->ieee80211_ptr;
7339
Johannes Berg4c476992010-10-04 21:36:35 +02007340 if (!rdev->ops->set_cqm_rssi_config)
7341 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007342
Johannes Berg074ac8d2010-09-16 14:58:22 +02007343 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007344 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7345 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007346
Hila Gonene35e4d22012-06-27 17:19:42 +03007347 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007348}
7349
7350static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7351{
7352 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7353 struct nlattr *cqm;
7354 int err;
7355
7356 cqm = info->attrs[NL80211_ATTR_CQM];
7357 if (!cqm) {
7358 err = -EINVAL;
7359 goto out;
7360 }
7361
7362 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7363 nl80211_attr_cqm_policy);
7364 if (err)
7365 goto out;
7366
7367 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7368 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7369 s32 threshold;
7370 u32 hysteresis;
7371 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7372 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7373 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007374 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7375 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7376 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7377 u32 rate, pkts, intvl;
7378 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7379 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7380 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7381 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007382 } else
7383 err = -EINVAL;
7384
7385out:
7386 return err;
7387}
7388
Johannes Berg29cbe682010-12-03 09:20:44 +01007389static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7390{
7391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7392 struct net_device *dev = info->user_ptr[1];
7393 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007394 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007395 int err;
7396
7397 /* start with default */
7398 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007399 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007400
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007401 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007402 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007403 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007404 if (err)
7405 return err;
7406 }
7407
7408 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7409 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7410 return -EINVAL;
7411
Javier Cardonac80d5452010-12-16 17:37:49 -08007412 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7413 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7414
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007415 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7416 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7417 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7418 return -EINVAL;
7419
Marco Porsch9bdbf042013-01-07 16:04:51 +01007420 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7421 setup.beacon_interval =
7422 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7423 if (setup.beacon_interval < 10 ||
7424 setup.beacon_interval > 10000)
7425 return -EINVAL;
7426 }
7427
7428 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7429 setup.dtim_period =
7430 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7431 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7432 return -EINVAL;
7433 }
7434
Javier Cardonac80d5452010-12-16 17:37:49 -08007435 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7436 /* parse additional setup parameters if given */
7437 err = nl80211_parse_mesh_setup(info, &setup);
7438 if (err)
7439 return err;
7440 }
7441
Johannes Bergcc1d2802012-05-16 23:50:20 +02007442 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007443 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7444 if (err)
7445 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007446 } else {
7447 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007448 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007449 }
7450
Javier Cardonac80d5452010-12-16 17:37:49 -08007451 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007452}
7453
7454static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7455{
7456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7457 struct net_device *dev = info->user_ptr[1];
7458
7459 return cfg80211_leave_mesh(rdev, dev);
7460}
7461
Johannes Bergdfb89c52012-06-27 09:23:48 +02007462#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007463static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7464 struct cfg80211_registered_device *rdev)
7465{
7466 struct nlattr *nl_pats, *nl_pat;
7467 int i, pat_len;
7468
7469 if (!rdev->wowlan->n_patterns)
7470 return 0;
7471
7472 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7473 if (!nl_pats)
7474 return -ENOBUFS;
7475
7476 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7477 nl_pat = nla_nest_start(msg, i + 1);
7478 if (!nl_pat)
7479 return -ENOBUFS;
7480 pat_len = rdev->wowlan->patterns[i].pattern_len;
7481 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7482 DIV_ROUND_UP(pat_len, 8),
7483 rdev->wowlan->patterns[i].mask) ||
7484 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7485 pat_len, rdev->wowlan->patterns[i].pattern) ||
7486 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7487 rdev->wowlan->patterns[i].pkt_offset))
7488 return -ENOBUFS;
7489 nla_nest_end(msg, nl_pat);
7490 }
7491 nla_nest_end(msg, nl_pats);
7492
7493 return 0;
7494}
7495
Johannes Berg2a0e0472013-01-23 22:57:40 +01007496static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7497 struct cfg80211_wowlan_tcp *tcp)
7498{
7499 struct nlattr *nl_tcp;
7500
7501 if (!tcp)
7502 return 0;
7503
7504 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7505 if (!nl_tcp)
7506 return -ENOBUFS;
7507
7508 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7509 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7510 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7511 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7512 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7513 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7514 tcp->payload_len, tcp->payload) ||
7515 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7516 tcp->data_interval) ||
7517 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7518 tcp->wake_len, tcp->wake_data) ||
7519 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7520 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7521 return -ENOBUFS;
7522
7523 if (tcp->payload_seq.len &&
7524 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7525 sizeof(tcp->payload_seq), &tcp->payload_seq))
7526 return -ENOBUFS;
7527
7528 if (tcp->payload_tok.len &&
7529 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7530 sizeof(tcp->payload_tok) + tcp->tokens_size,
7531 &tcp->payload_tok))
7532 return -ENOBUFS;
7533
7534 return 0;
7535}
7536
Johannes Bergff1b6e62011-05-04 15:37:28 +02007537static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7538{
7539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7540 struct sk_buff *msg;
7541 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007542 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007543
Johannes Berg2a0e0472013-01-23 22:57:40 +01007544 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7545 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007546 return -EOPNOTSUPP;
7547
Johannes Berg2a0e0472013-01-23 22:57:40 +01007548 if (rdev->wowlan && rdev->wowlan->tcp) {
7549 /* adjust size to have room for all the data */
7550 size += rdev->wowlan->tcp->tokens_size +
7551 rdev->wowlan->tcp->payload_len +
7552 rdev->wowlan->tcp->wake_len +
7553 rdev->wowlan->tcp->wake_len / 8;
7554 }
7555
7556 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007557 if (!msg)
7558 return -ENOMEM;
7559
Eric W. Biederman15e47302012-09-07 20:12:54 +00007560 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007561 NL80211_CMD_GET_WOWLAN);
7562 if (!hdr)
7563 goto nla_put_failure;
7564
7565 if (rdev->wowlan) {
7566 struct nlattr *nl_wowlan;
7567
7568 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7569 if (!nl_wowlan)
7570 goto nla_put_failure;
7571
David S. Miller9360ffd2012-03-29 04:41:26 -04007572 if ((rdev->wowlan->any &&
7573 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7574 (rdev->wowlan->disconnect &&
7575 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7576 (rdev->wowlan->magic_pkt &&
7577 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7578 (rdev->wowlan->gtk_rekey_failure &&
7579 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7580 (rdev->wowlan->eap_identity_req &&
7581 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7582 (rdev->wowlan->four_way_handshake &&
7583 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7584 (rdev->wowlan->rfkill_release &&
7585 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7586 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007587
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007588 if (nl80211_send_wowlan_patterns(msg, rdev))
7589 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007590
7591 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7592 goto nla_put_failure;
7593
Johannes Bergff1b6e62011-05-04 15:37:28 +02007594 nla_nest_end(msg, nl_wowlan);
7595 }
7596
7597 genlmsg_end(msg, hdr);
7598 return genlmsg_reply(msg, info);
7599
7600nla_put_failure:
7601 nlmsg_free(msg);
7602 return -ENOBUFS;
7603}
7604
Johannes Berg2a0e0472013-01-23 22:57:40 +01007605static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7606 struct nlattr *attr,
7607 struct cfg80211_wowlan *trig)
7608{
7609 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7610 struct cfg80211_wowlan_tcp *cfg;
7611 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7612 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7613 u32 size;
7614 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7615 int err, port;
7616
7617 if (!rdev->wiphy.wowlan.tcp)
7618 return -EINVAL;
7619
7620 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7621 nla_data(attr), nla_len(attr),
7622 nl80211_wowlan_tcp_policy);
7623 if (err)
7624 return err;
7625
7626 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7627 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7628 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7629 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7630 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7631 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7632 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7633 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7634 return -EINVAL;
7635
7636 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7637 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7638 return -EINVAL;
7639
7640 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
7641 rdev->wiphy.wowlan.tcp->data_interval_max)
7642 return -EINVAL;
7643
7644 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7645 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7646 return -EINVAL;
7647
7648 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7649 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7650 return -EINVAL;
7651
7652 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7653 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7654
7655 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7656 tokens_size = tokln - sizeof(*tok);
7657
7658 if (!tok->len || tokens_size % tok->len)
7659 return -EINVAL;
7660 if (!rdev->wiphy.wowlan.tcp->tok)
7661 return -EINVAL;
7662 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7663 return -EINVAL;
7664 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7665 return -EINVAL;
7666 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7667 return -EINVAL;
7668 if (tok->offset + tok->len > data_size)
7669 return -EINVAL;
7670 }
7671
7672 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7673 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7674 if (!rdev->wiphy.wowlan.tcp->seq)
7675 return -EINVAL;
7676 if (seq->len == 0 || seq->len > 4)
7677 return -EINVAL;
7678 if (seq->len + seq->offset > data_size)
7679 return -EINVAL;
7680 }
7681
7682 size = sizeof(*cfg);
7683 size += data_size;
7684 size += wake_size + wake_mask_size;
7685 size += tokens_size;
7686
7687 cfg = kzalloc(size, GFP_KERNEL);
7688 if (!cfg)
7689 return -ENOMEM;
7690 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7691 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7692 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7693 ETH_ALEN);
7694 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7695 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7696 else
7697 port = 0;
7698#ifdef CONFIG_INET
7699 /* allocate a socket and port for it and use it */
7700 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7701 IPPROTO_TCP, &cfg->sock, 1);
7702 if (err) {
7703 kfree(cfg);
7704 return err;
7705 }
7706 if (inet_csk_get_port(cfg->sock->sk, port)) {
7707 sock_release(cfg->sock);
7708 kfree(cfg);
7709 return -EADDRINUSE;
7710 }
7711 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7712#else
7713 if (!port) {
7714 kfree(cfg);
7715 return -EINVAL;
7716 }
7717 cfg->src_port = port;
7718#endif
7719
7720 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7721 cfg->payload_len = data_size;
7722 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7723 memcpy((void *)cfg->payload,
7724 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7725 data_size);
7726 if (seq)
7727 cfg->payload_seq = *seq;
7728 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7729 cfg->wake_len = wake_size;
7730 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7731 memcpy((void *)cfg->wake_data,
7732 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7733 wake_size);
7734 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7735 data_size + wake_size;
7736 memcpy((void *)cfg->wake_mask,
7737 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7738 wake_mask_size);
7739 if (tok) {
7740 cfg->tokens_size = tokens_size;
7741 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7742 }
7743
7744 trig->tcp = cfg;
7745
7746 return 0;
7747}
7748
Johannes Bergff1b6e62011-05-04 15:37:28 +02007749static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7750{
7751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7752 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007753 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007754 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007755 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7756 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007757 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007758
Johannes Berg2a0e0472013-01-23 22:57:40 +01007759 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7760 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007761 return -EOPNOTSUPP;
7762
Johannes Bergae33bd82012-07-12 16:25:02 +02007763 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7764 cfg80211_rdev_free_wowlan(rdev);
7765 rdev->wowlan = NULL;
7766 goto set_wakeup;
7767 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007768
7769 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7770 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7771 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7772 nl80211_wowlan_policy);
7773 if (err)
7774 return err;
7775
7776 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7777 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7778 return -EINVAL;
7779 new_triggers.any = true;
7780 }
7781
7782 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7783 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7784 return -EINVAL;
7785 new_triggers.disconnect = true;
7786 }
7787
7788 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7789 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7790 return -EINVAL;
7791 new_triggers.magic_pkt = true;
7792 }
7793
Johannes Berg77dbbb132011-07-13 10:48:55 +02007794 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7795 return -EINVAL;
7796
7797 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7798 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7799 return -EINVAL;
7800 new_triggers.gtk_rekey_failure = true;
7801 }
7802
7803 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7804 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7805 return -EINVAL;
7806 new_triggers.eap_identity_req = true;
7807 }
7808
7809 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7810 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7811 return -EINVAL;
7812 new_triggers.four_way_handshake = true;
7813 }
7814
7815 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7816 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7817 return -EINVAL;
7818 new_triggers.rfkill_release = true;
7819 }
7820
Johannes Bergff1b6e62011-05-04 15:37:28 +02007821 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7822 struct nlattr *pat;
7823 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007824 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007825 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7826
7827 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7828 rem)
7829 n_patterns++;
7830 if (n_patterns > wowlan->n_patterns)
7831 return -EINVAL;
7832
7833 new_triggers.patterns = kcalloc(n_patterns,
7834 sizeof(new_triggers.patterns[0]),
7835 GFP_KERNEL);
7836 if (!new_triggers.patterns)
7837 return -ENOMEM;
7838
7839 new_triggers.n_patterns = n_patterns;
7840 i = 0;
7841
7842 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7843 rem) {
7844 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7845 nla_data(pat), nla_len(pat), NULL);
7846 err = -EINVAL;
7847 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7848 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7849 goto error;
7850 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7851 mask_len = DIV_ROUND_UP(pat_len, 8);
7852 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7853 mask_len)
7854 goto error;
7855 if (pat_len > wowlan->pattern_max_len ||
7856 pat_len < wowlan->pattern_min_len)
7857 goto error;
7858
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007859 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7860 pkt_offset = 0;
7861 else
7862 pkt_offset = nla_get_u32(
7863 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7864 if (pkt_offset > wowlan->max_pkt_offset)
7865 goto error;
7866 new_triggers.patterns[i].pkt_offset = pkt_offset;
7867
Johannes Bergff1b6e62011-05-04 15:37:28 +02007868 new_triggers.patterns[i].mask =
7869 kmalloc(mask_len + pat_len, GFP_KERNEL);
7870 if (!new_triggers.patterns[i].mask) {
7871 err = -ENOMEM;
7872 goto error;
7873 }
7874 new_triggers.patterns[i].pattern =
7875 new_triggers.patterns[i].mask + mask_len;
7876 memcpy(new_triggers.patterns[i].mask,
7877 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7878 mask_len);
7879 new_triggers.patterns[i].pattern_len = pat_len;
7880 memcpy(new_triggers.patterns[i].pattern,
7881 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7882 pat_len);
7883 i++;
7884 }
7885 }
7886
Johannes Berg2a0e0472013-01-23 22:57:40 +01007887 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7888 err = nl80211_parse_wowlan_tcp(
7889 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7890 &new_triggers);
7891 if (err)
7892 goto error;
7893 }
7894
Johannes Bergae33bd82012-07-12 16:25:02 +02007895 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7896 if (!ntrig) {
7897 err = -ENOMEM;
7898 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007899 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007900 cfg80211_rdev_free_wowlan(rdev);
7901 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007902
Johannes Bergae33bd82012-07-12 16:25:02 +02007903 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007904 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007905 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007906
Johannes Bergff1b6e62011-05-04 15:37:28 +02007907 return 0;
7908 error:
7909 for (i = 0; i < new_triggers.n_patterns; i++)
7910 kfree(new_triggers.patterns[i].mask);
7911 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007912 if (new_triggers.tcp && new_triggers.tcp->sock)
7913 sock_release(new_triggers.tcp->sock);
7914 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007915 return err;
7916}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007917#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007918
Johannes Berge5497d72011-07-05 16:35:40 +02007919static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7920{
7921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7922 struct net_device *dev = info->user_ptr[1];
7923 struct wireless_dev *wdev = dev->ieee80211_ptr;
7924 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7925 struct cfg80211_gtk_rekey_data rekey_data;
7926 int err;
7927
7928 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7929 return -EINVAL;
7930
7931 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7932 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7933 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7934 nl80211_rekey_policy);
7935 if (err)
7936 return err;
7937
7938 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7939 return -ERANGE;
7940 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7941 return -ERANGE;
7942 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7943 return -ERANGE;
7944
7945 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7946 NL80211_KEK_LEN);
7947 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7948 NL80211_KCK_LEN);
7949 memcpy(rekey_data.replay_ctr,
7950 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7951 NL80211_REPLAY_CTR_LEN);
7952
7953 wdev_lock(wdev);
7954 if (!wdev->current_bss) {
7955 err = -ENOTCONN;
7956 goto out;
7957 }
7958
7959 if (!rdev->ops->set_rekey_data) {
7960 err = -EOPNOTSUPP;
7961 goto out;
7962 }
7963
Hila Gonene35e4d22012-06-27 17:19:42 +03007964 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007965 out:
7966 wdev_unlock(wdev);
7967 return err;
7968}
7969
Johannes Berg28946da2011-11-04 11:18:12 +01007970static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7971 struct genl_info *info)
7972{
7973 struct net_device *dev = info->user_ptr[1];
7974 struct wireless_dev *wdev = dev->ieee80211_ptr;
7975
7976 if (wdev->iftype != NL80211_IFTYPE_AP &&
7977 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7978 return -EINVAL;
7979
Eric W. Biederman15e47302012-09-07 20:12:54 +00007980 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01007981 return -EBUSY;
7982
Eric W. Biederman15e47302012-09-07 20:12:54 +00007983 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01007984 return 0;
7985}
7986
Johannes Berg7f6cf312011-11-04 11:18:15 +01007987static int nl80211_probe_client(struct sk_buff *skb,
7988 struct genl_info *info)
7989{
7990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7991 struct net_device *dev = info->user_ptr[1];
7992 struct wireless_dev *wdev = dev->ieee80211_ptr;
7993 struct sk_buff *msg;
7994 void *hdr;
7995 const u8 *addr;
7996 u64 cookie;
7997 int err;
7998
7999 if (wdev->iftype != NL80211_IFTYPE_AP &&
8000 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8001 return -EOPNOTSUPP;
8002
8003 if (!info->attrs[NL80211_ATTR_MAC])
8004 return -EINVAL;
8005
8006 if (!rdev->ops->probe_client)
8007 return -EOPNOTSUPP;
8008
8009 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8010 if (!msg)
8011 return -ENOMEM;
8012
Eric W. Biederman15e47302012-09-07 20:12:54 +00008013 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008014 NL80211_CMD_PROBE_CLIENT);
8015
8016 if (IS_ERR(hdr)) {
8017 err = PTR_ERR(hdr);
8018 goto free_msg;
8019 }
8020
8021 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8022
Hila Gonene35e4d22012-06-27 17:19:42 +03008023 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008024 if (err)
8025 goto free_msg;
8026
David S. Miller9360ffd2012-03-29 04:41:26 -04008027 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8028 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008029
8030 genlmsg_end(msg, hdr);
8031
8032 return genlmsg_reply(msg, info);
8033
8034 nla_put_failure:
8035 err = -ENOBUFS;
8036 free_msg:
8037 nlmsg_free(msg);
8038 return err;
8039}
8040
Johannes Berg5e760232011-11-04 11:18:17 +01008041static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8042{
8043 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008044 struct cfg80211_beacon_registration *reg, *nreg;
8045 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008046
8047 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8048 return -EOPNOTSUPP;
8049
Ben Greear37c73b52012-10-26 14:49:25 -07008050 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8051 if (!nreg)
8052 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008053
Ben Greear37c73b52012-10-26 14:49:25 -07008054 /* First, check if already registered. */
8055 spin_lock_bh(&rdev->beacon_registrations_lock);
8056 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8057 if (reg->nlportid == info->snd_portid) {
8058 rv = -EALREADY;
8059 goto out_err;
8060 }
8061 }
8062 /* Add it to the list */
8063 nreg->nlportid = info->snd_portid;
8064 list_add(&nreg->list, &rdev->beacon_registrations);
8065
8066 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008067
8068 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008069out_err:
8070 spin_unlock_bh(&rdev->beacon_registrations_lock);
8071 kfree(nreg);
8072 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008073}
8074
Johannes Berg98104fde2012-06-16 00:19:54 +02008075static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8076{
8077 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8078 struct wireless_dev *wdev = info->user_ptr[1];
8079 int err;
8080
8081 if (!rdev->ops->start_p2p_device)
8082 return -EOPNOTSUPP;
8083
8084 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8085 return -EOPNOTSUPP;
8086
8087 if (wdev->p2p_started)
8088 return 0;
8089
8090 mutex_lock(&rdev->devlist_mtx);
8091 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8092 mutex_unlock(&rdev->devlist_mtx);
8093 if (err)
8094 return err;
8095
Johannes Bergeeb126e2012-10-23 15:16:50 +02008096 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008097 if (err)
8098 return err;
8099
8100 wdev->p2p_started = true;
8101 mutex_lock(&rdev->devlist_mtx);
8102 rdev->opencount++;
8103 mutex_unlock(&rdev->devlist_mtx);
8104
8105 return 0;
8106}
8107
8108static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8109{
8110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8111 struct wireless_dev *wdev = info->user_ptr[1];
8112
8113 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8114 return -EOPNOTSUPP;
8115
8116 if (!rdev->ops->stop_p2p_device)
8117 return -EOPNOTSUPP;
8118
8119 if (!wdev->p2p_started)
8120 return 0;
8121
Johannes Bergeeb126e2012-10-23 15:16:50 +02008122 rdev_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008123 wdev->p2p_started = false;
8124
8125 mutex_lock(&rdev->devlist_mtx);
8126 rdev->opencount--;
8127 mutex_unlock(&rdev->devlist_mtx);
8128
8129 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
8130 rdev->scan_req->aborted = true;
8131 ___cfg80211_scan_done(rdev, true);
8132 }
8133
8134 return 0;
8135}
8136
Johannes Berg3713b4e2013-02-14 16:19:38 +01008137static int nl80211_get_protocol_features(struct sk_buff *skb,
8138 struct genl_info *info)
8139{
8140 void *hdr;
8141 struct sk_buff *msg;
8142
8143 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8144 if (!msg)
8145 return -ENOMEM;
8146
8147 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8148 NL80211_CMD_GET_PROTOCOL_FEATURES);
8149 if (!hdr)
8150 goto nla_put_failure;
8151
8152 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8153 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8154 goto nla_put_failure;
8155
8156 genlmsg_end(msg, hdr);
8157 return genlmsg_reply(msg, info);
8158
8159 nla_put_failure:
8160 kfree_skb(msg);
8161 return -ENOBUFS;
8162}
8163
Johannes Berg4c476992010-10-04 21:36:35 +02008164#define NL80211_FLAG_NEED_WIPHY 0x01
8165#define NL80211_FLAG_NEED_NETDEV 0x02
8166#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008167#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8168#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8169 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008170#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008171/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008172#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8173 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008174
8175static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8176 struct genl_info *info)
8177{
8178 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008179 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008180 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008181 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8182
8183 if (rtnl)
8184 rtnl_lock();
8185
8186 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008187 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008188 if (IS_ERR(rdev)) {
8189 if (rtnl)
8190 rtnl_unlock();
8191 return PTR_ERR(rdev);
8192 }
8193 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008194 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8195 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008196 mutex_lock(&cfg80211_mutex);
8197 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8198 info->attrs);
8199 if (IS_ERR(wdev)) {
8200 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02008201 if (rtnl)
8202 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008203 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008204 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008205
Johannes Berg89a54e42012-06-15 14:33:17 +02008206 dev = wdev->netdev;
8207 rdev = wiphy_to_dev(wdev->wiphy);
8208
Johannes Berg1bf614e2012-06-15 15:23:36 +02008209 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8210 if (!dev) {
8211 mutex_unlock(&cfg80211_mutex);
8212 if (rtnl)
8213 rtnl_unlock();
8214 return -EINVAL;
8215 }
8216
8217 info->user_ptr[1] = dev;
8218 } else {
8219 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008220 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008221
Johannes Berg1bf614e2012-06-15 15:23:36 +02008222 if (dev) {
8223 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8224 !netif_running(dev)) {
8225 mutex_unlock(&cfg80211_mutex);
8226 if (rtnl)
8227 rtnl_unlock();
8228 return -ENETDOWN;
8229 }
8230
8231 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008232 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8233 if (!wdev->p2p_started) {
8234 mutex_unlock(&cfg80211_mutex);
8235 if (rtnl)
8236 rtnl_unlock();
8237 return -ENETDOWN;
8238 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008239 }
8240
Johannes Berg89a54e42012-06-15 14:33:17 +02008241 cfg80211_lock_rdev(rdev);
8242
8243 mutex_unlock(&cfg80211_mutex);
8244
Johannes Berg4c476992010-10-04 21:36:35 +02008245 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008246 }
8247
8248 return 0;
8249}
8250
8251static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8252 struct genl_info *info)
8253{
8254 if (info->user_ptr[0])
8255 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02008256 if (info->user_ptr[1]) {
8257 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8258 struct wireless_dev *wdev = info->user_ptr[1];
8259
8260 if (wdev->netdev)
8261 dev_put(wdev->netdev);
8262 } else {
8263 dev_put(info->user_ptr[1]);
8264 }
8265 }
Johannes Berg4c476992010-10-04 21:36:35 +02008266 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8267 rtnl_unlock();
8268}
8269
Johannes Berg55682962007-09-20 13:09:35 -04008270static struct genl_ops nl80211_ops[] = {
8271 {
8272 .cmd = NL80211_CMD_GET_WIPHY,
8273 .doit = nl80211_get_wiphy,
8274 .dumpit = nl80211_dump_wiphy,
8275 .policy = nl80211_policy,
8276 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008277 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04008278 },
8279 {
8280 .cmd = NL80211_CMD_SET_WIPHY,
8281 .doit = nl80211_set_wiphy,
8282 .policy = nl80211_policy,
8283 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008284 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008285 },
8286 {
8287 .cmd = NL80211_CMD_GET_INTERFACE,
8288 .doit = nl80211_get_interface,
8289 .dumpit = nl80211_dump_interface,
8290 .policy = nl80211_policy,
8291 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02008292 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04008293 },
8294 {
8295 .cmd = NL80211_CMD_SET_INTERFACE,
8296 .doit = nl80211_set_interface,
8297 .policy = nl80211_policy,
8298 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008299 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8300 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008301 },
8302 {
8303 .cmd = NL80211_CMD_NEW_INTERFACE,
8304 .doit = nl80211_new_interface,
8305 .policy = nl80211_policy,
8306 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008307 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8308 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008309 },
8310 {
8311 .cmd = NL80211_CMD_DEL_INTERFACE,
8312 .doit = nl80211_del_interface,
8313 .policy = nl80211_policy,
8314 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008315 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008316 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008317 },
Johannes Berg41ade002007-12-19 02:03:29 +01008318 {
8319 .cmd = NL80211_CMD_GET_KEY,
8320 .doit = nl80211_get_key,
8321 .policy = nl80211_policy,
8322 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008323 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008324 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008325 },
8326 {
8327 .cmd = NL80211_CMD_SET_KEY,
8328 .doit = nl80211_set_key,
8329 .policy = nl80211_policy,
8330 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008332 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008333 },
8334 {
8335 .cmd = NL80211_CMD_NEW_KEY,
8336 .doit = nl80211_new_key,
8337 .policy = nl80211_policy,
8338 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008339 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008340 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008341 },
8342 {
8343 .cmd = NL80211_CMD_DEL_KEY,
8344 .doit = nl80211_del_key,
8345 .policy = nl80211_policy,
8346 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008347 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008348 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008349 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008350 {
8351 .cmd = NL80211_CMD_SET_BEACON,
8352 .policy = nl80211_policy,
8353 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008354 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008356 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008357 },
8358 {
Johannes Berg88600202012-02-13 15:17:18 +01008359 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008360 .policy = nl80211_policy,
8361 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008362 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008364 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008365 },
8366 {
Johannes Berg88600202012-02-13 15:17:18 +01008367 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008368 .policy = nl80211_policy,
8369 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008370 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008372 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008373 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008374 {
8375 .cmd = NL80211_CMD_GET_STATION,
8376 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008377 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008378 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008379 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8380 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008381 },
8382 {
8383 .cmd = NL80211_CMD_SET_STATION,
8384 .doit = nl80211_set_station,
8385 .policy = nl80211_policy,
8386 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008388 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008389 },
8390 {
8391 .cmd = NL80211_CMD_NEW_STATION,
8392 .doit = nl80211_new_station,
8393 .policy = nl80211_policy,
8394 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008396 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008397 },
8398 {
8399 .cmd = NL80211_CMD_DEL_STATION,
8400 .doit = nl80211_del_station,
8401 .policy = nl80211_policy,
8402 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008403 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008404 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008405 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008406 {
8407 .cmd = NL80211_CMD_GET_MPATH,
8408 .doit = nl80211_get_mpath,
8409 .dumpit = nl80211_dump_mpath,
8410 .policy = nl80211_policy,
8411 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008412 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008413 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008414 },
8415 {
8416 .cmd = NL80211_CMD_SET_MPATH,
8417 .doit = nl80211_set_mpath,
8418 .policy = nl80211_policy,
8419 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008420 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008421 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008422 },
8423 {
8424 .cmd = NL80211_CMD_NEW_MPATH,
8425 .doit = nl80211_new_mpath,
8426 .policy = nl80211_policy,
8427 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008428 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008429 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008430 },
8431 {
8432 .cmd = NL80211_CMD_DEL_MPATH,
8433 .doit = nl80211_del_mpath,
8434 .policy = nl80211_policy,
8435 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008436 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008437 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008438 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008439 {
8440 .cmd = NL80211_CMD_SET_BSS,
8441 .doit = nl80211_set_bss,
8442 .policy = nl80211_policy,
8443 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008444 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008445 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008446 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008447 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008448 .cmd = NL80211_CMD_GET_REG,
8449 .doit = nl80211_get_reg,
8450 .policy = nl80211_policy,
8451 /* can be retrieved by unprivileged users */
8452 },
8453 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008454 .cmd = NL80211_CMD_SET_REG,
8455 .doit = nl80211_set_reg,
8456 .policy = nl80211_policy,
8457 .flags = GENL_ADMIN_PERM,
8458 },
8459 {
8460 .cmd = NL80211_CMD_REQ_SET_REG,
8461 .doit = nl80211_req_set_reg,
8462 .policy = nl80211_policy,
8463 .flags = GENL_ADMIN_PERM,
8464 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008465 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008466 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8467 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008468 .policy = nl80211_policy,
8469 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008470 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008471 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008472 },
8473 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008474 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8475 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008476 .policy = nl80211_policy,
8477 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008478 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008479 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008480 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008481 {
Johannes Berg2a519312009-02-10 21:25:55 +01008482 .cmd = NL80211_CMD_TRIGGER_SCAN,
8483 .doit = nl80211_trigger_scan,
8484 .policy = nl80211_policy,
8485 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008486 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008487 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008488 },
8489 {
8490 .cmd = NL80211_CMD_GET_SCAN,
8491 .policy = nl80211_policy,
8492 .dumpit = nl80211_dump_scan,
8493 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008494 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008495 .cmd = NL80211_CMD_START_SCHED_SCAN,
8496 .doit = nl80211_start_sched_scan,
8497 .policy = nl80211_policy,
8498 .flags = GENL_ADMIN_PERM,
8499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8500 NL80211_FLAG_NEED_RTNL,
8501 },
8502 {
8503 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8504 .doit = nl80211_stop_sched_scan,
8505 .policy = nl80211_policy,
8506 .flags = GENL_ADMIN_PERM,
8507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8508 NL80211_FLAG_NEED_RTNL,
8509 },
8510 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008511 .cmd = NL80211_CMD_AUTHENTICATE,
8512 .doit = nl80211_authenticate,
8513 .policy = nl80211_policy,
8514 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008516 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008517 },
8518 {
8519 .cmd = NL80211_CMD_ASSOCIATE,
8520 .doit = nl80211_associate,
8521 .policy = nl80211_policy,
8522 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008523 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008524 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008525 },
8526 {
8527 .cmd = NL80211_CMD_DEAUTHENTICATE,
8528 .doit = nl80211_deauthenticate,
8529 .policy = nl80211_policy,
8530 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008531 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008532 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008533 },
8534 {
8535 .cmd = NL80211_CMD_DISASSOCIATE,
8536 .doit = nl80211_disassociate,
8537 .policy = nl80211_policy,
8538 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008539 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008540 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008541 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008542 {
8543 .cmd = NL80211_CMD_JOIN_IBSS,
8544 .doit = nl80211_join_ibss,
8545 .policy = nl80211_policy,
8546 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008547 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008548 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008549 },
8550 {
8551 .cmd = NL80211_CMD_LEAVE_IBSS,
8552 .doit = nl80211_leave_ibss,
8553 .policy = nl80211_policy,
8554 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008556 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008557 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008558#ifdef CONFIG_NL80211_TESTMODE
8559 {
8560 .cmd = NL80211_CMD_TESTMODE,
8561 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008562 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008563 .policy = nl80211_policy,
8564 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008565 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8566 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008567 },
8568#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008569 {
8570 .cmd = NL80211_CMD_CONNECT,
8571 .doit = nl80211_connect,
8572 .policy = nl80211_policy,
8573 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008574 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008575 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008576 },
8577 {
8578 .cmd = NL80211_CMD_DISCONNECT,
8579 .doit = nl80211_disconnect,
8580 .policy = nl80211_policy,
8581 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008582 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008583 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008584 },
Johannes Berg463d0182009-07-14 00:33:35 +02008585 {
8586 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8587 .doit = nl80211_wiphy_netns,
8588 .policy = nl80211_policy,
8589 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008590 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8591 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008592 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008593 {
8594 .cmd = NL80211_CMD_GET_SURVEY,
8595 .policy = nl80211_policy,
8596 .dumpit = nl80211_dump_survey,
8597 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008598 {
8599 .cmd = NL80211_CMD_SET_PMKSA,
8600 .doit = nl80211_setdel_pmksa,
8601 .policy = nl80211_policy,
8602 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008604 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008605 },
8606 {
8607 .cmd = NL80211_CMD_DEL_PMKSA,
8608 .doit = nl80211_setdel_pmksa,
8609 .policy = nl80211_policy,
8610 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008612 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008613 },
8614 {
8615 .cmd = NL80211_CMD_FLUSH_PMKSA,
8616 .doit = nl80211_flush_pmksa,
8617 .policy = nl80211_policy,
8618 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008620 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008621 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008622 {
8623 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8624 .doit = nl80211_remain_on_channel,
8625 .policy = nl80211_policy,
8626 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008627 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008628 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008629 },
8630 {
8631 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8632 .doit = nl80211_cancel_remain_on_channel,
8633 .policy = nl80211_policy,
8634 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008635 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008636 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008637 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008638 {
8639 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8640 .doit = nl80211_set_tx_bitrate_mask,
8641 .policy = nl80211_policy,
8642 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008643 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8644 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008645 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008646 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008647 .cmd = NL80211_CMD_REGISTER_FRAME,
8648 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008649 .policy = nl80211_policy,
8650 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008651 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008652 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008653 },
8654 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008655 .cmd = NL80211_CMD_FRAME,
8656 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008657 .policy = nl80211_policy,
8658 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008659 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008660 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008661 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008662 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008663 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8664 .doit = nl80211_tx_mgmt_cancel_wait,
8665 .policy = nl80211_policy,
8666 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008667 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008668 NL80211_FLAG_NEED_RTNL,
8669 },
8670 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008671 .cmd = NL80211_CMD_SET_POWER_SAVE,
8672 .doit = nl80211_set_power_save,
8673 .policy = nl80211_policy,
8674 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008675 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8676 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008677 },
8678 {
8679 .cmd = NL80211_CMD_GET_POWER_SAVE,
8680 .doit = nl80211_get_power_save,
8681 .policy = nl80211_policy,
8682 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008683 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8684 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008685 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008686 {
8687 .cmd = NL80211_CMD_SET_CQM,
8688 .doit = nl80211_set_cqm,
8689 .policy = nl80211_policy,
8690 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008691 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8692 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008693 },
Johannes Bergf444de02010-05-05 15:25:02 +02008694 {
8695 .cmd = NL80211_CMD_SET_CHANNEL,
8696 .doit = nl80211_set_channel,
8697 .policy = nl80211_policy,
8698 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008699 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8700 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008701 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008702 {
8703 .cmd = NL80211_CMD_SET_WDS_PEER,
8704 .doit = nl80211_set_wds_peer,
8705 .policy = nl80211_policy,
8706 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008707 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8708 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008709 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008710 {
8711 .cmd = NL80211_CMD_JOIN_MESH,
8712 .doit = nl80211_join_mesh,
8713 .policy = nl80211_policy,
8714 .flags = GENL_ADMIN_PERM,
8715 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8716 NL80211_FLAG_NEED_RTNL,
8717 },
8718 {
8719 .cmd = NL80211_CMD_LEAVE_MESH,
8720 .doit = nl80211_leave_mesh,
8721 .policy = nl80211_policy,
8722 .flags = GENL_ADMIN_PERM,
8723 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8724 NL80211_FLAG_NEED_RTNL,
8725 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008726#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008727 {
8728 .cmd = NL80211_CMD_GET_WOWLAN,
8729 .doit = nl80211_get_wowlan,
8730 .policy = nl80211_policy,
8731 /* can be retrieved by unprivileged users */
8732 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8733 NL80211_FLAG_NEED_RTNL,
8734 },
8735 {
8736 .cmd = NL80211_CMD_SET_WOWLAN,
8737 .doit = nl80211_set_wowlan,
8738 .policy = nl80211_policy,
8739 .flags = GENL_ADMIN_PERM,
8740 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8741 NL80211_FLAG_NEED_RTNL,
8742 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008743#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008744 {
8745 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8746 .doit = nl80211_set_rekey_data,
8747 .policy = nl80211_policy,
8748 .flags = GENL_ADMIN_PERM,
8749 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8750 NL80211_FLAG_NEED_RTNL,
8751 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008752 {
8753 .cmd = NL80211_CMD_TDLS_MGMT,
8754 .doit = nl80211_tdls_mgmt,
8755 .policy = nl80211_policy,
8756 .flags = GENL_ADMIN_PERM,
8757 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8758 NL80211_FLAG_NEED_RTNL,
8759 },
8760 {
8761 .cmd = NL80211_CMD_TDLS_OPER,
8762 .doit = nl80211_tdls_oper,
8763 .policy = nl80211_policy,
8764 .flags = GENL_ADMIN_PERM,
8765 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8766 NL80211_FLAG_NEED_RTNL,
8767 },
Johannes Berg28946da2011-11-04 11:18:12 +01008768 {
8769 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8770 .doit = nl80211_register_unexpected_frame,
8771 .policy = nl80211_policy,
8772 .flags = GENL_ADMIN_PERM,
8773 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8774 NL80211_FLAG_NEED_RTNL,
8775 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008776 {
8777 .cmd = NL80211_CMD_PROBE_CLIENT,
8778 .doit = nl80211_probe_client,
8779 .policy = nl80211_policy,
8780 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008781 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008782 NL80211_FLAG_NEED_RTNL,
8783 },
Johannes Berg5e760232011-11-04 11:18:17 +01008784 {
8785 .cmd = NL80211_CMD_REGISTER_BEACONS,
8786 .doit = nl80211_register_beacons,
8787 .policy = nl80211_policy,
8788 .flags = GENL_ADMIN_PERM,
8789 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8790 NL80211_FLAG_NEED_RTNL,
8791 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008792 {
8793 .cmd = NL80211_CMD_SET_NOACK_MAP,
8794 .doit = nl80211_set_noack_map,
8795 .policy = nl80211_policy,
8796 .flags = GENL_ADMIN_PERM,
8797 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8798 NL80211_FLAG_NEED_RTNL,
8799 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008800 {
8801 .cmd = NL80211_CMD_START_P2P_DEVICE,
8802 .doit = nl80211_start_p2p_device,
8803 .policy = nl80211_policy,
8804 .flags = GENL_ADMIN_PERM,
8805 .internal_flags = NL80211_FLAG_NEED_WDEV |
8806 NL80211_FLAG_NEED_RTNL,
8807 },
8808 {
8809 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8810 .doit = nl80211_stop_p2p_device,
8811 .policy = nl80211_policy,
8812 .flags = GENL_ADMIN_PERM,
8813 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8814 NL80211_FLAG_NEED_RTNL,
8815 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008816 {
8817 .cmd = NL80211_CMD_SET_MCAST_RATE,
8818 .doit = nl80211_set_mcast_rate,
8819 .policy = nl80211_policy,
8820 .flags = GENL_ADMIN_PERM,
8821 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8822 NL80211_FLAG_NEED_RTNL,
8823 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308824 {
8825 .cmd = NL80211_CMD_SET_MAC_ACL,
8826 .doit = nl80211_set_mac_acl,
8827 .policy = nl80211_policy,
8828 .flags = GENL_ADMIN_PERM,
8829 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8830 NL80211_FLAG_NEED_RTNL,
8831 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008832 {
8833 .cmd = NL80211_CMD_RADAR_DETECT,
8834 .doit = nl80211_start_radar_detection,
8835 .policy = nl80211_policy,
8836 .flags = GENL_ADMIN_PERM,
8837 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8838 NL80211_FLAG_NEED_RTNL,
8839 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008840 {
8841 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8842 .doit = nl80211_get_protocol_features,
8843 .policy = nl80211_policy,
8844 },
Johannes Berg55682962007-09-20 13:09:35 -04008845};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008846
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008847static struct genl_multicast_group nl80211_mlme_mcgrp = {
8848 .name = "mlme",
8849};
Johannes Berg55682962007-09-20 13:09:35 -04008850
8851/* multicast groups */
8852static struct genl_multicast_group nl80211_config_mcgrp = {
8853 .name = "config",
8854};
Johannes Berg2a519312009-02-10 21:25:55 +01008855static struct genl_multicast_group nl80211_scan_mcgrp = {
8856 .name = "scan",
8857};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008858static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8859 .name = "regulatory",
8860};
Johannes Berg55682962007-09-20 13:09:35 -04008861
8862/* notification functions */
8863
8864void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8865{
8866 struct sk_buff *msg;
8867
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008868 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008869 if (!msg)
8870 return;
8871
Johannes Berg3713b4e2013-02-14 16:19:38 +01008872 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8873 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008874 nlmsg_free(msg);
8875 return;
8876 }
8877
Johannes Berg463d0182009-07-14 00:33:35 +02008878 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8879 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008880}
8881
Johannes Berg362a4152009-05-24 16:43:15 +02008882static int nl80211_add_scan_req(struct sk_buff *msg,
8883 struct cfg80211_registered_device *rdev)
8884{
8885 struct cfg80211_scan_request *req = rdev->scan_req;
8886 struct nlattr *nest;
8887 int i;
8888
Johannes Berg667503d2009-07-07 03:56:11 +02008889 ASSERT_RDEV_LOCK(rdev);
8890
Johannes Berg362a4152009-05-24 16:43:15 +02008891 if (WARN_ON(!req))
8892 return 0;
8893
8894 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8895 if (!nest)
8896 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008897 for (i = 0; i < req->n_ssids; i++) {
8898 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8899 goto nla_put_failure;
8900 }
Johannes Berg362a4152009-05-24 16:43:15 +02008901 nla_nest_end(msg, nest);
8902
8903 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8904 if (!nest)
8905 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008906 for (i = 0; i < req->n_channels; i++) {
8907 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8908 goto nla_put_failure;
8909 }
Johannes Berg362a4152009-05-24 16:43:15 +02008910 nla_nest_end(msg, nest);
8911
David S. Miller9360ffd2012-03-29 04:41:26 -04008912 if (req->ie &&
8913 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8914 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008915
Sam Lefflered4737712012-10-11 21:03:31 -07008916 if (req->flags)
8917 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8918
Johannes Berg362a4152009-05-24 16:43:15 +02008919 return 0;
8920 nla_put_failure:
8921 return -ENOBUFS;
8922}
8923
Johannes Berga538e2d2009-06-16 19:56:42 +02008924static int nl80211_send_scan_msg(struct sk_buff *msg,
8925 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008926 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008927 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008928 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008929{
8930 void *hdr;
8931
Eric W. Biederman15e47302012-09-07 20:12:54 +00008932 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008933 if (!hdr)
8934 return -1;
8935
David S. Miller9360ffd2012-03-29 04:41:26 -04008936 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008937 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8938 wdev->netdev->ifindex)) ||
8939 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008940 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008941
Johannes Berg362a4152009-05-24 16:43:15 +02008942 /* ignore errors and send incomplete event anyway */
8943 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008944
8945 return genlmsg_end(msg, hdr);
8946
8947 nla_put_failure:
8948 genlmsg_cancel(msg, hdr);
8949 return -EMSGSIZE;
8950}
8951
Luciano Coelho807f8a82011-05-11 17:09:35 +03008952static int
8953nl80211_send_sched_scan_msg(struct sk_buff *msg,
8954 struct cfg80211_registered_device *rdev,
8955 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008956 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008957{
8958 void *hdr;
8959
Eric W. Biederman15e47302012-09-07 20:12:54 +00008960 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008961 if (!hdr)
8962 return -1;
8963
David S. Miller9360ffd2012-03-29 04:41:26 -04008964 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8965 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8966 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008967
8968 return genlmsg_end(msg, hdr);
8969
8970 nla_put_failure:
8971 genlmsg_cancel(msg, hdr);
8972 return -EMSGSIZE;
8973}
8974
Johannes Berga538e2d2009-06-16 19:56:42 +02008975void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008976 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02008977{
8978 struct sk_buff *msg;
8979
Thomas Graf58050fc2012-06-28 03:57:45 +00008980 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008981 if (!msg)
8982 return;
8983
Johannes Bergfd014282012-06-18 19:17:03 +02008984 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008985 NL80211_CMD_TRIGGER_SCAN) < 0) {
8986 nlmsg_free(msg);
8987 return;
8988 }
8989
Johannes Berg463d0182009-07-14 00:33:35 +02008990 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8991 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008992}
8993
Johannes Berg2a519312009-02-10 21:25:55 +01008994void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008995 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01008996{
8997 struct sk_buff *msg;
8998
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008999 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009000 if (!msg)
9001 return;
9002
Johannes Bergfd014282012-06-18 19:17:03 +02009003 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009004 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009005 nlmsg_free(msg);
9006 return;
9007 }
9008
Johannes Berg463d0182009-07-14 00:33:35 +02009009 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9010 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009011}
9012
9013void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009014 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009015{
9016 struct sk_buff *msg;
9017
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009018 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009019 if (!msg)
9020 return;
9021
Johannes Bergfd014282012-06-18 19:17:03 +02009022 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009023 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009024 nlmsg_free(msg);
9025 return;
9026 }
9027
Johannes Berg463d0182009-07-14 00:33:35 +02009028 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9029 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009030}
9031
Luciano Coelho807f8a82011-05-11 17:09:35 +03009032void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9033 struct net_device *netdev)
9034{
9035 struct sk_buff *msg;
9036
9037 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9038 if (!msg)
9039 return;
9040
9041 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9042 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9043 nlmsg_free(msg);
9044 return;
9045 }
9046
9047 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9048 nl80211_scan_mcgrp.id, GFP_KERNEL);
9049}
9050
9051void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9052 struct net_device *netdev, u32 cmd)
9053{
9054 struct sk_buff *msg;
9055
Thomas Graf58050fc2012-06-28 03:57:45 +00009056 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009057 if (!msg)
9058 return;
9059
9060 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9061 nlmsg_free(msg);
9062 return;
9063 }
9064
9065 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9066 nl80211_scan_mcgrp.id, GFP_KERNEL);
9067}
9068
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009069/*
9070 * This can happen on global regulatory changes or device specific settings
9071 * based on custom world regulatory domains.
9072 */
9073void nl80211_send_reg_change_event(struct regulatory_request *request)
9074{
9075 struct sk_buff *msg;
9076 void *hdr;
9077
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009078 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009079 if (!msg)
9080 return;
9081
9082 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9083 if (!hdr) {
9084 nlmsg_free(msg);
9085 return;
9086 }
9087
9088 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009089 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9090 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009091
David S. Miller9360ffd2012-03-29 04:41:26 -04009092 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9093 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9094 NL80211_REGDOM_TYPE_WORLD))
9095 goto nla_put_failure;
9096 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9097 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9098 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9099 goto nla_put_failure;
9100 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9101 request->intersect) {
9102 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9103 NL80211_REGDOM_TYPE_INTERSECTION))
9104 goto nla_put_failure;
9105 } else {
9106 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9107 NL80211_REGDOM_TYPE_COUNTRY) ||
9108 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9109 request->alpha2))
9110 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009111 }
9112
Johannes Bergf4173762012-12-03 18:23:37 +01009113 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009114 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9115 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009116
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009117 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009118
Johannes Bergbc43b282009-07-25 10:54:13 +02009119 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009120 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009121 GFP_ATOMIC);
9122 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009123
9124 return;
9125
9126nla_put_failure:
9127 genlmsg_cancel(msg, hdr);
9128 nlmsg_free(msg);
9129}
9130
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009131static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9132 struct net_device *netdev,
9133 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009134 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009135{
9136 struct sk_buff *msg;
9137 void *hdr;
9138
Johannes Berge6d6e342009-07-01 21:26:47 +02009139 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009140 if (!msg)
9141 return;
9142
9143 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9144 if (!hdr) {
9145 nlmsg_free(msg);
9146 return;
9147 }
9148
David S. Miller9360ffd2012-03-29 04:41:26 -04009149 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9150 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9151 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9152 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009153
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009154 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009155
Johannes Berg463d0182009-07-14 00:33:35 +02009156 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9157 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009158 return;
9159
9160 nla_put_failure:
9161 genlmsg_cancel(msg, hdr);
9162 nlmsg_free(msg);
9163}
9164
9165void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009166 struct net_device *netdev, const u8 *buf,
9167 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009168{
9169 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009170 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009171}
9172
9173void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9174 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009175 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009176{
Johannes Berge6d6e342009-07-01 21:26:47 +02009177 nl80211_send_mlme_event(rdev, netdev, buf, len,
9178 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009179}
9180
Jouni Malinen53b46b82009-03-27 20:53:56 +02009181void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009182 struct net_device *netdev, const u8 *buf,
9183 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009184{
9185 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009186 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009187}
9188
Jouni Malinen53b46b82009-03-27 20:53:56 +02009189void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9190 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009191 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009192{
9193 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009194 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009195}
9196
Johannes Berg947add32013-02-22 22:05:20 +01009197void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9198 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009199{
Johannes Berg947add32013-02-22 22:05:20 +01009200 struct wireless_dev *wdev = dev->ieee80211_ptr;
9201 struct wiphy *wiphy = wdev->wiphy;
9202 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009203
Johannes Berg947add32013-02-22 22:05:20 +01009204 trace_cfg80211_send_unprot_deauth(dev);
9205 nl80211_send_mlme_event(rdev, dev, buf, len,
9206 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009207}
Johannes Berg947add32013-02-22 22:05:20 +01009208EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9209
9210void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9211 size_t len)
9212{
9213 struct wireless_dev *wdev = dev->ieee80211_ptr;
9214 struct wiphy *wiphy = wdev->wiphy;
9215 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9216
9217 trace_cfg80211_send_unprot_disassoc(dev);
9218 nl80211_send_mlme_event(rdev, dev, buf, len,
9219 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9220}
9221EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009222
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009223static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9224 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009225 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009226{
9227 struct sk_buff *msg;
9228 void *hdr;
9229
Johannes Berge6d6e342009-07-01 21:26:47 +02009230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009231 if (!msg)
9232 return;
9233
9234 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9235 if (!hdr) {
9236 nlmsg_free(msg);
9237 return;
9238 }
9239
David S. Miller9360ffd2012-03-29 04:41:26 -04009240 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9241 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9242 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9243 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9244 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009245
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009246 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009247
Johannes Berg463d0182009-07-14 00:33:35 +02009248 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9249 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009250 return;
9251
9252 nla_put_failure:
9253 genlmsg_cancel(msg, hdr);
9254 nlmsg_free(msg);
9255}
9256
9257void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009258 struct net_device *netdev, const u8 *addr,
9259 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009260{
9261 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009262 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009263}
9264
9265void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009266 struct net_device *netdev, const u8 *addr,
9267 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009268{
Johannes Berge6d6e342009-07-01 21:26:47 +02009269 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9270 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009271}
9272
Samuel Ortizb23aa672009-07-01 21:26:54 +02009273void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9274 struct net_device *netdev, const u8 *bssid,
9275 const u8 *req_ie, size_t req_ie_len,
9276 const u8 *resp_ie, size_t resp_ie_len,
9277 u16 status, gfp_t gfp)
9278{
9279 struct sk_buff *msg;
9280 void *hdr;
9281
Thomas Graf58050fc2012-06-28 03:57:45 +00009282 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009283 if (!msg)
9284 return;
9285
9286 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9287 if (!hdr) {
9288 nlmsg_free(msg);
9289 return;
9290 }
9291
David S. Miller9360ffd2012-03-29 04:41:26 -04009292 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9293 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9294 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9295 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9296 (req_ie &&
9297 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9298 (resp_ie &&
9299 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9300 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009301
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009302 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009303
Johannes Berg463d0182009-07-14 00:33:35 +02009304 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9305 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009306 return;
9307
9308 nla_put_failure:
9309 genlmsg_cancel(msg, hdr);
9310 nlmsg_free(msg);
9311
9312}
9313
9314void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9315 struct net_device *netdev, const u8 *bssid,
9316 const u8 *req_ie, size_t req_ie_len,
9317 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9318{
9319 struct sk_buff *msg;
9320 void *hdr;
9321
Thomas Graf58050fc2012-06-28 03:57:45 +00009322 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009323 if (!msg)
9324 return;
9325
9326 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9327 if (!hdr) {
9328 nlmsg_free(msg);
9329 return;
9330 }
9331
David S. Miller9360ffd2012-03-29 04:41:26 -04009332 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9333 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9334 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9335 (req_ie &&
9336 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9337 (resp_ie &&
9338 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9339 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009340
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009341 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009342
Johannes Berg463d0182009-07-14 00:33:35 +02009343 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9344 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009345 return;
9346
9347 nla_put_failure:
9348 genlmsg_cancel(msg, hdr);
9349 nlmsg_free(msg);
9350
9351}
9352
9353void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9354 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009355 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009356{
9357 struct sk_buff *msg;
9358 void *hdr;
9359
Thomas Graf58050fc2012-06-28 03:57:45 +00009360 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009361 if (!msg)
9362 return;
9363
9364 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9365 if (!hdr) {
9366 nlmsg_free(msg);
9367 return;
9368 }
9369
David S. Miller9360ffd2012-03-29 04:41:26 -04009370 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9371 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9372 (from_ap && reason &&
9373 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9374 (from_ap &&
9375 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9376 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9377 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009378
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009379 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009380
Johannes Berg463d0182009-07-14 00:33:35 +02009381 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9382 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009383 return;
9384
9385 nla_put_failure:
9386 genlmsg_cancel(msg, hdr);
9387 nlmsg_free(msg);
9388
9389}
9390
Johannes Berg04a773a2009-04-19 21:24:32 +02009391void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9392 struct net_device *netdev, const u8 *bssid,
9393 gfp_t gfp)
9394{
9395 struct sk_buff *msg;
9396 void *hdr;
9397
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009398 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009399 if (!msg)
9400 return;
9401
9402 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9403 if (!hdr) {
9404 nlmsg_free(msg);
9405 return;
9406 }
9407
David S. Miller9360ffd2012-03-29 04:41:26 -04009408 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9409 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9410 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9411 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009412
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009413 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009414
Johannes Berg463d0182009-07-14 00:33:35 +02009415 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9416 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009417 return;
9418
9419 nla_put_failure:
9420 genlmsg_cancel(msg, hdr);
9421 nlmsg_free(msg);
9422}
9423
Johannes Berg947add32013-02-22 22:05:20 +01009424void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9425 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009426{
Johannes Berg947add32013-02-22 22:05:20 +01009427 struct wireless_dev *wdev = dev->ieee80211_ptr;
9428 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009429 struct sk_buff *msg;
9430 void *hdr;
9431
Johannes Berg947add32013-02-22 22:05:20 +01009432 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9433 return;
9434
9435 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9436
Javier Cardonac93b5e72011-04-07 15:08:34 -07009437 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9438 if (!msg)
9439 return;
9440
9441 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9442 if (!hdr) {
9443 nlmsg_free(msg);
9444 return;
9445 }
9446
David S. Miller9360ffd2012-03-29 04:41:26 -04009447 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009448 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9449 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009450 (ie_len && ie &&
9451 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9452 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009453
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009454 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009455
9456 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9457 nl80211_mlme_mcgrp.id, gfp);
9458 return;
9459
9460 nla_put_failure:
9461 genlmsg_cancel(msg, hdr);
9462 nlmsg_free(msg);
9463}
Johannes Berg947add32013-02-22 22:05:20 +01009464EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009465
Jouni Malinena3b8b052009-03-27 21:59:49 +02009466void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9467 struct net_device *netdev, const u8 *addr,
9468 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009469 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009470{
9471 struct sk_buff *msg;
9472 void *hdr;
9473
Johannes Berge6d6e342009-07-01 21:26:47 +02009474 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009475 if (!msg)
9476 return;
9477
9478 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9479 if (!hdr) {
9480 nlmsg_free(msg);
9481 return;
9482 }
9483
David S. Miller9360ffd2012-03-29 04:41:26 -04009484 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9485 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9486 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9487 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9488 (key_id != -1 &&
9489 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9490 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9491 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009492
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009493 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009494
Johannes Berg463d0182009-07-14 00:33:35 +02009495 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9496 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009497 return;
9498
9499 nla_put_failure:
9500 genlmsg_cancel(msg, hdr);
9501 nlmsg_free(msg);
9502}
9503
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009504void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9505 struct ieee80211_channel *channel_before,
9506 struct ieee80211_channel *channel_after)
9507{
9508 struct sk_buff *msg;
9509 void *hdr;
9510 struct nlattr *nl_freq;
9511
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009512 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009513 if (!msg)
9514 return;
9515
9516 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9517 if (!hdr) {
9518 nlmsg_free(msg);
9519 return;
9520 }
9521
9522 /*
9523 * Since we are applying the beacon hint to a wiphy we know its
9524 * wiphy_idx is valid
9525 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009526 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9527 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009528
9529 /* Before */
9530 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9531 if (!nl_freq)
9532 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009533 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009534 goto nla_put_failure;
9535 nla_nest_end(msg, nl_freq);
9536
9537 /* After */
9538 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9539 if (!nl_freq)
9540 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009541 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009542 goto nla_put_failure;
9543 nla_nest_end(msg, nl_freq);
9544
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009545 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009546
Johannes Berg463d0182009-07-14 00:33:35 +02009547 rcu_read_lock();
9548 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9549 GFP_ATOMIC);
9550 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009551
9552 return;
9553
9554nla_put_failure:
9555 genlmsg_cancel(msg, hdr);
9556 nlmsg_free(msg);
9557}
9558
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009559static void nl80211_send_remain_on_chan_event(
9560 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009561 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009562 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009563 unsigned int duration, gfp_t gfp)
9564{
9565 struct sk_buff *msg;
9566 void *hdr;
9567
9568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9569 if (!msg)
9570 return;
9571
9572 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9573 if (!hdr) {
9574 nlmsg_free(msg);
9575 return;
9576 }
9577
David S. Miller9360ffd2012-03-29 04:41:26 -04009578 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009579 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9580 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009581 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009582 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009583 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9584 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009585 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9586 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009587
David S. Miller9360ffd2012-03-29 04:41:26 -04009588 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9589 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9590 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009591
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009592 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009593
9594 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9595 nl80211_mlme_mcgrp.id, gfp);
9596 return;
9597
9598 nla_put_failure:
9599 genlmsg_cancel(msg, hdr);
9600 nlmsg_free(msg);
9601}
9602
Johannes Berg947add32013-02-22 22:05:20 +01009603void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9604 struct ieee80211_channel *chan,
9605 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009606{
Johannes Berg947add32013-02-22 22:05:20 +01009607 struct wiphy *wiphy = wdev->wiphy;
9608 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9609
9610 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009611 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009612 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009613 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009614}
Johannes Berg947add32013-02-22 22:05:20 +01009615EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009616
Johannes Berg947add32013-02-22 22:05:20 +01009617void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9618 struct ieee80211_channel *chan,
9619 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009620{
Johannes Berg947add32013-02-22 22:05:20 +01009621 struct wiphy *wiphy = wdev->wiphy;
9622 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9623
9624 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009625 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009626 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009627}
Johannes Berg947add32013-02-22 22:05:20 +01009628EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009629
Johannes Berg947add32013-02-22 22:05:20 +01009630void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9631 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009632{
Johannes Berg947add32013-02-22 22:05:20 +01009633 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9634 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009635 struct sk_buff *msg;
9636
Johannes Berg947add32013-02-22 22:05:20 +01009637 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9638
Thomas Graf58050fc2012-06-28 03:57:45 +00009639 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009640 if (!msg)
9641 return;
9642
John W. Linville66266b32012-03-15 13:25:41 -04009643 if (nl80211_send_station(msg, 0, 0, 0,
9644 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009645 nlmsg_free(msg);
9646 return;
9647 }
9648
9649 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9650 nl80211_mlme_mcgrp.id, gfp);
9651}
Johannes Berg947add32013-02-22 22:05:20 +01009652EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009653
Johannes Berg947add32013-02-22 22:05:20 +01009654void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009655{
Johannes Berg947add32013-02-22 22:05:20 +01009656 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9657 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009658 struct sk_buff *msg;
9659 void *hdr;
9660
Johannes Berg947add32013-02-22 22:05:20 +01009661 trace_cfg80211_del_sta(dev, mac_addr);
9662
Thomas Graf58050fc2012-06-28 03:57:45 +00009663 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009664 if (!msg)
9665 return;
9666
9667 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9668 if (!hdr) {
9669 nlmsg_free(msg);
9670 return;
9671 }
9672
David S. Miller9360ffd2012-03-29 04:41:26 -04009673 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9674 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9675 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009676
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009677 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009678
9679 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9680 nl80211_mlme_mcgrp.id, gfp);
9681 return;
9682
9683 nla_put_failure:
9684 genlmsg_cancel(msg, hdr);
9685 nlmsg_free(msg);
9686}
Johannes Berg947add32013-02-22 22:05:20 +01009687EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009688
Johannes Berg947add32013-02-22 22:05:20 +01009689void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9690 enum nl80211_connect_failed_reason reason,
9691 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309692{
Johannes Berg947add32013-02-22 22:05:20 +01009693 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9694 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309695 struct sk_buff *msg;
9696 void *hdr;
9697
9698 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9699 if (!msg)
9700 return;
9701
9702 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9703 if (!hdr) {
9704 nlmsg_free(msg);
9705 return;
9706 }
9707
9708 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9709 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9710 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9711 goto nla_put_failure;
9712
9713 genlmsg_end(msg, hdr);
9714
9715 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9716 nl80211_mlme_mcgrp.id, gfp);
9717 return;
9718
9719 nla_put_failure:
9720 genlmsg_cancel(msg, hdr);
9721 nlmsg_free(msg);
9722}
Johannes Berg947add32013-02-22 22:05:20 +01009723EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309724
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009725static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9726 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009727{
9728 struct wireless_dev *wdev = dev->ieee80211_ptr;
9729 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9730 struct sk_buff *msg;
9731 void *hdr;
9732 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009733 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009734
Eric W. Biederman15e47302012-09-07 20:12:54 +00009735 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009736 return false;
9737
9738 msg = nlmsg_new(100, gfp);
9739 if (!msg)
9740 return true;
9741
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009742 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009743 if (!hdr) {
9744 nlmsg_free(msg);
9745 return true;
9746 }
9747
David S. Miller9360ffd2012-03-29 04:41:26 -04009748 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9749 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9750 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9751 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009752
9753 err = genlmsg_end(msg, hdr);
9754 if (err < 0) {
9755 nlmsg_free(msg);
9756 return true;
9757 }
9758
Eric W. Biederman15e47302012-09-07 20:12:54 +00009759 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009760 return true;
9761
9762 nla_put_failure:
9763 genlmsg_cancel(msg, hdr);
9764 nlmsg_free(msg);
9765 return true;
9766}
9767
Johannes Berg947add32013-02-22 22:05:20 +01009768bool cfg80211_rx_spurious_frame(struct net_device *dev,
9769 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009770{
Johannes Berg947add32013-02-22 22:05:20 +01009771 struct wireless_dev *wdev = dev->ieee80211_ptr;
9772 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009773
Johannes Berg947add32013-02-22 22:05:20 +01009774 trace_cfg80211_rx_spurious_frame(dev, addr);
9775
9776 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9777 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9778 trace_cfg80211_return_bool(false);
9779 return false;
9780 }
9781 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9782 addr, gfp);
9783 trace_cfg80211_return_bool(ret);
9784 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009785}
Johannes Berg947add32013-02-22 22:05:20 +01009786EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9787
9788bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9789 const u8 *addr, gfp_t gfp)
9790{
9791 struct wireless_dev *wdev = dev->ieee80211_ptr;
9792 bool ret;
9793
9794 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9795
9796 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9797 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9798 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9799 trace_cfg80211_return_bool(false);
9800 return false;
9801 }
9802 ret = __nl80211_unexpected_frame(dev,
9803 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9804 addr, gfp);
9805 trace_cfg80211_return_bool(ret);
9806 return ret;
9807}
9808EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009809
Johannes Berg2e161f72010-08-12 15:38:38 +02009810int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009811 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009812 int freq, int sig_dbm,
9813 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009814{
Johannes Berg71bbc992012-06-15 15:30:18 +02009815 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009816 struct sk_buff *msg;
9817 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009818
9819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9820 if (!msg)
9821 return -ENOMEM;
9822
Johannes Berg2e161f72010-08-12 15:38:38 +02009823 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009824 if (!hdr) {
9825 nlmsg_free(msg);
9826 return -ENOMEM;
9827 }
9828
David S. Miller9360ffd2012-03-29 04:41:26 -04009829 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009830 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9831 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009832 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9833 (sig_dbm &&
9834 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9835 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9836 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009837
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009838 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009839
Eric W. Biederman15e47302012-09-07 20:12:54 +00009840 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009841
9842 nla_put_failure:
9843 genlmsg_cancel(msg, hdr);
9844 nlmsg_free(msg);
9845 return -ENOBUFS;
9846}
9847
Johannes Berg947add32013-02-22 22:05:20 +01009848void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9849 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009850{
Johannes Berg947add32013-02-22 22:05:20 +01009851 struct wiphy *wiphy = wdev->wiphy;
9852 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009853 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009854 struct sk_buff *msg;
9855 void *hdr;
9856
Johannes Berg947add32013-02-22 22:05:20 +01009857 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9858
Jouni Malinen026331c2010-02-15 12:53:10 +02009859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9860 if (!msg)
9861 return;
9862
Johannes Berg2e161f72010-08-12 15:38:38 +02009863 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009864 if (!hdr) {
9865 nlmsg_free(msg);
9866 return;
9867 }
9868
David S. Miller9360ffd2012-03-29 04:41:26 -04009869 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009870 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9871 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009872 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9873 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9874 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9875 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009876
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009877 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009878
9879 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9880 return;
9881
9882 nla_put_failure:
9883 genlmsg_cancel(msg, hdr);
9884 nlmsg_free(msg);
9885}
Johannes Berg947add32013-02-22 22:05:20 +01009886EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009887
Johannes Berg947add32013-02-22 22:05:20 +01009888void cfg80211_cqm_rssi_notify(struct net_device *dev,
9889 enum nl80211_cqm_rssi_threshold_event rssi_event,
9890 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009891{
Johannes Berg947add32013-02-22 22:05:20 +01009892 struct wireless_dev *wdev = dev->ieee80211_ptr;
9893 struct wiphy *wiphy = wdev->wiphy;
9894 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009895 struct sk_buff *msg;
9896 struct nlattr *pinfoattr;
9897 void *hdr;
9898
Johannes Berg947add32013-02-22 22:05:20 +01009899 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
9900
Thomas Graf58050fc2012-06-28 03:57:45 +00009901 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009902 if (!msg)
9903 return;
9904
9905 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9906 if (!hdr) {
9907 nlmsg_free(msg);
9908 return;
9909 }
9910
David S. Miller9360ffd2012-03-29 04:41:26 -04009911 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009912 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -04009913 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009914
9915 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9916 if (!pinfoattr)
9917 goto nla_put_failure;
9918
David S. Miller9360ffd2012-03-29 04:41:26 -04009919 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9920 rssi_event))
9921 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009922
9923 nla_nest_end(msg, pinfoattr);
9924
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009925 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009926
9927 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9928 nl80211_mlme_mcgrp.id, gfp);
9929 return;
9930
9931 nla_put_failure:
9932 genlmsg_cancel(msg, hdr);
9933 nlmsg_free(msg);
9934}
Johannes Berg947add32013-02-22 22:05:20 +01009935EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009936
Johannes Berg947add32013-02-22 22:05:20 +01009937static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9938 struct net_device *netdev, const u8 *bssid,
9939 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +02009940{
9941 struct sk_buff *msg;
9942 struct nlattr *rekey_attr;
9943 void *hdr;
9944
Thomas Graf58050fc2012-06-28 03:57:45 +00009945 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009946 if (!msg)
9947 return;
9948
9949 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9950 if (!hdr) {
9951 nlmsg_free(msg);
9952 return;
9953 }
9954
David S. Miller9360ffd2012-03-29 04:41:26 -04009955 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9956 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9957 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9958 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009959
9960 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9961 if (!rekey_attr)
9962 goto nla_put_failure;
9963
David S. Miller9360ffd2012-03-29 04:41:26 -04009964 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9965 NL80211_REPLAY_CTR_LEN, replay_ctr))
9966 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009967
9968 nla_nest_end(msg, rekey_attr);
9969
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009970 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02009971
9972 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9973 nl80211_mlme_mcgrp.id, gfp);
9974 return;
9975
9976 nla_put_failure:
9977 genlmsg_cancel(msg, hdr);
9978 nlmsg_free(msg);
9979}
9980
Johannes Berg947add32013-02-22 22:05:20 +01009981void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
9982 const u8 *replay_ctr, gfp_t gfp)
9983{
9984 struct wireless_dev *wdev = dev->ieee80211_ptr;
9985 struct wiphy *wiphy = wdev->wiphy;
9986 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9987
9988 trace_cfg80211_gtk_rekey_notify(dev, bssid);
9989 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
9990}
9991EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
9992
9993static void
9994nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
9995 struct net_device *netdev, int index,
9996 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009997{
9998 struct sk_buff *msg;
9999 struct nlattr *attr;
10000 void *hdr;
10001
Thomas Graf58050fc2012-06-28 03:57:45 +000010002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010003 if (!msg)
10004 return;
10005
10006 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10007 if (!hdr) {
10008 nlmsg_free(msg);
10009 return;
10010 }
10011
David S. Miller9360ffd2012-03-29 04:41:26 -040010012 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10013 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10014 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010015
10016 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10017 if (!attr)
10018 goto nla_put_failure;
10019
David S. Miller9360ffd2012-03-29 04:41:26 -040010020 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10021 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10022 (preauth &&
10023 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10024 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010025
10026 nla_nest_end(msg, attr);
10027
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010028 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010029
10030 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10031 nl80211_mlme_mcgrp.id, gfp);
10032 return;
10033
10034 nla_put_failure:
10035 genlmsg_cancel(msg, hdr);
10036 nlmsg_free(msg);
10037}
10038
Johannes Berg947add32013-02-22 22:05:20 +010010039void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10040 const u8 *bssid, bool preauth, gfp_t gfp)
10041{
10042 struct wireless_dev *wdev = dev->ieee80211_ptr;
10043 struct wiphy *wiphy = wdev->wiphy;
10044 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10045
10046 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10047 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10048}
10049EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10050
10051static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10052 struct net_device *netdev,
10053 struct cfg80211_chan_def *chandef,
10054 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010055{
10056 struct sk_buff *msg;
10057 void *hdr;
10058
Thomas Graf58050fc2012-06-28 03:57:45 +000010059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010060 if (!msg)
10061 return;
10062
10063 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10064 if (!hdr) {
10065 nlmsg_free(msg);
10066 return;
10067 }
10068
Johannes Berg683b6d32012-11-08 21:25:48 +010010069 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10070 goto nla_put_failure;
10071
10072 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010073 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010074
10075 genlmsg_end(msg, hdr);
10076
10077 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10078 nl80211_mlme_mcgrp.id, gfp);
10079 return;
10080
10081 nla_put_failure:
10082 genlmsg_cancel(msg, hdr);
10083 nlmsg_free(msg);
10084}
10085
Johannes Berg947add32013-02-22 22:05:20 +010010086void cfg80211_ch_switch_notify(struct net_device *dev,
10087 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010088{
Johannes Berg947add32013-02-22 22:05:20 +010010089 struct wireless_dev *wdev = dev->ieee80211_ptr;
10090 struct wiphy *wiphy = wdev->wiphy;
10091 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10092
10093 trace_cfg80211_ch_switch_notify(dev, chandef);
10094
10095 wdev_lock(wdev);
10096
10097 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10098 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10099 goto out;
10100
10101 wdev->channel = chandef->chan;
10102 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10103out:
10104 wdev_unlock(wdev);
10105 return;
10106}
10107EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10108
10109void cfg80211_cqm_txe_notify(struct net_device *dev,
10110 const u8 *peer, u32 num_packets,
10111 u32 rate, u32 intvl, gfp_t gfp)
10112{
10113 struct wireless_dev *wdev = dev->ieee80211_ptr;
10114 struct wiphy *wiphy = wdev->wiphy;
10115 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010116 struct sk_buff *msg;
10117 struct nlattr *pinfoattr;
10118 void *hdr;
10119
10120 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10121 if (!msg)
10122 return;
10123
10124 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10125 if (!hdr) {
10126 nlmsg_free(msg);
10127 return;
10128 }
10129
10130 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010131 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010132 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10133 goto nla_put_failure;
10134
10135 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10136 if (!pinfoattr)
10137 goto nla_put_failure;
10138
10139 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10140 goto nla_put_failure;
10141
10142 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10143 goto nla_put_failure;
10144
10145 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10146 goto nla_put_failure;
10147
10148 nla_nest_end(msg, pinfoattr);
10149
10150 genlmsg_end(msg, hdr);
10151
10152 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10153 nl80211_mlme_mcgrp.id, gfp);
10154 return;
10155
10156 nla_put_failure:
10157 genlmsg_cancel(msg, hdr);
10158 nlmsg_free(msg);
10159}
Johannes Berg947add32013-02-22 22:05:20 +010010160EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010161
10162void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010163nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10164 struct cfg80211_chan_def *chandef,
10165 enum nl80211_radar_event event,
10166 struct net_device *netdev, gfp_t gfp)
10167{
10168 struct sk_buff *msg;
10169 void *hdr;
10170
10171 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10172 if (!msg)
10173 return;
10174
10175 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10176 if (!hdr) {
10177 nlmsg_free(msg);
10178 return;
10179 }
10180
10181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10182 goto nla_put_failure;
10183
10184 /* NOP and radar events don't need a netdev parameter */
10185 if (netdev) {
10186 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10187
10188 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10189 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10190 goto nla_put_failure;
10191 }
10192
10193 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10194 goto nla_put_failure;
10195
10196 if (nl80211_send_chandef(msg, chandef))
10197 goto nla_put_failure;
10198
10199 if (genlmsg_end(msg, hdr) < 0) {
10200 nlmsg_free(msg);
10201 return;
10202 }
10203
10204 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10205 nl80211_mlme_mcgrp.id, gfp);
10206 return;
10207
10208 nla_put_failure:
10209 genlmsg_cancel(msg, hdr);
10210 nlmsg_free(msg);
10211}
10212
Johannes Berg947add32013-02-22 22:05:20 +010010213void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10214 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010215{
Johannes Berg947add32013-02-22 22:05:20 +010010216 struct wireless_dev *wdev = dev->ieee80211_ptr;
10217 struct wiphy *wiphy = wdev->wiphy;
10218 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010219 struct sk_buff *msg;
10220 struct nlattr *pinfoattr;
10221 void *hdr;
10222
Johannes Berg947add32013-02-22 22:05:20 +010010223 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10224
Thomas Graf58050fc2012-06-28 03:57:45 +000010225 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010226 if (!msg)
10227 return;
10228
10229 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10230 if (!hdr) {
10231 nlmsg_free(msg);
10232 return;
10233 }
10234
David S. Miller9360ffd2012-03-29 04:41:26 -040010235 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010236 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010237 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10238 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010239
10240 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10241 if (!pinfoattr)
10242 goto nla_put_failure;
10243
David S. Miller9360ffd2012-03-29 04:41:26 -040010244 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10245 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010246
10247 nla_nest_end(msg, pinfoattr);
10248
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010249 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010250
10251 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10252 nl80211_mlme_mcgrp.id, gfp);
10253 return;
10254
10255 nla_put_failure:
10256 genlmsg_cancel(msg, hdr);
10257 nlmsg_free(msg);
10258}
Johannes Berg947add32013-02-22 22:05:20 +010010259EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010260
Johannes Berg7f6cf312011-11-04 11:18:15 +010010261void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10262 u64 cookie, bool acked, gfp_t gfp)
10263{
10264 struct wireless_dev *wdev = dev->ieee80211_ptr;
10265 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10266 struct sk_buff *msg;
10267 void *hdr;
10268 int err;
10269
Beni Lev4ee3e062012-08-27 12:49:39 +030010270 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10271
Thomas Graf58050fc2012-06-28 03:57:45 +000010272 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010273
Johannes Berg7f6cf312011-11-04 11:18:15 +010010274 if (!msg)
10275 return;
10276
10277 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10278 if (!hdr) {
10279 nlmsg_free(msg);
10280 return;
10281 }
10282
David S. Miller9360ffd2012-03-29 04:41:26 -040010283 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10284 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10285 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10286 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10287 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10288 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010289
10290 err = genlmsg_end(msg, hdr);
10291 if (err < 0) {
10292 nlmsg_free(msg);
10293 return;
10294 }
10295
10296 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10297 nl80211_mlme_mcgrp.id, gfp);
10298 return;
10299
10300 nla_put_failure:
10301 genlmsg_cancel(msg, hdr);
10302 nlmsg_free(msg);
10303}
10304EXPORT_SYMBOL(cfg80211_probe_status);
10305
Johannes Berg5e760232011-11-04 11:18:17 +010010306void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10307 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010308 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010309{
10310 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10311 struct sk_buff *msg;
10312 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010313 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010314
Beni Lev4ee3e062012-08-27 12:49:39 +030010315 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10316
Ben Greear37c73b52012-10-26 14:49:25 -070010317 spin_lock_bh(&rdev->beacon_registrations_lock);
10318 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10319 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10320 if (!msg) {
10321 spin_unlock_bh(&rdev->beacon_registrations_lock);
10322 return;
10323 }
Johannes Berg5e760232011-11-04 11:18:17 +010010324
Ben Greear37c73b52012-10-26 14:49:25 -070010325 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10326 if (!hdr)
10327 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010328
Ben Greear37c73b52012-10-26 14:49:25 -070010329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10330 (freq &&
10331 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10332 (sig_dbm &&
10333 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10334 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10335 goto nla_put_failure;
10336
10337 genlmsg_end(msg, hdr);
10338
10339 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010340 }
Ben Greear37c73b52012-10-26 14:49:25 -070010341 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010342 return;
10343
10344 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010345 spin_unlock_bh(&rdev->beacon_registrations_lock);
10346 if (hdr)
10347 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010348 nlmsg_free(msg);
10349}
10350EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10351
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010352#ifdef CONFIG_PM
10353void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10354 struct cfg80211_wowlan_wakeup *wakeup,
10355 gfp_t gfp)
10356{
10357 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10358 struct sk_buff *msg;
10359 void *hdr;
10360 int err, size = 200;
10361
10362 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10363
10364 if (wakeup)
10365 size += wakeup->packet_present_len;
10366
10367 msg = nlmsg_new(size, gfp);
10368 if (!msg)
10369 return;
10370
10371 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10372 if (!hdr)
10373 goto free_msg;
10374
10375 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10376 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10377 goto free_msg;
10378
10379 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10380 wdev->netdev->ifindex))
10381 goto free_msg;
10382
10383 if (wakeup) {
10384 struct nlattr *reasons;
10385
10386 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10387
10388 if (wakeup->disconnect &&
10389 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10390 goto free_msg;
10391 if (wakeup->magic_pkt &&
10392 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10393 goto free_msg;
10394 if (wakeup->gtk_rekey_failure &&
10395 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10396 goto free_msg;
10397 if (wakeup->eap_identity_req &&
10398 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10399 goto free_msg;
10400 if (wakeup->four_way_handshake &&
10401 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10402 goto free_msg;
10403 if (wakeup->rfkill_release &&
10404 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10405 goto free_msg;
10406
10407 if (wakeup->pattern_idx >= 0 &&
10408 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10409 wakeup->pattern_idx))
10410 goto free_msg;
10411
Johannes Berg2a0e0472013-01-23 22:57:40 +010010412 if (wakeup->tcp_match)
10413 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10414
10415 if (wakeup->tcp_connlost)
10416 nla_put_flag(msg,
10417 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10418
10419 if (wakeup->tcp_nomoretokens)
10420 nla_put_flag(msg,
10421 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10422
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010423 if (wakeup->packet) {
10424 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10425 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10426
10427 if (!wakeup->packet_80211) {
10428 pkt_attr =
10429 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10430 len_attr =
10431 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10432 }
10433
10434 if (wakeup->packet_len &&
10435 nla_put_u32(msg, len_attr, wakeup->packet_len))
10436 goto free_msg;
10437
10438 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10439 wakeup->packet))
10440 goto free_msg;
10441 }
10442
10443 nla_nest_end(msg, reasons);
10444 }
10445
10446 err = genlmsg_end(msg, hdr);
10447 if (err < 0)
10448 goto free_msg;
10449
10450 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10451 nl80211_mlme_mcgrp.id, gfp);
10452 return;
10453
10454 free_msg:
10455 nlmsg_free(msg);
10456}
10457EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10458#endif
10459
Jouni Malinen3475b092012-11-16 22:49:57 +020010460void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10461 enum nl80211_tdls_operation oper,
10462 u16 reason_code, gfp_t gfp)
10463{
10464 struct wireless_dev *wdev = dev->ieee80211_ptr;
10465 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10466 struct sk_buff *msg;
10467 void *hdr;
10468 int err;
10469
10470 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10471 reason_code);
10472
10473 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10474 if (!msg)
10475 return;
10476
10477 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10478 if (!hdr) {
10479 nlmsg_free(msg);
10480 return;
10481 }
10482
10483 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10484 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10485 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10486 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10487 (reason_code > 0 &&
10488 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10489 goto nla_put_failure;
10490
10491 err = genlmsg_end(msg, hdr);
10492 if (err < 0) {
10493 nlmsg_free(msg);
10494 return;
10495 }
10496
10497 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10498 nl80211_mlme_mcgrp.id, gfp);
10499 return;
10500
10501 nla_put_failure:
10502 genlmsg_cancel(msg, hdr);
10503 nlmsg_free(msg);
10504}
10505EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10506
Jouni Malinen026331c2010-02-15 12:53:10 +020010507static int nl80211_netlink_notify(struct notifier_block * nb,
10508 unsigned long state,
10509 void *_notify)
10510{
10511 struct netlink_notify *notify = _notify;
10512 struct cfg80211_registered_device *rdev;
10513 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010514 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010515
10516 if (state != NETLINK_URELEASE)
10517 return NOTIFY_DONE;
10518
10519 rcu_read_lock();
10520
Johannes Berg5e760232011-11-04 11:18:17 +010010521 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010522 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010523 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010524
10525 spin_lock_bh(&rdev->beacon_registrations_lock);
10526 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10527 list) {
10528 if (reg->nlportid == notify->portid) {
10529 list_del(&reg->list);
10530 kfree(reg);
10531 break;
10532 }
10533 }
10534 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010535 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010536
10537 rcu_read_unlock();
10538
10539 return NOTIFY_DONE;
10540}
10541
10542static struct notifier_block nl80211_netlink_notifier = {
10543 .notifier_call = nl80211_netlink_notify,
10544};
10545
Johannes Berg55682962007-09-20 13:09:35 -040010546/* initialisation/exit functions */
10547
10548int nl80211_init(void)
10549{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010550 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010551
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010552 err = genl_register_family_with_ops(&nl80211_fam,
10553 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010554 if (err)
10555 return err;
10556
Johannes Berg55682962007-09-20 13:09:35 -040010557 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10558 if (err)
10559 goto err_out;
10560
Johannes Berg2a519312009-02-10 21:25:55 +010010561 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10562 if (err)
10563 goto err_out;
10564
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010565 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10566 if (err)
10567 goto err_out;
10568
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010569 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10570 if (err)
10571 goto err_out;
10572
Johannes Bergaff89a92009-07-01 21:26:51 +020010573#ifdef CONFIG_NL80211_TESTMODE
10574 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10575 if (err)
10576 goto err_out;
10577#endif
10578
Jouni Malinen026331c2010-02-15 12:53:10 +020010579 err = netlink_register_notifier(&nl80211_netlink_notifier);
10580 if (err)
10581 goto err_out;
10582
Johannes Berg55682962007-09-20 13:09:35 -040010583 return 0;
10584 err_out:
10585 genl_unregister_family(&nl80211_fam);
10586 return err;
10587}
10588
10589void nl80211_exit(void)
10590{
Jouni Malinen026331c2010-02-15 12:53:10 +020010591 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010592 genl_unregister_family(&nl80211_fam);
10593}