blob: 08de0c6035f1ca88255d8f7f93583dc9a68416b1 [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 Malinendc6382ce2009-05-06 22:09:37 +0300301 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300302 [NL80211_ATTR_STA_FLAGS2] = {
303 .len = sizeof(struct nl80211_sta_flag_update),
304 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300305 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200308 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
309 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
310 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200311 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100312 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100313 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
314 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100315 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
316 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200317 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200318 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
319 .len = IEEE80211_MAX_DATA_LEN },
320 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200321 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200322 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300323 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200324 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200327 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900328 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
329 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100330 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100331 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100332 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200333 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700334 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300335 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200336 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200337 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300338 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300339 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
340 .len = IEEE80211_MAX_DATA_LEN },
341 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530343 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300344 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530345 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300346 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
348 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
349 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100351 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200352 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
353 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700354 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800355 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
356 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
357 .len = NL80211_HT_CAPABILITY_LEN
358 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100359 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530360 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530361 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200362 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700363 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300364 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000365 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700366 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100367 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
368 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530369 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
370 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200371 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
372 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100373 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100374 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
375 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
376 .len = NL80211_VHT_CAPABILITY_LEN,
377 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200378 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
379 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
380 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg55682962007-09-20 13:09:35 -0400381};
382
Johannes Berge31b8212010-10-05 19:39:30 +0200383/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000384static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200385 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200386 [NL80211_KEY_IDX] = { .type = NLA_U8 },
387 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200388 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200389 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
390 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200391 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100392 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
393};
394
395/* policy for the key default flags */
396static const struct nla_policy
397nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
398 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
399 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200400};
401
Johannes Bergff1b6e62011-05-04 15:37:28 +0200402/* policy for WoWLAN attributes */
403static const struct nla_policy
404nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
405 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
406 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
407 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
408 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200409 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
410 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
411 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
412 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100413 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
414};
415
416static const struct nla_policy
417nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
418 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
419 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
420 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
421 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
422 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
423 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
424 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
425 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
426 },
427 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
428 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
429 },
430 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
431 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
432 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200433};
434
Johannes Berge5497d72011-07-05 16:35:40 +0200435/* policy for GTK rekey offload attributes */
436static const struct nla_policy
437nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
438 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
439 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
440 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
441};
442
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300443static const struct nla_policy
444nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200445 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300446 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700447 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300448};
449
Holger Schuriga0438972009-11-11 11:30:02 +0100450/* ifidx get helper */
451static int nl80211_get_ifidx(struct netlink_callback *cb)
452{
453 int res;
454
455 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
456 nl80211_fam.attrbuf, nl80211_fam.maxattr,
457 nl80211_policy);
458 if (res)
459 return res;
460
461 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
462 return -EINVAL;
463
464 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
465 if (!res)
466 return -EINVAL;
467 return res;
468}
469
Johannes Berg67748892010-10-04 21:14:06 +0200470static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
471 struct netlink_callback *cb,
472 struct cfg80211_registered_device **rdev,
473 struct net_device **dev)
474{
475 int ifidx = cb->args[0];
476 int err;
477
478 if (!ifidx)
479 ifidx = nl80211_get_ifidx(cb);
480 if (ifidx < 0)
481 return ifidx;
482
483 cb->args[0] = ifidx;
484
485 rtnl_lock();
486
487 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
488 if (!*dev) {
489 err = -ENODEV;
490 goto out_rtnl;
491 }
492
493 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100494 if (IS_ERR(*rdev)) {
495 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200496 goto out_rtnl;
497 }
498
499 return 0;
500 out_rtnl:
501 rtnl_unlock();
502 return err;
503}
504
505static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
506{
507 cfg80211_unlock_rdev(rdev);
508 rtnl_unlock();
509}
510
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100511/* IE validation */
512static bool is_valid_ie_attr(const struct nlattr *attr)
513{
514 const u8 *pos;
515 int len;
516
517 if (!attr)
518 return true;
519
520 pos = nla_data(attr);
521 len = nla_len(attr);
522
523 while (len) {
524 u8 elemlen;
525
526 if (len < 2)
527 return false;
528 len -= 2;
529
530 elemlen = pos[1];
531 if (elemlen > len)
532 return false;
533
534 len -= elemlen;
535 pos += 2 + elemlen;
536 }
537
538 return true;
539}
540
Johannes Berg55682962007-09-20 13:09:35 -0400541/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000542static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400543 int flags, u8 cmd)
544{
545 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000546 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400547}
548
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400549static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100550 struct ieee80211_channel *chan,
551 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400552{
David S. Miller9360ffd2012-03-29 04:41:26 -0400553 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
554 chan->center_freq))
555 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400556
David S. Miller9360ffd2012-03-29 04:41:26 -0400557 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
565 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100566 if (chan->flags & IEEE80211_CHAN_RADAR) {
567 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
568 goto nla_put_failure;
569 if (large) {
570 u32 time;
571
572 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
573
574 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
575 chan->dfs_state))
576 goto nla_put_failure;
577 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
578 time))
579 goto nla_put_failure;
580 }
581 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400582
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100583 if (large) {
584 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
585 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
586 goto nla_put_failure;
587 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
588 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
589 goto nla_put_failure;
590 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
591 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
592 goto nla_put_failure;
593 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
594 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
595 goto nla_put_failure;
596 }
597
David S. Miller9360ffd2012-03-29 04:41:26 -0400598 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
599 DBM_TO_MBM(chan->max_power)))
600 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400601
602 return 0;
603
604 nla_put_failure:
605 return -ENOBUFS;
606}
607
Johannes Berg55682962007-09-20 13:09:35 -0400608/* netlink command implementations */
609
Johannes Bergb9454e82009-07-08 13:29:08 +0200610struct key_parse {
611 struct key_params p;
612 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200613 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100615 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200616};
617
618static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
619{
620 struct nlattr *tb[NL80211_KEY_MAX + 1];
621 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
622 nl80211_key_policy);
623 if (err)
624 return err;
625
626 k->def = !!tb[NL80211_KEY_DEFAULT];
627 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
628
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100629 if (k->def) {
630 k->def_uni = true;
631 k->def_multi = true;
632 }
633 if (k->defmgmt)
634 k->def_multi = true;
635
Johannes Bergb9454e82009-07-08 13:29:08 +0200636 if (tb[NL80211_KEY_IDX])
637 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
638
639 if (tb[NL80211_KEY_DATA]) {
640 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
641 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
642 }
643
644 if (tb[NL80211_KEY_SEQ]) {
645 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
646 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
647 }
648
649 if (tb[NL80211_KEY_CIPHER])
650 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
651
Johannes Berge31b8212010-10-05 19:39:30 +0200652 if (tb[NL80211_KEY_TYPE]) {
653 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
654 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
655 return -EINVAL;
656 }
657
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100658 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
659 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100660 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
661 tb[NL80211_KEY_DEFAULT_TYPES],
662 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100663 if (err)
664 return err;
665
666 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
667 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
668 }
669
Johannes Bergb9454e82009-07-08 13:29:08 +0200670 return 0;
671}
672
673static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
674{
675 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
676 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
677 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
678 }
679
680 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
681 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
682 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
683 }
684
685 if (info->attrs[NL80211_ATTR_KEY_IDX])
686 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
687
688 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
689 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
690
691 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
692 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
693
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100694 if (k->def) {
695 k->def_uni = true;
696 k->def_multi = true;
697 }
698 if (k->defmgmt)
699 k->def_multi = true;
700
Johannes Berge31b8212010-10-05 19:39:30 +0200701 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
702 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
703 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
704 return -EINVAL;
705 }
706
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100707 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
708 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
709 int err = nla_parse_nested(
710 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
711 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
712 nl80211_key_default_policy);
713 if (err)
714 return err;
715
716 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
717 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
718 }
719
Johannes Bergb9454e82009-07-08 13:29:08 +0200720 return 0;
721}
722
723static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
724{
725 int err;
726
727 memset(k, 0, sizeof(*k));
728 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200729 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200730
731 if (info->attrs[NL80211_ATTR_KEY])
732 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
733 else
734 err = nl80211_parse_key_old(info, k);
735
736 if (err)
737 return err;
738
739 if (k->def && k->defmgmt)
740 return -EINVAL;
741
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100742 if (k->defmgmt) {
743 if (k->def_uni || !k->def_multi)
744 return -EINVAL;
745 }
746
Johannes Bergb9454e82009-07-08 13:29:08 +0200747 if (k->idx != -1) {
748 if (k->defmgmt) {
749 if (k->idx < 4 || k->idx > 5)
750 return -EINVAL;
751 } else if (k->def) {
752 if (k->idx < 0 || k->idx > 3)
753 return -EINVAL;
754 } else {
755 if (k->idx < 0 || k->idx > 5)
756 return -EINVAL;
757 }
758 }
759
760 return 0;
761}
762
Johannes Bergfffd0932009-07-08 14:22:54 +0200763static struct cfg80211_cached_keys *
764nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530765 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200766{
767 struct key_parse parse;
768 struct nlattr *key;
769 struct cfg80211_cached_keys *result;
770 int rem, err, def = 0;
771
772 result = kzalloc(sizeof(*result), GFP_KERNEL);
773 if (!result)
774 return ERR_PTR(-ENOMEM);
775
776 result->def = -1;
777 result->defmgmt = -1;
778
779 nla_for_each_nested(key, keys, rem) {
780 memset(&parse, 0, sizeof(parse));
781 parse.idx = -1;
782
783 err = nl80211_parse_key_new(key, &parse);
784 if (err)
785 goto error;
786 err = -EINVAL;
787 if (!parse.p.key)
788 goto error;
789 if (parse.idx < 0 || parse.idx > 4)
790 goto error;
791 if (parse.def) {
792 if (def)
793 goto error;
794 def = 1;
795 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100796 if (!parse.def_uni || !parse.def_multi)
797 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200798 } else if (parse.defmgmt)
799 goto error;
800 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200801 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200802 if (err)
803 goto error;
804 result->params[parse.idx].cipher = parse.p.cipher;
805 result->params[parse.idx].key_len = parse.p.key_len;
806 result->params[parse.idx].key = result->data[parse.idx];
807 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530808
809 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
810 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
811 if (no_ht)
812 *no_ht = true;
813 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200814 }
815
816 return result;
817 error:
818 kfree(result);
819 return ERR_PTR(err);
820}
821
822static int nl80211_key_allowed(struct wireless_dev *wdev)
823{
824 ASSERT_WDEV_LOCK(wdev);
825
Johannes Bergfffd0932009-07-08 14:22:54 +0200826 switch (wdev->iftype) {
827 case NL80211_IFTYPE_AP:
828 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200829 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700830 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200831 break;
832 case NL80211_IFTYPE_ADHOC:
833 if (!wdev->current_bss)
834 return -ENOLINK;
835 break;
836 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200837 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200838 if (wdev->sme_state != CFG80211_SME_CONNECTED)
839 return -ENOLINK;
840 break;
841 default:
842 return -EINVAL;
843 }
844
845 return 0;
846}
847
Johannes Berg7527a782011-05-13 10:58:57 +0200848static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
849{
850 struct nlattr *nl_modes = nla_nest_start(msg, attr);
851 int i;
852
853 if (!nl_modes)
854 goto nla_put_failure;
855
856 i = 0;
857 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400858 if ((ifmodes & 1) && nla_put_flag(msg, i))
859 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200860 ifmodes >>= 1;
861 i++;
862 }
863
864 nla_nest_end(msg, nl_modes);
865 return 0;
866
867nla_put_failure:
868 return -ENOBUFS;
869}
870
871static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100872 struct sk_buff *msg,
873 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200874{
875 struct nlattr *nl_combis;
876 int i, j;
877
878 nl_combis = nla_nest_start(msg,
879 NL80211_ATTR_INTERFACE_COMBINATIONS);
880 if (!nl_combis)
881 goto nla_put_failure;
882
883 for (i = 0; i < wiphy->n_iface_combinations; i++) {
884 const struct ieee80211_iface_combination *c;
885 struct nlattr *nl_combi, *nl_limits;
886
887 c = &wiphy->iface_combinations[i];
888
889 nl_combi = nla_nest_start(msg, i + 1);
890 if (!nl_combi)
891 goto nla_put_failure;
892
893 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
894 if (!nl_limits)
895 goto nla_put_failure;
896
897 for (j = 0; j < c->n_limits; j++) {
898 struct nlattr *nl_limit;
899
900 nl_limit = nla_nest_start(msg, j + 1);
901 if (!nl_limit)
902 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400903 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
904 c->limits[j].max))
905 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200906 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
907 c->limits[j].types))
908 goto nla_put_failure;
909 nla_nest_end(msg, nl_limit);
910 }
911
912 nla_nest_end(msg, nl_limits);
913
David S. Miller9360ffd2012-03-29 04:41:26 -0400914 if (c->beacon_int_infra_match &&
915 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
916 goto nla_put_failure;
917 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
918 c->num_different_channels) ||
919 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
920 c->max_interfaces))
921 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100922 if (large &&
923 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
924 c->radar_detect_widths))
925 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200926
927 nla_nest_end(msg, nl_combi);
928 }
929
930 nla_nest_end(msg, nl_combis);
931
932 return 0;
933nla_put_failure:
934 return -ENOBUFS;
935}
936
Johannes Berg3713b4e2013-02-14 16:19:38 +0100937#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100938static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
939 struct sk_buff *msg)
940{
941 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
942 struct nlattr *nl_tcp;
943
944 if (!tcp)
945 return 0;
946
947 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
948 if (!nl_tcp)
949 return -ENOBUFS;
950
951 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
952 tcp->data_payload_max))
953 return -ENOBUFS;
954
955 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
956 tcp->data_payload_max))
957 return -ENOBUFS;
958
959 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
960 return -ENOBUFS;
961
962 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
963 sizeof(*tcp->tok), tcp->tok))
964 return -ENOBUFS;
965
966 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
967 tcp->data_interval_max))
968 return -ENOBUFS;
969
970 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
971 tcp->wake_payload_max))
972 return -ENOBUFS;
973
974 nla_nest_end(msg, nl_tcp);
975 return 0;
976}
977
Johannes Berg3713b4e2013-02-14 16:19:38 +0100978static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100979 struct cfg80211_registered_device *dev,
980 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100981{
982 struct nlattr *nl_wowlan;
983
984 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
985 return 0;
986
987 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
988 if (!nl_wowlan)
989 return -ENOBUFS;
990
991 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
992 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
993 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
994 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
995 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
996 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
997 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
998 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
999 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1000 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1001 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1002 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1003 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1005 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1007 return -ENOBUFS;
1008
1009 if (dev->wiphy.wowlan.n_patterns) {
1010 struct nl80211_wowlan_pattern_support pat = {
1011 .max_patterns = dev->wiphy.wowlan.n_patterns,
1012 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
1013 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
1014 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
1015 };
1016
1017 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1018 sizeof(pat), &pat))
1019 return -ENOBUFS;
1020 }
1021
Johannes Bergb56cf722013-02-20 01:02:38 +01001022 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1023 return -ENOBUFS;
1024
Johannes Berg3713b4e2013-02-14 16:19:38 +01001025 nla_nest_end(msg, nl_wowlan);
1026
1027 return 0;
1028}
1029#endif
1030
1031static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1032 struct ieee80211_supported_band *sband)
1033{
1034 struct nlattr *nl_rates, *nl_rate;
1035 struct ieee80211_rate *rate;
1036 int i;
1037
1038 /* add HT info */
1039 if (sband->ht_cap.ht_supported &&
1040 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1041 sizeof(sband->ht_cap.mcs),
1042 &sband->ht_cap.mcs) ||
1043 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1044 sband->ht_cap.cap) ||
1045 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1046 sband->ht_cap.ampdu_factor) ||
1047 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1048 sband->ht_cap.ampdu_density)))
1049 return -ENOBUFS;
1050
1051 /* add VHT info */
1052 if (sband->vht_cap.vht_supported &&
1053 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1054 sizeof(sband->vht_cap.vht_mcs),
1055 &sband->vht_cap.vht_mcs) ||
1056 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1057 sband->vht_cap.cap)))
1058 return -ENOBUFS;
1059
1060 /* add bitrates */
1061 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1062 if (!nl_rates)
1063 return -ENOBUFS;
1064
1065 for (i = 0; i < sband->n_bitrates; i++) {
1066 nl_rate = nla_nest_start(msg, i);
1067 if (!nl_rate)
1068 return -ENOBUFS;
1069
1070 rate = &sband->bitrates[i];
1071 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1072 rate->bitrate))
1073 return -ENOBUFS;
1074 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1075 nla_put_flag(msg,
1076 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1077 return -ENOBUFS;
1078
1079 nla_nest_end(msg, nl_rate);
1080 }
1081
1082 nla_nest_end(msg, nl_rates);
1083
1084 return 0;
1085}
1086
1087static int
1088nl80211_send_mgmt_stypes(struct sk_buff *msg,
1089 const struct ieee80211_txrx_stypes *mgmt_stypes)
1090{
1091 u16 stypes;
1092 struct nlattr *nl_ftypes, *nl_ifs;
1093 enum nl80211_iftype ift;
1094 int i;
1095
1096 if (!mgmt_stypes)
1097 return 0;
1098
1099 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1100 if (!nl_ifs)
1101 return -ENOBUFS;
1102
1103 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1104 nl_ftypes = nla_nest_start(msg, ift);
1105 if (!nl_ftypes)
1106 return -ENOBUFS;
1107 i = 0;
1108 stypes = mgmt_stypes[ift].tx;
1109 while (stypes) {
1110 if ((stypes & 1) &&
1111 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1112 (i << 4) | IEEE80211_FTYPE_MGMT))
1113 return -ENOBUFS;
1114 stypes >>= 1;
1115 i++;
1116 }
1117 nla_nest_end(msg, nl_ftypes);
1118 }
1119
1120 nla_nest_end(msg, nl_ifs);
1121
1122 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1123 if (!nl_ifs)
1124 return -ENOBUFS;
1125
1126 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1127 nl_ftypes = nla_nest_start(msg, ift);
1128 if (!nl_ftypes)
1129 return -ENOBUFS;
1130 i = 0;
1131 stypes = mgmt_stypes[ift].rx;
1132 while (stypes) {
1133 if ((stypes & 1) &&
1134 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1135 (i << 4) | IEEE80211_FTYPE_MGMT))
1136 return -ENOBUFS;
1137 stypes >>= 1;
1138 i++;
1139 }
1140 nla_nest_end(msg, nl_ftypes);
1141 }
1142 nla_nest_end(msg, nl_ifs);
1143
1144 return 0;
1145}
1146
1147static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1148 struct sk_buff *msg, u32 portid, u32 seq,
1149 int flags, bool split, long *split_start,
1150 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001151{
1152 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001153 struct nlattr *nl_bands, *nl_band;
1154 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001155 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001156 enum ieee80211_band band;
1157 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001158 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001159 const struct ieee80211_txrx_stypes *mgmt_stypes =
1160 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001161 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001162 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001163
Eric W. Biederman15e47302012-09-07 20:12:54 +00001164 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001165 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001166 return -ENOBUFS;
1167
1168 /* allow always using the variables */
1169 if (!split) {
1170 split_start = &start;
1171 band_start = &start_band;
1172 chan_start = &start_chan;
1173 }
Johannes Berg55682962007-09-20 13:09:35 -04001174
David S. Miller9360ffd2012-03-29 04:41:26 -04001175 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1177 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001178 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001179 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001180 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001181
Johannes Berg3713b4e2013-02-14 16:19:38 +01001182 switch (*split_start) {
1183 case 0:
1184 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1185 dev->wiphy.retry_short) ||
1186 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1187 dev->wiphy.retry_long) ||
1188 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1189 dev->wiphy.frag_threshold) ||
1190 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1191 dev->wiphy.rts_threshold) ||
1192 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1193 dev->wiphy.coverage_class) ||
1194 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1195 dev->wiphy.max_scan_ssids) ||
1196 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1197 dev->wiphy.max_sched_scan_ssids) ||
1198 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1199 dev->wiphy.max_scan_ie_len) ||
1200 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1201 dev->wiphy.max_sched_scan_ie_len) ||
1202 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1203 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001204 goto nla_put_failure;
1205
Johannes Berg3713b4e2013-02-14 16:19:38 +01001206 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1207 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1208 goto nla_put_failure;
1209 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1210 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1211 goto nla_put_failure;
1212 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1213 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1216 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1219 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1220 goto nla_put_failure;
1221 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1222 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001223 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001224
Johannes Berg3713b4e2013-02-14 16:19:38 +01001225 (*split_start)++;
1226 if (split)
1227 break;
1228 case 1:
1229 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1230 sizeof(u32) * dev->wiphy.n_cipher_suites,
1231 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001232 goto nla_put_failure;
1233
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1235 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001236 goto nla_put_failure;
1237
Johannes Berg3713b4e2013-02-14 16:19:38 +01001238 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1239 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1240 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001241
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1243 dev->wiphy.available_antennas_tx) ||
1244 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1245 dev->wiphy.available_antennas_rx))
1246 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001247
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1249 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1250 dev->wiphy.probe_resp_offload))
1251 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.available_antennas_tx ||
1254 dev->wiphy.available_antennas_rx) &&
1255 dev->ops->get_antenna) {
1256 u32 tx_ant = 0, rx_ant = 0;
1257 int res;
1258 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1259 if (!res) {
1260 if (nla_put_u32(msg,
1261 NL80211_ATTR_WIPHY_ANTENNA_TX,
1262 tx_ant) ||
1263 nla_put_u32(msg,
1264 NL80211_ATTR_WIPHY_ANTENNA_RX,
1265 rx_ant))
1266 goto nla_put_failure;
1267 }
Johannes Bergee688b002008-01-24 19:38:39 +01001268 }
1269
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 (*split_start)++;
1271 if (split)
1272 break;
1273 case 2:
1274 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1275 dev->wiphy.interface_modes))
1276 goto nla_put_failure;
1277 (*split_start)++;
1278 if (split)
1279 break;
1280 case 3:
1281 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1282 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001283 goto nla_put_failure;
1284
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1286 struct ieee80211_supported_band *sband;
1287
1288 sband = dev->wiphy.bands[band];
1289
1290 if (!sband)
1291 continue;
1292
1293 nl_band = nla_nest_start(msg, band);
1294 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001295 goto nla_put_failure;
1296
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 switch (*chan_start) {
1298 case 0:
1299 if (nl80211_send_band_rateinfo(msg, sband))
1300 goto nla_put_failure;
1301 (*chan_start)++;
1302 if (split)
1303 break;
1304 default:
1305 /* add frequencies */
1306 nl_freqs = nla_nest_start(
1307 msg, NL80211_BAND_ATTR_FREQS);
1308 if (!nl_freqs)
1309 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001310
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 for (i = *chan_start - 1;
1312 i < sband->n_channels;
1313 i++) {
1314 nl_freq = nla_nest_start(msg, i);
1315 if (!nl_freq)
1316 goto nla_put_failure;
1317
1318 chan = &sband->channels[i];
1319
Johannes Bergcdc89b92013-02-18 23:54:36 +01001320 if (nl80211_msg_put_channel(msg, chan,
1321 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 goto nla_put_failure;
1323
1324 nla_nest_end(msg, nl_freq);
1325 if (split)
1326 break;
1327 }
1328 if (i < sband->n_channels)
1329 *chan_start = i + 2;
1330 else
1331 *chan_start = 0;
1332 nla_nest_end(msg, nl_freqs);
1333 }
1334
1335 nla_nest_end(msg, nl_band);
1336
1337 if (split) {
1338 /* start again here */
1339 if (*chan_start)
1340 band--;
1341 break;
1342 }
Johannes Bergee688b002008-01-24 19:38:39 +01001343 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001345
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 if (band < IEEE80211_NUM_BANDS)
1347 *band_start = band + 1;
1348 else
1349 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001350
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 /* if bands & channels are done, continue outside */
1352 if (*band_start == 0 && *chan_start == 0)
1353 (*split_start)++;
1354 if (split)
1355 break;
1356 case 4:
1357 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1358 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001359 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360
1361 i = 0;
1362#define CMD(op, n) \
1363 do { \
1364 if (dev->ops->op) { \
1365 i++; \
1366 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1367 goto nla_put_failure; \
1368 } \
1369 } while (0)
1370
1371 CMD(add_virtual_intf, NEW_INTERFACE);
1372 CMD(change_virtual_intf, SET_INTERFACE);
1373 CMD(add_key, NEW_KEY);
1374 CMD(start_ap, START_AP);
1375 CMD(add_station, NEW_STATION);
1376 CMD(add_mpath, NEW_MPATH);
1377 CMD(update_mesh_config, SET_MESH_CONFIG);
1378 CMD(change_bss, SET_BSS);
1379 CMD(auth, AUTHENTICATE);
1380 CMD(assoc, ASSOCIATE);
1381 CMD(deauth, DEAUTHENTICATE);
1382 CMD(disassoc, DISASSOCIATE);
1383 CMD(join_ibss, JOIN_IBSS);
1384 CMD(join_mesh, JOIN_MESH);
1385 CMD(set_pmksa, SET_PMKSA);
1386 CMD(del_pmksa, DEL_PMKSA);
1387 CMD(flush_pmksa, FLUSH_PMKSA);
1388 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1389 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1390 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1391 CMD(mgmt_tx, FRAME);
1392 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1393 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1394 i++;
1395 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1396 goto nla_put_failure;
1397 }
1398 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1399 dev->ops->join_mesh) {
1400 i++;
1401 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1402 goto nla_put_failure;
1403 }
1404 CMD(set_wds_peer, SET_WDS_PEER);
1405 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1406 CMD(tdls_mgmt, TDLS_MGMT);
1407 CMD(tdls_oper, TDLS_OPER);
1408 }
1409 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1410 CMD(sched_scan_start, START_SCHED_SCAN);
1411 CMD(probe_client, PROBE_CLIENT);
1412 CMD(set_noack_map, SET_NOACK_MAP);
1413 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1414 i++;
1415 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1416 goto nla_put_failure;
1417 }
1418 CMD(start_p2p_device, START_P2P_DEVICE);
1419 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001420
Kalle Valo4745fc02011-11-17 19:06:10 +02001421#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001423#endif
1424
Johannes Berg8fdc6212009-03-14 09:34:01 +01001425#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001426
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 if (dev->ops->connect || dev->ops->auth) {
1428 i++;
1429 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001430 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001431 }
1432
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 if (dev->ops->disconnect || dev->ops->deauth) {
1434 i++;
1435 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1436 goto nla_put_failure;
1437 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 nla_nest_end(msg, nl_cmds);
1440 (*split_start)++;
1441 if (split)
1442 break;
1443 case 5:
1444 if (dev->ops->remain_on_channel &&
1445 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1446 nla_put_u32(msg,
1447 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1448 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001449 goto nla_put_failure;
1450
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1452 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1453 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001454
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1456 goto nla_put_failure;
1457 (*split_start)++;
1458 if (split)
1459 break;
1460 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001461#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001462 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 goto nla_put_failure;
1464 (*split_start)++;
1465 if (split)
1466 break;
1467#else
1468 (*split_start)++;
1469#endif
1470 case 7:
1471 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1472 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001473 goto nla_put_failure;
1474
Johannes Bergcdc89b92013-02-18 23:54:36 +01001475 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001477
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 (*split_start)++;
1479 if (split)
1480 break;
1481 case 8:
1482 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1483 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1484 dev->wiphy.ap_sme_capa))
1485 goto nla_put_failure;
1486
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001487 features = dev->wiphy.features;
1488 /*
1489 * We can only add the per-channel limit information if the
1490 * dump is split, otherwise it makes it too big. Therefore
1491 * only advertise it in that case.
1492 */
1493 if (split)
1494 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1495 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 goto nla_put_failure;
1497
1498 if (dev->wiphy.ht_capa_mod_mask &&
1499 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1500 sizeof(*dev->wiphy.ht_capa_mod_mask),
1501 dev->wiphy.ht_capa_mod_mask))
1502 goto nla_put_failure;
1503
1504 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1505 dev->wiphy.max_acl_mac_addrs &&
1506 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1507 dev->wiphy.max_acl_mac_addrs))
1508 goto nla_put_failure;
1509
1510 /*
1511 * Any information below this point is only available to
1512 * applications that can deal with it being split. This
1513 * helps ensure that newly added capabilities don't break
1514 * older tools by overrunning their buffers.
1515 *
1516 * We still increment split_start so that in the split
1517 * case we'll continue with more data in the next round,
1518 * but break unconditionally so unsplit data stops here.
1519 */
1520 (*split_start)++;
1521 break;
1522 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001523 if (dev->wiphy.extended_capabilities &&
1524 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1525 dev->wiphy.extended_capabilities_len,
1526 dev->wiphy.extended_capabilities) ||
1527 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1528 dev->wiphy.extended_capabilities_len,
1529 dev->wiphy.extended_capabilities_mask)))
1530 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531
Johannes Bergee2aca32013-02-21 17:36:01 +01001532 if (dev->wiphy.vht_capa_mod_mask &&
1533 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1534 sizeof(*dev->wiphy.vht_capa_mod_mask),
1535 dev->wiphy.vht_capa_mod_mask))
1536 goto nla_put_failure;
1537
Johannes Berg3713b4e2013-02-14 16:19:38 +01001538 /* done */
1539 *split_start = 0;
1540 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001541 }
Johannes Berg55682962007-09-20 13:09:35 -04001542 return genlmsg_end(msg, hdr);
1543
1544 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001545 genlmsg_cancel(msg, hdr);
1546 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001547}
1548
1549static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1550{
Johannes Berg645e77d2013-03-01 14:03:49 +01001551 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001552 int start = cb->args[0];
1553 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 s64 filter_wiphy = -1;
1555 bool split = false;
1556 struct nlattr **tb = nl80211_fam.attrbuf;
1557 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001558
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001559 mutex_lock(&cfg80211_mutex);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1561 tb, nl80211_fam.maxattr, nl80211_policy);
1562 if (res == 0) {
1563 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1564 if (tb[NL80211_ATTR_WIPHY])
1565 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1566 if (tb[NL80211_ATTR_WDEV])
1567 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1568 if (tb[NL80211_ATTR_IFINDEX]) {
1569 struct net_device *netdev;
1570 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1571
1572 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1573 if (!netdev) {
1574 mutex_unlock(&cfg80211_mutex);
1575 return -ENODEV;
1576 }
1577 if (netdev->ieee80211_ptr) {
1578 dev = wiphy_to_dev(
1579 netdev->ieee80211_ptr->wiphy);
1580 filter_wiphy = dev->wiphy_idx;
1581 }
1582 dev_put(netdev);
1583 }
1584 }
1585
Johannes Berg79c97e92009-07-07 03:56:12 +02001586 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001587 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1588 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001589 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001590 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1592 continue;
1593 /* attempt to fit multiple wiphy data chunks into the skb */
1594 do {
1595 ret = nl80211_send_wiphy(dev, skb,
1596 NETLINK_CB(cb->skb).portid,
1597 cb->nlh->nlmsg_seq,
1598 NLM_F_MULTI,
1599 split, &cb->args[1],
1600 &cb->args[2],
1601 &cb->args[3]);
1602 if (ret < 0) {
1603 /*
1604 * If sending the wiphy data didn't fit (ENOBUFS
1605 * or EMSGSIZE returned), this SKB is still
1606 * empty (so it's not too big because another
1607 * wiphy dataset is already in the skb) and
1608 * we've not tried to adjust the dump allocation
1609 * yet ... then adjust the alloc size to be
1610 * bigger, and return 1 but with the empty skb.
1611 * This results in an empty message being RX'ed
1612 * in userspace, but that is ignored.
1613 *
1614 * We can then retry with the larger buffer.
1615 */
1616 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1617 !skb->len &&
1618 cb->min_dump_alloc < 4096) {
1619 cb->min_dump_alloc = 4096;
1620 mutex_unlock(&cfg80211_mutex);
1621 return 1;
1622 }
1623 idx--;
1624 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001625 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 } while (cb->args[1] > 0);
1627 break;
Johannes Berg55682962007-09-20 13:09:35 -04001628 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001629 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001630
1631 cb->args[0] = idx;
1632
1633 return skb->len;
1634}
1635
1636static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1637{
1638 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001639 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001640
Johannes Berg645e77d2013-03-01 14:03:49 +01001641 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001642 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001643 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001644
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1646 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001647 nlmsg_free(msg);
1648 return -ENOBUFS;
1649 }
Johannes Berg55682962007-09-20 13:09:35 -04001650
Johannes Berg134e6372009-07-10 09:51:34 +00001651 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001652}
1653
Jouni Malinen31888482008-10-30 16:59:24 +02001654static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1655 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1656 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1657 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1658 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1659 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1660};
1661
1662static int parse_txq_params(struct nlattr *tb[],
1663 struct ieee80211_txq_params *txq_params)
1664{
Johannes Berga3304b02012-03-28 11:04:24 +02001665 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001666 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1667 !tb[NL80211_TXQ_ATTR_AIFS])
1668 return -EINVAL;
1669
Johannes Berga3304b02012-03-28 11:04:24 +02001670 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001671 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1672 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1673 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1674 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1675
Johannes Berga3304b02012-03-28 11:04:24 +02001676 if (txq_params->ac >= NL80211_NUM_ACS)
1677 return -EINVAL;
1678
Jouni Malinen31888482008-10-30 16:59:24 +02001679 return 0;
1680}
1681
Johannes Bergf444de02010-05-05 15:25:02 +02001682static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1683{
1684 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001685 * You can only set the channel explicitly for WDS interfaces,
1686 * all others have their channel managed via their respective
1687 * "establish a connection" command (connect, join, ...)
1688 *
1689 * For AP/GO and mesh mode, the channel can be set with the
1690 * channel userspace API, but is only stored and passed to the
1691 * low-level driver when the AP starts or the mesh is joined.
1692 * This is for backward compatibility, userspace can also give
1693 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001694 *
1695 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001696 * whatever else is going on, so they have their own special
1697 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001698 */
1699 return !wdev ||
1700 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001701 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001702 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1703 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001704}
1705
Johannes Berg683b6d32012-11-08 21:25:48 +01001706static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1707 struct genl_info *info,
1708 struct cfg80211_chan_def *chandef)
1709{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301710 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001711
1712 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1713 return -EINVAL;
1714
1715 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1716
1717 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001718 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1719 chandef->center_freq1 = control_freq;
1720 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001721
1722 /* Primary channel not allowed */
1723 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1724 return -EINVAL;
1725
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001726 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1727 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001728
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001729 chantype = nla_get_u32(
1730 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1731
1732 switch (chantype) {
1733 case NL80211_CHAN_NO_HT:
1734 case NL80211_CHAN_HT20:
1735 case NL80211_CHAN_HT40PLUS:
1736 case NL80211_CHAN_HT40MINUS:
1737 cfg80211_chandef_create(chandef, chandef->chan,
1738 chantype);
1739 break;
1740 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001741 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001742 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001743 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1744 chandef->width =
1745 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1746 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1747 chandef->center_freq1 =
1748 nla_get_u32(
1749 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1750 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1751 chandef->center_freq2 =
1752 nla_get_u32(
1753 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1754 }
1755
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001756 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001757 return -EINVAL;
1758
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001759 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1760 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001761 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001762
Johannes Berg683b6d32012-11-08 21:25:48 +01001763 return 0;
1764}
1765
Johannes Bergf444de02010-05-05 15:25:02 +02001766static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1767 struct wireless_dev *wdev,
1768 struct genl_info *info)
1769{
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001771 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001772 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1773
1774 if (wdev)
1775 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001776
Johannes Bergf444de02010-05-05 15:25:02 +02001777 if (!nl80211_can_set_dev_channel(wdev))
1778 return -EOPNOTSUPP;
1779
Johannes Berg683b6d32012-11-08 21:25:48 +01001780 result = nl80211_parse_chandef(rdev, info, &chandef);
1781 if (result)
1782 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001783
1784 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001785 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001786 case NL80211_IFTYPE_AP:
1787 case NL80211_IFTYPE_P2P_GO:
1788 if (wdev->beacon_interval) {
1789 result = -EBUSY;
1790 break;
1791 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001792 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001793 result = -EINVAL;
1794 break;
1795 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001796 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001797 result = 0;
1798 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001799 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001800 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001801 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001802 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001803 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001804 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001805 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001806 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001807 }
1808 mutex_unlock(&rdev->devlist_mtx);
1809
1810 return result;
1811}
1812
1813static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1814{
Johannes Berg4c476992010-10-04 21:36:35 +02001815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1816 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001817
Johannes Berg4c476992010-10-04 21:36:35 +02001818 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001819}
1820
Bill Jordane8347eb2010-10-01 13:54:28 -04001821static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1822{
Johannes Berg43b19952010-10-07 13:10:30 +02001823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1824 struct net_device *dev = info->user_ptr[1];
1825 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001826 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001827
1828 if (!info->attrs[NL80211_ATTR_MAC])
1829 return -EINVAL;
1830
Johannes Berg43b19952010-10-07 13:10:30 +02001831 if (netif_running(dev))
1832 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001833
Johannes Berg43b19952010-10-07 13:10:30 +02001834 if (!rdev->ops->set_wds_peer)
1835 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001836
Johannes Berg43b19952010-10-07 13:10:30 +02001837 if (wdev->iftype != NL80211_IFTYPE_WDS)
1838 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001839
1840 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001841 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001842}
1843
1844
Johannes Berg55682962007-09-20 13:09:35 -04001845static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1846{
1847 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001848 struct net_device *netdev = NULL;
1849 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001850 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001851 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001852 u32 changed;
1853 u8 retry_short = 0, retry_long = 0;
1854 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001855 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001856
Johannes Bergf444de02010-05-05 15:25:02 +02001857 /*
1858 * Try to find the wiphy and netdev. Normally this
1859 * function shouldn't need the netdev, but this is
1860 * done for backward compatibility -- previously
1861 * setting the channel was done per wiphy, but now
1862 * it is per netdev. Previous userland like hostapd
1863 * also passed a netdev to set_wiphy, so that it is
1864 * possible to let that go to the right netdev!
1865 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001866 mutex_lock(&cfg80211_mutex);
1867
Johannes Bergf444de02010-05-05 15:25:02 +02001868 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1869 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1870
1871 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1872 if (netdev && netdev->ieee80211_ptr) {
1873 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1874 mutex_lock(&rdev->mtx);
1875 } else
1876 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001877 }
1878
Johannes Bergf444de02010-05-05 15:25:02 +02001879 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001880 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1881 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001882 if (IS_ERR(rdev)) {
1883 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001884 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001885 }
1886 wdev = NULL;
1887 netdev = NULL;
1888 result = 0;
1889
1890 mutex_lock(&rdev->mtx);
Johannes Berg71fe96b2012-10-24 10:04:58 +02001891 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001892 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001893
1894 /*
1895 * end workaround code, by now the rdev is available
1896 * and locked, and wdev may or may not be NULL.
1897 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001898
1899 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001900 result = cfg80211_dev_rename(
1901 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001902
1903 mutex_unlock(&cfg80211_mutex);
1904
1905 if (result)
1906 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001907
Jouni Malinen31888482008-10-30 16:59:24 +02001908 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1909 struct ieee80211_txq_params txq_params;
1910 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1911
1912 if (!rdev->ops->set_txq_params) {
1913 result = -EOPNOTSUPP;
1914 goto bad_res;
1915 }
1916
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001917 if (!netdev) {
1918 result = -EINVAL;
1919 goto bad_res;
1920 }
1921
Johannes Berg133a3ff2011-11-03 14:50:13 +01001922 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1923 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1924 result = -EINVAL;
1925 goto bad_res;
1926 }
1927
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001928 if (!netif_running(netdev)) {
1929 result = -ENETDOWN;
1930 goto bad_res;
1931 }
1932
Jouni Malinen31888482008-10-30 16:59:24 +02001933 nla_for_each_nested(nl_txq_params,
1934 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1935 rem_txq_params) {
1936 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1937 nla_data(nl_txq_params),
1938 nla_len(nl_txq_params),
1939 txq_params_policy);
1940 result = parse_txq_params(tb, &txq_params);
1941 if (result)
1942 goto bad_res;
1943
Hila Gonene35e4d22012-06-27 17:19:42 +03001944 result = rdev_set_txq_params(rdev, netdev,
1945 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001946 if (result)
1947 goto bad_res;
1948 }
1949 }
1950
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001951 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001952 result = __nl80211_set_channel(rdev,
1953 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1954 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001955 if (result)
1956 goto bad_res;
1957 }
1958
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001959 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001960 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001961 enum nl80211_tx_power_setting type;
1962 int idx, mbm = 0;
1963
Johannes Bergc8442112012-10-24 10:17:18 +02001964 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1965 txp_wdev = NULL;
1966
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001967 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001968 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001969 goto bad_res;
1970 }
1971
1972 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1973 type = nla_get_u32(info->attrs[idx]);
1974
1975 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1976 (type != NL80211_TX_POWER_AUTOMATIC)) {
1977 result = -EINVAL;
1978 goto bad_res;
1979 }
1980
1981 if (type != NL80211_TX_POWER_AUTOMATIC) {
1982 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1983 mbm = nla_get_u32(info->attrs[idx]);
1984 }
1985
Johannes Bergc8442112012-10-24 10:17:18 +02001986 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001987 if (result)
1988 goto bad_res;
1989 }
1990
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001991 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1992 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1993 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001994 if ((!rdev->wiphy.available_antennas_tx &&
1995 !rdev->wiphy.available_antennas_rx) ||
1996 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001997 result = -EOPNOTSUPP;
1998 goto bad_res;
1999 }
2000
2001 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2002 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2003
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002004 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002005 * available antenna masks, except for the "all" mask */
2006 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2007 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002008 result = -EINVAL;
2009 goto bad_res;
2010 }
2011
Bruno Randolf7f531e02010-12-16 11:30:22 +09002012 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2013 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002014
Hila Gonene35e4d22012-06-27 17:19:42 +03002015 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002016 if (result)
2017 goto bad_res;
2018 }
2019
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002020 changed = 0;
2021
2022 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2023 retry_short = nla_get_u8(
2024 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2025 if (retry_short == 0) {
2026 result = -EINVAL;
2027 goto bad_res;
2028 }
2029 changed |= WIPHY_PARAM_RETRY_SHORT;
2030 }
2031
2032 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2033 retry_long = nla_get_u8(
2034 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2035 if (retry_long == 0) {
2036 result = -EINVAL;
2037 goto bad_res;
2038 }
2039 changed |= WIPHY_PARAM_RETRY_LONG;
2040 }
2041
2042 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2043 frag_threshold = nla_get_u32(
2044 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2045 if (frag_threshold < 256) {
2046 result = -EINVAL;
2047 goto bad_res;
2048 }
2049 if (frag_threshold != (u32) -1) {
2050 /*
2051 * Fragments (apart from the last one) are required to
2052 * have even length. Make the fragmentation code
2053 * simpler by stripping LSB should someone try to use
2054 * odd threshold value.
2055 */
2056 frag_threshold &= ~0x1;
2057 }
2058 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2059 }
2060
2061 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2062 rts_threshold = nla_get_u32(
2063 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2064 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2065 }
2066
Lukáš Turek81077e82009-12-21 22:50:47 +01002067 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2068 coverage_class = nla_get_u8(
2069 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2070 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2071 }
2072
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002073 if (changed) {
2074 u8 old_retry_short, old_retry_long;
2075 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002076 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002077
2078 if (!rdev->ops->set_wiphy_params) {
2079 result = -EOPNOTSUPP;
2080 goto bad_res;
2081 }
2082
2083 old_retry_short = rdev->wiphy.retry_short;
2084 old_retry_long = rdev->wiphy.retry_long;
2085 old_frag_threshold = rdev->wiphy.frag_threshold;
2086 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002087 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002088
2089 if (changed & WIPHY_PARAM_RETRY_SHORT)
2090 rdev->wiphy.retry_short = retry_short;
2091 if (changed & WIPHY_PARAM_RETRY_LONG)
2092 rdev->wiphy.retry_long = retry_long;
2093 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2094 rdev->wiphy.frag_threshold = frag_threshold;
2095 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2096 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002097 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2098 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002099
Hila Gonene35e4d22012-06-27 17:19:42 +03002100 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002101 if (result) {
2102 rdev->wiphy.retry_short = old_retry_short;
2103 rdev->wiphy.retry_long = old_retry_long;
2104 rdev->wiphy.frag_threshold = old_frag_threshold;
2105 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002106 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002107 }
2108 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002109
Johannes Berg306d6112008-12-08 12:39:04 +01002110 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002111 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02002112 if (netdev)
2113 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002114 return result;
2115}
2116
Johannes Berg71bbc992012-06-15 15:30:18 +02002117static inline u64 wdev_id(struct wireless_dev *wdev)
2118{
2119 return (u64)wdev->identifier |
2120 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2121}
Johannes Berg55682962007-09-20 13:09:35 -04002122
Johannes Berg683b6d32012-11-08 21:25:48 +01002123static int nl80211_send_chandef(struct sk_buff *msg,
2124 struct cfg80211_chan_def *chandef)
2125{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002126 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002127
Johannes Berg683b6d32012-11-08 21:25:48 +01002128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2129 chandef->chan->center_freq))
2130 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002131 switch (chandef->width) {
2132 case NL80211_CHAN_WIDTH_20_NOHT:
2133 case NL80211_CHAN_WIDTH_20:
2134 case NL80211_CHAN_WIDTH_40:
2135 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2136 cfg80211_get_chandef_type(chandef)))
2137 return -ENOBUFS;
2138 break;
2139 default:
2140 break;
2141 }
2142 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2143 return -ENOBUFS;
2144 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2145 return -ENOBUFS;
2146 if (chandef->center_freq2 &&
2147 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002148 return -ENOBUFS;
2149 return 0;
2150}
2151
Eric W. Biederman15e47302012-09-07 20:12:54 +00002152static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002153 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002154 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002155{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002156 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002157 void *hdr;
2158
Eric W. Biederman15e47302012-09-07 20:12:54 +00002159 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002160 if (!hdr)
2161 return -1;
2162
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002163 if (dev &&
2164 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002165 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002166 goto nla_put_failure;
2167
2168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2169 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002170 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002171 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002172 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2173 rdev->devlist_generation ^
2174 (cfg80211_rdev_list_generation << 2)))
2175 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002176
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002177 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002178 int ret;
2179 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002180
Johannes Berg683b6d32012-11-08 21:25:48 +01002181 ret = rdev_get_channel(rdev, wdev, &chandef);
2182 if (ret == 0) {
2183 if (nl80211_send_chandef(msg, &chandef))
2184 goto nla_put_failure;
2185 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002186 }
2187
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002188 if (wdev->ssid_len) {
2189 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2190 goto nla_put_failure;
2191 }
2192
Johannes Berg55682962007-09-20 13:09:35 -04002193 return genlmsg_end(msg, hdr);
2194
2195 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002196 genlmsg_cancel(msg, hdr);
2197 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002198}
2199
2200static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2201{
2202 int wp_idx = 0;
2203 int if_idx = 0;
2204 int wp_start = cb->args[0];
2205 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002206 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002207 struct wireless_dev *wdev;
2208
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002209 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02002210 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2211 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002212 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002213 if (wp_idx < wp_start) {
2214 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002215 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002216 }
Johannes Berg55682962007-09-20 13:09:35 -04002217 if_idx = 0;
2218
Johannes Bergf5ea9122009-08-07 16:17:38 +02002219 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02002220 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002221 if (if_idx < if_start) {
2222 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002223 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002224 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002225 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002226 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002227 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02002228 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002229 goto out;
2230 }
2231 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002232 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02002233 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002234
2235 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002236 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002237 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002238 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04002239
2240 cb->args[0] = wp_idx;
2241 cb->args[1] = if_idx;
2242
2243 return skb->len;
2244}
2245
2246static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2247{
2248 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002249 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002250 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002251
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002253 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002254 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002255
Eric W. Biederman15e47302012-09-07 20:12:54 +00002256 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002257 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002258 nlmsg_free(msg);
2259 return -ENOBUFS;
2260 }
Johannes Berg55682962007-09-20 13:09:35 -04002261
Johannes Berg134e6372009-07-10 09:51:34 +00002262 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002263}
2264
Michael Wu66f7ac52008-01-31 19:48:22 +01002265static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2266 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2267 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2268 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2269 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2270 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2271};
2272
2273static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2274{
2275 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2276 int flag;
2277
2278 *mntrflags = 0;
2279
2280 if (!nla)
2281 return -EINVAL;
2282
2283 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2284 nla, mntr_flags_policy))
2285 return -EINVAL;
2286
2287 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2288 if (flags[flag])
2289 *mntrflags |= (1<<flag);
2290
2291 return 0;
2292}
2293
Johannes Berg9bc383d2009-11-19 11:55:19 +01002294static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002295 struct net_device *netdev, u8 use_4addr,
2296 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002297{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002298 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002299 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002300 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002301 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002302 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002303
2304 switch (iftype) {
2305 case NL80211_IFTYPE_AP_VLAN:
2306 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2307 return 0;
2308 break;
2309 case NL80211_IFTYPE_STATION:
2310 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2311 return 0;
2312 break;
2313 default:
2314 break;
2315 }
2316
2317 return -EOPNOTSUPP;
2318}
2319
Johannes Berg55682962007-09-20 13:09:35 -04002320static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2321{
Johannes Berg4c476992010-10-04 21:36:35 +02002322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002323 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002324 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002325 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002326 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002327 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002328 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002329
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002330 memset(&params, 0, sizeof(params));
2331
Johannes Berg04a773a2009-04-19 21:24:32 +02002332 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002333
Johannes Berg723b0382008-09-16 20:22:09 +02002334 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002335 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002336 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002337 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002338 if (ntype > NL80211_IFTYPE_MAX)
2339 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002340 }
2341
Johannes Berg92ffe052008-09-16 20:39:36 +02002342 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002343 struct wireless_dev *wdev = dev->ieee80211_ptr;
2344
Johannes Berg4c476992010-10-04 21:36:35 +02002345 if (ntype != NL80211_IFTYPE_MESH_POINT)
2346 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002347 if (netif_running(dev))
2348 return -EBUSY;
2349
2350 wdev_lock(wdev);
2351 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2352 IEEE80211_MAX_MESH_ID_LEN);
2353 wdev->mesh_id_up_len =
2354 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2355 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2356 wdev->mesh_id_up_len);
2357 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002358 }
2359
Felix Fietkau8b787642009-11-10 18:53:10 +01002360 if (info->attrs[NL80211_ATTR_4ADDR]) {
2361 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2362 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002363 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002364 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002365 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002366 } else {
2367 params.use_4addr = -1;
2368 }
2369
Johannes Berg92ffe052008-09-16 20:39:36 +02002370 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002371 if (ntype != NL80211_IFTYPE_MONITOR)
2372 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002373 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2374 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002375 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002376 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002377
2378 flags = &_flags;
2379 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002380 }
Johannes Berg3b858752009-03-12 09:55:09 +01002381
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002382 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002383 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002384 else
2385 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002386
Johannes Berg9bc383d2009-11-19 11:55:19 +01002387 if (!err && params.use_4addr != -1)
2388 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2389
Johannes Berg55682962007-09-20 13:09:35 -04002390 return err;
2391}
2392
2393static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2394{
Johannes Berg4c476992010-10-04 21:36:35 +02002395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002396 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002397 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002398 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002399 int err;
2400 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002401 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002402
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002403 memset(&params, 0, sizeof(params));
2404
Johannes Berg55682962007-09-20 13:09:35 -04002405 if (!info->attrs[NL80211_ATTR_IFNAME])
2406 return -EINVAL;
2407
2408 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2409 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2410 if (type > NL80211_IFTYPE_MAX)
2411 return -EINVAL;
2412 }
2413
Johannes Berg79c97e92009-07-07 03:56:12 +02002414 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002415 !(rdev->wiphy.interface_modes & (1 << type)))
2416 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002417
Arend van Spriel1c18f142013-01-08 10:17:27 +01002418 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2419 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2420 ETH_ALEN);
2421 if (!is_valid_ether_addr(params.macaddr))
2422 return -EADDRNOTAVAIL;
2423 }
2424
Johannes Berg9bc383d2009-11-19 11:55:19 +01002425 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002426 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002427 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002428 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002429 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002430 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002431
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2433 if (!msg)
2434 return -ENOMEM;
2435
Michael Wu66f7ac52008-01-31 19:48:22 +01002436 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2437 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2438 &flags);
Hila Gonene35e4d22012-06-27 17:19:42 +03002439 wdev = rdev_add_virtual_intf(rdev,
2440 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2441 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002442 if (IS_ERR(wdev)) {
2443 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002444 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002445 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002446
Johannes Berg98104fde2012-06-16 00:19:54 +02002447 switch (type) {
2448 case NL80211_IFTYPE_MESH_POINT:
2449 if (!info->attrs[NL80211_ATTR_MESH_ID])
2450 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002451 wdev_lock(wdev);
2452 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2453 IEEE80211_MAX_MESH_ID_LEN);
2454 wdev->mesh_id_up_len =
2455 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2456 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2457 wdev->mesh_id_up_len);
2458 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002459 break;
2460 case NL80211_IFTYPE_P2P_DEVICE:
2461 /*
2462 * P2P Device doesn't have a netdev, so doesn't go
2463 * through the netdev notifier and must be added here
2464 */
2465 mutex_init(&wdev->mtx);
2466 INIT_LIST_HEAD(&wdev->event_list);
2467 spin_lock_init(&wdev->event_lock);
2468 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2469 spin_lock_init(&wdev->mgmt_registrations_lock);
2470
2471 mutex_lock(&rdev->devlist_mtx);
2472 wdev->identifier = ++rdev->wdev_id;
2473 list_add_rcu(&wdev->list, &rdev->wdev_list);
2474 rdev->devlist_generation++;
2475 mutex_unlock(&rdev->devlist_mtx);
2476 break;
2477 default:
2478 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002479 }
2480
Eric W. Biederman15e47302012-09-07 20:12:54 +00002481 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002482 rdev, wdev) < 0) {
2483 nlmsg_free(msg);
2484 return -ENOBUFS;
2485 }
2486
2487 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002488}
2489
2490static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2491{
Johannes Berg4c476992010-10-04 21:36:35 +02002492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002493 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002494
Johannes Berg4c476992010-10-04 21:36:35 +02002495 if (!rdev->ops->del_virtual_intf)
2496 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002497
Johannes Berg84efbb82012-06-16 00:00:26 +02002498 /*
2499 * If we remove a wireless device without a netdev then clear
2500 * user_ptr[1] so that nl80211_post_doit won't dereference it
2501 * to check if it needs to do dev_put(). Otherwise it crashes
2502 * since the wdev has been freed, unlike with a netdev where
2503 * we need the dev_put() for the netdev to really be freed.
2504 */
2505 if (!wdev->netdev)
2506 info->user_ptr[1] = NULL;
2507
Hila Gonene35e4d22012-06-27 17:19:42 +03002508 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002509}
2510
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002511static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2512{
2513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2514 struct net_device *dev = info->user_ptr[1];
2515 u16 noack_map;
2516
2517 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2518 return -EINVAL;
2519
2520 if (!rdev->ops->set_noack_map)
2521 return -EOPNOTSUPP;
2522
2523 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2524
Hila Gonene35e4d22012-06-27 17:19:42 +03002525 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002526}
2527
Johannes Berg41ade002007-12-19 02:03:29 +01002528struct get_key_cookie {
2529 struct sk_buff *msg;
2530 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002531 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002532};
2533
2534static void get_key_callback(void *c, struct key_params *params)
2535{
Johannes Bergb9454e82009-07-08 13:29:08 +02002536 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002537 struct get_key_cookie *cookie = c;
2538
David S. Miller9360ffd2012-03-29 04:41:26 -04002539 if ((params->key &&
2540 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2541 params->key_len, params->key)) ||
2542 (params->seq &&
2543 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2544 params->seq_len, params->seq)) ||
2545 (params->cipher &&
2546 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2547 params->cipher)))
2548 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002549
Johannes Bergb9454e82009-07-08 13:29:08 +02002550 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2551 if (!key)
2552 goto nla_put_failure;
2553
David S. Miller9360ffd2012-03-29 04:41:26 -04002554 if ((params->key &&
2555 nla_put(cookie->msg, NL80211_KEY_DATA,
2556 params->key_len, params->key)) ||
2557 (params->seq &&
2558 nla_put(cookie->msg, NL80211_KEY_SEQ,
2559 params->seq_len, params->seq)) ||
2560 (params->cipher &&
2561 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2562 params->cipher)))
2563 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002564
David S. Miller9360ffd2012-03-29 04:41:26 -04002565 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2566 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002567
2568 nla_nest_end(cookie->msg, key);
2569
Johannes Berg41ade002007-12-19 02:03:29 +01002570 return;
2571 nla_put_failure:
2572 cookie->error = 1;
2573}
2574
2575static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2576{
Johannes Berg4c476992010-10-04 21:36:35 +02002577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002578 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002579 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002580 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002581 const u8 *mac_addr = NULL;
2582 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002583 struct get_key_cookie cookie = {
2584 .error = 0,
2585 };
2586 void *hdr;
2587 struct sk_buff *msg;
2588
2589 if (info->attrs[NL80211_ATTR_KEY_IDX])
2590 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2591
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002592 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002593 return -EINVAL;
2594
2595 if (info->attrs[NL80211_ATTR_MAC])
2596 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2597
Johannes Berge31b8212010-10-05 19:39:30 +02002598 pairwise = !!mac_addr;
2599 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2600 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2601 if (kt >= NUM_NL80211_KEYTYPES)
2602 return -EINVAL;
2603 if (kt != NL80211_KEYTYPE_GROUP &&
2604 kt != NL80211_KEYTYPE_PAIRWISE)
2605 return -EINVAL;
2606 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2607 }
2608
Johannes Berg4c476992010-10-04 21:36:35 +02002609 if (!rdev->ops->get_key)
2610 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002611
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002613 if (!msg)
2614 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002615
Eric W. Biederman15e47302012-09-07 20:12:54 +00002616 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002617 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002618 if (IS_ERR(hdr))
2619 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002620
2621 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002622 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002623
David S. Miller9360ffd2012-03-29 04:41:26 -04002624 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2625 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2626 goto nla_put_failure;
2627 if (mac_addr &&
2628 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2629 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002630
Johannes Berge31b8212010-10-05 19:39:30 +02002631 if (pairwise && mac_addr &&
2632 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2633 return -ENOENT;
2634
Hila Gonene35e4d22012-06-27 17:19:42 +03002635 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2636 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002637
2638 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002639 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002640
2641 if (cookie.error)
2642 goto nla_put_failure;
2643
2644 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002645 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002646
2647 nla_put_failure:
2648 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002649 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002650 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002651 return err;
2652}
2653
2654static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2655{
Johannes Berg4c476992010-10-04 21:36:35 +02002656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002657 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002658 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002659 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002660
Johannes Bergb9454e82009-07-08 13:29:08 +02002661 err = nl80211_parse_key(info, &key);
2662 if (err)
2663 return err;
2664
2665 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002666 return -EINVAL;
2667
Johannes Bergb9454e82009-07-08 13:29:08 +02002668 /* only support setting default key */
2669 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002670 return -EINVAL;
2671
Johannes Bergfffd0932009-07-08 14:22:54 +02002672 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002673
2674 if (key.def) {
2675 if (!rdev->ops->set_default_key) {
2676 err = -EOPNOTSUPP;
2677 goto out;
2678 }
2679
2680 err = nl80211_key_allowed(dev->ieee80211_ptr);
2681 if (err)
2682 goto out;
2683
Hila Gonene35e4d22012-06-27 17:19:42 +03002684 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002685 key.def_uni, key.def_multi);
2686
2687 if (err)
2688 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002689
Johannes Berg3d23e342009-09-29 23:27:28 +02002690#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002691 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002692#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002693 } else {
2694 if (key.def_uni || !key.def_multi) {
2695 err = -EINVAL;
2696 goto out;
2697 }
2698
2699 if (!rdev->ops->set_default_mgmt_key) {
2700 err = -EOPNOTSUPP;
2701 goto out;
2702 }
2703
2704 err = nl80211_key_allowed(dev->ieee80211_ptr);
2705 if (err)
2706 goto out;
2707
Hila Gonene35e4d22012-06-27 17:19:42 +03002708 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002709 if (err)
2710 goto out;
2711
2712#ifdef CONFIG_CFG80211_WEXT
2713 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2714#endif
2715 }
2716
2717 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002718 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002719
Johannes Berg41ade002007-12-19 02:03:29 +01002720 return err;
2721}
2722
2723static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2724{
Johannes Berg4c476992010-10-04 21:36:35 +02002725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002726 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002727 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002728 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002729 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002730
Johannes Bergb9454e82009-07-08 13:29:08 +02002731 err = nl80211_parse_key(info, &key);
2732 if (err)
2733 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002734
Johannes Bergb9454e82009-07-08 13:29:08 +02002735 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002736 return -EINVAL;
2737
Johannes Berg41ade002007-12-19 02:03:29 +01002738 if (info->attrs[NL80211_ATTR_MAC])
2739 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2740
Johannes Berge31b8212010-10-05 19:39:30 +02002741 if (key.type == -1) {
2742 if (mac_addr)
2743 key.type = NL80211_KEYTYPE_PAIRWISE;
2744 else
2745 key.type = NL80211_KEYTYPE_GROUP;
2746 }
2747
2748 /* for now */
2749 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2750 key.type != NL80211_KEYTYPE_GROUP)
2751 return -EINVAL;
2752
Johannes Berg4c476992010-10-04 21:36:35 +02002753 if (!rdev->ops->add_key)
2754 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002755
Johannes Berge31b8212010-10-05 19:39:30 +02002756 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2757 key.type == NL80211_KEYTYPE_PAIRWISE,
2758 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002759 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002760
2761 wdev_lock(dev->ieee80211_ptr);
2762 err = nl80211_key_allowed(dev->ieee80211_ptr);
2763 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002764 err = rdev_add_key(rdev, dev, key.idx,
2765 key.type == NL80211_KEYTYPE_PAIRWISE,
2766 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002767 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002768
Johannes Berg41ade002007-12-19 02:03:29 +01002769 return err;
2770}
2771
2772static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2773{
Johannes Berg4c476992010-10-04 21:36:35 +02002774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002775 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002776 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002777 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002778 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002779
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 err = nl80211_parse_key(info, &key);
2781 if (err)
2782 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002783
2784 if (info->attrs[NL80211_ATTR_MAC])
2785 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2786
Johannes Berge31b8212010-10-05 19:39:30 +02002787 if (key.type == -1) {
2788 if (mac_addr)
2789 key.type = NL80211_KEYTYPE_PAIRWISE;
2790 else
2791 key.type = NL80211_KEYTYPE_GROUP;
2792 }
2793
2794 /* for now */
2795 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2796 key.type != NL80211_KEYTYPE_GROUP)
2797 return -EINVAL;
2798
Johannes Berg4c476992010-10-04 21:36:35 +02002799 if (!rdev->ops->del_key)
2800 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002801
Johannes Bergfffd0932009-07-08 14:22:54 +02002802 wdev_lock(dev->ieee80211_ptr);
2803 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002804
2805 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2806 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2807 err = -ENOENT;
2808
Johannes Bergfffd0932009-07-08 14:22:54 +02002809 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002810 err = rdev_del_key(rdev, dev, key.idx,
2811 key.type == NL80211_KEYTYPE_PAIRWISE,
2812 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002813
Johannes Berg3d23e342009-09-29 23:27:28 +02002814#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002815 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002816 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002817 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002819 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2820 }
2821#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002822 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002823
Johannes Berg41ade002007-12-19 02:03:29 +01002824 return err;
2825}
2826
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302827/* This function returns an error or the number of nested attributes */
2828static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2829{
2830 struct nlattr *attr;
2831 int n_entries = 0, tmp;
2832
2833 nla_for_each_nested(attr, nl_attr, tmp) {
2834 if (nla_len(attr) != ETH_ALEN)
2835 return -EINVAL;
2836
2837 n_entries++;
2838 }
2839
2840 return n_entries;
2841}
2842
2843/*
2844 * This function parses ACL information and allocates memory for ACL data.
2845 * On successful return, the calling function is responsible to free the
2846 * ACL buffer returned by this function.
2847 */
2848static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2849 struct genl_info *info)
2850{
2851 enum nl80211_acl_policy acl_policy;
2852 struct nlattr *attr;
2853 struct cfg80211_acl_data *acl;
2854 int i = 0, n_entries, tmp;
2855
2856 if (!wiphy->max_acl_mac_addrs)
2857 return ERR_PTR(-EOPNOTSUPP);
2858
2859 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2860 return ERR_PTR(-EINVAL);
2861
2862 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2863 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2864 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2865 return ERR_PTR(-EINVAL);
2866
2867 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2868 return ERR_PTR(-EINVAL);
2869
2870 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2871 if (n_entries < 0)
2872 return ERR_PTR(n_entries);
2873
2874 if (n_entries > wiphy->max_acl_mac_addrs)
2875 return ERR_PTR(-ENOTSUPP);
2876
2877 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2878 GFP_KERNEL);
2879 if (!acl)
2880 return ERR_PTR(-ENOMEM);
2881
2882 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2883 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2884 i++;
2885 }
2886
2887 acl->n_acl_entries = n_entries;
2888 acl->acl_policy = acl_policy;
2889
2890 return acl;
2891}
2892
2893static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2894{
2895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2896 struct net_device *dev = info->user_ptr[1];
2897 struct cfg80211_acl_data *acl;
2898 int err;
2899
2900 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2901 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2902 return -EOPNOTSUPP;
2903
2904 if (!dev->ieee80211_ptr->beacon_interval)
2905 return -EINVAL;
2906
2907 acl = parse_acl_data(&rdev->wiphy, info);
2908 if (IS_ERR(acl))
2909 return PTR_ERR(acl);
2910
2911 err = rdev_set_mac_acl(rdev, dev, acl);
2912
2913 kfree(acl);
2914
2915 return err;
2916}
2917
Johannes Berg88600202012-02-13 15:17:18 +01002918static int nl80211_parse_beacon(struct genl_info *info,
2919 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002920{
Johannes Berg88600202012-02-13 15:17:18 +01002921 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002922
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002923 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2924 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2925 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2926 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002927 return -EINVAL;
2928
Johannes Berg88600202012-02-13 15:17:18 +01002929 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002930
Johannes Berged1b6cc2007-12-19 02:03:32 +01002931 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002932 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2933 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2934 if (!bcn->head_len)
2935 return -EINVAL;
2936 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002937 }
2938
2939 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002940 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2941 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002942 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002943 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002944 }
2945
Johannes Berg4c476992010-10-04 21:36:35 +02002946 if (!haveinfo)
2947 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002948
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002949 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002950 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2951 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002952 }
2953
2954 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002955 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002956 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002957 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002958 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2959 }
2960
2961 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002962 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002963 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002964 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002965 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2966 }
2967
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002968 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002969 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002970 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002971 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002972 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2973 }
2974
Johannes Berg88600202012-02-13 15:17:18 +01002975 return 0;
2976}
2977
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002978static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2979 struct cfg80211_ap_settings *params)
2980{
2981 struct wireless_dev *wdev;
2982 bool ret = false;
2983
2984 mutex_lock(&rdev->devlist_mtx);
2985
Johannes Berg89a54e42012-06-15 14:33:17 +02002986 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002987 if (wdev->iftype != NL80211_IFTYPE_AP &&
2988 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2989 continue;
2990
Johannes Berg683b6d32012-11-08 21:25:48 +01002991 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002992 continue;
2993
Johannes Berg683b6d32012-11-08 21:25:48 +01002994 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002995 ret = true;
2996 break;
2997 }
2998
2999 mutex_unlock(&rdev->devlist_mtx);
3000
3001 return ret;
3002}
3003
Jouni Malinene39e5b52012-09-30 19:29:39 +03003004static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3005 enum nl80211_auth_type auth_type,
3006 enum nl80211_commands cmd)
3007{
3008 if (auth_type > NL80211_AUTHTYPE_MAX)
3009 return false;
3010
3011 switch (cmd) {
3012 case NL80211_CMD_AUTHENTICATE:
3013 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3014 auth_type == NL80211_AUTHTYPE_SAE)
3015 return false;
3016 return true;
3017 case NL80211_CMD_CONNECT:
3018 case NL80211_CMD_START_AP:
3019 /* SAE not supported yet */
3020 if (auth_type == NL80211_AUTHTYPE_SAE)
3021 return false;
3022 return true;
3023 default:
3024 return false;
3025 }
3026}
3027
Johannes Berg88600202012-02-13 15:17:18 +01003028static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3029{
3030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3031 struct net_device *dev = info->user_ptr[1];
3032 struct wireless_dev *wdev = dev->ieee80211_ptr;
3033 struct cfg80211_ap_settings params;
3034 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003035 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003036
3037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3038 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3039 return -EOPNOTSUPP;
3040
3041 if (!rdev->ops->start_ap)
3042 return -EOPNOTSUPP;
3043
3044 if (wdev->beacon_interval)
3045 return -EALREADY;
3046
3047 memset(&params, 0, sizeof(params));
3048
3049 /* these are required for START_AP */
3050 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3051 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3052 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3053 return -EINVAL;
3054
3055 err = nl80211_parse_beacon(info, &params.beacon);
3056 if (err)
3057 return err;
3058
3059 params.beacon_interval =
3060 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3061 params.dtim_period =
3062 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3063
3064 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3065 if (err)
3066 return err;
3067
3068 /*
3069 * In theory, some of these attributes should be required here
3070 * but since they were not used when the command was originally
3071 * added, keep them optional for old user space programs to let
3072 * them continue to work with drivers that do not need the
3073 * additional information -- drivers must check!
3074 */
3075 if (info->attrs[NL80211_ATTR_SSID]) {
3076 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3077 params.ssid_len =
3078 nla_len(info->attrs[NL80211_ATTR_SSID]);
3079 if (params.ssid_len == 0 ||
3080 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3081 return -EINVAL;
3082 }
3083
3084 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3085 params.hidden_ssid = nla_get_u32(
3086 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3087 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3088 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3089 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3090 return -EINVAL;
3091 }
3092
3093 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3094
3095 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3096 params.auth_type = nla_get_u32(
3097 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003098 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3099 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003100 return -EINVAL;
3101 } else
3102 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3103
3104 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3105 NL80211_MAX_NR_CIPHER_SUITES);
3106 if (err)
3107 return err;
3108
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303109 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3110 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3111 return -EOPNOTSUPP;
3112 params.inactivity_timeout = nla_get_u16(
3113 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3114 }
3115
Johannes Berg53cabad2012-11-14 15:17:28 +01003116 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3117 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3118 return -EINVAL;
3119 params.p2p_ctwindow =
3120 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3121 if (params.p2p_ctwindow > 127)
3122 return -EINVAL;
3123 if (params.p2p_ctwindow != 0 &&
3124 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3125 return -EINVAL;
3126 }
3127
3128 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3129 u8 tmp;
3130
3131 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3132 return -EINVAL;
3133 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3134 if (tmp > 1)
3135 return -EINVAL;
3136 params.p2p_opp_ps = tmp;
3137 if (params.p2p_opp_ps != 0 &&
3138 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3139 return -EINVAL;
3140 }
3141
Johannes Bergaa430da2012-05-16 23:50:18 +02003142 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003143 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3144 if (err)
3145 return err;
3146 } else if (wdev->preset_chandef.chan) {
3147 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003148 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003149 return -EINVAL;
3150
Johannes Berg683b6d32012-11-08 21:25:48 +01003151 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003152 return -EINVAL;
3153
Simon Wunderlich04f39042013-02-08 18:16:19 +01003154 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3155 if (err < 0)
3156 return err;
3157 if (err) {
3158 radar_detect_width = BIT(params.chandef.width);
3159 params.radar_required = true;
3160 }
3161
Michal Kaziore4e32452012-06-29 12:47:08 +02003162 mutex_lock(&rdev->devlist_mtx);
Simon Wunderlich04f39042013-02-08 18:16:19 +01003163 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3164 params.chandef.chan,
3165 CHAN_MODE_SHARED,
3166 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003167 mutex_unlock(&rdev->devlist_mtx);
3168
3169 if (err)
3170 return err;
3171
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303172 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3173 params.acl = parse_acl_data(&rdev->wiphy, info);
3174 if (IS_ERR(params.acl))
3175 return PTR_ERR(params.acl);
3176 }
3177
Hila Gonene35e4d22012-06-27 17:19:42 +03003178 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003179 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003180 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003181 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003182 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003183 wdev->ssid_len = params.ssid_len;
3184 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003185 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303186
3187 kfree(params.acl);
3188
Johannes Berg56d18932011-05-09 18:41:15 +02003189 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003190}
3191
Johannes Berg88600202012-02-13 15:17:18 +01003192static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3193{
3194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3195 struct net_device *dev = info->user_ptr[1];
3196 struct wireless_dev *wdev = dev->ieee80211_ptr;
3197 struct cfg80211_beacon_data params;
3198 int err;
3199
3200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3202 return -EOPNOTSUPP;
3203
3204 if (!rdev->ops->change_beacon)
3205 return -EOPNOTSUPP;
3206
3207 if (!wdev->beacon_interval)
3208 return -EINVAL;
3209
3210 err = nl80211_parse_beacon(info, &params);
3211 if (err)
3212 return err;
3213
Hila Gonene35e4d22012-06-27 17:19:42 +03003214 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003215}
3216
3217static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003218{
Johannes Berg4c476992010-10-04 21:36:35 +02003219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3220 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003221
Michal Kazior60771782012-06-29 12:46:56 +02003222 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003223}
3224
Johannes Berg5727ef12007-12-19 02:03:34 +01003225static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3226 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3227 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3228 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003229 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003230 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003231 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003232};
3233
Johannes Bergeccb8e82009-05-11 21:57:56 +03003234static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003235 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003236 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003237{
3238 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003239 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003240 int flag;
3241
Johannes Bergeccb8e82009-05-11 21:57:56 +03003242 /*
3243 * Try parsing the new attribute first so userspace
3244 * can specify both for older kernels.
3245 */
3246 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3247 if (nla) {
3248 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003249
Johannes Bergeccb8e82009-05-11 21:57:56 +03003250 sta_flags = nla_data(nla);
3251 params->sta_flags_mask = sta_flags->mask;
3252 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003253 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003254 if ((params->sta_flags_mask |
3255 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3256 return -EINVAL;
3257 return 0;
3258 }
3259
3260 /* if present, parse the old attribute */
3261
3262 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003263 if (!nla)
3264 return 0;
3265
3266 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3267 nla, sta_flags_policy))
3268 return -EINVAL;
3269
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003270 /*
3271 * Only allow certain flags for interface types so that
3272 * other attributes are silently ignored. Remember that
3273 * this is backward compatibility code with old userspace
3274 * and shouldn't be hit in other cases anyway.
3275 */
3276 switch (iftype) {
3277 case NL80211_IFTYPE_AP:
3278 case NL80211_IFTYPE_AP_VLAN:
3279 case NL80211_IFTYPE_P2P_GO:
3280 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3281 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3282 BIT(NL80211_STA_FLAG_WME) |
3283 BIT(NL80211_STA_FLAG_MFP);
3284 break;
3285 case NL80211_IFTYPE_P2P_CLIENT:
3286 case NL80211_IFTYPE_STATION:
3287 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3288 BIT(NL80211_STA_FLAG_TDLS_PEER);
3289 break;
3290 case NL80211_IFTYPE_MESH_POINT:
3291 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3292 BIT(NL80211_STA_FLAG_MFP) |
3293 BIT(NL80211_STA_FLAG_AUTHORIZED);
3294 default:
3295 return -EINVAL;
3296 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003297
Johannes Berg3383b5a2012-05-10 20:14:43 +02003298 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3299 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003300 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003301
Johannes Berg3383b5a2012-05-10 20:14:43 +02003302 /* no longer support new API additions in old API */
3303 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3304 return -EINVAL;
3305 }
3306 }
3307
Johannes Berg5727ef12007-12-19 02:03:34 +01003308 return 0;
3309}
3310
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003311static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3312 int attr)
3313{
3314 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003315 u32 bitrate;
3316 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003317
3318 rate = nla_nest_start(msg, attr);
3319 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003320 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003321
3322 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3323 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003324 /* report 16-bit bitrate only if we can */
3325 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003326 if (bitrate > 0 &&
3327 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3328 return false;
3329 if (bitrate_compat > 0 &&
3330 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3331 return false;
3332
3333 if (info->flags & RATE_INFO_FLAGS_MCS) {
3334 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3335 return false;
3336 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3337 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3338 return false;
3339 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3340 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3341 return false;
3342 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3343 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3344 return false;
3345 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3346 return false;
3347 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3348 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3349 return false;
3350 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3351 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3352 return false;
3353 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3354 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3355 return false;
3356 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3357 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3358 return false;
3359 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3360 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3361 return false;
3362 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003363
3364 nla_nest_end(msg, rate);
3365 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003366}
3367
Eric W. Biederman15e47302012-09-07 20:12:54 +00003368static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003369 int flags,
3370 struct cfg80211_registered_device *rdev,
3371 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003372 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003373{
3374 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003375 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003376
Eric W. Biederman15e47302012-09-07 20:12:54 +00003377 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003378 if (!hdr)
3379 return -1;
3380
David S. Miller9360ffd2012-03-29 04:41:26 -04003381 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3382 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3383 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3384 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003385
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003386 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3387 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003388 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003389 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3390 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3391 sinfo->connected_time))
3392 goto nla_put_failure;
3393 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3394 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3395 sinfo->inactive_time))
3396 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003397 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3398 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003399 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003400 (u32)sinfo->rx_bytes))
3401 goto nla_put_failure;
3402 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3403 NL80211_STA_INFO_TX_BYTES64)) &&
3404 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3405 (u32)sinfo->tx_bytes))
3406 goto nla_put_failure;
3407 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3408 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003409 sinfo->rx_bytes))
3410 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003411 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3412 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003413 sinfo->tx_bytes))
3414 goto nla_put_failure;
3415 if ((sinfo->filled & STATION_INFO_LLID) &&
3416 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3417 goto nla_put_failure;
3418 if ((sinfo->filled & STATION_INFO_PLID) &&
3419 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3420 goto nla_put_failure;
3421 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3422 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3423 sinfo->plink_state))
3424 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003425 switch (rdev->wiphy.signal_type) {
3426 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003427 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3428 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3429 sinfo->signal))
3430 goto nla_put_failure;
3431 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3432 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3433 sinfo->signal_avg))
3434 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003435 break;
3436 default:
3437 break;
3438 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003439 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003440 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3441 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003442 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003443 }
3444 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3445 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3446 NL80211_STA_INFO_RX_BITRATE))
3447 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003448 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003449 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3450 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3451 sinfo->rx_packets))
3452 goto nla_put_failure;
3453 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3454 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3455 sinfo->tx_packets))
3456 goto nla_put_failure;
3457 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3458 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3459 sinfo->tx_retries))
3460 goto nla_put_failure;
3461 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3462 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3463 sinfo->tx_failed))
3464 goto nla_put_failure;
3465 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3466 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3467 sinfo->beacon_loss_count))
3468 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003469 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3470 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3471 sinfo->local_pm))
3472 goto nla_put_failure;
3473 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3474 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3475 sinfo->peer_pm))
3476 goto nla_put_failure;
3477 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3478 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3479 sinfo->nonpeer_pm))
3480 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003481 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3482 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3483 if (!bss_param)
3484 goto nla_put_failure;
3485
David S. Miller9360ffd2012-03-29 04:41:26 -04003486 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3487 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3488 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3489 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3490 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3491 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3492 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3493 sinfo->bss_param.dtim_period) ||
3494 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3495 sinfo->bss_param.beacon_interval))
3496 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003497
3498 nla_nest_end(msg, bss_param);
3499 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003500 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3501 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3502 sizeof(struct nl80211_sta_flag_update),
3503 &sinfo->sta_flags))
3504 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003505 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3506 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3507 sinfo->t_offset))
3508 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003509 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003510
David S. Miller9360ffd2012-03-29 04:41:26 -04003511 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3512 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3513 sinfo->assoc_req_ies))
3514 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003515
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003516 return genlmsg_end(msg, hdr);
3517
3518 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003519 genlmsg_cancel(msg, hdr);
3520 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003521}
3522
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003523static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003524 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003525{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526 struct station_info sinfo;
3527 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003528 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003529 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003530 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003531 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003532
Johannes Berg67748892010-10-04 21:14:06 +02003533 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3534 if (err)
3535 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003536
3537 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003538 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 goto out_err;
3540 }
3541
Johannes Bergbba95fe2008-07-29 13:22:51 +02003542 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003543 memset(&sinfo, 0, sizeof(sinfo));
Hila Gonene35e4d22012-06-27 17:19:42 +03003544 err = rdev_dump_station(dev, netdev, sta_idx,
3545 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003546 if (err == -ENOENT)
3547 break;
3548 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003549 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003550
3551 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003552 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04003554 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003555 &sinfo) < 0)
3556 goto out;
3557
3558 sta_idx++;
3559 }
3560
3561
3562 out:
3563 cb->args[1] = sta_idx;
3564 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003565 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003566 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003567
3568 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003570
Johannes Berg5727ef12007-12-19 02:03:34 +01003571static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3572{
Johannes Berg4c476992010-10-04 21:36:35 +02003573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3574 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003575 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003576 struct sk_buff *msg;
3577 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003578 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003579
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003580 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003581
3582 if (!info->attrs[NL80211_ATTR_MAC])
3583 return -EINVAL;
3584
3585 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3586
Johannes Berg4c476992010-10-04 21:36:35 +02003587 if (!rdev->ops->get_station)
3588 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589
Hila Gonene35e4d22012-06-27 17:19:42 +03003590 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003592 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003595 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003596 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003597
Eric W. Biederman15e47302012-09-07 20:12:54 +00003598 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003599 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003600 nlmsg_free(msg);
3601 return -ENOBUFS;
3602 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003603
Johannes Berg4c476992010-10-04 21:36:35 +02003604 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003605}
3606
Johannes Berg77ee7c82013-02-15 00:48:33 +01003607int cfg80211_check_station_change(struct wiphy *wiphy,
3608 struct station_parameters *params,
3609 enum cfg80211_station_type statype)
3610{
3611 if (params->listen_interval != -1)
3612 return -EINVAL;
3613 if (params->aid)
3614 return -EINVAL;
3615
3616 /* When you run into this, adjust the code below for the new flag */
3617 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3618
3619 switch (statype) {
3620 case CFG80211_STA_MESH_PEER_NONSEC:
3621 case CFG80211_STA_MESH_PEER_SECURE:
3622 /*
3623 * No ignoring the TDLS flag here -- the userspace mesh
3624 * code doesn't have the bug of including TDLS in the
3625 * mask everywhere.
3626 */
3627 if (params->sta_flags_mask &
3628 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3629 BIT(NL80211_STA_FLAG_MFP) |
3630 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3631 return -EINVAL;
3632 break;
3633 case CFG80211_STA_TDLS_PEER_SETUP:
3634 case CFG80211_STA_TDLS_PEER_ACTIVE:
3635 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3636 return -EINVAL;
3637 /* ignore since it can't change */
3638 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3639 break;
3640 default:
3641 /* disallow mesh-specific things */
3642 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3643 return -EINVAL;
3644 if (params->local_pm)
3645 return -EINVAL;
3646 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3647 return -EINVAL;
3648 }
3649
3650 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3651 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3652 /* TDLS can't be set, ... */
3653 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3654 return -EINVAL;
3655 /*
3656 * ... but don't bother the driver with it. This works around
3657 * a hostapd/wpa_supplicant issue -- it always includes the
3658 * TLDS_PEER flag in the mask even for AP mode.
3659 */
3660 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3661 }
3662
3663 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3664 /* reject other things that can't change */
3665 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3666 return -EINVAL;
3667 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3668 return -EINVAL;
3669 if (params->supported_rates)
3670 return -EINVAL;
3671 if (params->ext_capab || params->ht_capa || params->vht_capa)
3672 return -EINVAL;
3673 }
3674
3675 if (statype != CFG80211_STA_AP_CLIENT) {
3676 if (params->vlan)
3677 return -EINVAL;
3678 }
3679
3680 switch (statype) {
3681 case CFG80211_STA_AP_MLME_CLIENT:
3682 /* Use this only for authorizing/unauthorizing a station */
3683 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3684 return -EOPNOTSUPP;
3685 break;
3686 case CFG80211_STA_AP_CLIENT:
3687 /* accept only the listed bits */
3688 if (params->sta_flags_mask &
3689 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3690 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3691 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3692 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3693 BIT(NL80211_STA_FLAG_WME) |
3694 BIT(NL80211_STA_FLAG_MFP)))
3695 return -EINVAL;
3696
3697 /* but authenticated/associated only if driver handles it */
3698 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3699 params->sta_flags_mask &
3700 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3701 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3702 return -EINVAL;
3703 break;
3704 case CFG80211_STA_IBSS:
3705 case CFG80211_STA_AP_STA:
3706 /* reject any changes other than AUTHORIZED */
3707 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3708 return -EINVAL;
3709 break;
3710 case CFG80211_STA_TDLS_PEER_SETUP:
3711 /* reject any changes other than AUTHORIZED or WME */
3712 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3713 BIT(NL80211_STA_FLAG_WME)))
3714 return -EINVAL;
3715 /* force (at least) rates when authorizing */
3716 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3717 !params->supported_rates)
3718 return -EINVAL;
3719 break;
3720 case CFG80211_STA_TDLS_PEER_ACTIVE:
3721 /* reject any changes */
3722 return -EINVAL;
3723 case CFG80211_STA_MESH_PEER_NONSEC:
3724 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3725 return -EINVAL;
3726 break;
3727 case CFG80211_STA_MESH_PEER_SECURE:
3728 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3729 return -EINVAL;
3730 break;
3731 }
3732
3733 return 0;
3734}
3735EXPORT_SYMBOL(cfg80211_check_station_change);
3736
Johannes Berg5727ef12007-12-19 02:03:34 +01003737/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003738 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003739 */
Johannes Berg80b99892011-11-18 16:23:01 +01003740static struct net_device *get_vlan(struct genl_info *info,
3741 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003742{
Johannes Berg463d0182009-07-14 00:33:35 +02003743 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003744 struct net_device *v;
3745 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003746
Johannes Berg80b99892011-11-18 16:23:01 +01003747 if (!vlanattr)
3748 return NULL;
3749
3750 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3751 if (!v)
3752 return ERR_PTR(-ENODEV);
3753
3754 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3755 ret = -EINVAL;
3756 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003757 }
Johannes Berg80b99892011-11-18 16:23:01 +01003758
Johannes Berg77ee7c82013-02-15 00:48:33 +01003759 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3760 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3761 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3762 ret = -EINVAL;
3763 goto error;
3764 }
3765
Johannes Berg80b99892011-11-18 16:23:01 +01003766 if (!netif_running(v)) {
3767 ret = -ENETDOWN;
3768 goto error;
3769 }
3770
3771 return v;
3772 error:
3773 dev_put(v);
3774 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003775}
3776
Jouni Malinendf881292013-02-14 21:10:54 +02003777static struct nla_policy
3778nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3779 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3780 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3781};
3782
Johannes Bergff276692013-02-15 00:09:01 +01003783static int nl80211_parse_sta_wme(struct genl_info *info,
3784 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003785{
Jouni Malinendf881292013-02-14 21:10:54 +02003786 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3787 struct nlattr *nla;
3788 int err;
3789
Jouni Malinendf881292013-02-14 21:10:54 +02003790 /* parse WME attributes if present */
3791 if (!info->attrs[NL80211_ATTR_STA_WME])
3792 return 0;
3793
3794 nla = info->attrs[NL80211_ATTR_STA_WME];
3795 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3796 nl80211_sta_wme_policy);
3797 if (err)
3798 return err;
3799
3800 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3801 params->uapsd_queues = nla_get_u8(
3802 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3803 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3804 return -EINVAL;
3805
3806 if (tb[NL80211_STA_WME_MAX_SP])
3807 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3808
3809 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3810 return -EINVAL;
3811
3812 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3813
3814 return 0;
3815}
3816
Johannes Bergff276692013-02-15 00:09:01 +01003817static int nl80211_set_station_tdls(struct genl_info *info,
3818 struct station_parameters *params)
3819{
3820 /* Dummy STA entry gets updated once the peer capabilities are known */
3821 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3822 params->ht_capa =
3823 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3824 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3825 params->vht_capa =
3826 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3827
3828 return nl80211_parse_sta_wme(info, params);
3829}
3830
Johannes Berg5727ef12007-12-19 02:03:34 +01003831static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3832{
Johannes Berg4c476992010-10-04 21:36:35 +02003833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003834 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003835 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003836 u8 *mac_addr;
3837 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003838
3839 memset(&params, 0, sizeof(params));
3840
3841 params.listen_interval = -1;
3842
Johannes Berg77ee7c82013-02-15 00:48:33 +01003843 if (!rdev->ops->change_station)
3844 return -EOPNOTSUPP;
3845
Johannes Berg5727ef12007-12-19 02:03:34 +01003846 if (info->attrs[NL80211_ATTR_STA_AID])
3847 return -EINVAL;
3848
3849 if (!info->attrs[NL80211_ATTR_MAC])
3850 return -EINVAL;
3851
3852 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3853
3854 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3855 params.supported_rates =
3856 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3857 params.supported_rates_len =
3858 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3859 }
3860
Jouni Malinen9d62a982013-02-14 21:10:13 +02003861 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3862 params.capability =
3863 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3864 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3865 }
3866
3867 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3868 params.ext_capab =
3869 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3870 params.ext_capab_len =
3871 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3872 }
3873
Jouni Malinendf881292013-02-14 21:10:54 +02003874 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003875 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003876
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003877 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003878 return -EINVAL;
3879
Johannes Bergf8bacc22013-02-14 23:27:01 +01003880 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003881 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003882 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3883 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3884 return -EINVAL;
3885 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003886
Johannes Bergf8bacc22013-02-14 23:27:01 +01003887 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003888 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003889 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3890 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3891 return -EINVAL;
3892 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3893 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003894
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003895 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3896 enum nl80211_mesh_power_mode pm = nla_get_u32(
3897 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3898
3899 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3900 pm > NL80211_MESH_POWER_MAX)
3901 return -EINVAL;
3902
3903 params.local_pm = pm;
3904 }
3905
Johannes Berg77ee7c82013-02-15 00:48:33 +01003906 /* Include parameters for TDLS peer (will check later) */
3907 err = nl80211_set_station_tdls(info, &params);
3908 if (err)
3909 return err;
3910
3911 params.vlan = get_vlan(info, rdev);
3912 if (IS_ERR(params.vlan))
3913 return PTR_ERR(params.vlan);
3914
Johannes Berga97f4422009-06-18 17:23:43 +02003915 switch (dev->ieee80211_ptr->iftype) {
3916 case NL80211_IFTYPE_AP:
3917 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003918 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003919 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003920 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003921 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003922 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003923 break;
3924 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003925 err = -EOPNOTSUPP;
3926 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003927 }
3928
Johannes Berg77ee7c82013-02-15 00:48:33 +01003929 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003930 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003931
Johannes Berg77ee7c82013-02-15 00:48:33 +01003932 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003933 if (params.vlan)
3934 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003935
Johannes Berg5727ef12007-12-19 02:03:34 +01003936 return err;
3937}
3938
3939static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3940{
Johannes Berg4c476992010-10-04 21:36:35 +02003941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003942 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003943 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003944 struct station_parameters params;
3945 u8 *mac_addr = NULL;
3946
3947 memset(&params, 0, sizeof(params));
3948
Johannes Berg984c3112013-02-14 23:43:25 +01003949 if (!rdev->ops->add_station)
3950 return -EOPNOTSUPP;
3951
Johannes Berg5727ef12007-12-19 02:03:34 +01003952 if (!info->attrs[NL80211_ATTR_MAC])
3953 return -EINVAL;
3954
Johannes Berg5727ef12007-12-19 02:03:34 +01003955 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3956 return -EINVAL;
3957
3958 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3959 return -EINVAL;
3960
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003961 if (!info->attrs[NL80211_ATTR_STA_AID])
3962 return -EINVAL;
3963
Johannes Berg5727ef12007-12-19 02:03:34 +01003964 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3965 params.supported_rates =
3966 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3967 params.supported_rates_len =
3968 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3969 params.listen_interval =
3970 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003971
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003972 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3973 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3974 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003975
Jouni Malinen9d62a982013-02-14 21:10:13 +02003976 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3977 params.capability =
3978 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3979 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3980 }
3981
3982 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3983 params.ext_capab =
3984 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3985 params.ext_capab_len =
3986 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3987 }
3988
Jouni Malinen36aedc92008-08-25 11:58:58 +03003989 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3990 params.ht_capa =
3991 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003992
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003993 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3994 params.vht_capa =
3995 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3996
Johannes Bergf8bacc22013-02-14 23:27:01 +01003997 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07003998 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003999 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4000 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4001 return -EINVAL;
4002 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004003
Johannes Bergff276692013-02-15 00:09:01 +01004004 err = nl80211_parse_sta_wme(info, &params);
4005 if (err)
4006 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004007
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004008 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004009 return -EINVAL;
4010
Johannes Berg77ee7c82013-02-15 00:48:33 +01004011 /* When you run into this, adjust the code below for the new flag */
4012 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4013
Johannes Bergbdd90d52011-12-14 12:20:27 +01004014 switch (dev->ieee80211_ptr->iftype) {
4015 case NL80211_IFTYPE_AP:
4016 case NL80211_IFTYPE_AP_VLAN:
4017 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004018 /* ignore WME attributes if iface/sta is not capable */
4019 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4020 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4021 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004022
Johannes Bergbdd90d52011-12-14 12:20:27 +01004023 /* TDLS peers cannot be added */
4024 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004025 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004026 /* but don't bother the driver with it */
4027 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004028
Johannes Bergd582cff2012-10-26 17:53:44 +02004029 /* allow authenticated/associated only if driver handles it */
4030 if (!(rdev->wiphy.features &
4031 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4032 params.sta_flags_mask &
4033 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4034 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4035 return -EINVAL;
4036
Johannes Bergbdd90d52011-12-14 12:20:27 +01004037 /* must be last in here for error handling */
4038 params.vlan = get_vlan(info, rdev);
4039 if (IS_ERR(params.vlan))
4040 return PTR_ERR(params.vlan);
4041 break;
4042 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004043 /* ignore uAPSD data */
4044 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4045
Johannes Bergd582cff2012-10-26 17:53:44 +02004046 /* associated is disallowed */
4047 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4048 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004049 /* TDLS peers cannot be added */
4050 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004051 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004052 break;
4053 case NL80211_IFTYPE_STATION:
Johannes Berg984c3112013-02-14 23:43:25 +01004054 /* ignore uAPSD data */
4055 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4056
Johannes Berg77ee7c82013-02-15 00:48:33 +01004057 /* these are disallowed */
4058 if (params.sta_flags_mask &
4059 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4060 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004061 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004062 /* Only TDLS peers can be added */
4063 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4064 return -EINVAL;
4065 /* Can only add if TDLS ... */
4066 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4067 return -EOPNOTSUPP;
4068 /* ... with external setup is supported */
4069 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4070 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004071 /*
4072 * Older wpa_supplicant versions always mark the TDLS peer
4073 * as authorized, but it shouldn't yet be.
4074 */
4075 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004076 break;
4077 default:
4078 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004079 }
4080
Johannes Bergbdd90d52011-12-14 12:20:27 +01004081 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004082
Hila Gonene35e4d22012-06-27 17:19:42 +03004083 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004084
Johannes Berg5727ef12007-12-19 02:03:34 +01004085 if (params.vlan)
4086 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004087 return err;
4088}
4089
4090static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4091{
Johannes Berg4c476992010-10-04 21:36:35 +02004092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4093 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004094 u8 *mac_addr = NULL;
4095
4096 if (info->attrs[NL80211_ATTR_MAC])
4097 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4098
Johannes Berge80cf852009-05-11 14:43:13 +02004099 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004100 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004101 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4103 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004104
Johannes Berg4c476992010-10-04 21:36:35 +02004105 if (!rdev->ops->del_station)
4106 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004107
Hila Gonene35e4d22012-06-27 17:19:42 +03004108 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004109}
4110
Eric W. Biederman15e47302012-09-07 20:12:54 +00004111static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004112 int flags, struct net_device *dev,
4113 u8 *dst, u8 *next_hop,
4114 struct mpath_info *pinfo)
4115{
4116 void *hdr;
4117 struct nlattr *pinfoattr;
4118
Eric W. Biederman15e47302012-09-07 20:12:54 +00004119 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004120 if (!hdr)
4121 return -1;
4122
David S. Miller9360ffd2012-03-29 04:41:26 -04004123 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4124 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4125 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4126 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4127 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004128
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004129 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4130 if (!pinfoattr)
4131 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004132 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4133 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4134 pinfo->frame_qlen))
4135 goto nla_put_failure;
4136 if (((pinfo->filled & MPATH_INFO_SN) &&
4137 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4138 ((pinfo->filled & MPATH_INFO_METRIC) &&
4139 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4140 pinfo->metric)) ||
4141 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4142 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4143 pinfo->exptime)) ||
4144 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4145 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4146 pinfo->flags)) ||
4147 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4148 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4149 pinfo->discovery_timeout)) ||
4150 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4151 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4152 pinfo->discovery_retries)))
4153 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004154
4155 nla_nest_end(msg, pinfoattr);
4156
4157 return genlmsg_end(msg, hdr);
4158
4159 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004160 genlmsg_cancel(msg, hdr);
4161 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004162}
4163
4164static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004165 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004166{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004167 struct mpath_info pinfo;
4168 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004169 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004170 u8 dst[ETH_ALEN];
4171 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02004172 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004173 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004174
Johannes Berg67748892010-10-04 21:14:06 +02004175 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4176 if (err)
4177 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004178
4179 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004180 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004181 goto out_err;
4182 }
4183
Jouni Malineneec60b02009-03-20 21:21:19 +02004184 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
4185 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004186 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004187 }
4188
Johannes Bergbba95fe2008-07-29 13:22:51 +02004189 while (1) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004190 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
4191 &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004192 if (err == -ENOENT)
4193 break;
4194 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004195 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004196
Eric W. Biederman15e47302012-09-07 20:12:54 +00004197 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004198 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4199 netdev, dst, next_hop,
4200 &pinfo) < 0)
4201 goto out;
4202
4203 path_idx++;
4204 }
4205
4206
4207 out:
4208 cb->args[1] = path_idx;
4209 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004210 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004211 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004212 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004213}
4214
4215static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4216{
Johannes Berg4c476992010-10-04 21:36:35 +02004217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004218 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004219 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004220 struct mpath_info pinfo;
4221 struct sk_buff *msg;
4222 u8 *dst = NULL;
4223 u8 next_hop[ETH_ALEN];
4224
4225 memset(&pinfo, 0, sizeof(pinfo));
4226
4227 if (!info->attrs[NL80211_ATTR_MAC])
4228 return -EINVAL;
4229
4230 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4231
Johannes Berg4c476992010-10-04 21:36:35 +02004232 if (!rdev->ops->get_mpath)
4233 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004234
Johannes Berg4c476992010-10-04 21:36:35 +02004235 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4236 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004237
Hila Gonene35e4d22012-06-27 17:19:42 +03004238 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004239 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004240 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004241
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004243 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004244 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004245
Eric W. Biederman15e47302012-09-07 20:12:54 +00004246 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004247 dev, dst, next_hop, &pinfo) < 0) {
4248 nlmsg_free(msg);
4249 return -ENOBUFS;
4250 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004251
Johannes Berg4c476992010-10-04 21:36:35 +02004252 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004253}
4254
4255static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4256{
Johannes Berg4c476992010-10-04 21:36:35 +02004257 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4258 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004259 u8 *dst = NULL;
4260 u8 *next_hop = NULL;
4261
4262 if (!info->attrs[NL80211_ATTR_MAC])
4263 return -EINVAL;
4264
4265 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4266 return -EINVAL;
4267
4268 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4269 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4270
Johannes Berg4c476992010-10-04 21:36:35 +02004271 if (!rdev->ops->change_mpath)
4272 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004273
Johannes Berg4c476992010-10-04 21:36:35 +02004274 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4275 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004276
Hila Gonene35e4d22012-06-27 17:19:42 +03004277 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004278}
Johannes Berg4c476992010-10-04 21:36:35 +02004279
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004280static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4281{
Johannes Berg4c476992010-10-04 21:36:35 +02004282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4283 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004284 u8 *dst = NULL;
4285 u8 *next_hop = NULL;
4286
4287 if (!info->attrs[NL80211_ATTR_MAC])
4288 return -EINVAL;
4289
4290 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4291 return -EINVAL;
4292
4293 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4294 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4295
Johannes Berg4c476992010-10-04 21:36:35 +02004296 if (!rdev->ops->add_mpath)
4297 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004298
Johannes Berg4c476992010-10-04 21:36:35 +02004299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4300 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004301
Hila Gonene35e4d22012-06-27 17:19:42 +03004302 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004303}
4304
4305static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4306{
Johannes Berg4c476992010-10-04 21:36:35 +02004307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4308 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004309 u8 *dst = NULL;
4310
4311 if (info->attrs[NL80211_ATTR_MAC])
4312 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4313
Johannes Berg4c476992010-10-04 21:36:35 +02004314 if (!rdev->ops->del_mpath)
4315 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004316
Hila Gonene35e4d22012-06-27 17:19:42 +03004317 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004318}
4319
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004320static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4321{
Johannes Berg4c476992010-10-04 21:36:35 +02004322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4323 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004324 struct bss_parameters params;
4325
4326 memset(&params, 0, sizeof(params));
4327 /* default to not changing parameters */
4328 params.use_cts_prot = -1;
4329 params.use_short_preamble = -1;
4330 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004331 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004332 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004333 params.p2p_ctwindow = -1;
4334 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004335
4336 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4337 params.use_cts_prot =
4338 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4339 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4340 params.use_short_preamble =
4341 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4342 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4343 params.use_short_slot_time =
4344 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004345 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4346 params.basic_rates =
4347 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4348 params.basic_rates_len =
4349 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4350 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004351 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4352 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004353 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4354 params.ht_opmode =
4355 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004356
Johannes Berg53cabad2012-11-14 15:17:28 +01004357 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4358 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4359 return -EINVAL;
4360 params.p2p_ctwindow =
4361 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4362 if (params.p2p_ctwindow < 0)
4363 return -EINVAL;
4364 if (params.p2p_ctwindow != 0 &&
4365 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4366 return -EINVAL;
4367 }
4368
4369 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4370 u8 tmp;
4371
4372 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4373 return -EINVAL;
4374 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4375 if (tmp > 1)
4376 return -EINVAL;
4377 params.p2p_opp_ps = tmp;
4378 if (params.p2p_opp_ps &&
4379 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4380 return -EINVAL;
4381 }
4382
Johannes Berg4c476992010-10-04 21:36:35 +02004383 if (!rdev->ops->change_bss)
4384 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004385
Johannes Berg074ac8d2010-09-16 14:58:22 +02004386 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004387 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4388 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004389
Hila Gonene35e4d22012-06-27 17:19:42 +03004390 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004391}
4392
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004393static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004394 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4395 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4396 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4397 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4398 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4399 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4400};
4401
4402static int parse_reg_rule(struct nlattr *tb[],
4403 struct ieee80211_reg_rule *reg_rule)
4404{
4405 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4406 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4407
4408 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4409 return -EINVAL;
4410 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4411 return -EINVAL;
4412 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4413 return -EINVAL;
4414 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4415 return -EINVAL;
4416 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4417 return -EINVAL;
4418
4419 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4420
4421 freq_range->start_freq_khz =
4422 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4423 freq_range->end_freq_khz =
4424 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4425 freq_range->max_bandwidth_khz =
4426 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4427
4428 power_rule->max_eirp =
4429 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4430
4431 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4432 power_rule->max_antenna_gain =
4433 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4434
4435 return 0;
4436}
4437
4438static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4439{
4440 int r;
4441 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004442 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004443
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004444 /*
4445 * You should only get this when cfg80211 hasn't yet initialized
4446 * completely when built-in to the kernel right between the time
4447 * window between nl80211_init() and regulatory_init(), if that is
4448 * even possible.
4449 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004450 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004451 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004452
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004453 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4454 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004455
4456 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4457
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004458 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4459 user_reg_hint_type =
4460 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4461 else
4462 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4463
4464 switch (user_reg_hint_type) {
4465 case NL80211_USER_REG_HINT_USER:
4466 case NL80211_USER_REG_HINT_CELL_BASE:
4467 break;
4468 default:
4469 return -EINVAL;
4470 }
4471
4472 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004473
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004474 return r;
4475}
4476
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004477static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004478 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004479{
Johannes Berg4c476992010-10-04 21:36:35 +02004480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004481 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004482 struct wireless_dev *wdev = dev->ieee80211_ptr;
4483 struct mesh_config cur_params;
4484 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004485 void *hdr;
4486 struct nlattr *pinfoattr;
4487 struct sk_buff *msg;
4488
Johannes Berg29cbe682010-12-03 09:20:44 +01004489 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4490 return -EOPNOTSUPP;
4491
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004492 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004493 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004494
Johannes Berg29cbe682010-12-03 09:20:44 +01004495 wdev_lock(wdev);
4496 /* If not connected, get default parameters */
4497 if (!wdev->mesh_id_len)
4498 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4499 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004500 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004501 wdev_unlock(wdev);
4502
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004503 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004504 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004505
4506 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004508 if (!msg)
4509 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004510 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004511 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004512 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004513 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004514 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004515 if (!pinfoattr)
4516 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004517 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4518 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4519 cur_params.dot11MeshRetryTimeout) ||
4520 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4521 cur_params.dot11MeshConfirmTimeout) ||
4522 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4523 cur_params.dot11MeshHoldingTimeout) ||
4524 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4525 cur_params.dot11MeshMaxPeerLinks) ||
4526 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4527 cur_params.dot11MeshMaxRetries) ||
4528 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4529 cur_params.dot11MeshTTL) ||
4530 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4531 cur_params.element_ttl) ||
4532 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4533 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004534 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4535 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004536 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4537 cur_params.dot11MeshHWMPmaxPREQretries) ||
4538 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4539 cur_params.path_refresh_time) ||
4540 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4541 cur_params.min_discovery_timeout) ||
4542 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4543 cur_params.dot11MeshHWMPactivePathTimeout) ||
4544 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4545 cur_params.dot11MeshHWMPpreqMinInterval) ||
4546 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4547 cur_params.dot11MeshHWMPperrMinInterval) ||
4548 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4549 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4550 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4551 cur_params.dot11MeshHWMPRootMode) ||
4552 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4553 cur_params.dot11MeshHWMPRannInterval) ||
4554 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4555 cur_params.dot11MeshGateAnnouncementProtocol) ||
4556 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4557 cur_params.dot11MeshForwarding) ||
4558 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004559 cur_params.rssi_threshold) ||
4560 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004561 cur_params.ht_opmode) ||
4562 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4563 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4564 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004565 cur_params.dot11MeshHWMProotInterval) ||
4566 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004567 cur_params.dot11MeshHWMPconfirmationInterval) ||
4568 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4569 cur_params.power_mode) ||
4570 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4571 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004572 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004573 nla_nest_end(msg, pinfoattr);
4574 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004575 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004576
Johannes Berg3b858752009-03-12 09:55:09 +01004577 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004578 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004579 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004580 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004581 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004582}
4583
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004584static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004585 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4586 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4587 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4588 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4589 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4590 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004591 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004592 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004593 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4595 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4596 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4597 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4598 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004599 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004600 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004601 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004602 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004603 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004604 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004605 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4606 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004607 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4608 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004609 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004610 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4611 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004612};
4613
Javier Cardonac80d5452010-12-16 17:37:49 -08004614static const struct nla_policy
4615 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004616 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004617 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4618 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004619 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004620 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004621 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004622 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004623};
4624
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004625static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004626 struct mesh_config *cfg,
4627 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004628{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004629 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004630 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004631
Marco Porschea54fba2013-01-07 16:04:48 +01004632#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4633do { \
4634 if (tb[attr]) { \
4635 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4636 return -EINVAL; \
4637 cfg->param = fn(tb[attr]); \
4638 mask |= (1 << (attr - 1)); \
4639 } \
4640} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004641
4642
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004643 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004644 return -EINVAL;
4645 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004646 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004647 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004648 return -EINVAL;
4649
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004650 /* This makes sure that there aren't more than 32 mesh config
4651 * parameters (otherwise our bitfield scheme would not work.) */
4652 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4653
4654 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004655 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004656 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4657 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004658 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004659 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4660 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004661 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004662 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4663 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004664 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004665 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4666 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004667 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004668 mask, NL80211_MESHCONF_MAX_RETRIES,
4669 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004670 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004671 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004673 mask, NL80211_MESHCONF_ELEMENT_TTL,
4674 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004676 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4677 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4679 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004680 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4681 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004682 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004683 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4684 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004685 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004686 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4687 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004688 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004689 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4690 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004691 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4692 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004693 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4694 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004696 1, 65535, mask,
4697 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004698 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004699 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004700 1, 65535, mask,
4701 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004702 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004703 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004704 dot11MeshHWMPnetDiameterTraversalTime,
4705 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004706 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4707 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004708 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4709 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4710 nla_get_u8);
4711 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4712 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004713 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004714 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004715 dot11MeshGateAnnouncementProtocol, 0, 1,
4716 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004717 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004719 mask, NL80211_MESHCONF_FORWARDING,
4720 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004721 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004722 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4723 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004724 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004725 mask, NL80211_MESHCONF_HT_OPMODE,
4726 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004728 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004729 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4730 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004731 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004732 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4733 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004734 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004735 dot11MeshHWMPconfirmationInterval,
4736 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004737 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4738 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004739 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4740 NL80211_MESH_POWER_ACTIVE,
4741 NL80211_MESH_POWER_MAX,
4742 mask, NL80211_MESHCONF_POWER_MODE,
4743 nla_get_u32);
4744 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4745 0, 65535, mask,
4746 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004747 if (mask_out)
4748 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004749
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004750 return 0;
4751
4752#undef FILL_IN_MESH_PARAM_IF_SET
4753}
4754
Javier Cardonac80d5452010-12-16 17:37:49 -08004755static int nl80211_parse_mesh_setup(struct genl_info *info,
4756 struct mesh_setup *setup)
4757{
4758 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4759
4760 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4761 return -EINVAL;
4762 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4763 info->attrs[NL80211_ATTR_MESH_SETUP],
4764 nl80211_mesh_setup_params_policy))
4765 return -EINVAL;
4766
Javier Cardonad299a1f2012-03-31 11:31:33 -07004767 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4768 setup->sync_method =
4769 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4770 IEEE80211_SYNC_METHOD_VENDOR :
4771 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4772
Javier Cardonac80d5452010-12-16 17:37:49 -08004773 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4774 setup->path_sel_proto =
4775 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4776 IEEE80211_PATH_PROTOCOL_VENDOR :
4777 IEEE80211_PATH_PROTOCOL_HWMP;
4778
4779 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4780 setup->path_metric =
4781 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4782 IEEE80211_PATH_METRIC_VENDOR :
4783 IEEE80211_PATH_METRIC_AIRTIME;
4784
Javier Cardona581a8b02011-04-07 15:08:27 -07004785
4786 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004787 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004788 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004789 if (!is_valid_ie_attr(ieattr))
4790 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004791 setup->ie = nla_data(ieattr);
4792 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004793 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07004794 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4795 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08004796
4797 return 0;
4798}
4799
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004800static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004801 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004802{
4803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4804 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004805 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004806 struct mesh_config cfg;
4807 u32 mask;
4808 int err;
4809
Johannes Berg29cbe682010-12-03 09:20:44 +01004810 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4811 return -EOPNOTSUPP;
4812
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004813 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004814 return -EOPNOTSUPP;
4815
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004816 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004817 if (err)
4818 return err;
4819
Johannes Berg29cbe682010-12-03 09:20:44 +01004820 wdev_lock(wdev);
4821 if (!wdev->mesh_id_len)
4822 err = -ENOLINK;
4823
4824 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004825 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004826
4827 wdev_unlock(wdev);
4828
4829 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004830}
4831
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004832static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4833{
Johannes Berg458f4f92012-12-06 15:47:38 +01004834 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004835 struct sk_buff *msg;
4836 void *hdr = NULL;
4837 struct nlattr *nl_reg_rules;
4838 unsigned int i;
4839 int err = -EINVAL;
4840
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004841 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004842
4843 if (!cfg80211_regdomain)
4844 goto out;
4845
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004846 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004847 if (!msg) {
4848 err = -ENOBUFS;
4849 goto out;
4850 }
4851
Eric W. Biederman15e47302012-09-07 20:12:54 +00004852 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004853 NL80211_CMD_GET_REG);
4854 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004855 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004856
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004857 if (reg_last_request_cell_base() &&
4858 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4859 NL80211_USER_REG_HINT_CELL_BASE))
4860 goto nla_put_failure;
4861
Johannes Berg458f4f92012-12-06 15:47:38 +01004862 rcu_read_lock();
4863 regdom = rcu_dereference(cfg80211_regdomain);
4864
4865 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4866 (regdom->dfs_region &&
4867 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4868 goto nla_put_failure_rcu;
4869
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004870 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4871 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004872 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004873
Johannes Berg458f4f92012-12-06 15:47:38 +01004874 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004875 struct nlattr *nl_reg_rule;
4876 const struct ieee80211_reg_rule *reg_rule;
4877 const struct ieee80211_freq_range *freq_range;
4878 const struct ieee80211_power_rule *power_rule;
4879
Johannes Berg458f4f92012-12-06 15:47:38 +01004880 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004881 freq_range = &reg_rule->freq_range;
4882 power_rule = &reg_rule->power_rule;
4883
4884 nl_reg_rule = nla_nest_start(msg, i);
4885 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004886 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004887
David S. Miller9360ffd2012-03-29 04:41:26 -04004888 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4889 reg_rule->flags) ||
4890 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4891 freq_range->start_freq_khz) ||
4892 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4893 freq_range->end_freq_khz) ||
4894 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4895 freq_range->max_bandwidth_khz) ||
4896 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4897 power_rule->max_antenna_gain) ||
4898 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4899 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004900 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004901
4902 nla_nest_end(msg, nl_reg_rule);
4903 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004904 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004905
4906 nla_nest_end(msg, nl_reg_rules);
4907
4908 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004909 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004910 goto out;
4911
Johannes Berg458f4f92012-12-06 15:47:38 +01004912nla_put_failure_rcu:
4913 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004914nla_put_failure:
4915 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004916put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004917 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004918 err = -EMSGSIZE;
4919out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004920 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004921 return err;
4922}
4923
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004924static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4925{
4926 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4927 struct nlattr *nl_reg_rule;
4928 char *alpha2 = NULL;
4929 int rem_reg_rules = 0, r = 0;
4930 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004931 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004932 struct ieee80211_regdomain *rd = NULL;
4933
4934 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4935 return -EINVAL;
4936
4937 if (!info->attrs[NL80211_ATTR_REG_RULES])
4938 return -EINVAL;
4939
4940 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4941
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004942 if (info->attrs[NL80211_ATTR_DFS_REGION])
4943 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4944
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004945 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004946 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004947 num_rules++;
4948 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004949 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004950 }
4951
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004952 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004953 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004954
4955 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004956 if (!rd)
4957 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004958
4959 rd->n_reg_rules = num_rules;
4960 rd->alpha2[0] = alpha2[0];
4961 rd->alpha2[1] = alpha2[1];
4962
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004963 /*
4964 * Disable DFS master mode if the DFS region was
4965 * not supported or known on this kernel.
4966 */
4967 if (reg_supported_dfs_region(dfs_region))
4968 rd->dfs_region = dfs_region;
4969
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004970 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004971 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004972 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004973 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4974 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004975 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4976 if (r)
4977 goto bad_reg;
4978
4979 rule_idx++;
4980
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004981 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4982 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004983 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004984 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004985 }
4986
Johannes Berg6913b492012-12-04 00:48:59 +01004987 mutex_lock(&cfg80211_mutex);
4988
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004989 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01004990 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01004991 rd = NULL;
Johannes Berg6913b492012-12-04 00:48:59 +01004992 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004993
Johannes Bergd2372b32008-10-24 20:32:20 +02004994 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004995 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004996 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004997}
4998
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004999static int validate_scan_freqs(struct nlattr *freqs)
5000{
5001 struct nlattr *attr1, *attr2;
5002 int n_channels = 0, tmp1, tmp2;
5003
5004 nla_for_each_nested(attr1, freqs, tmp1) {
5005 n_channels++;
5006 /*
5007 * Some hardware has a limited channel list for
5008 * scanning, and it is pretty much nonsensical
5009 * to scan for a channel twice, so disallow that
5010 * and don't require drivers to check that the
5011 * channel list they get isn't longer than what
5012 * they can scan, as long as they can scan all
5013 * the channels they registered at once.
5014 */
5015 nla_for_each_nested(attr2, freqs, tmp2)
5016 if (attr1 != attr2 &&
5017 nla_get_u32(attr1) == nla_get_u32(attr2))
5018 return 0;
5019 }
5020
5021 return n_channels;
5022}
5023
Johannes Berg2a519312009-02-10 21:25:55 +01005024static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5025{
Johannes Berg4c476992010-10-04 21:36:35 +02005026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005027 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005028 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005029 struct nlattr *attr;
5030 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005031 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005032 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005033
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005034 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5035 return -EINVAL;
5036
Johannes Berg79c97e92009-07-07 03:56:12 +02005037 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005038
Johannes Berg4c476992010-10-04 21:36:35 +02005039 if (!rdev->ops->scan)
5040 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005041
Johannes Berg4c476992010-10-04 21:36:35 +02005042 if (rdev->scan_req)
5043 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01005044
5045 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005046 n_channels = validate_scan_freqs(
5047 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02005048 if (!n_channels)
5049 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005050 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005051 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005052 n_channels = 0;
5053
Johannes Berg2a519312009-02-10 21:25:55 +01005054 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5055 if (wiphy->bands[band])
5056 n_channels += wiphy->bands[band]->n_channels;
5057 }
5058
5059 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5060 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5061 n_ssids++;
5062
Johannes Berg4c476992010-10-04 21:36:35 +02005063 if (n_ssids > wiphy->max_scan_ssids)
5064 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005065
Jouni Malinen70692ad2009-02-16 19:39:13 +02005066 if (info->attrs[NL80211_ATTR_IE])
5067 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5068 else
5069 ie_len = 0;
5070
Johannes Berg4c476992010-10-04 21:36:35 +02005071 if (ie_len > wiphy->max_scan_ie_len)
5072 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02005073
Johannes Berg2a519312009-02-10 21:25:55 +01005074 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005075 + sizeof(*request->ssids) * n_ssids
5076 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005077 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005078 if (!request)
5079 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01005080
Johannes Berg2a519312009-02-10 21:25:55 +01005081 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005082 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005083 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005084 if (ie_len) {
5085 if (request->ssids)
5086 request->ie = (void *)(request->ssids + n_ssids);
5087 else
5088 request->ie = (void *)(request->channels + n_channels);
5089 }
Johannes Berg2a519312009-02-10 21:25:55 +01005090
Johannes Berg584991d2009-11-02 13:32:03 +01005091 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005092 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5093 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005094 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005095 struct ieee80211_channel *chan;
5096
5097 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5098
5099 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005100 err = -EINVAL;
5101 goto out_free;
5102 }
Johannes Berg584991d2009-11-02 13:32:03 +01005103
5104 /* ignore disabled channels */
5105 if (chan->flags & IEEE80211_CHAN_DISABLED)
5106 continue;
5107
5108 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005109 i++;
5110 }
5111 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005112 enum ieee80211_band band;
5113
Johannes Berg2a519312009-02-10 21:25:55 +01005114 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005115 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5116 int j;
5117 if (!wiphy->bands[band])
5118 continue;
5119 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005120 struct ieee80211_channel *chan;
5121
5122 chan = &wiphy->bands[band]->channels[j];
5123
5124 if (chan->flags & IEEE80211_CHAN_DISABLED)
5125 continue;
5126
5127 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005128 i++;
5129 }
5130 }
5131 }
5132
Johannes Berg584991d2009-11-02 13:32:03 +01005133 if (!i) {
5134 err = -EINVAL;
5135 goto out_free;
5136 }
5137
5138 request->n_channels = i;
5139
Johannes Berg2a519312009-02-10 21:25:55 +01005140 i = 0;
5141 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5142 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005143 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005144 err = -EINVAL;
5145 goto out_free;
5146 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005147 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005148 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005149 i++;
5150 }
5151 }
5152
Jouni Malinen70692ad2009-02-16 19:39:13 +02005153 if (info->attrs[NL80211_ATTR_IE]) {
5154 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005155 memcpy((void *)request->ie,
5156 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005157 request->ie_len);
5158 }
5159
Johannes Berg34850ab2011-07-18 18:08:35 +02005160 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005161 if (wiphy->bands[i])
5162 request->rates[i] =
5163 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005164
5165 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5166 nla_for_each_nested(attr,
5167 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5168 tmp) {
5169 enum ieee80211_band band = nla_type(attr);
5170
Dan Carpenter84404622011-07-29 11:52:18 +03005171 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005172 err = -EINVAL;
5173 goto out_free;
5174 }
5175 err = ieee80211_get_ratemask(wiphy->bands[band],
5176 nla_data(attr),
5177 nla_len(attr),
5178 &request->rates[band]);
5179 if (err)
5180 goto out_free;
5181 }
5182 }
5183
Sam Leffler46856bb2012-10-11 21:03:32 -07005184 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005185 request->flags = nla_get_u32(
5186 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005187 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5188 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5189 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5190 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005191 err = -EOPNOTSUPP;
5192 goto out_free;
5193 }
5194 }
Sam Lefflered4737712012-10-11 21:03:31 -07005195
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305196 request->no_cck =
5197 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5198
Johannes Bergfd014282012-06-18 19:17:03 +02005199 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005200 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005201 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005202
Johannes Berg79c97e92009-07-07 03:56:12 +02005203 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005204 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005205
Johannes Berg463d0182009-07-14 00:33:35 +02005206 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005207 nl80211_send_scan_start(rdev, wdev);
5208 if (wdev->netdev)
5209 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005210 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005211 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005212 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005213 kfree(request);
5214 }
Johannes Berg3b858752009-03-12 09:55:09 +01005215
Johannes Berg2a519312009-02-10 21:25:55 +01005216 return err;
5217}
5218
Luciano Coelho807f8a82011-05-11 17:09:35 +03005219static int nl80211_start_sched_scan(struct sk_buff *skb,
5220 struct genl_info *info)
5221{
5222 struct cfg80211_sched_scan_request *request;
5223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5224 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005225 struct nlattr *attr;
5226 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005227 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005228 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005229 enum ieee80211_band band;
5230 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005231 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005232
5233 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5234 !rdev->ops->sched_scan_start)
5235 return -EOPNOTSUPP;
5236
5237 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5238 return -EINVAL;
5239
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005240 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5241 return -EINVAL;
5242
5243 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5244 if (interval == 0)
5245 return -EINVAL;
5246
Luciano Coelho807f8a82011-05-11 17:09:35 +03005247 wiphy = &rdev->wiphy;
5248
5249 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5250 n_channels = validate_scan_freqs(
5251 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5252 if (!n_channels)
5253 return -EINVAL;
5254 } else {
5255 n_channels = 0;
5256
5257 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5258 if (wiphy->bands[band])
5259 n_channels += wiphy->bands[band]->n_channels;
5260 }
5261
5262 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5263 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5264 tmp)
5265 n_ssids++;
5266
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005267 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005268 return -EINVAL;
5269
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005270 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5271 nla_for_each_nested(attr,
5272 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5273 tmp)
5274 n_match_sets++;
5275
5276 if (n_match_sets > wiphy->max_match_sets)
5277 return -EINVAL;
5278
Luciano Coelho807f8a82011-05-11 17:09:35 +03005279 if (info->attrs[NL80211_ATTR_IE])
5280 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5281 else
5282 ie_len = 0;
5283
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005284 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005285 return -EINVAL;
5286
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005287 mutex_lock(&rdev->sched_scan_mtx);
5288
5289 if (rdev->sched_scan_req) {
5290 err = -EINPROGRESS;
5291 goto out;
5292 }
5293
Luciano Coelho807f8a82011-05-11 17:09:35 +03005294 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005295 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005296 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005297 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005298 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005299 if (!request) {
5300 err = -ENOMEM;
5301 goto out;
5302 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005303
5304 if (n_ssids)
5305 request->ssids = (void *)&request->channels[n_channels];
5306 request->n_ssids = n_ssids;
5307 if (ie_len) {
5308 if (request->ssids)
5309 request->ie = (void *)(request->ssids + n_ssids);
5310 else
5311 request->ie = (void *)(request->channels + n_channels);
5312 }
5313
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005314 if (n_match_sets) {
5315 if (request->ie)
5316 request->match_sets = (void *)(request->ie + ie_len);
5317 else if (request->ssids)
5318 request->match_sets =
5319 (void *)(request->ssids + n_ssids);
5320 else
5321 request->match_sets =
5322 (void *)(request->channels + n_channels);
5323 }
5324 request->n_match_sets = n_match_sets;
5325
Luciano Coelho807f8a82011-05-11 17:09:35 +03005326 i = 0;
5327 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5328 /* user specified, bail out if channel not found */
5329 nla_for_each_nested(attr,
5330 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5331 tmp) {
5332 struct ieee80211_channel *chan;
5333
5334 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5335
5336 if (!chan) {
5337 err = -EINVAL;
5338 goto out_free;
5339 }
5340
5341 /* ignore disabled channels */
5342 if (chan->flags & IEEE80211_CHAN_DISABLED)
5343 continue;
5344
5345 request->channels[i] = chan;
5346 i++;
5347 }
5348 } else {
5349 /* all channels */
5350 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5351 int j;
5352 if (!wiphy->bands[band])
5353 continue;
5354 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5355 struct ieee80211_channel *chan;
5356
5357 chan = &wiphy->bands[band]->channels[j];
5358
5359 if (chan->flags & IEEE80211_CHAN_DISABLED)
5360 continue;
5361
5362 request->channels[i] = chan;
5363 i++;
5364 }
5365 }
5366 }
5367
5368 if (!i) {
5369 err = -EINVAL;
5370 goto out_free;
5371 }
5372
5373 request->n_channels = i;
5374
5375 i = 0;
5376 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5377 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5378 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005379 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005380 err = -EINVAL;
5381 goto out_free;
5382 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005383 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005384 memcpy(request->ssids[i].ssid, nla_data(attr),
5385 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005386 i++;
5387 }
5388 }
5389
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005390 i = 0;
5391 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5392 nla_for_each_nested(attr,
5393 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5394 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005395 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005396
5397 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5398 nla_data(attr), nla_len(attr),
5399 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005400 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005401 if (ssid) {
5402 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5403 err = -EINVAL;
5404 goto out_free;
5405 }
5406 memcpy(request->match_sets[i].ssid.ssid,
5407 nla_data(ssid), nla_len(ssid));
5408 request->match_sets[i].ssid.ssid_len =
5409 nla_len(ssid);
5410 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005411 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5412 if (rssi)
5413 request->rssi_thold = nla_get_u32(rssi);
5414 else
5415 request->rssi_thold =
5416 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005417 i++;
5418 }
5419 }
5420
Luciano Coelho807f8a82011-05-11 17:09:35 +03005421 if (info->attrs[NL80211_ATTR_IE]) {
5422 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5423 memcpy((void *)request->ie,
5424 nla_data(info->attrs[NL80211_ATTR_IE]),
5425 request->ie_len);
5426 }
5427
Sam Leffler46856bb2012-10-11 21:03:32 -07005428 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005429 request->flags = nla_get_u32(
5430 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005431 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5432 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5433 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5434 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005435 err = -EOPNOTSUPP;
5436 goto out_free;
5437 }
5438 }
Sam Lefflered4737712012-10-11 21:03:31 -07005439
Luciano Coelho807f8a82011-05-11 17:09:35 +03005440 request->dev = dev;
5441 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005442 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005443 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005444
Hila Gonene35e4d22012-06-27 17:19:42 +03005445 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005446 if (!err) {
5447 rdev->sched_scan_req = request;
5448 nl80211_send_sched_scan(rdev, dev,
5449 NL80211_CMD_START_SCHED_SCAN);
5450 goto out;
5451 }
5452
5453out_free:
5454 kfree(request);
5455out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005456 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005457 return err;
5458}
5459
5460static int nl80211_stop_sched_scan(struct sk_buff *skb,
5461 struct genl_info *info)
5462{
5463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005464 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005465
5466 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5467 !rdev->ops->sched_scan_stop)
5468 return -EOPNOTSUPP;
5469
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005470 mutex_lock(&rdev->sched_scan_mtx);
5471 err = __cfg80211_stop_sched_scan(rdev, false);
5472 mutex_unlock(&rdev->sched_scan_mtx);
5473
5474 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005475}
5476
Simon Wunderlich04f39042013-02-08 18:16:19 +01005477static int nl80211_start_radar_detection(struct sk_buff *skb,
5478 struct genl_info *info)
5479{
5480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5481 struct net_device *dev = info->user_ptr[1];
5482 struct wireless_dev *wdev = dev->ieee80211_ptr;
5483 struct cfg80211_chan_def chandef;
5484 int err;
5485
5486 err = nl80211_parse_chandef(rdev, info, &chandef);
5487 if (err)
5488 return err;
5489
5490 if (wdev->cac_started)
5491 return -EBUSY;
5492
5493 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5494 if (err < 0)
5495 return err;
5496
5497 if (err == 0)
5498 return -EINVAL;
5499
5500 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5501 return -EINVAL;
5502
5503 if (!rdev->ops->start_radar_detection)
5504 return -EOPNOTSUPP;
5505
5506 mutex_lock(&rdev->devlist_mtx);
5507 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5508 chandef.chan, CHAN_MODE_SHARED,
5509 BIT(chandef.width));
5510 if (err)
5511 goto err_locked;
5512
5513 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5514 if (!err) {
5515 wdev->channel = chandef.chan;
5516 wdev->cac_started = true;
5517 wdev->cac_start_time = jiffies;
5518 }
5519err_locked:
5520 mutex_unlock(&rdev->devlist_mtx);
5521
5522 return err;
5523}
5524
Johannes Berg9720bb32011-06-21 09:45:33 +02005525static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5526 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005527 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005528 struct wireless_dev *wdev,
5529 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005530{
Johannes Berg48ab9052009-07-10 18:42:31 +02005531 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005532 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005533 void *hdr;
5534 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005535 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005536
5537 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005538
Eric W. Biederman15e47302012-09-07 20:12:54 +00005539 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005540 NL80211_CMD_NEW_SCAN_RESULTS);
5541 if (!hdr)
5542 return -1;
5543
Johannes Berg9720bb32011-06-21 09:45:33 +02005544 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5545
David S. Miller9360ffd2012-03-29 04:41:26 -04005546 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5547 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5548 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005549
5550 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5551 if (!bss)
5552 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005553 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005554 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005555 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005556
5557 rcu_read_lock();
5558 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005559 if (ies) {
5560 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5561 goto fail_unlock_rcu;
5562 tsf = true;
5563 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5564 ies->len, ies->data))
5565 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005566 }
5567 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005568 if (ies) {
5569 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5570 goto fail_unlock_rcu;
5571 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5572 ies->len, ies->data))
5573 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005574 }
5575 rcu_read_unlock();
5576
David S. Miller9360ffd2012-03-29 04:41:26 -04005577 if (res->beacon_interval &&
5578 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5579 goto nla_put_failure;
5580 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5581 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5582 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5583 jiffies_to_msecs(jiffies - intbss->ts)))
5584 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005585
Johannes Berg77965c92009-02-18 18:45:06 +01005586 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005587 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005588 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5589 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005590 break;
5591 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005592 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5593 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005594 break;
5595 default:
5596 break;
5597 }
5598
Johannes Berg48ab9052009-07-10 18:42:31 +02005599 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005600 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005601 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005602 if (intbss == wdev->current_bss &&
5603 nla_put_u32(msg, NL80211_BSS_STATUS,
5604 NL80211_BSS_STATUS_ASSOCIATED))
5605 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005606 break;
5607 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005608 if (intbss == wdev->current_bss &&
5609 nla_put_u32(msg, NL80211_BSS_STATUS,
5610 NL80211_BSS_STATUS_IBSS_JOINED))
5611 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005612 break;
5613 default:
5614 break;
5615 }
5616
Johannes Berg2a519312009-02-10 21:25:55 +01005617 nla_nest_end(msg, bss);
5618
5619 return genlmsg_end(msg, hdr);
5620
Johannes Berg8cef2c92013-02-05 16:54:31 +01005621 fail_unlock_rcu:
5622 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005623 nla_put_failure:
5624 genlmsg_cancel(msg, hdr);
5625 return -EMSGSIZE;
5626}
5627
5628static int nl80211_dump_scan(struct sk_buff *skb,
5629 struct netlink_callback *cb)
5630{
Johannes Berg48ab9052009-07-10 18:42:31 +02005631 struct cfg80211_registered_device *rdev;
5632 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01005633 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005634 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005635 int start = cb->args[1], idx = 0;
5636 int err;
5637
Johannes Berg67748892010-10-04 21:14:06 +02005638 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5639 if (err)
5640 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005641
Johannes Berg48ab9052009-07-10 18:42:31 +02005642 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01005643
Johannes Berg48ab9052009-07-10 18:42:31 +02005644 wdev_lock(wdev);
5645 spin_lock_bh(&rdev->bss_lock);
5646 cfg80211_bss_expire(rdev);
5647
Johannes Berg9720bb32011-06-21 09:45:33 +02005648 cb->seq = rdev->bss_generation;
5649
Johannes Berg48ab9052009-07-10 18:42:31 +02005650 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005651 if (++idx <= start)
5652 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005653 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005654 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005655 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005656 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005657 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005658 }
5659 }
5660
Johannes Berg48ab9052009-07-10 18:42:31 +02005661 spin_unlock_bh(&rdev->bss_lock);
5662 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005663
5664 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02005665 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005666
Johannes Berg67748892010-10-04 21:14:06 +02005667 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005668}
5669
Eric W. Biederman15e47302012-09-07 20:12:54 +00005670static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005671 int flags, struct net_device *dev,
5672 struct survey_info *survey)
5673{
5674 void *hdr;
5675 struct nlattr *infoattr;
5676
Eric W. Biederman15e47302012-09-07 20:12:54 +00005677 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005678 NL80211_CMD_NEW_SURVEY_RESULTS);
5679 if (!hdr)
5680 return -ENOMEM;
5681
David S. Miller9360ffd2012-03-29 04:41:26 -04005682 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5683 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005684
5685 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5686 if (!infoattr)
5687 goto nla_put_failure;
5688
David S. Miller9360ffd2012-03-29 04:41:26 -04005689 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5690 survey->channel->center_freq))
5691 goto nla_put_failure;
5692
5693 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5694 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5695 goto nla_put_failure;
5696 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5697 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5698 goto nla_put_failure;
5699 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5700 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5701 survey->channel_time))
5702 goto nla_put_failure;
5703 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5704 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5705 survey->channel_time_busy))
5706 goto nla_put_failure;
5707 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5708 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5709 survey->channel_time_ext_busy))
5710 goto nla_put_failure;
5711 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5712 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5713 survey->channel_time_rx))
5714 goto nla_put_failure;
5715 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5716 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5717 survey->channel_time_tx))
5718 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005719
5720 nla_nest_end(msg, infoattr);
5721
5722 return genlmsg_end(msg, hdr);
5723
5724 nla_put_failure:
5725 genlmsg_cancel(msg, hdr);
5726 return -EMSGSIZE;
5727}
5728
5729static int nl80211_dump_survey(struct sk_buff *skb,
5730 struct netlink_callback *cb)
5731{
5732 struct survey_info survey;
5733 struct cfg80211_registered_device *dev;
5734 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01005735 int survey_idx = cb->args[1];
5736 int res;
5737
Johannes Berg67748892010-10-04 21:14:06 +02005738 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5739 if (res)
5740 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005741
5742 if (!dev->ops->dump_survey) {
5743 res = -EOPNOTSUPP;
5744 goto out_err;
5745 }
5746
5747 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005748 struct ieee80211_channel *chan;
5749
Hila Gonene35e4d22012-06-27 17:19:42 +03005750 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005751 if (res == -ENOENT)
5752 break;
5753 if (res)
5754 goto out_err;
5755
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005756 /* Survey without a channel doesn't make sense */
5757 if (!survey.channel) {
5758 res = -EINVAL;
5759 goto out;
5760 }
5761
5762 chan = ieee80211_get_channel(&dev->wiphy,
5763 survey.channel->center_freq);
5764 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5765 survey_idx++;
5766 continue;
5767 }
5768
Holger Schurig61fa7132009-11-11 12:25:40 +01005769 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005770 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005771 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5772 netdev,
5773 &survey) < 0)
5774 goto out;
5775 survey_idx++;
5776 }
5777
5778 out:
5779 cb->args[1] = survey_idx;
5780 res = skb->len;
5781 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02005782 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005783 return res;
5784}
5785
Samuel Ortizb23aa672009-07-01 21:26:54 +02005786static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5787{
5788 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5789 NL80211_WPA_VERSION_2));
5790}
5791
Jouni Malinen636a5d32009-03-19 13:39:22 +02005792static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5793{
Johannes Berg4c476992010-10-04 21:36:35 +02005794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5795 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005796 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005797 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5798 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005799 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005800 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005801 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005802
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005803 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5804 return -EINVAL;
5805
5806 if (!info->attrs[NL80211_ATTR_MAC])
5807 return -EINVAL;
5808
Jouni Malinen17780922009-03-27 20:52:47 +02005809 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5810 return -EINVAL;
5811
Johannes Berg19957bb2009-07-02 17:20:43 +02005812 if (!info->attrs[NL80211_ATTR_SSID])
5813 return -EINVAL;
5814
5815 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5816 return -EINVAL;
5817
Johannes Bergfffd0932009-07-08 14:22:54 +02005818 err = nl80211_parse_key(info, &key);
5819 if (err)
5820 return err;
5821
5822 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005823 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5824 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005825 if (!key.p.key || !key.p.key_len)
5826 return -EINVAL;
5827 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5828 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5829 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5830 key.p.key_len != WLAN_KEY_LEN_WEP104))
5831 return -EINVAL;
5832 if (key.idx > 4)
5833 return -EINVAL;
5834 } else {
5835 key.p.key_len = 0;
5836 key.p.key = NULL;
5837 }
5838
Johannes Bergafea0b72010-08-10 09:46:42 +02005839 if (key.idx >= 0) {
5840 int i;
5841 bool ok = false;
5842 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5843 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5844 ok = true;
5845 break;
5846 }
5847 }
Johannes Berg4c476992010-10-04 21:36:35 +02005848 if (!ok)
5849 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005850 }
5851
Johannes Berg4c476992010-10-04 21:36:35 +02005852 if (!rdev->ops->auth)
5853 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005854
Johannes Berg074ac8d2010-09-16 14:58:22 +02005855 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005856 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5857 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005858
Johannes Berg19957bb2009-07-02 17:20:43 +02005859 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005860 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005861 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005862 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5863 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005864
Johannes Berg19957bb2009-07-02 17:20:43 +02005865 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5866 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5867
5868 if (info->attrs[NL80211_ATTR_IE]) {
5869 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5870 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5871 }
5872
5873 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005874 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005875 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005876
Jouni Malinene39e5b52012-09-30 19:29:39 +03005877 if (auth_type == NL80211_AUTHTYPE_SAE &&
5878 !info->attrs[NL80211_ATTR_SAE_DATA])
5879 return -EINVAL;
5880
5881 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5882 if (auth_type != NL80211_AUTHTYPE_SAE)
5883 return -EINVAL;
5884 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5885 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5886 /* need to include at least Auth Transaction and Status Code */
5887 if (sae_data_len < 4)
5888 return -EINVAL;
5889 }
5890
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005891 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5892
Johannes Berg95de8172012-01-20 13:55:25 +01005893 /*
5894 * Since we no longer track auth state, ignore
5895 * requests to only change local state.
5896 */
5897 if (local_state_change)
5898 return 0;
5899
Johannes Berg4c476992010-10-04 21:36:35 +02005900 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5901 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005902 key.p.key, key.p.key_len, key.idx,
5903 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005904}
5905
Johannes Bergc0692b82010-08-27 14:26:53 +03005906static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5907 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005908 struct cfg80211_crypto_settings *settings,
5909 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005910{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005911 memset(settings, 0, sizeof(*settings));
5912
Samuel Ortizb23aa672009-07-01 21:26:54 +02005913 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5914
Johannes Bergc0692b82010-08-27 14:26:53 +03005915 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5916 u16 proto;
5917 proto = nla_get_u16(
5918 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5919 settings->control_port_ethertype = cpu_to_be16(proto);
5920 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5921 proto != ETH_P_PAE)
5922 return -EINVAL;
5923 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5924 settings->control_port_no_encrypt = true;
5925 } else
5926 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5927
Samuel Ortizb23aa672009-07-01 21:26:54 +02005928 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5929 void *data;
5930 int len, i;
5931
5932 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5933 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5934 settings->n_ciphers_pairwise = len / sizeof(u32);
5935
5936 if (len % sizeof(u32))
5937 return -EINVAL;
5938
Johannes Berg3dc27d22009-07-02 21:36:37 +02005939 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005940 return -EINVAL;
5941
5942 memcpy(settings->ciphers_pairwise, data, len);
5943
5944 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005945 if (!cfg80211_supported_cipher_suite(
5946 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005947 settings->ciphers_pairwise[i]))
5948 return -EINVAL;
5949 }
5950
5951 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5952 settings->cipher_group =
5953 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005954 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5955 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005956 return -EINVAL;
5957 }
5958
5959 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5960 settings->wpa_versions =
5961 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5962 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5963 return -EINVAL;
5964 }
5965
5966 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5967 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005968 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005969
5970 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5971 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5972 settings->n_akm_suites = len / sizeof(u32);
5973
5974 if (len % sizeof(u32))
5975 return -EINVAL;
5976
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005977 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5978 return -EINVAL;
5979
Samuel Ortizb23aa672009-07-01 21:26:54 +02005980 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005981 }
5982
5983 return 0;
5984}
5985
Jouni Malinen636a5d32009-03-19 13:39:22 +02005986static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5987{
Johannes Berg4c476992010-10-04 21:36:35 +02005988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5989 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02005990 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01005991 struct cfg80211_assoc_request req = {};
5992 const u8 *bssid, *ssid;
5993 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005994
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005995 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5996 return -EINVAL;
5997
5998 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005999 !info->attrs[NL80211_ATTR_SSID] ||
6000 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006001 return -EINVAL;
6002
Johannes Berg4c476992010-10-04 21:36:35 +02006003 if (!rdev->ops->assoc)
6004 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006005
Johannes Berg074ac8d2010-09-16 14:58:22 +02006006 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006007 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6008 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006009
Johannes Berg19957bb2009-07-02 17:20:43 +02006010 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006011
Johannes Berg19957bb2009-07-02 17:20:43 +02006012 chan = ieee80211_get_channel(&rdev->wiphy,
6013 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006014 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6015 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006016
Johannes Berg19957bb2009-07-02 17:20:43 +02006017 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6018 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006019
6020 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006021 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6022 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006023 }
6024
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006025 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006026 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006027 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006028 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006029 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006030 else if (mfp != NL80211_MFP_NO)
6031 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006032 }
6033
Johannes Berg3e5d7642009-07-07 14:37:26 +02006034 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006035 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006036
Ben Greear7e7c8922011-11-18 11:31:59 -08006037 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006038 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006039
6040 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006041 memcpy(&req.ht_capa_mask,
6042 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6043 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006044
6045 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006046 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006047 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006048 memcpy(&req.ht_capa,
6049 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6050 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006051 }
6052
Johannes Bergee2aca32013-02-21 17:36:01 +01006053 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006054 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006055
6056 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006057 memcpy(&req.vht_capa_mask,
6058 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6059 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006060
6061 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006062 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006063 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006064 memcpy(&req.vht_capa,
6065 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6066 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006067 }
6068
Johannes Bergf62fab72013-02-21 20:09:09 +01006069 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006070 if (!err)
Johannes Bergf62fab72013-02-21 20:09:09 +01006071 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6072 ssid, ssid_len, &req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006073
Jouni Malinen636a5d32009-03-19 13:39:22 +02006074 return err;
6075}
6076
6077static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6078{
Johannes Berg4c476992010-10-04 21:36:35 +02006079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6080 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006081 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006082 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006083 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006084 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006085
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006086 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6087 return -EINVAL;
6088
6089 if (!info->attrs[NL80211_ATTR_MAC])
6090 return -EINVAL;
6091
6092 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6093 return -EINVAL;
6094
Johannes Berg4c476992010-10-04 21:36:35 +02006095 if (!rdev->ops->deauth)
6096 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006097
Johannes Berg074ac8d2010-09-16 14:58:22 +02006098 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006099 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6100 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006101
Johannes Berg19957bb2009-07-02 17:20:43 +02006102 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006103
Johannes Berg19957bb2009-07-02 17:20:43 +02006104 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6105 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006106 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006107 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006108 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006109
6110 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006111 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6112 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006113 }
6114
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006115 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6116
Johannes Berg4c476992010-10-04 21:36:35 +02006117 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6118 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006119}
6120
6121static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6122{
Johannes Berg4c476992010-10-04 21:36:35 +02006123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6124 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006125 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006126 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006127 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006128 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006129
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006130 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6131 return -EINVAL;
6132
6133 if (!info->attrs[NL80211_ATTR_MAC])
6134 return -EINVAL;
6135
6136 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6137 return -EINVAL;
6138
Johannes Berg4c476992010-10-04 21:36:35 +02006139 if (!rdev->ops->disassoc)
6140 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006141
Johannes Berg074ac8d2010-09-16 14:58:22 +02006142 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006143 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6144 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006145
Johannes Berg19957bb2009-07-02 17:20:43 +02006146 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006147
Johannes Berg19957bb2009-07-02 17:20:43 +02006148 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6149 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006150 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006151 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006152 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006153
6154 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006155 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6156 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006157 }
6158
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006159 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6160
Johannes Berg4c476992010-10-04 21:36:35 +02006161 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6162 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006163}
6164
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006165static bool
6166nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6167 int mcast_rate[IEEE80211_NUM_BANDS],
6168 int rateval)
6169{
6170 struct wiphy *wiphy = &rdev->wiphy;
6171 bool found = false;
6172 int band, i;
6173
6174 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6175 struct ieee80211_supported_band *sband;
6176
6177 sband = wiphy->bands[band];
6178 if (!sband)
6179 continue;
6180
6181 for (i = 0; i < sband->n_bitrates; i++) {
6182 if (sband->bitrates[i].bitrate == rateval) {
6183 mcast_rate[band] = i + 1;
6184 found = true;
6185 break;
6186 }
6187 }
6188 }
6189
6190 return found;
6191}
6192
Johannes Berg04a773a2009-04-19 21:24:32 +02006193static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6194{
Johannes Berg4c476992010-10-04 21:36:35 +02006195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6196 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006197 struct cfg80211_ibss_params ibss;
6198 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006199 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006200 int err;
6201
Johannes Berg8e30bc52009-04-22 17:45:38 +02006202 memset(&ibss, 0, sizeof(ibss));
6203
Johannes Berg04a773a2009-04-19 21:24:32 +02006204 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6205 return -EINVAL;
6206
Johannes Berg683b6d32012-11-08 21:25:48 +01006207 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006208 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6209 return -EINVAL;
6210
Johannes Berg8e30bc52009-04-22 17:45:38 +02006211 ibss.beacon_interval = 100;
6212
6213 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6214 ibss.beacon_interval =
6215 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6216 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6217 return -EINVAL;
6218 }
6219
Johannes Berg4c476992010-10-04 21:36:35 +02006220 if (!rdev->ops->join_ibss)
6221 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006222
Johannes Berg4c476992010-10-04 21:36:35 +02006223 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6224 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006225
Johannes Berg79c97e92009-07-07 03:56:12 +02006226 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006227
Johannes Berg39193492011-09-16 13:45:25 +02006228 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006229 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006230
6231 if (!is_valid_ether_addr(ibss.bssid))
6232 return -EINVAL;
6233 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006234 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6235 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6236
6237 if (info->attrs[NL80211_ATTR_IE]) {
6238 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6239 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6240 }
6241
Johannes Berg683b6d32012-11-08 21:25:48 +01006242 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6243 if (err)
6244 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006245
Johannes Berg683b6d32012-11-08 21:25:48 +01006246 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006247 return -EINVAL;
6248
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006249 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6250 return -EINVAL;
6251 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6252 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006253 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006254
Johannes Berg04a773a2009-04-19 21:24:32 +02006255 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006256 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006257
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006258 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6259 u8 *rates =
6260 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6261 int n_rates =
6262 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6263 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006264 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006265
Johannes Berg34850ab2011-07-18 18:08:35 +02006266 err = ieee80211_get_ratemask(sband, rates, n_rates,
6267 &ibss.basic_rates);
6268 if (err)
6269 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006270 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006271
6272 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6273 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6274 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6275 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006276
Johannes Berg4c476992010-10-04 21:36:35 +02006277 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306278 bool no_ht = false;
6279
Johannes Berg4c476992010-10-04 21:36:35 +02006280 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306281 info->attrs[NL80211_ATTR_KEYS],
6282 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006283 if (IS_ERR(connkeys))
6284 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306285
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006286 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6287 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306288 kfree(connkeys);
6289 return -EINVAL;
6290 }
Johannes Berg4c476992010-10-04 21:36:35 +02006291 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006292
Antonio Quartulli267335d2012-01-31 20:25:47 +01006293 ibss.control_port =
6294 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6295
Johannes Berg4c476992010-10-04 21:36:35 +02006296 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006297 if (err)
6298 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006299 return err;
6300}
6301
6302static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6303{
Johannes Berg4c476992010-10-04 21:36:35 +02006304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6305 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006306
Johannes Berg4c476992010-10-04 21:36:35 +02006307 if (!rdev->ops->leave_ibss)
6308 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006309
Johannes Berg4c476992010-10-04 21:36:35 +02006310 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6311 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006312
Johannes Berg4c476992010-10-04 21:36:35 +02006313 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006314}
6315
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006316static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6317{
6318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6319 struct net_device *dev = info->user_ptr[1];
6320 int mcast_rate[IEEE80211_NUM_BANDS];
6321 u32 nla_rate;
6322 int err;
6323
6324 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6325 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6326 return -EOPNOTSUPP;
6327
6328 if (!rdev->ops->set_mcast_rate)
6329 return -EOPNOTSUPP;
6330
6331 memset(mcast_rate, 0, sizeof(mcast_rate));
6332
6333 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6334 return -EINVAL;
6335
6336 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6337 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6338 return -EINVAL;
6339
6340 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6341
6342 return err;
6343}
6344
6345
Johannes Bergaff89a92009-07-01 21:26:51 +02006346#ifdef CONFIG_NL80211_TESTMODE
6347static struct genl_multicast_group nl80211_testmode_mcgrp = {
6348 .name = "testmode",
6349};
6350
6351static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6352{
Johannes Berg4c476992010-10-04 21:36:35 +02006353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006354 int err;
6355
6356 if (!info->attrs[NL80211_ATTR_TESTDATA])
6357 return -EINVAL;
6358
Johannes Bergaff89a92009-07-01 21:26:51 +02006359 err = -EOPNOTSUPP;
6360 if (rdev->ops->testmode_cmd) {
6361 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006362 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006363 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6364 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6365 rdev->testmode_info = NULL;
6366 }
6367
Johannes Bergaff89a92009-07-01 21:26:51 +02006368 return err;
6369}
6370
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006371static int nl80211_testmode_dump(struct sk_buff *skb,
6372 struct netlink_callback *cb)
6373{
Johannes Berg00918d32011-12-13 17:22:05 +01006374 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006375 int err;
6376 long phy_idx;
6377 void *data = NULL;
6378 int data_len = 0;
6379
6380 if (cb->args[0]) {
6381 /*
6382 * 0 is a valid index, but not valid for args[0],
6383 * so we need to offset by 1.
6384 */
6385 phy_idx = cb->args[0] - 1;
6386 } else {
6387 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6388 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6389 nl80211_policy);
6390 if (err)
6391 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01006392
Johannes Berg2bd7e352012-06-15 14:23:16 +02006393 mutex_lock(&cfg80211_mutex);
6394 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6395 nl80211_fam.attrbuf);
6396 if (IS_ERR(rdev)) {
6397 mutex_unlock(&cfg80211_mutex);
6398 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01006399 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006400 phy_idx = rdev->wiphy_idx;
6401 rdev = NULL;
6402 mutex_unlock(&cfg80211_mutex);
6403
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006404 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6405 cb->args[1] =
6406 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6407 }
6408
6409 if (cb->args[1]) {
6410 data = nla_data((void *)cb->args[1]);
6411 data_len = nla_len((void *)cb->args[1]);
6412 }
6413
6414 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01006415 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6416 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006417 mutex_unlock(&cfg80211_mutex);
6418 return -ENOENT;
6419 }
Johannes Berg00918d32011-12-13 17:22:05 +01006420 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006421 mutex_unlock(&cfg80211_mutex);
6422
Johannes Berg00918d32011-12-13 17:22:05 +01006423 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006424 err = -EOPNOTSUPP;
6425 goto out_err;
6426 }
6427
6428 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006429 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006430 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6431 NL80211_CMD_TESTMODE);
6432 struct nlattr *tmdata;
6433
David S. Miller9360ffd2012-03-29 04:41:26 -04006434 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006435 genlmsg_cancel(skb, hdr);
6436 break;
6437 }
6438
6439 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6440 if (!tmdata) {
6441 genlmsg_cancel(skb, hdr);
6442 break;
6443 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006444 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006445 nla_nest_end(skb, tmdata);
6446
6447 if (err == -ENOBUFS || err == -ENOENT) {
6448 genlmsg_cancel(skb, hdr);
6449 break;
6450 } else if (err) {
6451 genlmsg_cancel(skb, hdr);
6452 goto out_err;
6453 }
6454
6455 genlmsg_end(skb, hdr);
6456 }
6457
6458 err = skb->len;
6459 /* see above */
6460 cb->args[0] = phy_idx + 1;
6461 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01006462 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006463 return err;
6464}
6465
Johannes Bergaff89a92009-07-01 21:26:51 +02006466static struct sk_buff *
6467__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006468 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006469{
6470 struct sk_buff *skb;
6471 void *hdr;
6472 struct nlattr *data;
6473
6474 skb = nlmsg_new(approxlen + 100, gfp);
6475 if (!skb)
6476 return NULL;
6477
Eric W. Biederman15e47302012-09-07 20:12:54 +00006478 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006479 if (!hdr) {
6480 kfree_skb(skb);
6481 return NULL;
6482 }
6483
David S. Miller9360ffd2012-03-29 04:41:26 -04006484 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6485 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006486 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6487
6488 ((void **)skb->cb)[0] = rdev;
6489 ((void **)skb->cb)[1] = hdr;
6490 ((void **)skb->cb)[2] = data;
6491
6492 return skb;
6493
6494 nla_put_failure:
6495 kfree_skb(skb);
6496 return NULL;
6497}
6498
6499struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6500 int approxlen)
6501{
6502 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6503
6504 if (WARN_ON(!rdev->testmode_info))
6505 return NULL;
6506
6507 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006508 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006509 rdev->testmode_info->snd_seq,
6510 GFP_KERNEL);
6511}
6512EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6513
6514int cfg80211_testmode_reply(struct sk_buff *skb)
6515{
6516 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6517 void *hdr = ((void **)skb->cb)[1];
6518 struct nlattr *data = ((void **)skb->cb)[2];
6519
6520 if (WARN_ON(!rdev->testmode_info)) {
6521 kfree_skb(skb);
6522 return -EINVAL;
6523 }
6524
6525 nla_nest_end(skb, data);
6526 genlmsg_end(skb, hdr);
6527 return genlmsg_reply(skb, rdev->testmode_info);
6528}
6529EXPORT_SYMBOL(cfg80211_testmode_reply);
6530
6531struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6532 int approxlen, gfp_t gfp)
6533{
6534 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6535
6536 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6537}
6538EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6539
6540void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6541{
6542 void *hdr = ((void **)skb->cb)[1];
6543 struct nlattr *data = ((void **)skb->cb)[2];
6544
6545 nla_nest_end(skb, data);
6546 genlmsg_end(skb, hdr);
6547 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6548}
6549EXPORT_SYMBOL(cfg80211_testmode_event);
6550#endif
6551
Samuel Ortizb23aa672009-07-01 21:26:54 +02006552static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6553{
Johannes Berg4c476992010-10-04 21:36:35 +02006554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6555 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006556 struct cfg80211_connect_params connect;
6557 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006558 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006559 int err;
6560
6561 memset(&connect, 0, sizeof(connect));
6562
6563 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6564 return -EINVAL;
6565
6566 if (!info->attrs[NL80211_ATTR_SSID] ||
6567 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6568 return -EINVAL;
6569
6570 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6571 connect.auth_type =
6572 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006573 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6574 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006575 return -EINVAL;
6576 } else
6577 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6578
6579 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6580
Johannes Bergc0692b82010-08-27 14:26:53 +03006581 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006582 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006583 if (err)
6584 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006585
Johannes Berg074ac8d2010-09-16 14:58:22 +02006586 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006587 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6588 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006589
Johannes Berg79c97e92009-07-07 03:56:12 +02006590 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006591
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306592 connect.bg_scan_period = -1;
6593 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6594 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6595 connect.bg_scan_period =
6596 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6597 }
6598
Samuel Ortizb23aa672009-07-01 21:26:54 +02006599 if (info->attrs[NL80211_ATTR_MAC])
6600 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6601 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6602 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6603
6604 if (info->attrs[NL80211_ATTR_IE]) {
6605 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6606 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6607 }
6608
Jouni Malinencee00a92013-01-15 17:15:57 +02006609 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6610 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6611 if (connect.mfp != NL80211_MFP_REQUIRED &&
6612 connect.mfp != NL80211_MFP_NO)
6613 return -EINVAL;
6614 } else {
6615 connect.mfp = NL80211_MFP_NO;
6616 }
6617
Samuel Ortizb23aa672009-07-01 21:26:54 +02006618 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6619 connect.channel =
6620 ieee80211_get_channel(wiphy,
6621 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6622 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006623 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6624 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006625 }
6626
Johannes Bergfffd0932009-07-08 14:22:54 +02006627 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6628 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306629 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006630 if (IS_ERR(connkeys))
6631 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006632 }
6633
Ben Greear7e7c8922011-11-18 11:31:59 -08006634 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6635 connect.flags |= ASSOC_REQ_DISABLE_HT;
6636
6637 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6638 memcpy(&connect.ht_capa_mask,
6639 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6640 sizeof(connect.ht_capa_mask));
6641
6642 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006643 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6644 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006645 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006646 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006647 memcpy(&connect.ht_capa,
6648 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6649 sizeof(connect.ht_capa));
6650 }
6651
Johannes Bergee2aca32013-02-21 17:36:01 +01006652 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6653 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6654
6655 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6656 memcpy(&connect.vht_capa_mask,
6657 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6658 sizeof(connect.vht_capa_mask));
6659
6660 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6661 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6662 kfree(connkeys);
6663 return -EINVAL;
6664 }
6665 memcpy(&connect.vht_capa,
6666 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6667 sizeof(connect.vht_capa));
6668 }
6669
Johannes Bergfffd0932009-07-08 14:22:54 +02006670 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006671 if (err)
6672 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006673 return err;
6674}
6675
6676static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6677{
Johannes Berg4c476992010-10-04 21:36:35 +02006678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6679 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006680 u16 reason;
6681
6682 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6683 reason = WLAN_REASON_DEAUTH_LEAVING;
6684 else
6685 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6686
6687 if (reason == 0)
6688 return -EINVAL;
6689
Johannes Berg074ac8d2010-09-16 14:58:22 +02006690 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006691 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6692 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006693
Johannes Berg4c476992010-10-04 21:36:35 +02006694 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006695}
6696
Johannes Berg463d0182009-07-14 00:33:35 +02006697static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6698{
Johannes Berg4c476992010-10-04 21:36:35 +02006699 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006700 struct net *net;
6701 int err;
6702 u32 pid;
6703
6704 if (!info->attrs[NL80211_ATTR_PID])
6705 return -EINVAL;
6706
6707 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6708
Johannes Berg463d0182009-07-14 00:33:35 +02006709 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006710 if (IS_ERR(net))
6711 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006712
6713 err = 0;
6714
6715 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006716 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6717 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006718
Johannes Berg463d0182009-07-14 00:33:35 +02006719 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006720 return err;
6721}
6722
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006723static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6724{
Johannes Berg4c476992010-10-04 21:36:35 +02006725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006726 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6727 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006728 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006729 struct cfg80211_pmksa pmksa;
6730
6731 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6732
6733 if (!info->attrs[NL80211_ATTR_MAC])
6734 return -EINVAL;
6735
6736 if (!info->attrs[NL80211_ATTR_PMKID])
6737 return -EINVAL;
6738
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006739 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6740 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6741
Johannes Berg074ac8d2010-09-16 14:58:22 +02006742 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006743 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6744 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006745
6746 switch (info->genlhdr->cmd) {
6747 case NL80211_CMD_SET_PMKSA:
6748 rdev_ops = rdev->ops->set_pmksa;
6749 break;
6750 case NL80211_CMD_DEL_PMKSA:
6751 rdev_ops = rdev->ops->del_pmksa;
6752 break;
6753 default:
6754 WARN_ON(1);
6755 break;
6756 }
6757
Johannes Berg4c476992010-10-04 21:36:35 +02006758 if (!rdev_ops)
6759 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006760
Johannes Berg4c476992010-10-04 21:36:35 +02006761 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006762}
6763
6764static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6765{
Johannes Berg4c476992010-10-04 21:36:35 +02006766 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6767 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006768
Johannes Berg074ac8d2010-09-16 14:58:22 +02006769 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006770 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6771 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006772
Johannes Berg4c476992010-10-04 21:36:35 +02006773 if (!rdev->ops->flush_pmksa)
6774 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006775
Hila Gonene35e4d22012-06-27 17:19:42 +03006776 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006777}
6778
Arik Nemtsov109086c2011-09-28 14:12:50 +03006779static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6780{
6781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6782 struct net_device *dev = info->user_ptr[1];
6783 u8 action_code, dialog_token;
6784 u16 status_code;
6785 u8 *peer;
6786
6787 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6788 !rdev->ops->tdls_mgmt)
6789 return -EOPNOTSUPP;
6790
6791 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6792 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6793 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6794 !info->attrs[NL80211_ATTR_IE] ||
6795 !info->attrs[NL80211_ATTR_MAC])
6796 return -EINVAL;
6797
6798 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6799 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6800 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6801 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6802
Hila Gonene35e4d22012-06-27 17:19:42 +03006803 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6804 dialog_token, status_code,
6805 nla_data(info->attrs[NL80211_ATTR_IE]),
6806 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006807}
6808
6809static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6810{
6811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6812 struct net_device *dev = info->user_ptr[1];
6813 enum nl80211_tdls_operation operation;
6814 u8 *peer;
6815
6816 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6817 !rdev->ops->tdls_oper)
6818 return -EOPNOTSUPP;
6819
6820 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6821 !info->attrs[NL80211_ATTR_MAC])
6822 return -EINVAL;
6823
6824 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6825 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6826
Hila Gonene35e4d22012-06-27 17:19:42 +03006827 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006828}
6829
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006830static int nl80211_remain_on_channel(struct sk_buff *skb,
6831 struct genl_info *info)
6832{
Johannes Berg4c476992010-10-04 21:36:35 +02006833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006834 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006835 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006836 struct sk_buff *msg;
6837 void *hdr;
6838 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006839 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006840 int err;
6841
6842 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6843 !info->attrs[NL80211_ATTR_DURATION])
6844 return -EINVAL;
6845
6846 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6847
Johannes Berg7c4ef712011-11-18 15:33:48 +01006848 if (!rdev->ops->remain_on_channel ||
6849 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006850 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006851
Johannes Bergebf348f2012-06-01 12:50:54 +02006852 /*
6853 * We should be on that channel for at least a minimum amount of
6854 * time (10ms) but no longer than the driver supports.
6855 */
6856 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6857 duration > rdev->wiphy.max_remain_on_channel_duration)
6858 return -EINVAL;
6859
Johannes Berg683b6d32012-11-08 21:25:48 +01006860 err = nl80211_parse_chandef(rdev, info, &chandef);
6861 if (err)
6862 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006863
6864 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006865 if (!msg)
6866 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006867
Eric W. Biederman15e47302012-09-07 20:12:54 +00006868 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006869 NL80211_CMD_REMAIN_ON_CHANNEL);
6870
6871 if (IS_ERR(hdr)) {
6872 err = PTR_ERR(hdr);
6873 goto free_msg;
6874 }
6875
Johannes Berg683b6d32012-11-08 21:25:48 +01006876 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6877 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006878
6879 if (err)
6880 goto free_msg;
6881
David S. Miller9360ffd2012-03-29 04:41:26 -04006882 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6883 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006884
6885 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006886
6887 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006888
6889 nla_put_failure:
6890 err = -ENOBUFS;
6891 free_msg:
6892 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006893 return err;
6894}
6895
6896static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6897 struct genl_info *info)
6898{
Johannes Berg4c476992010-10-04 21:36:35 +02006899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006900 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006901 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006902
6903 if (!info->attrs[NL80211_ATTR_COOKIE])
6904 return -EINVAL;
6905
Johannes Berg4c476992010-10-04 21:36:35 +02006906 if (!rdev->ops->cancel_remain_on_channel)
6907 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006908
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006909 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6910
Hila Gonene35e4d22012-06-27 17:19:42 +03006911 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006912}
6913
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006914static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6915 u8 *rates, u8 rates_len)
6916{
6917 u8 i;
6918 u32 mask = 0;
6919
6920 for (i = 0; i < rates_len; i++) {
6921 int rate = (rates[i] & 0x7f) * 5;
6922 int ridx;
6923 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6924 struct ieee80211_rate *srate =
6925 &sband->bitrates[ridx];
6926 if (rate == srate->bitrate) {
6927 mask |= 1 << ridx;
6928 break;
6929 }
6930 }
6931 if (ridx == sband->n_bitrates)
6932 return 0; /* rate not found */
6933 }
6934
6935 return mask;
6936}
6937
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006938static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6939 u8 *rates, u8 rates_len,
6940 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6941{
6942 u8 i;
6943
6944 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6945
6946 for (i = 0; i < rates_len; i++) {
6947 int ridx, rbit;
6948
6949 ridx = rates[i] / 8;
6950 rbit = BIT(rates[i] % 8);
6951
6952 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006953 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006954 return false;
6955
6956 /* check availability */
6957 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6958 mcs[ridx] |= rbit;
6959 else
6960 return false;
6961 }
6962
6963 return true;
6964}
6965
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006966static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006967 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6968 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006969 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6970 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006971};
6972
6973static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6974 struct genl_info *info)
6975{
6976 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006978 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006979 int rem, i;
6980 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006981 struct nlattr *tx_rates;
6982 struct ieee80211_supported_band *sband;
6983
6984 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6985 return -EINVAL;
6986
Johannes Berg4c476992010-10-04 21:36:35 +02006987 if (!rdev->ops->set_bitrate_mask)
6988 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006989
6990 memset(&mask, 0, sizeof(mask));
6991 /* Default to all rates enabled */
6992 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6993 sband = rdev->wiphy.bands[i];
6994 mask.control[i].legacy =
6995 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006996 if (sband)
6997 memcpy(mask.control[i].mcs,
6998 sband->ht_cap.mcs.rx_mask,
6999 sizeof(mask.control[i].mcs));
7000 else
7001 memset(mask.control[i].mcs, 0,
7002 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007003 }
7004
7005 /*
7006 * The nested attribute uses enum nl80211_band as the index. This maps
7007 * directly to the enum ieee80211_band values used in cfg80211.
7008 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007009 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007010 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7011 {
7012 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007013 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7014 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007015 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007016 if (sband == NULL)
7017 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007018 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7019 nla_len(tx_rates), nl80211_txattr_policy);
7020 if (tb[NL80211_TXRATE_LEGACY]) {
7021 mask.control[band].legacy = rateset_to_mask(
7022 sband,
7023 nla_data(tb[NL80211_TXRATE_LEGACY]),
7024 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307025 if ((mask.control[band].legacy == 0) &&
7026 nla_len(tb[NL80211_TXRATE_LEGACY]))
7027 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007028 }
7029 if (tb[NL80211_TXRATE_MCS]) {
7030 if (!ht_rateset_to_mask(
7031 sband,
7032 nla_data(tb[NL80211_TXRATE_MCS]),
7033 nla_len(tb[NL80211_TXRATE_MCS]),
7034 mask.control[band].mcs))
7035 return -EINVAL;
7036 }
7037
7038 if (mask.control[band].legacy == 0) {
7039 /* don't allow empty legacy rates if HT
7040 * is not even supported. */
7041 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7042 return -EINVAL;
7043
7044 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7045 if (mask.control[band].mcs[i])
7046 break;
7047
7048 /* legacy and mcs rates may not be both empty */
7049 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007050 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007051 }
7052 }
7053
Hila Gonene35e4d22012-06-27 17:19:42 +03007054 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007055}
7056
Johannes Berg2e161f72010-08-12 15:38:38 +02007057static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007058{
Johannes Berg4c476992010-10-04 21:36:35 +02007059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007060 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007061 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007062
7063 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7064 return -EINVAL;
7065
Johannes Berg2e161f72010-08-12 15:38:38 +02007066 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7067 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007068
Johannes Berg71bbc992012-06-15 15:30:18 +02007069 switch (wdev->iftype) {
7070 case NL80211_IFTYPE_STATION:
7071 case NL80211_IFTYPE_ADHOC:
7072 case NL80211_IFTYPE_P2P_CLIENT:
7073 case NL80211_IFTYPE_AP:
7074 case NL80211_IFTYPE_AP_VLAN:
7075 case NL80211_IFTYPE_MESH_POINT:
7076 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007077 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007078 break;
7079 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007080 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007081 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007082
7083 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007084 if (!rdev->ops->mgmt_tx)
7085 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007086
Eric W. Biederman15e47302012-09-07 20:12:54 +00007087 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007088 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7089 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007090}
7091
Johannes Berg2e161f72010-08-12 15:38:38 +02007092static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007093{
Johannes Berg4c476992010-10-04 21:36:35 +02007094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007095 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007096 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007097 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007098 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007099 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007100 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007101 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007102 bool offchan, no_cck, dont_wait_for_ack;
7103
7104 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007105
Johannes Berg683b6d32012-11-08 21:25:48 +01007106 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007107 return -EINVAL;
7108
Johannes Berg4c476992010-10-04 21:36:35 +02007109 if (!rdev->ops->mgmt_tx)
7110 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007111
Johannes Berg71bbc992012-06-15 15:30:18 +02007112 switch (wdev->iftype) {
7113 case NL80211_IFTYPE_STATION:
7114 case NL80211_IFTYPE_ADHOC:
7115 case NL80211_IFTYPE_P2P_CLIENT:
7116 case NL80211_IFTYPE_AP:
7117 case NL80211_IFTYPE_AP_VLAN:
7118 case NL80211_IFTYPE_MESH_POINT:
7119 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007120 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007121 break;
7122 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007123 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007124 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007125
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007126 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007127 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007128 return -EINVAL;
7129 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007130
7131 /*
7132 * We should wait on the channel for at least a minimum amount
7133 * of time (10ms) but no longer than the driver supports.
7134 */
7135 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7136 wait > rdev->wiphy.max_remain_on_channel_duration)
7137 return -EINVAL;
7138
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007139 }
7140
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007141 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7142
Johannes Berg7c4ef712011-11-18 15:33:48 +01007143 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7144 return -EINVAL;
7145
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307146 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7147
Johannes Berg683b6d32012-11-08 21:25:48 +01007148 err = nl80211_parse_chandef(rdev, info, &chandef);
7149 if (err)
7150 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007151
Johannes Berge247bd902011-11-04 11:18:21 +01007152 if (!dont_wait_for_ack) {
7153 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7154 if (!msg)
7155 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007156
Eric W. Biederman15e47302012-09-07 20:12:54 +00007157 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007158 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007159
Johannes Berge247bd902011-11-04 11:18:21 +01007160 if (IS_ERR(hdr)) {
7161 err = PTR_ERR(hdr);
7162 goto free_msg;
7163 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007164 }
Johannes Berge247bd902011-11-04 11:18:21 +01007165
Johannes Berg683b6d32012-11-08 21:25:48 +01007166 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007167 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7168 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007169 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007170 if (err)
7171 goto free_msg;
7172
Johannes Berge247bd902011-11-04 11:18:21 +01007173 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007174 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7175 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007176
Johannes Berge247bd902011-11-04 11:18:21 +01007177 genlmsg_end(msg, hdr);
7178 return genlmsg_reply(msg, info);
7179 }
7180
7181 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007182
7183 nla_put_failure:
7184 err = -ENOBUFS;
7185 free_msg:
7186 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007187 return err;
7188}
7189
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007190static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7191{
7192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007193 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007194 u64 cookie;
7195
7196 if (!info->attrs[NL80211_ATTR_COOKIE])
7197 return -EINVAL;
7198
7199 if (!rdev->ops->mgmt_tx_cancel_wait)
7200 return -EOPNOTSUPP;
7201
Johannes Berg71bbc992012-06-15 15:30:18 +02007202 switch (wdev->iftype) {
7203 case NL80211_IFTYPE_STATION:
7204 case NL80211_IFTYPE_ADHOC:
7205 case NL80211_IFTYPE_P2P_CLIENT:
7206 case NL80211_IFTYPE_AP:
7207 case NL80211_IFTYPE_AP_VLAN:
7208 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007209 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007210 break;
7211 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007212 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007213 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007214
7215 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7216
Hila Gonene35e4d22012-06-27 17:19:42 +03007217 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007218}
7219
Kalle Valoffb9eb32010-02-17 17:58:10 +02007220static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7221{
Johannes Berg4c476992010-10-04 21:36:35 +02007222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007223 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007224 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007225 u8 ps_state;
7226 bool state;
7227 int err;
7228
Johannes Berg4c476992010-10-04 21:36:35 +02007229 if (!info->attrs[NL80211_ATTR_PS_STATE])
7230 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007231
7232 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7233
Johannes Berg4c476992010-10-04 21:36:35 +02007234 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7235 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007236
7237 wdev = dev->ieee80211_ptr;
7238
Johannes Berg4c476992010-10-04 21:36:35 +02007239 if (!rdev->ops->set_power_mgmt)
7240 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007241
7242 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7243
7244 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007245 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007246
Hila Gonene35e4d22012-06-27 17:19:42 +03007247 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007248 if (!err)
7249 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007250 return err;
7251}
7252
7253static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7254{
Johannes Berg4c476992010-10-04 21:36:35 +02007255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007256 enum nl80211_ps_state ps_state;
7257 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007258 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007259 struct sk_buff *msg;
7260 void *hdr;
7261 int err;
7262
Kalle Valoffb9eb32010-02-17 17:58:10 +02007263 wdev = dev->ieee80211_ptr;
7264
Johannes Berg4c476992010-10-04 21:36:35 +02007265 if (!rdev->ops->set_power_mgmt)
7266 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007267
7268 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007269 if (!msg)
7270 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007271
Eric W. Biederman15e47302012-09-07 20:12:54 +00007272 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007273 NL80211_CMD_GET_POWER_SAVE);
7274 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007275 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007276 goto free_msg;
7277 }
7278
7279 if (wdev->ps)
7280 ps_state = NL80211_PS_ENABLED;
7281 else
7282 ps_state = NL80211_PS_DISABLED;
7283
David S. Miller9360ffd2012-03-29 04:41:26 -04007284 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7285 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007286
7287 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007288 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007289
Johannes Berg4c476992010-10-04 21:36:35 +02007290 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007291 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007292 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007293 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007294 return err;
7295}
7296
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007297static struct nla_policy
7298nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7299 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7300 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7301 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007302 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7303 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7304 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007305};
7306
Thomas Pedersen84f10702012-07-12 16:17:33 -07007307static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007308 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007309{
7310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7311 struct wireless_dev *wdev;
7312 struct net_device *dev = info->user_ptr[1];
7313
Johannes Bergd9d8b012012-11-26 12:51:52 +01007314 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007315 return -EINVAL;
7316
7317 wdev = dev->ieee80211_ptr;
7318
7319 if (!rdev->ops->set_cqm_txe_config)
7320 return -EOPNOTSUPP;
7321
7322 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7323 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7324 return -EOPNOTSUPP;
7325
Hila Gonene35e4d22012-06-27 17:19:42 +03007326 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007327}
7328
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007329static int nl80211_set_cqm_rssi(struct genl_info *info,
7330 s32 threshold, u32 hysteresis)
7331{
Johannes Berg4c476992010-10-04 21:36:35 +02007332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007333 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007334 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007335
7336 if (threshold > 0)
7337 return -EINVAL;
7338
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007339 wdev = dev->ieee80211_ptr;
7340
Johannes Berg4c476992010-10-04 21:36:35 +02007341 if (!rdev->ops->set_cqm_rssi_config)
7342 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007343
Johannes Berg074ac8d2010-09-16 14:58:22 +02007344 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007345 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7346 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007347
Hila Gonene35e4d22012-06-27 17:19:42 +03007348 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007349}
7350
7351static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7352{
7353 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7354 struct nlattr *cqm;
7355 int err;
7356
7357 cqm = info->attrs[NL80211_ATTR_CQM];
7358 if (!cqm) {
7359 err = -EINVAL;
7360 goto out;
7361 }
7362
7363 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7364 nl80211_attr_cqm_policy);
7365 if (err)
7366 goto out;
7367
7368 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7369 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7370 s32 threshold;
7371 u32 hysteresis;
7372 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7373 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7374 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007375 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7376 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7377 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7378 u32 rate, pkts, intvl;
7379 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7380 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7381 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7382 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007383 } else
7384 err = -EINVAL;
7385
7386out:
7387 return err;
7388}
7389
Johannes Berg29cbe682010-12-03 09:20:44 +01007390static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7391{
7392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7393 struct net_device *dev = info->user_ptr[1];
7394 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007395 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007396 int err;
7397
7398 /* start with default */
7399 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007400 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007401
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007402 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007403 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007404 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007405 if (err)
7406 return err;
7407 }
7408
7409 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7410 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7411 return -EINVAL;
7412
Javier Cardonac80d5452010-12-16 17:37:49 -08007413 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7414 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7415
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007416 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7417 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7418 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7419 return -EINVAL;
7420
Marco Porsch9bdbf042013-01-07 16:04:51 +01007421 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7422 setup.beacon_interval =
7423 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7424 if (setup.beacon_interval < 10 ||
7425 setup.beacon_interval > 10000)
7426 return -EINVAL;
7427 }
7428
7429 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7430 setup.dtim_period =
7431 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7432 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7433 return -EINVAL;
7434 }
7435
Javier Cardonac80d5452010-12-16 17:37:49 -08007436 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7437 /* parse additional setup parameters if given */
7438 err = nl80211_parse_mesh_setup(info, &setup);
7439 if (err)
7440 return err;
7441 }
7442
Johannes Bergcc1d2802012-05-16 23:50:20 +02007443 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007444 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7445 if (err)
7446 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007447 } else {
7448 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007449 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007450 }
7451
Javier Cardonac80d5452010-12-16 17:37:49 -08007452 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007453}
7454
7455static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7456{
7457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7458 struct net_device *dev = info->user_ptr[1];
7459
7460 return cfg80211_leave_mesh(rdev, dev);
7461}
7462
Johannes Bergdfb89c52012-06-27 09:23:48 +02007463#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007464static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7465 struct cfg80211_registered_device *rdev)
7466{
7467 struct nlattr *nl_pats, *nl_pat;
7468 int i, pat_len;
7469
7470 if (!rdev->wowlan->n_patterns)
7471 return 0;
7472
7473 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7474 if (!nl_pats)
7475 return -ENOBUFS;
7476
7477 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7478 nl_pat = nla_nest_start(msg, i + 1);
7479 if (!nl_pat)
7480 return -ENOBUFS;
7481 pat_len = rdev->wowlan->patterns[i].pattern_len;
7482 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7483 DIV_ROUND_UP(pat_len, 8),
7484 rdev->wowlan->patterns[i].mask) ||
7485 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7486 pat_len, rdev->wowlan->patterns[i].pattern) ||
7487 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7488 rdev->wowlan->patterns[i].pkt_offset))
7489 return -ENOBUFS;
7490 nla_nest_end(msg, nl_pat);
7491 }
7492 nla_nest_end(msg, nl_pats);
7493
7494 return 0;
7495}
7496
Johannes Berg2a0e0472013-01-23 22:57:40 +01007497static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7498 struct cfg80211_wowlan_tcp *tcp)
7499{
7500 struct nlattr *nl_tcp;
7501
7502 if (!tcp)
7503 return 0;
7504
7505 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7506 if (!nl_tcp)
7507 return -ENOBUFS;
7508
7509 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7510 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7511 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7512 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7513 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7514 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7515 tcp->payload_len, tcp->payload) ||
7516 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7517 tcp->data_interval) ||
7518 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7519 tcp->wake_len, tcp->wake_data) ||
7520 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7521 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7522 return -ENOBUFS;
7523
7524 if (tcp->payload_seq.len &&
7525 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7526 sizeof(tcp->payload_seq), &tcp->payload_seq))
7527 return -ENOBUFS;
7528
7529 if (tcp->payload_tok.len &&
7530 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7531 sizeof(tcp->payload_tok) + tcp->tokens_size,
7532 &tcp->payload_tok))
7533 return -ENOBUFS;
7534
7535 return 0;
7536}
7537
Johannes Bergff1b6e62011-05-04 15:37:28 +02007538static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7539{
7540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7541 struct sk_buff *msg;
7542 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007543 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007544
Johannes Berg2a0e0472013-01-23 22:57:40 +01007545 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7546 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007547 return -EOPNOTSUPP;
7548
Johannes Berg2a0e0472013-01-23 22:57:40 +01007549 if (rdev->wowlan && rdev->wowlan->tcp) {
7550 /* adjust size to have room for all the data */
7551 size += rdev->wowlan->tcp->tokens_size +
7552 rdev->wowlan->tcp->payload_len +
7553 rdev->wowlan->tcp->wake_len +
7554 rdev->wowlan->tcp->wake_len / 8;
7555 }
7556
7557 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007558 if (!msg)
7559 return -ENOMEM;
7560
Eric W. Biederman15e47302012-09-07 20:12:54 +00007561 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007562 NL80211_CMD_GET_WOWLAN);
7563 if (!hdr)
7564 goto nla_put_failure;
7565
7566 if (rdev->wowlan) {
7567 struct nlattr *nl_wowlan;
7568
7569 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7570 if (!nl_wowlan)
7571 goto nla_put_failure;
7572
David S. Miller9360ffd2012-03-29 04:41:26 -04007573 if ((rdev->wowlan->any &&
7574 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7575 (rdev->wowlan->disconnect &&
7576 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7577 (rdev->wowlan->magic_pkt &&
7578 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7579 (rdev->wowlan->gtk_rekey_failure &&
7580 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7581 (rdev->wowlan->eap_identity_req &&
7582 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7583 (rdev->wowlan->four_way_handshake &&
7584 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7585 (rdev->wowlan->rfkill_release &&
7586 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7587 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007588
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007589 if (nl80211_send_wowlan_patterns(msg, rdev))
7590 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007591
7592 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7593 goto nla_put_failure;
7594
Johannes Bergff1b6e62011-05-04 15:37:28 +02007595 nla_nest_end(msg, nl_wowlan);
7596 }
7597
7598 genlmsg_end(msg, hdr);
7599 return genlmsg_reply(msg, info);
7600
7601nla_put_failure:
7602 nlmsg_free(msg);
7603 return -ENOBUFS;
7604}
7605
Johannes Berg2a0e0472013-01-23 22:57:40 +01007606static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7607 struct nlattr *attr,
7608 struct cfg80211_wowlan *trig)
7609{
7610 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7611 struct cfg80211_wowlan_tcp *cfg;
7612 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7613 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7614 u32 size;
7615 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7616 int err, port;
7617
7618 if (!rdev->wiphy.wowlan.tcp)
7619 return -EINVAL;
7620
7621 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7622 nla_data(attr), nla_len(attr),
7623 nl80211_wowlan_tcp_policy);
7624 if (err)
7625 return err;
7626
7627 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7628 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7629 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7630 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7631 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7632 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7633 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7634 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7635 return -EINVAL;
7636
7637 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7638 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7639 return -EINVAL;
7640
7641 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg723d5682013-02-26 13:56:40 +01007642 rdev->wiphy.wowlan.tcp->data_interval_max ||
7643 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007644 return -EINVAL;
7645
7646 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7647 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7648 return -EINVAL;
7649
7650 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7651 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7652 return -EINVAL;
7653
7654 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7655 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7656
7657 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7658 tokens_size = tokln - sizeof(*tok);
7659
7660 if (!tok->len || tokens_size % tok->len)
7661 return -EINVAL;
7662 if (!rdev->wiphy.wowlan.tcp->tok)
7663 return -EINVAL;
7664 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7665 return -EINVAL;
7666 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7667 return -EINVAL;
7668 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7669 return -EINVAL;
7670 if (tok->offset + tok->len > data_size)
7671 return -EINVAL;
7672 }
7673
7674 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7675 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7676 if (!rdev->wiphy.wowlan.tcp->seq)
7677 return -EINVAL;
7678 if (seq->len == 0 || seq->len > 4)
7679 return -EINVAL;
7680 if (seq->len + seq->offset > data_size)
7681 return -EINVAL;
7682 }
7683
7684 size = sizeof(*cfg);
7685 size += data_size;
7686 size += wake_size + wake_mask_size;
7687 size += tokens_size;
7688
7689 cfg = kzalloc(size, GFP_KERNEL);
7690 if (!cfg)
7691 return -ENOMEM;
7692 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7693 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7694 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7695 ETH_ALEN);
7696 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7697 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7698 else
7699 port = 0;
7700#ifdef CONFIG_INET
7701 /* allocate a socket and port for it and use it */
7702 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7703 IPPROTO_TCP, &cfg->sock, 1);
7704 if (err) {
7705 kfree(cfg);
7706 return err;
7707 }
7708 if (inet_csk_get_port(cfg->sock->sk, port)) {
7709 sock_release(cfg->sock);
7710 kfree(cfg);
7711 return -EADDRINUSE;
7712 }
7713 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7714#else
7715 if (!port) {
7716 kfree(cfg);
7717 return -EINVAL;
7718 }
7719 cfg->src_port = port;
7720#endif
7721
7722 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7723 cfg->payload_len = data_size;
7724 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7725 memcpy((void *)cfg->payload,
7726 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7727 data_size);
7728 if (seq)
7729 cfg->payload_seq = *seq;
7730 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7731 cfg->wake_len = wake_size;
7732 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7733 memcpy((void *)cfg->wake_data,
7734 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7735 wake_size);
7736 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7737 data_size + wake_size;
7738 memcpy((void *)cfg->wake_mask,
7739 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7740 wake_mask_size);
7741 if (tok) {
7742 cfg->tokens_size = tokens_size;
7743 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7744 }
7745
7746 trig->tcp = cfg;
7747
7748 return 0;
7749}
7750
Johannes Bergff1b6e62011-05-04 15:37:28 +02007751static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7752{
7753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7754 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007755 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007756 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007757 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7758 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007759 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007760
Johannes Berg2a0e0472013-01-23 22:57:40 +01007761 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7762 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007763 return -EOPNOTSUPP;
7764
Johannes Bergae33bd82012-07-12 16:25:02 +02007765 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7766 cfg80211_rdev_free_wowlan(rdev);
7767 rdev->wowlan = NULL;
7768 goto set_wakeup;
7769 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007770
7771 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7772 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7773 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7774 nl80211_wowlan_policy);
7775 if (err)
7776 return err;
7777
7778 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7779 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7780 return -EINVAL;
7781 new_triggers.any = true;
7782 }
7783
7784 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7785 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7786 return -EINVAL;
7787 new_triggers.disconnect = true;
7788 }
7789
7790 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7791 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7792 return -EINVAL;
7793 new_triggers.magic_pkt = true;
7794 }
7795
Johannes Berg77dbbb12011-07-13 10:48:55 +02007796 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7797 return -EINVAL;
7798
7799 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7800 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7801 return -EINVAL;
7802 new_triggers.gtk_rekey_failure = true;
7803 }
7804
7805 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7806 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7807 return -EINVAL;
7808 new_triggers.eap_identity_req = true;
7809 }
7810
7811 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7812 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7813 return -EINVAL;
7814 new_triggers.four_way_handshake = true;
7815 }
7816
7817 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7818 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7819 return -EINVAL;
7820 new_triggers.rfkill_release = true;
7821 }
7822
Johannes Bergff1b6e62011-05-04 15:37:28 +02007823 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7824 struct nlattr *pat;
7825 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007826 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007827 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7828
7829 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7830 rem)
7831 n_patterns++;
7832 if (n_patterns > wowlan->n_patterns)
7833 return -EINVAL;
7834
7835 new_triggers.patterns = kcalloc(n_patterns,
7836 sizeof(new_triggers.patterns[0]),
7837 GFP_KERNEL);
7838 if (!new_triggers.patterns)
7839 return -ENOMEM;
7840
7841 new_triggers.n_patterns = n_patterns;
7842 i = 0;
7843
7844 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7845 rem) {
7846 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7847 nla_data(pat), nla_len(pat), NULL);
7848 err = -EINVAL;
7849 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7850 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7851 goto error;
7852 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7853 mask_len = DIV_ROUND_UP(pat_len, 8);
7854 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7855 mask_len)
7856 goto error;
7857 if (pat_len > wowlan->pattern_max_len ||
7858 pat_len < wowlan->pattern_min_len)
7859 goto error;
7860
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007861 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7862 pkt_offset = 0;
7863 else
7864 pkt_offset = nla_get_u32(
7865 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7866 if (pkt_offset > wowlan->max_pkt_offset)
7867 goto error;
7868 new_triggers.patterns[i].pkt_offset = pkt_offset;
7869
Johannes Bergff1b6e62011-05-04 15:37:28 +02007870 new_triggers.patterns[i].mask =
7871 kmalloc(mask_len + pat_len, GFP_KERNEL);
7872 if (!new_triggers.patterns[i].mask) {
7873 err = -ENOMEM;
7874 goto error;
7875 }
7876 new_triggers.patterns[i].pattern =
7877 new_triggers.patterns[i].mask + mask_len;
7878 memcpy(new_triggers.patterns[i].mask,
7879 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7880 mask_len);
7881 new_triggers.patterns[i].pattern_len = pat_len;
7882 memcpy(new_triggers.patterns[i].pattern,
7883 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7884 pat_len);
7885 i++;
7886 }
7887 }
7888
Johannes Berg2a0e0472013-01-23 22:57:40 +01007889 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7890 err = nl80211_parse_wowlan_tcp(
7891 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7892 &new_triggers);
7893 if (err)
7894 goto error;
7895 }
7896
Johannes Bergae33bd82012-07-12 16:25:02 +02007897 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7898 if (!ntrig) {
7899 err = -ENOMEM;
7900 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007901 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007902 cfg80211_rdev_free_wowlan(rdev);
7903 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007904
Johannes Bergae33bd82012-07-12 16:25:02 +02007905 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007906 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007907 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007908
Johannes Bergff1b6e62011-05-04 15:37:28 +02007909 return 0;
7910 error:
7911 for (i = 0; i < new_triggers.n_patterns; i++)
7912 kfree(new_triggers.patterns[i].mask);
7913 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007914 if (new_triggers.tcp && new_triggers.tcp->sock)
7915 sock_release(new_triggers.tcp->sock);
7916 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007917 return err;
7918}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007919#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007920
Johannes Berge5497d72011-07-05 16:35:40 +02007921static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7922{
7923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7924 struct net_device *dev = info->user_ptr[1];
7925 struct wireless_dev *wdev = dev->ieee80211_ptr;
7926 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7927 struct cfg80211_gtk_rekey_data rekey_data;
7928 int err;
7929
7930 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7931 return -EINVAL;
7932
7933 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7934 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7935 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7936 nl80211_rekey_policy);
7937 if (err)
7938 return err;
7939
7940 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7941 return -ERANGE;
7942 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7943 return -ERANGE;
7944 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7945 return -ERANGE;
7946
7947 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7948 NL80211_KEK_LEN);
7949 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7950 NL80211_KCK_LEN);
7951 memcpy(rekey_data.replay_ctr,
7952 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7953 NL80211_REPLAY_CTR_LEN);
7954
7955 wdev_lock(wdev);
7956 if (!wdev->current_bss) {
7957 err = -ENOTCONN;
7958 goto out;
7959 }
7960
7961 if (!rdev->ops->set_rekey_data) {
7962 err = -EOPNOTSUPP;
7963 goto out;
7964 }
7965
Hila Gonene35e4d22012-06-27 17:19:42 +03007966 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007967 out:
7968 wdev_unlock(wdev);
7969 return err;
7970}
7971
Johannes Berg28946da2011-11-04 11:18:12 +01007972static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7973 struct genl_info *info)
7974{
7975 struct net_device *dev = info->user_ptr[1];
7976 struct wireless_dev *wdev = dev->ieee80211_ptr;
7977
7978 if (wdev->iftype != NL80211_IFTYPE_AP &&
7979 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7980 return -EINVAL;
7981
Eric W. Biederman15e47302012-09-07 20:12:54 +00007982 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01007983 return -EBUSY;
7984
Eric W. Biederman15e47302012-09-07 20:12:54 +00007985 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01007986 return 0;
7987}
7988
Johannes Berg7f6cf312011-11-04 11:18:15 +01007989static int nl80211_probe_client(struct sk_buff *skb,
7990 struct genl_info *info)
7991{
7992 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7993 struct net_device *dev = info->user_ptr[1];
7994 struct wireless_dev *wdev = dev->ieee80211_ptr;
7995 struct sk_buff *msg;
7996 void *hdr;
7997 const u8 *addr;
7998 u64 cookie;
7999 int err;
8000
8001 if (wdev->iftype != NL80211_IFTYPE_AP &&
8002 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8003 return -EOPNOTSUPP;
8004
8005 if (!info->attrs[NL80211_ATTR_MAC])
8006 return -EINVAL;
8007
8008 if (!rdev->ops->probe_client)
8009 return -EOPNOTSUPP;
8010
8011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8012 if (!msg)
8013 return -ENOMEM;
8014
Eric W. Biederman15e47302012-09-07 20:12:54 +00008015 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008016 NL80211_CMD_PROBE_CLIENT);
8017
8018 if (IS_ERR(hdr)) {
8019 err = PTR_ERR(hdr);
8020 goto free_msg;
8021 }
8022
8023 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8024
Hila Gonene35e4d22012-06-27 17:19:42 +03008025 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008026 if (err)
8027 goto free_msg;
8028
David S. Miller9360ffd2012-03-29 04:41:26 -04008029 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8030 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008031
8032 genlmsg_end(msg, hdr);
8033
8034 return genlmsg_reply(msg, info);
8035
8036 nla_put_failure:
8037 err = -ENOBUFS;
8038 free_msg:
8039 nlmsg_free(msg);
8040 return err;
8041}
8042
Johannes Berg5e760232011-11-04 11:18:17 +01008043static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8044{
8045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008046 struct cfg80211_beacon_registration *reg, *nreg;
8047 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008048
8049 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8050 return -EOPNOTSUPP;
8051
Ben Greear37c73b52012-10-26 14:49:25 -07008052 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8053 if (!nreg)
8054 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008055
Ben Greear37c73b52012-10-26 14:49:25 -07008056 /* First, check if already registered. */
8057 spin_lock_bh(&rdev->beacon_registrations_lock);
8058 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8059 if (reg->nlportid == info->snd_portid) {
8060 rv = -EALREADY;
8061 goto out_err;
8062 }
8063 }
8064 /* Add it to the list */
8065 nreg->nlportid = info->snd_portid;
8066 list_add(&nreg->list, &rdev->beacon_registrations);
8067
8068 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008069
8070 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008071out_err:
8072 spin_unlock_bh(&rdev->beacon_registrations_lock);
8073 kfree(nreg);
8074 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008075}
8076
Johannes Berg98104fde2012-06-16 00:19:54 +02008077static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8078{
8079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8080 struct wireless_dev *wdev = info->user_ptr[1];
8081 int err;
8082
8083 if (!rdev->ops->start_p2p_device)
8084 return -EOPNOTSUPP;
8085
8086 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8087 return -EOPNOTSUPP;
8088
8089 if (wdev->p2p_started)
8090 return 0;
8091
8092 mutex_lock(&rdev->devlist_mtx);
8093 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8094 mutex_unlock(&rdev->devlist_mtx);
8095 if (err)
8096 return err;
8097
Johannes Bergeeb126e2012-10-23 15:16:50 +02008098 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008099 if (err)
8100 return err;
8101
8102 wdev->p2p_started = true;
8103 mutex_lock(&rdev->devlist_mtx);
8104 rdev->opencount++;
8105 mutex_unlock(&rdev->devlist_mtx);
8106
8107 return 0;
8108}
8109
8110static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8111{
8112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8113 struct wireless_dev *wdev = info->user_ptr[1];
8114
8115 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8116 return -EOPNOTSUPP;
8117
8118 if (!rdev->ops->stop_p2p_device)
8119 return -EOPNOTSUPP;
8120
8121 if (!wdev->p2p_started)
8122 return 0;
8123
Johannes Bergeeb126e2012-10-23 15:16:50 +02008124 rdev_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008125 wdev->p2p_started = false;
8126
8127 mutex_lock(&rdev->devlist_mtx);
8128 rdev->opencount--;
8129 mutex_unlock(&rdev->devlist_mtx);
8130
8131 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
8132 rdev->scan_req->aborted = true;
8133 ___cfg80211_scan_done(rdev, true);
8134 }
8135
8136 return 0;
8137}
8138
Johannes Berg3713b4e2013-02-14 16:19:38 +01008139static int nl80211_get_protocol_features(struct sk_buff *skb,
8140 struct genl_info *info)
8141{
8142 void *hdr;
8143 struct sk_buff *msg;
8144
8145 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8146 if (!msg)
8147 return -ENOMEM;
8148
8149 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8150 NL80211_CMD_GET_PROTOCOL_FEATURES);
8151 if (!hdr)
8152 goto nla_put_failure;
8153
8154 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8155 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8156 goto nla_put_failure;
8157
8158 genlmsg_end(msg, hdr);
8159 return genlmsg_reply(msg, info);
8160
8161 nla_put_failure:
8162 kfree_skb(msg);
8163 return -ENOBUFS;
8164}
8165
Jouni Malinen355199e2013-02-27 17:14:27 +02008166static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8167{
8168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8169 struct cfg80211_update_ft_ies_params ft_params;
8170 struct net_device *dev = info->user_ptr[1];
8171
8172 if (!rdev->ops->update_ft_ies)
8173 return -EOPNOTSUPP;
8174
8175 if (!info->attrs[NL80211_ATTR_MDID] ||
8176 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8177 return -EINVAL;
8178
8179 memset(&ft_params, 0, sizeof(ft_params));
8180 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8181 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8182 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8183
8184 return rdev_update_ft_ies(rdev, dev, &ft_params);
8185}
8186
Johannes Berg4c476992010-10-04 21:36:35 +02008187#define NL80211_FLAG_NEED_WIPHY 0x01
8188#define NL80211_FLAG_NEED_NETDEV 0x02
8189#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008190#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8191#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8192 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008193#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008194/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008195#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8196 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008197
8198static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8199 struct genl_info *info)
8200{
8201 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008202 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008203 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008204 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8205
8206 if (rtnl)
8207 rtnl_lock();
8208
8209 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008210 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008211 if (IS_ERR(rdev)) {
8212 if (rtnl)
8213 rtnl_unlock();
8214 return PTR_ERR(rdev);
8215 }
8216 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008217 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8218 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008219 mutex_lock(&cfg80211_mutex);
8220 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8221 info->attrs);
8222 if (IS_ERR(wdev)) {
8223 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02008224 if (rtnl)
8225 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008226 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008227 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008228
Johannes Berg89a54e42012-06-15 14:33:17 +02008229 dev = wdev->netdev;
8230 rdev = wiphy_to_dev(wdev->wiphy);
8231
Johannes Berg1bf614e2012-06-15 15:23:36 +02008232 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8233 if (!dev) {
8234 mutex_unlock(&cfg80211_mutex);
8235 if (rtnl)
8236 rtnl_unlock();
8237 return -EINVAL;
8238 }
8239
8240 info->user_ptr[1] = dev;
8241 } else {
8242 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008243 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008244
Johannes Berg1bf614e2012-06-15 15:23:36 +02008245 if (dev) {
8246 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8247 !netif_running(dev)) {
8248 mutex_unlock(&cfg80211_mutex);
8249 if (rtnl)
8250 rtnl_unlock();
8251 return -ENETDOWN;
8252 }
8253
8254 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008255 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8256 if (!wdev->p2p_started) {
8257 mutex_unlock(&cfg80211_mutex);
8258 if (rtnl)
8259 rtnl_unlock();
8260 return -ENETDOWN;
8261 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008262 }
8263
Johannes Berg89a54e42012-06-15 14:33:17 +02008264 cfg80211_lock_rdev(rdev);
8265
8266 mutex_unlock(&cfg80211_mutex);
8267
Johannes Berg4c476992010-10-04 21:36:35 +02008268 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008269 }
8270
8271 return 0;
8272}
8273
8274static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8275 struct genl_info *info)
8276{
8277 if (info->user_ptr[0])
8278 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02008279 if (info->user_ptr[1]) {
8280 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8281 struct wireless_dev *wdev = info->user_ptr[1];
8282
8283 if (wdev->netdev)
8284 dev_put(wdev->netdev);
8285 } else {
8286 dev_put(info->user_ptr[1]);
8287 }
8288 }
Johannes Berg4c476992010-10-04 21:36:35 +02008289 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8290 rtnl_unlock();
8291}
8292
Johannes Berg55682962007-09-20 13:09:35 -04008293static struct genl_ops nl80211_ops[] = {
8294 {
8295 .cmd = NL80211_CMD_GET_WIPHY,
8296 .doit = nl80211_get_wiphy,
8297 .dumpit = nl80211_dump_wiphy,
8298 .policy = nl80211_policy,
8299 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008300 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04008301 },
8302 {
8303 .cmd = NL80211_CMD_SET_WIPHY,
8304 .doit = nl80211_set_wiphy,
8305 .policy = nl80211_policy,
8306 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008307 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008308 },
8309 {
8310 .cmd = NL80211_CMD_GET_INTERFACE,
8311 .doit = nl80211_get_interface,
8312 .dumpit = nl80211_dump_interface,
8313 .policy = nl80211_policy,
8314 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02008315 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04008316 },
8317 {
8318 .cmd = NL80211_CMD_SET_INTERFACE,
8319 .doit = nl80211_set_interface,
8320 .policy = nl80211_policy,
8321 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008322 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8323 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008324 },
8325 {
8326 .cmd = NL80211_CMD_NEW_INTERFACE,
8327 .doit = nl80211_new_interface,
8328 .policy = nl80211_policy,
8329 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008330 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8331 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008332 },
8333 {
8334 .cmd = NL80211_CMD_DEL_INTERFACE,
8335 .doit = nl80211_del_interface,
8336 .policy = nl80211_policy,
8337 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008338 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008339 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008340 },
Johannes Berg41ade002007-12-19 02:03:29 +01008341 {
8342 .cmd = NL80211_CMD_GET_KEY,
8343 .doit = nl80211_get_key,
8344 .policy = nl80211_policy,
8345 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008346 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008347 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008348 },
8349 {
8350 .cmd = NL80211_CMD_SET_KEY,
8351 .doit = nl80211_set_key,
8352 .policy = nl80211_policy,
8353 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008355 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008356 },
8357 {
8358 .cmd = NL80211_CMD_NEW_KEY,
8359 .doit = nl80211_new_key,
8360 .policy = nl80211_policy,
8361 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008363 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008364 },
8365 {
8366 .cmd = NL80211_CMD_DEL_KEY,
8367 .doit = nl80211_del_key,
8368 .policy = nl80211_policy,
8369 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008371 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008372 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008373 {
8374 .cmd = NL80211_CMD_SET_BEACON,
8375 .policy = nl80211_policy,
8376 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008377 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008379 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008380 },
8381 {
Johannes Berg88600202012-02-13 15:17:18 +01008382 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008383 .policy = nl80211_policy,
8384 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008385 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008387 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008388 },
8389 {
Johannes Berg88600202012-02-13 15:17:18 +01008390 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008391 .policy = nl80211_policy,
8392 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008393 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008395 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008396 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008397 {
8398 .cmd = NL80211_CMD_GET_STATION,
8399 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008400 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008401 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008402 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8403 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008404 },
8405 {
8406 .cmd = NL80211_CMD_SET_STATION,
8407 .doit = nl80211_set_station,
8408 .policy = nl80211_policy,
8409 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008410 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008411 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008412 },
8413 {
8414 .cmd = NL80211_CMD_NEW_STATION,
8415 .doit = nl80211_new_station,
8416 .policy = nl80211_policy,
8417 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008418 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008419 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008420 },
8421 {
8422 .cmd = NL80211_CMD_DEL_STATION,
8423 .doit = nl80211_del_station,
8424 .policy = nl80211_policy,
8425 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008426 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008427 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008428 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008429 {
8430 .cmd = NL80211_CMD_GET_MPATH,
8431 .doit = nl80211_get_mpath,
8432 .dumpit = nl80211_dump_mpath,
8433 .policy = nl80211_policy,
8434 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008436 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008437 },
8438 {
8439 .cmd = NL80211_CMD_SET_MPATH,
8440 .doit = nl80211_set_mpath,
8441 .policy = nl80211_policy,
8442 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008444 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008445 },
8446 {
8447 .cmd = NL80211_CMD_NEW_MPATH,
8448 .doit = nl80211_new_mpath,
8449 .policy = nl80211_policy,
8450 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008452 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008453 },
8454 {
8455 .cmd = NL80211_CMD_DEL_MPATH,
8456 .doit = nl80211_del_mpath,
8457 .policy = nl80211_policy,
8458 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008460 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008461 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008462 {
8463 .cmd = NL80211_CMD_SET_BSS,
8464 .doit = nl80211_set_bss,
8465 .policy = nl80211_policy,
8466 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008467 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008468 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008469 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008470 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008471 .cmd = NL80211_CMD_GET_REG,
8472 .doit = nl80211_get_reg,
8473 .policy = nl80211_policy,
8474 /* can be retrieved by unprivileged users */
8475 },
8476 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008477 .cmd = NL80211_CMD_SET_REG,
8478 .doit = nl80211_set_reg,
8479 .policy = nl80211_policy,
8480 .flags = GENL_ADMIN_PERM,
8481 },
8482 {
8483 .cmd = NL80211_CMD_REQ_SET_REG,
8484 .doit = nl80211_req_set_reg,
8485 .policy = nl80211_policy,
8486 .flags = GENL_ADMIN_PERM,
8487 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008488 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008489 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8490 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008491 .policy = nl80211_policy,
8492 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008494 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008495 },
8496 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008497 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8498 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008499 .policy = nl80211_policy,
8500 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008502 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008503 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008504 {
Johannes Berg2a519312009-02-10 21:25:55 +01008505 .cmd = NL80211_CMD_TRIGGER_SCAN,
8506 .doit = nl80211_trigger_scan,
8507 .policy = nl80211_policy,
8508 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008509 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008510 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008511 },
8512 {
8513 .cmd = NL80211_CMD_GET_SCAN,
8514 .policy = nl80211_policy,
8515 .dumpit = nl80211_dump_scan,
8516 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008517 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008518 .cmd = NL80211_CMD_START_SCHED_SCAN,
8519 .doit = nl80211_start_sched_scan,
8520 .policy = nl80211_policy,
8521 .flags = GENL_ADMIN_PERM,
8522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8523 NL80211_FLAG_NEED_RTNL,
8524 },
8525 {
8526 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8527 .doit = nl80211_stop_sched_scan,
8528 .policy = nl80211_policy,
8529 .flags = GENL_ADMIN_PERM,
8530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8531 NL80211_FLAG_NEED_RTNL,
8532 },
8533 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008534 .cmd = NL80211_CMD_AUTHENTICATE,
8535 .doit = nl80211_authenticate,
8536 .policy = nl80211_policy,
8537 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008539 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008540 },
8541 {
8542 .cmd = NL80211_CMD_ASSOCIATE,
8543 .doit = nl80211_associate,
8544 .policy = nl80211_policy,
8545 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008547 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008548 },
8549 {
8550 .cmd = NL80211_CMD_DEAUTHENTICATE,
8551 .doit = nl80211_deauthenticate,
8552 .policy = nl80211_policy,
8553 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008555 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008556 },
8557 {
8558 .cmd = NL80211_CMD_DISASSOCIATE,
8559 .doit = nl80211_disassociate,
8560 .policy = nl80211_policy,
8561 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008562 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008563 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008564 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008565 {
8566 .cmd = NL80211_CMD_JOIN_IBSS,
8567 .doit = nl80211_join_ibss,
8568 .policy = nl80211_policy,
8569 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008570 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008571 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008572 },
8573 {
8574 .cmd = NL80211_CMD_LEAVE_IBSS,
8575 .doit = nl80211_leave_ibss,
8576 .policy = nl80211_policy,
8577 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008578 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008579 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008580 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008581#ifdef CONFIG_NL80211_TESTMODE
8582 {
8583 .cmd = NL80211_CMD_TESTMODE,
8584 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008585 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008586 .policy = nl80211_policy,
8587 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008588 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8589 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008590 },
8591#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008592 {
8593 .cmd = NL80211_CMD_CONNECT,
8594 .doit = nl80211_connect,
8595 .policy = nl80211_policy,
8596 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008598 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008599 },
8600 {
8601 .cmd = NL80211_CMD_DISCONNECT,
8602 .doit = nl80211_disconnect,
8603 .policy = nl80211_policy,
8604 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008606 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008607 },
Johannes Berg463d0182009-07-14 00:33:35 +02008608 {
8609 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8610 .doit = nl80211_wiphy_netns,
8611 .policy = nl80211_policy,
8612 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008613 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8614 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008615 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008616 {
8617 .cmd = NL80211_CMD_GET_SURVEY,
8618 .policy = nl80211_policy,
8619 .dumpit = nl80211_dump_survey,
8620 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008621 {
8622 .cmd = NL80211_CMD_SET_PMKSA,
8623 .doit = nl80211_setdel_pmksa,
8624 .policy = nl80211_policy,
8625 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008626 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008627 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008628 },
8629 {
8630 .cmd = NL80211_CMD_DEL_PMKSA,
8631 .doit = nl80211_setdel_pmksa,
8632 .policy = nl80211_policy,
8633 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008634 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008635 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008636 },
8637 {
8638 .cmd = NL80211_CMD_FLUSH_PMKSA,
8639 .doit = nl80211_flush_pmksa,
8640 .policy = nl80211_policy,
8641 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008643 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008644 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008645 {
8646 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8647 .doit = nl80211_remain_on_channel,
8648 .policy = nl80211_policy,
8649 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008650 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008651 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008652 },
8653 {
8654 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8655 .doit = nl80211_cancel_remain_on_channel,
8656 .policy = nl80211_policy,
8657 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008658 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008659 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008660 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008661 {
8662 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8663 .doit = nl80211_set_tx_bitrate_mask,
8664 .policy = nl80211_policy,
8665 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008666 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8667 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008668 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008669 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008670 .cmd = NL80211_CMD_REGISTER_FRAME,
8671 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008672 .policy = nl80211_policy,
8673 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008674 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008675 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008676 },
8677 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008678 .cmd = NL80211_CMD_FRAME,
8679 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008680 .policy = nl80211_policy,
8681 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008682 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008683 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008684 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008685 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008686 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8687 .doit = nl80211_tx_mgmt_cancel_wait,
8688 .policy = nl80211_policy,
8689 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008690 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008691 NL80211_FLAG_NEED_RTNL,
8692 },
8693 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008694 .cmd = NL80211_CMD_SET_POWER_SAVE,
8695 .doit = nl80211_set_power_save,
8696 .policy = nl80211_policy,
8697 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008698 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8699 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008700 },
8701 {
8702 .cmd = NL80211_CMD_GET_POWER_SAVE,
8703 .doit = nl80211_get_power_save,
8704 .policy = nl80211_policy,
8705 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008706 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8707 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008708 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008709 {
8710 .cmd = NL80211_CMD_SET_CQM,
8711 .doit = nl80211_set_cqm,
8712 .policy = nl80211_policy,
8713 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008714 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8715 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008716 },
Johannes Bergf444de02010-05-05 15:25:02 +02008717 {
8718 .cmd = NL80211_CMD_SET_CHANNEL,
8719 .doit = nl80211_set_channel,
8720 .policy = nl80211_policy,
8721 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008722 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8723 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008724 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008725 {
8726 .cmd = NL80211_CMD_SET_WDS_PEER,
8727 .doit = nl80211_set_wds_peer,
8728 .policy = nl80211_policy,
8729 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008730 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8731 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008732 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008733 {
8734 .cmd = NL80211_CMD_JOIN_MESH,
8735 .doit = nl80211_join_mesh,
8736 .policy = nl80211_policy,
8737 .flags = GENL_ADMIN_PERM,
8738 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8739 NL80211_FLAG_NEED_RTNL,
8740 },
8741 {
8742 .cmd = NL80211_CMD_LEAVE_MESH,
8743 .doit = nl80211_leave_mesh,
8744 .policy = nl80211_policy,
8745 .flags = GENL_ADMIN_PERM,
8746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8747 NL80211_FLAG_NEED_RTNL,
8748 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008749#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008750 {
8751 .cmd = NL80211_CMD_GET_WOWLAN,
8752 .doit = nl80211_get_wowlan,
8753 .policy = nl80211_policy,
8754 /* can be retrieved by unprivileged users */
8755 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8756 NL80211_FLAG_NEED_RTNL,
8757 },
8758 {
8759 .cmd = NL80211_CMD_SET_WOWLAN,
8760 .doit = nl80211_set_wowlan,
8761 .policy = nl80211_policy,
8762 .flags = GENL_ADMIN_PERM,
8763 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8764 NL80211_FLAG_NEED_RTNL,
8765 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008766#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008767 {
8768 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8769 .doit = nl80211_set_rekey_data,
8770 .policy = nl80211_policy,
8771 .flags = GENL_ADMIN_PERM,
8772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8773 NL80211_FLAG_NEED_RTNL,
8774 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008775 {
8776 .cmd = NL80211_CMD_TDLS_MGMT,
8777 .doit = nl80211_tdls_mgmt,
8778 .policy = nl80211_policy,
8779 .flags = GENL_ADMIN_PERM,
8780 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8781 NL80211_FLAG_NEED_RTNL,
8782 },
8783 {
8784 .cmd = NL80211_CMD_TDLS_OPER,
8785 .doit = nl80211_tdls_oper,
8786 .policy = nl80211_policy,
8787 .flags = GENL_ADMIN_PERM,
8788 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8789 NL80211_FLAG_NEED_RTNL,
8790 },
Johannes Berg28946da2011-11-04 11:18:12 +01008791 {
8792 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8793 .doit = nl80211_register_unexpected_frame,
8794 .policy = nl80211_policy,
8795 .flags = GENL_ADMIN_PERM,
8796 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8797 NL80211_FLAG_NEED_RTNL,
8798 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008799 {
8800 .cmd = NL80211_CMD_PROBE_CLIENT,
8801 .doit = nl80211_probe_client,
8802 .policy = nl80211_policy,
8803 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008805 NL80211_FLAG_NEED_RTNL,
8806 },
Johannes Berg5e760232011-11-04 11:18:17 +01008807 {
8808 .cmd = NL80211_CMD_REGISTER_BEACONS,
8809 .doit = nl80211_register_beacons,
8810 .policy = nl80211_policy,
8811 .flags = GENL_ADMIN_PERM,
8812 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8813 NL80211_FLAG_NEED_RTNL,
8814 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008815 {
8816 .cmd = NL80211_CMD_SET_NOACK_MAP,
8817 .doit = nl80211_set_noack_map,
8818 .policy = nl80211_policy,
8819 .flags = GENL_ADMIN_PERM,
8820 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8821 NL80211_FLAG_NEED_RTNL,
8822 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008823 {
8824 .cmd = NL80211_CMD_START_P2P_DEVICE,
8825 .doit = nl80211_start_p2p_device,
8826 .policy = nl80211_policy,
8827 .flags = GENL_ADMIN_PERM,
8828 .internal_flags = NL80211_FLAG_NEED_WDEV |
8829 NL80211_FLAG_NEED_RTNL,
8830 },
8831 {
8832 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8833 .doit = nl80211_stop_p2p_device,
8834 .policy = nl80211_policy,
8835 .flags = GENL_ADMIN_PERM,
8836 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8837 NL80211_FLAG_NEED_RTNL,
8838 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008839 {
8840 .cmd = NL80211_CMD_SET_MCAST_RATE,
8841 .doit = nl80211_set_mcast_rate,
8842 .policy = nl80211_policy,
8843 .flags = GENL_ADMIN_PERM,
8844 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8845 NL80211_FLAG_NEED_RTNL,
8846 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308847 {
8848 .cmd = NL80211_CMD_SET_MAC_ACL,
8849 .doit = nl80211_set_mac_acl,
8850 .policy = nl80211_policy,
8851 .flags = GENL_ADMIN_PERM,
8852 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8853 NL80211_FLAG_NEED_RTNL,
8854 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008855 {
8856 .cmd = NL80211_CMD_RADAR_DETECT,
8857 .doit = nl80211_start_radar_detection,
8858 .policy = nl80211_policy,
8859 .flags = GENL_ADMIN_PERM,
8860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8861 NL80211_FLAG_NEED_RTNL,
8862 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008863 {
8864 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8865 .doit = nl80211_get_protocol_features,
8866 .policy = nl80211_policy,
8867 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008868 {
8869 .cmd = NL80211_CMD_UPDATE_FT_IES,
8870 .doit = nl80211_update_ft_ies,
8871 .policy = nl80211_policy,
8872 .flags = GENL_ADMIN_PERM,
8873 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8874 NL80211_FLAG_NEED_RTNL,
8875 },
Johannes Berg55682962007-09-20 13:09:35 -04008876};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008877
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008878static struct genl_multicast_group nl80211_mlme_mcgrp = {
8879 .name = "mlme",
8880};
Johannes Berg55682962007-09-20 13:09:35 -04008881
8882/* multicast groups */
8883static struct genl_multicast_group nl80211_config_mcgrp = {
8884 .name = "config",
8885};
Johannes Berg2a519312009-02-10 21:25:55 +01008886static struct genl_multicast_group nl80211_scan_mcgrp = {
8887 .name = "scan",
8888};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008889static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8890 .name = "regulatory",
8891};
Johannes Berg55682962007-09-20 13:09:35 -04008892
8893/* notification functions */
8894
8895void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8896{
8897 struct sk_buff *msg;
8898
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008900 if (!msg)
8901 return;
8902
Johannes Berg3713b4e2013-02-14 16:19:38 +01008903 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8904 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008905 nlmsg_free(msg);
8906 return;
8907 }
8908
Johannes Berg463d0182009-07-14 00:33:35 +02008909 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8910 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008911}
8912
Johannes Berg362a4152009-05-24 16:43:15 +02008913static int nl80211_add_scan_req(struct sk_buff *msg,
8914 struct cfg80211_registered_device *rdev)
8915{
8916 struct cfg80211_scan_request *req = rdev->scan_req;
8917 struct nlattr *nest;
8918 int i;
8919
Johannes Berg667503d2009-07-07 03:56:11 +02008920 ASSERT_RDEV_LOCK(rdev);
8921
Johannes Berg362a4152009-05-24 16:43:15 +02008922 if (WARN_ON(!req))
8923 return 0;
8924
8925 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8926 if (!nest)
8927 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008928 for (i = 0; i < req->n_ssids; i++) {
8929 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8930 goto nla_put_failure;
8931 }
Johannes Berg362a4152009-05-24 16:43:15 +02008932 nla_nest_end(msg, nest);
8933
8934 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8935 if (!nest)
8936 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008937 for (i = 0; i < req->n_channels; i++) {
8938 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8939 goto nla_put_failure;
8940 }
Johannes Berg362a4152009-05-24 16:43:15 +02008941 nla_nest_end(msg, nest);
8942
David S. Miller9360ffd2012-03-29 04:41:26 -04008943 if (req->ie &&
8944 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8945 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008946
Sam Lefflered4737712012-10-11 21:03:31 -07008947 if (req->flags)
8948 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8949
Johannes Berg362a4152009-05-24 16:43:15 +02008950 return 0;
8951 nla_put_failure:
8952 return -ENOBUFS;
8953}
8954
Johannes Berga538e2d2009-06-16 19:56:42 +02008955static int nl80211_send_scan_msg(struct sk_buff *msg,
8956 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008957 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008958 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008959 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008960{
8961 void *hdr;
8962
Eric W. Biederman15e47302012-09-07 20:12:54 +00008963 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008964 if (!hdr)
8965 return -1;
8966
David S. Miller9360ffd2012-03-29 04:41:26 -04008967 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008968 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8969 wdev->netdev->ifindex)) ||
8970 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008971 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008972
Johannes Berg362a4152009-05-24 16:43:15 +02008973 /* ignore errors and send incomplete event anyway */
8974 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008975
8976 return genlmsg_end(msg, hdr);
8977
8978 nla_put_failure:
8979 genlmsg_cancel(msg, hdr);
8980 return -EMSGSIZE;
8981}
8982
Luciano Coelho807f8a82011-05-11 17:09:35 +03008983static int
8984nl80211_send_sched_scan_msg(struct sk_buff *msg,
8985 struct cfg80211_registered_device *rdev,
8986 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008987 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008988{
8989 void *hdr;
8990
Eric W. Biederman15e47302012-09-07 20:12:54 +00008991 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008992 if (!hdr)
8993 return -1;
8994
David S. Miller9360ffd2012-03-29 04:41:26 -04008995 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8996 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8997 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008998
8999 return genlmsg_end(msg, hdr);
9000
9001 nla_put_failure:
9002 genlmsg_cancel(msg, hdr);
9003 return -EMSGSIZE;
9004}
9005
Johannes Berga538e2d2009-06-16 19:56:42 +02009006void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009007 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009008{
9009 struct sk_buff *msg;
9010
Thomas Graf58050fc2012-06-28 03:57:45 +00009011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009012 if (!msg)
9013 return;
9014
Johannes Bergfd014282012-06-18 19:17:03 +02009015 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009016 NL80211_CMD_TRIGGER_SCAN) < 0) {
9017 nlmsg_free(msg);
9018 return;
9019 }
9020
Johannes Berg463d0182009-07-14 00:33:35 +02009021 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9022 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009023}
9024
Johannes Berg2a519312009-02-10 21:25:55 +01009025void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009026 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009027{
9028 struct sk_buff *msg;
9029
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009030 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009031 if (!msg)
9032 return;
9033
Johannes Bergfd014282012-06-18 19:17:03 +02009034 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009035 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009036 nlmsg_free(msg);
9037 return;
9038 }
9039
Johannes Berg463d0182009-07-14 00:33:35 +02009040 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9041 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009042}
9043
9044void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009045 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009046{
9047 struct sk_buff *msg;
9048
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009049 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009050 if (!msg)
9051 return;
9052
Johannes Bergfd014282012-06-18 19:17:03 +02009053 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009054 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009055 nlmsg_free(msg);
9056 return;
9057 }
9058
Johannes Berg463d0182009-07-14 00:33:35 +02009059 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9060 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009061}
9062
Luciano Coelho807f8a82011-05-11 17:09:35 +03009063void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9064 struct net_device *netdev)
9065{
9066 struct sk_buff *msg;
9067
9068 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9069 if (!msg)
9070 return;
9071
9072 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9073 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9074 nlmsg_free(msg);
9075 return;
9076 }
9077
9078 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9079 nl80211_scan_mcgrp.id, GFP_KERNEL);
9080}
9081
9082void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9083 struct net_device *netdev, u32 cmd)
9084{
9085 struct sk_buff *msg;
9086
Thomas Graf58050fc2012-06-28 03:57:45 +00009087 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009088 if (!msg)
9089 return;
9090
9091 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9092 nlmsg_free(msg);
9093 return;
9094 }
9095
9096 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9097 nl80211_scan_mcgrp.id, GFP_KERNEL);
9098}
9099
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009100/*
9101 * This can happen on global regulatory changes or device specific settings
9102 * based on custom world regulatory domains.
9103 */
9104void nl80211_send_reg_change_event(struct regulatory_request *request)
9105{
9106 struct sk_buff *msg;
9107 void *hdr;
9108
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009109 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009110 if (!msg)
9111 return;
9112
9113 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9114 if (!hdr) {
9115 nlmsg_free(msg);
9116 return;
9117 }
9118
9119 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009120 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9121 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009122
David S. Miller9360ffd2012-03-29 04:41:26 -04009123 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9124 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9125 NL80211_REGDOM_TYPE_WORLD))
9126 goto nla_put_failure;
9127 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9128 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9129 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9130 goto nla_put_failure;
9131 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9132 request->intersect) {
9133 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9134 NL80211_REGDOM_TYPE_INTERSECTION))
9135 goto nla_put_failure;
9136 } else {
9137 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9138 NL80211_REGDOM_TYPE_COUNTRY) ||
9139 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9140 request->alpha2))
9141 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009142 }
9143
Johannes Bergf4173762012-12-03 18:23:37 +01009144 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009145 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9146 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009147
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009148 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009149
Johannes Bergbc43b282009-07-25 10:54:13 +02009150 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009151 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009152 GFP_ATOMIC);
9153 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009154
9155 return;
9156
9157nla_put_failure:
9158 genlmsg_cancel(msg, hdr);
9159 nlmsg_free(msg);
9160}
9161
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009162static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9163 struct net_device *netdev,
9164 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009165 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009166{
9167 struct sk_buff *msg;
9168 void *hdr;
9169
Johannes Berge6d6e342009-07-01 21:26:47 +02009170 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009171 if (!msg)
9172 return;
9173
9174 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9175 if (!hdr) {
9176 nlmsg_free(msg);
9177 return;
9178 }
9179
David S. Miller9360ffd2012-03-29 04:41:26 -04009180 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9181 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9182 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9183 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009184
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009185 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009186
Johannes Berg463d0182009-07-14 00:33:35 +02009187 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9188 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009189 return;
9190
9191 nla_put_failure:
9192 genlmsg_cancel(msg, hdr);
9193 nlmsg_free(msg);
9194}
9195
9196void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009197 struct net_device *netdev, const u8 *buf,
9198 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009199{
9200 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009201 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009202}
9203
9204void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9205 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009206 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009207{
Johannes Berge6d6e342009-07-01 21:26:47 +02009208 nl80211_send_mlme_event(rdev, netdev, buf, len,
9209 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009210}
9211
Jouni Malinen53b46b82009-03-27 20:53:56 +02009212void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009213 struct net_device *netdev, const u8 *buf,
9214 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009215{
9216 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009217 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009218}
9219
Jouni Malinen53b46b82009-03-27 20:53:56 +02009220void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9221 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009222 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009223{
9224 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009225 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009226}
9227
Johannes Berg947add32013-02-22 22:05:20 +01009228void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9229 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009230{
Johannes Berg947add32013-02-22 22:05:20 +01009231 struct wireless_dev *wdev = dev->ieee80211_ptr;
9232 struct wiphy *wiphy = wdev->wiphy;
9233 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009234
Johannes Berg947add32013-02-22 22:05:20 +01009235 trace_cfg80211_send_unprot_deauth(dev);
9236 nl80211_send_mlme_event(rdev, dev, buf, len,
9237 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009238}
Johannes Berg947add32013-02-22 22:05:20 +01009239EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9240
9241void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9242 size_t len)
9243{
9244 struct wireless_dev *wdev = dev->ieee80211_ptr;
9245 struct wiphy *wiphy = wdev->wiphy;
9246 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9247
9248 trace_cfg80211_send_unprot_disassoc(dev);
9249 nl80211_send_mlme_event(rdev, dev, buf, len,
9250 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9251}
9252EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009253
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009254static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9255 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009256 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009257{
9258 struct sk_buff *msg;
9259 void *hdr;
9260
Johannes Berge6d6e342009-07-01 21:26:47 +02009261 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009262 if (!msg)
9263 return;
9264
9265 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9266 if (!hdr) {
9267 nlmsg_free(msg);
9268 return;
9269 }
9270
David S. Miller9360ffd2012-03-29 04:41:26 -04009271 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9272 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9273 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9274 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9275 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009276
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009277 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009278
Johannes Berg463d0182009-07-14 00:33:35 +02009279 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9280 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009281 return;
9282
9283 nla_put_failure:
9284 genlmsg_cancel(msg, hdr);
9285 nlmsg_free(msg);
9286}
9287
9288void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009289 struct net_device *netdev, const u8 *addr,
9290 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009291{
9292 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009293 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009294}
9295
9296void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009297 struct net_device *netdev, const u8 *addr,
9298 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009299{
Johannes Berge6d6e342009-07-01 21:26:47 +02009300 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9301 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009302}
9303
Samuel Ortizb23aa672009-07-01 21:26:54 +02009304void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9305 struct net_device *netdev, const u8 *bssid,
9306 const u8 *req_ie, size_t req_ie_len,
9307 const u8 *resp_ie, size_t resp_ie_len,
9308 u16 status, gfp_t gfp)
9309{
9310 struct sk_buff *msg;
9311 void *hdr;
9312
Thomas Graf58050fc2012-06-28 03:57:45 +00009313 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009314 if (!msg)
9315 return;
9316
9317 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9318 if (!hdr) {
9319 nlmsg_free(msg);
9320 return;
9321 }
9322
David S. Miller9360ffd2012-03-29 04:41:26 -04009323 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9324 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9325 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9326 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9327 (req_ie &&
9328 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9329 (resp_ie &&
9330 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9331 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009332
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009333 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009334
Johannes Berg463d0182009-07-14 00:33:35 +02009335 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9336 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009337 return;
9338
9339 nla_put_failure:
9340 genlmsg_cancel(msg, hdr);
9341 nlmsg_free(msg);
9342
9343}
9344
9345void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9346 struct net_device *netdev, const u8 *bssid,
9347 const u8 *req_ie, size_t req_ie_len,
9348 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9349{
9350 struct sk_buff *msg;
9351 void *hdr;
9352
Thomas Graf58050fc2012-06-28 03:57:45 +00009353 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009354 if (!msg)
9355 return;
9356
9357 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9358 if (!hdr) {
9359 nlmsg_free(msg);
9360 return;
9361 }
9362
David S. Miller9360ffd2012-03-29 04:41:26 -04009363 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9364 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9366 (req_ie &&
9367 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9368 (resp_ie &&
9369 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9370 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009371
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009372 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009373
Johannes Berg463d0182009-07-14 00:33:35 +02009374 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9375 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009376 return;
9377
9378 nla_put_failure:
9379 genlmsg_cancel(msg, hdr);
9380 nlmsg_free(msg);
9381
9382}
9383
9384void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9385 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009386 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009387{
9388 struct sk_buff *msg;
9389 void *hdr;
9390
Thomas Graf58050fc2012-06-28 03:57:45 +00009391 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009392 if (!msg)
9393 return;
9394
9395 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9396 if (!hdr) {
9397 nlmsg_free(msg);
9398 return;
9399 }
9400
David S. Miller9360ffd2012-03-29 04:41:26 -04009401 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9402 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9403 (from_ap && reason &&
9404 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9405 (from_ap &&
9406 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9407 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9408 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009409
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009410 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009411
Johannes Berg463d0182009-07-14 00:33:35 +02009412 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9413 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009414 return;
9415
9416 nla_put_failure:
9417 genlmsg_cancel(msg, hdr);
9418 nlmsg_free(msg);
9419
9420}
9421
Johannes Berg04a773a2009-04-19 21:24:32 +02009422void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9423 struct net_device *netdev, const u8 *bssid,
9424 gfp_t gfp)
9425{
9426 struct sk_buff *msg;
9427 void *hdr;
9428
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009430 if (!msg)
9431 return;
9432
9433 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9434 if (!hdr) {
9435 nlmsg_free(msg);
9436 return;
9437 }
9438
David S. Miller9360ffd2012-03-29 04:41:26 -04009439 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9440 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9441 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9442 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009443
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009444 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009445
Johannes Berg463d0182009-07-14 00:33:35 +02009446 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9447 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009448 return;
9449
9450 nla_put_failure:
9451 genlmsg_cancel(msg, hdr);
9452 nlmsg_free(msg);
9453}
9454
Johannes Berg947add32013-02-22 22:05:20 +01009455void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9456 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009457{
Johannes Berg947add32013-02-22 22:05:20 +01009458 struct wireless_dev *wdev = dev->ieee80211_ptr;
9459 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009460 struct sk_buff *msg;
9461 void *hdr;
9462
Johannes Berg947add32013-02-22 22:05:20 +01009463 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9464 return;
9465
9466 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9467
Javier Cardonac93b5e72011-04-07 15:08:34 -07009468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9469 if (!msg)
9470 return;
9471
9472 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9473 if (!hdr) {
9474 nlmsg_free(msg);
9475 return;
9476 }
9477
David S. Miller9360ffd2012-03-29 04:41:26 -04009478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009479 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9480 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009481 (ie_len && ie &&
9482 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9483 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009484
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009485 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009486
9487 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9488 nl80211_mlme_mcgrp.id, gfp);
9489 return;
9490
9491 nla_put_failure:
9492 genlmsg_cancel(msg, hdr);
9493 nlmsg_free(msg);
9494}
Johannes Berg947add32013-02-22 22:05:20 +01009495EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009496
Jouni Malinena3b8b052009-03-27 21:59:49 +02009497void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9498 struct net_device *netdev, const u8 *addr,
9499 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009500 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009501{
9502 struct sk_buff *msg;
9503 void *hdr;
9504
Johannes Berge6d6e342009-07-01 21:26:47 +02009505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009506 if (!msg)
9507 return;
9508
9509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9510 if (!hdr) {
9511 nlmsg_free(msg);
9512 return;
9513 }
9514
David S. Miller9360ffd2012-03-29 04:41:26 -04009515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9517 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9518 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9519 (key_id != -1 &&
9520 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9521 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9522 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009523
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009524 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009525
Johannes Berg463d0182009-07-14 00:33:35 +02009526 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9527 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009528 return;
9529
9530 nla_put_failure:
9531 genlmsg_cancel(msg, hdr);
9532 nlmsg_free(msg);
9533}
9534
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009535void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9536 struct ieee80211_channel *channel_before,
9537 struct ieee80211_channel *channel_after)
9538{
9539 struct sk_buff *msg;
9540 void *hdr;
9541 struct nlattr *nl_freq;
9542
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009543 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009544 if (!msg)
9545 return;
9546
9547 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9548 if (!hdr) {
9549 nlmsg_free(msg);
9550 return;
9551 }
9552
9553 /*
9554 * Since we are applying the beacon hint to a wiphy we know its
9555 * wiphy_idx is valid
9556 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009557 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9558 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009559
9560 /* Before */
9561 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9562 if (!nl_freq)
9563 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009564 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009565 goto nla_put_failure;
9566 nla_nest_end(msg, nl_freq);
9567
9568 /* After */
9569 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9570 if (!nl_freq)
9571 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009572 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009573 goto nla_put_failure;
9574 nla_nest_end(msg, nl_freq);
9575
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009576 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009577
Johannes Berg463d0182009-07-14 00:33:35 +02009578 rcu_read_lock();
9579 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9580 GFP_ATOMIC);
9581 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009582
9583 return;
9584
9585nla_put_failure:
9586 genlmsg_cancel(msg, hdr);
9587 nlmsg_free(msg);
9588}
9589
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009590static void nl80211_send_remain_on_chan_event(
9591 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009592 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009593 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009594 unsigned int duration, gfp_t gfp)
9595{
9596 struct sk_buff *msg;
9597 void *hdr;
9598
9599 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9600 if (!msg)
9601 return;
9602
9603 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9604 if (!hdr) {
9605 nlmsg_free(msg);
9606 return;
9607 }
9608
David S. Miller9360ffd2012-03-29 04:41:26 -04009609 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009610 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9611 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009612 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009613 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009614 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9615 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009616 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9617 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009618
David S. Miller9360ffd2012-03-29 04:41:26 -04009619 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9620 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9621 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009622
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009623 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009624
9625 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9626 nl80211_mlme_mcgrp.id, gfp);
9627 return;
9628
9629 nla_put_failure:
9630 genlmsg_cancel(msg, hdr);
9631 nlmsg_free(msg);
9632}
9633
Johannes Berg947add32013-02-22 22:05:20 +01009634void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9635 struct ieee80211_channel *chan,
9636 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009637{
Johannes Berg947add32013-02-22 22:05:20 +01009638 struct wiphy *wiphy = wdev->wiphy;
9639 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9640
9641 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009642 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009643 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009644 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009645}
Johannes Berg947add32013-02-22 22:05:20 +01009646EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009647
Johannes Berg947add32013-02-22 22:05:20 +01009648void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9649 struct ieee80211_channel *chan,
9650 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009651{
Johannes Berg947add32013-02-22 22:05:20 +01009652 struct wiphy *wiphy = wdev->wiphy;
9653 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9654
9655 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009656 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009657 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009658}
Johannes Berg947add32013-02-22 22:05:20 +01009659EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009660
Johannes Berg947add32013-02-22 22:05:20 +01009661void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9662 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009663{
Johannes Berg947add32013-02-22 22:05:20 +01009664 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9665 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009666 struct sk_buff *msg;
9667
Johannes Berg947add32013-02-22 22:05:20 +01009668 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9669
Thomas Graf58050fc2012-06-28 03:57:45 +00009670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009671 if (!msg)
9672 return;
9673
John W. Linville66266b32012-03-15 13:25:41 -04009674 if (nl80211_send_station(msg, 0, 0, 0,
9675 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009676 nlmsg_free(msg);
9677 return;
9678 }
9679
9680 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9681 nl80211_mlme_mcgrp.id, gfp);
9682}
Johannes Berg947add32013-02-22 22:05:20 +01009683EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009684
Johannes Berg947add32013-02-22 22:05:20 +01009685void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009686{
Johannes Berg947add32013-02-22 22:05:20 +01009687 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9688 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009689 struct sk_buff *msg;
9690 void *hdr;
9691
Johannes Berg947add32013-02-22 22:05:20 +01009692 trace_cfg80211_del_sta(dev, mac_addr);
9693
Thomas Graf58050fc2012-06-28 03:57:45 +00009694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009695 if (!msg)
9696 return;
9697
9698 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9699 if (!hdr) {
9700 nlmsg_free(msg);
9701 return;
9702 }
9703
David S. Miller9360ffd2012-03-29 04:41:26 -04009704 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9705 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9706 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009707
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009708 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009709
9710 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9711 nl80211_mlme_mcgrp.id, gfp);
9712 return;
9713
9714 nla_put_failure:
9715 genlmsg_cancel(msg, hdr);
9716 nlmsg_free(msg);
9717}
Johannes Berg947add32013-02-22 22:05:20 +01009718EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009719
Johannes Berg947add32013-02-22 22:05:20 +01009720void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9721 enum nl80211_connect_failed_reason reason,
9722 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309723{
Johannes Berg947add32013-02-22 22:05:20 +01009724 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9725 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309726 struct sk_buff *msg;
9727 void *hdr;
9728
9729 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9730 if (!msg)
9731 return;
9732
9733 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9734 if (!hdr) {
9735 nlmsg_free(msg);
9736 return;
9737 }
9738
9739 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9740 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9741 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9742 goto nla_put_failure;
9743
9744 genlmsg_end(msg, hdr);
9745
9746 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9747 nl80211_mlme_mcgrp.id, gfp);
9748 return;
9749
9750 nla_put_failure:
9751 genlmsg_cancel(msg, hdr);
9752 nlmsg_free(msg);
9753}
Johannes Berg947add32013-02-22 22:05:20 +01009754EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309755
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009756static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9757 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009758{
9759 struct wireless_dev *wdev = dev->ieee80211_ptr;
9760 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9761 struct sk_buff *msg;
9762 void *hdr;
9763 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009764 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009765
Eric W. Biederman15e47302012-09-07 20:12:54 +00009766 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009767 return false;
9768
9769 msg = nlmsg_new(100, gfp);
9770 if (!msg)
9771 return true;
9772
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009773 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009774 if (!hdr) {
9775 nlmsg_free(msg);
9776 return true;
9777 }
9778
David S. Miller9360ffd2012-03-29 04:41:26 -04009779 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9780 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9781 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9782 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009783
9784 err = genlmsg_end(msg, hdr);
9785 if (err < 0) {
9786 nlmsg_free(msg);
9787 return true;
9788 }
9789
Eric W. Biederman15e47302012-09-07 20:12:54 +00009790 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009791 return true;
9792
9793 nla_put_failure:
9794 genlmsg_cancel(msg, hdr);
9795 nlmsg_free(msg);
9796 return true;
9797}
9798
Johannes Berg947add32013-02-22 22:05:20 +01009799bool cfg80211_rx_spurious_frame(struct net_device *dev,
9800 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009801{
Johannes Berg947add32013-02-22 22:05:20 +01009802 struct wireless_dev *wdev = dev->ieee80211_ptr;
9803 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009804
Johannes Berg947add32013-02-22 22:05:20 +01009805 trace_cfg80211_rx_spurious_frame(dev, addr);
9806
9807 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9808 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9809 trace_cfg80211_return_bool(false);
9810 return false;
9811 }
9812 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9813 addr, gfp);
9814 trace_cfg80211_return_bool(ret);
9815 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009816}
Johannes Berg947add32013-02-22 22:05:20 +01009817EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9818
9819bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9820 const u8 *addr, gfp_t gfp)
9821{
9822 struct wireless_dev *wdev = dev->ieee80211_ptr;
9823 bool ret;
9824
9825 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9826
9827 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9828 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9829 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9830 trace_cfg80211_return_bool(false);
9831 return false;
9832 }
9833 ret = __nl80211_unexpected_frame(dev,
9834 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9835 addr, gfp);
9836 trace_cfg80211_return_bool(ret);
9837 return ret;
9838}
9839EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009840
Johannes Berg2e161f72010-08-12 15:38:38 +02009841int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009842 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009843 int freq, int sig_dbm,
9844 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009845{
Johannes Berg71bbc992012-06-15 15:30:18 +02009846 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009847 struct sk_buff *msg;
9848 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009849
9850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9851 if (!msg)
9852 return -ENOMEM;
9853
Johannes Berg2e161f72010-08-12 15:38:38 +02009854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009855 if (!hdr) {
9856 nlmsg_free(msg);
9857 return -ENOMEM;
9858 }
9859
David S. Miller9360ffd2012-03-29 04:41:26 -04009860 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009861 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9862 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009863 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9864 (sig_dbm &&
9865 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9866 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9867 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009868
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009869 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009870
Eric W. Biederman15e47302012-09-07 20:12:54 +00009871 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009872
9873 nla_put_failure:
9874 genlmsg_cancel(msg, hdr);
9875 nlmsg_free(msg);
9876 return -ENOBUFS;
9877}
9878
Johannes Berg947add32013-02-22 22:05:20 +01009879void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9880 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009881{
Johannes Berg947add32013-02-22 22:05:20 +01009882 struct wiphy *wiphy = wdev->wiphy;
9883 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009884 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009885 struct sk_buff *msg;
9886 void *hdr;
9887
Johannes Berg947add32013-02-22 22:05:20 +01009888 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9889
Jouni Malinen026331c2010-02-15 12:53:10 +02009890 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9891 if (!msg)
9892 return;
9893
Johannes Berg2e161f72010-08-12 15:38:38 +02009894 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009895 if (!hdr) {
9896 nlmsg_free(msg);
9897 return;
9898 }
9899
David S. Miller9360ffd2012-03-29 04:41:26 -04009900 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009901 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9902 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009903 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9904 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9905 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9906 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009907
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009908 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009909
9910 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9911 return;
9912
9913 nla_put_failure:
9914 genlmsg_cancel(msg, hdr);
9915 nlmsg_free(msg);
9916}
Johannes Berg947add32013-02-22 22:05:20 +01009917EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009918
Johannes Berg947add32013-02-22 22:05:20 +01009919void cfg80211_cqm_rssi_notify(struct net_device *dev,
9920 enum nl80211_cqm_rssi_threshold_event rssi_event,
9921 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009922{
Johannes Berg947add32013-02-22 22:05:20 +01009923 struct wireless_dev *wdev = dev->ieee80211_ptr;
9924 struct wiphy *wiphy = wdev->wiphy;
9925 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009926 struct sk_buff *msg;
9927 struct nlattr *pinfoattr;
9928 void *hdr;
9929
Johannes Berg947add32013-02-22 22:05:20 +01009930 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
9931
Thomas Graf58050fc2012-06-28 03:57:45 +00009932 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009933 if (!msg)
9934 return;
9935
9936 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9937 if (!hdr) {
9938 nlmsg_free(msg);
9939 return;
9940 }
9941
David S. Miller9360ffd2012-03-29 04:41:26 -04009942 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009943 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -04009944 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009945
9946 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9947 if (!pinfoattr)
9948 goto nla_put_failure;
9949
David S. Miller9360ffd2012-03-29 04:41:26 -04009950 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9951 rssi_event))
9952 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009953
9954 nla_nest_end(msg, pinfoattr);
9955
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009956 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009957
9958 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9959 nl80211_mlme_mcgrp.id, gfp);
9960 return;
9961
9962 nla_put_failure:
9963 genlmsg_cancel(msg, hdr);
9964 nlmsg_free(msg);
9965}
Johannes Berg947add32013-02-22 22:05:20 +01009966EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009967
Johannes Berg947add32013-02-22 22:05:20 +01009968static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9969 struct net_device *netdev, const u8 *bssid,
9970 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +02009971{
9972 struct sk_buff *msg;
9973 struct nlattr *rekey_attr;
9974 void *hdr;
9975
Thomas Graf58050fc2012-06-28 03:57:45 +00009976 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009977 if (!msg)
9978 return;
9979
9980 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9981 if (!hdr) {
9982 nlmsg_free(msg);
9983 return;
9984 }
9985
David S. Miller9360ffd2012-03-29 04:41:26 -04009986 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9987 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9988 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9989 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009990
9991 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9992 if (!rekey_attr)
9993 goto nla_put_failure;
9994
David S. Miller9360ffd2012-03-29 04:41:26 -04009995 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9996 NL80211_REPLAY_CTR_LEN, replay_ctr))
9997 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009998
9999 nla_nest_end(msg, rekey_attr);
10000
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010001 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010002
10003 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10004 nl80211_mlme_mcgrp.id, gfp);
10005 return;
10006
10007 nla_put_failure:
10008 genlmsg_cancel(msg, hdr);
10009 nlmsg_free(msg);
10010}
10011
Johannes Berg947add32013-02-22 22:05:20 +010010012void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10013 const u8 *replay_ctr, gfp_t gfp)
10014{
10015 struct wireless_dev *wdev = dev->ieee80211_ptr;
10016 struct wiphy *wiphy = wdev->wiphy;
10017 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10018
10019 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10020 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10021}
10022EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10023
10024static void
10025nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10026 struct net_device *netdev, int index,
10027 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010028{
10029 struct sk_buff *msg;
10030 struct nlattr *attr;
10031 void *hdr;
10032
Thomas Graf58050fc2012-06-28 03:57:45 +000010033 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010034 if (!msg)
10035 return;
10036
10037 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10038 if (!hdr) {
10039 nlmsg_free(msg);
10040 return;
10041 }
10042
David S. Miller9360ffd2012-03-29 04:41:26 -040010043 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10044 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10045 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010046
10047 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10048 if (!attr)
10049 goto nla_put_failure;
10050
David S. Miller9360ffd2012-03-29 04:41:26 -040010051 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10052 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10053 (preauth &&
10054 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10055 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010056
10057 nla_nest_end(msg, attr);
10058
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010059 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010060
10061 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10062 nl80211_mlme_mcgrp.id, gfp);
10063 return;
10064
10065 nla_put_failure:
10066 genlmsg_cancel(msg, hdr);
10067 nlmsg_free(msg);
10068}
10069
Johannes Berg947add32013-02-22 22:05:20 +010010070void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10071 const u8 *bssid, bool preauth, gfp_t gfp)
10072{
10073 struct wireless_dev *wdev = dev->ieee80211_ptr;
10074 struct wiphy *wiphy = wdev->wiphy;
10075 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10076
10077 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10078 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10079}
10080EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10081
10082static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10083 struct net_device *netdev,
10084 struct cfg80211_chan_def *chandef,
10085 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010086{
10087 struct sk_buff *msg;
10088 void *hdr;
10089
Thomas Graf58050fc2012-06-28 03:57:45 +000010090 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010091 if (!msg)
10092 return;
10093
10094 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10095 if (!hdr) {
10096 nlmsg_free(msg);
10097 return;
10098 }
10099
Johannes Berg683b6d32012-11-08 21:25:48 +010010100 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10101 goto nla_put_failure;
10102
10103 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010104 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010105
10106 genlmsg_end(msg, hdr);
10107
10108 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10109 nl80211_mlme_mcgrp.id, gfp);
10110 return;
10111
10112 nla_put_failure:
10113 genlmsg_cancel(msg, hdr);
10114 nlmsg_free(msg);
10115}
10116
Johannes Berg947add32013-02-22 22:05:20 +010010117void cfg80211_ch_switch_notify(struct net_device *dev,
10118 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010119{
Johannes Berg947add32013-02-22 22:05:20 +010010120 struct wireless_dev *wdev = dev->ieee80211_ptr;
10121 struct wiphy *wiphy = wdev->wiphy;
10122 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10123
10124 trace_cfg80211_ch_switch_notify(dev, chandef);
10125
10126 wdev_lock(wdev);
10127
10128 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10129 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10130 goto out;
10131
10132 wdev->channel = chandef->chan;
10133 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10134out:
10135 wdev_unlock(wdev);
10136 return;
10137}
10138EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10139
10140void cfg80211_cqm_txe_notify(struct net_device *dev,
10141 const u8 *peer, u32 num_packets,
10142 u32 rate, u32 intvl, gfp_t gfp)
10143{
10144 struct wireless_dev *wdev = dev->ieee80211_ptr;
10145 struct wiphy *wiphy = wdev->wiphy;
10146 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010147 struct sk_buff *msg;
10148 struct nlattr *pinfoattr;
10149 void *hdr;
10150
10151 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10152 if (!msg)
10153 return;
10154
10155 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10156 if (!hdr) {
10157 nlmsg_free(msg);
10158 return;
10159 }
10160
10161 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010162 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010163 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10164 goto nla_put_failure;
10165
10166 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10167 if (!pinfoattr)
10168 goto nla_put_failure;
10169
10170 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10171 goto nla_put_failure;
10172
10173 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10174 goto nla_put_failure;
10175
10176 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10177 goto nla_put_failure;
10178
10179 nla_nest_end(msg, pinfoattr);
10180
10181 genlmsg_end(msg, hdr);
10182
10183 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10184 nl80211_mlme_mcgrp.id, gfp);
10185 return;
10186
10187 nla_put_failure:
10188 genlmsg_cancel(msg, hdr);
10189 nlmsg_free(msg);
10190}
Johannes Berg947add32013-02-22 22:05:20 +010010191EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010192
10193void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010194nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10195 struct cfg80211_chan_def *chandef,
10196 enum nl80211_radar_event event,
10197 struct net_device *netdev, gfp_t gfp)
10198{
10199 struct sk_buff *msg;
10200 void *hdr;
10201
10202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10203 if (!msg)
10204 return;
10205
10206 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10207 if (!hdr) {
10208 nlmsg_free(msg);
10209 return;
10210 }
10211
10212 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10213 goto nla_put_failure;
10214
10215 /* NOP and radar events don't need a netdev parameter */
10216 if (netdev) {
10217 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10218
10219 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10220 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10221 goto nla_put_failure;
10222 }
10223
10224 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10225 goto nla_put_failure;
10226
10227 if (nl80211_send_chandef(msg, chandef))
10228 goto nla_put_failure;
10229
10230 if (genlmsg_end(msg, hdr) < 0) {
10231 nlmsg_free(msg);
10232 return;
10233 }
10234
10235 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10236 nl80211_mlme_mcgrp.id, gfp);
10237 return;
10238
10239 nla_put_failure:
10240 genlmsg_cancel(msg, hdr);
10241 nlmsg_free(msg);
10242}
10243
Johannes Berg947add32013-02-22 22:05:20 +010010244void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10245 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010246{
Johannes Berg947add32013-02-22 22:05:20 +010010247 struct wireless_dev *wdev = dev->ieee80211_ptr;
10248 struct wiphy *wiphy = wdev->wiphy;
10249 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010250 struct sk_buff *msg;
10251 struct nlattr *pinfoattr;
10252 void *hdr;
10253
Johannes Berg947add32013-02-22 22:05:20 +010010254 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10255
Thomas Graf58050fc2012-06-28 03:57:45 +000010256 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010257 if (!msg)
10258 return;
10259
10260 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10261 if (!hdr) {
10262 nlmsg_free(msg);
10263 return;
10264 }
10265
David S. Miller9360ffd2012-03-29 04:41:26 -040010266 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010267 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010268 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10269 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010270
10271 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10272 if (!pinfoattr)
10273 goto nla_put_failure;
10274
David S. Miller9360ffd2012-03-29 04:41:26 -040010275 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10276 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010277
10278 nla_nest_end(msg, pinfoattr);
10279
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010280 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010281
10282 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10283 nl80211_mlme_mcgrp.id, gfp);
10284 return;
10285
10286 nla_put_failure:
10287 genlmsg_cancel(msg, hdr);
10288 nlmsg_free(msg);
10289}
Johannes Berg947add32013-02-22 22:05:20 +010010290EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010291
Johannes Berg7f6cf312011-11-04 11:18:15 +010010292void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10293 u64 cookie, bool acked, gfp_t gfp)
10294{
10295 struct wireless_dev *wdev = dev->ieee80211_ptr;
10296 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10297 struct sk_buff *msg;
10298 void *hdr;
10299 int err;
10300
Beni Lev4ee3e062012-08-27 12:49:39 +030010301 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10302
Thomas Graf58050fc2012-06-28 03:57:45 +000010303 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010304
Johannes Berg7f6cf312011-11-04 11:18:15 +010010305 if (!msg)
10306 return;
10307
10308 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10309 if (!hdr) {
10310 nlmsg_free(msg);
10311 return;
10312 }
10313
David S. Miller9360ffd2012-03-29 04:41:26 -040010314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10315 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10316 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10317 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10318 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10319 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010320
10321 err = genlmsg_end(msg, hdr);
10322 if (err < 0) {
10323 nlmsg_free(msg);
10324 return;
10325 }
10326
10327 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10328 nl80211_mlme_mcgrp.id, gfp);
10329 return;
10330
10331 nla_put_failure:
10332 genlmsg_cancel(msg, hdr);
10333 nlmsg_free(msg);
10334}
10335EXPORT_SYMBOL(cfg80211_probe_status);
10336
Johannes Berg5e760232011-11-04 11:18:17 +010010337void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10338 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010339 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010340{
10341 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10342 struct sk_buff *msg;
10343 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010344 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010345
Beni Lev4ee3e062012-08-27 12:49:39 +030010346 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10347
Ben Greear37c73b52012-10-26 14:49:25 -070010348 spin_lock_bh(&rdev->beacon_registrations_lock);
10349 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10350 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10351 if (!msg) {
10352 spin_unlock_bh(&rdev->beacon_registrations_lock);
10353 return;
10354 }
Johannes Berg5e760232011-11-04 11:18:17 +010010355
Ben Greear37c73b52012-10-26 14:49:25 -070010356 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10357 if (!hdr)
10358 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010359
Ben Greear37c73b52012-10-26 14:49:25 -070010360 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10361 (freq &&
10362 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10363 (sig_dbm &&
10364 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10365 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10366 goto nla_put_failure;
10367
10368 genlmsg_end(msg, hdr);
10369
10370 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010371 }
Ben Greear37c73b52012-10-26 14:49:25 -070010372 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010373 return;
10374
10375 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010376 spin_unlock_bh(&rdev->beacon_registrations_lock);
10377 if (hdr)
10378 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010379 nlmsg_free(msg);
10380}
10381EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10382
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010383#ifdef CONFIG_PM
10384void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10385 struct cfg80211_wowlan_wakeup *wakeup,
10386 gfp_t gfp)
10387{
10388 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10389 struct sk_buff *msg;
10390 void *hdr;
10391 int err, size = 200;
10392
10393 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10394
10395 if (wakeup)
10396 size += wakeup->packet_present_len;
10397
10398 msg = nlmsg_new(size, gfp);
10399 if (!msg)
10400 return;
10401
10402 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10403 if (!hdr)
10404 goto free_msg;
10405
10406 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10407 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10408 goto free_msg;
10409
10410 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10411 wdev->netdev->ifindex))
10412 goto free_msg;
10413
10414 if (wakeup) {
10415 struct nlattr *reasons;
10416
10417 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10418
10419 if (wakeup->disconnect &&
10420 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10421 goto free_msg;
10422 if (wakeup->magic_pkt &&
10423 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10424 goto free_msg;
10425 if (wakeup->gtk_rekey_failure &&
10426 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10427 goto free_msg;
10428 if (wakeup->eap_identity_req &&
10429 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10430 goto free_msg;
10431 if (wakeup->four_way_handshake &&
10432 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10433 goto free_msg;
10434 if (wakeup->rfkill_release &&
10435 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10436 goto free_msg;
10437
10438 if (wakeup->pattern_idx >= 0 &&
10439 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10440 wakeup->pattern_idx))
10441 goto free_msg;
10442
Johannes Berg2a0e0472013-01-23 22:57:40 +010010443 if (wakeup->tcp_match)
10444 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10445
10446 if (wakeup->tcp_connlost)
10447 nla_put_flag(msg,
10448 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10449
10450 if (wakeup->tcp_nomoretokens)
10451 nla_put_flag(msg,
10452 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10453
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010454 if (wakeup->packet) {
10455 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10456 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10457
10458 if (!wakeup->packet_80211) {
10459 pkt_attr =
10460 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10461 len_attr =
10462 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10463 }
10464
10465 if (wakeup->packet_len &&
10466 nla_put_u32(msg, len_attr, wakeup->packet_len))
10467 goto free_msg;
10468
10469 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10470 wakeup->packet))
10471 goto free_msg;
10472 }
10473
10474 nla_nest_end(msg, reasons);
10475 }
10476
10477 err = genlmsg_end(msg, hdr);
10478 if (err < 0)
10479 goto free_msg;
10480
10481 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10482 nl80211_mlme_mcgrp.id, gfp);
10483 return;
10484
10485 free_msg:
10486 nlmsg_free(msg);
10487}
10488EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10489#endif
10490
Jouni Malinen3475b092012-11-16 22:49:57 +020010491void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10492 enum nl80211_tdls_operation oper,
10493 u16 reason_code, gfp_t gfp)
10494{
10495 struct wireless_dev *wdev = dev->ieee80211_ptr;
10496 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10497 struct sk_buff *msg;
10498 void *hdr;
10499 int err;
10500
10501 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10502 reason_code);
10503
10504 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10505 if (!msg)
10506 return;
10507
10508 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10509 if (!hdr) {
10510 nlmsg_free(msg);
10511 return;
10512 }
10513
10514 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10515 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10516 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10517 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10518 (reason_code > 0 &&
10519 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10520 goto nla_put_failure;
10521
10522 err = genlmsg_end(msg, hdr);
10523 if (err < 0) {
10524 nlmsg_free(msg);
10525 return;
10526 }
10527
10528 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10529 nl80211_mlme_mcgrp.id, gfp);
10530 return;
10531
10532 nla_put_failure:
10533 genlmsg_cancel(msg, hdr);
10534 nlmsg_free(msg);
10535}
10536EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10537
Jouni Malinen026331c2010-02-15 12:53:10 +020010538static int nl80211_netlink_notify(struct notifier_block * nb,
10539 unsigned long state,
10540 void *_notify)
10541{
10542 struct netlink_notify *notify = _notify;
10543 struct cfg80211_registered_device *rdev;
10544 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010545 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010546
10547 if (state != NETLINK_URELEASE)
10548 return NOTIFY_DONE;
10549
10550 rcu_read_lock();
10551
Johannes Berg5e760232011-11-04 11:18:17 +010010552 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010553 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010554 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010555
10556 spin_lock_bh(&rdev->beacon_registrations_lock);
10557 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10558 list) {
10559 if (reg->nlportid == notify->portid) {
10560 list_del(&reg->list);
10561 kfree(reg);
10562 break;
10563 }
10564 }
10565 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010566 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010567
10568 rcu_read_unlock();
10569
10570 return NOTIFY_DONE;
10571}
10572
10573static struct notifier_block nl80211_netlink_notifier = {
10574 .notifier_call = nl80211_netlink_notify,
10575};
10576
Jouni Malinen355199e2013-02-27 17:14:27 +020010577void cfg80211_ft_event(struct net_device *netdev,
10578 struct cfg80211_ft_event_params *ft_event)
10579{
10580 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10581 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10582 struct sk_buff *msg;
10583 void *hdr;
10584 int err;
10585
10586 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10587
10588 if (!ft_event->target_ap)
10589 return;
10590
10591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10592 if (!msg)
10593 return;
10594
10595 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10596 if (!hdr) {
10597 nlmsg_free(msg);
10598 return;
10599 }
10600
10601 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10602 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10603 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10604 if (ft_event->ies)
10605 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10606 if (ft_event->ric_ies)
10607 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10608 ft_event->ric_ies);
10609
10610 err = genlmsg_end(msg, hdr);
10611 if (err < 0) {
10612 nlmsg_free(msg);
10613 return;
10614 }
10615
10616 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10617 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10618}
10619EXPORT_SYMBOL(cfg80211_ft_event);
10620
Johannes Berg55682962007-09-20 13:09:35 -040010621/* initialisation/exit functions */
10622
10623int nl80211_init(void)
10624{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010625 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010626
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010627 err = genl_register_family_with_ops(&nl80211_fam,
10628 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010629 if (err)
10630 return err;
10631
Johannes Berg55682962007-09-20 13:09:35 -040010632 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10633 if (err)
10634 goto err_out;
10635
Johannes Berg2a519312009-02-10 21:25:55 +010010636 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10637 if (err)
10638 goto err_out;
10639
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010640 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10641 if (err)
10642 goto err_out;
10643
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010644 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10645 if (err)
10646 goto err_out;
10647
Johannes Bergaff89a92009-07-01 21:26:51 +020010648#ifdef CONFIG_NL80211_TESTMODE
10649 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10650 if (err)
10651 goto err_out;
10652#endif
10653
Jouni Malinen026331c2010-02-15 12:53:10 +020010654 err = netlink_register_notifier(&nl80211_netlink_notifier);
10655 if (err)
10656 goto err_out;
10657
Johannes Berg55682962007-09-20 13:09:35 -040010658 return 0;
10659 err_out:
10660 genl_unregister_family(&nl80211_fam);
10661 return err;
10662}
10663
10664void nl80211_exit(void)
10665{
Jouni Malinen026331c2010-02-15 12:53:10 +020010666 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010667 genl_unregister_family(&nl80211_fam);
10668}