blob: 946b2e7acdf291c28acfafac51b0aa354998ae7c [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
40 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = "nl80211", /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
44 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg89a54e42012-06-15 14:33:17 +020062 assert_cfg80211_lock();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
83 mutex_lock(&rdev->devlist_mtx);
84 list_for_each_entry(wdev, &rdev->wdev_list, list) {
85 if (have_ifidx && wdev->netdev &&
86 wdev->netdev->ifindex == ifidx) {
87 result = wdev;
88 break;
89 }
90 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
91 result = wdev;
92 break;
93 }
94 }
95 mutex_unlock(&rdev->devlist_mtx);
96
97 if (result)
98 break;
99 }
100
101 if (result)
102 return result;
103 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400104}
105
Johannes Berga9455402012-06-15 13:32:49 +0200106static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200107__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200108{
Johannes Berg7fee4772012-06-15 14:09:58 +0200109 struct cfg80211_registered_device *rdev = NULL, *tmp;
110 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200111
112 assert_cfg80211_lock();
113
Johannes Berg878d9ec2012-06-15 14:18:32 +0200114 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200115 !attrs[NL80211_ATTR_IFINDEX] &&
116 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200117 return ERR_PTR(-EINVAL);
118
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200120 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200121 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg89a54e42012-06-15 14:33:17 +0200123 if (attrs[NL80211_ATTR_WDEV]) {
124 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
125 struct wireless_dev *wdev;
126 bool found = false;
127
128 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
129 if (tmp) {
130 /* make sure wdev exists */
131 mutex_lock(&tmp->devlist_mtx);
132 list_for_each_entry(wdev, &tmp->wdev_list, list) {
133 if (wdev->identifier != (u32)wdev_id)
134 continue;
135 found = true;
136 break;
137 }
138 mutex_unlock(&tmp->devlist_mtx);
139
140 if (!found)
141 tmp = NULL;
142
143 if (rdev && tmp != rdev)
144 return ERR_PTR(-EINVAL);
145 rdev = tmp;
146 }
147 }
148
Johannes Berg878d9ec2012-06-15 14:18:32 +0200149 if (attrs[NL80211_ATTR_IFINDEX]) {
150 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200151 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200152 if (netdev) {
153 if (netdev->ieee80211_ptr)
154 tmp = wiphy_to_dev(
155 netdev->ieee80211_ptr->wiphy);
156 else
157 tmp = NULL;
158
159 dev_put(netdev);
160
161 /* not wireless device -- return error */
162 if (!tmp)
163 return ERR_PTR(-EINVAL);
164
165 /* mismatch -- return error */
166 if (rdev && tmp != rdev)
167 return ERR_PTR(-EINVAL);
168
169 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200170 }
Johannes Berga9455402012-06-15 13:32:49 +0200171 }
172
Johannes Berg4f7eff12012-06-15 14:14:22 +0200173 if (!rdev)
174 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200175
Johannes Berg4f7eff12012-06-15 14:14:22 +0200176 if (netns != wiphy_net(&rdev->wiphy))
177 return ERR_PTR(-ENODEV);
178
179 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200180}
181
182/*
183 * This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 * If successful, it returns non-NULL and also locks
186 * the driver's mutex!
187 *
188 * This means that you need to call cfg80211_unlock_rdev()
189 * before being allowed to acquire &cfg80211_mutex!
190 *
191 * This is necessary because we need to lock the global
192 * mutex to get an item off the list safely, and then
193 * we lock the rdev mutex so it doesn't go away under us.
194 *
195 * We don't want to keep cfg80211_mutex locked
196 * for all the time in order to allow requests on
197 * other interfaces to go through at the same time.
198 *
199 * The result of this can be a PTR_ERR and hence must
200 * be checked with IS_ERR() for errors.
201 */
202static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200203cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200204{
205 struct cfg80211_registered_device *rdev;
206
207 mutex_lock(&cfg80211_mutex);
Johannes Berg878d9ec2012-06-15 14:18:32 +0200208 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209
210 /* if it is not an error we grab the lock on
211 * it to assure it won't be going away while
212 * we operate on it */
213 if (!IS_ERR(rdev))
214 mutex_lock(&rdev->mtx);
215
216 mutex_unlock(&cfg80211_mutex);
217
218 return rdev;
219}
220
Johannes Berg55682962007-09-20 13:09:35 -0400221/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000222static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400223 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
224 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700225 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200226 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100227
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200228 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530229 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100230 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
231 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
232 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
233
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200234 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
235 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
236 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
237 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100238 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400239
240 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
241 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
242 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100243
Eliad Pellere007b852011-11-24 18:13:56 +0200244 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
245 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100246
Johannes Bergb9454e82009-07-08 13:29:08 +0200247 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100248 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
249 .len = WLAN_MAX_KEY_LEN },
250 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
251 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
252 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200253 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200254 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100255
256 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
257 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
258 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
259 .len = IEEE80211_MAX_DATA_LEN },
260 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100262 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
263 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
264 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
265 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
266 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100267 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100268 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200269 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100270 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800271 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100272 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300273
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700274 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
275 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
276
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300277 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
278 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
279 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200280 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
281 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100282 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300283
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800284 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700285 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700286
Johannes Berg6c739412011-11-03 09:27:01 +0100287 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200288
289 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
290 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
291 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100292 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
293 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200294
295 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
296 .len = IEEE80211_MAX_SSID_LEN },
297 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
298 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200299 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300300 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300301 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300302 [NL80211_ATTR_STA_FLAGS2] = {
303 .len = sizeof(struct nl80211_sta_flag_update),
304 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300305 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200308 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
309 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
310 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200311 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100312 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100313 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
314 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100315 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
316 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200317 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200318 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
319 .len = IEEE80211_MAX_DATA_LEN },
320 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200321 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200322 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300323 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200324 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200327 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900328 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
329 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100330 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100331 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100332 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200333 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700334 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300335 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200336 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200337 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300338 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300339 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
340 .len = IEEE80211_MAX_DATA_LEN },
341 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530343 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300344 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530345 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300346 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
348 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
349 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100351 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200352 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
353 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700354 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800355 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
356 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
357 .len = NL80211_HT_CAPABILITY_LEN
358 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100359 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530360 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530361 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200362 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700363 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300364 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000365 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700366 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100367 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
368 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530369 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
370 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200371 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
372 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100373 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100374 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
375 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
376 .len = NL80211_VHT_CAPABILITY_LEN,
377 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200378 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
379 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
380 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg55682962007-09-20 13:09:35 -0400381};
382
Johannes Berge31b8212010-10-05 19:39:30 +0200383/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000384static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200385 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200386 [NL80211_KEY_IDX] = { .type = NLA_U8 },
387 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200388 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200389 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
390 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200391 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100392 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
393};
394
395/* policy for the key default flags */
396static const struct nla_policy
397nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
398 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
399 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200400};
401
Johannes Bergff1b6e62011-05-04 15:37:28 +0200402/* policy for WoWLAN attributes */
403static const struct nla_policy
404nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
405 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
406 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
407 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
408 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200409 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
410 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
411 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
412 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100413 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
414};
415
416static const struct nla_policy
417nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
418 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
419 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
420 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
421 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
422 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
423 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
424 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
425 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
426 },
427 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
428 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
429 },
430 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
431 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
432 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200433};
434
Johannes Berge5497d72011-07-05 16:35:40 +0200435/* policy for GTK rekey offload attributes */
436static const struct nla_policy
437nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
438 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
439 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
440 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
441};
442
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300443static const struct nla_policy
444nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200445 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300446 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700447 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300448};
449
Holger Schuriga0438972009-11-11 11:30:02 +0100450/* ifidx get helper */
451static int nl80211_get_ifidx(struct netlink_callback *cb)
452{
453 int res;
454
455 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
456 nl80211_fam.attrbuf, nl80211_fam.maxattr,
457 nl80211_policy);
458 if (res)
459 return res;
460
461 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
462 return -EINVAL;
463
464 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
465 if (!res)
466 return -EINVAL;
467 return res;
468}
469
Johannes Berg67748892010-10-04 21:14:06 +0200470static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
471 struct netlink_callback *cb,
472 struct cfg80211_registered_device **rdev,
473 struct net_device **dev)
474{
475 int ifidx = cb->args[0];
476 int err;
477
478 if (!ifidx)
479 ifidx = nl80211_get_ifidx(cb);
480 if (ifidx < 0)
481 return ifidx;
482
483 cb->args[0] = ifidx;
484
485 rtnl_lock();
486
487 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
488 if (!*dev) {
489 err = -ENODEV;
490 goto out_rtnl;
491 }
492
493 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100494 if (IS_ERR(*rdev)) {
495 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200496 goto out_rtnl;
497 }
498
499 return 0;
500 out_rtnl:
501 rtnl_unlock();
502 return err;
503}
504
505static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
506{
507 cfg80211_unlock_rdev(rdev);
508 rtnl_unlock();
509}
510
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100511/* IE validation */
512static bool is_valid_ie_attr(const struct nlattr *attr)
513{
514 const u8 *pos;
515 int len;
516
517 if (!attr)
518 return true;
519
520 pos = nla_data(attr);
521 len = nla_len(attr);
522
523 while (len) {
524 u8 elemlen;
525
526 if (len < 2)
527 return false;
528 len -= 2;
529
530 elemlen = pos[1];
531 if (elemlen > len)
532 return false;
533
534 len -= elemlen;
535 pos += 2 + elemlen;
536 }
537
538 return true;
539}
540
Johannes Berg55682962007-09-20 13:09:35 -0400541/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000542static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400543 int flags, u8 cmd)
544{
545 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000546 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400547}
548
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400549static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100550 struct ieee80211_channel *chan,
551 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400552{
David S. Miller9360ffd2012-03-29 04:41:26 -0400553 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
554 chan->center_freq))
555 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400556
David S. Miller9360ffd2012-03-29 04:41:26 -0400557 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
565 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100566 if (chan->flags & IEEE80211_CHAN_RADAR) {
567 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
568 goto nla_put_failure;
569 if (large) {
570 u32 time;
571
572 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
573
574 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
575 chan->dfs_state))
576 goto nla_put_failure;
577 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
578 time))
579 goto nla_put_failure;
580 }
581 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400582
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100583 if (large) {
584 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
585 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
586 goto nla_put_failure;
587 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
588 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
589 goto nla_put_failure;
590 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
591 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
592 goto nla_put_failure;
593 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
594 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
595 goto nla_put_failure;
596 }
597
David S. Miller9360ffd2012-03-29 04:41:26 -0400598 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
599 DBM_TO_MBM(chan->max_power)))
600 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400601
602 return 0;
603
604 nla_put_failure:
605 return -ENOBUFS;
606}
607
Johannes Berg55682962007-09-20 13:09:35 -0400608/* netlink command implementations */
609
Johannes Bergb9454e82009-07-08 13:29:08 +0200610struct key_parse {
611 struct key_params p;
612 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200613 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100615 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200616};
617
618static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
619{
620 struct nlattr *tb[NL80211_KEY_MAX + 1];
621 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
622 nl80211_key_policy);
623 if (err)
624 return err;
625
626 k->def = !!tb[NL80211_KEY_DEFAULT];
627 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
628
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100629 if (k->def) {
630 k->def_uni = true;
631 k->def_multi = true;
632 }
633 if (k->defmgmt)
634 k->def_multi = true;
635
Johannes Bergb9454e82009-07-08 13:29:08 +0200636 if (tb[NL80211_KEY_IDX])
637 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
638
639 if (tb[NL80211_KEY_DATA]) {
640 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
641 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
642 }
643
644 if (tb[NL80211_KEY_SEQ]) {
645 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
646 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
647 }
648
649 if (tb[NL80211_KEY_CIPHER])
650 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
651
Johannes Berge31b8212010-10-05 19:39:30 +0200652 if (tb[NL80211_KEY_TYPE]) {
653 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
654 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
655 return -EINVAL;
656 }
657
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100658 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
659 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100660 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
661 tb[NL80211_KEY_DEFAULT_TYPES],
662 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100663 if (err)
664 return err;
665
666 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
667 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
668 }
669
Johannes Bergb9454e82009-07-08 13:29:08 +0200670 return 0;
671}
672
673static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
674{
675 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
676 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
677 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
678 }
679
680 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
681 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
682 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
683 }
684
685 if (info->attrs[NL80211_ATTR_KEY_IDX])
686 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
687
688 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
689 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
690
691 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
692 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
693
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100694 if (k->def) {
695 k->def_uni = true;
696 k->def_multi = true;
697 }
698 if (k->defmgmt)
699 k->def_multi = true;
700
Johannes Berge31b8212010-10-05 19:39:30 +0200701 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
702 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
703 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
704 return -EINVAL;
705 }
706
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100707 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
708 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
709 int err = nla_parse_nested(
710 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
711 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
712 nl80211_key_default_policy);
713 if (err)
714 return err;
715
716 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
717 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
718 }
719
Johannes Bergb9454e82009-07-08 13:29:08 +0200720 return 0;
721}
722
723static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
724{
725 int err;
726
727 memset(k, 0, sizeof(*k));
728 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200729 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200730
731 if (info->attrs[NL80211_ATTR_KEY])
732 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
733 else
734 err = nl80211_parse_key_old(info, k);
735
736 if (err)
737 return err;
738
739 if (k->def && k->defmgmt)
740 return -EINVAL;
741
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100742 if (k->defmgmt) {
743 if (k->def_uni || !k->def_multi)
744 return -EINVAL;
745 }
746
Johannes Bergb9454e82009-07-08 13:29:08 +0200747 if (k->idx != -1) {
748 if (k->defmgmt) {
749 if (k->idx < 4 || k->idx > 5)
750 return -EINVAL;
751 } else if (k->def) {
752 if (k->idx < 0 || k->idx > 3)
753 return -EINVAL;
754 } else {
755 if (k->idx < 0 || k->idx > 5)
756 return -EINVAL;
757 }
758 }
759
760 return 0;
761}
762
Johannes Bergfffd0932009-07-08 14:22:54 +0200763static struct cfg80211_cached_keys *
764nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530765 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200766{
767 struct key_parse parse;
768 struct nlattr *key;
769 struct cfg80211_cached_keys *result;
770 int rem, err, def = 0;
771
772 result = kzalloc(sizeof(*result), GFP_KERNEL);
773 if (!result)
774 return ERR_PTR(-ENOMEM);
775
776 result->def = -1;
777 result->defmgmt = -1;
778
779 nla_for_each_nested(key, keys, rem) {
780 memset(&parse, 0, sizeof(parse));
781 parse.idx = -1;
782
783 err = nl80211_parse_key_new(key, &parse);
784 if (err)
785 goto error;
786 err = -EINVAL;
787 if (!parse.p.key)
788 goto error;
789 if (parse.idx < 0 || parse.idx > 4)
790 goto error;
791 if (parse.def) {
792 if (def)
793 goto error;
794 def = 1;
795 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100796 if (!parse.def_uni || !parse.def_multi)
797 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200798 } else if (parse.defmgmt)
799 goto error;
800 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200801 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200802 if (err)
803 goto error;
804 result->params[parse.idx].cipher = parse.p.cipher;
805 result->params[parse.idx].key_len = parse.p.key_len;
806 result->params[parse.idx].key = result->data[parse.idx];
807 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530808
809 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
810 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
811 if (no_ht)
812 *no_ht = true;
813 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200814 }
815
816 return result;
817 error:
818 kfree(result);
819 return ERR_PTR(err);
820}
821
822static int nl80211_key_allowed(struct wireless_dev *wdev)
823{
824 ASSERT_WDEV_LOCK(wdev);
825
Johannes Bergfffd0932009-07-08 14:22:54 +0200826 switch (wdev->iftype) {
827 case NL80211_IFTYPE_AP:
828 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200829 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700830 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200831 break;
832 case NL80211_IFTYPE_ADHOC:
833 if (!wdev->current_bss)
834 return -ENOLINK;
835 break;
836 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200837 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200838 if (wdev->sme_state != CFG80211_SME_CONNECTED)
839 return -ENOLINK;
840 break;
841 default:
842 return -EINVAL;
843 }
844
845 return 0;
846}
847
Johannes Berg7527a782011-05-13 10:58:57 +0200848static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
849{
850 struct nlattr *nl_modes = nla_nest_start(msg, attr);
851 int i;
852
853 if (!nl_modes)
854 goto nla_put_failure;
855
856 i = 0;
857 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400858 if ((ifmodes & 1) && nla_put_flag(msg, i))
859 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200860 ifmodes >>= 1;
861 i++;
862 }
863
864 nla_nest_end(msg, nl_modes);
865 return 0;
866
867nla_put_failure:
868 return -ENOBUFS;
869}
870
871static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100872 struct sk_buff *msg,
873 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200874{
875 struct nlattr *nl_combis;
876 int i, j;
877
878 nl_combis = nla_nest_start(msg,
879 NL80211_ATTR_INTERFACE_COMBINATIONS);
880 if (!nl_combis)
881 goto nla_put_failure;
882
883 for (i = 0; i < wiphy->n_iface_combinations; i++) {
884 const struct ieee80211_iface_combination *c;
885 struct nlattr *nl_combi, *nl_limits;
886
887 c = &wiphy->iface_combinations[i];
888
889 nl_combi = nla_nest_start(msg, i + 1);
890 if (!nl_combi)
891 goto nla_put_failure;
892
893 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
894 if (!nl_limits)
895 goto nla_put_failure;
896
897 for (j = 0; j < c->n_limits; j++) {
898 struct nlattr *nl_limit;
899
900 nl_limit = nla_nest_start(msg, j + 1);
901 if (!nl_limit)
902 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400903 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
904 c->limits[j].max))
905 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200906 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
907 c->limits[j].types))
908 goto nla_put_failure;
909 nla_nest_end(msg, nl_limit);
910 }
911
912 nla_nest_end(msg, nl_limits);
913
David S. Miller9360ffd2012-03-29 04:41:26 -0400914 if (c->beacon_int_infra_match &&
915 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
916 goto nla_put_failure;
917 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
918 c->num_different_channels) ||
919 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
920 c->max_interfaces))
921 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100922 if (large &&
923 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
924 c->radar_detect_widths))
925 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200926
927 nla_nest_end(msg, nl_combi);
928 }
929
930 nla_nest_end(msg, nl_combis);
931
932 return 0;
933nla_put_failure:
934 return -ENOBUFS;
935}
936
Johannes Berg3713b4e2013-02-14 16:19:38 +0100937#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100938static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
939 struct sk_buff *msg)
940{
941 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
942 struct nlattr *nl_tcp;
943
944 if (!tcp)
945 return 0;
946
947 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
948 if (!nl_tcp)
949 return -ENOBUFS;
950
951 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
952 tcp->data_payload_max))
953 return -ENOBUFS;
954
955 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
956 tcp->data_payload_max))
957 return -ENOBUFS;
958
959 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
960 return -ENOBUFS;
961
962 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
963 sizeof(*tcp->tok), tcp->tok))
964 return -ENOBUFS;
965
966 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
967 tcp->data_interval_max))
968 return -ENOBUFS;
969
970 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
971 tcp->wake_payload_max))
972 return -ENOBUFS;
973
974 nla_nest_end(msg, nl_tcp);
975 return 0;
976}
977
Johannes Berg3713b4e2013-02-14 16:19:38 +0100978static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100979 struct cfg80211_registered_device *dev,
980 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100981{
982 struct nlattr *nl_wowlan;
983
984 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
985 return 0;
986
987 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
988 if (!nl_wowlan)
989 return -ENOBUFS;
990
991 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
992 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
993 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
994 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
995 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
996 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
997 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
998 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
999 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1000 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1001 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1002 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1003 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1005 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1007 return -ENOBUFS;
1008
1009 if (dev->wiphy.wowlan.n_patterns) {
1010 struct nl80211_wowlan_pattern_support pat = {
1011 .max_patterns = dev->wiphy.wowlan.n_patterns,
1012 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
1013 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
1014 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
1015 };
1016
1017 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1018 sizeof(pat), &pat))
1019 return -ENOBUFS;
1020 }
1021
Johannes Bergb56cf722013-02-20 01:02:38 +01001022 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1023 return -ENOBUFS;
1024
Johannes Berg3713b4e2013-02-14 16:19:38 +01001025 nla_nest_end(msg, nl_wowlan);
1026
1027 return 0;
1028}
1029#endif
1030
1031static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1032 struct ieee80211_supported_band *sband)
1033{
1034 struct nlattr *nl_rates, *nl_rate;
1035 struct ieee80211_rate *rate;
1036 int i;
1037
1038 /* add HT info */
1039 if (sband->ht_cap.ht_supported &&
1040 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1041 sizeof(sband->ht_cap.mcs),
1042 &sband->ht_cap.mcs) ||
1043 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1044 sband->ht_cap.cap) ||
1045 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1046 sband->ht_cap.ampdu_factor) ||
1047 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1048 sband->ht_cap.ampdu_density)))
1049 return -ENOBUFS;
1050
1051 /* add VHT info */
1052 if (sband->vht_cap.vht_supported &&
1053 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1054 sizeof(sband->vht_cap.vht_mcs),
1055 &sband->vht_cap.vht_mcs) ||
1056 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1057 sband->vht_cap.cap)))
1058 return -ENOBUFS;
1059
1060 /* add bitrates */
1061 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1062 if (!nl_rates)
1063 return -ENOBUFS;
1064
1065 for (i = 0; i < sband->n_bitrates; i++) {
1066 nl_rate = nla_nest_start(msg, i);
1067 if (!nl_rate)
1068 return -ENOBUFS;
1069
1070 rate = &sband->bitrates[i];
1071 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1072 rate->bitrate))
1073 return -ENOBUFS;
1074 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1075 nla_put_flag(msg,
1076 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1077 return -ENOBUFS;
1078
1079 nla_nest_end(msg, nl_rate);
1080 }
1081
1082 nla_nest_end(msg, nl_rates);
1083
1084 return 0;
1085}
1086
1087static int
1088nl80211_send_mgmt_stypes(struct sk_buff *msg,
1089 const struct ieee80211_txrx_stypes *mgmt_stypes)
1090{
1091 u16 stypes;
1092 struct nlattr *nl_ftypes, *nl_ifs;
1093 enum nl80211_iftype ift;
1094 int i;
1095
1096 if (!mgmt_stypes)
1097 return 0;
1098
1099 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1100 if (!nl_ifs)
1101 return -ENOBUFS;
1102
1103 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1104 nl_ftypes = nla_nest_start(msg, ift);
1105 if (!nl_ftypes)
1106 return -ENOBUFS;
1107 i = 0;
1108 stypes = mgmt_stypes[ift].tx;
1109 while (stypes) {
1110 if ((stypes & 1) &&
1111 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1112 (i << 4) | IEEE80211_FTYPE_MGMT))
1113 return -ENOBUFS;
1114 stypes >>= 1;
1115 i++;
1116 }
1117 nla_nest_end(msg, nl_ftypes);
1118 }
1119
1120 nla_nest_end(msg, nl_ifs);
1121
1122 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1123 if (!nl_ifs)
1124 return -ENOBUFS;
1125
1126 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1127 nl_ftypes = nla_nest_start(msg, ift);
1128 if (!nl_ftypes)
1129 return -ENOBUFS;
1130 i = 0;
1131 stypes = mgmt_stypes[ift].rx;
1132 while (stypes) {
1133 if ((stypes & 1) &&
1134 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1135 (i << 4) | IEEE80211_FTYPE_MGMT))
1136 return -ENOBUFS;
1137 stypes >>= 1;
1138 i++;
1139 }
1140 nla_nest_end(msg, nl_ftypes);
1141 }
1142 nla_nest_end(msg, nl_ifs);
1143
1144 return 0;
1145}
1146
1147static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1148 struct sk_buff *msg, u32 portid, u32 seq,
1149 int flags, bool split, long *split_start,
1150 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001151{
1152 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001153 struct nlattr *nl_bands, *nl_band;
1154 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001155 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001156 enum ieee80211_band band;
1157 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001158 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001159 const struct ieee80211_txrx_stypes *mgmt_stypes =
1160 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001161 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001162 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001163
Eric W. Biederman15e47302012-09-07 20:12:54 +00001164 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001165 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001166 return -ENOBUFS;
1167
1168 /* allow always using the variables */
1169 if (!split) {
1170 split_start = &start;
1171 band_start = &start_band;
1172 chan_start = &start_chan;
1173 }
Johannes Berg55682962007-09-20 13:09:35 -04001174
David S. Miller9360ffd2012-03-29 04:41:26 -04001175 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1177 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001178 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001179 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001180 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001181
Johannes Berg3713b4e2013-02-14 16:19:38 +01001182 switch (*split_start) {
1183 case 0:
1184 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1185 dev->wiphy.retry_short) ||
1186 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1187 dev->wiphy.retry_long) ||
1188 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1189 dev->wiphy.frag_threshold) ||
1190 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1191 dev->wiphy.rts_threshold) ||
1192 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1193 dev->wiphy.coverage_class) ||
1194 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1195 dev->wiphy.max_scan_ssids) ||
1196 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1197 dev->wiphy.max_sched_scan_ssids) ||
1198 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1199 dev->wiphy.max_scan_ie_len) ||
1200 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1201 dev->wiphy.max_sched_scan_ie_len) ||
1202 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1203 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001204 goto nla_put_failure;
1205
Johannes Berg3713b4e2013-02-14 16:19:38 +01001206 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1207 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1208 goto nla_put_failure;
1209 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1210 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1211 goto nla_put_failure;
1212 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1213 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1216 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1219 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1220 goto nla_put_failure;
1221 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1222 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001223 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001224
Johannes Berg3713b4e2013-02-14 16:19:38 +01001225 (*split_start)++;
1226 if (split)
1227 break;
1228 case 1:
1229 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1230 sizeof(u32) * dev->wiphy.n_cipher_suites,
1231 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001232 goto nla_put_failure;
1233
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1235 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001236 goto nla_put_failure;
1237
Johannes Berg3713b4e2013-02-14 16:19:38 +01001238 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1239 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1240 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001241
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1243 dev->wiphy.available_antennas_tx) ||
1244 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1245 dev->wiphy.available_antennas_rx))
1246 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001247
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1249 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1250 dev->wiphy.probe_resp_offload))
1251 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.available_antennas_tx ||
1254 dev->wiphy.available_antennas_rx) &&
1255 dev->ops->get_antenna) {
1256 u32 tx_ant = 0, rx_ant = 0;
1257 int res;
1258 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1259 if (!res) {
1260 if (nla_put_u32(msg,
1261 NL80211_ATTR_WIPHY_ANTENNA_TX,
1262 tx_ant) ||
1263 nla_put_u32(msg,
1264 NL80211_ATTR_WIPHY_ANTENNA_RX,
1265 rx_ant))
1266 goto nla_put_failure;
1267 }
Johannes Bergee688b002008-01-24 19:38:39 +01001268 }
1269
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 (*split_start)++;
1271 if (split)
1272 break;
1273 case 2:
1274 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1275 dev->wiphy.interface_modes))
1276 goto nla_put_failure;
1277 (*split_start)++;
1278 if (split)
1279 break;
1280 case 3:
1281 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1282 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001283 goto nla_put_failure;
1284
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1286 struct ieee80211_supported_band *sband;
1287
1288 sband = dev->wiphy.bands[band];
1289
1290 if (!sband)
1291 continue;
1292
1293 nl_band = nla_nest_start(msg, band);
1294 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001295 goto nla_put_failure;
1296
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 switch (*chan_start) {
1298 case 0:
1299 if (nl80211_send_band_rateinfo(msg, sband))
1300 goto nla_put_failure;
1301 (*chan_start)++;
1302 if (split)
1303 break;
1304 default:
1305 /* add frequencies */
1306 nl_freqs = nla_nest_start(
1307 msg, NL80211_BAND_ATTR_FREQS);
1308 if (!nl_freqs)
1309 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001310
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 for (i = *chan_start - 1;
1312 i < sband->n_channels;
1313 i++) {
1314 nl_freq = nla_nest_start(msg, i);
1315 if (!nl_freq)
1316 goto nla_put_failure;
1317
1318 chan = &sband->channels[i];
1319
Johannes Bergcdc89b92013-02-18 23:54:36 +01001320 if (nl80211_msg_put_channel(msg, chan,
1321 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 goto nla_put_failure;
1323
1324 nla_nest_end(msg, nl_freq);
1325 if (split)
1326 break;
1327 }
1328 if (i < sband->n_channels)
1329 *chan_start = i + 2;
1330 else
1331 *chan_start = 0;
1332 nla_nest_end(msg, nl_freqs);
1333 }
1334
1335 nla_nest_end(msg, nl_band);
1336
1337 if (split) {
1338 /* start again here */
1339 if (*chan_start)
1340 band--;
1341 break;
1342 }
Johannes Bergee688b002008-01-24 19:38:39 +01001343 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001345
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 if (band < IEEE80211_NUM_BANDS)
1347 *band_start = band + 1;
1348 else
1349 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001350
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 /* if bands & channels are done, continue outside */
1352 if (*band_start == 0 && *chan_start == 0)
1353 (*split_start)++;
1354 if (split)
1355 break;
1356 case 4:
1357 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1358 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001359 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360
1361 i = 0;
1362#define CMD(op, n) \
1363 do { \
1364 if (dev->ops->op) { \
1365 i++; \
1366 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1367 goto nla_put_failure; \
1368 } \
1369 } while (0)
1370
1371 CMD(add_virtual_intf, NEW_INTERFACE);
1372 CMD(change_virtual_intf, SET_INTERFACE);
1373 CMD(add_key, NEW_KEY);
1374 CMD(start_ap, START_AP);
1375 CMD(add_station, NEW_STATION);
1376 CMD(add_mpath, NEW_MPATH);
1377 CMD(update_mesh_config, SET_MESH_CONFIG);
1378 CMD(change_bss, SET_BSS);
1379 CMD(auth, AUTHENTICATE);
1380 CMD(assoc, ASSOCIATE);
1381 CMD(deauth, DEAUTHENTICATE);
1382 CMD(disassoc, DISASSOCIATE);
1383 CMD(join_ibss, JOIN_IBSS);
1384 CMD(join_mesh, JOIN_MESH);
1385 CMD(set_pmksa, SET_PMKSA);
1386 CMD(del_pmksa, DEL_PMKSA);
1387 CMD(flush_pmksa, FLUSH_PMKSA);
1388 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1389 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1390 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1391 CMD(mgmt_tx, FRAME);
1392 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1393 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1394 i++;
1395 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1396 goto nla_put_failure;
1397 }
1398 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1399 dev->ops->join_mesh) {
1400 i++;
1401 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1402 goto nla_put_failure;
1403 }
1404 CMD(set_wds_peer, SET_WDS_PEER);
1405 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1406 CMD(tdls_mgmt, TDLS_MGMT);
1407 CMD(tdls_oper, TDLS_OPER);
1408 }
1409 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1410 CMD(sched_scan_start, START_SCHED_SCAN);
1411 CMD(probe_client, PROBE_CLIENT);
1412 CMD(set_noack_map, SET_NOACK_MAP);
1413 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1414 i++;
1415 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1416 goto nla_put_failure;
1417 }
1418 CMD(start_p2p_device, START_P2P_DEVICE);
1419 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001420
Kalle Valo4745fc02011-11-17 19:06:10 +02001421#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001423#endif
1424
Johannes Berg8fdc6212009-03-14 09:34:01 +01001425#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001426
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 if (dev->ops->connect || dev->ops->auth) {
1428 i++;
1429 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001430 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001431 }
1432
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 if (dev->ops->disconnect || dev->ops->deauth) {
1434 i++;
1435 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1436 goto nla_put_failure;
1437 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 nla_nest_end(msg, nl_cmds);
1440 (*split_start)++;
1441 if (split)
1442 break;
1443 case 5:
1444 if (dev->ops->remain_on_channel &&
1445 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1446 nla_put_u32(msg,
1447 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1448 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001449 goto nla_put_failure;
1450
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1452 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1453 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001454
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1456 goto nla_put_failure;
1457 (*split_start)++;
1458 if (split)
1459 break;
1460 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001461#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001462 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 goto nla_put_failure;
1464 (*split_start)++;
1465 if (split)
1466 break;
1467#else
1468 (*split_start)++;
1469#endif
1470 case 7:
1471 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1472 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001473 goto nla_put_failure;
1474
Johannes Bergcdc89b92013-02-18 23:54:36 +01001475 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001477
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 (*split_start)++;
1479 if (split)
1480 break;
1481 case 8:
1482 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1483 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1484 dev->wiphy.ap_sme_capa))
1485 goto nla_put_failure;
1486
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001487 features = dev->wiphy.features;
1488 /*
1489 * We can only add the per-channel limit information if the
1490 * dump is split, otherwise it makes it too big. Therefore
1491 * only advertise it in that case.
1492 */
1493 if (split)
1494 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1495 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 goto nla_put_failure;
1497
1498 if (dev->wiphy.ht_capa_mod_mask &&
1499 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1500 sizeof(*dev->wiphy.ht_capa_mod_mask),
1501 dev->wiphy.ht_capa_mod_mask))
1502 goto nla_put_failure;
1503
1504 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1505 dev->wiphy.max_acl_mac_addrs &&
1506 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1507 dev->wiphy.max_acl_mac_addrs))
1508 goto nla_put_failure;
1509
1510 /*
1511 * Any information below this point is only available to
1512 * applications that can deal with it being split. This
1513 * helps ensure that newly added capabilities don't break
1514 * older tools by overrunning their buffers.
1515 *
1516 * We still increment split_start so that in the split
1517 * case we'll continue with more data in the next round,
1518 * but break unconditionally so unsplit data stops here.
1519 */
1520 (*split_start)++;
1521 break;
1522 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001523 if (dev->wiphy.extended_capabilities &&
1524 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1525 dev->wiphy.extended_capabilities_len,
1526 dev->wiphy.extended_capabilities) ||
1527 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1528 dev->wiphy.extended_capabilities_len,
1529 dev->wiphy.extended_capabilities_mask)))
1530 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531
Johannes Bergee2aca32013-02-21 17:36:01 +01001532 if (dev->wiphy.vht_capa_mod_mask &&
1533 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1534 sizeof(*dev->wiphy.vht_capa_mod_mask),
1535 dev->wiphy.vht_capa_mod_mask))
1536 goto nla_put_failure;
1537
Johannes Berg3713b4e2013-02-14 16:19:38 +01001538 /* done */
1539 *split_start = 0;
1540 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001541 }
Johannes Berg55682962007-09-20 13:09:35 -04001542 return genlmsg_end(msg, hdr);
1543
1544 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001545 genlmsg_cancel(msg, hdr);
1546 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001547}
1548
1549static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1550{
Johannes Berg645e77d2013-03-01 14:03:49 +01001551 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001552 int start = cb->args[0];
1553 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 s64 filter_wiphy = -1;
1555 bool split = false;
1556 struct nlattr **tb = nl80211_fam.attrbuf;
1557 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001558
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001559 mutex_lock(&cfg80211_mutex);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1561 tb, nl80211_fam.maxattr, nl80211_policy);
1562 if (res == 0) {
1563 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1564 if (tb[NL80211_ATTR_WIPHY])
1565 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1566 if (tb[NL80211_ATTR_WDEV])
1567 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1568 if (tb[NL80211_ATTR_IFINDEX]) {
1569 struct net_device *netdev;
1570 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1571
1572 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1573 if (!netdev) {
1574 mutex_unlock(&cfg80211_mutex);
1575 return -ENODEV;
1576 }
1577 if (netdev->ieee80211_ptr) {
1578 dev = wiphy_to_dev(
1579 netdev->ieee80211_ptr->wiphy);
1580 filter_wiphy = dev->wiphy_idx;
1581 }
1582 dev_put(netdev);
1583 }
1584 }
1585
Johannes Berg79c97e92009-07-07 03:56:12 +02001586 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001587 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1588 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001589 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001590 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1592 continue;
1593 /* attempt to fit multiple wiphy data chunks into the skb */
1594 do {
1595 ret = nl80211_send_wiphy(dev, skb,
1596 NETLINK_CB(cb->skb).portid,
1597 cb->nlh->nlmsg_seq,
1598 NLM_F_MULTI,
1599 split, &cb->args[1],
1600 &cb->args[2],
1601 &cb->args[3]);
1602 if (ret < 0) {
1603 /*
1604 * If sending the wiphy data didn't fit (ENOBUFS
1605 * or EMSGSIZE returned), this SKB is still
1606 * empty (so it's not too big because another
1607 * wiphy dataset is already in the skb) and
1608 * we've not tried to adjust the dump allocation
1609 * yet ... then adjust the alloc size to be
1610 * bigger, and return 1 but with the empty skb.
1611 * This results in an empty message being RX'ed
1612 * in userspace, but that is ignored.
1613 *
1614 * We can then retry with the larger buffer.
1615 */
1616 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1617 !skb->len &&
1618 cb->min_dump_alloc < 4096) {
1619 cb->min_dump_alloc = 4096;
1620 mutex_unlock(&cfg80211_mutex);
1621 return 1;
1622 }
1623 idx--;
1624 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001625 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 } while (cb->args[1] > 0);
1627 break;
Johannes Berg55682962007-09-20 13:09:35 -04001628 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001629 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001630
1631 cb->args[0] = idx;
1632
1633 return skb->len;
1634}
1635
1636static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1637{
1638 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001639 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001640
Johannes Berg645e77d2013-03-01 14:03:49 +01001641 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001642 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001643 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001644
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1646 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001647 nlmsg_free(msg);
1648 return -ENOBUFS;
1649 }
Johannes Berg55682962007-09-20 13:09:35 -04001650
Johannes Berg134e6372009-07-10 09:51:34 +00001651 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001652}
1653
Jouni Malinen31888482008-10-30 16:59:24 +02001654static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1655 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1656 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1657 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1658 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1659 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1660};
1661
1662static int parse_txq_params(struct nlattr *tb[],
1663 struct ieee80211_txq_params *txq_params)
1664{
Johannes Berga3304b02012-03-28 11:04:24 +02001665 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001666 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1667 !tb[NL80211_TXQ_ATTR_AIFS])
1668 return -EINVAL;
1669
Johannes Berga3304b02012-03-28 11:04:24 +02001670 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001671 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1672 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1673 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1674 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1675
Johannes Berga3304b02012-03-28 11:04:24 +02001676 if (txq_params->ac >= NL80211_NUM_ACS)
1677 return -EINVAL;
1678
Jouni Malinen31888482008-10-30 16:59:24 +02001679 return 0;
1680}
1681
Johannes Bergf444de02010-05-05 15:25:02 +02001682static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1683{
1684 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001685 * You can only set the channel explicitly for WDS interfaces,
1686 * all others have their channel managed via their respective
1687 * "establish a connection" command (connect, join, ...)
1688 *
1689 * For AP/GO and mesh mode, the channel can be set with the
1690 * channel userspace API, but is only stored and passed to the
1691 * low-level driver when the AP starts or the mesh is joined.
1692 * This is for backward compatibility, userspace can also give
1693 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001694 *
1695 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001696 * whatever else is going on, so they have their own special
1697 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001698 */
1699 return !wdev ||
1700 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001701 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001702 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1703 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001704}
1705
Johannes Berg683b6d32012-11-08 21:25:48 +01001706static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1707 struct genl_info *info,
1708 struct cfg80211_chan_def *chandef)
1709{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301710 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001711
1712 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1713 return -EINVAL;
1714
1715 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1716
1717 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001718 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1719 chandef->center_freq1 = control_freq;
1720 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001721
1722 /* Primary channel not allowed */
1723 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1724 return -EINVAL;
1725
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001726 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1727 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001728
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001729 chantype = nla_get_u32(
1730 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1731
1732 switch (chantype) {
1733 case NL80211_CHAN_NO_HT:
1734 case NL80211_CHAN_HT20:
1735 case NL80211_CHAN_HT40PLUS:
1736 case NL80211_CHAN_HT40MINUS:
1737 cfg80211_chandef_create(chandef, chandef->chan,
1738 chantype);
1739 break;
1740 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001741 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001742 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001743 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1744 chandef->width =
1745 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1746 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1747 chandef->center_freq1 =
1748 nla_get_u32(
1749 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1750 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1751 chandef->center_freq2 =
1752 nla_get_u32(
1753 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1754 }
1755
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001756 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001757 return -EINVAL;
1758
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001759 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1760 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001761 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001762
Johannes Berg683b6d32012-11-08 21:25:48 +01001763 return 0;
1764}
1765
Johannes Bergf444de02010-05-05 15:25:02 +02001766static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1767 struct wireless_dev *wdev,
1768 struct genl_info *info)
1769{
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001771 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001772 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1773
1774 if (wdev)
1775 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001776
Johannes Bergf444de02010-05-05 15:25:02 +02001777 if (!nl80211_can_set_dev_channel(wdev))
1778 return -EOPNOTSUPP;
1779
Johannes Berg683b6d32012-11-08 21:25:48 +01001780 result = nl80211_parse_chandef(rdev, info, &chandef);
1781 if (result)
1782 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001783
1784 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001785 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001786 case NL80211_IFTYPE_AP:
1787 case NL80211_IFTYPE_P2P_GO:
1788 if (wdev->beacon_interval) {
1789 result = -EBUSY;
1790 break;
1791 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001792 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001793 result = -EINVAL;
1794 break;
1795 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001796 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001797 result = 0;
1798 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001799 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001800 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001801 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001802 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001803 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001804 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001805 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001806 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001807 }
1808 mutex_unlock(&rdev->devlist_mtx);
1809
1810 return result;
1811}
1812
1813static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1814{
Johannes Berg4c476992010-10-04 21:36:35 +02001815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1816 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001817
Johannes Berg4c476992010-10-04 21:36:35 +02001818 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001819}
1820
Bill Jordane8347eb2010-10-01 13:54:28 -04001821static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1822{
Johannes Berg43b19952010-10-07 13:10:30 +02001823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1824 struct net_device *dev = info->user_ptr[1];
1825 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001826 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001827
1828 if (!info->attrs[NL80211_ATTR_MAC])
1829 return -EINVAL;
1830
Johannes Berg43b19952010-10-07 13:10:30 +02001831 if (netif_running(dev))
1832 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001833
Johannes Berg43b19952010-10-07 13:10:30 +02001834 if (!rdev->ops->set_wds_peer)
1835 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001836
Johannes Berg43b19952010-10-07 13:10:30 +02001837 if (wdev->iftype != NL80211_IFTYPE_WDS)
1838 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001839
1840 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001841 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001842}
1843
1844
Johannes Berg55682962007-09-20 13:09:35 -04001845static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1846{
1847 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001848 struct net_device *netdev = NULL;
1849 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001850 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001851 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001852 u32 changed;
1853 u8 retry_short = 0, retry_long = 0;
1854 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001855 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001856
Johannes Bergf444de02010-05-05 15:25:02 +02001857 /*
1858 * Try to find the wiphy and netdev. Normally this
1859 * function shouldn't need the netdev, but this is
1860 * done for backward compatibility -- previously
1861 * setting the channel was done per wiphy, but now
1862 * it is per netdev. Previous userland like hostapd
1863 * also passed a netdev to set_wiphy, so that it is
1864 * possible to let that go to the right netdev!
1865 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001866 mutex_lock(&cfg80211_mutex);
1867
Johannes Bergf444de02010-05-05 15:25:02 +02001868 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1869 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1870
1871 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1872 if (netdev && netdev->ieee80211_ptr) {
1873 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1874 mutex_lock(&rdev->mtx);
1875 } else
1876 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001877 }
1878
Johannes Bergf444de02010-05-05 15:25:02 +02001879 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001880 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1881 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001882 if (IS_ERR(rdev)) {
1883 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001884 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001885 }
1886 wdev = NULL;
1887 netdev = NULL;
1888 result = 0;
1889
1890 mutex_lock(&rdev->mtx);
Johannes Berg71fe96b2012-10-24 10:04:58 +02001891 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001892 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001893
1894 /*
1895 * end workaround code, by now the rdev is available
1896 * and locked, and wdev may or may not be NULL.
1897 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001898
1899 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001900 result = cfg80211_dev_rename(
1901 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001902
1903 mutex_unlock(&cfg80211_mutex);
1904
1905 if (result)
1906 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001907
Jouni Malinen31888482008-10-30 16:59:24 +02001908 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1909 struct ieee80211_txq_params txq_params;
1910 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1911
1912 if (!rdev->ops->set_txq_params) {
1913 result = -EOPNOTSUPP;
1914 goto bad_res;
1915 }
1916
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001917 if (!netdev) {
1918 result = -EINVAL;
1919 goto bad_res;
1920 }
1921
Johannes Berg133a3ff2011-11-03 14:50:13 +01001922 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1923 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1924 result = -EINVAL;
1925 goto bad_res;
1926 }
1927
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001928 if (!netif_running(netdev)) {
1929 result = -ENETDOWN;
1930 goto bad_res;
1931 }
1932
Jouni Malinen31888482008-10-30 16:59:24 +02001933 nla_for_each_nested(nl_txq_params,
1934 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1935 rem_txq_params) {
1936 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1937 nla_data(nl_txq_params),
1938 nla_len(nl_txq_params),
1939 txq_params_policy);
1940 result = parse_txq_params(tb, &txq_params);
1941 if (result)
1942 goto bad_res;
1943
Hila Gonene35e4d22012-06-27 17:19:42 +03001944 result = rdev_set_txq_params(rdev, netdev,
1945 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001946 if (result)
1947 goto bad_res;
1948 }
1949 }
1950
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001951 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001952 result = __nl80211_set_channel(rdev,
1953 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1954 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001955 if (result)
1956 goto bad_res;
1957 }
1958
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001959 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001960 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001961 enum nl80211_tx_power_setting type;
1962 int idx, mbm = 0;
1963
Johannes Bergc8442112012-10-24 10:17:18 +02001964 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1965 txp_wdev = NULL;
1966
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001967 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001968 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001969 goto bad_res;
1970 }
1971
1972 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1973 type = nla_get_u32(info->attrs[idx]);
1974
1975 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1976 (type != NL80211_TX_POWER_AUTOMATIC)) {
1977 result = -EINVAL;
1978 goto bad_res;
1979 }
1980
1981 if (type != NL80211_TX_POWER_AUTOMATIC) {
1982 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1983 mbm = nla_get_u32(info->attrs[idx]);
1984 }
1985
Johannes Bergc8442112012-10-24 10:17:18 +02001986 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001987 if (result)
1988 goto bad_res;
1989 }
1990
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001991 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1992 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1993 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001994 if ((!rdev->wiphy.available_antennas_tx &&
1995 !rdev->wiphy.available_antennas_rx) ||
1996 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001997 result = -EOPNOTSUPP;
1998 goto bad_res;
1999 }
2000
2001 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2002 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2003
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002004 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002005 * available antenna masks, except for the "all" mask */
2006 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2007 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002008 result = -EINVAL;
2009 goto bad_res;
2010 }
2011
Bruno Randolf7f531e02010-12-16 11:30:22 +09002012 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2013 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002014
Hila Gonene35e4d22012-06-27 17:19:42 +03002015 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002016 if (result)
2017 goto bad_res;
2018 }
2019
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002020 changed = 0;
2021
2022 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2023 retry_short = nla_get_u8(
2024 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2025 if (retry_short == 0) {
2026 result = -EINVAL;
2027 goto bad_res;
2028 }
2029 changed |= WIPHY_PARAM_RETRY_SHORT;
2030 }
2031
2032 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2033 retry_long = nla_get_u8(
2034 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2035 if (retry_long == 0) {
2036 result = -EINVAL;
2037 goto bad_res;
2038 }
2039 changed |= WIPHY_PARAM_RETRY_LONG;
2040 }
2041
2042 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2043 frag_threshold = nla_get_u32(
2044 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2045 if (frag_threshold < 256) {
2046 result = -EINVAL;
2047 goto bad_res;
2048 }
2049 if (frag_threshold != (u32) -1) {
2050 /*
2051 * Fragments (apart from the last one) are required to
2052 * have even length. Make the fragmentation code
2053 * simpler by stripping LSB should someone try to use
2054 * odd threshold value.
2055 */
2056 frag_threshold &= ~0x1;
2057 }
2058 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2059 }
2060
2061 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2062 rts_threshold = nla_get_u32(
2063 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2064 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2065 }
2066
Lukáš Turek81077e82009-12-21 22:50:47 +01002067 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2068 coverage_class = nla_get_u8(
2069 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2070 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2071 }
2072
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002073 if (changed) {
2074 u8 old_retry_short, old_retry_long;
2075 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002076 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002077
2078 if (!rdev->ops->set_wiphy_params) {
2079 result = -EOPNOTSUPP;
2080 goto bad_res;
2081 }
2082
2083 old_retry_short = rdev->wiphy.retry_short;
2084 old_retry_long = rdev->wiphy.retry_long;
2085 old_frag_threshold = rdev->wiphy.frag_threshold;
2086 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002087 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002088
2089 if (changed & WIPHY_PARAM_RETRY_SHORT)
2090 rdev->wiphy.retry_short = retry_short;
2091 if (changed & WIPHY_PARAM_RETRY_LONG)
2092 rdev->wiphy.retry_long = retry_long;
2093 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2094 rdev->wiphy.frag_threshold = frag_threshold;
2095 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2096 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002097 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2098 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002099
Hila Gonene35e4d22012-06-27 17:19:42 +03002100 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002101 if (result) {
2102 rdev->wiphy.retry_short = old_retry_short;
2103 rdev->wiphy.retry_long = old_retry_long;
2104 rdev->wiphy.frag_threshold = old_frag_threshold;
2105 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002106 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002107 }
2108 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002109
Johannes Berg306d6112008-12-08 12:39:04 +01002110 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002111 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02002112 if (netdev)
2113 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002114 return result;
2115}
2116
Johannes Berg71bbc992012-06-15 15:30:18 +02002117static inline u64 wdev_id(struct wireless_dev *wdev)
2118{
2119 return (u64)wdev->identifier |
2120 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2121}
Johannes Berg55682962007-09-20 13:09:35 -04002122
Johannes Berg683b6d32012-11-08 21:25:48 +01002123static int nl80211_send_chandef(struct sk_buff *msg,
2124 struct cfg80211_chan_def *chandef)
2125{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002126 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002127
Johannes Berg683b6d32012-11-08 21:25:48 +01002128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2129 chandef->chan->center_freq))
2130 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002131 switch (chandef->width) {
2132 case NL80211_CHAN_WIDTH_20_NOHT:
2133 case NL80211_CHAN_WIDTH_20:
2134 case NL80211_CHAN_WIDTH_40:
2135 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2136 cfg80211_get_chandef_type(chandef)))
2137 return -ENOBUFS;
2138 break;
2139 default:
2140 break;
2141 }
2142 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2143 return -ENOBUFS;
2144 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2145 return -ENOBUFS;
2146 if (chandef->center_freq2 &&
2147 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002148 return -ENOBUFS;
2149 return 0;
2150}
2151
Eric W. Biederman15e47302012-09-07 20:12:54 +00002152static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002153 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002154 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002155{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002156 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002157 void *hdr;
2158
Eric W. Biederman15e47302012-09-07 20:12:54 +00002159 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002160 if (!hdr)
2161 return -1;
2162
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002163 if (dev &&
2164 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002165 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002166 goto nla_put_failure;
2167
2168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2169 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002170 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002171 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002172 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2173 rdev->devlist_generation ^
2174 (cfg80211_rdev_list_generation << 2)))
2175 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002176
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002177 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002178 int ret;
2179 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002180
Johannes Berg683b6d32012-11-08 21:25:48 +01002181 ret = rdev_get_channel(rdev, wdev, &chandef);
2182 if (ret == 0) {
2183 if (nl80211_send_chandef(msg, &chandef))
2184 goto nla_put_failure;
2185 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002186 }
2187
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002188 if (wdev->ssid_len) {
2189 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2190 goto nla_put_failure;
2191 }
2192
Johannes Berg55682962007-09-20 13:09:35 -04002193 return genlmsg_end(msg, hdr);
2194
2195 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002196 genlmsg_cancel(msg, hdr);
2197 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002198}
2199
2200static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2201{
2202 int wp_idx = 0;
2203 int if_idx = 0;
2204 int wp_start = cb->args[0];
2205 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002206 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002207 struct wireless_dev *wdev;
2208
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002209 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02002210 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2211 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002212 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002213 if (wp_idx < wp_start) {
2214 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002215 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002216 }
Johannes Berg55682962007-09-20 13:09:35 -04002217 if_idx = 0;
2218
Johannes Bergf5ea9122009-08-07 16:17:38 +02002219 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02002220 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002221 if (if_idx < if_start) {
2222 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002223 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002224 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002225 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002226 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002227 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02002228 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002229 goto out;
2230 }
2231 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002232 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02002233 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002234
2235 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002236 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002237 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002238 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04002239
2240 cb->args[0] = wp_idx;
2241 cb->args[1] = if_idx;
2242
2243 return skb->len;
2244}
2245
2246static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2247{
2248 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002249 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002250 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002251
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002253 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002254 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002255
Eric W. Biederman15e47302012-09-07 20:12:54 +00002256 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002257 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002258 nlmsg_free(msg);
2259 return -ENOBUFS;
2260 }
Johannes Berg55682962007-09-20 13:09:35 -04002261
Johannes Berg134e6372009-07-10 09:51:34 +00002262 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002263}
2264
Michael Wu66f7ac52008-01-31 19:48:22 +01002265static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2266 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2267 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2268 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2269 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2270 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2271};
2272
2273static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2274{
2275 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2276 int flag;
2277
2278 *mntrflags = 0;
2279
2280 if (!nla)
2281 return -EINVAL;
2282
2283 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2284 nla, mntr_flags_policy))
2285 return -EINVAL;
2286
2287 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2288 if (flags[flag])
2289 *mntrflags |= (1<<flag);
2290
2291 return 0;
2292}
2293
Johannes Berg9bc383d2009-11-19 11:55:19 +01002294static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002295 struct net_device *netdev, u8 use_4addr,
2296 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002297{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002298 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002299 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002300 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002301 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002302 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002303
2304 switch (iftype) {
2305 case NL80211_IFTYPE_AP_VLAN:
2306 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2307 return 0;
2308 break;
2309 case NL80211_IFTYPE_STATION:
2310 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2311 return 0;
2312 break;
2313 default:
2314 break;
2315 }
2316
2317 return -EOPNOTSUPP;
2318}
2319
Johannes Berg55682962007-09-20 13:09:35 -04002320static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2321{
Johannes Berg4c476992010-10-04 21:36:35 +02002322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002323 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002324 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002325 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002326 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002327 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002328 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002329
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002330 memset(&params, 0, sizeof(params));
2331
Johannes Berg04a773a2009-04-19 21:24:32 +02002332 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002333
Johannes Berg723b0382008-09-16 20:22:09 +02002334 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002335 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002336 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002337 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002338 if (ntype > NL80211_IFTYPE_MAX)
2339 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002340 }
2341
Johannes Berg92ffe052008-09-16 20:39:36 +02002342 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002343 struct wireless_dev *wdev = dev->ieee80211_ptr;
2344
Johannes Berg4c476992010-10-04 21:36:35 +02002345 if (ntype != NL80211_IFTYPE_MESH_POINT)
2346 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002347 if (netif_running(dev))
2348 return -EBUSY;
2349
2350 wdev_lock(wdev);
2351 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2352 IEEE80211_MAX_MESH_ID_LEN);
2353 wdev->mesh_id_up_len =
2354 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2355 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2356 wdev->mesh_id_up_len);
2357 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002358 }
2359
Felix Fietkau8b787642009-11-10 18:53:10 +01002360 if (info->attrs[NL80211_ATTR_4ADDR]) {
2361 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2362 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002363 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002364 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002365 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002366 } else {
2367 params.use_4addr = -1;
2368 }
2369
Johannes Berg92ffe052008-09-16 20:39:36 +02002370 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002371 if (ntype != NL80211_IFTYPE_MONITOR)
2372 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002373 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2374 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002375 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002376 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002377
2378 flags = &_flags;
2379 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002380 }
Johannes Berg3b858752009-03-12 09:55:09 +01002381
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002382 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002383 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002384 else
2385 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002386
Johannes Berg9bc383d2009-11-19 11:55:19 +01002387 if (!err && params.use_4addr != -1)
2388 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2389
Johannes Berg55682962007-09-20 13:09:35 -04002390 return err;
2391}
2392
2393static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2394{
Johannes Berg4c476992010-10-04 21:36:35 +02002395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002396 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002397 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002398 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002399 int err;
2400 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002401 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002402
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002403 memset(&params, 0, sizeof(params));
2404
Johannes Berg55682962007-09-20 13:09:35 -04002405 if (!info->attrs[NL80211_ATTR_IFNAME])
2406 return -EINVAL;
2407
2408 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2409 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2410 if (type > NL80211_IFTYPE_MAX)
2411 return -EINVAL;
2412 }
2413
Johannes Berg79c97e92009-07-07 03:56:12 +02002414 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002415 !(rdev->wiphy.interface_modes & (1 << type)))
2416 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002417
Arend van Spriel1c18f142013-01-08 10:17:27 +01002418 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2419 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2420 ETH_ALEN);
2421 if (!is_valid_ether_addr(params.macaddr))
2422 return -EADDRNOTAVAIL;
2423 }
2424
Johannes Berg9bc383d2009-11-19 11:55:19 +01002425 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002426 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002427 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002428 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002429 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002430 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002431
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2433 if (!msg)
2434 return -ENOMEM;
2435
Michael Wu66f7ac52008-01-31 19:48:22 +01002436 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2437 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2438 &flags);
Hila Gonene35e4d22012-06-27 17:19:42 +03002439 wdev = rdev_add_virtual_intf(rdev,
2440 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2441 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002442 if (IS_ERR(wdev)) {
2443 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002444 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002445 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002446
Johannes Berg98104fde2012-06-16 00:19:54 +02002447 switch (type) {
2448 case NL80211_IFTYPE_MESH_POINT:
2449 if (!info->attrs[NL80211_ATTR_MESH_ID])
2450 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002451 wdev_lock(wdev);
2452 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2453 IEEE80211_MAX_MESH_ID_LEN);
2454 wdev->mesh_id_up_len =
2455 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2456 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2457 wdev->mesh_id_up_len);
2458 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002459 break;
2460 case NL80211_IFTYPE_P2P_DEVICE:
2461 /*
2462 * P2P Device doesn't have a netdev, so doesn't go
2463 * through the netdev notifier and must be added here
2464 */
2465 mutex_init(&wdev->mtx);
2466 INIT_LIST_HEAD(&wdev->event_list);
2467 spin_lock_init(&wdev->event_lock);
2468 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2469 spin_lock_init(&wdev->mgmt_registrations_lock);
2470
2471 mutex_lock(&rdev->devlist_mtx);
2472 wdev->identifier = ++rdev->wdev_id;
2473 list_add_rcu(&wdev->list, &rdev->wdev_list);
2474 rdev->devlist_generation++;
2475 mutex_unlock(&rdev->devlist_mtx);
2476 break;
2477 default:
2478 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002479 }
2480
Eric W. Biederman15e47302012-09-07 20:12:54 +00002481 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002482 rdev, wdev) < 0) {
2483 nlmsg_free(msg);
2484 return -ENOBUFS;
2485 }
2486
2487 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002488}
2489
2490static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2491{
Johannes Berg4c476992010-10-04 21:36:35 +02002492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002493 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002494
Johannes Berg4c476992010-10-04 21:36:35 +02002495 if (!rdev->ops->del_virtual_intf)
2496 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002497
Johannes Berg84efbb82012-06-16 00:00:26 +02002498 /*
2499 * If we remove a wireless device without a netdev then clear
2500 * user_ptr[1] so that nl80211_post_doit won't dereference it
2501 * to check if it needs to do dev_put(). Otherwise it crashes
2502 * since the wdev has been freed, unlike with a netdev where
2503 * we need the dev_put() for the netdev to really be freed.
2504 */
2505 if (!wdev->netdev)
2506 info->user_ptr[1] = NULL;
2507
Hila Gonene35e4d22012-06-27 17:19:42 +03002508 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002509}
2510
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002511static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2512{
2513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2514 struct net_device *dev = info->user_ptr[1];
2515 u16 noack_map;
2516
2517 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2518 return -EINVAL;
2519
2520 if (!rdev->ops->set_noack_map)
2521 return -EOPNOTSUPP;
2522
2523 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2524
Hila Gonene35e4d22012-06-27 17:19:42 +03002525 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002526}
2527
Johannes Berg41ade002007-12-19 02:03:29 +01002528struct get_key_cookie {
2529 struct sk_buff *msg;
2530 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002531 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002532};
2533
2534static void get_key_callback(void *c, struct key_params *params)
2535{
Johannes Bergb9454e82009-07-08 13:29:08 +02002536 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002537 struct get_key_cookie *cookie = c;
2538
David S. Miller9360ffd2012-03-29 04:41:26 -04002539 if ((params->key &&
2540 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2541 params->key_len, params->key)) ||
2542 (params->seq &&
2543 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2544 params->seq_len, params->seq)) ||
2545 (params->cipher &&
2546 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2547 params->cipher)))
2548 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002549
Johannes Bergb9454e82009-07-08 13:29:08 +02002550 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2551 if (!key)
2552 goto nla_put_failure;
2553
David S. Miller9360ffd2012-03-29 04:41:26 -04002554 if ((params->key &&
2555 nla_put(cookie->msg, NL80211_KEY_DATA,
2556 params->key_len, params->key)) ||
2557 (params->seq &&
2558 nla_put(cookie->msg, NL80211_KEY_SEQ,
2559 params->seq_len, params->seq)) ||
2560 (params->cipher &&
2561 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2562 params->cipher)))
2563 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002564
David S. Miller9360ffd2012-03-29 04:41:26 -04002565 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2566 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002567
2568 nla_nest_end(cookie->msg, key);
2569
Johannes Berg41ade002007-12-19 02:03:29 +01002570 return;
2571 nla_put_failure:
2572 cookie->error = 1;
2573}
2574
2575static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2576{
Johannes Berg4c476992010-10-04 21:36:35 +02002577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002578 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002579 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002580 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002581 const u8 *mac_addr = NULL;
2582 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002583 struct get_key_cookie cookie = {
2584 .error = 0,
2585 };
2586 void *hdr;
2587 struct sk_buff *msg;
2588
2589 if (info->attrs[NL80211_ATTR_KEY_IDX])
2590 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2591
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002592 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002593 return -EINVAL;
2594
2595 if (info->attrs[NL80211_ATTR_MAC])
2596 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2597
Johannes Berge31b8212010-10-05 19:39:30 +02002598 pairwise = !!mac_addr;
2599 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2600 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2601 if (kt >= NUM_NL80211_KEYTYPES)
2602 return -EINVAL;
2603 if (kt != NL80211_KEYTYPE_GROUP &&
2604 kt != NL80211_KEYTYPE_PAIRWISE)
2605 return -EINVAL;
2606 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2607 }
2608
Johannes Berg4c476992010-10-04 21:36:35 +02002609 if (!rdev->ops->get_key)
2610 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002611
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002613 if (!msg)
2614 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002615
Eric W. Biederman15e47302012-09-07 20:12:54 +00002616 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002617 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002618 if (IS_ERR(hdr))
2619 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002620
2621 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002622 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002623
David S. Miller9360ffd2012-03-29 04:41:26 -04002624 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2625 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2626 goto nla_put_failure;
2627 if (mac_addr &&
2628 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2629 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002630
Johannes Berge31b8212010-10-05 19:39:30 +02002631 if (pairwise && mac_addr &&
2632 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2633 return -ENOENT;
2634
Hila Gonene35e4d22012-06-27 17:19:42 +03002635 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2636 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002637
2638 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002639 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002640
2641 if (cookie.error)
2642 goto nla_put_failure;
2643
2644 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002645 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002646
2647 nla_put_failure:
2648 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002649 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002650 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002651 return err;
2652}
2653
2654static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2655{
Johannes Berg4c476992010-10-04 21:36:35 +02002656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002657 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002658 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002659 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002660
Johannes Bergb9454e82009-07-08 13:29:08 +02002661 err = nl80211_parse_key(info, &key);
2662 if (err)
2663 return err;
2664
2665 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002666 return -EINVAL;
2667
Johannes Bergb9454e82009-07-08 13:29:08 +02002668 /* only support setting default key */
2669 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002670 return -EINVAL;
2671
Johannes Bergfffd0932009-07-08 14:22:54 +02002672 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002673
2674 if (key.def) {
2675 if (!rdev->ops->set_default_key) {
2676 err = -EOPNOTSUPP;
2677 goto out;
2678 }
2679
2680 err = nl80211_key_allowed(dev->ieee80211_ptr);
2681 if (err)
2682 goto out;
2683
Hila Gonene35e4d22012-06-27 17:19:42 +03002684 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002685 key.def_uni, key.def_multi);
2686
2687 if (err)
2688 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002689
Johannes Berg3d23e342009-09-29 23:27:28 +02002690#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002691 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002692#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002693 } else {
2694 if (key.def_uni || !key.def_multi) {
2695 err = -EINVAL;
2696 goto out;
2697 }
2698
2699 if (!rdev->ops->set_default_mgmt_key) {
2700 err = -EOPNOTSUPP;
2701 goto out;
2702 }
2703
2704 err = nl80211_key_allowed(dev->ieee80211_ptr);
2705 if (err)
2706 goto out;
2707
Hila Gonene35e4d22012-06-27 17:19:42 +03002708 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002709 if (err)
2710 goto out;
2711
2712#ifdef CONFIG_CFG80211_WEXT
2713 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2714#endif
2715 }
2716
2717 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002718 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002719
Johannes Berg41ade002007-12-19 02:03:29 +01002720 return err;
2721}
2722
2723static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2724{
Johannes Berg4c476992010-10-04 21:36:35 +02002725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002726 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002727 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002728 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002729 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002730
Johannes Bergb9454e82009-07-08 13:29:08 +02002731 err = nl80211_parse_key(info, &key);
2732 if (err)
2733 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002734
Johannes Bergb9454e82009-07-08 13:29:08 +02002735 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002736 return -EINVAL;
2737
Johannes Berg41ade002007-12-19 02:03:29 +01002738 if (info->attrs[NL80211_ATTR_MAC])
2739 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2740
Johannes Berge31b8212010-10-05 19:39:30 +02002741 if (key.type == -1) {
2742 if (mac_addr)
2743 key.type = NL80211_KEYTYPE_PAIRWISE;
2744 else
2745 key.type = NL80211_KEYTYPE_GROUP;
2746 }
2747
2748 /* for now */
2749 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2750 key.type != NL80211_KEYTYPE_GROUP)
2751 return -EINVAL;
2752
Johannes Berg4c476992010-10-04 21:36:35 +02002753 if (!rdev->ops->add_key)
2754 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002755
Johannes Berge31b8212010-10-05 19:39:30 +02002756 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2757 key.type == NL80211_KEYTYPE_PAIRWISE,
2758 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002759 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002760
2761 wdev_lock(dev->ieee80211_ptr);
2762 err = nl80211_key_allowed(dev->ieee80211_ptr);
2763 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002764 err = rdev_add_key(rdev, dev, key.idx,
2765 key.type == NL80211_KEYTYPE_PAIRWISE,
2766 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002767 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002768
Johannes Berg41ade002007-12-19 02:03:29 +01002769 return err;
2770}
2771
2772static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2773{
Johannes Berg4c476992010-10-04 21:36:35 +02002774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002775 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002776 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002777 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002778 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002779
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 err = nl80211_parse_key(info, &key);
2781 if (err)
2782 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002783
2784 if (info->attrs[NL80211_ATTR_MAC])
2785 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2786
Johannes Berge31b8212010-10-05 19:39:30 +02002787 if (key.type == -1) {
2788 if (mac_addr)
2789 key.type = NL80211_KEYTYPE_PAIRWISE;
2790 else
2791 key.type = NL80211_KEYTYPE_GROUP;
2792 }
2793
2794 /* for now */
2795 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2796 key.type != NL80211_KEYTYPE_GROUP)
2797 return -EINVAL;
2798
Johannes Berg4c476992010-10-04 21:36:35 +02002799 if (!rdev->ops->del_key)
2800 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002801
Johannes Bergfffd0932009-07-08 14:22:54 +02002802 wdev_lock(dev->ieee80211_ptr);
2803 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002804
2805 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2806 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2807 err = -ENOENT;
2808
Johannes Bergfffd0932009-07-08 14:22:54 +02002809 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002810 err = rdev_del_key(rdev, dev, key.idx,
2811 key.type == NL80211_KEYTYPE_PAIRWISE,
2812 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002813
Johannes Berg3d23e342009-09-29 23:27:28 +02002814#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002815 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002816 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002817 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002819 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2820 }
2821#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002822 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002823
Johannes Berg41ade002007-12-19 02:03:29 +01002824 return err;
2825}
2826
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302827/* This function returns an error or the number of nested attributes */
2828static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2829{
2830 struct nlattr *attr;
2831 int n_entries = 0, tmp;
2832
2833 nla_for_each_nested(attr, nl_attr, tmp) {
2834 if (nla_len(attr) != ETH_ALEN)
2835 return -EINVAL;
2836
2837 n_entries++;
2838 }
2839
2840 return n_entries;
2841}
2842
2843/*
2844 * This function parses ACL information and allocates memory for ACL data.
2845 * On successful return, the calling function is responsible to free the
2846 * ACL buffer returned by this function.
2847 */
2848static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2849 struct genl_info *info)
2850{
2851 enum nl80211_acl_policy acl_policy;
2852 struct nlattr *attr;
2853 struct cfg80211_acl_data *acl;
2854 int i = 0, n_entries, tmp;
2855
2856 if (!wiphy->max_acl_mac_addrs)
2857 return ERR_PTR(-EOPNOTSUPP);
2858
2859 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2860 return ERR_PTR(-EINVAL);
2861
2862 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2863 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2864 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2865 return ERR_PTR(-EINVAL);
2866
2867 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2868 return ERR_PTR(-EINVAL);
2869
2870 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2871 if (n_entries < 0)
2872 return ERR_PTR(n_entries);
2873
2874 if (n_entries > wiphy->max_acl_mac_addrs)
2875 return ERR_PTR(-ENOTSUPP);
2876
2877 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2878 GFP_KERNEL);
2879 if (!acl)
2880 return ERR_PTR(-ENOMEM);
2881
2882 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2883 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2884 i++;
2885 }
2886
2887 acl->n_acl_entries = n_entries;
2888 acl->acl_policy = acl_policy;
2889
2890 return acl;
2891}
2892
2893static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2894{
2895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2896 struct net_device *dev = info->user_ptr[1];
2897 struct cfg80211_acl_data *acl;
2898 int err;
2899
2900 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2901 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2902 return -EOPNOTSUPP;
2903
2904 if (!dev->ieee80211_ptr->beacon_interval)
2905 return -EINVAL;
2906
2907 acl = parse_acl_data(&rdev->wiphy, info);
2908 if (IS_ERR(acl))
2909 return PTR_ERR(acl);
2910
2911 err = rdev_set_mac_acl(rdev, dev, acl);
2912
2913 kfree(acl);
2914
2915 return err;
2916}
2917
Johannes Berg88600202012-02-13 15:17:18 +01002918static int nl80211_parse_beacon(struct genl_info *info,
2919 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002920{
Johannes Berg88600202012-02-13 15:17:18 +01002921 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002922
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002923 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2924 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2925 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2926 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002927 return -EINVAL;
2928
Johannes Berg88600202012-02-13 15:17:18 +01002929 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002930
Johannes Berged1b6cc2007-12-19 02:03:32 +01002931 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002932 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2933 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2934 if (!bcn->head_len)
2935 return -EINVAL;
2936 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002937 }
2938
2939 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002940 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2941 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002942 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002943 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002944 }
2945
Johannes Berg4c476992010-10-04 21:36:35 +02002946 if (!haveinfo)
2947 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002948
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002949 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002950 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2951 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002952 }
2953
2954 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002955 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002956 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002957 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002958 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2959 }
2960
2961 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002962 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002963 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002964 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002965 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2966 }
2967
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002968 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002969 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002970 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002971 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002972 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2973 }
2974
Johannes Berg88600202012-02-13 15:17:18 +01002975 return 0;
2976}
2977
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002978static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2979 struct cfg80211_ap_settings *params)
2980{
2981 struct wireless_dev *wdev;
2982 bool ret = false;
2983
2984 mutex_lock(&rdev->devlist_mtx);
2985
Johannes Berg89a54e42012-06-15 14:33:17 +02002986 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002987 if (wdev->iftype != NL80211_IFTYPE_AP &&
2988 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2989 continue;
2990
Johannes Berg683b6d32012-11-08 21:25:48 +01002991 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002992 continue;
2993
Johannes Berg683b6d32012-11-08 21:25:48 +01002994 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002995 ret = true;
2996 break;
2997 }
2998
2999 mutex_unlock(&rdev->devlist_mtx);
3000
3001 return ret;
3002}
3003
Jouni Malinene39e5b52012-09-30 19:29:39 +03003004static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3005 enum nl80211_auth_type auth_type,
3006 enum nl80211_commands cmd)
3007{
3008 if (auth_type > NL80211_AUTHTYPE_MAX)
3009 return false;
3010
3011 switch (cmd) {
3012 case NL80211_CMD_AUTHENTICATE:
3013 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3014 auth_type == NL80211_AUTHTYPE_SAE)
3015 return false;
3016 return true;
3017 case NL80211_CMD_CONNECT:
3018 case NL80211_CMD_START_AP:
3019 /* SAE not supported yet */
3020 if (auth_type == NL80211_AUTHTYPE_SAE)
3021 return false;
3022 return true;
3023 default:
3024 return false;
3025 }
3026}
3027
Johannes Berg88600202012-02-13 15:17:18 +01003028static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3029{
3030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3031 struct net_device *dev = info->user_ptr[1];
3032 struct wireless_dev *wdev = dev->ieee80211_ptr;
3033 struct cfg80211_ap_settings params;
3034 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003035 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003036
3037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3038 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3039 return -EOPNOTSUPP;
3040
3041 if (!rdev->ops->start_ap)
3042 return -EOPNOTSUPP;
3043
3044 if (wdev->beacon_interval)
3045 return -EALREADY;
3046
3047 memset(&params, 0, sizeof(params));
3048
3049 /* these are required for START_AP */
3050 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3051 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3052 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3053 return -EINVAL;
3054
3055 err = nl80211_parse_beacon(info, &params.beacon);
3056 if (err)
3057 return err;
3058
3059 params.beacon_interval =
3060 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3061 params.dtim_period =
3062 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3063
3064 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3065 if (err)
3066 return err;
3067
3068 /*
3069 * In theory, some of these attributes should be required here
3070 * but since they were not used when the command was originally
3071 * added, keep them optional for old user space programs to let
3072 * them continue to work with drivers that do not need the
3073 * additional information -- drivers must check!
3074 */
3075 if (info->attrs[NL80211_ATTR_SSID]) {
3076 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3077 params.ssid_len =
3078 nla_len(info->attrs[NL80211_ATTR_SSID]);
3079 if (params.ssid_len == 0 ||
3080 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3081 return -EINVAL;
3082 }
3083
3084 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3085 params.hidden_ssid = nla_get_u32(
3086 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3087 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3088 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3089 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3090 return -EINVAL;
3091 }
3092
3093 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3094
3095 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3096 params.auth_type = nla_get_u32(
3097 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003098 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3099 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003100 return -EINVAL;
3101 } else
3102 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3103
3104 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3105 NL80211_MAX_NR_CIPHER_SUITES);
3106 if (err)
3107 return err;
3108
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303109 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3110 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3111 return -EOPNOTSUPP;
3112 params.inactivity_timeout = nla_get_u16(
3113 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3114 }
3115
Johannes Berg53cabad2012-11-14 15:17:28 +01003116 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3117 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3118 return -EINVAL;
3119 params.p2p_ctwindow =
3120 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3121 if (params.p2p_ctwindow > 127)
3122 return -EINVAL;
3123 if (params.p2p_ctwindow != 0 &&
3124 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3125 return -EINVAL;
3126 }
3127
3128 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3129 u8 tmp;
3130
3131 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3132 return -EINVAL;
3133 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3134 if (tmp > 1)
3135 return -EINVAL;
3136 params.p2p_opp_ps = tmp;
3137 if (params.p2p_opp_ps != 0 &&
3138 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3139 return -EINVAL;
3140 }
3141
Johannes Bergaa430da2012-05-16 23:50:18 +02003142 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003143 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3144 if (err)
3145 return err;
3146 } else if (wdev->preset_chandef.chan) {
3147 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003148 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003149 return -EINVAL;
3150
Johannes Berg683b6d32012-11-08 21:25:48 +01003151 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003152 return -EINVAL;
3153
Simon Wunderlich04f39042013-02-08 18:16:19 +01003154 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3155 if (err < 0)
3156 return err;
3157 if (err) {
3158 radar_detect_width = BIT(params.chandef.width);
3159 params.radar_required = true;
3160 }
3161
Michal Kaziore4e32452012-06-29 12:47:08 +02003162 mutex_lock(&rdev->devlist_mtx);
Simon Wunderlich04f39042013-02-08 18:16:19 +01003163 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3164 params.chandef.chan,
3165 CHAN_MODE_SHARED,
3166 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003167 mutex_unlock(&rdev->devlist_mtx);
3168
3169 if (err)
3170 return err;
3171
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303172 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3173 params.acl = parse_acl_data(&rdev->wiphy, info);
3174 if (IS_ERR(params.acl))
3175 return PTR_ERR(params.acl);
3176 }
3177
Hila Gonene35e4d22012-06-27 17:19:42 +03003178 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003179 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003180 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003181 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003182 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003183 wdev->ssid_len = params.ssid_len;
3184 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003185 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303186
3187 kfree(params.acl);
3188
Johannes Berg56d18932011-05-09 18:41:15 +02003189 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003190}
3191
Johannes Berg88600202012-02-13 15:17:18 +01003192static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3193{
3194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3195 struct net_device *dev = info->user_ptr[1];
3196 struct wireless_dev *wdev = dev->ieee80211_ptr;
3197 struct cfg80211_beacon_data params;
3198 int err;
3199
3200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3202 return -EOPNOTSUPP;
3203
3204 if (!rdev->ops->change_beacon)
3205 return -EOPNOTSUPP;
3206
3207 if (!wdev->beacon_interval)
3208 return -EINVAL;
3209
3210 err = nl80211_parse_beacon(info, &params);
3211 if (err)
3212 return err;
3213
Hila Gonene35e4d22012-06-27 17:19:42 +03003214 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003215}
3216
3217static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003218{
Johannes Berg4c476992010-10-04 21:36:35 +02003219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3220 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003221
Michal Kazior60771782012-06-29 12:46:56 +02003222 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003223}
3224
Johannes Berg5727ef12007-12-19 02:03:34 +01003225static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3226 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3227 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3228 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003229 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003230 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003231 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003232};
3233
Johannes Bergeccb8e82009-05-11 21:57:56 +03003234static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003235 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003236 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003237{
3238 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003239 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003240 int flag;
3241
Johannes Bergeccb8e82009-05-11 21:57:56 +03003242 /*
3243 * Try parsing the new attribute first so userspace
3244 * can specify both for older kernels.
3245 */
3246 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3247 if (nla) {
3248 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003249
Johannes Bergeccb8e82009-05-11 21:57:56 +03003250 sta_flags = nla_data(nla);
3251 params->sta_flags_mask = sta_flags->mask;
3252 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003253 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003254 if ((params->sta_flags_mask |
3255 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3256 return -EINVAL;
3257 return 0;
3258 }
3259
3260 /* if present, parse the old attribute */
3261
3262 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003263 if (!nla)
3264 return 0;
3265
3266 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3267 nla, sta_flags_policy))
3268 return -EINVAL;
3269
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003270 /*
3271 * Only allow certain flags for interface types so that
3272 * other attributes are silently ignored. Remember that
3273 * this is backward compatibility code with old userspace
3274 * and shouldn't be hit in other cases anyway.
3275 */
3276 switch (iftype) {
3277 case NL80211_IFTYPE_AP:
3278 case NL80211_IFTYPE_AP_VLAN:
3279 case NL80211_IFTYPE_P2P_GO:
3280 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3281 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3282 BIT(NL80211_STA_FLAG_WME) |
3283 BIT(NL80211_STA_FLAG_MFP);
3284 break;
3285 case NL80211_IFTYPE_P2P_CLIENT:
3286 case NL80211_IFTYPE_STATION:
3287 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3288 BIT(NL80211_STA_FLAG_TDLS_PEER);
3289 break;
3290 case NL80211_IFTYPE_MESH_POINT:
3291 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3292 BIT(NL80211_STA_FLAG_MFP) |
3293 BIT(NL80211_STA_FLAG_AUTHORIZED);
3294 default:
3295 return -EINVAL;
3296 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003297
Johannes Berg3383b5a2012-05-10 20:14:43 +02003298 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3299 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003300 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003301
Johannes Berg3383b5a2012-05-10 20:14:43 +02003302 /* no longer support new API additions in old API */
3303 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3304 return -EINVAL;
3305 }
3306 }
3307
Johannes Berg5727ef12007-12-19 02:03:34 +01003308 return 0;
3309}
3310
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003311static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3312 int attr)
3313{
3314 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003315 u32 bitrate;
3316 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003317
3318 rate = nla_nest_start(msg, attr);
3319 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003320 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003321
3322 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3323 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003324 /* report 16-bit bitrate only if we can */
3325 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003326 if (bitrate > 0 &&
3327 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3328 return false;
3329 if (bitrate_compat > 0 &&
3330 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3331 return false;
3332
3333 if (info->flags & RATE_INFO_FLAGS_MCS) {
3334 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3335 return false;
3336 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3337 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3338 return false;
3339 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3340 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3341 return false;
3342 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3343 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3344 return false;
3345 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3346 return false;
3347 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3348 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3349 return false;
3350 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3351 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3352 return false;
3353 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3354 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3355 return false;
3356 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3357 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3358 return false;
3359 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3360 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3361 return false;
3362 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003363
3364 nla_nest_end(msg, rate);
3365 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003366}
3367
Eric W. Biederman15e47302012-09-07 20:12:54 +00003368static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003369 int flags,
3370 struct cfg80211_registered_device *rdev,
3371 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003372 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003373{
3374 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003375 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003376
Eric W. Biederman15e47302012-09-07 20:12:54 +00003377 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003378 if (!hdr)
3379 return -1;
3380
David S. Miller9360ffd2012-03-29 04:41:26 -04003381 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3382 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3383 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3384 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003385
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003386 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3387 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003388 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003389 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3390 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3391 sinfo->connected_time))
3392 goto nla_put_failure;
3393 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3394 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3395 sinfo->inactive_time))
3396 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003397 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3398 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003399 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003400 (u32)sinfo->rx_bytes))
3401 goto nla_put_failure;
3402 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3403 NL80211_STA_INFO_TX_BYTES64)) &&
3404 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3405 (u32)sinfo->tx_bytes))
3406 goto nla_put_failure;
3407 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3408 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003409 sinfo->rx_bytes))
3410 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003411 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3412 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003413 sinfo->tx_bytes))
3414 goto nla_put_failure;
3415 if ((sinfo->filled & STATION_INFO_LLID) &&
3416 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3417 goto nla_put_failure;
3418 if ((sinfo->filled & STATION_INFO_PLID) &&
3419 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3420 goto nla_put_failure;
3421 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3422 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3423 sinfo->plink_state))
3424 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003425 switch (rdev->wiphy.signal_type) {
3426 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003427 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3428 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3429 sinfo->signal))
3430 goto nla_put_failure;
3431 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3432 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3433 sinfo->signal_avg))
3434 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003435 break;
3436 default:
3437 break;
3438 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003439 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003440 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3441 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003442 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003443 }
3444 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3445 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3446 NL80211_STA_INFO_RX_BITRATE))
3447 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003448 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003449 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3450 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3451 sinfo->rx_packets))
3452 goto nla_put_failure;
3453 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3454 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3455 sinfo->tx_packets))
3456 goto nla_put_failure;
3457 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3458 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3459 sinfo->tx_retries))
3460 goto nla_put_failure;
3461 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3462 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3463 sinfo->tx_failed))
3464 goto nla_put_failure;
3465 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3466 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3467 sinfo->beacon_loss_count))
3468 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003469 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3470 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3471 sinfo->local_pm))
3472 goto nla_put_failure;
3473 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3474 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3475 sinfo->peer_pm))
3476 goto nla_put_failure;
3477 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3478 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3479 sinfo->nonpeer_pm))
3480 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003481 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3482 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3483 if (!bss_param)
3484 goto nla_put_failure;
3485
David S. Miller9360ffd2012-03-29 04:41:26 -04003486 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3487 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3488 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3489 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3490 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3491 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3492 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3493 sinfo->bss_param.dtim_period) ||
3494 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3495 sinfo->bss_param.beacon_interval))
3496 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003497
3498 nla_nest_end(msg, bss_param);
3499 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003500 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3501 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3502 sizeof(struct nl80211_sta_flag_update),
3503 &sinfo->sta_flags))
3504 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003505 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3506 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3507 sinfo->t_offset))
3508 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003509 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003510
David S. Miller9360ffd2012-03-29 04:41:26 -04003511 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3512 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3513 sinfo->assoc_req_ies))
3514 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003515
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003516 return genlmsg_end(msg, hdr);
3517
3518 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003519 genlmsg_cancel(msg, hdr);
3520 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003521}
3522
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003523static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003524 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003525{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526 struct station_info sinfo;
3527 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003528 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003529 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003530 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003531 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003532
Johannes Berg67748892010-10-04 21:14:06 +02003533 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3534 if (err)
3535 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003536
3537 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003538 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 goto out_err;
3540 }
3541
Johannes Bergbba95fe2008-07-29 13:22:51 +02003542 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003543 memset(&sinfo, 0, sizeof(sinfo));
Hila Gonene35e4d22012-06-27 17:19:42 +03003544 err = rdev_dump_station(dev, netdev, sta_idx,
3545 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003546 if (err == -ENOENT)
3547 break;
3548 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003549 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003550
3551 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003552 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04003554 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003555 &sinfo) < 0)
3556 goto out;
3557
3558 sta_idx++;
3559 }
3560
3561
3562 out:
3563 cb->args[1] = sta_idx;
3564 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003565 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003566 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003567
3568 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003570
Johannes Berg5727ef12007-12-19 02:03:34 +01003571static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3572{
Johannes Berg4c476992010-10-04 21:36:35 +02003573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3574 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003575 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003576 struct sk_buff *msg;
3577 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003578 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003579
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003580 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003581
3582 if (!info->attrs[NL80211_ATTR_MAC])
3583 return -EINVAL;
3584
3585 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3586
Johannes Berg4c476992010-10-04 21:36:35 +02003587 if (!rdev->ops->get_station)
3588 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589
Hila Gonene35e4d22012-06-27 17:19:42 +03003590 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003592 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003595 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003596 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003597
Eric W. Biederman15e47302012-09-07 20:12:54 +00003598 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003599 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003600 nlmsg_free(msg);
3601 return -ENOBUFS;
3602 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003603
Johannes Berg4c476992010-10-04 21:36:35 +02003604 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003605}
3606
Johannes Berg77ee7c82013-02-15 00:48:33 +01003607int cfg80211_check_station_change(struct wiphy *wiphy,
3608 struct station_parameters *params,
3609 enum cfg80211_station_type statype)
3610{
3611 if (params->listen_interval != -1)
3612 return -EINVAL;
3613 if (params->aid)
3614 return -EINVAL;
3615
3616 /* When you run into this, adjust the code below for the new flag */
3617 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3618
3619 switch (statype) {
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 Berg4c476992010-10-04 21:36:35 +02005051 if (rdev->scan_req)
5052 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01005053
5054 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005055 n_channels = validate_scan_freqs(
5056 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02005057 if (!n_channels)
5058 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005059 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005060 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005061 n_channels = 0;
5062
Johannes Berg2a519312009-02-10 21:25:55 +01005063 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5064 if (wiphy->bands[band])
5065 n_channels += wiphy->bands[band]->n_channels;
5066 }
5067
5068 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5069 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5070 n_ssids++;
5071
Johannes Berg4c476992010-10-04 21:36:35 +02005072 if (n_ssids > wiphy->max_scan_ssids)
5073 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005074
Jouni Malinen70692ad2009-02-16 19:39:13 +02005075 if (info->attrs[NL80211_ATTR_IE])
5076 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5077 else
5078 ie_len = 0;
5079
Johannes Berg4c476992010-10-04 21:36:35 +02005080 if (ie_len > wiphy->max_scan_ie_len)
5081 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02005082
Johannes Berg2a519312009-02-10 21:25:55 +01005083 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005084 + sizeof(*request->ssids) * n_ssids
5085 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005086 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005087 if (!request)
5088 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01005089
Johannes Berg2a519312009-02-10 21:25:55 +01005090 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005091 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005092 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005093 if (ie_len) {
5094 if (request->ssids)
5095 request->ie = (void *)(request->ssids + n_ssids);
5096 else
5097 request->ie = (void *)(request->channels + n_channels);
5098 }
Johannes Berg2a519312009-02-10 21:25:55 +01005099
Johannes Berg584991d2009-11-02 13:32:03 +01005100 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005101 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5102 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005103 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005104 struct ieee80211_channel *chan;
5105
5106 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5107
5108 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005109 err = -EINVAL;
5110 goto out_free;
5111 }
Johannes Berg584991d2009-11-02 13:32:03 +01005112
5113 /* ignore disabled channels */
5114 if (chan->flags & IEEE80211_CHAN_DISABLED)
5115 continue;
5116
5117 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005118 i++;
5119 }
5120 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005121 enum ieee80211_band band;
5122
Johannes Berg2a519312009-02-10 21:25:55 +01005123 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005124 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5125 int j;
5126 if (!wiphy->bands[band])
5127 continue;
5128 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005129 struct ieee80211_channel *chan;
5130
5131 chan = &wiphy->bands[band]->channels[j];
5132
5133 if (chan->flags & IEEE80211_CHAN_DISABLED)
5134 continue;
5135
5136 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005137 i++;
5138 }
5139 }
5140 }
5141
Johannes Berg584991d2009-11-02 13:32:03 +01005142 if (!i) {
5143 err = -EINVAL;
5144 goto out_free;
5145 }
5146
5147 request->n_channels = i;
5148
Johannes Berg2a519312009-02-10 21:25:55 +01005149 i = 0;
5150 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5151 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005152 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005153 err = -EINVAL;
5154 goto out_free;
5155 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005156 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005157 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005158 i++;
5159 }
5160 }
5161
Jouni Malinen70692ad2009-02-16 19:39:13 +02005162 if (info->attrs[NL80211_ATTR_IE]) {
5163 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005164 memcpy((void *)request->ie,
5165 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005166 request->ie_len);
5167 }
5168
Johannes Berg34850ab2011-07-18 18:08:35 +02005169 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005170 if (wiphy->bands[i])
5171 request->rates[i] =
5172 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005173
5174 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5175 nla_for_each_nested(attr,
5176 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5177 tmp) {
5178 enum ieee80211_band band = nla_type(attr);
5179
Dan Carpenter84404622011-07-29 11:52:18 +03005180 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005181 err = -EINVAL;
5182 goto out_free;
5183 }
5184 err = ieee80211_get_ratemask(wiphy->bands[band],
5185 nla_data(attr),
5186 nla_len(attr),
5187 &request->rates[band]);
5188 if (err)
5189 goto out_free;
5190 }
5191 }
5192
Sam Leffler46856bb2012-10-11 21:03:32 -07005193 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005194 request->flags = nla_get_u32(
5195 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005196 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5197 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5198 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5199 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005200 err = -EOPNOTSUPP;
5201 goto out_free;
5202 }
5203 }
Sam Lefflered4737712012-10-11 21:03:31 -07005204
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305205 request->no_cck =
5206 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5207
Johannes Bergfd014282012-06-18 19:17:03 +02005208 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005209 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005210 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005211
Johannes Berg79c97e92009-07-07 03:56:12 +02005212 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005213 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005214
Johannes Berg463d0182009-07-14 00:33:35 +02005215 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005216 nl80211_send_scan_start(rdev, wdev);
5217 if (wdev->netdev)
5218 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005219 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005220 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005221 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005222 kfree(request);
5223 }
Johannes Berg3b858752009-03-12 09:55:09 +01005224
Johannes Berg2a519312009-02-10 21:25:55 +01005225 return err;
5226}
5227
Luciano Coelho807f8a82011-05-11 17:09:35 +03005228static int nl80211_start_sched_scan(struct sk_buff *skb,
5229 struct genl_info *info)
5230{
5231 struct cfg80211_sched_scan_request *request;
5232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5233 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005234 struct nlattr *attr;
5235 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005236 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005237 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005238 enum ieee80211_band band;
5239 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005240 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005241
5242 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5243 !rdev->ops->sched_scan_start)
5244 return -EOPNOTSUPP;
5245
5246 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5247 return -EINVAL;
5248
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005249 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5250 return -EINVAL;
5251
5252 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5253 if (interval == 0)
5254 return -EINVAL;
5255
Luciano Coelho807f8a82011-05-11 17:09:35 +03005256 wiphy = &rdev->wiphy;
5257
5258 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5259 n_channels = validate_scan_freqs(
5260 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5261 if (!n_channels)
5262 return -EINVAL;
5263 } else {
5264 n_channels = 0;
5265
5266 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5267 if (wiphy->bands[band])
5268 n_channels += wiphy->bands[band]->n_channels;
5269 }
5270
5271 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5272 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5273 tmp)
5274 n_ssids++;
5275
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005276 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005277 return -EINVAL;
5278
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005279 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5280 nla_for_each_nested(attr,
5281 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5282 tmp)
5283 n_match_sets++;
5284
5285 if (n_match_sets > wiphy->max_match_sets)
5286 return -EINVAL;
5287
Luciano Coelho807f8a82011-05-11 17:09:35 +03005288 if (info->attrs[NL80211_ATTR_IE])
5289 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5290 else
5291 ie_len = 0;
5292
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005293 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005294 return -EINVAL;
5295
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005296 mutex_lock(&rdev->sched_scan_mtx);
5297
5298 if (rdev->sched_scan_req) {
5299 err = -EINPROGRESS;
5300 goto out;
5301 }
5302
Luciano Coelho807f8a82011-05-11 17:09:35 +03005303 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005304 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005305 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005306 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005307 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005308 if (!request) {
5309 err = -ENOMEM;
5310 goto out;
5311 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005312
5313 if (n_ssids)
5314 request->ssids = (void *)&request->channels[n_channels];
5315 request->n_ssids = n_ssids;
5316 if (ie_len) {
5317 if (request->ssids)
5318 request->ie = (void *)(request->ssids + n_ssids);
5319 else
5320 request->ie = (void *)(request->channels + n_channels);
5321 }
5322
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005323 if (n_match_sets) {
5324 if (request->ie)
5325 request->match_sets = (void *)(request->ie + ie_len);
5326 else if (request->ssids)
5327 request->match_sets =
5328 (void *)(request->ssids + n_ssids);
5329 else
5330 request->match_sets =
5331 (void *)(request->channels + n_channels);
5332 }
5333 request->n_match_sets = n_match_sets;
5334
Luciano Coelho807f8a82011-05-11 17:09:35 +03005335 i = 0;
5336 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5337 /* user specified, bail out if channel not found */
5338 nla_for_each_nested(attr,
5339 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5340 tmp) {
5341 struct ieee80211_channel *chan;
5342
5343 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5344
5345 if (!chan) {
5346 err = -EINVAL;
5347 goto out_free;
5348 }
5349
5350 /* ignore disabled channels */
5351 if (chan->flags & IEEE80211_CHAN_DISABLED)
5352 continue;
5353
5354 request->channels[i] = chan;
5355 i++;
5356 }
5357 } else {
5358 /* all channels */
5359 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5360 int j;
5361 if (!wiphy->bands[band])
5362 continue;
5363 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5364 struct ieee80211_channel *chan;
5365
5366 chan = &wiphy->bands[band]->channels[j];
5367
5368 if (chan->flags & IEEE80211_CHAN_DISABLED)
5369 continue;
5370
5371 request->channels[i] = chan;
5372 i++;
5373 }
5374 }
5375 }
5376
5377 if (!i) {
5378 err = -EINVAL;
5379 goto out_free;
5380 }
5381
5382 request->n_channels = i;
5383
5384 i = 0;
5385 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5386 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5387 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005388 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005389 err = -EINVAL;
5390 goto out_free;
5391 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005392 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005393 memcpy(request->ssids[i].ssid, nla_data(attr),
5394 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005395 i++;
5396 }
5397 }
5398
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005399 i = 0;
5400 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5401 nla_for_each_nested(attr,
5402 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5403 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005404 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005405
5406 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5407 nla_data(attr), nla_len(attr),
5408 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005409 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005410 if (ssid) {
5411 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5412 err = -EINVAL;
5413 goto out_free;
5414 }
5415 memcpy(request->match_sets[i].ssid.ssid,
5416 nla_data(ssid), nla_len(ssid));
5417 request->match_sets[i].ssid.ssid_len =
5418 nla_len(ssid);
5419 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005420 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5421 if (rssi)
5422 request->rssi_thold = nla_get_u32(rssi);
5423 else
5424 request->rssi_thold =
5425 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005426 i++;
5427 }
5428 }
5429
Luciano Coelho807f8a82011-05-11 17:09:35 +03005430 if (info->attrs[NL80211_ATTR_IE]) {
5431 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5432 memcpy((void *)request->ie,
5433 nla_data(info->attrs[NL80211_ATTR_IE]),
5434 request->ie_len);
5435 }
5436
Sam Leffler46856bb2012-10-11 21:03:32 -07005437 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005438 request->flags = nla_get_u32(
5439 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005440 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5441 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5442 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5443 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005444 err = -EOPNOTSUPP;
5445 goto out_free;
5446 }
5447 }
Sam Lefflered4737712012-10-11 21:03:31 -07005448
Luciano Coelho807f8a82011-05-11 17:09:35 +03005449 request->dev = dev;
5450 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005451 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005452 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005453
Hila Gonene35e4d22012-06-27 17:19:42 +03005454 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005455 if (!err) {
5456 rdev->sched_scan_req = request;
5457 nl80211_send_sched_scan(rdev, dev,
5458 NL80211_CMD_START_SCHED_SCAN);
5459 goto out;
5460 }
5461
5462out_free:
5463 kfree(request);
5464out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005465 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005466 return err;
5467}
5468
5469static int nl80211_stop_sched_scan(struct sk_buff *skb,
5470 struct genl_info *info)
5471{
5472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005473 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005474
5475 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5476 !rdev->ops->sched_scan_stop)
5477 return -EOPNOTSUPP;
5478
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005479 mutex_lock(&rdev->sched_scan_mtx);
5480 err = __cfg80211_stop_sched_scan(rdev, false);
5481 mutex_unlock(&rdev->sched_scan_mtx);
5482
5483 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005484}
5485
Simon Wunderlich04f39042013-02-08 18:16:19 +01005486static int nl80211_start_radar_detection(struct sk_buff *skb,
5487 struct genl_info *info)
5488{
5489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5490 struct net_device *dev = info->user_ptr[1];
5491 struct wireless_dev *wdev = dev->ieee80211_ptr;
5492 struct cfg80211_chan_def chandef;
5493 int err;
5494
5495 err = nl80211_parse_chandef(rdev, info, &chandef);
5496 if (err)
5497 return err;
5498
5499 if (wdev->cac_started)
5500 return -EBUSY;
5501
5502 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5503 if (err < 0)
5504 return err;
5505
5506 if (err == 0)
5507 return -EINVAL;
5508
5509 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5510 return -EINVAL;
5511
5512 if (!rdev->ops->start_radar_detection)
5513 return -EOPNOTSUPP;
5514
5515 mutex_lock(&rdev->devlist_mtx);
5516 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5517 chandef.chan, CHAN_MODE_SHARED,
5518 BIT(chandef.width));
5519 if (err)
5520 goto err_locked;
5521
5522 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5523 if (!err) {
5524 wdev->channel = chandef.chan;
5525 wdev->cac_started = true;
5526 wdev->cac_start_time = jiffies;
5527 }
5528err_locked:
5529 mutex_unlock(&rdev->devlist_mtx);
5530
5531 return err;
5532}
5533
Johannes Berg9720bb32011-06-21 09:45:33 +02005534static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5535 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005536 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005537 struct wireless_dev *wdev,
5538 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005539{
Johannes Berg48ab9052009-07-10 18:42:31 +02005540 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005541 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005542 void *hdr;
5543 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005544 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005545
5546 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005547
Eric W. Biederman15e47302012-09-07 20:12:54 +00005548 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005549 NL80211_CMD_NEW_SCAN_RESULTS);
5550 if (!hdr)
5551 return -1;
5552
Johannes Berg9720bb32011-06-21 09:45:33 +02005553 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5554
David S. Miller9360ffd2012-03-29 04:41:26 -04005555 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5556 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5557 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005558
5559 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5560 if (!bss)
5561 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005562 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005563 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005564 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005565
5566 rcu_read_lock();
5567 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005568 if (ies) {
5569 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5570 goto fail_unlock_rcu;
5571 tsf = true;
5572 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5573 ies->len, ies->data))
5574 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005575 }
5576 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005577 if (ies) {
5578 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5579 goto fail_unlock_rcu;
5580 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5581 ies->len, ies->data))
5582 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005583 }
5584 rcu_read_unlock();
5585
David S. Miller9360ffd2012-03-29 04:41:26 -04005586 if (res->beacon_interval &&
5587 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5588 goto nla_put_failure;
5589 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5590 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5591 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5592 jiffies_to_msecs(jiffies - intbss->ts)))
5593 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005594
Johannes Berg77965c92009-02-18 18:45:06 +01005595 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005596 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005597 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5598 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005599 break;
5600 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005601 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5602 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005603 break;
5604 default:
5605 break;
5606 }
5607
Johannes Berg48ab9052009-07-10 18:42:31 +02005608 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005609 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005610 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005611 if (intbss == wdev->current_bss &&
5612 nla_put_u32(msg, NL80211_BSS_STATUS,
5613 NL80211_BSS_STATUS_ASSOCIATED))
5614 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005615 break;
5616 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005617 if (intbss == wdev->current_bss &&
5618 nla_put_u32(msg, NL80211_BSS_STATUS,
5619 NL80211_BSS_STATUS_IBSS_JOINED))
5620 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005621 break;
5622 default:
5623 break;
5624 }
5625
Johannes Berg2a519312009-02-10 21:25:55 +01005626 nla_nest_end(msg, bss);
5627
5628 return genlmsg_end(msg, hdr);
5629
Johannes Berg8cef2c92013-02-05 16:54:31 +01005630 fail_unlock_rcu:
5631 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005632 nla_put_failure:
5633 genlmsg_cancel(msg, hdr);
5634 return -EMSGSIZE;
5635}
5636
5637static int nl80211_dump_scan(struct sk_buff *skb,
5638 struct netlink_callback *cb)
5639{
Johannes Berg48ab9052009-07-10 18:42:31 +02005640 struct cfg80211_registered_device *rdev;
5641 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01005642 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005643 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005644 int start = cb->args[1], idx = 0;
5645 int err;
5646
Johannes Berg67748892010-10-04 21:14:06 +02005647 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5648 if (err)
5649 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005650
Johannes Berg48ab9052009-07-10 18:42:31 +02005651 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01005652
Johannes Berg48ab9052009-07-10 18:42:31 +02005653 wdev_lock(wdev);
5654 spin_lock_bh(&rdev->bss_lock);
5655 cfg80211_bss_expire(rdev);
5656
Johannes Berg9720bb32011-06-21 09:45:33 +02005657 cb->seq = rdev->bss_generation;
5658
Johannes Berg48ab9052009-07-10 18:42:31 +02005659 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005660 if (++idx <= start)
5661 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005662 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005663 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005664 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005665 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005666 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005667 }
5668 }
5669
Johannes Berg48ab9052009-07-10 18:42:31 +02005670 spin_unlock_bh(&rdev->bss_lock);
5671 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005672
5673 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02005674 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005675
Johannes Berg67748892010-10-04 21:14:06 +02005676 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005677}
5678
Eric W. Biederman15e47302012-09-07 20:12:54 +00005679static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005680 int flags, struct net_device *dev,
5681 struct survey_info *survey)
5682{
5683 void *hdr;
5684 struct nlattr *infoattr;
5685
Eric W. Biederman15e47302012-09-07 20:12:54 +00005686 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005687 NL80211_CMD_NEW_SURVEY_RESULTS);
5688 if (!hdr)
5689 return -ENOMEM;
5690
David S. Miller9360ffd2012-03-29 04:41:26 -04005691 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5692 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005693
5694 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5695 if (!infoattr)
5696 goto nla_put_failure;
5697
David S. Miller9360ffd2012-03-29 04:41:26 -04005698 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5699 survey->channel->center_freq))
5700 goto nla_put_failure;
5701
5702 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5703 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5704 goto nla_put_failure;
5705 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5706 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5707 goto nla_put_failure;
5708 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5709 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5710 survey->channel_time))
5711 goto nla_put_failure;
5712 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5713 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5714 survey->channel_time_busy))
5715 goto nla_put_failure;
5716 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5717 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5718 survey->channel_time_ext_busy))
5719 goto nla_put_failure;
5720 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5721 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5722 survey->channel_time_rx))
5723 goto nla_put_failure;
5724 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5725 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5726 survey->channel_time_tx))
5727 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005728
5729 nla_nest_end(msg, infoattr);
5730
5731 return genlmsg_end(msg, hdr);
5732
5733 nla_put_failure:
5734 genlmsg_cancel(msg, hdr);
5735 return -EMSGSIZE;
5736}
5737
5738static int nl80211_dump_survey(struct sk_buff *skb,
5739 struct netlink_callback *cb)
5740{
5741 struct survey_info survey;
5742 struct cfg80211_registered_device *dev;
5743 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01005744 int survey_idx = cb->args[1];
5745 int res;
5746
Johannes Berg67748892010-10-04 21:14:06 +02005747 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5748 if (res)
5749 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005750
5751 if (!dev->ops->dump_survey) {
5752 res = -EOPNOTSUPP;
5753 goto out_err;
5754 }
5755
5756 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005757 struct ieee80211_channel *chan;
5758
Hila Gonene35e4d22012-06-27 17:19:42 +03005759 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005760 if (res == -ENOENT)
5761 break;
5762 if (res)
5763 goto out_err;
5764
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005765 /* Survey without a channel doesn't make sense */
5766 if (!survey.channel) {
5767 res = -EINVAL;
5768 goto out;
5769 }
5770
5771 chan = ieee80211_get_channel(&dev->wiphy,
5772 survey.channel->center_freq);
5773 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5774 survey_idx++;
5775 continue;
5776 }
5777
Holger Schurig61fa7132009-11-11 12:25:40 +01005778 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005779 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005780 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5781 netdev,
5782 &survey) < 0)
5783 goto out;
5784 survey_idx++;
5785 }
5786
5787 out:
5788 cb->args[1] = survey_idx;
5789 res = skb->len;
5790 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02005791 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005792 return res;
5793}
5794
Samuel Ortizb23aa672009-07-01 21:26:54 +02005795static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5796{
5797 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5798 NL80211_WPA_VERSION_2));
5799}
5800
Jouni Malinen636a5d32009-03-19 13:39:22 +02005801static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5802{
Johannes Berg4c476992010-10-04 21:36:35 +02005803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5804 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005805 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005806 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5807 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005808 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005809 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005810 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005811
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005812 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5813 return -EINVAL;
5814
5815 if (!info->attrs[NL80211_ATTR_MAC])
5816 return -EINVAL;
5817
Jouni Malinen17780922009-03-27 20:52:47 +02005818 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5819 return -EINVAL;
5820
Johannes Berg19957bb2009-07-02 17:20:43 +02005821 if (!info->attrs[NL80211_ATTR_SSID])
5822 return -EINVAL;
5823
5824 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5825 return -EINVAL;
5826
Johannes Bergfffd0932009-07-08 14:22:54 +02005827 err = nl80211_parse_key(info, &key);
5828 if (err)
5829 return err;
5830
5831 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005832 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5833 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005834 if (!key.p.key || !key.p.key_len)
5835 return -EINVAL;
5836 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5837 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5838 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5839 key.p.key_len != WLAN_KEY_LEN_WEP104))
5840 return -EINVAL;
5841 if (key.idx > 4)
5842 return -EINVAL;
5843 } else {
5844 key.p.key_len = 0;
5845 key.p.key = NULL;
5846 }
5847
Johannes Bergafea0b72010-08-10 09:46:42 +02005848 if (key.idx >= 0) {
5849 int i;
5850 bool ok = false;
5851 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5852 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5853 ok = true;
5854 break;
5855 }
5856 }
Johannes Berg4c476992010-10-04 21:36:35 +02005857 if (!ok)
5858 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005859 }
5860
Johannes Berg4c476992010-10-04 21:36:35 +02005861 if (!rdev->ops->auth)
5862 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005863
Johannes Berg074ac8d2010-09-16 14:58:22 +02005864 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005865 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5866 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005867
Johannes Berg19957bb2009-07-02 17:20:43 +02005868 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005869 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005870 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005871 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5872 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005873
Johannes Berg19957bb2009-07-02 17:20:43 +02005874 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5875 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5876
5877 if (info->attrs[NL80211_ATTR_IE]) {
5878 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5879 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5880 }
5881
5882 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005883 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005884 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005885
Jouni Malinene39e5b52012-09-30 19:29:39 +03005886 if (auth_type == NL80211_AUTHTYPE_SAE &&
5887 !info->attrs[NL80211_ATTR_SAE_DATA])
5888 return -EINVAL;
5889
5890 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5891 if (auth_type != NL80211_AUTHTYPE_SAE)
5892 return -EINVAL;
5893 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5894 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5895 /* need to include at least Auth Transaction and Status Code */
5896 if (sae_data_len < 4)
5897 return -EINVAL;
5898 }
5899
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005900 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5901
Johannes Berg95de8172012-01-20 13:55:25 +01005902 /*
5903 * Since we no longer track auth state, ignore
5904 * requests to only change local state.
5905 */
5906 if (local_state_change)
5907 return 0;
5908
Johannes Berg4c476992010-10-04 21:36:35 +02005909 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5910 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005911 key.p.key, key.p.key_len, key.idx,
5912 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005913}
5914
Johannes Bergc0692b82010-08-27 14:26:53 +03005915static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5916 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005917 struct cfg80211_crypto_settings *settings,
5918 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005919{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005920 memset(settings, 0, sizeof(*settings));
5921
Samuel Ortizb23aa672009-07-01 21:26:54 +02005922 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5923
Johannes Bergc0692b82010-08-27 14:26:53 +03005924 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5925 u16 proto;
5926 proto = nla_get_u16(
5927 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5928 settings->control_port_ethertype = cpu_to_be16(proto);
5929 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5930 proto != ETH_P_PAE)
5931 return -EINVAL;
5932 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5933 settings->control_port_no_encrypt = true;
5934 } else
5935 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5936
Samuel Ortizb23aa672009-07-01 21:26:54 +02005937 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5938 void *data;
5939 int len, i;
5940
5941 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5942 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5943 settings->n_ciphers_pairwise = len / sizeof(u32);
5944
5945 if (len % sizeof(u32))
5946 return -EINVAL;
5947
Johannes Berg3dc27d22009-07-02 21:36:37 +02005948 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005949 return -EINVAL;
5950
5951 memcpy(settings->ciphers_pairwise, data, len);
5952
5953 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005954 if (!cfg80211_supported_cipher_suite(
5955 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005956 settings->ciphers_pairwise[i]))
5957 return -EINVAL;
5958 }
5959
5960 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5961 settings->cipher_group =
5962 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005963 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5964 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005965 return -EINVAL;
5966 }
5967
5968 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5969 settings->wpa_versions =
5970 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5971 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5972 return -EINVAL;
5973 }
5974
5975 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5976 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005977 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005978
5979 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5980 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5981 settings->n_akm_suites = len / sizeof(u32);
5982
5983 if (len % sizeof(u32))
5984 return -EINVAL;
5985
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005986 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5987 return -EINVAL;
5988
Samuel Ortizb23aa672009-07-01 21:26:54 +02005989 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005990 }
5991
5992 return 0;
5993}
5994
Jouni Malinen636a5d32009-03-19 13:39:22 +02005995static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5996{
Johannes Berg4c476992010-10-04 21:36:35 +02005997 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5998 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02005999 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006000 struct cfg80211_assoc_request req = {};
6001 const u8 *bssid, *ssid;
6002 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006003
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006004 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6005 return -EINVAL;
6006
6007 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006008 !info->attrs[NL80211_ATTR_SSID] ||
6009 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006010 return -EINVAL;
6011
Johannes Berg4c476992010-10-04 21:36:35 +02006012 if (!rdev->ops->assoc)
6013 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006014
Johannes Berg074ac8d2010-09-16 14:58:22 +02006015 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006016 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6017 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006018
Johannes Berg19957bb2009-07-02 17:20:43 +02006019 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006020
Johannes Berg19957bb2009-07-02 17:20:43 +02006021 chan = ieee80211_get_channel(&rdev->wiphy,
6022 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006023 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6024 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006025
Johannes Berg19957bb2009-07-02 17:20:43 +02006026 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6027 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006028
6029 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006030 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6031 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006032 }
6033
Jouni Malinendc6382c2009-05-06 22:09:37 +03006034 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006035 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006036 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006037 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006038 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006039 else if (mfp != NL80211_MFP_NO)
6040 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006041 }
6042
Johannes Berg3e5d7642009-07-07 14:37:26 +02006043 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006044 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006045
Ben Greear7e7c8922011-11-18 11:31:59 -08006046 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006047 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006048
6049 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006050 memcpy(&req.ht_capa_mask,
6051 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6052 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006053
6054 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006055 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006056 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006057 memcpy(&req.ht_capa,
6058 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6059 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006060 }
6061
Johannes Bergee2aca32013-02-21 17:36:01 +01006062 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006063 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006064
6065 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006066 memcpy(&req.vht_capa_mask,
6067 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6068 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006069
6070 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006071 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006072 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006073 memcpy(&req.vht_capa,
6074 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6075 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006076 }
6077
Johannes Bergf62fab72013-02-21 20:09:09 +01006078 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006079 if (!err)
Johannes Bergf62fab72013-02-21 20:09:09 +01006080 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6081 ssid, ssid_len, &req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006082
Jouni Malinen636a5d32009-03-19 13:39:22 +02006083 return err;
6084}
6085
6086static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6087{
Johannes Berg4c476992010-10-04 21:36:35 +02006088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6089 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006090 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006091 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006092 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006093 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006094
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006095 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6096 return -EINVAL;
6097
6098 if (!info->attrs[NL80211_ATTR_MAC])
6099 return -EINVAL;
6100
6101 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6102 return -EINVAL;
6103
Johannes Berg4c476992010-10-04 21:36:35 +02006104 if (!rdev->ops->deauth)
6105 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006106
Johannes Berg074ac8d2010-09-16 14:58:22 +02006107 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006108 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6109 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006110
Johannes Berg19957bb2009-07-02 17:20:43 +02006111 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006112
Johannes Berg19957bb2009-07-02 17:20:43 +02006113 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6114 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006115 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006116 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006117 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006118
6119 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006120 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6121 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006122 }
6123
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006124 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6125
Johannes Berg4c476992010-10-04 21:36:35 +02006126 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6127 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006128}
6129
6130static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6131{
Johannes Berg4c476992010-10-04 21:36:35 +02006132 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6133 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006134 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006135 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006136 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006137 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006138
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006139 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6140 return -EINVAL;
6141
6142 if (!info->attrs[NL80211_ATTR_MAC])
6143 return -EINVAL;
6144
6145 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6146 return -EINVAL;
6147
Johannes Berg4c476992010-10-04 21:36:35 +02006148 if (!rdev->ops->disassoc)
6149 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006150
Johannes Berg074ac8d2010-09-16 14:58:22 +02006151 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006152 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6153 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006154
Johannes Berg19957bb2009-07-02 17:20:43 +02006155 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006156
Johannes Berg19957bb2009-07-02 17:20:43 +02006157 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6158 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006159 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006160 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006161 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006162
6163 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006164 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6165 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006166 }
6167
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006168 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6169
Johannes Berg4c476992010-10-04 21:36:35 +02006170 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6171 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006172}
6173
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006174static bool
6175nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6176 int mcast_rate[IEEE80211_NUM_BANDS],
6177 int rateval)
6178{
6179 struct wiphy *wiphy = &rdev->wiphy;
6180 bool found = false;
6181 int band, i;
6182
6183 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6184 struct ieee80211_supported_band *sband;
6185
6186 sband = wiphy->bands[band];
6187 if (!sband)
6188 continue;
6189
6190 for (i = 0; i < sband->n_bitrates; i++) {
6191 if (sband->bitrates[i].bitrate == rateval) {
6192 mcast_rate[band] = i + 1;
6193 found = true;
6194 break;
6195 }
6196 }
6197 }
6198
6199 return found;
6200}
6201
Johannes Berg04a773a2009-04-19 21:24:32 +02006202static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6203{
Johannes Berg4c476992010-10-04 21:36:35 +02006204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6205 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006206 struct cfg80211_ibss_params ibss;
6207 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006208 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006209 int err;
6210
Johannes Berg8e30bc52009-04-22 17:45:38 +02006211 memset(&ibss, 0, sizeof(ibss));
6212
Johannes Berg04a773a2009-04-19 21:24:32 +02006213 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6214 return -EINVAL;
6215
Johannes Berg683b6d32012-11-08 21:25:48 +01006216 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006217 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6218 return -EINVAL;
6219
Johannes Berg8e30bc52009-04-22 17:45:38 +02006220 ibss.beacon_interval = 100;
6221
6222 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6223 ibss.beacon_interval =
6224 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6225 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6226 return -EINVAL;
6227 }
6228
Johannes Berg4c476992010-10-04 21:36:35 +02006229 if (!rdev->ops->join_ibss)
6230 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006231
Johannes Berg4c476992010-10-04 21:36:35 +02006232 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6233 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006234
Johannes Berg79c97e92009-07-07 03:56:12 +02006235 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006236
Johannes Berg39193492011-09-16 13:45:25 +02006237 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006238 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006239
6240 if (!is_valid_ether_addr(ibss.bssid))
6241 return -EINVAL;
6242 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006243 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6244 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6245
6246 if (info->attrs[NL80211_ATTR_IE]) {
6247 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6248 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6249 }
6250
Johannes Berg683b6d32012-11-08 21:25:48 +01006251 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6252 if (err)
6253 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006254
Johannes Berg683b6d32012-11-08 21:25:48 +01006255 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006256 return -EINVAL;
6257
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006258 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6259 return -EINVAL;
6260 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6261 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006262 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006263
Johannes Berg04a773a2009-04-19 21:24:32 +02006264 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006265 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006266
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006267 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6268 u8 *rates =
6269 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6270 int n_rates =
6271 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6272 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006273 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006274
Johannes Berg34850ab2011-07-18 18:08:35 +02006275 err = ieee80211_get_ratemask(sband, rates, n_rates,
6276 &ibss.basic_rates);
6277 if (err)
6278 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006279 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006280
6281 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6282 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6283 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6284 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006285
Johannes Berg4c476992010-10-04 21:36:35 +02006286 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306287 bool no_ht = false;
6288
Johannes Berg4c476992010-10-04 21:36:35 +02006289 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306290 info->attrs[NL80211_ATTR_KEYS],
6291 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006292 if (IS_ERR(connkeys))
6293 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306294
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006295 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6296 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306297 kfree(connkeys);
6298 return -EINVAL;
6299 }
Johannes Berg4c476992010-10-04 21:36:35 +02006300 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006301
Antonio Quartulli267335d2012-01-31 20:25:47 +01006302 ibss.control_port =
6303 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6304
Johannes Berg4c476992010-10-04 21:36:35 +02006305 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006306 if (err)
6307 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006308 return err;
6309}
6310
6311static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6312{
Johannes Berg4c476992010-10-04 21:36:35 +02006313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6314 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006315
Johannes Berg4c476992010-10-04 21:36:35 +02006316 if (!rdev->ops->leave_ibss)
6317 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006318
Johannes Berg4c476992010-10-04 21:36:35 +02006319 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6320 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006321
Johannes Berg4c476992010-10-04 21:36:35 +02006322 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006323}
6324
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006325static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6326{
6327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6328 struct net_device *dev = info->user_ptr[1];
6329 int mcast_rate[IEEE80211_NUM_BANDS];
6330 u32 nla_rate;
6331 int err;
6332
6333 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6334 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6335 return -EOPNOTSUPP;
6336
6337 if (!rdev->ops->set_mcast_rate)
6338 return -EOPNOTSUPP;
6339
6340 memset(mcast_rate, 0, sizeof(mcast_rate));
6341
6342 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6343 return -EINVAL;
6344
6345 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6346 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6347 return -EINVAL;
6348
6349 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6350
6351 return err;
6352}
6353
6354
Johannes Bergaff89a92009-07-01 21:26:51 +02006355#ifdef CONFIG_NL80211_TESTMODE
6356static struct genl_multicast_group nl80211_testmode_mcgrp = {
6357 .name = "testmode",
6358};
6359
6360static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6361{
Johannes Berg4c476992010-10-04 21:36:35 +02006362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006363 int err;
6364
6365 if (!info->attrs[NL80211_ATTR_TESTDATA])
6366 return -EINVAL;
6367
Johannes Bergaff89a92009-07-01 21:26:51 +02006368 err = -EOPNOTSUPP;
6369 if (rdev->ops->testmode_cmd) {
6370 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006371 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006372 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6373 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6374 rdev->testmode_info = NULL;
6375 }
6376
Johannes Bergaff89a92009-07-01 21:26:51 +02006377 return err;
6378}
6379
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006380static int nl80211_testmode_dump(struct sk_buff *skb,
6381 struct netlink_callback *cb)
6382{
Johannes Berg00918d32011-12-13 17:22:05 +01006383 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006384 int err;
6385 long phy_idx;
6386 void *data = NULL;
6387 int data_len = 0;
6388
6389 if (cb->args[0]) {
6390 /*
6391 * 0 is a valid index, but not valid for args[0],
6392 * so we need to offset by 1.
6393 */
6394 phy_idx = cb->args[0] - 1;
6395 } else {
6396 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6397 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6398 nl80211_policy);
6399 if (err)
6400 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01006401
Johannes Berg2bd7e352012-06-15 14:23:16 +02006402 mutex_lock(&cfg80211_mutex);
6403 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6404 nl80211_fam.attrbuf);
6405 if (IS_ERR(rdev)) {
6406 mutex_unlock(&cfg80211_mutex);
6407 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01006408 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006409 phy_idx = rdev->wiphy_idx;
6410 rdev = NULL;
6411 mutex_unlock(&cfg80211_mutex);
6412
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006413 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6414 cb->args[1] =
6415 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6416 }
6417
6418 if (cb->args[1]) {
6419 data = nla_data((void *)cb->args[1]);
6420 data_len = nla_len((void *)cb->args[1]);
6421 }
6422
6423 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01006424 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6425 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006426 mutex_unlock(&cfg80211_mutex);
6427 return -ENOENT;
6428 }
Johannes Berg00918d32011-12-13 17:22:05 +01006429 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006430 mutex_unlock(&cfg80211_mutex);
6431
Johannes Berg00918d32011-12-13 17:22:05 +01006432 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006433 err = -EOPNOTSUPP;
6434 goto out_err;
6435 }
6436
6437 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006438 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006439 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6440 NL80211_CMD_TESTMODE);
6441 struct nlattr *tmdata;
6442
David S. Miller9360ffd2012-03-29 04:41:26 -04006443 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006444 genlmsg_cancel(skb, hdr);
6445 break;
6446 }
6447
6448 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6449 if (!tmdata) {
6450 genlmsg_cancel(skb, hdr);
6451 break;
6452 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006453 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006454 nla_nest_end(skb, tmdata);
6455
6456 if (err == -ENOBUFS || err == -ENOENT) {
6457 genlmsg_cancel(skb, hdr);
6458 break;
6459 } else if (err) {
6460 genlmsg_cancel(skb, hdr);
6461 goto out_err;
6462 }
6463
6464 genlmsg_end(skb, hdr);
6465 }
6466
6467 err = skb->len;
6468 /* see above */
6469 cb->args[0] = phy_idx + 1;
6470 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01006471 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006472 return err;
6473}
6474
Johannes Bergaff89a92009-07-01 21:26:51 +02006475static struct sk_buff *
6476__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006477 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006478{
6479 struct sk_buff *skb;
6480 void *hdr;
6481 struct nlattr *data;
6482
6483 skb = nlmsg_new(approxlen + 100, gfp);
6484 if (!skb)
6485 return NULL;
6486
Eric W. Biederman15e47302012-09-07 20:12:54 +00006487 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006488 if (!hdr) {
6489 kfree_skb(skb);
6490 return NULL;
6491 }
6492
David S. Miller9360ffd2012-03-29 04:41:26 -04006493 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6494 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006495 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6496
6497 ((void **)skb->cb)[0] = rdev;
6498 ((void **)skb->cb)[1] = hdr;
6499 ((void **)skb->cb)[2] = data;
6500
6501 return skb;
6502
6503 nla_put_failure:
6504 kfree_skb(skb);
6505 return NULL;
6506}
6507
6508struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6509 int approxlen)
6510{
6511 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6512
6513 if (WARN_ON(!rdev->testmode_info))
6514 return NULL;
6515
6516 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006517 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006518 rdev->testmode_info->snd_seq,
6519 GFP_KERNEL);
6520}
6521EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6522
6523int cfg80211_testmode_reply(struct sk_buff *skb)
6524{
6525 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6526 void *hdr = ((void **)skb->cb)[1];
6527 struct nlattr *data = ((void **)skb->cb)[2];
6528
6529 if (WARN_ON(!rdev->testmode_info)) {
6530 kfree_skb(skb);
6531 return -EINVAL;
6532 }
6533
6534 nla_nest_end(skb, data);
6535 genlmsg_end(skb, hdr);
6536 return genlmsg_reply(skb, rdev->testmode_info);
6537}
6538EXPORT_SYMBOL(cfg80211_testmode_reply);
6539
6540struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6541 int approxlen, gfp_t gfp)
6542{
6543 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6544
6545 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6546}
6547EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6548
6549void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6550{
6551 void *hdr = ((void **)skb->cb)[1];
6552 struct nlattr *data = ((void **)skb->cb)[2];
6553
6554 nla_nest_end(skb, data);
6555 genlmsg_end(skb, hdr);
6556 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6557}
6558EXPORT_SYMBOL(cfg80211_testmode_event);
6559#endif
6560
Samuel Ortizb23aa672009-07-01 21:26:54 +02006561static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6562{
Johannes Berg4c476992010-10-04 21:36:35 +02006563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6564 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006565 struct cfg80211_connect_params connect;
6566 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006567 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006568 int err;
6569
6570 memset(&connect, 0, sizeof(connect));
6571
6572 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6573 return -EINVAL;
6574
6575 if (!info->attrs[NL80211_ATTR_SSID] ||
6576 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6577 return -EINVAL;
6578
6579 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6580 connect.auth_type =
6581 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006582 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6583 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006584 return -EINVAL;
6585 } else
6586 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6587
6588 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6589
Johannes Bergc0692b82010-08-27 14:26:53 +03006590 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006591 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006592 if (err)
6593 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006594
Johannes Berg074ac8d2010-09-16 14:58:22 +02006595 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006596 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6597 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006598
Johannes Berg79c97e92009-07-07 03:56:12 +02006599 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006600
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306601 connect.bg_scan_period = -1;
6602 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6603 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6604 connect.bg_scan_period =
6605 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6606 }
6607
Samuel Ortizb23aa672009-07-01 21:26:54 +02006608 if (info->attrs[NL80211_ATTR_MAC])
6609 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6610 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6611 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6612
6613 if (info->attrs[NL80211_ATTR_IE]) {
6614 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6615 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6616 }
6617
Jouni Malinencee00a92013-01-15 17:15:57 +02006618 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6619 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6620 if (connect.mfp != NL80211_MFP_REQUIRED &&
6621 connect.mfp != NL80211_MFP_NO)
6622 return -EINVAL;
6623 } else {
6624 connect.mfp = NL80211_MFP_NO;
6625 }
6626
Samuel Ortizb23aa672009-07-01 21:26:54 +02006627 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6628 connect.channel =
6629 ieee80211_get_channel(wiphy,
6630 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6631 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006632 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6633 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006634 }
6635
Johannes Bergfffd0932009-07-08 14:22:54 +02006636 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6637 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306638 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006639 if (IS_ERR(connkeys))
6640 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006641 }
6642
Ben Greear7e7c8922011-11-18 11:31:59 -08006643 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6644 connect.flags |= ASSOC_REQ_DISABLE_HT;
6645
6646 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6647 memcpy(&connect.ht_capa_mask,
6648 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6649 sizeof(connect.ht_capa_mask));
6650
6651 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006652 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6653 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006654 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006655 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006656 memcpy(&connect.ht_capa,
6657 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6658 sizeof(connect.ht_capa));
6659 }
6660
Johannes Bergee2aca32013-02-21 17:36:01 +01006661 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6662 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6663
6664 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6665 memcpy(&connect.vht_capa_mask,
6666 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6667 sizeof(connect.vht_capa_mask));
6668
6669 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6670 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6671 kfree(connkeys);
6672 return -EINVAL;
6673 }
6674 memcpy(&connect.vht_capa,
6675 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6676 sizeof(connect.vht_capa));
6677 }
6678
Johannes Bergfffd0932009-07-08 14:22:54 +02006679 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006680 if (err)
6681 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006682 return err;
6683}
6684
6685static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6686{
Johannes Berg4c476992010-10-04 21:36:35 +02006687 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6688 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006689 u16 reason;
6690
6691 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6692 reason = WLAN_REASON_DEAUTH_LEAVING;
6693 else
6694 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6695
6696 if (reason == 0)
6697 return -EINVAL;
6698
Johannes Berg074ac8d2010-09-16 14:58:22 +02006699 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006700 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6701 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006702
Johannes Berg4c476992010-10-04 21:36:35 +02006703 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006704}
6705
Johannes Berg463d0182009-07-14 00:33:35 +02006706static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6707{
Johannes Berg4c476992010-10-04 21:36:35 +02006708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006709 struct net *net;
6710 int err;
6711 u32 pid;
6712
6713 if (!info->attrs[NL80211_ATTR_PID])
6714 return -EINVAL;
6715
6716 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6717
Johannes Berg463d0182009-07-14 00:33:35 +02006718 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006719 if (IS_ERR(net))
6720 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006721
6722 err = 0;
6723
6724 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006725 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6726 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006727
Johannes Berg463d0182009-07-14 00:33:35 +02006728 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006729 return err;
6730}
6731
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006732static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6733{
Johannes Berg4c476992010-10-04 21:36:35 +02006734 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006735 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6736 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006737 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006738 struct cfg80211_pmksa pmksa;
6739
6740 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6741
6742 if (!info->attrs[NL80211_ATTR_MAC])
6743 return -EINVAL;
6744
6745 if (!info->attrs[NL80211_ATTR_PMKID])
6746 return -EINVAL;
6747
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006748 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6749 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6750
Johannes Berg074ac8d2010-09-16 14:58:22 +02006751 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006752 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6753 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006754
6755 switch (info->genlhdr->cmd) {
6756 case NL80211_CMD_SET_PMKSA:
6757 rdev_ops = rdev->ops->set_pmksa;
6758 break;
6759 case NL80211_CMD_DEL_PMKSA:
6760 rdev_ops = rdev->ops->del_pmksa;
6761 break;
6762 default:
6763 WARN_ON(1);
6764 break;
6765 }
6766
Johannes Berg4c476992010-10-04 21:36:35 +02006767 if (!rdev_ops)
6768 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006769
Johannes Berg4c476992010-10-04 21:36:35 +02006770 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006771}
6772
6773static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6774{
Johannes Berg4c476992010-10-04 21:36:35 +02006775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6776 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006777
Johannes Berg074ac8d2010-09-16 14:58:22 +02006778 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006779 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6780 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006781
Johannes Berg4c476992010-10-04 21:36:35 +02006782 if (!rdev->ops->flush_pmksa)
6783 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006784
Hila Gonene35e4d22012-06-27 17:19:42 +03006785 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006786}
6787
Arik Nemtsov109086c2011-09-28 14:12:50 +03006788static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6789{
6790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6791 struct net_device *dev = info->user_ptr[1];
6792 u8 action_code, dialog_token;
6793 u16 status_code;
6794 u8 *peer;
6795
6796 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6797 !rdev->ops->tdls_mgmt)
6798 return -EOPNOTSUPP;
6799
6800 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6801 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6802 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6803 !info->attrs[NL80211_ATTR_IE] ||
6804 !info->attrs[NL80211_ATTR_MAC])
6805 return -EINVAL;
6806
6807 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6808 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6809 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6810 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6811
Hila Gonene35e4d22012-06-27 17:19:42 +03006812 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6813 dialog_token, status_code,
6814 nla_data(info->attrs[NL80211_ATTR_IE]),
6815 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006816}
6817
6818static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6819{
6820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6821 struct net_device *dev = info->user_ptr[1];
6822 enum nl80211_tdls_operation operation;
6823 u8 *peer;
6824
6825 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6826 !rdev->ops->tdls_oper)
6827 return -EOPNOTSUPP;
6828
6829 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6830 !info->attrs[NL80211_ATTR_MAC])
6831 return -EINVAL;
6832
6833 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6834 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6835
Hila Gonene35e4d22012-06-27 17:19:42 +03006836 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006837}
6838
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006839static int nl80211_remain_on_channel(struct sk_buff *skb,
6840 struct genl_info *info)
6841{
Johannes Berg4c476992010-10-04 21:36:35 +02006842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006843 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006844 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006845 struct sk_buff *msg;
6846 void *hdr;
6847 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006848 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006849 int err;
6850
6851 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6852 !info->attrs[NL80211_ATTR_DURATION])
6853 return -EINVAL;
6854
6855 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6856
Johannes Berg7c4ef712011-11-18 15:33:48 +01006857 if (!rdev->ops->remain_on_channel ||
6858 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006859 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006860
Johannes Bergebf348f2012-06-01 12:50:54 +02006861 /*
6862 * We should be on that channel for at least a minimum amount of
6863 * time (10ms) but no longer than the driver supports.
6864 */
6865 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6866 duration > rdev->wiphy.max_remain_on_channel_duration)
6867 return -EINVAL;
6868
Johannes Berg683b6d32012-11-08 21:25:48 +01006869 err = nl80211_parse_chandef(rdev, info, &chandef);
6870 if (err)
6871 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006872
6873 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006874 if (!msg)
6875 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006876
Eric W. Biederman15e47302012-09-07 20:12:54 +00006877 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006878 NL80211_CMD_REMAIN_ON_CHANNEL);
6879
6880 if (IS_ERR(hdr)) {
6881 err = PTR_ERR(hdr);
6882 goto free_msg;
6883 }
6884
Johannes Berg683b6d32012-11-08 21:25:48 +01006885 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6886 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006887
6888 if (err)
6889 goto free_msg;
6890
David S. Miller9360ffd2012-03-29 04:41:26 -04006891 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6892 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006893
6894 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006895
6896 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006897
6898 nla_put_failure:
6899 err = -ENOBUFS;
6900 free_msg:
6901 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006902 return err;
6903}
6904
6905static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6906 struct genl_info *info)
6907{
Johannes Berg4c476992010-10-04 21:36:35 +02006908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006909 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006910 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006911
6912 if (!info->attrs[NL80211_ATTR_COOKIE])
6913 return -EINVAL;
6914
Johannes Berg4c476992010-10-04 21:36:35 +02006915 if (!rdev->ops->cancel_remain_on_channel)
6916 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006917
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006918 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6919
Hila Gonene35e4d22012-06-27 17:19:42 +03006920 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006921}
6922
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006923static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6924 u8 *rates, u8 rates_len)
6925{
6926 u8 i;
6927 u32 mask = 0;
6928
6929 for (i = 0; i < rates_len; i++) {
6930 int rate = (rates[i] & 0x7f) * 5;
6931 int ridx;
6932 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6933 struct ieee80211_rate *srate =
6934 &sband->bitrates[ridx];
6935 if (rate == srate->bitrate) {
6936 mask |= 1 << ridx;
6937 break;
6938 }
6939 }
6940 if (ridx == sband->n_bitrates)
6941 return 0; /* rate not found */
6942 }
6943
6944 return mask;
6945}
6946
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006947static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6948 u8 *rates, u8 rates_len,
6949 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6950{
6951 u8 i;
6952
6953 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6954
6955 for (i = 0; i < rates_len; i++) {
6956 int ridx, rbit;
6957
6958 ridx = rates[i] / 8;
6959 rbit = BIT(rates[i] % 8);
6960
6961 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006962 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006963 return false;
6964
6965 /* check availability */
6966 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6967 mcs[ridx] |= rbit;
6968 else
6969 return false;
6970 }
6971
6972 return true;
6973}
6974
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006975static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006976 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6977 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006978 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6979 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006980};
6981
6982static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6983 struct genl_info *info)
6984{
6985 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006986 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006987 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006988 int rem, i;
6989 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006990 struct nlattr *tx_rates;
6991 struct ieee80211_supported_band *sband;
6992
6993 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6994 return -EINVAL;
6995
Johannes Berg4c476992010-10-04 21:36:35 +02006996 if (!rdev->ops->set_bitrate_mask)
6997 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006998
6999 memset(&mask, 0, sizeof(mask));
7000 /* Default to all rates enabled */
7001 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7002 sband = rdev->wiphy.bands[i];
7003 mask.control[i].legacy =
7004 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007005 if (sband)
7006 memcpy(mask.control[i].mcs,
7007 sband->ht_cap.mcs.rx_mask,
7008 sizeof(mask.control[i].mcs));
7009 else
7010 memset(mask.control[i].mcs, 0,
7011 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007012 }
7013
7014 /*
7015 * The nested attribute uses enum nl80211_band as the index. This maps
7016 * directly to the enum ieee80211_band values used in cfg80211.
7017 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007018 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007019 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7020 {
7021 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007022 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7023 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007024 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007025 if (sband == NULL)
7026 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007027 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7028 nla_len(tx_rates), nl80211_txattr_policy);
7029 if (tb[NL80211_TXRATE_LEGACY]) {
7030 mask.control[band].legacy = rateset_to_mask(
7031 sband,
7032 nla_data(tb[NL80211_TXRATE_LEGACY]),
7033 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307034 if ((mask.control[band].legacy == 0) &&
7035 nla_len(tb[NL80211_TXRATE_LEGACY]))
7036 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007037 }
7038 if (tb[NL80211_TXRATE_MCS]) {
7039 if (!ht_rateset_to_mask(
7040 sband,
7041 nla_data(tb[NL80211_TXRATE_MCS]),
7042 nla_len(tb[NL80211_TXRATE_MCS]),
7043 mask.control[band].mcs))
7044 return -EINVAL;
7045 }
7046
7047 if (mask.control[band].legacy == 0) {
7048 /* don't allow empty legacy rates if HT
7049 * is not even supported. */
7050 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7051 return -EINVAL;
7052
7053 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7054 if (mask.control[band].mcs[i])
7055 break;
7056
7057 /* legacy and mcs rates may not be both empty */
7058 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007059 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007060 }
7061 }
7062
Hila Gonene35e4d22012-06-27 17:19:42 +03007063 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007064}
7065
Johannes Berg2e161f72010-08-12 15:38:38 +02007066static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007067{
Johannes Berg4c476992010-10-04 21:36:35 +02007068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007069 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007070 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007071
7072 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7073 return -EINVAL;
7074
Johannes Berg2e161f72010-08-12 15:38:38 +02007075 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7076 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007077
Johannes Berg71bbc992012-06-15 15:30:18 +02007078 switch (wdev->iftype) {
7079 case NL80211_IFTYPE_STATION:
7080 case NL80211_IFTYPE_ADHOC:
7081 case NL80211_IFTYPE_P2P_CLIENT:
7082 case NL80211_IFTYPE_AP:
7083 case NL80211_IFTYPE_AP_VLAN:
7084 case NL80211_IFTYPE_MESH_POINT:
7085 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007086 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007087 break;
7088 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007089 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007090 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007091
7092 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007093 if (!rdev->ops->mgmt_tx)
7094 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007095
Eric W. Biederman15e47302012-09-07 20:12:54 +00007096 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007097 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7098 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007099}
7100
Johannes Berg2e161f72010-08-12 15:38:38 +02007101static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007102{
Johannes Berg4c476992010-10-04 21:36:35 +02007103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007104 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007105 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007106 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007107 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007108 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007109 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007110 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007111 bool offchan, no_cck, dont_wait_for_ack;
7112
7113 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007114
Johannes Berg683b6d32012-11-08 21:25:48 +01007115 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007116 return -EINVAL;
7117
Johannes Berg4c476992010-10-04 21:36:35 +02007118 if (!rdev->ops->mgmt_tx)
7119 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007120
Johannes Berg71bbc992012-06-15 15:30:18 +02007121 switch (wdev->iftype) {
7122 case NL80211_IFTYPE_STATION:
7123 case NL80211_IFTYPE_ADHOC:
7124 case NL80211_IFTYPE_P2P_CLIENT:
7125 case NL80211_IFTYPE_AP:
7126 case NL80211_IFTYPE_AP_VLAN:
7127 case NL80211_IFTYPE_MESH_POINT:
7128 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007129 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007130 break;
7131 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007132 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007133 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007134
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007135 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007136 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007137 return -EINVAL;
7138 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007139
7140 /*
7141 * We should wait on the channel for at least a minimum amount
7142 * of time (10ms) but no longer than the driver supports.
7143 */
7144 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7145 wait > rdev->wiphy.max_remain_on_channel_duration)
7146 return -EINVAL;
7147
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007148 }
7149
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007150 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7151
Johannes Berg7c4ef712011-11-18 15:33:48 +01007152 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7153 return -EINVAL;
7154
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307155 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7156
Johannes Berg683b6d32012-11-08 21:25:48 +01007157 err = nl80211_parse_chandef(rdev, info, &chandef);
7158 if (err)
7159 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007160
Johannes Berge247bd902011-11-04 11:18:21 +01007161 if (!dont_wait_for_ack) {
7162 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7163 if (!msg)
7164 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007165
Eric W. Biederman15e47302012-09-07 20:12:54 +00007166 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007167 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007168
Johannes Berge247bd902011-11-04 11:18:21 +01007169 if (IS_ERR(hdr)) {
7170 err = PTR_ERR(hdr);
7171 goto free_msg;
7172 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007173 }
Johannes Berge247bd902011-11-04 11:18:21 +01007174
Johannes Berg683b6d32012-11-08 21:25:48 +01007175 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007176 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7177 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007178 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007179 if (err)
7180 goto free_msg;
7181
Johannes Berge247bd902011-11-04 11:18:21 +01007182 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007183 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7184 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007185
Johannes Berge247bd902011-11-04 11:18:21 +01007186 genlmsg_end(msg, hdr);
7187 return genlmsg_reply(msg, info);
7188 }
7189
7190 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007191
7192 nla_put_failure:
7193 err = -ENOBUFS;
7194 free_msg:
7195 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007196 return err;
7197}
7198
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007199static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7200{
7201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007202 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007203 u64 cookie;
7204
7205 if (!info->attrs[NL80211_ATTR_COOKIE])
7206 return -EINVAL;
7207
7208 if (!rdev->ops->mgmt_tx_cancel_wait)
7209 return -EOPNOTSUPP;
7210
Johannes Berg71bbc992012-06-15 15:30:18 +02007211 switch (wdev->iftype) {
7212 case NL80211_IFTYPE_STATION:
7213 case NL80211_IFTYPE_ADHOC:
7214 case NL80211_IFTYPE_P2P_CLIENT:
7215 case NL80211_IFTYPE_AP:
7216 case NL80211_IFTYPE_AP_VLAN:
7217 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007218 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007219 break;
7220 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007221 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007222 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007223
7224 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7225
Hila Gonene35e4d22012-06-27 17:19:42 +03007226 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007227}
7228
Kalle Valoffb9eb32010-02-17 17:58:10 +02007229static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7230{
Johannes Berg4c476992010-10-04 21:36:35 +02007231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007232 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007233 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007234 u8 ps_state;
7235 bool state;
7236 int err;
7237
Johannes Berg4c476992010-10-04 21:36:35 +02007238 if (!info->attrs[NL80211_ATTR_PS_STATE])
7239 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007240
7241 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7242
Johannes Berg4c476992010-10-04 21:36:35 +02007243 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7244 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007245
7246 wdev = dev->ieee80211_ptr;
7247
Johannes Berg4c476992010-10-04 21:36:35 +02007248 if (!rdev->ops->set_power_mgmt)
7249 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007250
7251 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7252
7253 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007254 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007255
Hila Gonene35e4d22012-06-27 17:19:42 +03007256 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007257 if (!err)
7258 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007259 return err;
7260}
7261
7262static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7263{
Johannes Berg4c476992010-10-04 21:36:35 +02007264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007265 enum nl80211_ps_state ps_state;
7266 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007267 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007268 struct sk_buff *msg;
7269 void *hdr;
7270 int err;
7271
Kalle Valoffb9eb32010-02-17 17:58:10 +02007272 wdev = dev->ieee80211_ptr;
7273
Johannes Berg4c476992010-10-04 21:36:35 +02007274 if (!rdev->ops->set_power_mgmt)
7275 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007276
7277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007278 if (!msg)
7279 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007280
Eric W. Biederman15e47302012-09-07 20:12:54 +00007281 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007282 NL80211_CMD_GET_POWER_SAVE);
7283 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007284 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007285 goto free_msg;
7286 }
7287
7288 if (wdev->ps)
7289 ps_state = NL80211_PS_ENABLED;
7290 else
7291 ps_state = NL80211_PS_DISABLED;
7292
David S. Miller9360ffd2012-03-29 04:41:26 -04007293 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7294 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007295
7296 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007297 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007298
Johannes Berg4c476992010-10-04 21:36:35 +02007299 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007300 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007301 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007302 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007303 return err;
7304}
7305
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007306static struct nla_policy
7307nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7308 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7309 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7310 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007311 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7312 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7313 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007314};
7315
Thomas Pedersen84f10702012-07-12 16:17:33 -07007316static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007317 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007318{
7319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7320 struct wireless_dev *wdev;
7321 struct net_device *dev = info->user_ptr[1];
7322
Johannes Bergd9d8b012012-11-26 12:51:52 +01007323 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007324 return -EINVAL;
7325
7326 wdev = dev->ieee80211_ptr;
7327
7328 if (!rdev->ops->set_cqm_txe_config)
7329 return -EOPNOTSUPP;
7330
7331 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7332 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7333 return -EOPNOTSUPP;
7334
Hila Gonene35e4d22012-06-27 17:19:42 +03007335 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007336}
7337
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007338static int nl80211_set_cqm_rssi(struct genl_info *info,
7339 s32 threshold, u32 hysteresis)
7340{
Johannes Berg4c476992010-10-04 21:36:35 +02007341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007342 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007343 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007344
7345 if (threshold > 0)
7346 return -EINVAL;
7347
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007348 wdev = dev->ieee80211_ptr;
7349
Johannes Berg4c476992010-10-04 21:36:35 +02007350 if (!rdev->ops->set_cqm_rssi_config)
7351 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007352
Johannes Berg074ac8d2010-09-16 14:58:22 +02007353 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007354 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7355 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007356
Hila Gonene35e4d22012-06-27 17:19:42 +03007357 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007358}
7359
7360static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7361{
7362 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7363 struct nlattr *cqm;
7364 int err;
7365
7366 cqm = info->attrs[NL80211_ATTR_CQM];
7367 if (!cqm) {
7368 err = -EINVAL;
7369 goto out;
7370 }
7371
7372 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7373 nl80211_attr_cqm_policy);
7374 if (err)
7375 goto out;
7376
7377 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7378 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7379 s32 threshold;
7380 u32 hysteresis;
7381 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7382 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7383 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007384 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7385 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7386 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7387 u32 rate, pkts, intvl;
7388 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7389 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7390 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7391 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007392 } else
7393 err = -EINVAL;
7394
7395out:
7396 return err;
7397}
7398
Johannes Berg29cbe682010-12-03 09:20:44 +01007399static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7400{
7401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7402 struct net_device *dev = info->user_ptr[1];
7403 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007404 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007405 int err;
7406
7407 /* start with default */
7408 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007409 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007410
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007411 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007412 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007413 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007414 if (err)
7415 return err;
7416 }
7417
7418 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7419 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7420 return -EINVAL;
7421
Javier Cardonac80d5452010-12-16 17:37:49 -08007422 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7423 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7424
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007425 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7426 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7427 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7428 return -EINVAL;
7429
Marco Porsch9bdbf042013-01-07 16:04:51 +01007430 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7431 setup.beacon_interval =
7432 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7433 if (setup.beacon_interval < 10 ||
7434 setup.beacon_interval > 10000)
7435 return -EINVAL;
7436 }
7437
7438 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7439 setup.dtim_period =
7440 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7441 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7442 return -EINVAL;
7443 }
7444
Javier Cardonac80d5452010-12-16 17:37:49 -08007445 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7446 /* parse additional setup parameters if given */
7447 err = nl80211_parse_mesh_setup(info, &setup);
7448 if (err)
7449 return err;
7450 }
7451
Johannes Bergcc1d2802012-05-16 23:50:20 +02007452 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007453 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7454 if (err)
7455 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007456 } else {
7457 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007458 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007459 }
7460
Javier Cardonac80d5452010-12-16 17:37:49 -08007461 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007462}
7463
7464static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7465{
7466 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7467 struct net_device *dev = info->user_ptr[1];
7468
7469 return cfg80211_leave_mesh(rdev, dev);
7470}
7471
Johannes Bergdfb89c52012-06-27 09:23:48 +02007472#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007473static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7474 struct cfg80211_registered_device *rdev)
7475{
7476 struct nlattr *nl_pats, *nl_pat;
7477 int i, pat_len;
7478
7479 if (!rdev->wowlan->n_patterns)
7480 return 0;
7481
7482 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7483 if (!nl_pats)
7484 return -ENOBUFS;
7485
7486 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7487 nl_pat = nla_nest_start(msg, i + 1);
7488 if (!nl_pat)
7489 return -ENOBUFS;
7490 pat_len = rdev->wowlan->patterns[i].pattern_len;
7491 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7492 DIV_ROUND_UP(pat_len, 8),
7493 rdev->wowlan->patterns[i].mask) ||
7494 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7495 pat_len, rdev->wowlan->patterns[i].pattern) ||
7496 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7497 rdev->wowlan->patterns[i].pkt_offset))
7498 return -ENOBUFS;
7499 nla_nest_end(msg, nl_pat);
7500 }
7501 nla_nest_end(msg, nl_pats);
7502
7503 return 0;
7504}
7505
Johannes Berg2a0e0472013-01-23 22:57:40 +01007506static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7507 struct cfg80211_wowlan_tcp *tcp)
7508{
7509 struct nlattr *nl_tcp;
7510
7511 if (!tcp)
7512 return 0;
7513
7514 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7515 if (!nl_tcp)
7516 return -ENOBUFS;
7517
7518 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7519 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7520 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7521 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7522 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7523 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7524 tcp->payload_len, tcp->payload) ||
7525 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7526 tcp->data_interval) ||
7527 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7528 tcp->wake_len, tcp->wake_data) ||
7529 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7530 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7531 return -ENOBUFS;
7532
7533 if (tcp->payload_seq.len &&
7534 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7535 sizeof(tcp->payload_seq), &tcp->payload_seq))
7536 return -ENOBUFS;
7537
7538 if (tcp->payload_tok.len &&
7539 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7540 sizeof(tcp->payload_tok) + tcp->tokens_size,
7541 &tcp->payload_tok))
7542 return -ENOBUFS;
7543
7544 return 0;
7545}
7546
Johannes Bergff1b6e62011-05-04 15:37:28 +02007547static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7548{
7549 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7550 struct sk_buff *msg;
7551 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007552 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007553
Johannes Berg2a0e0472013-01-23 22:57:40 +01007554 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7555 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007556 return -EOPNOTSUPP;
7557
Johannes Berg2a0e0472013-01-23 22:57:40 +01007558 if (rdev->wowlan && rdev->wowlan->tcp) {
7559 /* adjust size to have room for all the data */
7560 size += rdev->wowlan->tcp->tokens_size +
7561 rdev->wowlan->tcp->payload_len +
7562 rdev->wowlan->tcp->wake_len +
7563 rdev->wowlan->tcp->wake_len / 8;
7564 }
7565
7566 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007567 if (!msg)
7568 return -ENOMEM;
7569
Eric W. Biederman15e47302012-09-07 20:12:54 +00007570 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007571 NL80211_CMD_GET_WOWLAN);
7572 if (!hdr)
7573 goto nla_put_failure;
7574
7575 if (rdev->wowlan) {
7576 struct nlattr *nl_wowlan;
7577
7578 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7579 if (!nl_wowlan)
7580 goto nla_put_failure;
7581
David S. Miller9360ffd2012-03-29 04:41:26 -04007582 if ((rdev->wowlan->any &&
7583 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7584 (rdev->wowlan->disconnect &&
7585 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7586 (rdev->wowlan->magic_pkt &&
7587 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7588 (rdev->wowlan->gtk_rekey_failure &&
7589 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7590 (rdev->wowlan->eap_identity_req &&
7591 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7592 (rdev->wowlan->four_way_handshake &&
7593 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7594 (rdev->wowlan->rfkill_release &&
7595 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7596 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007597
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007598 if (nl80211_send_wowlan_patterns(msg, rdev))
7599 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007600
7601 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7602 goto nla_put_failure;
7603
Johannes Bergff1b6e62011-05-04 15:37:28 +02007604 nla_nest_end(msg, nl_wowlan);
7605 }
7606
7607 genlmsg_end(msg, hdr);
7608 return genlmsg_reply(msg, info);
7609
7610nla_put_failure:
7611 nlmsg_free(msg);
7612 return -ENOBUFS;
7613}
7614
Johannes Berg2a0e0472013-01-23 22:57:40 +01007615static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7616 struct nlattr *attr,
7617 struct cfg80211_wowlan *trig)
7618{
7619 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7620 struct cfg80211_wowlan_tcp *cfg;
7621 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7622 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7623 u32 size;
7624 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7625 int err, port;
7626
7627 if (!rdev->wiphy.wowlan.tcp)
7628 return -EINVAL;
7629
7630 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7631 nla_data(attr), nla_len(attr),
7632 nl80211_wowlan_tcp_policy);
7633 if (err)
7634 return err;
7635
7636 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7637 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7638 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7639 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7640 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7641 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7642 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7643 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7644 return -EINVAL;
7645
7646 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7647 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7648 return -EINVAL;
7649
7650 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg723d5682013-02-26 13:56:40 +01007651 rdev->wiphy.wowlan.tcp->data_interval_max ||
7652 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007653 return -EINVAL;
7654
7655 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7656 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7657 return -EINVAL;
7658
7659 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7660 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7661 return -EINVAL;
7662
7663 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7664 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7665
7666 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7667 tokens_size = tokln - sizeof(*tok);
7668
7669 if (!tok->len || tokens_size % tok->len)
7670 return -EINVAL;
7671 if (!rdev->wiphy.wowlan.tcp->tok)
7672 return -EINVAL;
7673 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7674 return -EINVAL;
7675 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7676 return -EINVAL;
7677 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7678 return -EINVAL;
7679 if (tok->offset + tok->len > data_size)
7680 return -EINVAL;
7681 }
7682
7683 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7684 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7685 if (!rdev->wiphy.wowlan.tcp->seq)
7686 return -EINVAL;
7687 if (seq->len == 0 || seq->len > 4)
7688 return -EINVAL;
7689 if (seq->len + seq->offset > data_size)
7690 return -EINVAL;
7691 }
7692
7693 size = sizeof(*cfg);
7694 size += data_size;
7695 size += wake_size + wake_mask_size;
7696 size += tokens_size;
7697
7698 cfg = kzalloc(size, GFP_KERNEL);
7699 if (!cfg)
7700 return -ENOMEM;
7701 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7702 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7703 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7704 ETH_ALEN);
7705 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7706 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7707 else
7708 port = 0;
7709#ifdef CONFIG_INET
7710 /* allocate a socket and port for it and use it */
7711 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7712 IPPROTO_TCP, &cfg->sock, 1);
7713 if (err) {
7714 kfree(cfg);
7715 return err;
7716 }
7717 if (inet_csk_get_port(cfg->sock->sk, port)) {
7718 sock_release(cfg->sock);
7719 kfree(cfg);
7720 return -EADDRINUSE;
7721 }
7722 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7723#else
7724 if (!port) {
7725 kfree(cfg);
7726 return -EINVAL;
7727 }
7728 cfg->src_port = port;
7729#endif
7730
7731 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7732 cfg->payload_len = data_size;
7733 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7734 memcpy((void *)cfg->payload,
7735 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7736 data_size);
7737 if (seq)
7738 cfg->payload_seq = *seq;
7739 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7740 cfg->wake_len = wake_size;
7741 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7742 memcpy((void *)cfg->wake_data,
7743 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7744 wake_size);
7745 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7746 data_size + wake_size;
7747 memcpy((void *)cfg->wake_mask,
7748 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7749 wake_mask_size);
7750 if (tok) {
7751 cfg->tokens_size = tokens_size;
7752 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7753 }
7754
7755 trig->tcp = cfg;
7756
7757 return 0;
7758}
7759
Johannes Bergff1b6e62011-05-04 15:37:28 +02007760static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7761{
7762 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7763 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007764 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007765 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007766 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7767 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007768 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007769
Johannes Berg2a0e0472013-01-23 22:57:40 +01007770 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7771 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007772 return -EOPNOTSUPP;
7773
Johannes Bergae33bd82012-07-12 16:25:02 +02007774 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7775 cfg80211_rdev_free_wowlan(rdev);
7776 rdev->wowlan = NULL;
7777 goto set_wakeup;
7778 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007779
7780 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7781 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7782 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7783 nl80211_wowlan_policy);
7784 if (err)
7785 return err;
7786
7787 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7788 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7789 return -EINVAL;
7790 new_triggers.any = true;
7791 }
7792
7793 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7794 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7795 return -EINVAL;
7796 new_triggers.disconnect = true;
7797 }
7798
7799 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7800 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7801 return -EINVAL;
7802 new_triggers.magic_pkt = true;
7803 }
7804
Johannes Berg77dbbb12011-07-13 10:48:55 +02007805 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7806 return -EINVAL;
7807
7808 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7809 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7810 return -EINVAL;
7811 new_triggers.gtk_rekey_failure = true;
7812 }
7813
7814 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7815 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7816 return -EINVAL;
7817 new_triggers.eap_identity_req = true;
7818 }
7819
7820 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7821 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7822 return -EINVAL;
7823 new_triggers.four_way_handshake = true;
7824 }
7825
7826 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7827 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7828 return -EINVAL;
7829 new_triggers.rfkill_release = true;
7830 }
7831
Johannes Bergff1b6e62011-05-04 15:37:28 +02007832 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7833 struct nlattr *pat;
7834 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007835 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007836 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7837
7838 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7839 rem)
7840 n_patterns++;
7841 if (n_patterns > wowlan->n_patterns)
7842 return -EINVAL;
7843
7844 new_triggers.patterns = kcalloc(n_patterns,
7845 sizeof(new_triggers.patterns[0]),
7846 GFP_KERNEL);
7847 if (!new_triggers.patterns)
7848 return -ENOMEM;
7849
7850 new_triggers.n_patterns = n_patterns;
7851 i = 0;
7852
7853 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7854 rem) {
7855 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7856 nla_data(pat), nla_len(pat), NULL);
7857 err = -EINVAL;
7858 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7859 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7860 goto error;
7861 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7862 mask_len = DIV_ROUND_UP(pat_len, 8);
7863 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7864 mask_len)
7865 goto error;
7866 if (pat_len > wowlan->pattern_max_len ||
7867 pat_len < wowlan->pattern_min_len)
7868 goto error;
7869
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007870 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7871 pkt_offset = 0;
7872 else
7873 pkt_offset = nla_get_u32(
7874 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7875 if (pkt_offset > wowlan->max_pkt_offset)
7876 goto error;
7877 new_triggers.patterns[i].pkt_offset = pkt_offset;
7878
Johannes Bergff1b6e62011-05-04 15:37:28 +02007879 new_triggers.patterns[i].mask =
7880 kmalloc(mask_len + pat_len, GFP_KERNEL);
7881 if (!new_triggers.patterns[i].mask) {
7882 err = -ENOMEM;
7883 goto error;
7884 }
7885 new_triggers.patterns[i].pattern =
7886 new_triggers.patterns[i].mask + mask_len;
7887 memcpy(new_triggers.patterns[i].mask,
7888 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7889 mask_len);
7890 new_triggers.patterns[i].pattern_len = pat_len;
7891 memcpy(new_triggers.patterns[i].pattern,
7892 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7893 pat_len);
7894 i++;
7895 }
7896 }
7897
Johannes Berg2a0e0472013-01-23 22:57:40 +01007898 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7899 err = nl80211_parse_wowlan_tcp(
7900 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7901 &new_triggers);
7902 if (err)
7903 goto error;
7904 }
7905
Johannes Bergae33bd82012-07-12 16:25:02 +02007906 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7907 if (!ntrig) {
7908 err = -ENOMEM;
7909 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007910 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007911 cfg80211_rdev_free_wowlan(rdev);
7912 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007913
Johannes Bergae33bd82012-07-12 16:25:02 +02007914 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007915 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007916 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007917
Johannes Bergff1b6e62011-05-04 15:37:28 +02007918 return 0;
7919 error:
7920 for (i = 0; i < new_triggers.n_patterns; i++)
7921 kfree(new_triggers.patterns[i].mask);
7922 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007923 if (new_triggers.tcp && new_triggers.tcp->sock)
7924 sock_release(new_triggers.tcp->sock);
7925 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007926 return err;
7927}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007928#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007929
Johannes Berge5497d72011-07-05 16:35:40 +02007930static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7931{
7932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7933 struct net_device *dev = info->user_ptr[1];
7934 struct wireless_dev *wdev = dev->ieee80211_ptr;
7935 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7936 struct cfg80211_gtk_rekey_data rekey_data;
7937 int err;
7938
7939 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7940 return -EINVAL;
7941
7942 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7943 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7944 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7945 nl80211_rekey_policy);
7946 if (err)
7947 return err;
7948
7949 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7950 return -ERANGE;
7951 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7952 return -ERANGE;
7953 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7954 return -ERANGE;
7955
7956 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7957 NL80211_KEK_LEN);
7958 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7959 NL80211_KCK_LEN);
7960 memcpy(rekey_data.replay_ctr,
7961 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7962 NL80211_REPLAY_CTR_LEN);
7963
7964 wdev_lock(wdev);
7965 if (!wdev->current_bss) {
7966 err = -ENOTCONN;
7967 goto out;
7968 }
7969
7970 if (!rdev->ops->set_rekey_data) {
7971 err = -EOPNOTSUPP;
7972 goto out;
7973 }
7974
Hila Gonene35e4d22012-06-27 17:19:42 +03007975 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007976 out:
7977 wdev_unlock(wdev);
7978 return err;
7979}
7980
Johannes Berg28946da2011-11-04 11:18:12 +01007981static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7982 struct genl_info *info)
7983{
7984 struct net_device *dev = info->user_ptr[1];
7985 struct wireless_dev *wdev = dev->ieee80211_ptr;
7986
7987 if (wdev->iftype != NL80211_IFTYPE_AP &&
7988 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7989 return -EINVAL;
7990
Eric W. Biederman15e47302012-09-07 20:12:54 +00007991 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01007992 return -EBUSY;
7993
Eric W. Biederman15e47302012-09-07 20:12:54 +00007994 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01007995 return 0;
7996}
7997
Johannes Berg7f6cf312011-11-04 11:18:15 +01007998static int nl80211_probe_client(struct sk_buff *skb,
7999 struct genl_info *info)
8000{
8001 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8002 struct net_device *dev = info->user_ptr[1];
8003 struct wireless_dev *wdev = dev->ieee80211_ptr;
8004 struct sk_buff *msg;
8005 void *hdr;
8006 const u8 *addr;
8007 u64 cookie;
8008 int err;
8009
8010 if (wdev->iftype != NL80211_IFTYPE_AP &&
8011 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8012 return -EOPNOTSUPP;
8013
8014 if (!info->attrs[NL80211_ATTR_MAC])
8015 return -EINVAL;
8016
8017 if (!rdev->ops->probe_client)
8018 return -EOPNOTSUPP;
8019
8020 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8021 if (!msg)
8022 return -ENOMEM;
8023
Eric W. Biederman15e47302012-09-07 20:12:54 +00008024 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008025 NL80211_CMD_PROBE_CLIENT);
8026
8027 if (IS_ERR(hdr)) {
8028 err = PTR_ERR(hdr);
8029 goto free_msg;
8030 }
8031
8032 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8033
Hila Gonene35e4d22012-06-27 17:19:42 +03008034 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008035 if (err)
8036 goto free_msg;
8037
David S. Miller9360ffd2012-03-29 04:41:26 -04008038 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8039 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008040
8041 genlmsg_end(msg, hdr);
8042
8043 return genlmsg_reply(msg, info);
8044
8045 nla_put_failure:
8046 err = -ENOBUFS;
8047 free_msg:
8048 nlmsg_free(msg);
8049 return err;
8050}
8051
Johannes Berg5e760232011-11-04 11:18:17 +01008052static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8053{
8054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008055 struct cfg80211_beacon_registration *reg, *nreg;
8056 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008057
8058 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8059 return -EOPNOTSUPP;
8060
Ben Greear37c73b52012-10-26 14:49:25 -07008061 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8062 if (!nreg)
8063 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008064
Ben Greear37c73b52012-10-26 14:49:25 -07008065 /* First, check if already registered. */
8066 spin_lock_bh(&rdev->beacon_registrations_lock);
8067 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8068 if (reg->nlportid == info->snd_portid) {
8069 rv = -EALREADY;
8070 goto out_err;
8071 }
8072 }
8073 /* Add it to the list */
8074 nreg->nlportid = info->snd_portid;
8075 list_add(&nreg->list, &rdev->beacon_registrations);
8076
8077 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008078
8079 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008080out_err:
8081 spin_unlock_bh(&rdev->beacon_registrations_lock);
8082 kfree(nreg);
8083 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008084}
8085
Johannes Berg98104fde2012-06-16 00:19:54 +02008086static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8087{
8088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8089 struct wireless_dev *wdev = info->user_ptr[1];
8090 int err;
8091
8092 if (!rdev->ops->start_p2p_device)
8093 return -EOPNOTSUPP;
8094
8095 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8096 return -EOPNOTSUPP;
8097
8098 if (wdev->p2p_started)
8099 return 0;
8100
8101 mutex_lock(&rdev->devlist_mtx);
8102 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8103 mutex_unlock(&rdev->devlist_mtx);
8104 if (err)
8105 return err;
8106
Johannes Bergeeb126e2012-10-23 15:16:50 +02008107 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008108 if (err)
8109 return err;
8110
8111 wdev->p2p_started = true;
8112 mutex_lock(&rdev->devlist_mtx);
8113 rdev->opencount++;
8114 mutex_unlock(&rdev->devlist_mtx);
8115
8116 return 0;
8117}
8118
8119static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8120{
8121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8122 struct wireless_dev *wdev = info->user_ptr[1];
8123
8124 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8125 return -EOPNOTSUPP;
8126
8127 if (!rdev->ops->stop_p2p_device)
8128 return -EOPNOTSUPP;
8129
8130 if (!wdev->p2p_started)
8131 return 0;
8132
Johannes Bergeeb126e2012-10-23 15:16:50 +02008133 rdev_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008134 wdev->p2p_started = false;
8135
8136 mutex_lock(&rdev->devlist_mtx);
8137 rdev->opencount--;
8138 mutex_unlock(&rdev->devlist_mtx);
8139
8140 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
8141 rdev->scan_req->aborted = true;
8142 ___cfg80211_scan_done(rdev, true);
8143 }
8144
8145 return 0;
8146}
8147
Johannes Berg3713b4e2013-02-14 16:19:38 +01008148static int nl80211_get_protocol_features(struct sk_buff *skb,
8149 struct genl_info *info)
8150{
8151 void *hdr;
8152 struct sk_buff *msg;
8153
8154 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8155 if (!msg)
8156 return -ENOMEM;
8157
8158 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8159 NL80211_CMD_GET_PROTOCOL_FEATURES);
8160 if (!hdr)
8161 goto nla_put_failure;
8162
8163 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8164 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8165 goto nla_put_failure;
8166
8167 genlmsg_end(msg, hdr);
8168 return genlmsg_reply(msg, info);
8169
8170 nla_put_failure:
8171 kfree_skb(msg);
8172 return -ENOBUFS;
8173}
8174
Jouni Malinen355199e2013-02-27 17:14:27 +02008175static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8176{
8177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8178 struct cfg80211_update_ft_ies_params ft_params;
8179 struct net_device *dev = info->user_ptr[1];
8180
8181 if (!rdev->ops->update_ft_ies)
8182 return -EOPNOTSUPP;
8183
8184 if (!info->attrs[NL80211_ATTR_MDID] ||
8185 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8186 return -EINVAL;
8187
8188 memset(&ft_params, 0, sizeof(ft_params));
8189 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8190 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8191 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8192
8193 return rdev_update_ft_ies(rdev, dev, &ft_params);
8194}
8195
Johannes Berg4c476992010-10-04 21:36:35 +02008196#define NL80211_FLAG_NEED_WIPHY 0x01
8197#define NL80211_FLAG_NEED_NETDEV 0x02
8198#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008199#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8200#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8201 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008202#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008203/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008204#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8205 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008206
8207static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8208 struct genl_info *info)
8209{
8210 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008211 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008212 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008213 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8214
8215 if (rtnl)
8216 rtnl_lock();
8217
8218 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008219 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008220 if (IS_ERR(rdev)) {
8221 if (rtnl)
8222 rtnl_unlock();
8223 return PTR_ERR(rdev);
8224 }
8225 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008226 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8227 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008228 mutex_lock(&cfg80211_mutex);
8229 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8230 info->attrs);
8231 if (IS_ERR(wdev)) {
8232 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02008233 if (rtnl)
8234 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008235 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008236 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008237
Johannes Berg89a54e42012-06-15 14:33:17 +02008238 dev = wdev->netdev;
8239 rdev = wiphy_to_dev(wdev->wiphy);
8240
Johannes Berg1bf614e2012-06-15 15:23:36 +02008241 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8242 if (!dev) {
8243 mutex_unlock(&cfg80211_mutex);
8244 if (rtnl)
8245 rtnl_unlock();
8246 return -EINVAL;
8247 }
8248
8249 info->user_ptr[1] = dev;
8250 } else {
8251 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008252 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008253
Johannes Berg1bf614e2012-06-15 15:23:36 +02008254 if (dev) {
8255 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8256 !netif_running(dev)) {
8257 mutex_unlock(&cfg80211_mutex);
8258 if (rtnl)
8259 rtnl_unlock();
8260 return -ENETDOWN;
8261 }
8262
8263 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008264 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8265 if (!wdev->p2p_started) {
8266 mutex_unlock(&cfg80211_mutex);
8267 if (rtnl)
8268 rtnl_unlock();
8269 return -ENETDOWN;
8270 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008271 }
8272
Johannes Berg89a54e42012-06-15 14:33:17 +02008273 cfg80211_lock_rdev(rdev);
8274
8275 mutex_unlock(&cfg80211_mutex);
8276
Johannes Berg4c476992010-10-04 21:36:35 +02008277 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008278 }
8279
8280 return 0;
8281}
8282
8283static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8284 struct genl_info *info)
8285{
8286 if (info->user_ptr[0])
8287 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02008288 if (info->user_ptr[1]) {
8289 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8290 struct wireless_dev *wdev = info->user_ptr[1];
8291
8292 if (wdev->netdev)
8293 dev_put(wdev->netdev);
8294 } else {
8295 dev_put(info->user_ptr[1]);
8296 }
8297 }
Johannes Berg4c476992010-10-04 21:36:35 +02008298 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8299 rtnl_unlock();
8300}
8301
Johannes Berg55682962007-09-20 13:09:35 -04008302static struct genl_ops nl80211_ops[] = {
8303 {
8304 .cmd = NL80211_CMD_GET_WIPHY,
8305 .doit = nl80211_get_wiphy,
8306 .dumpit = nl80211_dump_wiphy,
8307 .policy = nl80211_policy,
8308 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008309 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04008310 },
8311 {
8312 .cmd = NL80211_CMD_SET_WIPHY,
8313 .doit = nl80211_set_wiphy,
8314 .policy = nl80211_policy,
8315 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008316 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008317 },
8318 {
8319 .cmd = NL80211_CMD_GET_INTERFACE,
8320 .doit = nl80211_get_interface,
8321 .dumpit = nl80211_dump_interface,
8322 .policy = nl80211_policy,
8323 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02008324 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04008325 },
8326 {
8327 .cmd = NL80211_CMD_SET_INTERFACE,
8328 .doit = nl80211_set_interface,
8329 .policy = nl80211_policy,
8330 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008331 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8332 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008333 },
8334 {
8335 .cmd = NL80211_CMD_NEW_INTERFACE,
8336 .doit = nl80211_new_interface,
8337 .policy = nl80211_policy,
8338 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008339 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8340 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008341 },
8342 {
8343 .cmd = NL80211_CMD_DEL_INTERFACE,
8344 .doit = nl80211_del_interface,
8345 .policy = nl80211_policy,
8346 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008347 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008348 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008349 },
Johannes Berg41ade002007-12-19 02:03:29 +01008350 {
8351 .cmd = NL80211_CMD_GET_KEY,
8352 .doit = nl80211_get_key,
8353 .policy = nl80211_policy,
8354 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008356 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008357 },
8358 {
8359 .cmd = NL80211_CMD_SET_KEY,
8360 .doit = nl80211_set_key,
8361 .policy = nl80211_policy,
8362 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008364 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008365 },
8366 {
8367 .cmd = NL80211_CMD_NEW_KEY,
8368 .doit = nl80211_new_key,
8369 .policy = nl80211_policy,
8370 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008372 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008373 },
8374 {
8375 .cmd = NL80211_CMD_DEL_KEY,
8376 .doit = nl80211_del_key,
8377 .policy = nl80211_policy,
8378 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008379 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008380 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008381 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008382 {
8383 .cmd = NL80211_CMD_SET_BEACON,
8384 .policy = nl80211_policy,
8385 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008386 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008388 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008389 },
8390 {
Johannes Berg88600202012-02-13 15:17:18 +01008391 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008392 .policy = nl80211_policy,
8393 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008394 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008396 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008397 },
8398 {
Johannes Berg88600202012-02-13 15:17:18 +01008399 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008400 .policy = nl80211_policy,
8401 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008402 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008403 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008404 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008405 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008406 {
8407 .cmd = NL80211_CMD_GET_STATION,
8408 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008409 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008410 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008411 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8412 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008413 },
8414 {
8415 .cmd = NL80211_CMD_SET_STATION,
8416 .doit = nl80211_set_station,
8417 .policy = nl80211_policy,
8418 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008420 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008421 },
8422 {
8423 .cmd = NL80211_CMD_NEW_STATION,
8424 .doit = nl80211_new_station,
8425 .policy = nl80211_policy,
8426 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008428 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008429 },
8430 {
8431 .cmd = NL80211_CMD_DEL_STATION,
8432 .doit = nl80211_del_station,
8433 .policy = nl80211_policy,
8434 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008436 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008437 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008438 {
8439 .cmd = NL80211_CMD_GET_MPATH,
8440 .doit = nl80211_get_mpath,
8441 .dumpit = nl80211_dump_mpath,
8442 .policy = nl80211_policy,
8443 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008444 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008445 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008446 },
8447 {
8448 .cmd = NL80211_CMD_SET_MPATH,
8449 .doit = nl80211_set_mpath,
8450 .policy = nl80211_policy,
8451 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008452 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008453 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008454 },
8455 {
8456 .cmd = NL80211_CMD_NEW_MPATH,
8457 .doit = nl80211_new_mpath,
8458 .policy = nl80211_policy,
8459 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008460 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008461 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008462 },
8463 {
8464 .cmd = NL80211_CMD_DEL_MPATH,
8465 .doit = nl80211_del_mpath,
8466 .policy = nl80211_policy,
8467 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008468 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008469 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008470 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008471 {
8472 .cmd = NL80211_CMD_SET_BSS,
8473 .doit = nl80211_set_bss,
8474 .policy = nl80211_policy,
8475 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008476 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008477 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008478 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008479 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008480 .cmd = NL80211_CMD_GET_REG,
8481 .doit = nl80211_get_reg,
8482 .policy = nl80211_policy,
8483 /* can be retrieved by unprivileged users */
8484 },
8485 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008486 .cmd = NL80211_CMD_SET_REG,
8487 .doit = nl80211_set_reg,
8488 .policy = nl80211_policy,
8489 .flags = GENL_ADMIN_PERM,
8490 },
8491 {
8492 .cmd = NL80211_CMD_REQ_SET_REG,
8493 .doit = nl80211_req_set_reg,
8494 .policy = nl80211_policy,
8495 .flags = GENL_ADMIN_PERM,
8496 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008497 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008498 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8499 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008500 .policy = nl80211_policy,
8501 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008502 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008503 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008504 },
8505 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008506 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8507 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008508 .policy = nl80211_policy,
8509 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008510 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008511 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008512 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008513 {
Johannes Berg2a519312009-02-10 21:25:55 +01008514 .cmd = NL80211_CMD_TRIGGER_SCAN,
8515 .doit = nl80211_trigger_scan,
8516 .policy = nl80211_policy,
8517 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008518 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008519 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008520 },
8521 {
8522 .cmd = NL80211_CMD_GET_SCAN,
8523 .policy = nl80211_policy,
8524 .dumpit = nl80211_dump_scan,
8525 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008526 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008527 .cmd = NL80211_CMD_START_SCHED_SCAN,
8528 .doit = nl80211_start_sched_scan,
8529 .policy = nl80211_policy,
8530 .flags = GENL_ADMIN_PERM,
8531 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8532 NL80211_FLAG_NEED_RTNL,
8533 },
8534 {
8535 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8536 .doit = nl80211_stop_sched_scan,
8537 .policy = nl80211_policy,
8538 .flags = GENL_ADMIN_PERM,
8539 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8540 NL80211_FLAG_NEED_RTNL,
8541 },
8542 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008543 .cmd = NL80211_CMD_AUTHENTICATE,
8544 .doit = nl80211_authenticate,
8545 .policy = nl80211_policy,
8546 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008547 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008548 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008549 },
8550 {
8551 .cmd = NL80211_CMD_ASSOCIATE,
8552 .doit = nl80211_associate,
8553 .policy = nl80211_policy,
8554 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008556 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008557 },
8558 {
8559 .cmd = NL80211_CMD_DEAUTHENTICATE,
8560 .doit = nl80211_deauthenticate,
8561 .policy = nl80211_policy,
8562 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008563 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008564 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008565 },
8566 {
8567 .cmd = NL80211_CMD_DISASSOCIATE,
8568 .doit = nl80211_disassociate,
8569 .policy = nl80211_policy,
8570 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008571 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008572 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008573 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008574 {
8575 .cmd = NL80211_CMD_JOIN_IBSS,
8576 .doit = nl80211_join_ibss,
8577 .policy = nl80211_policy,
8578 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008579 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008580 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008581 },
8582 {
8583 .cmd = NL80211_CMD_LEAVE_IBSS,
8584 .doit = nl80211_leave_ibss,
8585 .policy = nl80211_policy,
8586 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008587 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008588 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008589 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008590#ifdef CONFIG_NL80211_TESTMODE
8591 {
8592 .cmd = NL80211_CMD_TESTMODE,
8593 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008594 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008595 .policy = nl80211_policy,
8596 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008597 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8598 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008599 },
8600#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008601 {
8602 .cmd = NL80211_CMD_CONNECT,
8603 .doit = nl80211_connect,
8604 .policy = nl80211_policy,
8605 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008607 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008608 },
8609 {
8610 .cmd = NL80211_CMD_DISCONNECT,
8611 .doit = nl80211_disconnect,
8612 .policy = nl80211_policy,
8613 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008615 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008616 },
Johannes Berg463d0182009-07-14 00:33:35 +02008617 {
8618 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8619 .doit = nl80211_wiphy_netns,
8620 .policy = nl80211_policy,
8621 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008622 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8623 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008624 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008625 {
8626 .cmd = NL80211_CMD_GET_SURVEY,
8627 .policy = nl80211_policy,
8628 .dumpit = nl80211_dump_survey,
8629 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008630 {
8631 .cmd = NL80211_CMD_SET_PMKSA,
8632 .doit = nl80211_setdel_pmksa,
8633 .policy = nl80211_policy,
8634 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008635 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008636 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008637 },
8638 {
8639 .cmd = NL80211_CMD_DEL_PMKSA,
8640 .doit = nl80211_setdel_pmksa,
8641 .policy = nl80211_policy,
8642 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008643 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008644 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008645 },
8646 {
8647 .cmd = NL80211_CMD_FLUSH_PMKSA,
8648 .doit = nl80211_flush_pmksa,
8649 .policy = nl80211_policy,
8650 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008651 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008652 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008653 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008654 {
8655 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8656 .doit = nl80211_remain_on_channel,
8657 .policy = nl80211_policy,
8658 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008659 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008660 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008661 },
8662 {
8663 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8664 .doit = nl80211_cancel_remain_on_channel,
8665 .policy = nl80211_policy,
8666 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008667 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008668 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008669 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008670 {
8671 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8672 .doit = nl80211_set_tx_bitrate_mask,
8673 .policy = nl80211_policy,
8674 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008675 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8676 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008677 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008678 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008679 .cmd = NL80211_CMD_REGISTER_FRAME,
8680 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008681 .policy = nl80211_policy,
8682 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008683 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008684 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008685 },
8686 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008687 .cmd = NL80211_CMD_FRAME,
8688 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008689 .policy = nl80211_policy,
8690 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008691 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008692 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008693 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008694 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008695 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8696 .doit = nl80211_tx_mgmt_cancel_wait,
8697 .policy = nl80211_policy,
8698 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008699 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008700 NL80211_FLAG_NEED_RTNL,
8701 },
8702 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008703 .cmd = NL80211_CMD_SET_POWER_SAVE,
8704 .doit = nl80211_set_power_save,
8705 .policy = nl80211_policy,
8706 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008707 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8708 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008709 },
8710 {
8711 .cmd = NL80211_CMD_GET_POWER_SAVE,
8712 .doit = nl80211_get_power_save,
8713 .policy = nl80211_policy,
8714 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008715 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8716 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008717 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008718 {
8719 .cmd = NL80211_CMD_SET_CQM,
8720 .doit = nl80211_set_cqm,
8721 .policy = nl80211_policy,
8722 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008723 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8724 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008725 },
Johannes Bergf444de02010-05-05 15:25:02 +02008726 {
8727 .cmd = NL80211_CMD_SET_CHANNEL,
8728 .doit = nl80211_set_channel,
8729 .policy = nl80211_policy,
8730 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008731 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8732 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008733 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008734 {
8735 .cmd = NL80211_CMD_SET_WDS_PEER,
8736 .doit = nl80211_set_wds_peer,
8737 .policy = nl80211_policy,
8738 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008739 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8740 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008741 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008742 {
8743 .cmd = NL80211_CMD_JOIN_MESH,
8744 .doit = nl80211_join_mesh,
8745 .policy = nl80211_policy,
8746 .flags = GENL_ADMIN_PERM,
8747 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8748 NL80211_FLAG_NEED_RTNL,
8749 },
8750 {
8751 .cmd = NL80211_CMD_LEAVE_MESH,
8752 .doit = nl80211_leave_mesh,
8753 .policy = nl80211_policy,
8754 .flags = GENL_ADMIN_PERM,
8755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8756 NL80211_FLAG_NEED_RTNL,
8757 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008758#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008759 {
8760 .cmd = NL80211_CMD_GET_WOWLAN,
8761 .doit = nl80211_get_wowlan,
8762 .policy = nl80211_policy,
8763 /* can be retrieved by unprivileged users */
8764 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8765 NL80211_FLAG_NEED_RTNL,
8766 },
8767 {
8768 .cmd = NL80211_CMD_SET_WOWLAN,
8769 .doit = nl80211_set_wowlan,
8770 .policy = nl80211_policy,
8771 .flags = GENL_ADMIN_PERM,
8772 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8773 NL80211_FLAG_NEED_RTNL,
8774 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008775#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008776 {
8777 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8778 .doit = nl80211_set_rekey_data,
8779 .policy = nl80211_policy,
8780 .flags = GENL_ADMIN_PERM,
8781 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8782 NL80211_FLAG_NEED_RTNL,
8783 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008784 {
8785 .cmd = NL80211_CMD_TDLS_MGMT,
8786 .doit = nl80211_tdls_mgmt,
8787 .policy = nl80211_policy,
8788 .flags = GENL_ADMIN_PERM,
8789 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8790 NL80211_FLAG_NEED_RTNL,
8791 },
8792 {
8793 .cmd = NL80211_CMD_TDLS_OPER,
8794 .doit = nl80211_tdls_oper,
8795 .policy = nl80211_policy,
8796 .flags = GENL_ADMIN_PERM,
8797 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8798 NL80211_FLAG_NEED_RTNL,
8799 },
Johannes Berg28946da2011-11-04 11:18:12 +01008800 {
8801 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8802 .doit = nl80211_register_unexpected_frame,
8803 .policy = nl80211_policy,
8804 .flags = GENL_ADMIN_PERM,
8805 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8806 NL80211_FLAG_NEED_RTNL,
8807 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008808 {
8809 .cmd = NL80211_CMD_PROBE_CLIENT,
8810 .doit = nl80211_probe_client,
8811 .policy = nl80211_policy,
8812 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008813 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008814 NL80211_FLAG_NEED_RTNL,
8815 },
Johannes Berg5e760232011-11-04 11:18:17 +01008816 {
8817 .cmd = NL80211_CMD_REGISTER_BEACONS,
8818 .doit = nl80211_register_beacons,
8819 .policy = nl80211_policy,
8820 .flags = GENL_ADMIN_PERM,
8821 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8822 NL80211_FLAG_NEED_RTNL,
8823 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008824 {
8825 .cmd = NL80211_CMD_SET_NOACK_MAP,
8826 .doit = nl80211_set_noack_map,
8827 .policy = nl80211_policy,
8828 .flags = GENL_ADMIN_PERM,
8829 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8830 NL80211_FLAG_NEED_RTNL,
8831 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008832 {
8833 .cmd = NL80211_CMD_START_P2P_DEVICE,
8834 .doit = nl80211_start_p2p_device,
8835 .policy = nl80211_policy,
8836 .flags = GENL_ADMIN_PERM,
8837 .internal_flags = NL80211_FLAG_NEED_WDEV |
8838 NL80211_FLAG_NEED_RTNL,
8839 },
8840 {
8841 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8842 .doit = nl80211_stop_p2p_device,
8843 .policy = nl80211_policy,
8844 .flags = GENL_ADMIN_PERM,
8845 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8846 NL80211_FLAG_NEED_RTNL,
8847 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008848 {
8849 .cmd = NL80211_CMD_SET_MCAST_RATE,
8850 .doit = nl80211_set_mcast_rate,
8851 .policy = nl80211_policy,
8852 .flags = GENL_ADMIN_PERM,
8853 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8854 NL80211_FLAG_NEED_RTNL,
8855 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308856 {
8857 .cmd = NL80211_CMD_SET_MAC_ACL,
8858 .doit = nl80211_set_mac_acl,
8859 .policy = nl80211_policy,
8860 .flags = GENL_ADMIN_PERM,
8861 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8862 NL80211_FLAG_NEED_RTNL,
8863 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008864 {
8865 .cmd = NL80211_CMD_RADAR_DETECT,
8866 .doit = nl80211_start_radar_detection,
8867 .policy = nl80211_policy,
8868 .flags = GENL_ADMIN_PERM,
8869 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8870 NL80211_FLAG_NEED_RTNL,
8871 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008872 {
8873 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8874 .doit = nl80211_get_protocol_features,
8875 .policy = nl80211_policy,
8876 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008877 {
8878 .cmd = NL80211_CMD_UPDATE_FT_IES,
8879 .doit = nl80211_update_ft_ies,
8880 .policy = nl80211_policy,
8881 .flags = GENL_ADMIN_PERM,
8882 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8883 NL80211_FLAG_NEED_RTNL,
8884 },
Johannes Berg55682962007-09-20 13:09:35 -04008885};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008886
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008887static struct genl_multicast_group nl80211_mlme_mcgrp = {
8888 .name = "mlme",
8889};
Johannes Berg55682962007-09-20 13:09:35 -04008890
8891/* multicast groups */
8892static struct genl_multicast_group nl80211_config_mcgrp = {
8893 .name = "config",
8894};
Johannes Berg2a519312009-02-10 21:25:55 +01008895static struct genl_multicast_group nl80211_scan_mcgrp = {
8896 .name = "scan",
8897};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008898static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8899 .name = "regulatory",
8900};
Johannes Berg55682962007-09-20 13:09:35 -04008901
8902/* notification functions */
8903
8904void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8905{
8906 struct sk_buff *msg;
8907
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008909 if (!msg)
8910 return;
8911
Johannes Berg3713b4e2013-02-14 16:19:38 +01008912 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8913 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008914 nlmsg_free(msg);
8915 return;
8916 }
8917
Johannes Berg463d0182009-07-14 00:33:35 +02008918 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8919 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008920}
8921
Johannes Berg362a4152009-05-24 16:43:15 +02008922static int nl80211_add_scan_req(struct sk_buff *msg,
8923 struct cfg80211_registered_device *rdev)
8924{
8925 struct cfg80211_scan_request *req = rdev->scan_req;
8926 struct nlattr *nest;
8927 int i;
8928
Johannes Berg667503dd2009-07-07 03:56:11 +02008929 ASSERT_RDEV_LOCK(rdev);
8930
Johannes Berg362a4152009-05-24 16:43:15 +02008931 if (WARN_ON(!req))
8932 return 0;
8933
8934 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8935 if (!nest)
8936 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008937 for (i = 0; i < req->n_ssids; i++) {
8938 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8939 goto nla_put_failure;
8940 }
Johannes Berg362a4152009-05-24 16:43:15 +02008941 nla_nest_end(msg, nest);
8942
8943 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8944 if (!nest)
8945 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008946 for (i = 0; i < req->n_channels; i++) {
8947 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8948 goto nla_put_failure;
8949 }
Johannes Berg362a4152009-05-24 16:43:15 +02008950 nla_nest_end(msg, nest);
8951
David S. Miller9360ffd2012-03-29 04:41:26 -04008952 if (req->ie &&
8953 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8954 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008955
Sam Lefflered4737712012-10-11 21:03:31 -07008956 if (req->flags)
8957 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8958
Johannes Berg362a4152009-05-24 16:43:15 +02008959 return 0;
8960 nla_put_failure:
8961 return -ENOBUFS;
8962}
8963
Johannes Berga538e2d2009-06-16 19:56:42 +02008964static int nl80211_send_scan_msg(struct sk_buff *msg,
8965 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008966 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008967 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008968 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008969{
8970 void *hdr;
8971
Eric W. Biederman15e47302012-09-07 20:12:54 +00008972 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008973 if (!hdr)
8974 return -1;
8975
David S. Miller9360ffd2012-03-29 04:41:26 -04008976 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008977 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8978 wdev->netdev->ifindex)) ||
8979 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008980 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008981
Johannes Berg362a4152009-05-24 16:43:15 +02008982 /* ignore errors and send incomplete event anyway */
8983 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008984
8985 return genlmsg_end(msg, hdr);
8986
8987 nla_put_failure:
8988 genlmsg_cancel(msg, hdr);
8989 return -EMSGSIZE;
8990}
8991
Luciano Coelho807f8a82011-05-11 17:09:35 +03008992static int
8993nl80211_send_sched_scan_msg(struct sk_buff *msg,
8994 struct cfg80211_registered_device *rdev,
8995 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008996 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008997{
8998 void *hdr;
8999
Eric W. Biederman15e47302012-09-07 20:12:54 +00009000 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009001 if (!hdr)
9002 return -1;
9003
David S. Miller9360ffd2012-03-29 04:41:26 -04009004 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9005 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9006 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009007
9008 return genlmsg_end(msg, hdr);
9009
9010 nla_put_failure:
9011 genlmsg_cancel(msg, hdr);
9012 return -EMSGSIZE;
9013}
9014
Johannes Berga538e2d2009-06-16 19:56:42 +02009015void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009016 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009017{
9018 struct sk_buff *msg;
9019
Thomas Graf58050fc2012-06-28 03:57:45 +00009020 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009021 if (!msg)
9022 return;
9023
Johannes Bergfd014282012-06-18 19:17:03 +02009024 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009025 NL80211_CMD_TRIGGER_SCAN) < 0) {
9026 nlmsg_free(msg);
9027 return;
9028 }
9029
Johannes Berg463d0182009-07-14 00:33:35 +02009030 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9031 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009032}
9033
Johannes Berg2a519312009-02-10 21:25:55 +01009034void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009035 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009036{
9037 struct sk_buff *msg;
9038
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009039 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009040 if (!msg)
9041 return;
9042
Johannes Bergfd014282012-06-18 19:17:03 +02009043 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009044 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009045 nlmsg_free(msg);
9046 return;
9047 }
9048
Johannes Berg463d0182009-07-14 00:33:35 +02009049 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9050 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009051}
9052
9053void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009054 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009055{
9056 struct sk_buff *msg;
9057
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009058 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009059 if (!msg)
9060 return;
9061
Johannes Bergfd014282012-06-18 19:17:03 +02009062 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009063 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009064 nlmsg_free(msg);
9065 return;
9066 }
9067
Johannes Berg463d0182009-07-14 00:33:35 +02009068 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9069 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009070}
9071
Luciano Coelho807f8a82011-05-11 17:09:35 +03009072void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9073 struct net_device *netdev)
9074{
9075 struct sk_buff *msg;
9076
9077 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9078 if (!msg)
9079 return;
9080
9081 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9082 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9083 nlmsg_free(msg);
9084 return;
9085 }
9086
9087 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9088 nl80211_scan_mcgrp.id, GFP_KERNEL);
9089}
9090
9091void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9092 struct net_device *netdev, u32 cmd)
9093{
9094 struct sk_buff *msg;
9095
Thomas Graf58050fc2012-06-28 03:57:45 +00009096 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009097 if (!msg)
9098 return;
9099
9100 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9101 nlmsg_free(msg);
9102 return;
9103 }
9104
9105 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9106 nl80211_scan_mcgrp.id, GFP_KERNEL);
9107}
9108
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009109/*
9110 * This can happen on global regulatory changes or device specific settings
9111 * based on custom world regulatory domains.
9112 */
9113void nl80211_send_reg_change_event(struct regulatory_request *request)
9114{
9115 struct sk_buff *msg;
9116 void *hdr;
9117
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009119 if (!msg)
9120 return;
9121
9122 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9123 if (!hdr) {
9124 nlmsg_free(msg);
9125 return;
9126 }
9127
9128 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009129 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9130 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009131
David S. Miller9360ffd2012-03-29 04:41:26 -04009132 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9133 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9134 NL80211_REGDOM_TYPE_WORLD))
9135 goto nla_put_failure;
9136 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9137 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9138 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9139 goto nla_put_failure;
9140 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9141 request->intersect) {
9142 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9143 NL80211_REGDOM_TYPE_INTERSECTION))
9144 goto nla_put_failure;
9145 } else {
9146 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9147 NL80211_REGDOM_TYPE_COUNTRY) ||
9148 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9149 request->alpha2))
9150 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009151 }
9152
Johannes Bergf4173762012-12-03 18:23:37 +01009153 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009154 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9155 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009156
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009157 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009158
Johannes Bergbc43b282009-07-25 10:54:13 +02009159 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009160 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009161 GFP_ATOMIC);
9162 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009163
9164 return;
9165
9166nla_put_failure:
9167 genlmsg_cancel(msg, hdr);
9168 nlmsg_free(msg);
9169}
9170
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009171static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9172 struct net_device *netdev,
9173 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009174 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009175{
9176 struct sk_buff *msg;
9177 void *hdr;
9178
Johannes Berge6d6e342009-07-01 21:26:47 +02009179 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009180 if (!msg)
9181 return;
9182
9183 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9184 if (!hdr) {
9185 nlmsg_free(msg);
9186 return;
9187 }
9188
David S. Miller9360ffd2012-03-29 04:41:26 -04009189 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9190 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9191 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9192 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009193
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009194 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009195
Johannes Berg463d0182009-07-14 00:33:35 +02009196 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9197 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009198 return;
9199
9200 nla_put_failure:
9201 genlmsg_cancel(msg, hdr);
9202 nlmsg_free(msg);
9203}
9204
9205void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009206 struct net_device *netdev, const u8 *buf,
9207 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009208{
9209 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009210 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009211}
9212
9213void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9214 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009215 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009216{
Johannes Berge6d6e342009-07-01 21:26:47 +02009217 nl80211_send_mlme_event(rdev, netdev, buf, len,
9218 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009219}
9220
Jouni Malinen53b46b82009-03-27 20:53:56 +02009221void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009222 struct net_device *netdev, const u8 *buf,
9223 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009224{
9225 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009226 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009227}
9228
Jouni Malinen53b46b82009-03-27 20:53:56 +02009229void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9230 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009231 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009232{
9233 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009234 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009235}
9236
Johannes Berg947add32013-02-22 22:05:20 +01009237void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9238 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009239{
Johannes Berg947add32013-02-22 22:05:20 +01009240 struct wireless_dev *wdev = dev->ieee80211_ptr;
9241 struct wiphy *wiphy = wdev->wiphy;
9242 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009243
Johannes Berg947add32013-02-22 22:05:20 +01009244 trace_cfg80211_send_unprot_deauth(dev);
9245 nl80211_send_mlme_event(rdev, dev, buf, len,
9246 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009247}
Johannes Berg947add32013-02-22 22:05:20 +01009248EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9249
9250void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9251 size_t len)
9252{
9253 struct wireless_dev *wdev = dev->ieee80211_ptr;
9254 struct wiphy *wiphy = wdev->wiphy;
9255 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9256
9257 trace_cfg80211_send_unprot_disassoc(dev);
9258 nl80211_send_mlme_event(rdev, dev, buf, len,
9259 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9260}
9261EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009262
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009263static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9264 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009265 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009266{
9267 struct sk_buff *msg;
9268 void *hdr;
9269
Johannes Berge6d6e342009-07-01 21:26:47 +02009270 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009271 if (!msg)
9272 return;
9273
9274 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9275 if (!hdr) {
9276 nlmsg_free(msg);
9277 return;
9278 }
9279
David S. Miller9360ffd2012-03-29 04:41:26 -04009280 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9281 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9282 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9283 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9284 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009285
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009286 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009287
Johannes Berg463d0182009-07-14 00:33:35 +02009288 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9289 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009290 return;
9291
9292 nla_put_failure:
9293 genlmsg_cancel(msg, hdr);
9294 nlmsg_free(msg);
9295}
9296
9297void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009298 struct net_device *netdev, const u8 *addr,
9299 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009300{
9301 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009302 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009303}
9304
9305void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009306 struct net_device *netdev, const u8 *addr,
9307 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009308{
Johannes Berge6d6e342009-07-01 21:26:47 +02009309 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9310 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009311}
9312
Samuel Ortizb23aa672009-07-01 21:26:54 +02009313void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9314 struct net_device *netdev, const u8 *bssid,
9315 const u8 *req_ie, size_t req_ie_len,
9316 const u8 *resp_ie, size_t resp_ie_len,
9317 u16 status, gfp_t gfp)
9318{
9319 struct sk_buff *msg;
9320 void *hdr;
9321
Thomas Graf58050fc2012-06-28 03:57:45 +00009322 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009323 if (!msg)
9324 return;
9325
9326 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9327 if (!hdr) {
9328 nlmsg_free(msg);
9329 return;
9330 }
9331
David S. Miller9360ffd2012-03-29 04:41:26 -04009332 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9333 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9334 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9335 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9336 (req_ie &&
9337 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9338 (resp_ie &&
9339 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9340 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009341
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009342 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009343
Johannes Berg463d0182009-07-14 00:33:35 +02009344 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9345 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009346 return;
9347
9348 nla_put_failure:
9349 genlmsg_cancel(msg, hdr);
9350 nlmsg_free(msg);
9351
9352}
9353
9354void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9355 struct net_device *netdev, const u8 *bssid,
9356 const u8 *req_ie, size_t req_ie_len,
9357 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9358{
9359 struct sk_buff *msg;
9360 void *hdr;
9361
Thomas Graf58050fc2012-06-28 03:57:45 +00009362 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009363 if (!msg)
9364 return;
9365
9366 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9367 if (!hdr) {
9368 nlmsg_free(msg);
9369 return;
9370 }
9371
David S. Miller9360ffd2012-03-29 04:41:26 -04009372 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9373 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9374 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9375 (req_ie &&
9376 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9377 (resp_ie &&
9378 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9379 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009380
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009381 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009382
Johannes Berg463d0182009-07-14 00:33:35 +02009383 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9384 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009385 return;
9386
9387 nla_put_failure:
9388 genlmsg_cancel(msg, hdr);
9389 nlmsg_free(msg);
9390
9391}
9392
9393void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9394 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009395 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009396{
9397 struct sk_buff *msg;
9398 void *hdr;
9399
Thomas Graf58050fc2012-06-28 03:57:45 +00009400 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009401 if (!msg)
9402 return;
9403
9404 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9405 if (!hdr) {
9406 nlmsg_free(msg);
9407 return;
9408 }
9409
David S. Miller9360ffd2012-03-29 04:41:26 -04009410 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9411 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9412 (from_ap && reason &&
9413 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9414 (from_ap &&
9415 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9416 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9417 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009418
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009419 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009420
Johannes Berg463d0182009-07-14 00:33:35 +02009421 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9422 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009423 return;
9424
9425 nla_put_failure:
9426 genlmsg_cancel(msg, hdr);
9427 nlmsg_free(msg);
9428
9429}
9430
Johannes Berg04a773a2009-04-19 21:24:32 +02009431void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9432 struct net_device *netdev, const u8 *bssid,
9433 gfp_t gfp)
9434{
9435 struct sk_buff *msg;
9436 void *hdr;
9437
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009438 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009439 if (!msg)
9440 return;
9441
9442 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9443 if (!hdr) {
9444 nlmsg_free(msg);
9445 return;
9446 }
9447
David S. Miller9360ffd2012-03-29 04:41:26 -04009448 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9449 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9450 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9451 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009452
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009453 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009454
Johannes Berg463d0182009-07-14 00:33:35 +02009455 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9456 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009457 return;
9458
9459 nla_put_failure:
9460 genlmsg_cancel(msg, hdr);
9461 nlmsg_free(msg);
9462}
9463
Johannes Berg947add32013-02-22 22:05:20 +01009464void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9465 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009466{
Johannes Berg947add32013-02-22 22:05:20 +01009467 struct wireless_dev *wdev = dev->ieee80211_ptr;
9468 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009469 struct sk_buff *msg;
9470 void *hdr;
9471
Johannes Berg947add32013-02-22 22:05:20 +01009472 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9473 return;
9474
9475 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9476
Javier Cardonac93b5e72011-04-07 15:08:34 -07009477 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9478 if (!msg)
9479 return;
9480
9481 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9482 if (!hdr) {
9483 nlmsg_free(msg);
9484 return;
9485 }
9486
David S. Miller9360ffd2012-03-29 04:41:26 -04009487 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009488 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9489 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009490 (ie_len && ie &&
9491 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9492 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009493
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009494 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009495
9496 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9497 nl80211_mlme_mcgrp.id, gfp);
9498 return;
9499
9500 nla_put_failure:
9501 genlmsg_cancel(msg, hdr);
9502 nlmsg_free(msg);
9503}
Johannes Berg947add32013-02-22 22:05:20 +01009504EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009505
Jouni Malinena3b8b052009-03-27 21:59:49 +02009506void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9507 struct net_device *netdev, const u8 *addr,
9508 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009509 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009510{
9511 struct sk_buff *msg;
9512 void *hdr;
9513
Johannes Berge6d6e342009-07-01 21:26:47 +02009514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009515 if (!msg)
9516 return;
9517
9518 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9519 if (!hdr) {
9520 nlmsg_free(msg);
9521 return;
9522 }
9523
David S. Miller9360ffd2012-03-29 04:41:26 -04009524 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9525 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9526 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9527 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9528 (key_id != -1 &&
9529 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9530 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9531 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009532
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009533 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009534
Johannes Berg463d0182009-07-14 00:33:35 +02009535 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9536 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009537 return;
9538
9539 nla_put_failure:
9540 genlmsg_cancel(msg, hdr);
9541 nlmsg_free(msg);
9542}
9543
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009544void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9545 struct ieee80211_channel *channel_before,
9546 struct ieee80211_channel *channel_after)
9547{
9548 struct sk_buff *msg;
9549 void *hdr;
9550 struct nlattr *nl_freq;
9551
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009552 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009553 if (!msg)
9554 return;
9555
9556 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9557 if (!hdr) {
9558 nlmsg_free(msg);
9559 return;
9560 }
9561
9562 /*
9563 * Since we are applying the beacon hint to a wiphy we know its
9564 * wiphy_idx is valid
9565 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009566 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9567 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009568
9569 /* Before */
9570 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9571 if (!nl_freq)
9572 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009573 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009574 goto nla_put_failure;
9575 nla_nest_end(msg, nl_freq);
9576
9577 /* After */
9578 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9579 if (!nl_freq)
9580 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009581 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009582 goto nla_put_failure;
9583 nla_nest_end(msg, nl_freq);
9584
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009585 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009586
Johannes Berg463d0182009-07-14 00:33:35 +02009587 rcu_read_lock();
9588 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9589 GFP_ATOMIC);
9590 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009591
9592 return;
9593
9594nla_put_failure:
9595 genlmsg_cancel(msg, hdr);
9596 nlmsg_free(msg);
9597}
9598
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009599static void nl80211_send_remain_on_chan_event(
9600 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009601 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009602 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009603 unsigned int duration, gfp_t gfp)
9604{
9605 struct sk_buff *msg;
9606 void *hdr;
9607
9608 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9609 if (!msg)
9610 return;
9611
9612 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9613 if (!hdr) {
9614 nlmsg_free(msg);
9615 return;
9616 }
9617
David S. Miller9360ffd2012-03-29 04:41:26 -04009618 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009619 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9620 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009621 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009622 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009623 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9624 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009625 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9626 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009627
David S. Miller9360ffd2012-03-29 04:41:26 -04009628 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9629 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9630 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009631
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009632 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009633
9634 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9635 nl80211_mlme_mcgrp.id, gfp);
9636 return;
9637
9638 nla_put_failure:
9639 genlmsg_cancel(msg, hdr);
9640 nlmsg_free(msg);
9641}
9642
Johannes Berg947add32013-02-22 22:05:20 +01009643void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9644 struct ieee80211_channel *chan,
9645 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009646{
Johannes Berg947add32013-02-22 22:05:20 +01009647 struct wiphy *wiphy = wdev->wiphy;
9648 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9649
9650 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009651 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009652 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009653 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009654}
Johannes Berg947add32013-02-22 22:05:20 +01009655EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009656
Johannes Berg947add32013-02-22 22:05:20 +01009657void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9658 struct ieee80211_channel *chan,
9659 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009660{
Johannes Berg947add32013-02-22 22:05:20 +01009661 struct wiphy *wiphy = wdev->wiphy;
9662 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9663
9664 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009665 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009666 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009667}
Johannes Berg947add32013-02-22 22:05:20 +01009668EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009669
Johannes Berg947add32013-02-22 22:05:20 +01009670void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9671 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009672{
Johannes Berg947add32013-02-22 22:05:20 +01009673 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9674 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009675 struct sk_buff *msg;
9676
Johannes Berg947add32013-02-22 22:05:20 +01009677 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9678
Thomas Graf58050fc2012-06-28 03:57:45 +00009679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009680 if (!msg)
9681 return;
9682
John W. Linville66266b32012-03-15 13:25:41 -04009683 if (nl80211_send_station(msg, 0, 0, 0,
9684 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009685 nlmsg_free(msg);
9686 return;
9687 }
9688
9689 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9690 nl80211_mlme_mcgrp.id, gfp);
9691}
Johannes Berg947add32013-02-22 22:05:20 +01009692EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009693
Johannes Berg947add32013-02-22 22:05:20 +01009694void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009695{
Johannes Berg947add32013-02-22 22:05:20 +01009696 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9697 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009698 struct sk_buff *msg;
9699 void *hdr;
9700
Johannes Berg947add32013-02-22 22:05:20 +01009701 trace_cfg80211_del_sta(dev, mac_addr);
9702
Thomas Graf58050fc2012-06-28 03:57:45 +00009703 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009704 if (!msg)
9705 return;
9706
9707 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9708 if (!hdr) {
9709 nlmsg_free(msg);
9710 return;
9711 }
9712
David S. Miller9360ffd2012-03-29 04:41:26 -04009713 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9714 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9715 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009716
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009717 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009718
9719 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9720 nl80211_mlme_mcgrp.id, gfp);
9721 return;
9722
9723 nla_put_failure:
9724 genlmsg_cancel(msg, hdr);
9725 nlmsg_free(msg);
9726}
Johannes Berg947add32013-02-22 22:05:20 +01009727EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009728
Johannes Berg947add32013-02-22 22:05:20 +01009729void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9730 enum nl80211_connect_failed_reason reason,
9731 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309732{
Johannes Berg947add32013-02-22 22:05:20 +01009733 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9734 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309735 struct sk_buff *msg;
9736 void *hdr;
9737
9738 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9739 if (!msg)
9740 return;
9741
9742 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9743 if (!hdr) {
9744 nlmsg_free(msg);
9745 return;
9746 }
9747
9748 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9750 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9751 goto nla_put_failure;
9752
9753 genlmsg_end(msg, hdr);
9754
9755 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9756 nl80211_mlme_mcgrp.id, gfp);
9757 return;
9758
9759 nla_put_failure:
9760 genlmsg_cancel(msg, hdr);
9761 nlmsg_free(msg);
9762}
Johannes Berg947add32013-02-22 22:05:20 +01009763EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309764
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009765static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9766 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009767{
9768 struct wireless_dev *wdev = dev->ieee80211_ptr;
9769 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9770 struct sk_buff *msg;
9771 void *hdr;
9772 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009773 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009774
Eric W. Biederman15e47302012-09-07 20:12:54 +00009775 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009776 return false;
9777
9778 msg = nlmsg_new(100, gfp);
9779 if (!msg)
9780 return true;
9781
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009782 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009783 if (!hdr) {
9784 nlmsg_free(msg);
9785 return true;
9786 }
9787
David S. Miller9360ffd2012-03-29 04:41:26 -04009788 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9789 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9790 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9791 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009792
9793 err = genlmsg_end(msg, hdr);
9794 if (err < 0) {
9795 nlmsg_free(msg);
9796 return true;
9797 }
9798
Eric W. Biederman15e47302012-09-07 20:12:54 +00009799 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009800 return true;
9801
9802 nla_put_failure:
9803 genlmsg_cancel(msg, hdr);
9804 nlmsg_free(msg);
9805 return true;
9806}
9807
Johannes Berg947add32013-02-22 22:05:20 +01009808bool cfg80211_rx_spurious_frame(struct net_device *dev,
9809 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009810{
Johannes Berg947add32013-02-22 22:05:20 +01009811 struct wireless_dev *wdev = dev->ieee80211_ptr;
9812 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009813
Johannes Berg947add32013-02-22 22:05:20 +01009814 trace_cfg80211_rx_spurious_frame(dev, addr);
9815
9816 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9817 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9818 trace_cfg80211_return_bool(false);
9819 return false;
9820 }
9821 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9822 addr, gfp);
9823 trace_cfg80211_return_bool(ret);
9824 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009825}
Johannes Berg947add32013-02-22 22:05:20 +01009826EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9827
9828bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9829 const u8 *addr, gfp_t gfp)
9830{
9831 struct wireless_dev *wdev = dev->ieee80211_ptr;
9832 bool ret;
9833
9834 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9835
9836 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9837 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9838 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9839 trace_cfg80211_return_bool(false);
9840 return false;
9841 }
9842 ret = __nl80211_unexpected_frame(dev,
9843 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9844 addr, gfp);
9845 trace_cfg80211_return_bool(ret);
9846 return ret;
9847}
9848EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009849
Johannes Berg2e161f72010-08-12 15:38:38 +02009850int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009851 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009852 int freq, int sig_dbm,
9853 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009854{
Johannes Berg71bbc992012-06-15 15:30:18 +02009855 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009856 struct sk_buff *msg;
9857 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009858
9859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9860 if (!msg)
9861 return -ENOMEM;
9862
Johannes Berg2e161f72010-08-12 15:38:38 +02009863 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009864 if (!hdr) {
9865 nlmsg_free(msg);
9866 return -ENOMEM;
9867 }
9868
David S. Miller9360ffd2012-03-29 04:41:26 -04009869 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009870 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9871 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009872 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9873 (sig_dbm &&
9874 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9875 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9876 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009877
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009878 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009879
Eric W. Biederman15e47302012-09-07 20:12:54 +00009880 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009881
9882 nla_put_failure:
9883 genlmsg_cancel(msg, hdr);
9884 nlmsg_free(msg);
9885 return -ENOBUFS;
9886}
9887
Johannes Berg947add32013-02-22 22:05:20 +01009888void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9889 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009890{
Johannes Berg947add32013-02-22 22:05:20 +01009891 struct wiphy *wiphy = wdev->wiphy;
9892 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009893 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009894 struct sk_buff *msg;
9895 void *hdr;
9896
Johannes Berg947add32013-02-22 22:05:20 +01009897 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9898
Jouni Malinen026331c2010-02-15 12:53:10 +02009899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9900 if (!msg)
9901 return;
9902
Johannes Berg2e161f72010-08-12 15:38:38 +02009903 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009904 if (!hdr) {
9905 nlmsg_free(msg);
9906 return;
9907 }
9908
David S. Miller9360ffd2012-03-29 04:41:26 -04009909 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009910 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9911 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009912 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9913 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9914 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9915 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009916
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009917 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009918
9919 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9920 return;
9921
9922 nla_put_failure:
9923 genlmsg_cancel(msg, hdr);
9924 nlmsg_free(msg);
9925}
Johannes Berg947add32013-02-22 22:05:20 +01009926EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009927
Johannes Berg947add32013-02-22 22:05:20 +01009928void cfg80211_cqm_rssi_notify(struct net_device *dev,
9929 enum nl80211_cqm_rssi_threshold_event rssi_event,
9930 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009931{
Johannes Berg947add32013-02-22 22:05:20 +01009932 struct wireless_dev *wdev = dev->ieee80211_ptr;
9933 struct wiphy *wiphy = wdev->wiphy;
9934 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009935 struct sk_buff *msg;
9936 struct nlattr *pinfoattr;
9937 void *hdr;
9938
Johannes Berg947add32013-02-22 22:05:20 +01009939 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
9940
Thomas Graf58050fc2012-06-28 03:57:45 +00009941 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009942 if (!msg)
9943 return;
9944
9945 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9946 if (!hdr) {
9947 nlmsg_free(msg);
9948 return;
9949 }
9950
David S. Miller9360ffd2012-03-29 04:41:26 -04009951 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009952 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -04009953 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009954
9955 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9956 if (!pinfoattr)
9957 goto nla_put_failure;
9958
David S. Miller9360ffd2012-03-29 04:41:26 -04009959 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9960 rssi_event))
9961 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009962
9963 nla_nest_end(msg, pinfoattr);
9964
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009965 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009966
9967 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9968 nl80211_mlme_mcgrp.id, gfp);
9969 return;
9970
9971 nla_put_failure:
9972 genlmsg_cancel(msg, hdr);
9973 nlmsg_free(msg);
9974}
Johannes Berg947add32013-02-22 22:05:20 +01009975EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009976
Johannes Berg947add32013-02-22 22:05:20 +01009977static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9978 struct net_device *netdev, const u8 *bssid,
9979 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +02009980{
9981 struct sk_buff *msg;
9982 struct nlattr *rekey_attr;
9983 void *hdr;
9984
Thomas Graf58050fc2012-06-28 03:57:45 +00009985 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009986 if (!msg)
9987 return;
9988
9989 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9990 if (!hdr) {
9991 nlmsg_free(msg);
9992 return;
9993 }
9994
David S. Miller9360ffd2012-03-29 04:41:26 -04009995 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9996 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9997 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9998 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009999
10000 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10001 if (!rekey_attr)
10002 goto nla_put_failure;
10003
David S. Miller9360ffd2012-03-29 04:41:26 -040010004 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10005 NL80211_REPLAY_CTR_LEN, replay_ctr))
10006 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010007
10008 nla_nest_end(msg, rekey_attr);
10009
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010010 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010011
10012 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10013 nl80211_mlme_mcgrp.id, gfp);
10014 return;
10015
10016 nla_put_failure:
10017 genlmsg_cancel(msg, hdr);
10018 nlmsg_free(msg);
10019}
10020
Johannes Berg947add32013-02-22 22:05:20 +010010021void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10022 const u8 *replay_ctr, gfp_t gfp)
10023{
10024 struct wireless_dev *wdev = dev->ieee80211_ptr;
10025 struct wiphy *wiphy = wdev->wiphy;
10026 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10027
10028 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10029 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10030}
10031EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10032
10033static void
10034nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10035 struct net_device *netdev, int index,
10036 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010037{
10038 struct sk_buff *msg;
10039 struct nlattr *attr;
10040 void *hdr;
10041
Thomas Graf58050fc2012-06-28 03:57:45 +000010042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010043 if (!msg)
10044 return;
10045
10046 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10047 if (!hdr) {
10048 nlmsg_free(msg);
10049 return;
10050 }
10051
David S. Miller9360ffd2012-03-29 04:41:26 -040010052 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10053 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10054 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010055
10056 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10057 if (!attr)
10058 goto nla_put_failure;
10059
David S. Miller9360ffd2012-03-29 04:41:26 -040010060 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10061 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10062 (preauth &&
10063 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10064 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010065
10066 nla_nest_end(msg, attr);
10067
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010068 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010069
10070 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10071 nl80211_mlme_mcgrp.id, gfp);
10072 return;
10073
10074 nla_put_failure:
10075 genlmsg_cancel(msg, hdr);
10076 nlmsg_free(msg);
10077}
10078
Johannes Berg947add32013-02-22 22:05:20 +010010079void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10080 const u8 *bssid, bool preauth, gfp_t gfp)
10081{
10082 struct wireless_dev *wdev = dev->ieee80211_ptr;
10083 struct wiphy *wiphy = wdev->wiphy;
10084 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10085
10086 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10087 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10088}
10089EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10090
10091static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10092 struct net_device *netdev,
10093 struct cfg80211_chan_def *chandef,
10094 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010095{
10096 struct sk_buff *msg;
10097 void *hdr;
10098
Thomas Graf58050fc2012-06-28 03:57:45 +000010099 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010100 if (!msg)
10101 return;
10102
10103 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10104 if (!hdr) {
10105 nlmsg_free(msg);
10106 return;
10107 }
10108
Johannes Berg683b6d32012-11-08 21:25:48 +010010109 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10110 goto nla_put_failure;
10111
10112 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010113 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010114
10115 genlmsg_end(msg, hdr);
10116
10117 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10118 nl80211_mlme_mcgrp.id, gfp);
10119 return;
10120
10121 nla_put_failure:
10122 genlmsg_cancel(msg, hdr);
10123 nlmsg_free(msg);
10124}
10125
Johannes Berg947add32013-02-22 22:05:20 +010010126void cfg80211_ch_switch_notify(struct net_device *dev,
10127 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010128{
Johannes Berg947add32013-02-22 22:05:20 +010010129 struct wireless_dev *wdev = dev->ieee80211_ptr;
10130 struct wiphy *wiphy = wdev->wiphy;
10131 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10132
10133 trace_cfg80211_ch_switch_notify(dev, chandef);
10134
10135 wdev_lock(wdev);
10136
10137 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10138 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10139 goto out;
10140
10141 wdev->channel = chandef->chan;
10142 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10143out:
10144 wdev_unlock(wdev);
10145 return;
10146}
10147EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10148
10149void cfg80211_cqm_txe_notify(struct net_device *dev,
10150 const u8 *peer, u32 num_packets,
10151 u32 rate, u32 intvl, gfp_t gfp)
10152{
10153 struct wireless_dev *wdev = dev->ieee80211_ptr;
10154 struct wiphy *wiphy = wdev->wiphy;
10155 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010156 struct sk_buff *msg;
10157 struct nlattr *pinfoattr;
10158 void *hdr;
10159
10160 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10161 if (!msg)
10162 return;
10163
10164 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10165 if (!hdr) {
10166 nlmsg_free(msg);
10167 return;
10168 }
10169
10170 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010171 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010172 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10173 goto nla_put_failure;
10174
10175 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10176 if (!pinfoattr)
10177 goto nla_put_failure;
10178
10179 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10180 goto nla_put_failure;
10181
10182 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10183 goto nla_put_failure;
10184
10185 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10186 goto nla_put_failure;
10187
10188 nla_nest_end(msg, pinfoattr);
10189
10190 genlmsg_end(msg, hdr);
10191
10192 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10193 nl80211_mlme_mcgrp.id, gfp);
10194 return;
10195
10196 nla_put_failure:
10197 genlmsg_cancel(msg, hdr);
10198 nlmsg_free(msg);
10199}
Johannes Berg947add32013-02-22 22:05:20 +010010200EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010201
10202void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010203nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10204 struct cfg80211_chan_def *chandef,
10205 enum nl80211_radar_event event,
10206 struct net_device *netdev, gfp_t gfp)
10207{
10208 struct sk_buff *msg;
10209 void *hdr;
10210
10211 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10212 if (!msg)
10213 return;
10214
10215 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10216 if (!hdr) {
10217 nlmsg_free(msg);
10218 return;
10219 }
10220
10221 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10222 goto nla_put_failure;
10223
10224 /* NOP and radar events don't need a netdev parameter */
10225 if (netdev) {
10226 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10227
10228 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10229 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10230 goto nla_put_failure;
10231 }
10232
10233 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10234 goto nla_put_failure;
10235
10236 if (nl80211_send_chandef(msg, chandef))
10237 goto nla_put_failure;
10238
10239 if (genlmsg_end(msg, hdr) < 0) {
10240 nlmsg_free(msg);
10241 return;
10242 }
10243
10244 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10245 nl80211_mlme_mcgrp.id, gfp);
10246 return;
10247
10248 nla_put_failure:
10249 genlmsg_cancel(msg, hdr);
10250 nlmsg_free(msg);
10251}
10252
Johannes Berg947add32013-02-22 22:05:20 +010010253void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10254 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010255{
Johannes Berg947add32013-02-22 22:05:20 +010010256 struct wireless_dev *wdev = dev->ieee80211_ptr;
10257 struct wiphy *wiphy = wdev->wiphy;
10258 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010259 struct sk_buff *msg;
10260 struct nlattr *pinfoattr;
10261 void *hdr;
10262
Johannes Berg947add32013-02-22 22:05:20 +010010263 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10264
Thomas Graf58050fc2012-06-28 03:57:45 +000010265 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010266 if (!msg)
10267 return;
10268
10269 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10270 if (!hdr) {
10271 nlmsg_free(msg);
10272 return;
10273 }
10274
David S. Miller9360ffd2012-03-29 04:41:26 -040010275 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010276 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010277 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10278 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010279
10280 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10281 if (!pinfoattr)
10282 goto nla_put_failure;
10283
David S. Miller9360ffd2012-03-29 04:41:26 -040010284 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10285 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010286
10287 nla_nest_end(msg, pinfoattr);
10288
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010289 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010290
10291 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10292 nl80211_mlme_mcgrp.id, gfp);
10293 return;
10294
10295 nla_put_failure:
10296 genlmsg_cancel(msg, hdr);
10297 nlmsg_free(msg);
10298}
Johannes Berg947add32013-02-22 22:05:20 +010010299EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010300
Johannes Berg7f6cf312011-11-04 11:18:15 +010010301void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10302 u64 cookie, bool acked, gfp_t gfp)
10303{
10304 struct wireless_dev *wdev = dev->ieee80211_ptr;
10305 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10306 struct sk_buff *msg;
10307 void *hdr;
10308 int err;
10309
Beni Lev4ee3e062012-08-27 12:49:39 +030010310 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10311
Thomas Graf58050fc2012-06-28 03:57:45 +000010312 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010313
Johannes Berg7f6cf312011-11-04 11:18:15 +010010314 if (!msg)
10315 return;
10316
10317 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10318 if (!hdr) {
10319 nlmsg_free(msg);
10320 return;
10321 }
10322
David S. Miller9360ffd2012-03-29 04:41:26 -040010323 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10324 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10325 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10326 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10327 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10328 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010329
10330 err = genlmsg_end(msg, hdr);
10331 if (err < 0) {
10332 nlmsg_free(msg);
10333 return;
10334 }
10335
10336 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10337 nl80211_mlme_mcgrp.id, gfp);
10338 return;
10339
10340 nla_put_failure:
10341 genlmsg_cancel(msg, hdr);
10342 nlmsg_free(msg);
10343}
10344EXPORT_SYMBOL(cfg80211_probe_status);
10345
Johannes Berg5e760232011-11-04 11:18:17 +010010346void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10347 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010348 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010349{
10350 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10351 struct sk_buff *msg;
10352 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010353 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010354
Beni Lev4ee3e062012-08-27 12:49:39 +030010355 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10356
Ben Greear37c73b52012-10-26 14:49:25 -070010357 spin_lock_bh(&rdev->beacon_registrations_lock);
10358 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10359 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10360 if (!msg) {
10361 spin_unlock_bh(&rdev->beacon_registrations_lock);
10362 return;
10363 }
Johannes Berg5e760232011-11-04 11:18:17 +010010364
Ben Greear37c73b52012-10-26 14:49:25 -070010365 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10366 if (!hdr)
10367 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010368
Ben Greear37c73b52012-10-26 14:49:25 -070010369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10370 (freq &&
10371 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10372 (sig_dbm &&
10373 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10374 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10375 goto nla_put_failure;
10376
10377 genlmsg_end(msg, hdr);
10378
10379 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010380 }
Ben Greear37c73b52012-10-26 14:49:25 -070010381 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010382 return;
10383
10384 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010385 spin_unlock_bh(&rdev->beacon_registrations_lock);
10386 if (hdr)
10387 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010388 nlmsg_free(msg);
10389}
10390EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10391
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010392#ifdef CONFIG_PM
10393void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10394 struct cfg80211_wowlan_wakeup *wakeup,
10395 gfp_t gfp)
10396{
10397 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10398 struct sk_buff *msg;
10399 void *hdr;
10400 int err, size = 200;
10401
10402 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10403
10404 if (wakeup)
10405 size += wakeup->packet_present_len;
10406
10407 msg = nlmsg_new(size, gfp);
10408 if (!msg)
10409 return;
10410
10411 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10412 if (!hdr)
10413 goto free_msg;
10414
10415 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10416 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10417 goto free_msg;
10418
10419 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10420 wdev->netdev->ifindex))
10421 goto free_msg;
10422
10423 if (wakeup) {
10424 struct nlattr *reasons;
10425
10426 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10427
10428 if (wakeup->disconnect &&
10429 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10430 goto free_msg;
10431 if (wakeup->magic_pkt &&
10432 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10433 goto free_msg;
10434 if (wakeup->gtk_rekey_failure &&
10435 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10436 goto free_msg;
10437 if (wakeup->eap_identity_req &&
10438 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10439 goto free_msg;
10440 if (wakeup->four_way_handshake &&
10441 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10442 goto free_msg;
10443 if (wakeup->rfkill_release &&
10444 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10445 goto free_msg;
10446
10447 if (wakeup->pattern_idx >= 0 &&
10448 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10449 wakeup->pattern_idx))
10450 goto free_msg;
10451
Johannes Berg2a0e0472013-01-23 22:57:40 +010010452 if (wakeup->tcp_match)
10453 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10454
10455 if (wakeup->tcp_connlost)
10456 nla_put_flag(msg,
10457 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10458
10459 if (wakeup->tcp_nomoretokens)
10460 nla_put_flag(msg,
10461 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10462
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010463 if (wakeup->packet) {
10464 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10465 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10466
10467 if (!wakeup->packet_80211) {
10468 pkt_attr =
10469 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10470 len_attr =
10471 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10472 }
10473
10474 if (wakeup->packet_len &&
10475 nla_put_u32(msg, len_attr, wakeup->packet_len))
10476 goto free_msg;
10477
10478 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10479 wakeup->packet))
10480 goto free_msg;
10481 }
10482
10483 nla_nest_end(msg, reasons);
10484 }
10485
10486 err = genlmsg_end(msg, hdr);
10487 if (err < 0)
10488 goto free_msg;
10489
10490 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10491 nl80211_mlme_mcgrp.id, gfp);
10492 return;
10493
10494 free_msg:
10495 nlmsg_free(msg);
10496}
10497EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10498#endif
10499
Jouni Malinen3475b092012-11-16 22:49:57 +020010500void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10501 enum nl80211_tdls_operation oper,
10502 u16 reason_code, gfp_t gfp)
10503{
10504 struct wireless_dev *wdev = dev->ieee80211_ptr;
10505 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10506 struct sk_buff *msg;
10507 void *hdr;
10508 int err;
10509
10510 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10511 reason_code);
10512
10513 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10514 if (!msg)
10515 return;
10516
10517 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10518 if (!hdr) {
10519 nlmsg_free(msg);
10520 return;
10521 }
10522
10523 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10524 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10525 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10526 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10527 (reason_code > 0 &&
10528 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10529 goto nla_put_failure;
10530
10531 err = genlmsg_end(msg, hdr);
10532 if (err < 0) {
10533 nlmsg_free(msg);
10534 return;
10535 }
10536
10537 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10538 nl80211_mlme_mcgrp.id, gfp);
10539 return;
10540
10541 nla_put_failure:
10542 genlmsg_cancel(msg, hdr);
10543 nlmsg_free(msg);
10544}
10545EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10546
Jouni Malinen026331c2010-02-15 12:53:10 +020010547static int nl80211_netlink_notify(struct notifier_block * nb,
10548 unsigned long state,
10549 void *_notify)
10550{
10551 struct netlink_notify *notify = _notify;
10552 struct cfg80211_registered_device *rdev;
10553 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010554 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010555
10556 if (state != NETLINK_URELEASE)
10557 return NOTIFY_DONE;
10558
10559 rcu_read_lock();
10560
Johannes Berg5e760232011-11-04 11:18:17 +010010561 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010562 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010563 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010564
10565 spin_lock_bh(&rdev->beacon_registrations_lock);
10566 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10567 list) {
10568 if (reg->nlportid == notify->portid) {
10569 list_del(&reg->list);
10570 kfree(reg);
10571 break;
10572 }
10573 }
10574 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010575 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010576
10577 rcu_read_unlock();
10578
10579 return NOTIFY_DONE;
10580}
10581
10582static struct notifier_block nl80211_netlink_notifier = {
10583 .notifier_call = nl80211_netlink_notify,
10584};
10585
Jouni Malinen355199e2013-02-27 17:14:27 +020010586void cfg80211_ft_event(struct net_device *netdev,
10587 struct cfg80211_ft_event_params *ft_event)
10588{
10589 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10590 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10591 struct sk_buff *msg;
10592 void *hdr;
10593 int err;
10594
10595 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10596
10597 if (!ft_event->target_ap)
10598 return;
10599
10600 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10601 if (!msg)
10602 return;
10603
10604 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10605 if (!hdr) {
10606 nlmsg_free(msg);
10607 return;
10608 }
10609
10610 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10611 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10612 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10613 if (ft_event->ies)
10614 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10615 if (ft_event->ric_ies)
10616 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10617 ft_event->ric_ies);
10618
10619 err = genlmsg_end(msg, hdr);
10620 if (err < 0) {
10621 nlmsg_free(msg);
10622 return;
10623 }
10624
10625 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10626 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10627}
10628EXPORT_SYMBOL(cfg80211_ft_event);
10629
Johannes Berg55682962007-09-20 13:09:35 -040010630/* initialisation/exit functions */
10631
10632int nl80211_init(void)
10633{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010634 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010635
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010636 err = genl_register_family_with_ops(&nl80211_fam,
10637 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010638 if (err)
10639 return err;
10640
Johannes Berg55682962007-09-20 13:09:35 -040010641 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10642 if (err)
10643 goto err_out;
10644
Johannes Berg2a519312009-02-10 21:25:55 +010010645 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10646 if (err)
10647 goto err_out;
10648
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010649 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10650 if (err)
10651 goto err_out;
10652
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010653 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10654 if (err)
10655 goto err_out;
10656
Johannes Bergaff89a92009-07-01 21:26:51 +020010657#ifdef CONFIG_NL80211_TESTMODE
10658 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10659 if (err)
10660 goto err_out;
10661#endif
10662
Jouni Malinen026331c2010-02-15 12:53:10 +020010663 err = netlink_register_notifier(&nl80211_netlink_notifier);
10664 if (err)
10665 goto err_out;
10666
Johannes Berg55682962007-09-20 13:09:35 -040010667 return 0;
10668 err_out:
10669 genl_unregister_family(&nl80211_fam);
10670 return err;
10671}
10672
10673void nl80211_exit(void)
10674{
Jouni Malinen026331c2010-02-15 12:53:10 +020010675 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010676 genl_unregister_family(&nl80211_fam);
10677}