blob: 671b69a3c13646e39e4fc00209b4d588f1d37a1a [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) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003620 case CFG80211_STA_MESH_PEER_KERNEL:
3621 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003622 /*
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;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003723 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003724 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3725 return -EINVAL;
3726 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003727 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003728 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3729 return -EINVAL;
3730 break;
3731 }
3732
3733 return 0;
3734}
3735EXPORT_SYMBOL(cfg80211_check_station_change);
3736
Johannes Berg5727ef12007-12-19 02:03:34 +01003737/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003738 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003739 */
Johannes Berg80b99892011-11-18 16:23:01 +01003740static struct net_device *get_vlan(struct genl_info *info,
3741 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003742{
Johannes Berg463d0182009-07-14 00:33:35 +02003743 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003744 struct net_device *v;
3745 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003746
Johannes Berg80b99892011-11-18 16:23:01 +01003747 if (!vlanattr)
3748 return NULL;
3749
3750 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3751 if (!v)
3752 return ERR_PTR(-ENODEV);
3753
3754 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3755 ret = -EINVAL;
3756 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003757 }
Johannes Berg80b99892011-11-18 16:23:01 +01003758
Johannes Berg77ee7c82013-02-15 00:48:33 +01003759 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3760 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3761 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3762 ret = -EINVAL;
3763 goto error;
3764 }
3765
Johannes Berg80b99892011-11-18 16:23:01 +01003766 if (!netif_running(v)) {
3767 ret = -ENETDOWN;
3768 goto error;
3769 }
3770
3771 return v;
3772 error:
3773 dev_put(v);
3774 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003775}
3776
Jouni Malinendf881292013-02-14 21:10:54 +02003777static struct nla_policy
3778nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3779 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3780 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3781};
3782
Johannes Bergff276692013-02-15 00:09:01 +01003783static int nl80211_parse_sta_wme(struct genl_info *info,
3784 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003785{
Jouni Malinendf881292013-02-14 21:10:54 +02003786 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3787 struct nlattr *nla;
3788 int err;
3789
Jouni Malinendf881292013-02-14 21:10:54 +02003790 /* parse WME attributes if present */
3791 if (!info->attrs[NL80211_ATTR_STA_WME])
3792 return 0;
3793
3794 nla = info->attrs[NL80211_ATTR_STA_WME];
3795 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3796 nl80211_sta_wme_policy);
3797 if (err)
3798 return err;
3799
3800 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3801 params->uapsd_queues = nla_get_u8(
3802 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3803 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3804 return -EINVAL;
3805
3806 if (tb[NL80211_STA_WME_MAX_SP])
3807 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3808
3809 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3810 return -EINVAL;
3811
3812 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3813
3814 return 0;
3815}
3816
Johannes Bergff276692013-02-15 00:09:01 +01003817static int nl80211_set_station_tdls(struct genl_info *info,
3818 struct station_parameters *params)
3819{
3820 /* Dummy STA entry gets updated once the peer capabilities are known */
3821 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3822 params->ht_capa =
3823 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3824 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3825 params->vht_capa =
3826 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3827
3828 return nl80211_parse_sta_wme(info, params);
3829}
3830
Johannes Berg5727ef12007-12-19 02:03:34 +01003831static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3832{
Johannes Berg4c476992010-10-04 21:36:35 +02003833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003834 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003835 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003836 u8 *mac_addr;
3837 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003838
3839 memset(&params, 0, sizeof(params));
3840
3841 params.listen_interval = -1;
3842
Johannes Berg77ee7c82013-02-15 00:48:33 +01003843 if (!rdev->ops->change_station)
3844 return -EOPNOTSUPP;
3845
Johannes Berg5727ef12007-12-19 02:03:34 +01003846 if (info->attrs[NL80211_ATTR_STA_AID])
3847 return -EINVAL;
3848
3849 if (!info->attrs[NL80211_ATTR_MAC])
3850 return -EINVAL;
3851
3852 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3853
3854 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3855 params.supported_rates =
3856 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3857 params.supported_rates_len =
3858 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3859 }
3860
Jouni Malinen9d62a982013-02-14 21:10:13 +02003861 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3862 params.capability =
3863 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3864 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3865 }
3866
3867 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3868 params.ext_capab =
3869 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3870 params.ext_capab_len =
3871 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3872 }
3873
Jouni Malinendf881292013-02-14 21:10:54 +02003874 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003875 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003876
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003877 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003878 return -EINVAL;
3879
Johannes Bergf8bacc22013-02-14 23:27:01 +01003880 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003881 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003882 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3883 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3884 return -EINVAL;
3885 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003886
Johannes Bergf8bacc22013-02-14 23:27:01 +01003887 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003888 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003889 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3890 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3891 return -EINVAL;
3892 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3893 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003894
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003895 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3896 enum nl80211_mesh_power_mode pm = nla_get_u32(
3897 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3898
3899 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3900 pm > NL80211_MESH_POWER_MAX)
3901 return -EINVAL;
3902
3903 params.local_pm = pm;
3904 }
3905
Johannes Berg77ee7c82013-02-15 00:48:33 +01003906 /* Include parameters for TDLS peer (will check later) */
3907 err = nl80211_set_station_tdls(info, &params);
3908 if (err)
3909 return err;
3910
3911 params.vlan = get_vlan(info, rdev);
3912 if (IS_ERR(params.vlan))
3913 return PTR_ERR(params.vlan);
3914
Johannes Berga97f4422009-06-18 17:23:43 +02003915 switch (dev->ieee80211_ptr->iftype) {
3916 case NL80211_IFTYPE_AP:
3917 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003918 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003919 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003920 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003921 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003922 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003923 break;
3924 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003925 err = -EOPNOTSUPP;
3926 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003927 }
3928
Johannes Berg77ee7c82013-02-15 00:48:33 +01003929 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003930 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003931
Johannes Berg77ee7c82013-02-15 00:48:33 +01003932 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003933 if (params.vlan)
3934 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003935
Johannes Berg5727ef12007-12-19 02:03:34 +01003936 return err;
3937}
3938
3939static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3940{
Johannes Berg4c476992010-10-04 21:36:35 +02003941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003942 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003943 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003944 struct station_parameters params;
3945 u8 *mac_addr = NULL;
3946
3947 memset(&params, 0, sizeof(params));
3948
Johannes Berg984c3112013-02-14 23:43:25 +01003949 if (!rdev->ops->add_station)
3950 return -EOPNOTSUPP;
3951
Johannes Berg5727ef12007-12-19 02:03:34 +01003952 if (!info->attrs[NL80211_ATTR_MAC])
3953 return -EINVAL;
3954
Johannes Berg5727ef12007-12-19 02:03:34 +01003955 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3956 return -EINVAL;
3957
3958 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3959 return -EINVAL;
3960
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003961 if (!info->attrs[NL80211_ATTR_STA_AID])
3962 return -EINVAL;
3963
Johannes Berg5727ef12007-12-19 02:03:34 +01003964 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3965 params.supported_rates =
3966 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3967 params.supported_rates_len =
3968 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3969 params.listen_interval =
3970 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003971
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003972 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3973 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3974 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003975
Jouni Malinen9d62a982013-02-14 21:10:13 +02003976 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3977 params.capability =
3978 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3979 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3980 }
3981
3982 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3983 params.ext_capab =
3984 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3985 params.ext_capab_len =
3986 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3987 }
3988
Jouni Malinen36aedc92008-08-25 11:58:58 +03003989 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3990 params.ht_capa =
3991 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003992
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003993 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3994 params.vht_capa =
3995 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3996
Johannes Bergf8bacc22013-02-14 23:27:01 +01003997 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07003998 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003999 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4000 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4001 return -EINVAL;
4002 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004003
Johannes Bergff276692013-02-15 00:09:01 +01004004 err = nl80211_parse_sta_wme(info, &params);
4005 if (err)
4006 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004007
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004008 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004009 return -EINVAL;
4010
Johannes Berg77ee7c82013-02-15 00:48:33 +01004011 /* When you run into this, adjust the code below for the new flag */
4012 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4013
Johannes Bergbdd90d52011-12-14 12:20:27 +01004014 switch (dev->ieee80211_ptr->iftype) {
4015 case NL80211_IFTYPE_AP:
4016 case NL80211_IFTYPE_AP_VLAN:
4017 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004018 /* ignore WME attributes if iface/sta is not capable */
4019 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4020 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4021 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004022
Johannes Bergbdd90d52011-12-14 12:20:27 +01004023 /* TDLS peers cannot be added */
4024 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004025 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004026 /* but don't bother the driver with it */
4027 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004028
Johannes Bergd582cff2012-10-26 17:53:44 +02004029 /* allow authenticated/associated only if driver handles it */
4030 if (!(rdev->wiphy.features &
4031 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4032 params.sta_flags_mask &
4033 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4034 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4035 return -EINVAL;
4036
Johannes Bergbdd90d52011-12-14 12:20:27 +01004037 /* must be last in here for error handling */
4038 params.vlan = get_vlan(info, rdev);
4039 if (IS_ERR(params.vlan))
4040 return PTR_ERR(params.vlan);
4041 break;
4042 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004043 /* ignore uAPSD data */
4044 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4045
Johannes Bergd582cff2012-10-26 17:53:44 +02004046 /* associated is disallowed */
4047 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4048 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004049 /* TDLS peers cannot be added */
4050 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004051 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004052 break;
4053 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004054 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004055 /* ignore uAPSD data */
4056 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4057
Johannes Berg77ee7c82013-02-15 00:48:33 +01004058 /* these are disallowed */
4059 if (params.sta_flags_mask &
4060 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4061 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004062 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004063 /* Only TDLS peers can be added */
4064 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4065 return -EINVAL;
4066 /* Can only add if TDLS ... */
4067 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4068 return -EOPNOTSUPP;
4069 /* ... with external setup is supported */
4070 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4071 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004072 /*
4073 * Older wpa_supplicant versions always mark the TDLS peer
4074 * as authorized, but it shouldn't yet be.
4075 */
4076 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004077 break;
4078 default:
4079 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004080 }
4081
Johannes Bergbdd90d52011-12-14 12:20:27 +01004082 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004083
Hila Gonene35e4d22012-06-27 17:19:42 +03004084 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004085
Johannes Berg5727ef12007-12-19 02:03:34 +01004086 if (params.vlan)
4087 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004088 return err;
4089}
4090
4091static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4092{
Johannes Berg4c476992010-10-04 21:36:35 +02004093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4094 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004095 u8 *mac_addr = NULL;
4096
4097 if (info->attrs[NL80211_ATTR_MAC])
4098 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4099
Johannes Berge80cf852009-05-11 14:43:13 +02004100 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004101 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004103 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4104 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004105
Johannes Berg4c476992010-10-04 21:36:35 +02004106 if (!rdev->ops->del_station)
4107 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004108
Hila Gonene35e4d22012-06-27 17:19:42 +03004109 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004110}
4111
Eric W. Biederman15e47302012-09-07 20:12:54 +00004112static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004113 int flags, struct net_device *dev,
4114 u8 *dst, u8 *next_hop,
4115 struct mpath_info *pinfo)
4116{
4117 void *hdr;
4118 struct nlattr *pinfoattr;
4119
Eric W. Biederman15e47302012-09-07 20:12:54 +00004120 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004121 if (!hdr)
4122 return -1;
4123
David S. Miller9360ffd2012-03-29 04:41:26 -04004124 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4125 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4126 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4127 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4128 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004129
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004130 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4131 if (!pinfoattr)
4132 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004133 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4134 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4135 pinfo->frame_qlen))
4136 goto nla_put_failure;
4137 if (((pinfo->filled & MPATH_INFO_SN) &&
4138 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4139 ((pinfo->filled & MPATH_INFO_METRIC) &&
4140 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4141 pinfo->metric)) ||
4142 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4143 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4144 pinfo->exptime)) ||
4145 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4146 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4147 pinfo->flags)) ||
4148 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4149 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4150 pinfo->discovery_timeout)) ||
4151 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4152 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4153 pinfo->discovery_retries)))
4154 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004155
4156 nla_nest_end(msg, pinfoattr);
4157
4158 return genlmsg_end(msg, hdr);
4159
4160 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004161 genlmsg_cancel(msg, hdr);
4162 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004163}
4164
4165static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004166 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004167{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004168 struct mpath_info pinfo;
4169 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004170 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004171 u8 dst[ETH_ALEN];
4172 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02004173 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004174 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004175
Johannes Berg67748892010-10-04 21:14:06 +02004176 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4177 if (err)
4178 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004179
4180 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004181 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004182 goto out_err;
4183 }
4184
Jouni Malineneec60b02009-03-20 21:21:19 +02004185 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
4186 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004187 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004188 }
4189
Johannes Bergbba95fe2008-07-29 13:22:51 +02004190 while (1) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004191 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
4192 &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004193 if (err == -ENOENT)
4194 break;
4195 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004196 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004197
Eric W. Biederman15e47302012-09-07 20:12:54 +00004198 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004199 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4200 netdev, dst, next_hop,
4201 &pinfo) < 0)
4202 goto out;
4203
4204 path_idx++;
4205 }
4206
4207
4208 out:
4209 cb->args[1] = path_idx;
4210 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004211 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004212 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004213 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004214}
4215
4216static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4217{
Johannes Berg4c476992010-10-04 21:36:35 +02004218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004219 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004220 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004221 struct mpath_info pinfo;
4222 struct sk_buff *msg;
4223 u8 *dst = NULL;
4224 u8 next_hop[ETH_ALEN];
4225
4226 memset(&pinfo, 0, sizeof(pinfo));
4227
4228 if (!info->attrs[NL80211_ATTR_MAC])
4229 return -EINVAL;
4230
4231 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4232
Johannes Berg4c476992010-10-04 21:36:35 +02004233 if (!rdev->ops->get_mpath)
4234 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004235
Johannes Berg4c476992010-10-04 21:36:35 +02004236 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4237 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004238
Hila Gonene35e4d22012-06-27 17:19:42 +03004239 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004240 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004241 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004242
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004244 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004245 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004246
Eric W. Biederman15e47302012-09-07 20:12:54 +00004247 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004248 dev, dst, next_hop, &pinfo) < 0) {
4249 nlmsg_free(msg);
4250 return -ENOBUFS;
4251 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004252
Johannes Berg4c476992010-10-04 21:36:35 +02004253 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004254}
4255
4256static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4257{
Johannes Berg4c476992010-10-04 21:36:35 +02004258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4259 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260 u8 *dst = NULL;
4261 u8 *next_hop = NULL;
4262
4263 if (!info->attrs[NL80211_ATTR_MAC])
4264 return -EINVAL;
4265
4266 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4267 return -EINVAL;
4268
4269 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4270 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4271
Johannes Berg4c476992010-10-04 21:36:35 +02004272 if (!rdev->ops->change_mpath)
4273 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004274
Johannes Berg4c476992010-10-04 21:36:35 +02004275 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4276 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004277
Hila Gonene35e4d22012-06-27 17:19:42 +03004278 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004279}
Johannes Berg4c476992010-10-04 21:36:35 +02004280
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004281static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4282{
Johannes Berg4c476992010-10-04 21:36:35 +02004283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4284 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004285 u8 *dst = NULL;
4286 u8 *next_hop = NULL;
4287
4288 if (!info->attrs[NL80211_ATTR_MAC])
4289 return -EINVAL;
4290
4291 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4292 return -EINVAL;
4293
4294 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4295 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4296
Johannes Berg4c476992010-10-04 21:36:35 +02004297 if (!rdev->ops->add_mpath)
4298 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004299
Johannes Berg4c476992010-10-04 21:36:35 +02004300 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4301 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004302
Hila Gonene35e4d22012-06-27 17:19:42 +03004303 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004304}
4305
4306static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4307{
Johannes Berg4c476992010-10-04 21:36:35 +02004308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4309 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004310 u8 *dst = NULL;
4311
4312 if (info->attrs[NL80211_ATTR_MAC])
4313 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4314
Johannes Berg4c476992010-10-04 21:36:35 +02004315 if (!rdev->ops->del_mpath)
4316 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004317
Hila Gonene35e4d22012-06-27 17:19:42 +03004318 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004319}
4320
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004321static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4322{
Johannes Berg4c476992010-10-04 21:36:35 +02004323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4324 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004325 struct bss_parameters params;
4326
4327 memset(&params, 0, sizeof(params));
4328 /* default to not changing parameters */
4329 params.use_cts_prot = -1;
4330 params.use_short_preamble = -1;
4331 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004332 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004333 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004334 params.p2p_ctwindow = -1;
4335 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004336
4337 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4338 params.use_cts_prot =
4339 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4340 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4341 params.use_short_preamble =
4342 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4343 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4344 params.use_short_slot_time =
4345 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004346 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4347 params.basic_rates =
4348 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4349 params.basic_rates_len =
4350 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4351 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004352 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4353 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004354 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4355 params.ht_opmode =
4356 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004357
Johannes Berg53cabad2012-11-14 15:17:28 +01004358 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4359 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4360 return -EINVAL;
4361 params.p2p_ctwindow =
4362 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4363 if (params.p2p_ctwindow < 0)
4364 return -EINVAL;
4365 if (params.p2p_ctwindow != 0 &&
4366 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4367 return -EINVAL;
4368 }
4369
4370 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4371 u8 tmp;
4372
4373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4374 return -EINVAL;
4375 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4376 if (tmp > 1)
4377 return -EINVAL;
4378 params.p2p_opp_ps = tmp;
4379 if (params.p2p_opp_ps &&
4380 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4381 return -EINVAL;
4382 }
4383
Johannes Berg4c476992010-10-04 21:36:35 +02004384 if (!rdev->ops->change_bss)
4385 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004386
Johannes Berg074ac8d2010-09-16 14:58:22 +02004387 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004388 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4389 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004390
Hila Gonene35e4d22012-06-27 17:19:42 +03004391 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004392}
4393
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004394static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004395 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4396 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4397 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4398 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4399 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4400 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4401};
4402
4403static int parse_reg_rule(struct nlattr *tb[],
4404 struct ieee80211_reg_rule *reg_rule)
4405{
4406 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4407 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4408
4409 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4410 return -EINVAL;
4411 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4412 return -EINVAL;
4413 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4414 return -EINVAL;
4415 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4416 return -EINVAL;
4417 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4418 return -EINVAL;
4419
4420 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4421
4422 freq_range->start_freq_khz =
4423 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4424 freq_range->end_freq_khz =
4425 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4426 freq_range->max_bandwidth_khz =
4427 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4428
4429 power_rule->max_eirp =
4430 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4431
4432 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4433 power_rule->max_antenna_gain =
4434 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4435
4436 return 0;
4437}
4438
4439static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4440{
4441 int r;
4442 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004443 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004444
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004445 /*
4446 * You should only get this when cfg80211 hasn't yet initialized
4447 * completely when built-in to the kernel right between the time
4448 * window between nl80211_init() and regulatory_init(), if that is
4449 * even possible.
4450 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004451 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004452 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004453
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004454 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4455 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004456
4457 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4458
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004459 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4460 user_reg_hint_type =
4461 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4462 else
4463 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4464
4465 switch (user_reg_hint_type) {
4466 case NL80211_USER_REG_HINT_USER:
4467 case NL80211_USER_REG_HINT_CELL_BASE:
4468 break;
4469 default:
4470 return -EINVAL;
4471 }
4472
4473 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004474
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004475 return r;
4476}
4477
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004478static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004479 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004480{
Johannes Berg4c476992010-10-04 21:36:35 +02004481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004482 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004483 struct wireless_dev *wdev = dev->ieee80211_ptr;
4484 struct mesh_config cur_params;
4485 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004486 void *hdr;
4487 struct nlattr *pinfoattr;
4488 struct sk_buff *msg;
4489
Johannes Berg29cbe682010-12-03 09:20:44 +01004490 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4491 return -EOPNOTSUPP;
4492
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004493 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004494 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004495
Johannes Berg29cbe682010-12-03 09:20:44 +01004496 wdev_lock(wdev);
4497 /* If not connected, get default parameters */
4498 if (!wdev->mesh_id_len)
4499 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4500 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004501 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004502 wdev_unlock(wdev);
4503
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004504 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004505 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004506
4507 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004509 if (!msg)
4510 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004511 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004512 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004513 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004514 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004515 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004516 if (!pinfoattr)
4517 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004518 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4519 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4520 cur_params.dot11MeshRetryTimeout) ||
4521 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4522 cur_params.dot11MeshConfirmTimeout) ||
4523 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4524 cur_params.dot11MeshHoldingTimeout) ||
4525 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4526 cur_params.dot11MeshMaxPeerLinks) ||
4527 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4528 cur_params.dot11MeshMaxRetries) ||
4529 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4530 cur_params.dot11MeshTTL) ||
4531 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4532 cur_params.element_ttl) ||
4533 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4534 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004535 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4536 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004537 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4538 cur_params.dot11MeshHWMPmaxPREQretries) ||
4539 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4540 cur_params.path_refresh_time) ||
4541 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4542 cur_params.min_discovery_timeout) ||
4543 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4544 cur_params.dot11MeshHWMPactivePathTimeout) ||
4545 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4546 cur_params.dot11MeshHWMPpreqMinInterval) ||
4547 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4548 cur_params.dot11MeshHWMPperrMinInterval) ||
4549 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4550 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4551 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4552 cur_params.dot11MeshHWMPRootMode) ||
4553 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4554 cur_params.dot11MeshHWMPRannInterval) ||
4555 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4556 cur_params.dot11MeshGateAnnouncementProtocol) ||
4557 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4558 cur_params.dot11MeshForwarding) ||
4559 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004560 cur_params.rssi_threshold) ||
4561 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004562 cur_params.ht_opmode) ||
4563 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4564 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4565 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004566 cur_params.dot11MeshHWMProotInterval) ||
4567 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004568 cur_params.dot11MeshHWMPconfirmationInterval) ||
4569 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4570 cur_params.power_mode) ||
4571 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4572 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004573 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004574 nla_nest_end(msg, pinfoattr);
4575 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004576 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004577
Johannes Berg3b858752009-03-12 09:55:09 +01004578 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004579 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004580 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004581 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004582 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004583}
4584
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004585static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004586 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4587 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4588 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4589 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4590 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4591 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004592 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004593 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004594 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004595 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4596 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4597 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4598 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4599 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004600 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004601 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004602 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004603 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004604 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004605 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004606 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4607 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004608 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4609 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004610 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004611 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4612 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004613};
4614
Javier Cardonac80d5452010-12-16 17:37:49 -08004615static const struct nla_policy
4616 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004617 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004618 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4619 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004620 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004621 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004622 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004623 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004624 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004625};
4626
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004627static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004628 struct mesh_config *cfg,
4629 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004630{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004631 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004632 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004633
Marco Porschea54fba2013-01-07 16:04:48 +01004634#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4635do { \
4636 if (tb[attr]) { \
4637 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4638 return -EINVAL; \
4639 cfg->param = fn(tb[attr]); \
4640 mask |= (1 << (attr - 1)); \
4641 } \
4642} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004643
4644
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004645 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004646 return -EINVAL;
4647 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004648 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004649 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004650 return -EINVAL;
4651
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004652 /* This makes sure that there aren't more than 32 mesh config
4653 * parameters (otherwise our bitfield scheme would not work.) */
4654 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4655
4656 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004657 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004658 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4659 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004660 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004661 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4662 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004663 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004664 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4665 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004666 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004667 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4668 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004669 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004670 mask, NL80211_MESHCONF_MAX_RETRIES,
4671 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004673 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004674 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004675 mask, NL80211_MESHCONF_ELEMENT_TTL,
4676 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004677 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004678 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4679 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004680 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4681 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004682 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4683 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004685 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4686 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004688 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4689 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004691 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4692 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004693 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4694 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004695 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4696 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004697 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004698 1, 65535, mask,
4699 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004700 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004701 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004702 1, 65535, mask,
4703 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004704 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004706 dot11MeshHWMPnetDiameterTraversalTime,
4707 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004708 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4709 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4711 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4712 nla_get_u8);
4713 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4714 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004715 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004717 dot11MeshGateAnnouncementProtocol, 0, 1,
4718 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004719 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004720 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004721 mask, NL80211_MESHCONF_FORWARDING,
4722 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004723 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004724 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4725 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004726 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004727 mask, NL80211_MESHCONF_HT_OPMODE,
4728 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004729 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004730 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004731 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4732 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004733 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004734 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4735 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004736 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004737 dot11MeshHWMPconfirmationInterval,
4738 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004739 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4740 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004741 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4742 NL80211_MESH_POWER_ACTIVE,
4743 NL80211_MESH_POWER_MAX,
4744 mask, NL80211_MESHCONF_POWER_MODE,
4745 nla_get_u32);
4746 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4747 0, 65535, mask,
4748 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004749 if (mask_out)
4750 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004751
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004752 return 0;
4753
4754#undef FILL_IN_MESH_PARAM_IF_SET
4755}
4756
Javier Cardonac80d5452010-12-16 17:37:49 -08004757static int nl80211_parse_mesh_setup(struct genl_info *info,
4758 struct mesh_setup *setup)
4759{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004761 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4762
4763 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4764 return -EINVAL;
4765 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4766 info->attrs[NL80211_ATTR_MESH_SETUP],
4767 nl80211_mesh_setup_params_policy))
4768 return -EINVAL;
4769
Javier Cardonad299a1f2012-03-31 11:31:33 -07004770 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4771 setup->sync_method =
4772 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4773 IEEE80211_SYNC_METHOD_VENDOR :
4774 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4775
Javier Cardonac80d5452010-12-16 17:37:49 -08004776 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4777 setup->path_sel_proto =
4778 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4779 IEEE80211_PATH_PROTOCOL_VENDOR :
4780 IEEE80211_PATH_PROTOCOL_HWMP;
4781
4782 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4783 setup->path_metric =
4784 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4785 IEEE80211_PATH_METRIC_VENDOR :
4786 IEEE80211_PATH_METRIC_AIRTIME;
4787
Javier Cardona581a8b02011-04-07 15:08:27 -07004788
4789 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004790 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004791 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004792 if (!is_valid_ie_attr(ieattr))
4793 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004794 setup->ie = nla_data(ieattr);
4795 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004796 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004797 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4798 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4799 return -EINVAL;
4800 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004801 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4802 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004803 if (setup->is_secure)
4804 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004805
4806 return 0;
4807}
4808
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004809static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004810 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004811{
4812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4813 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004814 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004815 struct mesh_config cfg;
4816 u32 mask;
4817 int err;
4818
Johannes Berg29cbe682010-12-03 09:20:44 +01004819 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4820 return -EOPNOTSUPP;
4821
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004822 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004823 return -EOPNOTSUPP;
4824
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004825 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004826 if (err)
4827 return err;
4828
Johannes Berg29cbe682010-12-03 09:20:44 +01004829 wdev_lock(wdev);
4830 if (!wdev->mesh_id_len)
4831 err = -ENOLINK;
4832
4833 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004834 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004835
4836 wdev_unlock(wdev);
4837
4838 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004839}
4840
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004841static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4842{
Johannes Berg458f4f92012-12-06 15:47:38 +01004843 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004844 struct sk_buff *msg;
4845 void *hdr = NULL;
4846 struct nlattr *nl_reg_rules;
4847 unsigned int i;
4848 int err = -EINVAL;
4849
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004850 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004851
4852 if (!cfg80211_regdomain)
4853 goto out;
4854
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004855 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004856 if (!msg) {
4857 err = -ENOBUFS;
4858 goto out;
4859 }
4860
Eric W. Biederman15e47302012-09-07 20:12:54 +00004861 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004862 NL80211_CMD_GET_REG);
4863 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004864 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004865
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004866 if (reg_last_request_cell_base() &&
4867 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4868 NL80211_USER_REG_HINT_CELL_BASE))
4869 goto nla_put_failure;
4870
Johannes Berg458f4f92012-12-06 15:47:38 +01004871 rcu_read_lock();
4872 regdom = rcu_dereference(cfg80211_regdomain);
4873
4874 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4875 (regdom->dfs_region &&
4876 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4877 goto nla_put_failure_rcu;
4878
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004879 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4880 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004881 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004882
Johannes Berg458f4f92012-12-06 15:47:38 +01004883 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004884 struct nlattr *nl_reg_rule;
4885 const struct ieee80211_reg_rule *reg_rule;
4886 const struct ieee80211_freq_range *freq_range;
4887 const struct ieee80211_power_rule *power_rule;
4888
Johannes Berg458f4f92012-12-06 15:47:38 +01004889 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004890 freq_range = &reg_rule->freq_range;
4891 power_rule = &reg_rule->power_rule;
4892
4893 nl_reg_rule = nla_nest_start(msg, i);
4894 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004895 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004896
David S. Miller9360ffd2012-03-29 04:41:26 -04004897 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4898 reg_rule->flags) ||
4899 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4900 freq_range->start_freq_khz) ||
4901 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4902 freq_range->end_freq_khz) ||
4903 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4904 freq_range->max_bandwidth_khz) ||
4905 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4906 power_rule->max_antenna_gain) ||
4907 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4908 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004909 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004910
4911 nla_nest_end(msg, nl_reg_rule);
4912 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004913 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004914
4915 nla_nest_end(msg, nl_reg_rules);
4916
4917 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004918 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004919 goto out;
4920
Johannes Berg458f4f92012-12-06 15:47:38 +01004921nla_put_failure_rcu:
4922 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004923nla_put_failure:
4924 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004925put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004926 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004927 err = -EMSGSIZE;
4928out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004929 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004930 return err;
4931}
4932
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004933static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4934{
4935 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4936 struct nlattr *nl_reg_rule;
4937 char *alpha2 = NULL;
4938 int rem_reg_rules = 0, r = 0;
4939 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004940 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004941 struct ieee80211_regdomain *rd = NULL;
4942
4943 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4944 return -EINVAL;
4945
4946 if (!info->attrs[NL80211_ATTR_REG_RULES])
4947 return -EINVAL;
4948
4949 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4950
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004951 if (info->attrs[NL80211_ATTR_DFS_REGION])
4952 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4953
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004954 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004955 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004956 num_rules++;
4957 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004958 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004959 }
4960
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004961 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004962 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004963
4964 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004965 if (!rd)
4966 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004967
4968 rd->n_reg_rules = num_rules;
4969 rd->alpha2[0] = alpha2[0];
4970 rd->alpha2[1] = alpha2[1];
4971
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004972 /*
4973 * Disable DFS master mode if the DFS region was
4974 * not supported or known on this kernel.
4975 */
4976 if (reg_supported_dfs_region(dfs_region))
4977 rd->dfs_region = dfs_region;
4978
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004979 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004980 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004981 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004982 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4983 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004984 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4985 if (r)
4986 goto bad_reg;
4987
4988 rule_idx++;
4989
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004990 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4991 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004992 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004993 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004994 }
4995
Johannes Berg6913b492012-12-04 00:48:59 +01004996 mutex_lock(&cfg80211_mutex);
4997
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004998 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01004999 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005000 rd = NULL;
Johannes Berg6913b492012-12-04 00:48:59 +01005001 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005002
Johannes Bergd2372b32008-10-24 20:32:20 +02005003 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005004 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005005 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005006}
5007
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005008static int validate_scan_freqs(struct nlattr *freqs)
5009{
5010 struct nlattr *attr1, *attr2;
5011 int n_channels = 0, tmp1, tmp2;
5012
5013 nla_for_each_nested(attr1, freqs, tmp1) {
5014 n_channels++;
5015 /*
5016 * Some hardware has a limited channel list for
5017 * scanning, and it is pretty much nonsensical
5018 * to scan for a channel twice, so disallow that
5019 * and don't require drivers to check that the
5020 * channel list they get isn't longer than what
5021 * they can scan, as long as they can scan all
5022 * the channels they registered at once.
5023 */
5024 nla_for_each_nested(attr2, freqs, tmp2)
5025 if (attr1 != attr2 &&
5026 nla_get_u32(attr1) == nla_get_u32(attr2))
5027 return 0;
5028 }
5029
5030 return n_channels;
5031}
5032
Johannes Berg2a519312009-02-10 21:25:55 +01005033static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5034{
Johannes Berg4c476992010-10-04 21:36:35 +02005035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005036 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005037 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005038 struct nlattr *attr;
5039 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005040 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005041 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005042
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005043 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5044 return -EINVAL;
5045
Johannes Berg79c97e92009-07-07 03:56:12 +02005046 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005047
Johannes Berg4c476992010-10-04 21:36:35 +02005048 if (!rdev->ops->scan)
5049 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005050
Johannes Bergf9f47522013-03-19 15:04:07 +01005051 mutex_lock(&rdev->sched_scan_mtx);
5052 if (rdev->scan_req) {
5053 err = -EBUSY;
5054 goto unlock;
5055 }
Johannes Berg2a519312009-02-10 21:25:55 +01005056
5057 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005058 n_channels = validate_scan_freqs(
5059 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005060 if (!n_channels) {
5061 err = -EINVAL;
5062 goto unlock;
5063 }
Johannes Berg2a519312009-02-10 21:25:55 +01005064 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005065 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005066 n_channels = 0;
5067
Johannes Berg2a519312009-02-10 21:25:55 +01005068 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5069 if (wiphy->bands[band])
5070 n_channels += wiphy->bands[band]->n_channels;
5071 }
5072
5073 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5074 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5075 n_ssids++;
5076
Johannes Bergf9f47522013-03-19 15:04:07 +01005077 if (n_ssids > wiphy->max_scan_ssids) {
5078 err = -EINVAL;
5079 goto unlock;
5080 }
Johannes Berg2a519312009-02-10 21:25:55 +01005081
Jouni Malinen70692ad2009-02-16 19:39:13 +02005082 if (info->attrs[NL80211_ATTR_IE])
5083 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5084 else
5085 ie_len = 0;
5086
Johannes Bergf9f47522013-03-19 15:04:07 +01005087 if (ie_len > wiphy->max_scan_ie_len) {
5088 err = -EINVAL;
5089 goto unlock;
5090 }
Johannes Berg18a83652009-03-31 12:12:05 +02005091
Johannes Berg2a519312009-02-10 21:25:55 +01005092 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005093 + sizeof(*request->ssids) * n_ssids
5094 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005095 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005096 if (!request) {
5097 err = -ENOMEM;
5098 goto unlock;
5099 }
Johannes Berg2a519312009-02-10 21:25:55 +01005100
Johannes Berg2a519312009-02-10 21:25:55 +01005101 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005102 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005103 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005104 if (ie_len) {
5105 if (request->ssids)
5106 request->ie = (void *)(request->ssids + n_ssids);
5107 else
5108 request->ie = (void *)(request->channels + n_channels);
5109 }
Johannes Berg2a519312009-02-10 21:25:55 +01005110
Johannes Berg584991d2009-11-02 13:32:03 +01005111 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005112 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5113 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005114 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005115 struct ieee80211_channel *chan;
5116
5117 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5118
5119 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005120 err = -EINVAL;
5121 goto out_free;
5122 }
Johannes Berg584991d2009-11-02 13:32:03 +01005123
5124 /* ignore disabled channels */
5125 if (chan->flags & IEEE80211_CHAN_DISABLED)
5126 continue;
5127
5128 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005129 i++;
5130 }
5131 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005132 enum ieee80211_band band;
5133
Johannes Berg2a519312009-02-10 21:25:55 +01005134 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005135 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5136 int j;
5137 if (!wiphy->bands[band])
5138 continue;
5139 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005140 struct ieee80211_channel *chan;
5141
5142 chan = &wiphy->bands[band]->channels[j];
5143
5144 if (chan->flags & IEEE80211_CHAN_DISABLED)
5145 continue;
5146
5147 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005148 i++;
5149 }
5150 }
5151 }
5152
Johannes Berg584991d2009-11-02 13:32:03 +01005153 if (!i) {
5154 err = -EINVAL;
5155 goto out_free;
5156 }
5157
5158 request->n_channels = i;
5159
Johannes Berg2a519312009-02-10 21:25:55 +01005160 i = 0;
5161 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5162 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005163 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005164 err = -EINVAL;
5165 goto out_free;
5166 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005167 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005168 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005169 i++;
5170 }
5171 }
5172
Jouni Malinen70692ad2009-02-16 19:39:13 +02005173 if (info->attrs[NL80211_ATTR_IE]) {
5174 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005175 memcpy((void *)request->ie,
5176 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005177 request->ie_len);
5178 }
5179
Johannes Berg34850ab2011-07-18 18:08:35 +02005180 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005181 if (wiphy->bands[i])
5182 request->rates[i] =
5183 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005184
5185 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5186 nla_for_each_nested(attr,
5187 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5188 tmp) {
5189 enum ieee80211_band band = nla_type(attr);
5190
Dan Carpenter84404622011-07-29 11:52:18 +03005191 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005192 err = -EINVAL;
5193 goto out_free;
5194 }
5195 err = ieee80211_get_ratemask(wiphy->bands[band],
5196 nla_data(attr),
5197 nla_len(attr),
5198 &request->rates[band]);
5199 if (err)
5200 goto out_free;
5201 }
5202 }
5203
Sam Leffler46856bb2012-10-11 21:03:32 -07005204 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005205 request->flags = nla_get_u32(
5206 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005207 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5208 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5209 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5210 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005211 err = -EOPNOTSUPP;
5212 goto out_free;
5213 }
5214 }
Sam Lefflered4737712012-10-11 21:03:31 -07005215
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305216 request->no_cck =
5217 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5218
Johannes Bergfd014282012-06-18 19:17:03 +02005219 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005220 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005221 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005222
Johannes Berg79c97e92009-07-07 03:56:12 +02005223 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005224 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005225
Johannes Berg463d0182009-07-14 00:33:35 +02005226 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005227 nl80211_send_scan_start(rdev, wdev);
5228 if (wdev->netdev)
5229 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005230 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005231 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005232 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005233 kfree(request);
5234 }
Johannes Berg3b858752009-03-12 09:55:09 +01005235
Johannes Bergf9f47522013-03-19 15:04:07 +01005236 unlock:
5237 mutex_unlock(&rdev->sched_scan_mtx);
Johannes Berg2a519312009-02-10 21:25:55 +01005238 return err;
5239}
5240
Luciano Coelho807f8a82011-05-11 17:09:35 +03005241static int nl80211_start_sched_scan(struct sk_buff *skb,
5242 struct genl_info *info)
5243{
5244 struct cfg80211_sched_scan_request *request;
5245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5246 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005247 struct nlattr *attr;
5248 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005249 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005250 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005251 enum ieee80211_band band;
5252 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005253 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005254
5255 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5256 !rdev->ops->sched_scan_start)
5257 return -EOPNOTSUPP;
5258
5259 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5260 return -EINVAL;
5261
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005262 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5263 return -EINVAL;
5264
5265 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5266 if (interval == 0)
5267 return -EINVAL;
5268
Luciano Coelho807f8a82011-05-11 17:09:35 +03005269 wiphy = &rdev->wiphy;
5270
5271 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5272 n_channels = validate_scan_freqs(
5273 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5274 if (!n_channels)
5275 return -EINVAL;
5276 } else {
5277 n_channels = 0;
5278
5279 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5280 if (wiphy->bands[band])
5281 n_channels += wiphy->bands[band]->n_channels;
5282 }
5283
5284 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5285 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5286 tmp)
5287 n_ssids++;
5288
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005289 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005290 return -EINVAL;
5291
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005292 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5293 nla_for_each_nested(attr,
5294 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5295 tmp)
5296 n_match_sets++;
5297
5298 if (n_match_sets > wiphy->max_match_sets)
5299 return -EINVAL;
5300
Luciano Coelho807f8a82011-05-11 17:09:35 +03005301 if (info->attrs[NL80211_ATTR_IE])
5302 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5303 else
5304 ie_len = 0;
5305
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005306 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005307 return -EINVAL;
5308
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005309 mutex_lock(&rdev->sched_scan_mtx);
5310
5311 if (rdev->sched_scan_req) {
5312 err = -EINPROGRESS;
5313 goto out;
5314 }
5315
Luciano Coelho807f8a82011-05-11 17:09:35 +03005316 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005317 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005318 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005319 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005320 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005321 if (!request) {
5322 err = -ENOMEM;
5323 goto out;
5324 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005325
5326 if (n_ssids)
5327 request->ssids = (void *)&request->channels[n_channels];
5328 request->n_ssids = n_ssids;
5329 if (ie_len) {
5330 if (request->ssids)
5331 request->ie = (void *)(request->ssids + n_ssids);
5332 else
5333 request->ie = (void *)(request->channels + n_channels);
5334 }
5335
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005336 if (n_match_sets) {
5337 if (request->ie)
5338 request->match_sets = (void *)(request->ie + ie_len);
5339 else if (request->ssids)
5340 request->match_sets =
5341 (void *)(request->ssids + n_ssids);
5342 else
5343 request->match_sets =
5344 (void *)(request->channels + n_channels);
5345 }
5346 request->n_match_sets = n_match_sets;
5347
Luciano Coelho807f8a82011-05-11 17:09:35 +03005348 i = 0;
5349 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5350 /* user specified, bail out if channel not found */
5351 nla_for_each_nested(attr,
5352 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5353 tmp) {
5354 struct ieee80211_channel *chan;
5355
5356 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5357
5358 if (!chan) {
5359 err = -EINVAL;
5360 goto out_free;
5361 }
5362
5363 /* ignore disabled channels */
5364 if (chan->flags & IEEE80211_CHAN_DISABLED)
5365 continue;
5366
5367 request->channels[i] = chan;
5368 i++;
5369 }
5370 } else {
5371 /* all channels */
5372 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5373 int j;
5374 if (!wiphy->bands[band])
5375 continue;
5376 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5377 struct ieee80211_channel *chan;
5378
5379 chan = &wiphy->bands[band]->channels[j];
5380
5381 if (chan->flags & IEEE80211_CHAN_DISABLED)
5382 continue;
5383
5384 request->channels[i] = chan;
5385 i++;
5386 }
5387 }
5388 }
5389
5390 if (!i) {
5391 err = -EINVAL;
5392 goto out_free;
5393 }
5394
5395 request->n_channels = i;
5396
5397 i = 0;
5398 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5399 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5400 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005401 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005402 err = -EINVAL;
5403 goto out_free;
5404 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005405 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005406 memcpy(request->ssids[i].ssid, nla_data(attr),
5407 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005408 i++;
5409 }
5410 }
5411
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005412 i = 0;
5413 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5414 nla_for_each_nested(attr,
5415 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5416 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005417 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005418
5419 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5420 nla_data(attr), nla_len(attr),
5421 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005422 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005423 if (ssid) {
5424 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5425 err = -EINVAL;
5426 goto out_free;
5427 }
5428 memcpy(request->match_sets[i].ssid.ssid,
5429 nla_data(ssid), nla_len(ssid));
5430 request->match_sets[i].ssid.ssid_len =
5431 nla_len(ssid);
5432 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005433 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5434 if (rssi)
5435 request->rssi_thold = nla_get_u32(rssi);
5436 else
5437 request->rssi_thold =
5438 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005439 i++;
5440 }
5441 }
5442
Luciano Coelho807f8a82011-05-11 17:09:35 +03005443 if (info->attrs[NL80211_ATTR_IE]) {
5444 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5445 memcpy((void *)request->ie,
5446 nla_data(info->attrs[NL80211_ATTR_IE]),
5447 request->ie_len);
5448 }
5449
Sam Leffler46856bb2012-10-11 21:03:32 -07005450 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005451 request->flags = nla_get_u32(
5452 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005453 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5454 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5455 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5456 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005457 err = -EOPNOTSUPP;
5458 goto out_free;
5459 }
5460 }
Sam Lefflered4737712012-10-11 21:03:31 -07005461
Luciano Coelho807f8a82011-05-11 17:09:35 +03005462 request->dev = dev;
5463 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005464 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005465 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005466
Hila Gonene35e4d22012-06-27 17:19:42 +03005467 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005468 if (!err) {
5469 rdev->sched_scan_req = request;
5470 nl80211_send_sched_scan(rdev, dev,
5471 NL80211_CMD_START_SCHED_SCAN);
5472 goto out;
5473 }
5474
5475out_free:
5476 kfree(request);
5477out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005478 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005479 return err;
5480}
5481
5482static int nl80211_stop_sched_scan(struct sk_buff *skb,
5483 struct genl_info *info)
5484{
5485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005486 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005487
5488 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5489 !rdev->ops->sched_scan_stop)
5490 return -EOPNOTSUPP;
5491
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005492 mutex_lock(&rdev->sched_scan_mtx);
5493 err = __cfg80211_stop_sched_scan(rdev, false);
5494 mutex_unlock(&rdev->sched_scan_mtx);
5495
5496 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005497}
5498
Simon Wunderlich04f39042013-02-08 18:16:19 +01005499static int nl80211_start_radar_detection(struct sk_buff *skb,
5500 struct genl_info *info)
5501{
5502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5503 struct net_device *dev = info->user_ptr[1];
5504 struct wireless_dev *wdev = dev->ieee80211_ptr;
5505 struct cfg80211_chan_def chandef;
5506 int err;
5507
5508 err = nl80211_parse_chandef(rdev, info, &chandef);
5509 if (err)
5510 return err;
5511
5512 if (wdev->cac_started)
5513 return -EBUSY;
5514
5515 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5516 if (err < 0)
5517 return err;
5518
5519 if (err == 0)
5520 return -EINVAL;
5521
5522 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5523 return -EINVAL;
5524
5525 if (!rdev->ops->start_radar_detection)
5526 return -EOPNOTSUPP;
5527
5528 mutex_lock(&rdev->devlist_mtx);
5529 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5530 chandef.chan, CHAN_MODE_SHARED,
5531 BIT(chandef.width));
5532 if (err)
5533 goto err_locked;
5534
5535 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5536 if (!err) {
5537 wdev->channel = chandef.chan;
5538 wdev->cac_started = true;
5539 wdev->cac_start_time = jiffies;
5540 }
5541err_locked:
5542 mutex_unlock(&rdev->devlist_mtx);
5543
5544 return err;
5545}
5546
Johannes Berg9720bb32011-06-21 09:45:33 +02005547static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5548 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005549 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005550 struct wireless_dev *wdev,
5551 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005552{
Johannes Berg48ab9052009-07-10 18:42:31 +02005553 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005554 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005555 void *hdr;
5556 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005557 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005558
5559 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005560
Eric W. Biederman15e47302012-09-07 20:12:54 +00005561 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005562 NL80211_CMD_NEW_SCAN_RESULTS);
5563 if (!hdr)
5564 return -1;
5565
Johannes Berg9720bb32011-06-21 09:45:33 +02005566 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5567
David S. Miller9360ffd2012-03-29 04:41:26 -04005568 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5569 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5570 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005571
5572 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5573 if (!bss)
5574 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005575 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005576 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005577 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005578
5579 rcu_read_lock();
5580 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005581 if (ies) {
5582 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5583 goto fail_unlock_rcu;
5584 tsf = true;
5585 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5586 ies->len, ies->data))
5587 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005588 }
5589 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005590 if (ies) {
5591 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5592 goto fail_unlock_rcu;
5593 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5594 ies->len, ies->data))
5595 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005596 }
5597 rcu_read_unlock();
5598
David S. Miller9360ffd2012-03-29 04:41:26 -04005599 if (res->beacon_interval &&
5600 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5601 goto nla_put_failure;
5602 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5603 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5604 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5605 jiffies_to_msecs(jiffies - intbss->ts)))
5606 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005607
Johannes Berg77965c92009-02-18 18:45:06 +01005608 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005609 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005610 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5611 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005612 break;
5613 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005614 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5615 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005616 break;
5617 default:
5618 break;
5619 }
5620
Johannes Berg48ab9052009-07-10 18:42:31 +02005621 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005622 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005623 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005624 if (intbss == wdev->current_bss &&
5625 nla_put_u32(msg, NL80211_BSS_STATUS,
5626 NL80211_BSS_STATUS_ASSOCIATED))
5627 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005628 break;
5629 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005630 if (intbss == wdev->current_bss &&
5631 nla_put_u32(msg, NL80211_BSS_STATUS,
5632 NL80211_BSS_STATUS_IBSS_JOINED))
5633 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005634 break;
5635 default:
5636 break;
5637 }
5638
Johannes Berg2a519312009-02-10 21:25:55 +01005639 nla_nest_end(msg, bss);
5640
5641 return genlmsg_end(msg, hdr);
5642
Johannes Berg8cef2c92013-02-05 16:54:31 +01005643 fail_unlock_rcu:
5644 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005645 nla_put_failure:
5646 genlmsg_cancel(msg, hdr);
5647 return -EMSGSIZE;
5648}
5649
5650static int nl80211_dump_scan(struct sk_buff *skb,
5651 struct netlink_callback *cb)
5652{
Johannes Berg48ab9052009-07-10 18:42:31 +02005653 struct cfg80211_registered_device *rdev;
5654 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01005655 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005656 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005657 int start = cb->args[1], idx = 0;
5658 int err;
5659
Johannes Berg67748892010-10-04 21:14:06 +02005660 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5661 if (err)
5662 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005663
Johannes Berg48ab9052009-07-10 18:42:31 +02005664 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01005665
Johannes Berg48ab9052009-07-10 18:42:31 +02005666 wdev_lock(wdev);
5667 spin_lock_bh(&rdev->bss_lock);
5668 cfg80211_bss_expire(rdev);
5669
Johannes Berg9720bb32011-06-21 09:45:33 +02005670 cb->seq = rdev->bss_generation;
5671
Johannes Berg48ab9052009-07-10 18:42:31 +02005672 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005673 if (++idx <= start)
5674 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005675 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005676 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005677 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005678 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005679 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005680 }
5681 }
5682
Johannes Berg48ab9052009-07-10 18:42:31 +02005683 spin_unlock_bh(&rdev->bss_lock);
5684 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005685
5686 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02005687 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005688
Johannes Berg67748892010-10-04 21:14:06 +02005689 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005690}
5691
Eric W. Biederman15e47302012-09-07 20:12:54 +00005692static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005693 int flags, struct net_device *dev,
5694 struct survey_info *survey)
5695{
5696 void *hdr;
5697 struct nlattr *infoattr;
5698
Eric W. Biederman15e47302012-09-07 20:12:54 +00005699 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005700 NL80211_CMD_NEW_SURVEY_RESULTS);
5701 if (!hdr)
5702 return -ENOMEM;
5703
David S. Miller9360ffd2012-03-29 04:41:26 -04005704 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5705 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005706
5707 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5708 if (!infoattr)
5709 goto nla_put_failure;
5710
David S. Miller9360ffd2012-03-29 04:41:26 -04005711 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5712 survey->channel->center_freq))
5713 goto nla_put_failure;
5714
5715 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5716 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5717 goto nla_put_failure;
5718 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5719 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5720 goto nla_put_failure;
5721 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5722 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5723 survey->channel_time))
5724 goto nla_put_failure;
5725 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5726 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5727 survey->channel_time_busy))
5728 goto nla_put_failure;
5729 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5730 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5731 survey->channel_time_ext_busy))
5732 goto nla_put_failure;
5733 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5734 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5735 survey->channel_time_rx))
5736 goto nla_put_failure;
5737 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5738 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5739 survey->channel_time_tx))
5740 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005741
5742 nla_nest_end(msg, infoattr);
5743
5744 return genlmsg_end(msg, hdr);
5745
5746 nla_put_failure:
5747 genlmsg_cancel(msg, hdr);
5748 return -EMSGSIZE;
5749}
5750
5751static int nl80211_dump_survey(struct sk_buff *skb,
5752 struct netlink_callback *cb)
5753{
5754 struct survey_info survey;
5755 struct cfg80211_registered_device *dev;
5756 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01005757 int survey_idx = cb->args[1];
5758 int res;
5759
Johannes Berg67748892010-10-04 21:14:06 +02005760 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5761 if (res)
5762 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005763
5764 if (!dev->ops->dump_survey) {
5765 res = -EOPNOTSUPP;
5766 goto out_err;
5767 }
5768
5769 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005770 struct ieee80211_channel *chan;
5771
Hila Gonene35e4d22012-06-27 17:19:42 +03005772 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005773 if (res == -ENOENT)
5774 break;
5775 if (res)
5776 goto out_err;
5777
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005778 /* Survey without a channel doesn't make sense */
5779 if (!survey.channel) {
5780 res = -EINVAL;
5781 goto out;
5782 }
5783
5784 chan = ieee80211_get_channel(&dev->wiphy,
5785 survey.channel->center_freq);
5786 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5787 survey_idx++;
5788 continue;
5789 }
5790
Holger Schurig61fa7132009-11-11 12:25:40 +01005791 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005792 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005793 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5794 netdev,
5795 &survey) < 0)
5796 goto out;
5797 survey_idx++;
5798 }
5799
5800 out:
5801 cb->args[1] = survey_idx;
5802 res = skb->len;
5803 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02005804 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005805 return res;
5806}
5807
Samuel Ortizb23aa672009-07-01 21:26:54 +02005808static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5809{
5810 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5811 NL80211_WPA_VERSION_2));
5812}
5813
Jouni Malinen636a5d32009-03-19 13:39:22 +02005814static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5815{
Johannes Berg4c476992010-10-04 21:36:35 +02005816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5817 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005818 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005819 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5820 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005821 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005822 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005823 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005824
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005825 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5826 return -EINVAL;
5827
5828 if (!info->attrs[NL80211_ATTR_MAC])
5829 return -EINVAL;
5830
Jouni Malinen17780922009-03-27 20:52:47 +02005831 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5832 return -EINVAL;
5833
Johannes Berg19957bb2009-07-02 17:20:43 +02005834 if (!info->attrs[NL80211_ATTR_SSID])
5835 return -EINVAL;
5836
5837 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5838 return -EINVAL;
5839
Johannes Bergfffd0932009-07-08 14:22:54 +02005840 err = nl80211_parse_key(info, &key);
5841 if (err)
5842 return err;
5843
5844 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005845 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5846 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005847 if (!key.p.key || !key.p.key_len)
5848 return -EINVAL;
5849 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5850 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5851 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5852 key.p.key_len != WLAN_KEY_LEN_WEP104))
5853 return -EINVAL;
5854 if (key.idx > 4)
5855 return -EINVAL;
5856 } else {
5857 key.p.key_len = 0;
5858 key.p.key = NULL;
5859 }
5860
Johannes Bergafea0b72010-08-10 09:46:42 +02005861 if (key.idx >= 0) {
5862 int i;
5863 bool ok = false;
5864 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5865 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5866 ok = true;
5867 break;
5868 }
5869 }
Johannes Berg4c476992010-10-04 21:36:35 +02005870 if (!ok)
5871 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005872 }
5873
Johannes Berg4c476992010-10-04 21:36:35 +02005874 if (!rdev->ops->auth)
5875 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005876
Johannes Berg074ac8d2010-09-16 14:58:22 +02005877 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005878 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5879 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005880
Johannes Berg19957bb2009-07-02 17:20:43 +02005881 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005882 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005883 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005884 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5885 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005886
Johannes Berg19957bb2009-07-02 17:20:43 +02005887 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5888 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5889
5890 if (info->attrs[NL80211_ATTR_IE]) {
5891 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5892 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5893 }
5894
5895 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005896 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005897 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005898
Jouni Malinene39e5b52012-09-30 19:29:39 +03005899 if (auth_type == NL80211_AUTHTYPE_SAE &&
5900 !info->attrs[NL80211_ATTR_SAE_DATA])
5901 return -EINVAL;
5902
5903 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5904 if (auth_type != NL80211_AUTHTYPE_SAE)
5905 return -EINVAL;
5906 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5907 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5908 /* need to include at least Auth Transaction and Status Code */
5909 if (sae_data_len < 4)
5910 return -EINVAL;
5911 }
5912
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005913 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5914
Johannes Berg95de8172012-01-20 13:55:25 +01005915 /*
5916 * Since we no longer track auth state, ignore
5917 * requests to only change local state.
5918 */
5919 if (local_state_change)
5920 return 0;
5921
Johannes Berg4c476992010-10-04 21:36:35 +02005922 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5923 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005924 key.p.key, key.p.key_len, key.idx,
5925 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005926}
5927
Johannes Bergc0692b82010-08-27 14:26:53 +03005928static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5929 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005930 struct cfg80211_crypto_settings *settings,
5931 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005932{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005933 memset(settings, 0, sizeof(*settings));
5934
Samuel Ortizb23aa672009-07-01 21:26:54 +02005935 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5936
Johannes Bergc0692b82010-08-27 14:26:53 +03005937 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5938 u16 proto;
5939 proto = nla_get_u16(
5940 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5941 settings->control_port_ethertype = cpu_to_be16(proto);
5942 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5943 proto != ETH_P_PAE)
5944 return -EINVAL;
5945 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5946 settings->control_port_no_encrypt = true;
5947 } else
5948 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5949
Samuel Ortizb23aa672009-07-01 21:26:54 +02005950 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5951 void *data;
5952 int len, i;
5953
5954 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5955 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5956 settings->n_ciphers_pairwise = len / sizeof(u32);
5957
5958 if (len % sizeof(u32))
5959 return -EINVAL;
5960
Johannes Berg3dc27d22009-07-02 21:36:37 +02005961 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005962 return -EINVAL;
5963
5964 memcpy(settings->ciphers_pairwise, data, len);
5965
5966 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005967 if (!cfg80211_supported_cipher_suite(
5968 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005969 settings->ciphers_pairwise[i]))
5970 return -EINVAL;
5971 }
5972
5973 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5974 settings->cipher_group =
5975 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005976 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5977 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005978 return -EINVAL;
5979 }
5980
5981 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5982 settings->wpa_versions =
5983 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5984 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5985 return -EINVAL;
5986 }
5987
5988 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5989 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005990 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005991
5992 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5993 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5994 settings->n_akm_suites = len / sizeof(u32);
5995
5996 if (len % sizeof(u32))
5997 return -EINVAL;
5998
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005999 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6000 return -EINVAL;
6001
Samuel Ortizb23aa672009-07-01 21:26:54 +02006002 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006003 }
6004
6005 return 0;
6006}
6007
Jouni Malinen636a5d32009-03-19 13:39:22 +02006008static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6009{
Johannes Berg4c476992010-10-04 21:36:35 +02006010 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6011 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006012 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006013 struct cfg80211_assoc_request req = {};
6014 const u8 *bssid, *ssid;
6015 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006016
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006017 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6018 return -EINVAL;
6019
6020 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006021 !info->attrs[NL80211_ATTR_SSID] ||
6022 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006023 return -EINVAL;
6024
Johannes Berg4c476992010-10-04 21:36:35 +02006025 if (!rdev->ops->assoc)
6026 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006027
Johannes Berg074ac8d2010-09-16 14:58:22 +02006028 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006029 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6030 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006031
Johannes Berg19957bb2009-07-02 17:20:43 +02006032 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006033
Johannes Berg19957bb2009-07-02 17:20:43 +02006034 chan = ieee80211_get_channel(&rdev->wiphy,
6035 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006036 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6037 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006038
Johannes Berg19957bb2009-07-02 17:20:43 +02006039 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6040 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006041
6042 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006043 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6044 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006045 }
6046
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006047 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006048 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006049 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006050 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006051 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006052 else if (mfp != NL80211_MFP_NO)
6053 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006054 }
6055
Johannes Berg3e5d7642009-07-07 14:37:26 +02006056 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006057 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006058
Ben Greear7e7c8922011-11-18 11:31:59 -08006059 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006060 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006061
6062 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006063 memcpy(&req.ht_capa_mask,
6064 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6065 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006066
6067 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006068 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006069 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006070 memcpy(&req.ht_capa,
6071 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6072 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006073 }
6074
Johannes Bergee2aca32013-02-21 17:36:01 +01006075 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006076 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006077
6078 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006079 memcpy(&req.vht_capa_mask,
6080 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6081 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006082
6083 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006084 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006085 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006086 memcpy(&req.vht_capa,
6087 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6088 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006089 }
6090
Johannes Bergf62fab72013-02-21 20:09:09 +01006091 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006092 if (!err)
Johannes Bergf62fab72013-02-21 20:09:09 +01006093 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6094 ssid, ssid_len, &req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006095
Jouni Malinen636a5d32009-03-19 13:39:22 +02006096 return err;
6097}
6098
6099static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6100{
Johannes Berg4c476992010-10-04 21:36:35 +02006101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6102 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006103 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006104 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006105 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006106 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006107
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006108 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6109 return -EINVAL;
6110
6111 if (!info->attrs[NL80211_ATTR_MAC])
6112 return -EINVAL;
6113
6114 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6115 return -EINVAL;
6116
Johannes Berg4c476992010-10-04 21:36:35 +02006117 if (!rdev->ops->deauth)
6118 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006119
Johannes Berg074ac8d2010-09-16 14:58:22 +02006120 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006121 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6122 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006123
Johannes Berg19957bb2009-07-02 17:20:43 +02006124 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006125
Johannes Berg19957bb2009-07-02 17:20:43 +02006126 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6127 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006128 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006129 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006130 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006131
6132 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006133 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6134 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006135 }
6136
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006137 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6138
Johannes Berg4c476992010-10-04 21:36:35 +02006139 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6140 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006141}
6142
6143static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6144{
Johannes Berg4c476992010-10-04 21:36:35 +02006145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6146 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006147 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006148 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006149 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006150 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006151
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006152 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6153 return -EINVAL;
6154
6155 if (!info->attrs[NL80211_ATTR_MAC])
6156 return -EINVAL;
6157
6158 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6159 return -EINVAL;
6160
Johannes Berg4c476992010-10-04 21:36:35 +02006161 if (!rdev->ops->disassoc)
6162 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006163
Johannes Berg074ac8d2010-09-16 14:58:22 +02006164 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006165 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6166 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006167
Johannes Berg19957bb2009-07-02 17:20:43 +02006168 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006169
Johannes Berg19957bb2009-07-02 17:20:43 +02006170 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6171 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006172 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006173 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006174 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006175
6176 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006177 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6178 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006179 }
6180
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006181 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6182
Johannes Berg4c476992010-10-04 21:36:35 +02006183 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6184 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006185}
6186
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006187static bool
6188nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6189 int mcast_rate[IEEE80211_NUM_BANDS],
6190 int rateval)
6191{
6192 struct wiphy *wiphy = &rdev->wiphy;
6193 bool found = false;
6194 int band, i;
6195
6196 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6197 struct ieee80211_supported_band *sband;
6198
6199 sband = wiphy->bands[band];
6200 if (!sband)
6201 continue;
6202
6203 for (i = 0; i < sband->n_bitrates; i++) {
6204 if (sband->bitrates[i].bitrate == rateval) {
6205 mcast_rate[band] = i + 1;
6206 found = true;
6207 break;
6208 }
6209 }
6210 }
6211
6212 return found;
6213}
6214
Johannes Berg04a773a2009-04-19 21:24:32 +02006215static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6216{
Johannes Berg4c476992010-10-04 21:36:35 +02006217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6218 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006219 struct cfg80211_ibss_params ibss;
6220 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006221 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006222 int err;
6223
Johannes Berg8e30bc52009-04-22 17:45:38 +02006224 memset(&ibss, 0, sizeof(ibss));
6225
Johannes Berg04a773a2009-04-19 21:24:32 +02006226 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6227 return -EINVAL;
6228
Johannes Berg683b6d32012-11-08 21:25:48 +01006229 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006230 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6231 return -EINVAL;
6232
Johannes Berg8e30bc52009-04-22 17:45:38 +02006233 ibss.beacon_interval = 100;
6234
6235 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6236 ibss.beacon_interval =
6237 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6238 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6239 return -EINVAL;
6240 }
6241
Johannes Berg4c476992010-10-04 21:36:35 +02006242 if (!rdev->ops->join_ibss)
6243 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006244
Johannes Berg4c476992010-10-04 21:36:35 +02006245 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6246 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006247
Johannes Berg79c97e92009-07-07 03:56:12 +02006248 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006249
Johannes Berg39193492011-09-16 13:45:25 +02006250 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006251 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006252
6253 if (!is_valid_ether_addr(ibss.bssid))
6254 return -EINVAL;
6255 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006256 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6257 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6258
6259 if (info->attrs[NL80211_ATTR_IE]) {
6260 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6261 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6262 }
6263
Johannes Berg683b6d32012-11-08 21:25:48 +01006264 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6265 if (err)
6266 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006267
Johannes Berg683b6d32012-11-08 21:25:48 +01006268 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006269 return -EINVAL;
6270
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006271 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6272 return -EINVAL;
6273 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6274 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006275 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006276
Johannes Berg04a773a2009-04-19 21:24:32 +02006277 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006278 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006279
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006280 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6281 u8 *rates =
6282 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6283 int n_rates =
6284 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6285 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006286 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006287
Johannes Berg34850ab2011-07-18 18:08:35 +02006288 err = ieee80211_get_ratemask(sband, rates, n_rates,
6289 &ibss.basic_rates);
6290 if (err)
6291 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006292 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006293
6294 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6295 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6296 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6297 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006298
Johannes Berg4c476992010-10-04 21:36:35 +02006299 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306300 bool no_ht = false;
6301
Johannes Berg4c476992010-10-04 21:36:35 +02006302 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306303 info->attrs[NL80211_ATTR_KEYS],
6304 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006305 if (IS_ERR(connkeys))
6306 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306307
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006308 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6309 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306310 kfree(connkeys);
6311 return -EINVAL;
6312 }
Johannes Berg4c476992010-10-04 21:36:35 +02006313 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006314
Antonio Quartulli267335d2012-01-31 20:25:47 +01006315 ibss.control_port =
6316 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6317
Johannes Berg4c476992010-10-04 21:36:35 +02006318 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006319 if (err)
6320 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006321 return err;
6322}
6323
6324static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6325{
Johannes Berg4c476992010-10-04 21:36:35 +02006326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6327 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006328
Johannes Berg4c476992010-10-04 21:36:35 +02006329 if (!rdev->ops->leave_ibss)
6330 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006331
Johannes Berg4c476992010-10-04 21:36:35 +02006332 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6333 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006334
Johannes Berg4c476992010-10-04 21:36:35 +02006335 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006336}
6337
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006338static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6339{
6340 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6341 struct net_device *dev = info->user_ptr[1];
6342 int mcast_rate[IEEE80211_NUM_BANDS];
6343 u32 nla_rate;
6344 int err;
6345
6346 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6347 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6348 return -EOPNOTSUPP;
6349
6350 if (!rdev->ops->set_mcast_rate)
6351 return -EOPNOTSUPP;
6352
6353 memset(mcast_rate, 0, sizeof(mcast_rate));
6354
6355 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6356 return -EINVAL;
6357
6358 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6359 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6360 return -EINVAL;
6361
6362 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6363
6364 return err;
6365}
6366
6367
Johannes Bergaff89a92009-07-01 21:26:51 +02006368#ifdef CONFIG_NL80211_TESTMODE
6369static struct genl_multicast_group nl80211_testmode_mcgrp = {
6370 .name = "testmode",
6371};
6372
6373static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6374{
Johannes Berg4c476992010-10-04 21:36:35 +02006375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006376 int err;
6377
6378 if (!info->attrs[NL80211_ATTR_TESTDATA])
6379 return -EINVAL;
6380
Johannes Bergaff89a92009-07-01 21:26:51 +02006381 err = -EOPNOTSUPP;
6382 if (rdev->ops->testmode_cmd) {
6383 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006384 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006385 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6386 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6387 rdev->testmode_info = NULL;
6388 }
6389
Johannes Bergaff89a92009-07-01 21:26:51 +02006390 return err;
6391}
6392
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006393static int nl80211_testmode_dump(struct sk_buff *skb,
6394 struct netlink_callback *cb)
6395{
Johannes Berg00918d32011-12-13 17:22:05 +01006396 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006397 int err;
6398 long phy_idx;
6399 void *data = NULL;
6400 int data_len = 0;
6401
6402 if (cb->args[0]) {
6403 /*
6404 * 0 is a valid index, but not valid for args[0],
6405 * so we need to offset by 1.
6406 */
6407 phy_idx = cb->args[0] - 1;
6408 } else {
6409 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6410 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6411 nl80211_policy);
6412 if (err)
6413 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01006414
Johannes Berg2bd7e352012-06-15 14:23:16 +02006415 mutex_lock(&cfg80211_mutex);
6416 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6417 nl80211_fam.attrbuf);
6418 if (IS_ERR(rdev)) {
6419 mutex_unlock(&cfg80211_mutex);
6420 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01006421 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006422 phy_idx = rdev->wiphy_idx;
6423 rdev = NULL;
6424 mutex_unlock(&cfg80211_mutex);
6425
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006426 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6427 cb->args[1] =
6428 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6429 }
6430
6431 if (cb->args[1]) {
6432 data = nla_data((void *)cb->args[1]);
6433 data_len = nla_len((void *)cb->args[1]);
6434 }
6435
6436 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01006437 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6438 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006439 mutex_unlock(&cfg80211_mutex);
6440 return -ENOENT;
6441 }
Johannes Berg00918d32011-12-13 17:22:05 +01006442 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006443 mutex_unlock(&cfg80211_mutex);
6444
Johannes Berg00918d32011-12-13 17:22:05 +01006445 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006446 err = -EOPNOTSUPP;
6447 goto out_err;
6448 }
6449
6450 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006451 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006452 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6453 NL80211_CMD_TESTMODE);
6454 struct nlattr *tmdata;
6455
David S. Miller9360ffd2012-03-29 04:41:26 -04006456 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006457 genlmsg_cancel(skb, hdr);
6458 break;
6459 }
6460
6461 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6462 if (!tmdata) {
6463 genlmsg_cancel(skb, hdr);
6464 break;
6465 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006466 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006467 nla_nest_end(skb, tmdata);
6468
6469 if (err == -ENOBUFS || err == -ENOENT) {
6470 genlmsg_cancel(skb, hdr);
6471 break;
6472 } else if (err) {
6473 genlmsg_cancel(skb, hdr);
6474 goto out_err;
6475 }
6476
6477 genlmsg_end(skb, hdr);
6478 }
6479
6480 err = skb->len;
6481 /* see above */
6482 cb->args[0] = phy_idx + 1;
6483 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01006484 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006485 return err;
6486}
6487
Johannes Bergaff89a92009-07-01 21:26:51 +02006488static struct sk_buff *
6489__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006490 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006491{
6492 struct sk_buff *skb;
6493 void *hdr;
6494 struct nlattr *data;
6495
6496 skb = nlmsg_new(approxlen + 100, gfp);
6497 if (!skb)
6498 return NULL;
6499
Eric W. Biederman15e47302012-09-07 20:12:54 +00006500 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006501 if (!hdr) {
6502 kfree_skb(skb);
6503 return NULL;
6504 }
6505
David S. Miller9360ffd2012-03-29 04:41:26 -04006506 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6507 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006508 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6509
6510 ((void **)skb->cb)[0] = rdev;
6511 ((void **)skb->cb)[1] = hdr;
6512 ((void **)skb->cb)[2] = data;
6513
6514 return skb;
6515
6516 nla_put_failure:
6517 kfree_skb(skb);
6518 return NULL;
6519}
6520
6521struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6522 int approxlen)
6523{
6524 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6525
6526 if (WARN_ON(!rdev->testmode_info))
6527 return NULL;
6528
6529 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006530 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006531 rdev->testmode_info->snd_seq,
6532 GFP_KERNEL);
6533}
6534EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6535
6536int cfg80211_testmode_reply(struct sk_buff *skb)
6537{
6538 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6539 void *hdr = ((void **)skb->cb)[1];
6540 struct nlattr *data = ((void **)skb->cb)[2];
6541
6542 if (WARN_ON(!rdev->testmode_info)) {
6543 kfree_skb(skb);
6544 return -EINVAL;
6545 }
6546
6547 nla_nest_end(skb, data);
6548 genlmsg_end(skb, hdr);
6549 return genlmsg_reply(skb, rdev->testmode_info);
6550}
6551EXPORT_SYMBOL(cfg80211_testmode_reply);
6552
6553struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6554 int approxlen, gfp_t gfp)
6555{
6556 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6557
6558 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6559}
6560EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6561
6562void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6563{
6564 void *hdr = ((void **)skb->cb)[1];
6565 struct nlattr *data = ((void **)skb->cb)[2];
6566
6567 nla_nest_end(skb, data);
6568 genlmsg_end(skb, hdr);
6569 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6570}
6571EXPORT_SYMBOL(cfg80211_testmode_event);
6572#endif
6573
Samuel Ortizb23aa672009-07-01 21:26:54 +02006574static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6575{
Johannes Berg4c476992010-10-04 21:36:35 +02006576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6577 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006578 struct cfg80211_connect_params connect;
6579 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006580 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006581 int err;
6582
6583 memset(&connect, 0, sizeof(connect));
6584
6585 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6586 return -EINVAL;
6587
6588 if (!info->attrs[NL80211_ATTR_SSID] ||
6589 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6590 return -EINVAL;
6591
6592 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6593 connect.auth_type =
6594 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006595 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6596 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006597 return -EINVAL;
6598 } else
6599 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6600
6601 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6602
Johannes Bergc0692b82010-08-27 14:26:53 +03006603 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006604 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006605 if (err)
6606 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006607
Johannes Berg074ac8d2010-09-16 14:58:22 +02006608 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006609 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6610 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006611
Johannes Berg79c97e92009-07-07 03:56:12 +02006612 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006613
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306614 connect.bg_scan_period = -1;
6615 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6616 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6617 connect.bg_scan_period =
6618 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6619 }
6620
Samuel Ortizb23aa672009-07-01 21:26:54 +02006621 if (info->attrs[NL80211_ATTR_MAC])
6622 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6623 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6624 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6625
6626 if (info->attrs[NL80211_ATTR_IE]) {
6627 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6628 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6629 }
6630
Jouni Malinencee00a92013-01-15 17:15:57 +02006631 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6632 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6633 if (connect.mfp != NL80211_MFP_REQUIRED &&
6634 connect.mfp != NL80211_MFP_NO)
6635 return -EINVAL;
6636 } else {
6637 connect.mfp = NL80211_MFP_NO;
6638 }
6639
Samuel Ortizb23aa672009-07-01 21:26:54 +02006640 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6641 connect.channel =
6642 ieee80211_get_channel(wiphy,
6643 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6644 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006645 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6646 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006647 }
6648
Johannes Bergfffd0932009-07-08 14:22:54 +02006649 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6650 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306651 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006652 if (IS_ERR(connkeys))
6653 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006654 }
6655
Ben Greear7e7c8922011-11-18 11:31:59 -08006656 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6657 connect.flags |= ASSOC_REQ_DISABLE_HT;
6658
6659 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6660 memcpy(&connect.ht_capa_mask,
6661 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6662 sizeof(connect.ht_capa_mask));
6663
6664 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006665 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6666 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006667 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006668 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006669 memcpy(&connect.ht_capa,
6670 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6671 sizeof(connect.ht_capa));
6672 }
6673
Johannes Bergee2aca32013-02-21 17:36:01 +01006674 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6675 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6676
6677 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6678 memcpy(&connect.vht_capa_mask,
6679 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6680 sizeof(connect.vht_capa_mask));
6681
6682 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6683 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6684 kfree(connkeys);
6685 return -EINVAL;
6686 }
6687 memcpy(&connect.vht_capa,
6688 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6689 sizeof(connect.vht_capa));
6690 }
6691
Johannes Bergfffd0932009-07-08 14:22:54 +02006692 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006693 if (err)
6694 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006695 return err;
6696}
6697
6698static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6699{
Johannes Berg4c476992010-10-04 21:36:35 +02006700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6701 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006702 u16 reason;
6703
6704 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6705 reason = WLAN_REASON_DEAUTH_LEAVING;
6706 else
6707 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6708
6709 if (reason == 0)
6710 return -EINVAL;
6711
Johannes Berg074ac8d2010-09-16 14:58:22 +02006712 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006713 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6714 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006715
Johannes Berg4c476992010-10-04 21:36:35 +02006716 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006717}
6718
Johannes Berg463d0182009-07-14 00:33:35 +02006719static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6720{
Johannes Berg4c476992010-10-04 21:36:35 +02006721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006722 struct net *net;
6723 int err;
6724 u32 pid;
6725
6726 if (!info->attrs[NL80211_ATTR_PID])
6727 return -EINVAL;
6728
6729 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6730
Johannes Berg463d0182009-07-14 00:33:35 +02006731 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006732 if (IS_ERR(net))
6733 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006734
6735 err = 0;
6736
6737 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006738 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6739 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006740
Johannes Berg463d0182009-07-14 00:33:35 +02006741 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006742 return err;
6743}
6744
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006745static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6746{
Johannes Berg4c476992010-10-04 21:36:35 +02006747 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006748 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6749 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006750 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006751 struct cfg80211_pmksa pmksa;
6752
6753 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6754
6755 if (!info->attrs[NL80211_ATTR_MAC])
6756 return -EINVAL;
6757
6758 if (!info->attrs[NL80211_ATTR_PMKID])
6759 return -EINVAL;
6760
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006761 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6762 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6763
Johannes Berg074ac8d2010-09-16 14:58:22 +02006764 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006765 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6766 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006767
6768 switch (info->genlhdr->cmd) {
6769 case NL80211_CMD_SET_PMKSA:
6770 rdev_ops = rdev->ops->set_pmksa;
6771 break;
6772 case NL80211_CMD_DEL_PMKSA:
6773 rdev_ops = rdev->ops->del_pmksa;
6774 break;
6775 default:
6776 WARN_ON(1);
6777 break;
6778 }
6779
Johannes Berg4c476992010-10-04 21:36:35 +02006780 if (!rdev_ops)
6781 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006782
Johannes Berg4c476992010-10-04 21:36:35 +02006783 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006784}
6785
6786static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6787{
Johannes Berg4c476992010-10-04 21:36:35 +02006788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6789 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006790
Johannes Berg074ac8d2010-09-16 14:58:22 +02006791 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006792 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6793 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006794
Johannes Berg4c476992010-10-04 21:36:35 +02006795 if (!rdev->ops->flush_pmksa)
6796 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006797
Hila Gonene35e4d22012-06-27 17:19:42 +03006798 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006799}
6800
Arik Nemtsov109086c2011-09-28 14:12:50 +03006801static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6802{
6803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6804 struct net_device *dev = info->user_ptr[1];
6805 u8 action_code, dialog_token;
6806 u16 status_code;
6807 u8 *peer;
6808
6809 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6810 !rdev->ops->tdls_mgmt)
6811 return -EOPNOTSUPP;
6812
6813 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6814 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6815 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6816 !info->attrs[NL80211_ATTR_IE] ||
6817 !info->attrs[NL80211_ATTR_MAC])
6818 return -EINVAL;
6819
6820 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6821 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6822 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6823 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6824
Hila Gonene35e4d22012-06-27 17:19:42 +03006825 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6826 dialog_token, status_code,
6827 nla_data(info->attrs[NL80211_ATTR_IE]),
6828 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006829}
6830
6831static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6832{
6833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6834 struct net_device *dev = info->user_ptr[1];
6835 enum nl80211_tdls_operation operation;
6836 u8 *peer;
6837
6838 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6839 !rdev->ops->tdls_oper)
6840 return -EOPNOTSUPP;
6841
6842 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6843 !info->attrs[NL80211_ATTR_MAC])
6844 return -EINVAL;
6845
6846 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6847 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6848
Hila Gonene35e4d22012-06-27 17:19:42 +03006849 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006850}
6851
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006852static int nl80211_remain_on_channel(struct sk_buff *skb,
6853 struct genl_info *info)
6854{
Johannes Berg4c476992010-10-04 21:36:35 +02006855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006856 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006857 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006858 struct sk_buff *msg;
6859 void *hdr;
6860 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006861 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006862 int err;
6863
6864 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6865 !info->attrs[NL80211_ATTR_DURATION])
6866 return -EINVAL;
6867
6868 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6869
Johannes Berg7c4ef712011-11-18 15:33:48 +01006870 if (!rdev->ops->remain_on_channel ||
6871 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006872 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006873
Johannes Bergebf348f2012-06-01 12:50:54 +02006874 /*
6875 * We should be on that channel for at least a minimum amount of
6876 * time (10ms) but no longer than the driver supports.
6877 */
6878 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6879 duration > rdev->wiphy.max_remain_on_channel_duration)
6880 return -EINVAL;
6881
Johannes Berg683b6d32012-11-08 21:25:48 +01006882 err = nl80211_parse_chandef(rdev, info, &chandef);
6883 if (err)
6884 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006885
6886 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006887 if (!msg)
6888 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006889
Eric W. Biederman15e47302012-09-07 20:12:54 +00006890 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006891 NL80211_CMD_REMAIN_ON_CHANNEL);
6892
6893 if (IS_ERR(hdr)) {
6894 err = PTR_ERR(hdr);
6895 goto free_msg;
6896 }
6897
Johannes Berg683b6d32012-11-08 21:25:48 +01006898 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6899 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006900
6901 if (err)
6902 goto free_msg;
6903
David S. Miller9360ffd2012-03-29 04:41:26 -04006904 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6905 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006906
6907 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006908
6909 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006910
6911 nla_put_failure:
6912 err = -ENOBUFS;
6913 free_msg:
6914 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006915 return err;
6916}
6917
6918static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6919 struct genl_info *info)
6920{
Johannes Berg4c476992010-10-04 21:36:35 +02006921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006922 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006923 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006924
6925 if (!info->attrs[NL80211_ATTR_COOKIE])
6926 return -EINVAL;
6927
Johannes Berg4c476992010-10-04 21:36:35 +02006928 if (!rdev->ops->cancel_remain_on_channel)
6929 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006930
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006931 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6932
Hila Gonene35e4d22012-06-27 17:19:42 +03006933 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006934}
6935
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006936static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6937 u8 *rates, u8 rates_len)
6938{
6939 u8 i;
6940 u32 mask = 0;
6941
6942 for (i = 0; i < rates_len; i++) {
6943 int rate = (rates[i] & 0x7f) * 5;
6944 int ridx;
6945 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6946 struct ieee80211_rate *srate =
6947 &sband->bitrates[ridx];
6948 if (rate == srate->bitrate) {
6949 mask |= 1 << ridx;
6950 break;
6951 }
6952 }
6953 if (ridx == sband->n_bitrates)
6954 return 0; /* rate not found */
6955 }
6956
6957 return mask;
6958}
6959
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006960static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6961 u8 *rates, u8 rates_len,
6962 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6963{
6964 u8 i;
6965
6966 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6967
6968 for (i = 0; i < rates_len; i++) {
6969 int ridx, rbit;
6970
6971 ridx = rates[i] / 8;
6972 rbit = BIT(rates[i] % 8);
6973
6974 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006975 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006976 return false;
6977
6978 /* check availability */
6979 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6980 mcs[ridx] |= rbit;
6981 else
6982 return false;
6983 }
6984
6985 return true;
6986}
6987
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006988static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006989 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6990 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006991 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6992 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006993};
6994
6995static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6996 struct genl_info *info)
6997{
6998 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007000 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007001 int rem, i;
7002 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007003 struct nlattr *tx_rates;
7004 struct ieee80211_supported_band *sband;
7005
7006 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7007 return -EINVAL;
7008
Johannes Berg4c476992010-10-04 21:36:35 +02007009 if (!rdev->ops->set_bitrate_mask)
7010 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007011
7012 memset(&mask, 0, sizeof(mask));
7013 /* Default to all rates enabled */
7014 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7015 sband = rdev->wiphy.bands[i];
7016 mask.control[i].legacy =
7017 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007018 if (sband)
7019 memcpy(mask.control[i].mcs,
7020 sband->ht_cap.mcs.rx_mask,
7021 sizeof(mask.control[i].mcs));
7022 else
7023 memset(mask.control[i].mcs, 0,
7024 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007025 }
7026
7027 /*
7028 * The nested attribute uses enum nl80211_band as the index. This maps
7029 * directly to the enum ieee80211_band values used in cfg80211.
7030 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007031 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007032 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7033 {
7034 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007035 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7036 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007037 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007038 if (sband == NULL)
7039 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007040 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7041 nla_len(tx_rates), nl80211_txattr_policy);
7042 if (tb[NL80211_TXRATE_LEGACY]) {
7043 mask.control[band].legacy = rateset_to_mask(
7044 sband,
7045 nla_data(tb[NL80211_TXRATE_LEGACY]),
7046 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307047 if ((mask.control[band].legacy == 0) &&
7048 nla_len(tb[NL80211_TXRATE_LEGACY]))
7049 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007050 }
7051 if (tb[NL80211_TXRATE_MCS]) {
7052 if (!ht_rateset_to_mask(
7053 sband,
7054 nla_data(tb[NL80211_TXRATE_MCS]),
7055 nla_len(tb[NL80211_TXRATE_MCS]),
7056 mask.control[band].mcs))
7057 return -EINVAL;
7058 }
7059
7060 if (mask.control[band].legacy == 0) {
7061 /* don't allow empty legacy rates if HT
7062 * is not even supported. */
7063 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7064 return -EINVAL;
7065
7066 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7067 if (mask.control[band].mcs[i])
7068 break;
7069
7070 /* legacy and mcs rates may not be both empty */
7071 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007072 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007073 }
7074 }
7075
Hila Gonene35e4d22012-06-27 17:19:42 +03007076 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007077}
7078
Johannes Berg2e161f72010-08-12 15:38:38 +02007079static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007080{
Johannes Berg4c476992010-10-04 21:36:35 +02007081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007082 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007083 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007084
7085 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7086 return -EINVAL;
7087
Johannes Berg2e161f72010-08-12 15:38:38 +02007088 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7089 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007090
Johannes Berg71bbc992012-06-15 15:30:18 +02007091 switch (wdev->iftype) {
7092 case NL80211_IFTYPE_STATION:
7093 case NL80211_IFTYPE_ADHOC:
7094 case NL80211_IFTYPE_P2P_CLIENT:
7095 case NL80211_IFTYPE_AP:
7096 case NL80211_IFTYPE_AP_VLAN:
7097 case NL80211_IFTYPE_MESH_POINT:
7098 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007099 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007100 break;
7101 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007102 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007103 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007104
7105 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007106 if (!rdev->ops->mgmt_tx)
7107 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007108
Eric W. Biederman15e47302012-09-07 20:12:54 +00007109 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007110 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7111 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007112}
7113
Johannes Berg2e161f72010-08-12 15:38:38 +02007114static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007115{
Johannes Berg4c476992010-10-04 21:36:35 +02007116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007117 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007118 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007119 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007120 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007121 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007122 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007123 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007124 bool offchan, no_cck, dont_wait_for_ack;
7125
7126 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007127
Johannes Berg683b6d32012-11-08 21:25:48 +01007128 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007129 return -EINVAL;
7130
Johannes Berg4c476992010-10-04 21:36:35 +02007131 if (!rdev->ops->mgmt_tx)
7132 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007133
Johannes Berg71bbc992012-06-15 15:30:18 +02007134 switch (wdev->iftype) {
7135 case NL80211_IFTYPE_STATION:
7136 case NL80211_IFTYPE_ADHOC:
7137 case NL80211_IFTYPE_P2P_CLIENT:
7138 case NL80211_IFTYPE_AP:
7139 case NL80211_IFTYPE_AP_VLAN:
7140 case NL80211_IFTYPE_MESH_POINT:
7141 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007142 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007143 break;
7144 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007145 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007146 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007147
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007148 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007149 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007150 return -EINVAL;
7151 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007152
7153 /*
7154 * We should wait on the channel for at least a minimum amount
7155 * of time (10ms) but no longer than the driver supports.
7156 */
7157 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7158 wait > rdev->wiphy.max_remain_on_channel_duration)
7159 return -EINVAL;
7160
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007161 }
7162
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007163 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7164
Johannes Berg7c4ef712011-11-18 15:33:48 +01007165 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7166 return -EINVAL;
7167
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307168 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7169
Johannes Berg683b6d32012-11-08 21:25:48 +01007170 err = nl80211_parse_chandef(rdev, info, &chandef);
7171 if (err)
7172 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007173
Johannes Berge247bd902011-11-04 11:18:21 +01007174 if (!dont_wait_for_ack) {
7175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7176 if (!msg)
7177 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007178
Eric W. Biederman15e47302012-09-07 20:12:54 +00007179 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007180 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007181
Johannes Berge247bd902011-11-04 11:18:21 +01007182 if (IS_ERR(hdr)) {
7183 err = PTR_ERR(hdr);
7184 goto free_msg;
7185 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007186 }
Johannes Berge247bd902011-11-04 11:18:21 +01007187
Johannes Berg683b6d32012-11-08 21:25:48 +01007188 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007189 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7190 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007191 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007192 if (err)
7193 goto free_msg;
7194
Johannes Berge247bd902011-11-04 11:18:21 +01007195 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007196 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7197 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007198
Johannes Berge247bd902011-11-04 11:18:21 +01007199 genlmsg_end(msg, hdr);
7200 return genlmsg_reply(msg, info);
7201 }
7202
7203 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007204
7205 nla_put_failure:
7206 err = -ENOBUFS;
7207 free_msg:
7208 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007209 return err;
7210}
7211
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007212static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7213{
7214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007215 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007216 u64 cookie;
7217
7218 if (!info->attrs[NL80211_ATTR_COOKIE])
7219 return -EINVAL;
7220
7221 if (!rdev->ops->mgmt_tx_cancel_wait)
7222 return -EOPNOTSUPP;
7223
Johannes Berg71bbc992012-06-15 15:30:18 +02007224 switch (wdev->iftype) {
7225 case NL80211_IFTYPE_STATION:
7226 case NL80211_IFTYPE_ADHOC:
7227 case NL80211_IFTYPE_P2P_CLIENT:
7228 case NL80211_IFTYPE_AP:
7229 case NL80211_IFTYPE_AP_VLAN:
7230 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007231 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007232 break;
7233 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007234 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007235 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007236
7237 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7238
Hila Gonene35e4d22012-06-27 17:19:42 +03007239 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007240}
7241
Kalle Valoffb9eb32010-02-17 17:58:10 +02007242static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7243{
Johannes Berg4c476992010-10-04 21:36:35 +02007244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007245 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007246 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007247 u8 ps_state;
7248 bool state;
7249 int err;
7250
Johannes Berg4c476992010-10-04 21:36:35 +02007251 if (!info->attrs[NL80211_ATTR_PS_STATE])
7252 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007253
7254 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7255
Johannes Berg4c476992010-10-04 21:36:35 +02007256 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7257 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007258
7259 wdev = dev->ieee80211_ptr;
7260
Johannes Berg4c476992010-10-04 21:36:35 +02007261 if (!rdev->ops->set_power_mgmt)
7262 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007263
7264 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7265
7266 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007267 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007268
Hila Gonene35e4d22012-06-27 17:19:42 +03007269 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007270 if (!err)
7271 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007272 return err;
7273}
7274
7275static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7276{
Johannes Berg4c476992010-10-04 21:36:35 +02007277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007278 enum nl80211_ps_state ps_state;
7279 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007280 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007281 struct sk_buff *msg;
7282 void *hdr;
7283 int err;
7284
Kalle Valoffb9eb32010-02-17 17:58:10 +02007285 wdev = dev->ieee80211_ptr;
7286
Johannes Berg4c476992010-10-04 21:36:35 +02007287 if (!rdev->ops->set_power_mgmt)
7288 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007289
7290 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007291 if (!msg)
7292 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007293
Eric W. Biederman15e47302012-09-07 20:12:54 +00007294 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007295 NL80211_CMD_GET_POWER_SAVE);
7296 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007297 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007298 goto free_msg;
7299 }
7300
7301 if (wdev->ps)
7302 ps_state = NL80211_PS_ENABLED;
7303 else
7304 ps_state = NL80211_PS_DISABLED;
7305
David S. Miller9360ffd2012-03-29 04:41:26 -04007306 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7307 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007308
7309 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007310 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007311
Johannes Berg4c476992010-10-04 21:36:35 +02007312 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007313 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007314 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007315 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007316 return err;
7317}
7318
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007319static struct nla_policy
7320nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7321 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7322 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7323 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007324 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7325 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7326 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007327};
7328
Thomas Pedersen84f10702012-07-12 16:17:33 -07007329static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007330 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007331{
7332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7333 struct wireless_dev *wdev;
7334 struct net_device *dev = info->user_ptr[1];
7335
Johannes Bergd9d8b012012-11-26 12:51:52 +01007336 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007337 return -EINVAL;
7338
7339 wdev = dev->ieee80211_ptr;
7340
7341 if (!rdev->ops->set_cqm_txe_config)
7342 return -EOPNOTSUPP;
7343
7344 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7345 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7346 return -EOPNOTSUPP;
7347
Hila Gonene35e4d22012-06-27 17:19:42 +03007348 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007349}
7350
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007351static int nl80211_set_cqm_rssi(struct genl_info *info,
7352 s32 threshold, u32 hysteresis)
7353{
Johannes Berg4c476992010-10-04 21:36:35 +02007354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007355 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007356 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007357
7358 if (threshold > 0)
7359 return -EINVAL;
7360
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007361 wdev = dev->ieee80211_ptr;
7362
Johannes Berg4c476992010-10-04 21:36:35 +02007363 if (!rdev->ops->set_cqm_rssi_config)
7364 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007365
Johannes Berg074ac8d2010-09-16 14:58:22 +02007366 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007367 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7368 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007369
Hila Gonene35e4d22012-06-27 17:19:42 +03007370 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007371}
7372
7373static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7374{
7375 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7376 struct nlattr *cqm;
7377 int err;
7378
7379 cqm = info->attrs[NL80211_ATTR_CQM];
7380 if (!cqm) {
7381 err = -EINVAL;
7382 goto out;
7383 }
7384
7385 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7386 nl80211_attr_cqm_policy);
7387 if (err)
7388 goto out;
7389
7390 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7391 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7392 s32 threshold;
7393 u32 hysteresis;
7394 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7395 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7396 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007397 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7398 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7399 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7400 u32 rate, pkts, intvl;
7401 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7402 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7403 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7404 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007405 } else
7406 err = -EINVAL;
7407
7408out:
7409 return err;
7410}
7411
Johannes Berg29cbe682010-12-03 09:20:44 +01007412static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7413{
7414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7415 struct net_device *dev = info->user_ptr[1];
7416 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007417 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007418 int err;
7419
7420 /* start with default */
7421 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007422 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007423
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007424 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007425 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007426 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007427 if (err)
7428 return err;
7429 }
7430
7431 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7432 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7433 return -EINVAL;
7434
Javier Cardonac80d5452010-12-16 17:37:49 -08007435 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7436 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7437
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007438 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7439 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7440 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7441 return -EINVAL;
7442
Marco Porsch9bdbf042013-01-07 16:04:51 +01007443 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7444 setup.beacon_interval =
7445 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7446 if (setup.beacon_interval < 10 ||
7447 setup.beacon_interval > 10000)
7448 return -EINVAL;
7449 }
7450
7451 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7452 setup.dtim_period =
7453 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7454 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7455 return -EINVAL;
7456 }
7457
Javier Cardonac80d5452010-12-16 17:37:49 -08007458 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7459 /* parse additional setup parameters if given */
7460 err = nl80211_parse_mesh_setup(info, &setup);
7461 if (err)
7462 return err;
7463 }
7464
Thomas Pedersend37bb182013-03-04 13:06:13 -08007465 if (setup.user_mpm)
7466 cfg.auto_open_plinks = false;
7467
Johannes Bergcc1d2802012-05-16 23:50:20 +02007468 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007469 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7470 if (err)
7471 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007472 } else {
7473 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007474 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007475 }
7476
Javier Cardonac80d5452010-12-16 17:37:49 -08007477 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007478}
7479
7480static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7481{
7482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7483 struct net_device *dev = info->user_ptr[1];
7484
7485 return cfg80211_leave_mesh(rdev, dev);
7486}
7487
Johannes Bergdfb89c52012-06-27 09:23:48 +02007488#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007489static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7490 struct cfg80211_registered_device *rdev)
7491{
7492 struct nlattr *nl_pats, *nl_pat;
7493 int i, pat_len;
7494
7495 if (!rdev->wowlan->n_patterns)
7496 return 0;
7497
7498 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7499 if (!nl_pats)
7500 return -ENOBUFS;
7501
7502 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7503 nl_pat = nla_nest_start(msg, i + 1);
7504 if (!nl_pat)
7505 return -ENOBUFS;
7506 pat_len = rdev->wowlan->patterns[i].pattern_len;
7507 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7508 DIV_ROUND_UP(pat_len, 8),
7509 rdev->wowlan->patterns[i].mask) ||
7510 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7511 pat_len, rdev->wowlan->patterns[i].pattern) ||
7512 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7513 rdev->wowlan->patterns[i].pkt_offset))
7514 return -ENOBUFS;
7515 nla_nest_end(msg, nl_pat);
7516 }
7517 nla_nest_end(msg, nl_pats);
7518
7519 return 0;
7520}
7521
Johannes Berg2a0e0472013-01-23 22:57:40 +01007522static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7523 struct cfg80211_wowlan_tcp *tcp)
7524{
7525 struct nlattr *nl_tcp;
7526
7527 if (!tcp)
7528 return 0;
7529
7530 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7531 if (!nl_tcp)
7532 return -ENOBUFS;
7533
7534 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7535 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7536 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7537 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7538 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7539 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7540 tcp->payload_len, tcp->payload) ||
7541 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7542 tcp->data_interval) ||
7543 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7544 tcp->wake_len, tcp->wake_data) ||
7545 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7546 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7547 return -ENOBUFS;
7548
7549 if (tcp->payload_seq.len &&
7550 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7551 sizeof(tcp->payload_seq), &tcp->payload_seq))
7552 return -ENOBUFS;
7553
7554 if (tcp->payload_tok.len &&
7555 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7556 sizeof(tcp->payload_tok) + tcp->tokens_size,
7557 &tcp->payload_tok))
7558 return -ENOBUFS;
7559
7560 return 0;
7561}
7562
Johannes Bergff1b6e62011-05-04 15:37:28 +02007563static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7564{
7565 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7566 struct sk_buff *msg;
7567 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007568 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007569
Johannes Berg2a0e0472013-01-23 22:57:40 +01007570 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7571 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007572 return -EOPNOTSUPP;
7573
Johannes Berg2a0e0472013-01-23 22:57:40 +01007574 if (rdev->wowlan && rdev->wowlan->tcp) {
7575 /* adjust size to have room for all the data */
7576 size += rdev->wowlan->tcp->tokens_size +
7577 rdev->wowlan->tcp->payload_len +
7578 rdev->wowlan->tcp->wake_len +
7579 rdev->wowlan->tcp->wake_len / 8;
7580 }
7581
7582 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007583 if (!msg)
7584 return -ENOMEM;
7585
Eric W. Biederman15e47302012-09-07 20:12:54 +00007586 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007587 NL80211_CMD_GET_WOWLAN);
7588 if (!hdr)
7589 goto nla_put_failure;
7590
7591 if (rdev->wowlan) {
7592 struct nlattr *nl_wowlan;
7593
7594 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7595 if (!nl_wowlan)
7596 goto nla_put_failure;
7597
David S. Miller9360ffd2012-03-29 04:41:26 -04007598 if ((rdev->wowlan->any &&
7599 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7600 (rdev->wowlan->disconnect &&
7601 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7602 (rdev->wowlan->magic_pkt &&
7603 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7604 (rdev->wowlan->gtk_rekey_failure &&
7605 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7606 (rdev->wowlan->eap_identity_req &&
7607 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7608 (rdev->wowlan->four_way_handshake &&
7609 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7610 (rdev->wowlan->rfkill_release &&
7611 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7612 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007613
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007614 if (nl80211_send_wowlan_patterns(msg, rdev))
7615 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007616
7617 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7618 goto nla_put_failure;
7619
Johannes Bergff1b6e62011-05-04 15:37:28 +02007620 nla_nest_end(msg, nl_wowlan);
7621 }
7622
7623 genlmsg_end(msg, hdr);
7624 return genlmsg_reply(msg, info);
7625
7626nla_put_failure:
7627 nlmsg_free(msg);
7628 return -ENOBUFS;
7629}
7630
Johannes Berg2a0e0472013-01-23 22:57:40 +01007631static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7632 struct nlattr *attr,
7633 struct cfg80211_wowlan *trig)
7634{
7635 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7636 struct cfg80211_wowlan_tcp *cfg;
7637 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7638 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7639 u32 size;
7640 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7641 int err, port;
7642
7643 if (!rdev->wiphy.wowlan.tcp)
7644 return -EINVAL;
7645
7646 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7647 nla_data(attr), nla_len(attr),
7648 nl80211_wowlan_tcp_policy);
7649 if (err)
7650 return err;
7651
7652 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7653 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7654 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7655 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7656 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7657 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7658 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7659 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7660 return -EINVAL;
7661
7662 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7663 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7664 return -EINVAL;
7665
7666 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg723d5682013-02-26 13:56:40 +01007667 rdev->wiphy.wowlan.tcp->data_interval_max ||
7668 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007669 return -EINVAL;
7670
7671 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7672 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7673 return -EINVAL;
7674
7675 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7676 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7677 return -EINVAL;
7678
7679 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7680 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7681
7682 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7683 tokens_size = tokln - sizeof(*tok);
7684
7685 if (!tok->len || tokens_size % tok->len)
7686 return -EINVAL;
7687 if (!rdev->wiphy.wowlan.tcp->tok)
7688 return -EINVAL;
7689 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7690 return -EINVAL;
7691 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7692 return -EINVAL;
7693 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7694 return -EINVAL;
7695 if (tok->offset + tok->len > data_size)
7696 return -EINVAL;
7697 }
7698
7699 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7700 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7701 if (!rdev->wiphy.wowlan.tcp->seq)
7702 return -EINVAL;
7703 if (seq->len == 0 || seq->len > 4)
7704 return -EINVAL;
7705 if (seq->len + seq->offset > data_size)
7706 return -EINVAL;
7707 }
7708
7709 size = sizeof(*cfg);
7710 size += data_size;
7711 size += wake_size + wake_mask_size;
7712 size += tokens_size;
7713
7714 cfg = kzalloc(size, GFP_KERNEL);
7715 if (!cfg)
7716 return -ENOMEM;
7717 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7718 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7719 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7720 ETH_ALEN);
7721 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7722 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7723 else
7724 port = 0;
7725#ifdef CONFIG_INET
7726 /* allocate a socket and port for it and use it */
7727 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7728 IPPROTO_TCP, &cfg->sock, 1);
7729 if (err) {
7730 kfree(cfg);
7731 return err;
7732 }
7733 if (inet_csk_get_port(cfg->sock->sk, port)) {
7734 sock_release(cfg->sock);
7735 kfree(cfg);
7736 return -EADDRINUSE;
7737 }
7738 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7739#else
7740 if (!port) {
7741 kfree(cfg);
7742 return -EINVAL;
7743 }
7744 cfg->src_port = port;
7745#endif
7746
7747 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7748 cfg->payload_len = data_size;
7749 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7750 memcpy((void *)cfg->payload,
7751 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7752 data_size);
7753 if (seq)
7754 cfg->payload_seq = *seq;
7755 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7756 cfg->wake_len = wake_size;
7757 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7758 memcpy((void *)cfg->wake_data,
7759 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7760 wake_size);
7761 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7762 data_size + wake_size;
7763 memcpy((void *)cfg->wake_mask,
7764 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7765 wake_mask_size);
7766 if (tok) {
7767 cfg->tokens_size = tokens_size;
7768 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7769 }
7770
7771 trig->tcp = cfg;
7772
7773 return 0;
7774}
7775
Johannes Bergff1b6e62011-05-04 15:37:28 +02007776static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7777{
7778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7779 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007780 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007781 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007782 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7783 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007784 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007785
Johannes Berg2a0e0472013-01-23 22:57:40 +01007786 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7787 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007788 return -EOPNOTSUPP;
7789
Johannes Bergae33bd82012-07-12 16:25:02 +02007790 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7791 cfg80211_rdev_free_wowlan(rdev);
7792 rdev->wowlan = NULL;
7793 goto set_wakeup;
7794 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007795
7796 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7797 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7798 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7799 nl80211_wowlan_policy);
7800 if (err)
7801 return err;
7802
7803 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7804 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7805 return -EINVAL;
7806 new_triggers.any = true;
7807 }
7808
7809 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7810 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7811 return -EINVAL;
7812 new_triggers.disconnect = true;
7813 }
7814
7815 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7816 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7817 return -EINVAL;
7818 new_triggers.magic_pkt = true;
7819 }
7820
Johannes Berg77dbbb12011-07-13 10:48:55 +02007821 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7822 return -EINVAL;
7823
7824 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7825 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7826 return -EINVAL;
7827 new_triggers.gtk_rekey_failure = true;
7828 }
7829
7830 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7831 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7832 return -EINVAL;
7833 new_triggers.eap_identity_req = true;
7834 }
7835
7836 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7837 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7838 return -EINVAL;
7839 new_triggers.four_way_handshake = true;
7840 }
7841
7842 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7843 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7844 return -EINVAL;
7845 new_triggers.rfkill_release = true;
7846 }
7847
Johannes Bergff1b6e62011-05-04 15:37:28 +02007848 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7849 struct nlattr *pat;
7850 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007851 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007852 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7853
7854 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7855 rem)
7856 n_patterns++;
7857 if (n_patterns > wowlan->n_patterns)
7858 return -EINVAL;
7859
7860 new_triggers.patterns = kcalloc(n_patterns,
7861 sizeof(new_triggers.patterns[0]),
7862 GFP_KERNEL);
7863 if (!new_triggers.patterns)
7864 return -ENOMEM;
7865
7866 new_triggers.n_patterns = n_patterns;
7867 i = 0;
7868
7869 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7870 rem) {
7871 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7872 nla_data(pat), nla_len(pat), NULL);
7873 err = -EINVAL;
7874 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7875 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7876 goto error;
7877 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7878 mask_len = DIV_ROUND_UP(pat_len, 8);
7879 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7880 mask_len)
7881 goto error;
7882 if (pat_len > wowlan->pattern_max_len ||
7883 pat_len < wowlan->pattern_min_len)
7884 goto error;
7885
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007886 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7887 pkt_offset = 0;
7888 else
7889 pkt_offset = nla_get_u32(
7890 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7891 if (pkt_offset > wowlan->max_pkt_offset)
7892 goto error;
7893 new_triggers.patterns[i].pkt_offset = pkt_offset;
7894
Johannes Bergff1b6e62011-05-04 15:37:28 +02007895 new_triggers.patterns[i].mask =
7896 kmalloc(mask_len + pat_len, GFP_KERNEL);
7897 if (!new_triggers.patterns[i].mask) {
7898 err = -ENOMEM;
7899 goto error;
7900 }
7901 new_triggers.patterns[i].pattern =
7902 new_triggers.patterns[i].mask + mask_len;
7903 memcpy(new_triggers.patterns[i].mask,
7904 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7905 mask_len);
7906 new_triggers.patterns[i].pattern_len = pat_len;
7907 memcpy(new_triggers.patterns[i].pattern,
7908 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7909 pat_len);
7910 i++;
7911 }
7912 }
7913
Johannes Berg2a0e0472013-01-23 22:57:40 +01007914 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7915 err = nl80211_parse_wowlan_tcp(
7916 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7917 &new_triggers);
7918 if (err)
7919 goto error;
7920 }
7921
Johannes Bergae33bd82012-07-12 16:25:02 +02007922 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7923 if (!ntrig) {
7924 err = -ENOMEM;
7925 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007926 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007927 cfg80211_rdev_free_wowlan(rdev);
7928 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007929
Johannes Bergae33bd82012-07-12 16:25:02 +02007930 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007931 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007932 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007933
Johannes Bergff1b6e62011-05-04 15:37:28 +02007934 return 0;
7935 error:
7936 for (i = 0; i < new_triggers.n_patterns; i++)
7937 kfree(new_triggers.patterns[i].mask);
7938 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007939 if (new_triggers.tcp && new_triggers.tcp->sock)
7940 sock_release(new_triggers.tcp->sock);
7941 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007942 return err;
7943}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007944#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007945
Johannes Berge5497d72011-07-05 16:35:40 +02007946static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7947{
7948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7949 struct net_device *dev = info->user_ptr[1];
7950 struct wireless_dev *wdev = dev->ieee80211_ptr;
7951 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7952 struct cfg80211_gtk_rekey_data rekey_data;
7953 int err;
7954
7955 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7956 return -EINVAL;
7957
7958 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7959 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7960 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7961 nl80211_rekey_policy);
7962 if (err)
7963 return err;
7964
7965 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7966 return -ERANGE;
7967 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7968 return -ERANGE;
7969 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7970 return -ERANGE;
7971
7972 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7973 NL80211_KEK_LEN);
7974 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7975 NL80211_KCK_LEN);
7976 memcpy(rekey_data.replay_ctr,
7977 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7978 NL80211_REPLAY_CTR_LEN);
7979
7980 wdev_lock(wdev);
7981 if (!wdev->current_bss) {
7982 err = -ENOTCONN;
7983 goto out;
7984 }
7985
7986 if (!rdev->ops->set_rekey_data) {
7987 err = -EOPNOTSUPP;
7988 goto out;
7989 }
7990
Hila Gonene35e4d22012-06-27 17:19:42 +03007991 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007992 out:
7993 wdev_unlock(wdev);
7994 return err;
7995}
7996
Johannes Berg28946da2011-11-04 11:18:12 +01007997static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7998 struct genl_info *info)
7999{
8000 struct net_device *dev = info->user_ptr[1];
8001 struct wireless_dev *wdev = dev->ieee80211_ptr;
8002
8003 if (wdev->iftype != NL80211_IFTYPE_AP &&
8004 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8005 return -EINVAL;
8006
Eric W. Biederman15e47302012-09-07 20:12:54 +00008007 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008008 return -EBUSY;
8009
Eric W. Biederman15e47302012-09-07 20:12:54 +00008010 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008011 return 0;
8012}
8013
Johannes Berg7f6cf312011-11-04 11:18:15 +01008014static int nl80211_probe_client(struct sk_buff *skb,
8015 struct genl_info *info)
8016{
8017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8018 struct net_device *dev = info->user_ptr[1];
8019 struct wireless_dev *wdev = dev->ieee80211_ptr;
8020 struct sk_buff *msg;
8021 void *hdr;
8022 const u8 *addr;
8023 u64 cookie;
8024 int err;
8025
8026 if (wdev->iftype != NL80211_IFTYPE_AP &&
8027 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8028 return -EOPNOTSUPP;
8029
8030 if (!info->attrs[NL80211_ATTR_MAC])
8031 return -EINVAL;
8032
8033 if (!rdev->ops->probe_client)
8034 return -EOPNOTSUPP;
8035
8036 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8037 if (!msg)
8038 return -ENOMEM;
8039
Eric W. Biederman15e47302012-09-07 20:12:54 +00008040 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008041 NL80211_CMD_PROBE_CLIENT);
8042
8043 if (IS_ERR(hdr)) {
8044 err = PTR_ERR(hdr);
8045 goto free_msg;
8046 }
8047
8048 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8049
Hila Gonene35e4d22012-06-27 17:19:42 +03008050 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008051 if (err)
8052 goto free_msg;
8053
David S. Miller9360ffd2012-03-29 04:41:26 -04008054 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8055 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008056
8057 genlmsg_end(msg, hdr);
8058
8059 return genlmsg_reply(msg, info);
8060
8061 nla_put_failure:
8062 err = -ENOBUFS;
8063 free_msg:
8064 nlmsg_free(msg);
8065 return err;
8066}
8067
Johannes Berg5e760232011-11-04 11:18:17 +01008068static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8069{
8070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008071 struct cfg80211_beacon_registration *reg, *nreg;
8072 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008073
8074 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8075 return -EOPNOTSUPP;
8076
Ben Greear37c73b52012-10-26 14:49:25 -07008077 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8078 if (!nreg)
8079 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008080
Ben Greear37c73b52012-10-26 14:49:25 -07008081 /* First, check if already registered. */
8082 spin_lock_bh(&rdev->beacon_registrations_lock);
8083 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8084 if (reg->nlportid == info->snd_portid) {
8085 rv = -EALREADY;
8086 goto out_err;
8087 }
8088 }
8089 /* Add it to the list */
8090 nreg->nlportid = info->snd_portid;
8091 list_add(&nreg->list, &rdev->beacon_registrations);
8092
8093 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008094
8095 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008096out_err:
8097 spin_unlock_bh(&rdev->beacon_registrations_lock);
8098 kfree(nreg);
8099 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008100}
8101
Johannes Berg98104fde2012-06-16 00:19:54 +02008102static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8103{
8104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8105 struct wireless_dev *wdev = info->user_ptr[1];
8106 int err;
8107
8108 if (!rdev->ops->start_p2p_device)
8109 return -EOPNOTSUPP;
8110
8111 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8112 return -EOPNOTSUPP;
8113
8114 if (wdev->p2p_started)
8115 return 0;
8116
8117 mutex_lock(&rdev->devlist_mtx);
8118 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8119 mutex_unlock(&rdev->devlist_mtx);
8120 if (err)
8121 return err;
8122
Johannes Bergeeb126e2012-10-23 15:16:50 +02008123 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008124 if (err)
8125 return err;
8126
8127 wdev->p2p_started = true;
8128 mutex_lock(&rdev->devlist_mtx);
8129 rdev->opencount++;
8130 mutex_unlock(&rdev->devlist_mtx);
8131
8132 return 0;
8133}
8134
8135static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8136{
8137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8138 struct wireless_dev *wdev = info->user_ptr[1];
8139
8140 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8141 return -EOPNOTSUPP;
8142
8143 if (!rdev->ops->stop_p2p_device)
8144 return -EOPNOTSUPP;
8145
Johannes Bergf9f47522013-03-19 15:04:07 +01008146 mutex_lock(&rdev->sched_scan_mtx);
8147 cfg80211_stop_p2p_device(rdev, wdev);
8148 mutex_unlock(&rdev->sched_scan_mtx);
Johannes Berg98104fde2012-06-16 00:19:54 +02008149
8150 return 0;
8151}
8152
Johannes Berg3713b4e2013-02-14 16:19:38 +01008153static int nl80211_get_protocol_features(struct sk_buff *skb,
8154 struct genl_info *info)
8155{
8156 void *hdr;
8157 struct sk_buff *msg;
8158
8159 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8160 if (!msg)
8161 return -ENOMEM;
8162
8163 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8164 NL80211_CMD_GET_PROTOCOL_FEATURES);
8165 if (!hdr)
8166 goto nla_put_failure;
8167
8168 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8169 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8170 goto nla_put_failure;
8171
8172 genlmsg_end(msg, hdr);
8173 return genlmsg_reply(msg, info);
8174
8175 nla_put_failure:
8176 kfree_skb(msg);
8177 return -ENOBUFS;
8178}
8179
Jouni Malinen355199e2013-02-27 17:14:27 +02008180static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8181{
8182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8183 struct cfg80211_update_ft_ies_params ft_params;
8184 struct net_device *dev = info->user_ptr[1];
8185
8186 if (!rdev->ops->update_ft_ies)
8187 return -EOPNOTSUPP;
8188
8189 if (!info->attrs[NL80211_ATTR_MDID] ||
8190 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8191 return -EINVAL;
8192
8193 memset(&ft_params, 0, sizeof(ft_params));
8194 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8195 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8196 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8197
8198 return rdev_update_ft_ies(rdev, dev, &ft_params);
8199}
8200
Johannes Berg4c476992010-10-04 21:36:35 +02008201#define NL80211_FLAG_NEED_WIPHY 0x01
8202#define NL80211_FLAG_NEED_NETDEV 0x02
8203#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008204#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8205#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8206 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008207#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008208/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008209#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8210 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008211
8212static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8213 struct genl_info *info)
8214{
8215 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008216 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008217 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008218 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8219
8220 if (rtnl)
8221 rtnl_lock();
8222
8223 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008224 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008225 if (IS_ERR(rdev)) {
8226 if (rtnl)
8227 rtnl_unlock();
8228 return PTR_ERR(rdev);
8229 }
8230 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008231 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8232 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008233 mutex_lock(&cfg80211_mutex);
8234 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8235 info->attrs);
8236 if (IS_ERR(wdev)) {
8237 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02008238 if (rtnl)
8239 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008240 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008241 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008242
Johannes Berg89a54e42012-06-15 14:33:17 +02008243 dev = wdev->netdev;
8244 rdev = wiphy_to_dev(wdev->wiphy);
8245
Johannes Berg1bf614e2012-06-15 15:23:36 +02008246 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8247 if (!dev) {
8248 mutex_unlock(&cfg80211_mutex);
8249 if (rtnl)
8250 rtnl_unlock();
8251 return -EINVAL;
8252 }
8253
8254 info->user_ptr[1] = dev;
8255 } else {
8256 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008257 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008258
Johannes Berg1bf614e2012-06-15 15:23:36 +02008259 if (dev) {
8260 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8261 !netif_running(dev)) {
8262 mutex_unlock(&cfg80211_mutex);
8263 if (rtnl)
8264 rtnl_unlock();
8265 return -ENETDOWN;
8266 }
8267
8268 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008269 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8270 if (!wdev->p2p_started) {
8271 mutex_unlock(&cfg80211_mutex);
8272 if (rtnl)
8273 rtnl_unlock();
8274 return -ENETDOWN;
8275 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008276 }
8277
Johannes Berg89a54e42012-06-15 14:33:17 +02008278 cfg80211_lock_rdev(rdev);
8279
8280 mutex_unlock(&cfg80211_mutex);
8281
Johannes Berg4c476992010-10-04 21:36:35 +02008282 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008283 }
8284
8285 return 0;
8286}
8287
8288static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8289 struct genl_info *info)
8290{
8291 if (info->user_ptr[0])
8292 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02008293 if (info->user_ptr[1]) {
8294 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8295 struct wireless_dev *wdev = info->user_ptr[1];
8296
8297 if (wdev->netdev)
8298 dev_put(wdev->netdev);
8299 } else {
8300 dev_put(info->user_ptr[1]);
8301 }
8302 }
Johannes Berg4c476992010-10-04 21:36:35 +02008303 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8304 rtnl_unlock();
8305}
8306
Johannes Berg55682962007-09-20 13:09:35 -04008307static struct genl_ops nl80211_ops[] = {
8308 {
8309 .cmd = NL80211_CMD_GET_WIPHY,
8310 .doit = nl80211_get_wiphy,
8311 .dumpit = nl80211_dump_wiphy,
8312 .policy = nl80211_policy,
8313 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008314 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04008315 },
8316 {
8317 .cmd = NL80211_CMD_SET_WIPHY,
8318 .doit = nl80211_set_wiphy,
8319 .policy = nl80211_policy,
8320 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008321 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008322 },
8323 {
8324 .cmd = NL80211_CMD_GET_INTERFACE,
8325 .doit = nl80211_get_interface,
8326 .dumpit = nl80211_dump_interface,
8327 .policy = nl80211_policy,
8328 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02008329 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04008330 },
8331 {
8332 .cmd = NL80211_CMD_SET_INTERFACE,
8333 .doit = nl80211_set_interface,
8334 .policy = nl80211_policy,
8335 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008336 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8337 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008338 },
8339 {
8340 .cmd = NL80211_CMD_NEW_INTERFACE,
8341 .doit = nl80211_new_interface,
8342 .policy = nl80211_policy,
8343 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008344 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8345 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008346 },
8347 {
8348 .cmd = NL80211_CMD_DEL_INTERFACE,
8349 .doit = nl80211_del_interface,
8350 .policy = nl80211_policy,
8351 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008352 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008353 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008354 },
Johannes Berg41ade002007-12-19 02:03:29 +01008355 {
8356 .cmd = NL80211_CMD_GET_KEY,
8357 .doit = nl80211_get_key,
8358 .policy = nl80211_policy,
8359 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008360 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008361 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008362 },
8363 {
8364 .cmd = NL80211_CMD_SET_KEY,
8365 .doit = nl80211_set_key,
8366 .policy = nl80211_policy,
8367 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008368 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008369 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008370 },
8371 {
8372 .cmd = NL80211_CMD_NEW_KEY,
8373 .doit = nl80211_new_key,
8374 .policy = nl80211_policy,
8375 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008376 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008377 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008378 },
8379 {
8380 .cmd = NL80211_CMD_DEL_KEY,
8381 .doit = nl80211_del_key,
8382 .policy = nl80211_policy,
8383 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008384 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008385 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008386 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008387 {
8388 .cmd = NL80211_CMD_SET_BEACON,
8389 .policy = nl80211_policy,
8390 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008391 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008392 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008393 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008394 },
8395 {
Johannes Berg88600202012-02-13 15:17:18 +01008396 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008397 .policy = nl80211_policy,
8398 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008399 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008400 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008401 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008402 },
8403 {
Johannes Berg88600202012-02-13 15:17:18 +01008404 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008405 .policy = nl80211_policy,
8406 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008407 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008408 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008409 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008410 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008411 {
8412 .cmd = NL80211_CMD_GET_STATION,
8413 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008414 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008415 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008416 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8417 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008418 },
8419 {
8420 .cmd = NL80211_CMD_SET_STATION,
8421 .doit = nl80211_set_station,
8422 .policy = nl80211_policy,
8423 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008424 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008425 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008426 },
8427 {
8428 .cmd = NL80211_CMD_NEW_STATION,
8429 .doit = nl80211_new_station,
8430 .policy = nl80211_policy,
8431 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008432 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008433 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008434 },
8435 {
8436 .cmd = NL80211_CMD_DEL_STATION,
8437 .doit = nl80211_del_station,
8438 .policy = nl80211_policy,
8439 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008440 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008441 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008442 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008443 {
8444 .cmd = NL80211_CMD_GET_MPATH,
8445 .doit = nl80211_get_mpath,
8446 .dumpit = nl80211_dump_mpath,
8447 .policy = nl80211_policy,
8448 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008449 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008450 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008451 },
8452 {
8453 .cmd = NL80211_CMD_SET_MPATH,
8454 .doit = nl80211_set_mpath,
8455 .policy = nl80211_policy,
8456 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008457 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008458 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008459 },
8460 {
8461 .cmd = NL80211_CMD_NEW_MPATH,
8462 .doit = nl80211_new_mpath,
8463 .policy = nl80211_policy,
8464 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008465 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008466 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008467 },
8468 {
8469 .cmd = NL80211_CMD_DEL_MPATH,
8470 .doit = nl80211_del_mpath,
8471 .policy = nl80211_policy,
8472 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008473 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008474 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008475 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008476 {
8477 .cmd = NL80211_CMD_SET_BSS,
8478 .doit = nl80211_set_bss,
8479 .policy = nl80211_policy,
8480 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008481 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008482 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008483 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008484 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008485 .cmd = NL80211_CMD_GET_REG,
8486 .doit = nl80211_get_reg,
8487 .policy = nl80211_policy,
8488 /* can be retrieved by unprivileged users */
8489 },
8490 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008491 .cmd = NL80211_CMD_SET_REG,
8492 .doit = nl80211_set_reg,
8493 .policy = nl80211_policy,
8494 .flags = GENL_ADMIN_PERM,
8495 },
8496 {
8497 .cmd = NL80211_CMD_REQ_SET_REG,
8498 .doit = nl80211_req_set_reg,
8499 .policy = nl80211_policy,
8500 .flags = GENL_ADMIN_PERM,
8501 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008502 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008503 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8504 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008505 .policy = nl80211_policy,
8506 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008508 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008509 },
8510 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008511 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8512 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008513 .policy = nl80211_policy,
8514 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008516 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008517 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008518 {
Johannes Berg2a519312009-02-10 21:25:55 +01008519 .cmd = NL80211_CMD_TRIGGER_SCAN,
8520 .doit = nl80211_trigger_scan,
8521 .policy = nl80211_policy,
8522 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008523 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008524 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008525 },
8526 {
8527 .cmd = NL80211_CMD_GET_SCAN,
8528 .policy = nl80211_policy,
8529 .dumpit = nl80211_dump_scan,
8530 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008531 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008532 .cmd = NL80211_CMD_START_SCHED_SCAN,
8533 .doit = nl80211_start_sched_scan,
8534 .policy = nl80211_policy,
8535 .flags = GENL_ADMIN_PERM,
8536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8537 NL80211_FLAG_NEED_RTNL,
8538 },
8539 {
8540 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8541 .doit = nl80211_stop_sched_scan,
8542 .policy = nl80211_policy,
8543 .flags = GENL_ADMIN_PERM,
8544 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8545 NL80211_FLAG_NEED_RTNL,
8546 },
8547 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008548 .cmd = NL80211_CMD_AUTHENTICATE,
8549 .doit = nl80211_authenticate,
8550 .policy = nl80211_policy,
8551 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008552 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008553 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008554 },
8555 {
8556 .cmd = NL80211_CMD_ASSOCIATE,
8557 .doit = nl80211_associate,
8558 .policy = nl80211_policy,
8559 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008560 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008561 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008562 },
8563 {
8564 .cmd = NL80211_CMD_DEAUTHENTICATE,
8565 .doit = nl80211_deauthenticate,
8566 .policy = nl80211_policy,
8567 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008568 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008569 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008570 },
8571 {
8572 .cmd = NL80211_CMD_DISASSOCIATE,
8573 .doit = nl80211_disassociate,
8574 .policy = nl80211_policy,
8575 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008576 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008577 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008578 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008579 {
8580 .cmd = NL80211_CMD_JOIN_IBSS,
8581 .doit = nl80211_join_ibss,
8582 .policy = nl80211_policy,
8583 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008584 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008585 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008586 },
8587 {
8588 .cmd = NL80211_CMD_LEAVE_IBSS,
8589 .doit = nl80211_leave_ibss,
8590 .policy = nl80211_policy,
8591 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008592 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008593 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008594 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008595#ifdef CONFIG_NL80211_TESTMODE
8596 {
8597 .cmd = NL80211_CMD_TESTMODE,
8598 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008599 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008600 .policy = nl80211_policy,
8601 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008602 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8603 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008604 },
8605#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008606 {
8607 .cmd = NL80211_CMD_CONNECT,
8608 .doit = nl80211_connect,
8609 .policy = nl80211_policy,
8610 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008612 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008613 },
8614 {
8615 .cmd = NL80211_CMD_DISCONNECT,
8616 .doit = nl80211_disconnect,
8617 .policy = nl80211_policy,
8618 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008620 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008621 },
Johannes Berg463d0182009-07-14 00:33:35 +02008622 {
8623 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8624 .doit = nl80211_wiphy_netns,
8625 .policy = nl80211_policy,
8626 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008627 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8628 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008629 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008630 {
8631 .cmd = NL80211_CMD_GET_SURVEY,
8632 .policy = nl80211_policy,
8633 .dumpit = nl80211_dump_survey,
8634 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008635 {
8636 .cmd = NL80211_CMD_SET_PMKSA,
8637 .doit = nl80211_setdel_pmksa,
8638 .policy = nl80211_policy,
8639 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008640 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008641 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008642 },
8643 {
8644 .cmd = NL80211_CMD_DEL_PMKSA,
8645 .doit = nl80211_setdel_pmksa,
8646 .policy = nl80211_policy,
8647 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008648 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008649 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008650 },
8651 {
8652 .cmd = NL80211_CMD_FLUSH_PMKSA,
8653 .doit = nl80211_flush_pmksa,
8654 .policy = nl80211_policy,
8655 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008656 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008657 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008658 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008659 {
8660 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8661 .doit = nl80211_remain_on_channel,
8662 .policy = nl80211_policy,
8663 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008664 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008665 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008666 },
8667 {
8668 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8669 .doit = nl80211_cancel_remain_on_channel,
8670 .policy = nl80211_policy,
8671 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008672 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008673 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008674 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008675 {
8676 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8677 .doit = nl80211_set_tx_bitrate_mask,
8678 .policy = nl80211_policy,
8679 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008680 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8681 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008682 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008683 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008684 .cmd = NL80211_CMD_REGISTER_FRAME,
8685 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008686 .policy = nl80211_policy,
8687 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008688 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008689 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008690 },
8691 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008692 .cmd = NL80211_CMD_FRAME,
8693 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008694 .policy = nl80211_policy,
8695 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008696 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008697 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008698 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008699 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008700 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8701 .doit = nl80211_tx_mgmt_cancel_wait,
8702 .policy = nl80211_policy,
8703 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008704 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008705 NL80211_FLAG_NEED_RTNL,
8706 },
8707 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008708 .cmd = NL80211_CMD_SET_POWER_SAVE,
8709 .doit = nl80211_set_power_save,
8710 .policy = nl80211_policy,
8711 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008712 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8713 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008714 },
8715 {
8716 .cmd = NL80211_CMD_GET_POWER_SAVE,
8717 .doit = nl80211_get_power_save,
8718 .policy = nl80211_policy,
8719 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008720 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8721 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008722 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008723 {
8724 .cmd = NL80211_CMD_SET_CQM,
8725 .doit = nl80211_set_cqm,
8726 .policy = nl80211_policy,
8727 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008728 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8729 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008730 },
Johannes Bergf444de02010-05-05 15:25:02 +02008731 {
8732 .cmd = NL80211_CMD_SET_CHANNEL,
8733 .doit = nl80211_set_channel,
8734 .policy = nl80211_policy,
8735 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008736 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8737 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008738 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008739 {
8740 .cmd = NL80211_CMD_SET_WDS_PEER,
8741 .doit = nl80211_set_wds_peer,
8742 .policy = nl80211_policy,
8743 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008744 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8745 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008746 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008747 {
8748 .cmd = NL80211_CMD_JOIN_MESH,
8749 .doit = nl80211_join_mesh,
8750 .policy = nl80211_policy,
8751 .flags = GENL_ADMIN_PERM,
8752 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8753 NL80211_FLAG_NEED_RTNL,
8754 },
8755 {
8756 .cmd = NL80211_CMD_LEAVE_MESH,
8757 .doit = nl80211_leave_mesh,
8758 .policy = nl80211_policy,
8759 .flags = GENL_ADMIN_PERM,
8760 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8761 NL80211_FLAG_NEED_RTNL,
8762 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008763#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008764 {
8765 .cmd = NL80211_CMD_GET_WOWLAN,
8766 .doit = nl80211_get_wowlan,
8767 .policy = nl80211_policy,
8768 /* can be retrieved by unprivileged users */
8769 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8770 NL80211_FLAG_NEED_RTNL,
8771 },
8772 {
8773 .cmd = NL80211_CMD_SET_WOWLAN,
8774 .doit = nl80211_set_wowlan,
8775 .policy = nl80211_policy,
8776 .flags = GENL_ADMIN_PERM,
8777 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8778 NL80211_FLAG_NEED_RTNL,
8779 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008780#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008781 {
8782 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8783 .doit = nl80211_set_rekey_data,
8784 .policy = nl80211_policy,
8785 .flags = GENL_ADMIN_PERM,
8786 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8787 NL80211_FLAG_NEED_RTNL,
8788 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008789 {
8790 .cmd = NL80211_CMD_TDLS_MGMT,
8791 .doit = nl80211_tdls_mgmt,
8792 .policy = nl80211_policy,
8793 .flags = GENL_ADMIN_PERM,
8794 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8795 NL80211_FLAG_NEED_RTNL,
8796 },
8797 {
8798 .cmd = NL80211_CMD_TDLS_OPER,
8799 .doit = nl80211_tdls_oper,
8800 .policy = nl80211_policy,
8801 .flags = GENL_ADMIN_PERM,
8802 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8803 NL80211_FLAG_NEED_RTNL,
8804 },
Johannes Berg28946da2011-11-04 11:18:12 +01008805 {
8806 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8807 .doit = nl80211_register_unexpected_frame,
8808 .policy = nl80211_policy,
8809 .flags = GENL_ADMIN_PERM,
8810 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8811 NL80211_FLAG_NEED_RTNL,
8812 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008813 {
8814 .cmd = NL80211_CMD_PROBE_CLIENT,
8815 .doit = nl80211_probe_client,
8816 .policy = nl80211_policy,
8817 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008818 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008819 NL80211_FLAG_NEED_RTNL,
8820 },
Johannes Berg5e760232011-11-04 11:18:17 +01008821 {
8822 .cmd = NL80211_CMD_REGISTER_BEACONS,
8823 .doit = nl80211_register_beacons,
8824 .policy = nl80211_policy,
8825 .flags = GENL_ADMIN_PERM,
8826 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8827 NL80211_FLAG_NEED_RTNL,
8828 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008829 {
8830 .cmd = NL80211_CMD_SET_NOACK_MAP,
8831 .doit = nl80211_set_noack_map,
8832 .policy = nl80211_policy,
8833 .flags = GENL_ADMIN_PERM,
8834 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8835 NL80211_FLAG_NEED_RTNL,
8836 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008837 {
8838 .cmd = NL80211_CMD_START_P2P_DEVICE,
8839 .doit = nl80211_start_p2p_device,
8840 .policy = nl80211_policy,
8841 .flags = GENL_ADMIN_PERM,
8842 .internal_flags = NL80211_FLAG_NEED_WDEV |
8843 NL80211_FLAG_NEED_RTNL,
8844 },
8845 {
8846 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8847 .doit = nl80211_stop_p2p_device,
8848 .policy = nl80211_policy,
8849 .flags = GENL_ADMIN_PERM,
8850 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8851 NL80211_FLAG_NEED_RTNL,
8852 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008853 {
8854 .cmd = NL80211_CMD_SET_MCAST_RATE,
8855 .doit = nl80211_set_mcast_rate,
8856 .policy = nl80211_policy,
8857 .flags = GENL_ADMIN_PERM,
8858 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8859 NL80211_FLAG_NEED_RTNL,
8860 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308861 {
8862 .cmd = NL80211_CMD_SET_MAC_ACL,
8863 .doit = nl80211_set_mac_acl,
8864 .policy = nl80211_policy,
8865 .flags = GENL_ADMIN_PERM,
8866 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8867 NL80211_FLAG_NEED_RTNL,
8868 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008869 {
8870 .cmd = NL80211_CMD_RADAR_DETECT,
8871 .doit = nl80211_start_radar_detection,
8872 .policy = nl80211_policy,
8873 .flags = GENL_ADMIN_PERM,
8874 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8875 NL80211_FLAG_NEED_RTNL,
8876 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008877 {
8878 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8879 .doit = nl80211_get_protocol_features,
8880 .policy = nl80211_policy,
8881 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008882 {
8883 .cmd = NL80211_CMD_UPDATE_FT_IES,
8884 .doit = nl80211_update_ft_ies,
8885 .policy = nl80211_policy,
8886 .flags = GENL_ADMIN_PERM,
8887 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8888 NL80211_FLAG_NEED_RTNL,
8889 },
Johannes Berg55682962007-09-20 13:09:35 -04008890};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008891
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008892static struct genl_multicast_group nl80211_mlme_mcgrp = {
8893 .name = "mlme",
8894};
Johannes Berg55682962007-09-20 13:09:35 -04008895
8896/* multicast groups */
8897static struct genl_multicast_group nl80211_config_mcgrp = {
8898 .name = "config",
8899};
Johannes Berg2a519312009-02-10 21:25:55 +01008900static struct genl_multicast_group nl80211_scan_mcgrp = {
8901 .name = "scan",
8902};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008903static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8904 .name = "regulatory",
8905};
Johannes Berg55682962007-09-20 13:09:35 -04008906
8907/* notification functions */
8908
8909void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8910{
8911 struct sk_buff *msg;
8912
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008913 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008914 if (!msg)
8915 return;
8916
Johannes Berg3713b4e2013-02-14 16:19:38 +01008917 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8918 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008919 nlmsg_free(msg);
8920 return;
8921 }
8922
Johannes Berg463d0182009-07-14 00:33:35 +02008923 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8924 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008925}
8926
Johannes Berg362a4152009-05-24 16:43:15 +02008927static int nl80211_add_scan_req(struct sk_buff *msg,
8928 struct cfg80211_registered_device *rdev)
8929{
8930 struct cfg80211_scan_request *req = rdev->scan_req;
8931 struct nlattr *nest;
8932 int i;
8933
Johannes Bergf9f47522013-03-19 15:04:07 +01008934 lockdep_assert_held(&rdev->sched_scan_mtx);
Johannes Berg667503d2009-07-07 03:56:11 +02008935
Johannes Berg362a4152009-05-24 16:43:15 +02008936 if (WARN_ON(!req))
8937 return 0;
8938
8939 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8940 if (!nest)
8941 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008942 for (i = 0; i < req->n_ssids; i++) {
8943 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8944 goto nla_put_failure;
8945 }
Johannes Berg362a4152009-05-24 16:43:15 +02008946 nla_nest_end(msg, nest);
8947
8948 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8949 if (!nest)
8950 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008951 for (i = 0; i < req->n_channels; i++) {
8952 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8953 goto nla_put_failure;
8954 }
Johannes Berg362a4152009-05-24 16:43:15 +02008955 nla_nest_end(msg, nest);
8956
David S. Miller9360ffd2012-03-29 04:41:26 -04008957 if (req->ie &&
8958 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8959 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008960
Sam Lefflered4737712012-10-11 21:03:31 -07008961 if (req->flags)
8962 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8963
Johannes Berg362a4152009-05-24 16:43:15 +02008964 return 0;
8965 nla_put_failure:
8966 return -ENOBUFS;
8967}
8968
Johannes Berga538e2d2009-06-16 19:56:42 +02008969static int nl80211_send_scan_msg(struct sk_buff *msg,
8970 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008971 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008972 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008973 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008974{
8975 void *hdr;
8976
Eric W. Biederman15e47302012-09-07 20:12:54 +00008977 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008978 if (!hdr)
8979 return -1;
8980
David S. Miller9360ffd2012-03-29 04:41:26 -04008981 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008982 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8983 wdev->netdev->ifindex)) ||
8984 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008985 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008986
Johannes Berg362a4152009-05-24 16:43:15 +02008987 /* ignore errors and send incomplete event anyway */
8988 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008989
8990 return genlmsg_end(msg, hdr);
8991
8992 nla_put_failure:
8993 genlmsg_cancel(msg, hdr);
8994 return -EMSGSIZE;
8995}
8996
Luciano Coelho807f8a82011-05-11 17:09:35 +03008997static int
8998nl80211_send_sched_scan_msg(struct sk_buff *msg,
8999 struct cfg80211_registered_device *rdev,
9000 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009001 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009002{
9003 void *hdr;
9004
Eric W. Biederman15e47302012-09-07 20:12:54 +00009005 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009006 if (!hdr)
9007 return -1;
9008
David S. Miller9360ffd2012-03-29 04:41:26 -04009009 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9010 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9011 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009012
9013 return genlmsg_end(msg, hdr);
9014
9015 nla_put_failure:
9016 genlmsg_cancel(msg, hdr);
9017 return -EMSGSIZE;
9018}
9019
Johannes Berga538e2d2009-06-16 19:56:42 +02009020void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009021 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009022{
9023 struct sk_buff *msg;
9024
Thomas Graf58050fc2012-06-28 03:57:45 +00009025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009026 if (!msg)
9027 return;
9028
Johannes Bergfd014282012-06-18 19:17:03 +02009029 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009030 NL80211_CMD_TRIGGER_SCAN) < 0) {
9031 nlmsg_free(msg);
9032 return;
9033 }
9034
Johannes Berg463d0182009-07-14 00:33:35 +02009035 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9036 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009037}
9038
Johannes Berg2a519312009-02-10 21:25:55 +01009039void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009040 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009041{
9042 struct sk_buff *msg;
9043
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009044 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009045 if (!msg)
9046 return;
9047
Johannes Bergfd014282012-06-18 19:17:03 +02009048 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009049 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009050 nlmsg_free(msg);
9051 return;
9052 }
9053
Johannes Berg463d0182009-07-14 00:33:35 +02009054 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9055 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009056}
9057
9058void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009059 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009060{
9061 struct sk_buff *msg;
9062
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009063 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009064 if (!msg)
9065 return;
9066
Johannes Bergfd014282012-06-18 19:17:03 +02009067 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009068 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009069 nlmsg_free(msg);
9070 return;
9071 }
9072
Johannes Berg463d0182009-07-14 00:33:35 +02009073 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9074 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009075}
9076
Luciano Coelho807f8a82011-05-11 17:09:35 +03009077void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9078 struct net_device *netdev)
9079{
9080 struct sk_buff *msg;
9081
9082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9083 if (!msg)
9084 return;
9085
9086 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9087 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9088 nlmsg_free(msg);
9089 return;
9090 }
9091
9092 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9093 nl80211_scan_mcgrp.id, GFP_KERNEL);
9094}
9095
9096void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9097 struct net_device *netdev, u32 cmd)
9098{
9099 struct sk_buff *msg;
9100
Thomas Graf58050fc2012-06-28 03:57:45 +00009101 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009102 if (!msg)
9103 return;
9104
9105 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9106 nlmsg_free(msg);
9107 return;
9108 }
9109
9110 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9111 nl80211_scan_mcgrp.id, GFP_KERNEL);
9112}
9113
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009114/*
9115 * This can happen on global regulatory changes or device specific settings
9116 * based on custom world regulatory domains.
9117 */
9118void nl80211_send_reg_change_event(struct regulatory_request *request)
9119{
9120 struct sk_buff *msg;
9121 void *hdr;
9122
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009123 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009124 if (!msg)
9125 return;
9126
9127 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9128 if (!hdr) {
9129 nlmsg_free(msg);
9130 return;
9131 }
9132
9133 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009134 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9135 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009136
David S. Miller9360ffd2012-03-29 04:41:26 -04009137 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9138 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9139 NL80211_REGDOM_TYPE_WORLD))
9140 goto nla_put_failure;
9141 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9142 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9143 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9144 goto nla_put_failure;
9145 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9146 request->intersect) {
9147 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9148 NL80211_REGDOM_TYPE_INTERSECTION))
9149 goto nla_put_failure;
9150 } else {
9151 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9152 NL80211_REGDOM_TYPE_COUNTRY) ||
9153 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9154 request->alpha2))
9155 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009156 }
9157
Johannes Bergf4173762012-12-03 18:23:37 +01009158 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009159 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9160 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009161
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009162 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009163
Johannes Bergbc43b282009-07-25 10:54:13 +02009164 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009165 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009166 GFP_ATOMIC);
9167 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009168
9169 return;
9170
9171nla_put_failure:
9172 genlmsg_cancel(msg, hdr);
9173 nlmsg_free(msg);
9174}
9175
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009176static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9177 struct net_device *netdev,
9178 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009179 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009180{
9181 struct sk_buff *msg;
9182 void *hdr;
9183
Johannes Berge6d6e342009-07-01 21:26:47 +02009184 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009185 if (!msg)
9186 return;
9187
9188 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9189 if (!hdr) {
9190 nlmsg_free(msg);
9191 return;
9192 }
9193
David S. Miller9360ffd2012-03-29 04:41:26 -04009194 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9195 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9196 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9197 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009198
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009199 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009200
Johannes Berg463d0182009-07-14 00:33:35 +02009201 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9202 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009203 return;
9204
9205 nla_put_failure:
9206 genlmsg_cancel(msg, hdr);
9207 nlmsg_free(msg);
9208}
9209
9210void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009211 struct net_device *netdev, const u8 *buf,
9212 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009213{
9214 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009215 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009216}
9217
9218void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9219 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009220 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009221{
Johannes Berge6d6e342009-07-01 21:26:47 +02009222 nl80211_send_mlme_event(rdev, netdev, buf, len,
9223 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009224}
9225
Jouni Malinen53b46b82009-03-27 20:53:56 +02009226void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009227 struct net_device *netdev, const u8 *buf,
9228 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009229{
9230 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009231 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009232}
9233
Jouni Malinen53b46b82009-03-27 20:53:56 +02009234void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9235 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009236 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009237{
9238 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009239 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009240}
9241
Johannes Berg947add32013-02-22 22:05:20 +01009242void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9243 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009244{
Johannes Berg947add32013-02-22 22:05:20 +01009245 struct wireless_dev *wdev = dev->ieee80211_ptr;
9246 struct wiphy *wiphy = wdev->wiphy;
9247 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009248
Johannes Berg947add32013-02-22 22:05:20 +01009249 trace_cfg80211_send_unprot_deauth(dev);
9250 nl80211_send_mlme_event(rdev, dev, buf, len,
9251 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009252}
Johannes Berg947add32013-02-22 22:05:20 +01009253EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9254
9255void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9256 size_t len)
9257{
9258 struct wireless_dev *wdev = dev->ieee80211_ptr;
9259 struct wiphy *wiphy = wdev->wiphy;
9260 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9261
9262 trace_cfg80211_send_unprot_disassoc(dev);
9263 nl80211_send_mlme_event(rdev, dev, buf, len,
9264 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9265}
9266EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009267
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009268static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9269 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009270 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009271{
9272 struct sk_buff *msg;
9273 void *hdr;
9274
Johannes Berge6d6e342009-07-01 21:26:47 +02009275 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009276 if (!msg)
9277 return;
9278
9279 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9280 if (!hdr) {
9281 nlmsg_free(msg);
9282 return;
9283 }
9284
David S. Miller9360ffd2012-03-29 04:41:26 -04009285 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9286 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9287 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9288 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9289 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009290
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009291 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009292
Johannes Berg463d0182009-07-14 00:33:35 +02009293 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9294 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009295 return;
9296
9297 nla_put_failure:
9298 genlmsg_cancel(msg, hdr);
9299 nlmsg_free(msg);
9300}
9301
9302void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009303 struct net_device *netdev, const u8 *addr,
9304 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009305{
9306 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009307 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009308}
9309
9310void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009311 struct net_device *netdev, const u8 *addr,
9312 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009313{
Johannes Berge6d6e342009-07-01 21:26:47 +02009314 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9315 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009316}
9317
Samuel Ortizb23aa672009-07-01 21:26:54 +02009318void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9319 struct net_device *netdev, const u8 *bssid,
9320 const u8 *req_ie, size_t req_ie_len,
9321 const u8 *resp_ie, size_t resp_ie_len,
9322 u16 status, gfp_t gfp)
9323{
9324 struct sk_buff *msg;
9325 void *hdr;
9326
Thomas Graf58050fc2012-06-28 03:57:45 +00009327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009328 if (!msg)
9329 return;
9330
9331 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9332 if (!hdr) {
9333 nlmsg_free(msg);
9334 return;
9335 }
9336
David S. Miller9360ffd2012-03-29 04:41:26 -04009337 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9338 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9339 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9340 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9341 (req_ie &&
9342 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9343 (resp_ie &&
9344 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9345 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009346
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009347 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009348
Johannes Berg463d0182009-07-14 00:33:35 +02009349 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9350 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009351 return;
9352
9353 nla_put_failure:
9354 genlmsg_cancel(msg, hdr);
9355 nlmsg_free(msg);
9356
9357}
9358
9359void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9360 struct net_device *netdev, const u8 *bssid,
9361 const u8 *req_ie, size_t req_ie_len,
9362 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9363{
9364 struct sk_buff *msg;
9365 void *hdr;
9366
Thomas Graf58050fc2012-06-28 03:57:45 +00009367 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009368 if (!msg)
9369 return;
9370
9371 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9372 if (!hdr) {
9373 nlmsg_free(msg);
9374 return;
9375 }
9376
David S. Miller9360ffd2012-03-29 04:41:26 -04009377 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9378 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9379 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9380 (req_ie &&
9381 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9382 (resp_ie &&
9383 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9384 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009385
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009386 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009387
Johannes Berg463d0182009-07-14 00:33:35 +02009388 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9389 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009390 return;
9391
9392 nla_put_failure:
9393 genlmsg_cancel(msg, hdr);
9394 nlmsg_free(msg);
9395
9396}
9397
9398void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9399 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009400 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009401{
9402 struct sk_buff *msg;
9403 void *hdr;
9404
Thomas Graf58050fc2012-06-28 03:57:45 +00009405 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009406 if (!msg)
9407 return;
9408
9409 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9410 if (!hdr) {
9411 nlmsg_free(msg);
9412 return;
9413 }
9414
David S. Miller9360ffd2012-03-29 04:41:26 -04009415 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9416 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9417 (from_ap && reason &&
9418 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9419 (from_ap &&
9420 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9421 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9422 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009423
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009424 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009425
Johannes Berg463d0182009-07-14 00:33:35 +02009426 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9427 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009428 return;
9429
9430 nla_put_failure:
9431 genlmsg_cancel(msg, hdr);
9432 nlmsg_free(msg);
9433
9434}
9435
Johannes Berg04a773a2009-04-19 21:24:32 +02009436void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9437 struct net_device *netdev, const u8 *bssid,
9438 gfp_t gfp)
9439{
9440 struct sk_buff *msg;
9441 void *hdr;
9442
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009443 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009444 if (!msg)
9445 return;
9446
9447 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9448 if (!hdr) {
9449 nlmsg_free(msg);
9450 return;
9451 }
9452
David S. Miller9360ffd2012-03-29 04:41:26 -04009453 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9454 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9455 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9456 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009457
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009458 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009459
Johannes Berg463d0182009-07-14 00:33:35 +02009460 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9461 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009462 return;
9463
9464 nla_put_failure:
9465 genlmsg_cancel(msg, hdr);
9466 nlmsg_free(msg);
9467}
9468
Johannes Berg947add32013-02-22 22:05:20 +01009469void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9470 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009471{
Johannes Berg947add32013-02-22 22:05:20 +01009472 struct wireless_dev *wdev = dev->ieee80211_ptr;
9473 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009474 struct sk_buff *msg;
9475 void *hdr;
9476
Johannes Berg947add32013-02-22 22:05:20 +01009477 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9478 return;
9479
9480 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9481
Javier Cardonac93b5e72011-04-07 15:08:34 -07009482 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9483 if (!msg)
9484 return;
9485
9486 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9487 if (!hdr) {
9488 nlmsg_free(msg);
9489 return;
9490 }
9491
David S. Miller9360ffd2012-03-29 04:41:26 -04009492 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009493 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9494 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009495 (ie_len && ie &&
9496 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9497 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009498
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009499 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009500
9501 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9502 nl80211_mlme_mcgrp.id, gfp);
9503 return;
9504
9505 nla_put_failure:
9506 genlmsg_cancel(msg, hdr);
9507 nlmsg_free(msg);
9508}
Johannes Berg947add32013-02-22 22:05:20 +01009509EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009510
Jouni Malinena3b8b052009-03-27 21:59:49 +02009511void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9512 struct net_device *netdev, const u8 *addr,
9513 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009514 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009515{
9516 struct sk_buff *msg;
9517 void *hdr;
9518
Johannes Berge6d6e342009-07-01 21:26:47 +02009519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009520 if (!msg)
9521 return;
9522
9523 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9524 if (!hdr) {
9525 nlmsg_free(msg);
9526 return;
9527 }
9528
David S. Miller9360ffd2012-03-29 04:41:26 -04009529 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9530 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9531 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9532 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9533 (key_id != -1 &&
9534 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9535 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9536 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009537
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009538 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009539
Johannes Berg463d0182009-07-14 00:33:35 +02009540 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9541 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009542 return;
9543
9544 nla_put_failure:
9545 genlmsg_cancel(msg, hdr);
9546 nlmsg_free(msg);
9547}
9548
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009549void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9550 struct ieee80211_channel *channel_before,
9551 struct ieee80211_channel *channel_after)
9552{
9553 struct sk_buff *msg;
9554 void *hdr;
9555 struct nlattr *nl_freq;
9556
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009557 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009558 if (!msg)
9559 return;
9560
9561 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9562 if (!hdr) {
9563 nlmsg_free(msg);
9564 return;
9565 }
9566
9567 /*
9568 * Since we are applying the beacon hint to a wiphy we know its
9569 * wiphy_idx is valid
9570 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009571 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9572 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009573
9574 /* Before */
9575 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9576 if (!nl_freq)
9577 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009578 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009579 goto nla_put_failure;
9580 nla_nest_end(msg, nl_freq);
9581
9582 /* After */
9583 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9584 if (!nl_freq)
9585 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009586 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009587 goto nla_put_failure;
9588 nla_nest_end(msg, nl_freq);
9589
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009590 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009591
Johannes Berg463d0182009-07-14 00:33:35 +02009592 rcu_read_lock();
9593 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9594 GFP_ATOMIC);
9595 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009596
9597 return;
9598
9599nla_put_failure:
9600 genlmsg_cancel(msg, hdr);
9601 nlmsg_free(msg);
9602}
9603
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009604static void nl80211_send_remain_on_chan_event(
9605 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009606 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009607 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009608 unsigned int duration, gfp_t gfp)
9609{
9610 struct sk_buff *msg;
9611 void *hdr;
9612
9613 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9614 if (!msg)
9615 return;
9616
9617 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9618 if (!hdr) {
9619 nlmsg_free(msg);
9620 return;
9621 }
9622
David S. Miller9360ffd2012-03-29 04:41:26 -04009623 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009624 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9625 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009626 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009627 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009628 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9629 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009630 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9631 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009632
David S. Miller9360ffd2012-03-29 04:41:26 -04009633 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9634 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9635 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009636
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009637 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009638
9639 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9640 nl80211_mlme_mcgrp.id, gfp);
9641 return;
9642
9643 nla_put_failure:
9644 genlmsg_cancel(msg, hdr);
9645 nlmsg_free(msg);
9646}
9647
Johannes Berg947add32013-02-22 22:05:20 +01009648void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9649 struct ieee80211_channel *chan,
9650 unsigned int duration, 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(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009656 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009657 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009658 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009659}
Johannes Berg947add32013-02-22 22:05:20 +01009660EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009661
Johannes Berg947add32013-02-22 22:05:20 +01009662void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9663 struct ieee80211_channel *chan,
9664 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009665{
Johannes Berg947add32013-02-22 22:05:20 +01009666 struct wiphy *wiphy = wdev->wiphy;
9667 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9668
9669 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009670 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009671 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009672}
Johannes Berg947add32013-02-22 22:05:20 +01009673EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009674
Johannes Berg947add32013-02-22 22:05:20 +01009675void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9676 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009677{
Johannes Berg947add32013-02-22 22:05:20 +01009678 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9679 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009680 struct sk_buff *msg;
9681
Johannes Berg947add32013-02-22 22:05:20 +01009682 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9683
Thomas Graf58050fc2012-06-28 03:57:45 +00009684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009685 if (!msg)
9686 return;
9687
John W. Linville66266b32012-03-15 13:25:41 -04009688 if (nl80211_send_station(msg, 0, 0, 0,
9689 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009690 nlmsg_free(msg);
9691 return;
9692 }
9693
9694 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9695 nl80211_mlme_mcgrp.id, gfp);
9696}
Johannes Berg947add32013-02-22 22:05:20 +01009697EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009698
Johannes Berg947add32013-02-22 22:05:20 +01009699void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009700{
Johannes Berg947add32013-02-22 22:05:20 +01009701 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9702 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009703 struct sk_buff *msg;
9704 void *hdr;
9705
Johannes Berg947add32013-02-22 22:05:20 +01009706 trace_cfg80211_del_sta(dev, mac_addr);
9707
Thomas Graf58050fc2012-06-28 03:57:45 +00009708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009709 if (!msg)
9710 return;
9711
9712 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9713 if (!hdr) {
9714 nlmsg_free(msg);
9715 return;
9716 }
9717
David S. Miller9360ffd2012-03-29 04:41:26 -04009718 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9719 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9720 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009721
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009722 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009723
9724 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9725 nl80211_mlme_mcgrp.id, gfp);
9726 return;
9727
9728 nla_put_failure:
9729 genlmsg_cancel(msg, hdr);
9730 nlmsg_free(msg);
9731}
Johannes Berg947add32013-02-22 22:05:20 +01009732EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009733
Johannes Berg947add32013-02-22 22:05:20 +01009734void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9735 enum nl80211_connect_failed_reason reason,
9736 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309737{
Johannes Berg947add32013-02-22 22:05:20 +01009738 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9739 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309740 struct sk_buff *msg;
9741 void *hdr;
9742
9743 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9744 if (!msg)
9745 return;
9746
9747 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9748 if (!hdr) {
9749 nlmsg_free(msg);
9750 return;
9751 }
9752
9753 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9754 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9755 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9756 goto nla_put_failure;
9757
9758 genlmsg_end(msg, hdr);
9759
9760 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9761 nl80211_mlme_mcgrp.id, gfp);
9762 return;
9763
9764 nla_put_failure:
9765 genlmsg_cancel(msg, hdr);
9766 nlmsg_free(msg);
9767}
Johannes Berg947add32013-02-22 22:05:20 +01009768EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309769
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009770static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9771 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009772{
9773 struct wireless_dev *wdev = dev->ieee80211_ptr;
9774 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9775 struct sk_buff *msg;
9776 void *hdr;
9777 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009778 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009779
Eric W. Biederman15e47302012-09-07 20:12:54 +00009780 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009781 return false;
9782
9783 msg = nlmsg_new(100, gfp);
9784 if (!msg)
9785 return true;
9786
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009787 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009788 if (!hdr) {
9789 nlmsg_free(msg);
9790 return true;
9791 }
9792
David S. Miller9360ffd2012-03-29 04:41:26 -04009793 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9794 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9795 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9796 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009797
9798 err = genlmsg_end(msg, hdr);
9799 if (err < 0) {
9800 nlmsg_free(msg);
9801 return true;
9802 }
9803
Eric W. Biederman15e47302012-09-07 20:12:54 +00009804 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009805 return true;
9806
9807 nla_put_failure:
9808 genlmsg_cancel(msg, hdr);
9809 nlmsg_free(msg);
9810 return true;
9811}
9812
Johannes Berg947add32013-02-22 22:05:20 +01009813bool cfg80211_rx_spurious_frame(struct net_device *dev,
9814 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009815{
Johannes Berg947add32013-02-22 22:05:20 +01009816 struct wireless_dev *wdev = dev->ieee80211_ptr;
9817 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009818
Johannes Berg947add32013-02-22 22:05:20 +01009819 trace_cfg80211_rx_spurious_frame(dev, addr);
9820
9821 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9822 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9823 trace_cfg80211_return_bool(false);
9824 return false;
9825 }
9826 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9827 addr, gfp);
9828 trace_cfg80211_return_bool(ret);
9829 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009830}
Johannes Berg947add32013-02-22 22:05:20 +01009831EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9832
9833bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9834 const u8 *addr, gfp_t gfp)
9835{
9836 struct wireless_dev *wdev = dev->ieee80211_ptr;
9837 bool ret;
9838
9839 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9840
9841 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9842 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9843 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9844 trace_cfg80211_return_bool(false);
9845 return false;
9846 }
9847 ret = __nl80211_unexpected_frame(dev,
9848 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9849 addr, gfp);
9850 trace_cfg80211_return_bool(ret);
9851 return ret;
9852}
9853EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009854
Johannes Berg2e161f72010-08-12 15:38:38 +02009855int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009856 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009857 int freq, int sig_dbm,
9858 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009859{
Johannes Berg71bbc992012-06-15 15:30:18 +02009860 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009861 struct sk_buff *msg;
9862 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009863
9864 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9865 if (!msg)
9866 return -ENOMEM;
9867
Johannes Berg2e161f72010-08-12 15:38:38 +02009868 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009869 if (!hdr) {
9870 nlmsg_free(msg);
9871 return -ENOMEM;
9872 }
9873
David S. Miller9360ffd2012-03-29 04:41:26 -04009874 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009875 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9876 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009877 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9878 (sig_dbm &&
9879 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9880 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9881 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009882
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009883 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009884
Eric W. Biederman15e47302012-09-07 20:12:54 +00009885 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009886
9887 nla_put_failure:
9888 genlmsg_cancel(msg, hdr);
9889 nlmsg_free(msg);
9890 return -ENOBUFS;
9891}
9892
Johannes Berg947add32013-02-22 22:05:20 +01009893void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9894 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009895{
Johannes Berg947add32013-02-22 22:05:20 +01009896 struct wiphy *wiphy = wdev->wiphy;
9897 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009898 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009899 struct sk_buff *msg;
9900 void *hdr;
9901
Johannes Berg947add32013-02-22 22:05:20 +01009902 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9903
Jouni Malinen026331c2010-02-15 12:53:10 +02009904 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9905 if (!msg)
9906 return;
9907
Johannes Berg2e161f72010-08-12 15:38:38 +02009908 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009909 if (!hdr) {
9910 nlmsg_free(msg);
9911 return;
9912 }
9913
David S. Miller9360ffd2012-03-29 04:41:26 -04009914 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009915 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9916 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009917 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9918 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9919 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9920 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009921
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009922 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009923
9924 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9925 return;
9926
9927 nla_put_failure:
9928 genlmsg_cancel(msg, hdr);
9929 nlmsg_free(msg);
9930}
Johannes Berg947add32013-02-22 22:05:20 +01009931EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009932
Johannes Berg947add32013-02-22 22:05:20 +01009933void cfg80211_cqm_rssi_notify(struct net_device *dev,
9934 enum nl80211_cqm_rssi_threshold_event rssi_event,
9935 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009936{
Johannes Berg947add32013-02-22 22:05:20 +01009937 struct wireless_dev *wdev = dev->ieee80211_ptr;
9938 struct wiphy *wiphy = wdev->wiphy;
9939 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009940 struct sk_buff *msg;
9941 struct nlattr *pinfoattr;
9942 void *hdr;
9943
Johannes Berg947add32013-02-22 22:05:20 +01009944 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
9945
Thomas Graf58050fc2012-06-28 03:57:45 +00009946 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009947 if (!msg)
9948 return;
9949
9950 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9951 if (!hdr) {
9952 nlmsg_free(msg);
9953 return;
9954 }
9955
David S. Miller9360ffd2012-03-29 04:41:26 -04009956 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009957 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -04009958 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009959
9960 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9961 if (!pinfoattr)
9962 goto nla_put_failure;
9963
David S. Miller9360ffd2012-03-29 04:41:26 -04009964 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9965 rssi_event))
9966 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009967
9968 nla_nest_end(msg, pinfoattr);
9969
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009970 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009971
9972 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9973 nl80211_mlme_mcgrp.id, gfp);
9974 return;
9975
9976 nla_put_failure:
9977 genlmsg_cancel(msg, hdr);
9978 nlmsg_free(msg);
9979}
Johannes Berg947add32013-02-22 22:05:20 +01009980EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009981
Johannes Berg947add32013-02-22 22:05:20 +01009982static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9983 struct net_device *netdev, const u8 *bssid,
9984 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +02009985{
9986 struct sk_buff *msg;
9987 struct nlattr *rekey_attr;
9988 void *hdr;
9989
Thomas Graf58050fc2012-06-28 03:57:45 +00009990 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009991 if (!msg)
9992 return;
9993
9994 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9995 if (!hdr) {
9996 nlmsg_free(msg);
9997 return;
9998 }
9999
David S. Miller9360ffd2012-03-29 04:41:26 -040010000 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10001 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10002 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10003 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010004
10005 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10006 if (!rekey_attr)
10007 goto nla_put_failure;
10008
David S. Miller9360ffd2012-03-29 04:41:26 -040010009 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10010 NL80211_REPLAY_CTR_LEN, replay_ctr))
10011 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010012
10013 nla_nest_end(msg, rekey_attr);
10014
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010015 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010016
10017 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10018 nl80211_mlme_mcgrp.id, gfp);
10019 return;
10020
10021 nla_put_failure:
10022 genlmsg_cancel(msg, hdr);
10023 nlmsg_free(msg);
10024}
10025
Johannes Berg947add32013-02-22 22:05:20 +010010026void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10027 const u8 *replay_ctr, gfp_t gfp)
10028{
10029 struct wireless_dev *wdev = dev->ieee80211_ptr;
10030 struct wiphy *wiphy = wdev->wiphy;
10031 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10032
10033 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10034 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10035}
10036EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10037
10038static void
10039nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10040 struct net_device *netdev, int index,
10041 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010042{
10043 struct sk_buff *msg;
10044 struct nlattr *attr;
10045 void *hdr;
10046
Thomas Graf58050fc2012-06-28 03:57:45 +000010047 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010048 if (!msg)
10049 return;
10050
10051 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10052 if (!hdr) {
10053 nlmsg_free(msg);
10054 return;
10055 }
10056
David S. Miller9360ffd2012-03-29 04:41:26 -040010057 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10058 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10059 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010060
10061 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10062 if (!attr)
10063 goto nla_put_failure;
10064
David S. Miller9360ffd2012-03-29 04:41:26 -040010065 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10066 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10067 (preauth &&
10068 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10069 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010070
10071 nla_nest_end(msg, attr);
10072
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010073 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010074
10075 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10076 nl80211_mlme_mcgrp.id, gfp);
10077 return;
10078
10079 nla_put_failure:
10080 genlmsg_cancel(msg, hdr);
10081 nlmsg_free(msg);
10082}
10083
Johannes Berg947add32013-02-22 22:05:20 +010010084void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10085 const u8 *bssid, bool preauth, gfp_t gfp)
10086{
10087 struct wireless_dev *wdev = dev->ieee80211_ptr;
10088 struct wiphy *wiphy = wdev->wiphy;
10089 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10090
10091 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10092 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10093}
10094EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10095
10096static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10097 struct net_device *netdev,
10098 struct cfg80211_chan_def *chandef,
10099 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010100{
10101 struct sk_buff *msg;
10102 void *hdr;
10103
Thomas Graf58050fc2012-06-28 03:57:45 +000010104 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010105 if (!msg)
10106 return;
10107
10108 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10109 if (!hdr) {
10110 nlmsg_free(msg);
10111 return;
10112 }
10113
Johannes Berg683b6d32012-11-08 21:25:48 +010010114 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10115 goto nla_put_failure;
10116
10117 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010118 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010119
10120 genlmsg_end(msg, hdr);
10121
10122 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10123 nl80211_mlme_mcgrp.id, gfp);
10124 return;
10125
10126 nla_put_failure:
10127 genlmsg_cancel(msg, hdr);
10128 nlmsg_free(msg);
10129}
10130
Johannes Berg947add32013-02-22 22:05:20 +010010131void cfg80211_ch_switch_notify(struct net_device *dev,
10132 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010133{
Johannes Berg947add32013-02-22 22:05:20 +010010134 struct wireless_dev *wdev = dev->ieee80211_ptr;
10135 struct wiphy *wiphy = wdev->wiphy;
10136 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10137
10138 trace_cfg80211_ch_switch_notify(dev, chandef);
10139
10140 wdev_lock(wdev);
10141
10142 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10143 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10144 goto out;
10145
10146 wdev->channel = chandef->chan;
10147 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10148out:
10149 wdev_unlock(wdev);
10150 return;
10151}
10152EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10153
10154void cfg80211_cqm_txe_notify(struct net_device *dev,
10155 const u8 *peer, u32 num_packets,
10156 u32 rate, u32 intvl, gfp_t gfp)
10157{
10158 struct wireless_dev *wdev = dev->ieee80211_ptr;
10159 struct wiphy *wiphy = wdev->wiphy;
10160 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010161 struct sk_buff *msg;
10162 struct nlattr *pinfoattr;
10163 void *hdr;
10164
10165 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10166 if (!msg)
10167 return;
10168
10169 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10170 if (!hdr) {
10171 nlmsg_free(msg);
10172 return;
10173 }
10174
10175 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010176 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010177 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10178 goto nla_put_failure;
10179
10180 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10181 if (!pinfoattr)
10182 goto nla_put_failure;
10183
10184 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10185 goto nla_put_failure;
10186
10187 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10188 goto nla_put_failure;
10189
10190 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10191 goto nla_put_failure;
10192
10193 nla_nest_end(msg, pinfoattr);
10194
10195 genlmsg_end(msg, hdr);
10196
10197 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10198 nl80211_mlme_mcgrp.id, gfp);
10199 return;
10200
10201 nla_put_failure:
10202 genlmsg_cancel(msg, hdr);
10203 nlmsg_free(msg);
10204}
Johannes Berg947add32013-02-22 22:05:20 +010010205EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010206
10207void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010208nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10209 struct cfg80211_chan_def *chandef,
10210 enum nl80211_radar_event event,
10211 struct net_device *netdev, gfp_t gfp)
10212{
10213 struct sk_buff *msg;
10214 void *hdr;
10215
10216 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10217 if (!msg)
10218 return;
10219
10220 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10221 if (!hdr) {
10222 nlmsg_free(msg);
10223 return;
10224 }
10225
10226 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10227 goto nla_put_failure;
10228
10229 /* NOP and radar events don't need a netdev parameter */
10230 if (netdev) {
10231 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10232
10233 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10234 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10235 goto nla_put_failure;
10236 }
10237
10238 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10239 goto nla_put_failure;
10240
10241 if (nl80211_send_chandef(msg, chandef))
10242 goto nla_put_failure;
10243
10244 if (genlmsg_end(msg, hdr) < 0) {
10245 nlmsg_free(msg);
10246 return;
10247 }
10248
10249 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10250 nl80211_mlme_mcgrp.id, gfp);
10251 return;
10252
10253 nla_put_failure:
10254 genlmsg_cancel(msg, hdr);
10255 nlmsg_free(msg);
10256}
10257
Johannes Berg947add32013-02-22 22:05:20 +010010258void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10259 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010260{
Johannes Berg947add32013-02-22 22:05:20 +010010261 struct wireless_dev *wdev = dev->ieee80211_ptr;
10262 struct wiphy *wiphy = wdev->wiphy;
10263 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010264 struct sk_buff *msg;
10265 struct nlattr *pinfoattr;
10266 void *hdr;
10267
Johannes Berg947add32013-02-22 22:05:20 +010010268 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10269
Thomas Graf58050fc2012-06-28 03:57:45 +000010270 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010271 if (!msg)
10272 return;
10273
10274 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10275 if (!hdr) {
10276 nlmsg_free(msg);
10277 return;
10278 }
10279
David S. Miller9360ffd2012-03-29 04:41:26 -040010280 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010281 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010282 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10283 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010284
10285 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10286 if (!pinfoattr)
10287 goto nla_put_failure;
10288
David S. Miller9360ffd2012-03-29 04:41:26 -040010289 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10290 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010291
10292 nla_nest_end(msg, pinfoattr);
10293
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010294 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010295
10296 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10297 nl80211_mlme_mcgrp.id, gfp);
10298 return;
10299
10300 nla_put_failure:
10301 genlmsg_cancel(msg, hdr);
10302 nlmsg_free(msg);
10303}
Johannes Berg947add32013-02-22 22:05:20 +010010304EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010305
Johannes Berg7f6cf312011-11-04 11:18:15 +010010306void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10307 u64 cookie, bool acked, gfp_t gfp)
10308{
10309 struct wireless_dev *wdev = dev->ieee80211_ptr;
10310 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10311 struct sk_buff *msg;
10312 void *hdr;
10313 int err;
10314
Beni Lev4ee3e062012-08-27 12:49:39 +030010315 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10316
Thomas Graf58050fc2012-06-28 03:57:45 +000010317 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010318
Johannes Berg7f6cf312011-11-04 11:18:15 +010010319 if (!msg)
10320 return;
10321
10322 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10323 if (!hdr) {
10324 nlmsg_free(msg);
10325 return;
10326 }
10327
David S. Miller9360ffd2012-03-29 04:41:26 -040010328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10329 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10330 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10331 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10332 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10333 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010334
10335 err = genlmsg_end(msg, hdr);
10336 if (err < 0) {
10337 nlmsg_free(msg);
10338 return;
10339 }
10340
10341 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10342 nl80211_mlme_mcgrp.id, gfp);
10343 return;
10344
10345 nla_put_failure:
10346 genlmsg_cancel(msg, hdr);
10347 nlmsg_free(msg);
10348}
10349EXPORT_SYMBOL(cfg80211_probe_status);
10350
Johannes Berg5e760232011-11-04 11:18:17 +010010351void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10352 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010353 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010354{
10355 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10356 struct sk_buff *msg;
10357 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010358 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010359
Beni Lev4ee3e062012-08-27 12:49:39 +030010360 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10361
Ben Greear37c73b52012-10-26 14:49:25 -070010362 spin_lock_bh(&rdev->beacon_registrations_lock);
10363 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10364 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10365 if (!msg) {
10366 spin_unlock_bh(&rdev->beacon_registrations_lock);
10367 return;
10368 }
Johannes Berg5e760232011-11-04 11:18:17 +010010369
Ben Greear37c73b52012-10-26 14:49:25 -070010370 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10371 if (!hdr)
10372 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010373
Ben Greear37c73b52012-10-26 14:49:25 -070010374 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10375 (freq &&
10376 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10377 (sig_dbm &&
10378 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10379 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10380 goto nla_put_failure;
10381
10382 genlmsg_end(msg, hdr);
10383
10384 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010385 }
Ben Greear37c73b52012-10-26 14:49:25 -070010386 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010387 return;
10388
10389 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010390 spin_unlock_bh(&rdev->beacon_registrations_lock);
10391 if (hdr)
10392 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010393 nlmsg_free(msg);
10394}
10395EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10396
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010397#ifdef CONFIG_PM
10398void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10399 struct cfg80211_wowlan_wakeup *wakeup,
10400 gfp_t gfp)
10401{
10402 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10403 struct sk_buff *msg;
10404 void *hdr;
10405 int err, size = 200;
10406
10407 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10408
10409 if (wakeup)
10410 size += wakeup->packet_present_len;
10411
10412 msg = nlmsg_new(size, gfp);
10413 if (!msg)
10414 return;
10415
10416 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10417 if (!hdr)
10418 goto free_msg;
10419
10420 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10421 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10422 goto free_msg;
10423
10424 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10425 wdev->netdev->ifindex))
10426 goto free_msg;
10427
10428 if (wakeup) {
10429 struct nlattr *reasons;
10430
10431 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10432
10433 if (wakeup->disconnect &&
10434 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10435 goto free_msg;
10436 if (wakeup->magic_pkt &&
10437 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10438 goto free_msg;
10439 if (wakeup->gtk_rekey_failure &&
10440 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10441 goto free_msg;
10442 if (wakeup->eap_identity_req &&
10443 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10444 goto free_msg;
10445 if (wakeup->four_way_handshake &&
10446 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10447 goto free_msg;
10448 if (wakeup->rfkill_release &&
10449 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10450 goto free_msg;
10451
10452 if (wakeup->pattern_idx >= 0 &&
10453 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10454 wakeup->pattern_idx))
10455 goto free_msg;
10456
Johannes Berg2a0e0472013-01-23 22:57:40 +010010457 if (wakeup->tcp_match)
10458 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10459
10460 if (wakeup->tcp_connlost)
10461 nla_put_flag(msg,
10462 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10463
10464 if (wakeup->tcp_nomoretokens)
10465 nla_put_flag(msg,
10466 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10467
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010468 if (wakeup->packet) {
10469 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10470 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10471
10472 if (!wakeup->packet_80211) {
10473 pkt_attr =
10474 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10475 len_attr =
10476 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10477 }
10478
10479 if (wakeup->packet_len &&
10480 nla_put_u32(msg, len_attr, wakeup->packet_len))
10481 goto free_msg;
10482
10483 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10484 wakeup->packet))
10485 goto free_msg;
10486 }
10487
10488 nla_nest_end(msg, reasons);
10489 }
10490
10491 err = genlmsg_end(msg, hdr);
10492 if (err < 0)
10493 goto free_msg;
10494
10495 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10496 nl80211_mlme_mcgrp.id, gfp);
10497 return;
10498
10499 free_msg:
10500 nlmsg_free(msg);
10501}
10502EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10503#endif
10504
Jouni Malinen3475b092012-11-16 22:49:57 +020010505void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10506 enum nl80211_tdls_operation oper,
10507 u16 reason_code, gfp_t gfp)
10508{
10509 struct wireless_dev *wdev = dev->ieee80211_ptr;
10510 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10511 struct sk_buff *msg;
10512 void *hdr;
10513 int err;
10514
10515 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10516 reason_code);
10517
10518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10519 if (!msg)
10520 return;
10521
10522 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10523 if (!hdr) {
10524 nlmsg_free(msg);
10525 return;
10526 }
10527
10528 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10530 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10531 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10532 (reason_code > 0 &&
10533 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10534 goto nla_put_failure;
10535
10536 err = genlmsg_end(msg, hdr);
10537 if (err < 0) {
10538 nlmsg_free(msg);
10539 return;
10540 }
10541
10542 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10543 nl80211_mlme_mcgrp.id, gfp);
10544 return;
10545
10546 nla_put_failure:
10547 genlmsg_cancel(msg, hdr);
10548 nlmsg_free(msg);
10549}
10550EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10551
Jouni Malinen026331c2010-02-15 12:53:10 +020010552static int nl80211_netlink_notify(struct notifier_block * nb,
10553 unsigned long state,
10554 void *_notify)
10555{
10556 struct netlink_notify *notify = _notify;
10557 struct cfg80211_registered_device *rdev;
10558 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010559 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010560
10561 if (state != NETLINK_URELEASE)
10562 return NOTIFY_DONE;
10563
10564 rcu_read_lock();
10565
Johannes Berg5e760232011-11-04 11:18:17 +010010566 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010567 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010568 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010569
10570 spin_lock_bh(&rdev->beacon_registrations_lock);
10571 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10572 list) {
10573 if (reg->nlportid == notify->portid) {
10574 list_del(&reg->list);
10575 kfree(reg);
10576 break;
10577 }
10578 }
10579 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010580 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010581
10582 rcu_read_unlock();
10583
10584 return NOTIFY_DONE;
10585}
10586
10587static struct notifier_block nl80211_netlink_notifier = {
10588 .notifier_call = nl80211_netlink_notify,
10589};
10590
Jouni Malinen355199e2013-02-27 17:14:27 +020010591void cfg80211_ft_event(struct net_device *netdev,
10592 struct cfg80211_ft_event_params *ft_event)
10593{
10594 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10595 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10596 struct sk_buff *msg;
10597 void *hdr;
10598 int err;
10599
10600 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10601
10602 if (!ft_event->target_ap)
10603 return;
10604
10605 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10606 if (!msg)
10607 return;
10608
10609 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10610 if (!hdr) {
10611 nlmsg_free(msg);
10612 return;
10613 }
10614
10615 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10616 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10617 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10618 if (ft_event->ies)
10619 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10620 if (ft_event->ric_ies)
10621 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10622 ft_event->ric_ies);
10623
10624 err = genlmsg_end(msg, hdr);
10625 if (err < 0) {
10626 nlmsg_free(msg);
10627 return;
10628 }
10629
10630 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10631 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10632}
10633EXPORT_SYMBOL(cfg80211_ft_event);
10634
Johannes Berg55682962007-09-20 13:09:35 -040010635/* initialisation/exit functions */
10636
10637int nl80211_init(void)
10638{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010639 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010640
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010641 err = genl_register_family_with_ops(&nl80211_fam,
10642 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010643 if (err)
10644 return err;
10645
Johannes Berg55682962007-09-20 13:09:35 -040010646 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10647 if (err)
10648 goto err_out;
10649
Johannes Berg2a519312009-02-10 21:25:55 +010010650 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10651 if (err)
10652 goto err_out;
10653
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010654 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10655 if (err)
10656 goto err_out;
10657
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010658 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10659 if (err)
10660 goto err_out;
10661
Johannes Bergaff89a92009-07-01 21:26:51 +020010662#ifdef CONFIG_NL80211_TESTMODE
10663 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10664 if (err)
10665 goto err_out;
10666#endif
10667
Jouni Malinen026331c2010-02-15 12:53:10 +020010668 err = netlink_register_notifier(&nl80211_netlink_notifier);
10669 if (err)
10670 goto err_out;
10671
Johannes Berg55682962007-09-20 13:09:35 -040010672 return 0;
10673 err_out:
10674 genl_unregister_family(&nl80211_fam);
10675 return err;
10676}
10677
10678void nl80211_exit(void)
10679{
Jouni Malinen026331c2010-02-15 12:53:10 +020010680 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010681 genl_unregister_family(&nl80211_fam);
10682}