blob: c73a4dd4e19f2cb162b8ce409578147e83054a8c [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 Malinen36aedc902008-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 Berg55682962007-09-20 13:09:35 -0400374};
375
Johannes Berge31b8212010-10-05 19:39:30 +0200376/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000377static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200378 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200379 [NL80211_KEY_IDX] = { .type = NLA_U8 },
380 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200381 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200382 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
383 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200384 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100385 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
386};
387
388/* policy for the key default flags */
389static const struct nla_policy
390nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
391 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
392 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200393};
394
Johannes Bergff1b6e62011-05-04 15:37:28 +0200395/* policy for WoWLAN attributes */
396static const struct nla_policy
397nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
398 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
399 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
400 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
401 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200402 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
403 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
404 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
405 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100406 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
407};
408
409static const struct nla_policy
410nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
411 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
412 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
413 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
414 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
415 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
416 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
417 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
418 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
419 },
420 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
421 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
422 },
423 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
424 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
425 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200426};
427
Johannes Berge5497d72011-07-05 16:35:40 +0200428/* policy for GTK rekey offload attributes */
429static const struct nla_policy
430nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
431 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
432 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
433 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
434};
435
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300436static const struct nla_policy
437nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200438 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300439 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700440 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300441};
442
Holger Schuriga0438972009-11-11 11:30:02 +0100443/* ifidx get helper */
444static int nl80211_get_ifidx(struct netlink_callback *cb)
445{
446 int res;
447
448 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
449 nl80211_fam.attrbuf, nl80211_fam.maxattr,
450 nl80211_policy);
451 if (res)
452 return res;
453
454 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
455 return -EINVAL;
456
457 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
458 if (!res)
459 return -EINVAL;
460 return res;
461}
462
Johannes Berg67748892010-10-04 21:14:06 +0200463static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
464 struct netlink_callback *cb,
465 struct cfg80211_registered_device **rdev,
466 struct net_device **dev)
467{
468 int ifidx = cb->args[0];
469 int err;
470
471 if (!ifidx)
472 ifidx = nl80211_get_ifidx(cb);
473 if (ifidx < 0)
474 return ifidx;
475
476 cb->args[0] = ifidx;
477
478 rtnl_lock();
479
480 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
481 if (!*dev) {
482 err = -ENODEV;
483 goto out_rtnl;
484 }
485
486 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100487 if (IS_ERR(*rdev)) {
488 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200489 goto out_rtnl;
490 }
491
492 return 0;
493 out_rtnl:
494 rtnl_unlock();
495 return err;
496}
497
498static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
499{
500 cfg80211_unlock_rdev(rdev);
501 rtnl_unlock();
502}
503
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100504/* IE validation */
505static bool is_valid_ie_attr(const struct nlattr *attr)
506{
507 const u8 *pos;
508 int len;
509
510 if (!attr)
511 return true;
512
513 pos = nla_data(attr);
514 len = nla_len(attr);
515
516 while (len) {
517 u8 elemlen;
518
519 if (len < 2)
520 return false;
521 len -= 2;
522
523 elemlen = pos[1];
524 if (elemlen > len)
525 return false;
526
527 len -= elemlen;
528 pos += 2 + elemlen;
529 }
530
531 return true;
532}
533
Johannes Berg55682962007-09-20 13:09:35 -0400534/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000535static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400536 int flags, u8 cmd)
537{
538 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000539 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400540}
541
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400542static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100543 struct ieee80211_channel *chan,
544 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400545{
David S. Miller9360ffd2012-03-29 04:41:26 -0400546 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
547 chan->center_freq))
548 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400549
David S. Miller9360ffd2012-03-29 04:41:26 -0400550 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
551 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
552 goto nla_put_failure;
553 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
554 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
555 goto nla_put_failure;
556 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
557 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
558 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100559 if (chan->flags & IEEE80211_CHAN_RADAR) {
560 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
561 goto nla_put_failure;
562 if (large) {
563 u32 time;
564
565 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
566
567 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
568 chan->dfs_state))
569 goto nla_put_failure;
570 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
571 time))
572 goto nla_put_failure;
573 }
574 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400575
David S. Miller9360ffd2012-03-29 04:41:26 -0400576 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
577 DBM_TO_MBM(chan->max_power)))
578 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400579
580 return 0;
581
582 nla_put_failure:
583 return -ENOBUFS;
584}
585
Johannes Berg55682962007-09-20 13:09:35 -0400586/* netlink command implementations */
587
Johannes Bergb9454e82009-07-08 13:29:08 +0200588struct key_parse {
589 struct key_params p;
590 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200591 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200592 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100593 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200594};
595
596static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
597{
598 struct nlattr *tb[NL80211_KEY_MAX + 1];
599 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
600 nl80211_key_policy);
601 if (err)
602 return err;
603
604 k->def = !!tb[NL80211_KEY_DEFAULT];
605 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
606
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100607 if (k->def) {
608 k->def_uni = true;
609 k->def_multi = true;
610 }
611 if (k->defmgmt)
612 k->def_multi = true;
613
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 if (tb[NL80211_KEY_IDX])
615 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
616
617 if (tb[NL80211_KEY_DATA]) {
618 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
619 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
620 }
621
622 if (tb[NL80211_KEY_SEQ]) {
623 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
624 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
625 }
626
627 if (tb[NL80211_KEY_CIPHER])
628 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
629
Johannes Berge31b8212010-10-05 19:39:30 +0200630 if (tb[NL80211_KEY_TYPE]) {
631 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
632 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
633 return -EINVAL;
634 }
635
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100636 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
637 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100638 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
639 tb[NL80211_KEY_DEFAULT_TYPES],
640 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100641 if (err)
642 return err;
643
644 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
645 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
646 }
647
Johannes Bergb9454e82009-07-08 13:29:08 +0200648 return 0;
649}
650
651static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
652{
653 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
654 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
655 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
656 }
657
658 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
659 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
660 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
661 }
662
663 if (info->attrs[NL80211_ATTR_KEY_IDX])
664 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
665
666 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
667 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
668
669 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
670 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
671
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100672 if (k->def) {
673 k->def_uni = true;
674 k->def_multi = true;
675 }
676 if (k->defmgmt)
677 k->def_multi = true;
678
Johannes Berge31b8212010-10-05 19:39:30 +0200679 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
680 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
681 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
682 return -EINVAL;
683 }
684
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100685 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
686 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
687 int err = nla_parse_nested(
688 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
689 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
690 nl80211_key_default_policy);
691 if (err)
692 return err;
693
694 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
695 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
696 }
697
Johannes Bergb9454e82009-07-08 13:29:08 +0200698 return 0;
699}
700
701static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
702{
703 int err;
704
705 memset(k, 0, sizeof(*k));
706 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200707 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200708
709 if (info->attrs[NL80211_ATTR_KEY])
710 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
711 else
712 err = nl80211_parse_key_old(info, k);
713
714 if (err)
715 return err;
716
717 if (k->def && k->defmgmt)
718 return -EINVAL;
719
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100720 if (k->defmgmt) {
721 if (k->def_uni || !k->def_multi)
722 return -EINVAL;
723 }
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 if (k->idx != -1) {
726 if (k->defmgmt) {
727 if (k->idx < 4 || k->idx > 5)
728 return -EINVAL;
729 } else if (k->def) {
730 if (k->idx < 0 || k->idx > 3)
731 return -EINVAL;
732 } else {
733 if (k->idx < 0 || k->idx > 5)
734 return -EINVAL;
735 }
736 }
737
738 return 0;
739}
740
Johannes Bergfffd0932009-07-08 14:22:54 +0200741static struct cfg80211_cached_keys *
742nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530743 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200744{
745 struct key_parse parse;
746 struct nlattr *key;
747 struct cfg80211_cached_keys *result;
748 int rem, err, def = 0;
749
750 result = kzalloc(sizeof(*result), GFP_KERNEL);
751 if (!result)
752 return ERR_PTR(-ENOMEM);
753
754 result->def = -1;
755 result->defmgmt = -1;
756
757 nla_for_each_nested(key, keys, rem) {
758 memset(&parse, 0, sizeof(parse));
759 parse.idx = -1;
760
761 err = nl80211_parse_key_new(key, &parse);
762 if (err)
763 goto error;
764 err = -EINVAL;
765 if (!parse.p.key)
766 goto error;
767 if (parse.idx < 0 || parse.idx > 4)
768 goto error;
769 if (parse.def) {
770 if (def)
771 goto error;
772 def = 1;
773 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100774 if (!parse.def_uni || !parse.def_multi)
775 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200776 } else if (parse.defmgmt)
777 goto error;
778 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200779 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200780 if (err)
781 goto error;
782 result->params[parse.idx].cipher = parse.p.cipher;
783 result->params[parse.idx].key_len = parse.p.key_len;
784 result->params[parse.idx].key = result->data[parse.idx];
785 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530786
787 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
788 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
789 if (no_ht)
790 *no_ht = true;
791 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200792 }
793
794 return result;
795 error:
796 kfree(result);
797 return ERR_PTR(err);
798}
799
800static int nl80211_key_allowed(struct wireless_dev *wdev)
801{
802 ASSERT_WDEV_LOCK(wdev);
803
Johannes Bergfffd0932009-07-08 14:22:54 +0200804 switch (wdev->iftype) {
805 case NL80211_IFTYPE_AP:
806 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200807 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700808 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200809 break;
810 case NL80211_IFTYPE_ADHOC:
811 if (!wdev->current_bss)
812 return -ENOLINK;
813 break;
814 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200815 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200816 if (wdev->sme_state != CFG80211_SME_CONNECTED)
817 return -ENOLINK;
818 break;
819 default:
820 return -EINVAL;
821 }
822
823 return 0;
824}
825
Johannes Berg7527a782011-05-13 10:58:57 +0200826static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
827{
828 struct nlattr *nl_modes = nla_nest_start(msg, attr);
829 int i;
830
831 if (!nl_modes)
832 goto nla_put_failure;
833
834 i = 0;
835 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400836 if ((ifmodes & 1) && nla_put_flag(msg, i))
837 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200838 ifmodes >>= 1;
839 i++;
840 }
841
842 nla_nest_end(msg, nl_modes);
843 return 0;
844
845nla_put_failure:
846 return -ENOBUFS;
847}
848
849static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100850 struct sk_buff *msg,
851 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200852{
853 struct nlattr *nl_combis;
854 int i, j;
855
856 nl_combis = nla_nest_start(msg,
857 NL80211_ATTR_INTERFACE_COMBINATIONS);
858 if (!nl_combis)
859 goto nla_put_failure;
860
861 for (i = 0; i < wiphy->n_iface_combinations; i++) {
862 const struct ieee80211_iface_combination *c;
863 struct nlattr *nl_combi, *nl_limits;
864
865 c = &wiphy->iface_combinations[i];
866
867 nl_combi = nla_nest_start(msg, i + 1);
868 if (!nl_combi)
869 goto nla_put_failure;
870
871 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
872 if (!nl_limits)
873 goto nla_put_failure;
874
875 for (j = 0; j < c->n_limits; j++) {
876 struct nlattr *nl_limit;
877
878 nl_limit = nla_nest_start(msg, j + 1);
879 if (!nl_limit)
880 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400881 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
882 c->limits[j].max))
883 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200884 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
885 c->limits[j].types))
886 goto nla_put_failure;
887 nla_nest_end(msg, nl_limit);
888 }
889
890 nla_nest_end(msg, nl_limits);
891
David S. Miller9360ffd2012-03-29 04:41:26 -0400892 if (c->beacon_int_infra_match &&
893 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
894 goto nla_put_failure;
895 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
896 c->num_different_channels) ||
897 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
898 c->max_interfaces))
899 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100900 if (large &&
901 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
902 c->radar_detect_widths))
903 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200904
905 nla_nest_end(msg, nl_combi);
906 }
907
908 nla_nest_end(msg, nl_combis);
909
910 return 0;
911nla_put_failure:
912 return -ENOBUFS;
913}
914
Johannes Berg3713b4e2013-02-14 16:19:38 +0100915#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100916static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
917 struct sk_buff *msg)
918{
919 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
920 struct nlattr *nl_tcp;
921
922 if (!tcp)
923 return 0;
924
925 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
926 if (!nl_tcp)
927 return -ENOBUFS;
928
929 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
930 tcp->data_payload_max))
931 return -ENOBUFS;
932
933 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
934 tcp->data_payload_max))
935 return -ENOBUFS;
936
937 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
938 return -ENOBUFS;
939
940 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
941 sizeof(*tcp->tok), tcp->tok))
942 return -ENOBUFS;
943
944 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
945 tcp->data_interval_max))
946 return -ENOBUFS;
947
948 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
949 tcp->wake_payload_max))
950 return -ENOBUFS;
951
952 nla_nest_end(msg, nl_tcp);
953 return 0;
954}
955
Johannes Berg3713b4e2013-02-14 16:19:38 +0100956static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100957 struct cfg80211_registered_device *dev,
958 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100959{
960 struct nlattr *nl_wowlan;
961
962 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
963 return 0;
964
965 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
966 if (!nl_wowlan)
967 return -ENOBUFS;
968
969 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
970 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
971 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
972 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
973 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
974 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
975 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
976 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
977 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
978 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
979 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
980 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
981 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
982 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
983 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
984 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
985 return -ENOBUFS;
986
987 if (dev->wiphy.wowlan.n_patterns) {
988 struct nl80211_wowlan_pattern_support pat = {
989 .max_patterns = dev->wiphy.wowlan.n_patterns,
990 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
991 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
992 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
993 };
994
995 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
996 sizeof(pat), &pat))
997 return -ENOBUFS;
998 }
999
Johannes Bergb56cf722013-02-20 01:02:38 +01001000 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1001 return -ENOBUFS;
1002
Johannes Berg3713b4e2013-02-14 16:19:38 +01001003 nla_nest_end(msg, nl_wowlan);
1004
1005 return 0;
1006}
1007#endif
1008
1009static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1010 struct ieee80211_supported_band *sband)
1011{
1012 struct nlattr *nl_rates, *nl_rate;
1013 struct ieee80211_rate *rate;
1014 int i;
1015
1016 /* add HT info */
1017 if (sband->ht_cap.ht_supported &&
1018 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1019 sizeof(sband->ht_cap.mcs),
1020 &sband->ht_cap.mcs) ||
1021 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1022 sband->ht_cap.cap) ||
1023 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1024 sband->ht_cap.ampdu_factor) ||
1025 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1026 sband->ht_cap.ampdu_density)))
1027 return -ENOBUFS;
1028
1029 /* add VHT info */
1030 if (sband->vht_cap.vht_supported &&
1031 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1032 sizeof(sband->vht_cap.vht_mcs),
1033 &sband->vht_cap.vht_mcs) ||
1034 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1035 sband->vht_cap.cap)))
1036 return -ENOBUFS;
1037
1038 /* add bitrates */
1039 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1040 if (!nl_rates)
1041 return -ENOBUFS;
1042
1043 for (i = 0; i < sband->n_bitrates; i++) {
1044 nl_rate = nla_nest_start(msg, i);
1045 if (!nl_rate)
1046 return -ENOBUFS;
1047
1048 rate = &sband->bitrates[i];
1049 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1050 rate->bitrate))
1051 return -ENOBUFS;
1052 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1053 nla_put_flag(msg,
1054 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1055 return -ENOBUFS;
1056
1057 nla_nest_end(msg, nl_rate);
1058 }
1059
1060 nla_nest_end(msg, nl_rates);
1061
1062 return 0;
1063}
1064
1065static int
1066nl80211_send_mgmt_stypes(struct sk_buff *msg,
1067 const struct ieee80211_txrx_stypes *mgmt_stypes)
1068{
1069 u16 stypes;
1070 struct nlattr *nl_ftypes, *nl_ifs;
1071 enum nl80211_iftype ift;
1072 int i;
1073
1074 if (!mgmt_stypes)
1075 return 0;
1076
1077 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1078 if (!nl_ifs)
1079 return -ENOBUFS;
1080
1081 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1082 nl_ftypes = nla_nest_start(msg, ift);
1083 if (!nl_ftypes)
1084 return -ENOBUFS;
1085 i = 0;
1086 stypes = mgmt_stypes[ift].tx;
1087 while (stypes) {
1088 if ((stypes & 1) &&
1089 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1090 (i << 4) | IEEE80211_FTYPE_MGMT))
1091 return -ENOBUFS;
1092 stypes >>= 1;
1093 i++;
1094 }
1095 nla_nest_end(msg, nl_ftypes);
1096 }
1097
1098 nla_nest_end(msg, nl_ifs);
1099
1100 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1101 if (!nl_ifs)
1102 return -ENOBUFS;
1103
1104 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1105 nl_ftypes = nla_nest_start(msg, ift);
1106 if (!nl_ftypes)
1107 return -ENOBUFS;
1108 i = 0;
1109 stypes = mgmt_stypes[ift].rx;
1110 while (stypes) {
1111 if ((stypes & 1) &&
1112 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1113 (i << 4) | IEEE80211_FTYPE_MGMT))
1114 return -ENOBUFS;
1115 stypes >>= 1;
1116 i++;
1117 }
1118 nla_nest_end(msg, nl_ftypes);
1119 }
1120 nla_nest_end(msg, nl_ifs);
1121
1122 return 0;
1123}
1124
1125static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1126 struct sk_buff *msg, u32 portid, u32 seq,
1127 int flags, bool split, long *split_start,
1128 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001129{
1130 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001131 struct nlattr *nl_bands, *nl_band;
1132 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001133 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001134 enum ieee80211_band band;
1135 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001136 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001137 const struct ieee80211_txrx_stypes *mgmt_stypes =
1138 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001139 long start = 0, start_chan = 0, start_band = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001140
Eric W. Biederman15e47302012-09-07 20:12:54 +00001141 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001142 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 return -ENOBUFS;
1144
1145 /* allow always using the variables */
1146 if (!split) {
1147 split_start = &start;
1148 band_start = &start_band;
1149 chan_start = &start_chan;
1150 }
Johannes Berg55682962007-09-20 13:09:35 -04001151
David S. Miller9360ffd2012-03-29 04:41:26 -04001152 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001153 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1154 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001155 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001156 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001157 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001158
Johannes Berg3713b4e2013-02-14 16:19:38 +01001159 switch (*split_start) {
1160 case 0:
1161 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1162 dev->wiphy.retry_short) ||
1163 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1164 dev->wiphy.retry_long) ||
1165 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1166 dev->wiphy.frag_threshold) ||
1167 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1168 dev->wiphy.rts_threshold) ||
1169 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1170 dev->wiphy.coverage_class) ||
1171 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1172 dev->wiphy.max_scan_ssids) ||
1173 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1174 dev->wiphy.max_sched_scan_ssids) ||
1175 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1176 dev->wiphy.max_scan_ie_len) ||
1177 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1178 dev->wiphy.max_sched_scan_ie_len) ||
1179 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1180 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001181 goto nla_put_failure;
1182
Johannes Berg3713b4e2013-02-14 16:19:38 +01001183 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1184 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1185 goto nla_put_failure;
1186 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1187 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1188 goto nla_put_failure;
1189 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1190 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1191 goto nla_put_failure;
1192 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1193 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1194 goto nla_put_failure;
1195 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1196 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1197 goto nla_put_failure;
1198 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1199 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001200 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001201
Johannes Berg3713b4e2013-02-14 16:19:38 +01001202 (*split_start)++;
1203 if (split)
1204 break;
1205 case 1:
1206 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1207 sizeof(u32) * dev->wiphy.n_cipher_suites,
1208 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001209 goto nla_put_failure;
1210
Johannes Berg3713b4e2013-02-14 16:19:38 +01001211 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1212 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001213 goto nla_put_failure;
1214
Johannes Berg3713b4e2013-02-14 16:19:38 +01001215 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1216 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1217 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001218
Johannes Berg3713b4e2013-02-14 16:19:38 +01001219 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1220 dev->wiphy.available_antennas_tx) ||
1221 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1222 dev->wiphy.available_antennas_rx))
1223 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001224
Johannes Berg3713b4e2013-02-14 16:19:38 +01001225 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1226 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1227 dev->wiphy.probe_resp_offload))
1228 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001229
Johannes Berg3713b4e2013-02-14 16:19:38 +01001230 if ((dev->wiphy.available_antennas_tx ||
1231 dev->wiphy.available_antennas_rx) &&
1232 dev->ops->get_antenna) {
1233 u32 tx_ant = 0, rx_ant = 0;
1234 int res;
1235 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1236 if (!res) {
1237 if (nla_put_u32(msg,
1238 NL80211_ATTR_WIPHY_ANTENNA_TX,
1239 tx_ant) ||
1240 nla_put_u32(msg,
1241 NL80211_ATTR_WIPHY_ANTENNA_RX,
1242 rx_ant))
1243 goto nla_put_failure;
1244 }
Johannes Bergee688b002008-01-24 19:38:39 +01001245 }
1246
Johannes Berg3713b4e2013-02-14 16:19:38 +01001247 (*split_start)++;
1248 if (split)
1249 break;
1250 case 2:
1251 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1252 dev->wiphy.interface_modes))
1253 goto nla_put_failure;
1254 (*split_start)++;
1255 if (split)
1256 break;
1257 case 3:
1258 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1259 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001260 goto nla_put_failure;
1261
Johannes Berg3713b4e2013-02-14 16:19:38 +01001262 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1263 struct ieee80211_supported_band *sband;
1264
1265 sband = dev->wiphy.bands[band];
1266
1267 if (!sband)
1268 continue;
1269
1270 nl_band = nla_nest_start(msg, band);
1271 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001272 goto nla_put_failure;
1273
Johannes Berg3713b4e2013-02-14 16:19:38 +01001274 switch (*chan_start) {
1275 case 0:
1276 if (nl80211_send_band_rateinfo(msg, sband))
1277 goto nla_put_failure;
1278 (*chan_start)++;
1279 if (split)
1280 break;
1281 default:
1282 /* add frequencies */
1283 nl_freqs = nla_nest_start(
1284 msg, NL80211_BAND_ATTR_FREQS);
1285 if (!nl_freqs)
1286 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001287
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 for (i = *chan_start - 1;
1289 i < sband->n_channels;
1290 i++) {
1291 nl_freq = nla_nest_start(msg, i);
1292 if (!nl_freq)
1293 goto nla_put_failure;
1294
1295 chan = &sband->channels[i];
1296
Johannes Bergcdc89b92013-02-18 23:54:36 +01001297 if (nl80211_msg_put_channel(msg, chan,
1298 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 goto nla_put_failure;
1300
1301 nla_nest_end(msg, nl_freq);
1302 if (split)
1303 break;
1304 }
1305 if (i < sband->n_channels)
1306 *chan_start = i + 2;
1307 else
1308 *chan_start = 0;
1309 nla_nest_end(msg, nl_freqs);
1310 }
1311
1312 nla_nest_end(msg, nl_band);
1313
1314 if (split) {
1315 /* start again here */
1316 if (*chan_start)
1317 band--;
1318 break;
1319 }
Johannes Bergee688b002008-01-24 19:38:39 +01001320 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001322
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 if (band < IEEE80211_NUM_BANDS)
1324 *band_start = band + 1;
1325 else
1326 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001327
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 /* if bands & channels are done, continue outside */
1329 if (*band_start == 0 && *chan_start == 0)
1330 (*split_start)++;
1331 if (split)
1332 break;
1333 case 4:
1334 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1335 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001336 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337
1338 i = 0;
1339#define CMD(op, n) \
1340 do { \
1341 if (dev->ops->op) { \
1342 i++; \
1343 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1344 goto nla_put_failure; \
1345 } \
1346 } while (0)
1347
1348 CMD(add_virtual_intf, NEW_INTERFACE);
1349 CMD(change_virtual_intf, SET_INTERFACE);
1350 CMD(add_key, NEW_KEY);
1351 CMD(start_ap, START_AP);
1352 CMD(add_station, NEW_STATION);
1353 CMD(add_mpath, NEW_MPATH);
1354 CMD(update_mesh_config, SET_MESH_CONFIG);
1355 CMD(change_bss, SET_BSS);
1356 CMD(auth, AUTHENTICATE);
1357 CMD(assoc, ASSOCIATE);
1358 CMD(deauth, DEAUTHENTICATE);
1359 CMD(disassoc, DISASSOCIATE);
1360 CMD(join_ibss, JOIN_IBSS);
1361 CMD(join_mesh, JOIN_MESH);
1362 CMD(set_pmksa, SET_PMKSA);
1363 CMD(del_pmksa, DEL_PMKSA);
1364 CMD(flush_pmksa, FLUSH_PMKSA);
1365 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1366 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1367 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1368 CMD(mgmt_tx, FRAME);
1369 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1370 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1371 i++;
1372 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1373 goto nla_put_failure;
1374 }
1375 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1376 dev->ops->join_mesh) {
1377 i++;
1378 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1379 goto nla_put_failure;
1380 }
1381 CMD(set_wds_peer, SET_WDS_PEER);
1382 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1383 CMD(tdls_mgmt, TDLS_MGMT);
1384 CMD(tdls_oper, TDLS_OPER);
1385 }
1386 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1387 CMD(sched_scan_start, START_SCHED_SCAN);
1388 CMD(probe_client, PROBE_CLIENT);
1389 CMD(set_noack_map, SET_NOACK_MAP);
1390 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1391 i++;
1392 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1393 goto nla_put_failure;
1394 }
1395 CMD(start_p2p_device, START_P2P_DEVICE);
1396 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001397
Kalle Valo4745fc02011-11-17 19:06:10 +02001398#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001400#endif
1401
Johannes Berg8fdc6212009-03-14 09:34:01 +01001402#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001403
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 if (dev->ops->connect || dev->ops->auth) {
1405 i++;
1406 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001407 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001408 }
1409
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 if (dev->ops->disconnect || dev->ops->deauth) {
1411 i++;
1412 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1413 goto nla_put_failure;
1414 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001415
Johannes Berg3713b4e2013-02-14 16:19:38 +01001416 nla_nest_end(msg, nl_cmds);
1417 (*split_start)++;
1418 if (split)
1419 break;
1420 case 5:
1421 if (dev->ops->remain_on_channel &&
1422 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1423 nla_put_u32(msg,
1424 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1425 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001426 goto nla_put_failure;
1427
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1429 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1430 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001431
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1433 goto nla_put_failure;
1434 (*split_start)++;
1435 if (split)
1436 break;
1437 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001438#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001439 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 goto nla_put_failure;
1441 (*split_start)++;
1442 if (split)
1443 break;
1444#else
1445 (*split_start)++;
1446#endif
1447 case 7:
1448 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1449 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001450 goto nla_put_failure;
1451
Johannes Bergcdc89b92013-02-18 23:54:36 +01001452 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001454
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 (*split_start)++;
1456 if (split)
1457 break;
1458 case 8:
1459 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1460 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1461 dev->wiphy.ap_sme_capa))
1462 goto nla_put_failure;
1463
1464 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1465 dev->wiphy.features))
1466 goto nla_put_failure;
1467
1468 if (dev->wiphy.ht_capa_mod_mask &&
1469 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1470 sizeof(*dev->wiphy.ht_capa_mod_mask),
1471 dev->wiphy.ht_capa_mod_mask))
1472 goto nla_put_failure;
1473
1474 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1475 dev->wiphy.max_acl_mac_addrs &&
1476 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1477 dev->wiphy.max_acl_mac_addrs))
1478 goto nla_put_failure;
1479
1480 /*
1481 * Any information below this point is only available to
1482 * applications that can deal with it being split. This
1483 * helps ensure that newly added capabilities don't break
1484 * older tools by overrunning their buffers.
1485 *
1486 * We still increment split_start so that in the split
1487 * case we'll continue with more data in the next round,
1488 * but break unconditionally so unsplit data stops here.
1489 */
1490 (*split_start)++;
1491 break;
1492 case 9:
1493 /* placeholder */
1494
1495 /* done */
1496 *split_start = 0;
1497 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001498 }
Johannes Berg55682962007-09-20 13:09:35 -04001499 return genlmsg_end(msg, hdr);
1500
1501 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001502 genlmsg_cancel(msg, hdr);
1503 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001504}
1505
1506static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1507{
Johannes Berg645e77d2013-03-01 14:03:49 +01001508 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001509 int start = cb->args[0];
1510 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 s64 filter_wiphy = -1;
1512 bool split = false;
1513 struct nlattr **tb = nl80211_fam.attrbuf;
1514 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001515
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001516 mutex_lock(&cfg80211_mutex);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001517 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1518 tb, nl80211_fam.maxattr, nl80211_policy);
1519 if (res == 0) {
1520 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1521 if (tb[NL80211_ATTR_WIPHY])
1522 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1523 if (tb[NL80211_ATTR_WDEV])
1524 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1525 if (tb[NL80211_ATTR_IFINDEX]) {
1526 struct net_device *netdev;
1527 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1528
1529 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1530 if (!netdev) {
1531 mutex_unlock(&cfg80211_mutex);
1532 return -ENODEV;
1533 }
1534 if (netdev->ieee80211_ptr) {
1535 dev = wiphy_to_dev(
1536 netdev->ieee80211_ptr->wiphy);
1537 filter_wiphy = dev->wiphy_idx;
1538 }
1539 dev_put(netdev);
1540 }
1541 }
1542
Johannes Berg79c97e92009-07-07 03:56:12 +02001543 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001544 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1545 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001546 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001547 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1549 continue;
1550 /* attempt to fit multiple wiphy data chunks into the skb */
1551 do {
1552 ret = nl80211_send_wiphy(dev, skb,
1553 NETLINK_CB(cb->skb).portid,
1554 cb->nlh->nlmsg_seq,
1555 NLM_F_MULTI,
1556 split, &cb->args[1],
1557 &cb->args[2],
1558 &cb->args[3]);
1559 if (ret < 0) {
1560 /*
1561 * If sending the wiphy data didn't fit (ENOBUFS
1562 * or EMSGSIZE returned), this SKB is still
1563 * empty (so it's not too big because another
1564 * wiphy dataset is already in the skb) and
1565 * we've not tried to adjust the dump allocation
1566 * yet ... then adjust the alloc size to be
1567 * bigger, and return 1 but with the empty skb.
1568 * This results in an empty message being RX'ed
1569 * in userspace, but that is ignored.
1570 *
1571 * We can then retry with the larger buffer.
1572 */
1573 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1574 !skb->len &&
1575 cb->min_dump_alloc < 4096) {
1576 cb->min_dump_alloc = 4096;
1577 mutex_unlock(&cfg80211_mutex);
1578 return 1;
1579 }
1580 idx--;
1581 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001582 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 } while (cb->args[1] > 0);
1584 break;
Johannes Berg55682962007-09-20 13:09:35 -04001585 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001586 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001587
1588 cb->args[0] = idx;
1589
1590 return skb->len;
1591}
1592
1593static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1594{
1595 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001596 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001597
Johannes Berg645e77d2013-03-01 14:03:49 +01001598 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001599 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001600 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001601
Johannes Berg3713b4e2013-02-14 16:19:38 +01001602 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1603 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001604 nlmsg_free(msg);
1605 return -ENOBUFS;
1606 }
Johannes Berg55682962007-09-20 13:09:35 -04001607
Johannes Berg134e6372009-07-10 09:51:34 +00001608 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001609}
1610
Jouni Malinen31888482008-10-30 16:59:24 +02001611static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1612 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1613 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1614 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1615 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1616 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1617};
1618
1619static int parse_txq_params(struct nlattr *tb[],
1620 struct ieee80211_txq_params *txq_params)
1621{
Johannes Berga3304b02012-03-28 11:04:24 +02001622 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001623 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1624 !tb[NL80211_TXQ_ATTR_AIFS])
1625 return -EINVAL;
1626
Johannes Berga3304b02012-03-28 11:04:24 +02001627 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001628 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1629 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1630 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1631 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1632
Johannes Berga3304b02012-03-28 11:04:24 +02001633 if (txq_params->ac >= NL80211_NUM_ACS)
1634 return -EINVAL;
1635
Jouni Malinen31888482008-10-30 16:59:24 +02001636 return 0;
1637}
1638
Johannes Bergf444de02010-05-05 15:25:02 +02001639static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1640{
1641 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001642 * You can only set the channel explicitly for WDS interfaces,
1643 * all others have their channel managed via their respective
1644 * "establish a connection" command (connect, join, ...)
1645 *
1646 * For AP/GO and mesh mode, the channel can be set with the
1647 * channel userspace API, but is only stored and passed to the
1648 * low-level driver when the AP starts or the mesh is joined.
1649 * This is for backward compatibility, userspace can also give
1650 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001651 *
1652 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001653 * whatever else is going on, so they have their own special
1654 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001655 */
1656 return !wdev ||
1657 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001658 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001659 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1660 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001661}
1662
Johannes Berg683b6d32012-11-08 21:25:48 +01001663static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1664 struct genl_info *info,
1665 struct cfg80211_chan_def *chandef)
1666{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301667 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001668
1669 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1670 return -EINVAL;
1671
1672 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1673
1674 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001675 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1676 chandef->center_freq1 = control_freq;
1677 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001678
1679 /* Primary channel not allowed */
1680 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1681 return -EINVAL;
1682
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001683 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1684 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001685
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001686 chantype = nla_get_u32(
1687 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1688
1689 switch (chantype) {
1690 case NL80211_CHAN_NO_HT:
1691 case NL80211_CHAN_HT20:
1692 case NL80211_CHAN_HT40PLUS:
1693 case NL80211_CHAN_HT40MINUS:
1694 cfg80211_chandef_create(chandef, chandef->chan,
1695 chantype);
1696 break;
1697 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001698 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001699 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001700 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1701 chandef->width =
1702 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1703 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1704 chandef->center_freq1 =
1705 nla_get_u32(
1706 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1707 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1708 chandef->center_freq2 =
1709 nla_get_u32(
1710 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1711 }
1712
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001713 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001714 return -EINVAL;
1715
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001716 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1717 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001718 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001719
Johannes Berg683b6d32012-11-08 21:25:48 +01001720 return 0;
1721}
1722
Johannes Bergf444de02010-05-05 15:25:02 +02001723static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1724 struct wireless_dev *wdev,
1725 struct genl_info *info)
1726{
Johannes Berg683b6d32012-11-08 21:25:48 +01001727 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001728 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001729 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1730
1731 if (wdev)
1732 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001733
Johannes Bergf444de02010-05-05 15:25:02 +02001734 if (!nl80211_can_set_dev_channel(wdev))
1735 return -EOPNOTSUPP;
1736
Johannes Berg683b6d32012-11-08 21:25:48 +01001737 result = nl80211_parse_chandef(rdev, info, &chandef);
1738 if (result)
1739 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001740
1741 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001742 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001743 case NL80211_IFTYPE_AP:
1744 case NL80211_IFTYPE_P2P_GO:
1745 if (wdev->beacon_interval) {
1746 result = -EBUSY;
1747 break;
1748 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001749 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001750 result = -EINVAL;
1751 break;
1752 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001753 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001754 result = 0;
1755 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001756 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001757 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001758 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001759 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001760 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001761 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001762 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001763 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001764 }
1765 mutex_unlock(&rdev->devlist_mtx);
1766
1767 return result;
1768}
1769
1770static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1771{
Johannes Berg4c476992010-10-04 21:36:35 +02001772 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1773 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001774
Johannes Berg4c476992010-10-04 21:36:35 +02001775 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001776}
1777
Bill Jordane8347eb2010-10-01 13:54:28 -04001778static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1779{
Johannes Berg43b19952010-10-07 13:10:30 +02001780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1781 struct net_device *dev = info->user_ptr[1];
1782 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001783 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001784
1785 if (!info->attrs[NL80211_ATTR_MAC])
1786 return -EINVAL;
1787
Johannes Berg43b19952010-10-07 13:10:30 +02001788 if (netif_running(dev))
1789 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001790
Johannes Berg43b19952010-10-07 13:10:30 +02001791 if (!rdev->ops->set_wds_peer)
1792 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001793
Johannes Berg43b19952010-10-07 13:10:30 +02001794 if (wdev->iftype != NL80211_IFTYPE_WDS)
1795 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001796
1797 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001798 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001799}
1800
1801
Johannes Berg55682962007-09-20 13:09:35 -04001802static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1803{
1804 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001805 struct net_device *netdev = NULL;
1806 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001807 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001808 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001809 u32 changed;
1810 u8 retry_short = 0, retry_long = 0;
1811 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001812 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001813
Johannes Bergf444de02010-05-05 15:25:02 +02001814 /*
1815 * Try to find the wiphy and netdev. Normally this
1816 * function shouldn't need the netdev, but this is
1817 * done for backward compatibility -- previously
1818 * setting the channel was done per wiphy, but now
1819 * it is per netdev. Previous userland like hostapd
1820 * also passed a netdev to set_wiphy, so that it is
1821 * possible to let that go to the right netdev!
1822 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001823 mutex_lock(&cfg80211_mutex);
1824
Johannes Bergf444de02010-05-05 15:25:02 +02001825 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1826 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1827
1828 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1829 if (netdev && netdev->ieee80211_ptr) {
1830 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1831 mutex_lock(&rdev->mtx);
1832 } else
1833 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001834 }
1835
Johannes Bergf444de02010-05-05 15:25:02 +02001836 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001837 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1838 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001839 if (IS_ERR(rdev)) {
1840 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001841 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001842 }
1843 wdev = NULL;
1844 netdev = NULL;
1845 result = 0;
1846
1847 mutex_lock(&rdev->mtx);
Johannes Berg71fe96b2012-10-24 10:04:58 +02001848 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001849 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001850
1851 /*
1852 * end workaround code, by now the rdev is available
1853 * and locked, and wdev may or may not be NULL.
1854 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001855
1856 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001857 result = cfg80211_dev_rename(
1858 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001859
1860 mutex_unlock(&cfg80211_mutex);
1861
1862 if (result)
1863 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001864
Jouni Malinen31888482008-10-30 16:59:24 +02001865 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1866 struct ieee80211_txq_params txq_params;
1867 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1868
1869 if (!rdev->ops->set_txq_params) {
1870 result = -EOPNOTSUPP;
1871 goto bad_res;
1872 }
1873
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001874 if (!netdev) {
1875 result = -EINVAL;
1876 goto bad_res;
1877 }
1878
Johannes Berg133a3ff2011-11-03 14:50:13 +01001879 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1880 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1881 result = -EINVAL;
1882 goto bad_res;
1883 }
1884
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001885 if (!netif_running(netdev)) {
1886 result = -ENETDOWN;
1887 goto bad_res;
1888 }
1889
Jouni Malinen31888482008-10-30 16:59:24 +02001890 nla_for_each_nested(nl_txq_params,
1891 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1892 rem_txq_params) {
1893 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1894 nla_data(nl_txq_params),
1895 nla_len(nl_txq_params),
1896 txq_params_policy);
1897 result = parse_txq_params(tb, &txq_params);
1898 if (result)
1899 goto bad_res;
1900
Hila Gonene35e4d22012-06-27 17:19:42 +03001901 result = rdev_set_txq_params(rdev, netdev,
1902 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001903 if (result)
1904 goto bad_res;
1905 }
1906 }
1907
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001908 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001909 result = __nl80211_set_channel(rdev,
1910 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1911 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001912 if (result)
1913 goto bad_res;
1914 }
1915
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001916 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001917 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001918 enum nl80211_tx_power_setting type;
1919 int idx, mbm = 0;
1920
Johannes Bergc8442112012-10-24 10:17:18 +02001921 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1922 txp_wdev = NULL;
1923
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001924 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001925 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001926 goto bad_res;
1927 }
1928
1929 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1930 type = nla_get_u32(info->attrs[idx]);
1931
1932 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1933 (type != NL80211_TX_POWER_AUTOMATIC)) {
1934 result = -EINVAL;
1935 goto bad_res;
1936 }
1937
1938 if (type != NL80211_TX_POWER_AUTOMATIC) {
1939 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1940 mbm = nla_get_u32(info->attrs[idx]);
1941 }
1942
Johannes Bergc8442112012-10-24 10:17:18 +02001943 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001944 if (result)
1945 goto bad_res;
1946 }
1947
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001948 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1949 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1950 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001951 if ((!rdev->wiphy.available_antennas_tx &&
1952 !rdev->wiphy.available_antennas_rx) ||
1953 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001954 result = -EOPNOTSUPP;
1955 goto bad_res;
1956 }
1957
1958 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1959 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1960
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001961 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001962 * available antenna masks, except for the "all" mask */
1963 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1964 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001965 result = -EINVAL;
1966 goto bad_res;
1967 }
1968
Bruno Randolf7f531e02010-12-16 11:30:22 +09001969 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1970 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001971
Hila Gonene35e4d22012-06-27 17:19:42 +03001972 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001973 if (result)
1974 goto bad_res;
1975 }
1976
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001977 changed = 0;
1978
1979 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1980 retry_short = nla_get_u8(
1981 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1982 if (retry_short == 0) {
1983 result = -EINVAL;
1984 goto bad_res;
1985 }
1986 changed |= WIPHY_PARAM_RETRY_SHORT;
1987 }
1988
1989 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1990 retry_long = nla_get_u8(
1991 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1992 if (retry_long == 0) {
1993 result = -EINVAL;
1994 goto bad_res;
1995 }
1996 changed |= WIPHY_PARAM_RETRY_LONG;
1997 }
1998
1999 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2000 frag_threshold = nla_get_u32(
2001 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2002 if (frag_threshold < 256) {
2003 result = -EINVAL;
2004 goto bad_res;
2005 }
2006 if (frag_threshold != (u32) -1) {
2007 /*
2008 * Fragments (apart from the last one) are required to
2009 * have even length. Make the fragmentation code
2010 * simpler by stripping LSB should someone try to use
2011 * odd threshold value.
2012 */
2013 frag_threshold &= ~0x1;
2014 }
2015 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2016 }
2017
2018 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2019 rts_threshold = nla_get_u32(
2020 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2021 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2022 }
2023
Lukáš Turek81077e82009-12-21 22:50:47 +01002024 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2025 coverage_class = nla_get_u8(
2026 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2027 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2028 }
2029
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002030 if (changed) {
2031 u8 old_retry_short, old_retry_long;
2032 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002033 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002034
2035 if (!rdev->ops->set_wiphy_params) {
2036 result = -EOPNOTSUPP;
2037 goto bad_res;
2038 }
2039
2040 old_retry_short = rdev->wiphy.retry_short;
2041 old_retry_long = rdev->wiphy.retry_long;
2042 old_frag_threshold = rdev->wiphy.frag_threshold;
2043 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002044 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002045
2046 if (changed & WIPHY_PARAM_RETRY_SHORT)
2047 rdev->wiphy.retry_short = retry_short;
2048 if (changed & WIPHY_PARAM_RETRY_LONG)
2049 rdev->wiphy.retry_long = retry_long;
2050 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2051 rdev->wiphy.frag_threshold = frag_threshold;
2052 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2053 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002054 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2055 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002056
Hila Gonene35e4d22012-06-27 17:19:42 +03002057 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002058 if (result) {
2059 rdev->wiphy.retry_short = old_retry_short;
2060 rdev->wiphy.retry_long = old_retry_long;
2061 rdev->wiphy.frag_threshold = old_frag_threshold;
2062 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002063 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002064 }
2065 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002066
Johannes Berg306d6112008-12-08 12:39:04 +01002067 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002068 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02002069 if (netdev)
2070 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002071 return result;
2072}
2073
Johannes Berg71bbc992012-06-15 15:30:18 +02002074static inline u64 wdev_id(struct wireless_dev *wdev)
2075{
2076 return (u64)wdev->identifier |
2077 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2078}
Johannes Berg55682962007-09-20 13:09:35 -04002079
Johannes Berg683b6d32012-11-08 21:25:48 +01002080static int nl80211_send_chandef(struct sk_buff *msg,
2081 struct cfg80211_chan_def *chandef)
2082{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002083 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002084
Johannes Berg683b6d32012-11-08 21:25:48 +01002085 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2086 chandef->chan->center_freq))
2087 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002088 switch (chandef->width) {
2089 case NL80211_CHAN_WIDTH_20_NOHT:
2090 case NL80211_CHAN_WIDTH_20:
2091 case NL80211_CHAN_WIDTH_40:
2092 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2093 cfg80211_get_chandef_type(chandef)))
2094 return -ENOBUFS;
2095 break;
2096 default:
2097 break;
2098 }
2099 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2100 return -ENOBUFS;
2101 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2102 return -ENOBUFS;
2103 if (chandef->center_freq2 &&
2104 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002105 return -ENOBUFS;
2106 return 0;
2107}
2108
Eric W. Biederman15e47302012-09-07 20:12:54 +00002109static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002110 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002111 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002112{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002113 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002114 void *hdr;
2115
Eric W. Biederman15e47302012-09-07 20:12:54 +00002116 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002117 if (!hdr)
2118 return -1;
2119
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002120 if (dev &&
2121 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002122 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002123 goto nla_put_failure;
2124
2125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2126 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002127 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002128 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002129 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2130 rdev->devlist_generation ^
2131 (cfg80211_rdev_list_generation << 2)))
2132 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002133
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002134 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002135 int ret;
2136 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002137
Johannes Berg683b6d32012-11-08 21:25:48 +01002138 ret = rdev_get_channel(rdev, wdev, &chandef);
2139 if (ret == 0) {
2140 if (nl80211_send_chandef(msg, &chandef))
2141 goto nla_put_failure;
2142 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002143 }
2144
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002145 if (wdev->ssid_len) {
2146 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2147 goto nla_put_failure;
2148 }
2149
Johannes Berg55682962007-09-20 13:09:35 -04002150 return genlmsg_end(msg, hdr);
2151
2152 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002153 genlmsg_cancel(msg, hdr);
2154 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002155}
2156
2157static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2158{
2159 int wp_idx = 0;
2160 int if_idx = 0;
2161 int wp_start = cb->args[0];
2162 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002163 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002164 struct wireless_dev *wdev;
2165
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002166 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02002167 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2168 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002169 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002170 if (wp_idx < wp_start) {
2171 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002172 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002173 }
Johannes Berg55682962007-09-20 13:09:35 -04002174 if_idx = 0;
2175
Johannes Bergf5ea9122009-08-07 16:17:38 +02002176 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02002177 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002178 if (if_idx < if_start) {
2179 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002180 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002181 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002182 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002183 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002184 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02002185 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002186 goto out;
2187 }
2188 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002189 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02002190 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002191
2192 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002193 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002194 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002195 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04002196
2197 cb->args[0] = wp_idx;
2198 cb->args[1] = if_idx;
2199
2200 return skb->len;
2201}
2202
2203static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2204{
2205 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002206 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002207 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002208
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002209 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002210 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002211 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002212
Eric W. Biederman15e47302012-09-07 20:12:54 +00002213 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002214 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002215 nlmsg_free(msg);
2216 return -ENOBUFS;
2217 }
Johannes Berg55682962007-09-20 13:09:35 -04002218
Johannes Berg134e6372009-07-10 09:51:34 +00002219 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002220}
2221
Michael Wu66f7ac52008-01-31 19:48:22 +01002222static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2223 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2224 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2225 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2226 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2227 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2228};
2229
2230static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2231{
2232 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2233 int flag;
2234
2235 *mntrflags = 0;
2236
2237 if (!nla)
2238 return -EINVAL;
2239
2240 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2241 nla, mntr_flags_policy))
2242 return -EINVAL;
2243
2244 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2245 if (flags[flag])
2246 *mntrflags |= (1<<flag);
2247
2248 return 0;
2249}
2250
Johannes Berg9bc383d2009-11-19 11:55:19 +01002251static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002252 struct net_device *netdev, u8 use_4addr,
2253 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002254{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002255 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002256 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002257 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002258 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002259 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002260
2261 switch (iftype) {
2262 case NL80211_IFTYPE_AP_VLAN:
2263 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2264 return 0;
2265 break;
2266 case NL80211_IFTYPE_STATION:
2267 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2268 return 0;
2269 break;
2270 default:
2271 break;
2272 }
2273
2274 return -EOPNOTSUPP;
2275}
2276
Johannes Berg55682962007-09-20 13:09:35 -04002277static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2278{
Johannes Berg4c476992010-10-04 21:36:35 +02002279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002280 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002281 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002282 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002283 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002284 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002285 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002286
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002287 memset(&params, 0, sizeof(params));
2288
Johannes Berg04a773a2009-04-19 21:24:32 +02002289 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002290
Johannes Berg723b0382008-09-16 20:22:09 +02002291 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002292 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002293 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002294 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002295 if (ntype > NL80211_IFTYPE_MAX)
2296 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002297 }
2298
Johannes Berg92ffe052008-09-16 20:39:36 +02002299 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002300 struct wireless_dev *wdev = dev->ieee80211_ptr;
2301
Johannes Berg4c476992010-10-04 21:36:35 +02002302 if (ntype != NL80211_IFTYPE_MESH_POINT)
2303 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002304 if (netif_running(dev))
2305 return -EBUSY;
2306
2307 wdev_lock(wdev);
2308 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2309 IEEE80211_MAX_MESH_ID_LEN);
2310 wdev->mesh_id_up_len =
2311 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2312 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2313 wdev->mesh_id_up_len);
2314 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002315 }
2316
Felix Fietkau8b787642009-11-10 18:53:10 +01002317 if (info->attrs[NL80211_ATTR_4ADDR]) {
2318 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2319 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002320 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002321 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002322 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002323 } else {
2324 params.use_4addr = -1;
2325 }
2326
Johannes Berg92ffe052008-09-16 20:39:36 +02002327 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002328 if (ntype != NL80211_IFTYPE_MONITOR)
2329 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002330 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2331 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002332 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002333 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002334
2335 flags = &_flags;
2336 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002337 }
Johannes Berg3b858752009-03-12 09:55:09 +01002338
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002339 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002340 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002341 else
2342 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002343
Johannes Berg9bc383d2009-11-19 11:55:19 +01002344 if (!err && params.use_4addr != -1)
2345 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2346
Johannes Berg55682962007-09-20 13:09:35 -04002347 return err;
2348}
2349
2350static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2351{
Johannes Berg4c476992010-10-04 21:36:35 +02002352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002353 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002354 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002355 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002356 int err;
2357 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002358 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002359
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002360 memset(&params, 0, sizeof(params));
2361
Johannes Berg55682962007-09-20 13:09:35 -04002362 if (!info->attrs[NL80211_ATTR_IFNAME])
2363 return -EINVAL;
2364
2365 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2366 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2367 if (type > NL80211_IFTYPE_MAX)
2368 return -EINVAL;
2369 }
2370
Johannes Berg79c97e92009-07-07 03:56:12 +02002371 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002372 !(rdev->wiphy.interface_modes & (1 << type)))
2373 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002374
Arend van Spriel1c18f142013-01-08 10:17:27 +01002375 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2376 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2377 ETH_ALEN);
2378 if (!is_valid_ether_addr(params.macaddr))
2379 return -EADDRNOTAVAIL;
2380 }
2381
Johannes Berg9bc383d2009-11-19 11:55:19 +01002382 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002383 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002384 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002385 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002386 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002387 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002388
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002389 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2390 if (!msg)
2391 return -ENOMEM;
2392
Michael Wu66f7ac52008-01-31 19:48:22 +01002393 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2394 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2395 &flags);
Hila Gonene35e4d22012-06-27 17:19:42 +03002396 wdev = rdev_add_virtual_intf(rdev,
2397 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2398 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002399 if (IS_ERR(wdev)) {
2400 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002401 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002402 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002403
Johannes Berg98104fde2012-06-16 00:19:54 +02002404 switch (type) {
2405 case NL80211_IFTYPE_MESH_POINT:
2406 if (!info->attrs[NL80211_ATTR_MESH_ID])
2407 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002408 wdev_lock(wdev);
2409 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2410 IEEE80211_MAX_MESH_ID_LEN);
2411 wdev->mesh_id_up_len =
2412 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2413 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2414 wdev->mesh_id_up_len);
2415 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002416 break;
2417 case NL80211_IFTYPE_P2P_DEVICE:
2418 /*
2419 * P2P Device doesn't have a netdev, so doesn't go
2420 * through the netdev notifier and must be added here
2421 */
2422 mutex_init(&wdev->mtx);
2423 INIT_LIST_HEAD(&wdev->event_list);
2424 spin_lock_init(&wdev->event_lock);
2425 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2426 spin_lock_init(&wdev->mgmt_registrations_lock);
2427
2428 mutex_lock(&rdev->devlist_mtx);
2429 wdev->identifier = ++rdev->wdev_id;
2430 list_add_rcu(&wdev->list, &rdev->wdev_list);
2431 rdev->devlist_generation++;
2432 mutex_unlock(&rdev->devlist_mtx);
2433 break;
2434 default:
2435 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002436 }
2437
Eric W. Biederman15e47302012-09-07 20:12:54 +00002438 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002439 rdev, wdev) < 0) {
2440 nlmsg_free(msg);
2441 return -ENOBUFS;
2442 }
2443
2444 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002445}
2446
2447static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2448{
Johannes Berg4c476992010-10-04 21:36:35 +02002449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002450 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002451
Johannes Berg4c476992010-10-04 21:36:35 +02002452 if (!rdev->ops->del_virtual_intf)
2453 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002454
Johannes Berg84efbb82012-06-16 00:00:26 +02002455 /*
2456 * If we remove a wireless device without a netdev then clear
2457 * user_ptr[1] so that nl80211_post_doit won't dereference it
2458 * to check if it needs to do dev_put(). Otherwise it crashes
2459 * since the wdev has been freed, unlike with a netdev where
2460 * we need the dev_put() for the netdev to really be freed.
2461 */
2462 if (!wdev->netdev)
2463 info->user_ptr[1] = NULL;
2464
Hila Gonene35e4d22012-06-27 17:19:42 +03002465 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002466}
2467
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002468static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2469{
2470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2471 struct net_device *dev = info->user_ptr[1];
2472 u16 noack_map;
2473
2474 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2475 return -EINVAL;
2476
2477 if (!rdev->ops->set_noack_map)
2478 return -EOPNOTSUPP;
2479
2480 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2481
Hila Gonene35e4d22012-06-27 17:19:42 +03002482 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002483}
2484
Johannes Berg41ade002007-12-19 02:03:29 +01002485struct get_key_cookie {
2486 struct sk_buff *msg;
2487 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002488 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002489};
2490
2491static void get_key_callback(void *c, struct key_params *params)
2492{
Johannes Bergb9454e82009-07-08 13:29:08 +02002493 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002494 struct get_key_cookie *cookie = c;
2495
David S. Miller9360ffd2012-03-29 04:41:26 -04002496 if ((params->key &&
2497 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2498 params->key_len, params->key)) ||
2499 (params->seq &&
2500 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2501 params->seq_len, params->seq)) ||
2502 (params->cipher &&
2503 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2504 params->cipher)))
2505 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002506
Johannes Bergb9454e82009-07-08 13:29:08 +02002507 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2508 if (!key)
2509 goto nla_put_failure;
2510
David S. Miller9360ffd2012-03-29 04:41:26 -04002511 if ((params->key &&
2512 nla_put(cookie->msg, NL80211_KEY_DATA,
2513 params->key_len, params->key)) ||
2514 (params->seq &&
2515 nla_put(cookie->msg, NL80211_KEY_SEQ,
2516 params->seq_len, params->seq)) ||
2517 (params->cipher &&
2518 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2519 params->cipher)))
2520 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002521
David S. Miller9360ffd2012-03-29 04:41:26 -04002522 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2523 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002524
2525 nla_nest_end(cookie->msg, key);
2526
Johannes Berg41ade002007-12-19 02:03:29 +01002527 return;
2528 nla_put_failure:
2529 cookie->error = 1;
2530}
2531
2532static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2533{
Johannes Berg4c476992010-10-04 21:36:35 +02002534 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002535 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002536 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002537 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002538 const u8 *mac_addr = NULL;
2539 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002540 struct get_key_cookie cookie = {
2541 .error = 0,
2542 };
2543 void *hdr;
2544 struct sk_buff *msg;
2545
2546 if (info->attrs[NL80211_ATTR_KEY_IDX])
2547 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2548
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002549 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002550 return -EINVAL;
2551
2552 if (info->attrs[NL80211_ATTR_MAC])
2553 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2554
Johannes Berge31b8212010-10-05 19:39:30 +02002555 pairwise = !!mac_addr;
2556 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2557 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2558 if (kt >= NUM_NL80211_KEYTYPES)
2559 return -EINVAL;
2560 if (kt != NL80211_KEYTYPE_GROUP &&
2561 kt != NL80211_KEYTYPE_PAIRWISE)
2562 return -EINVAL;
2563 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2564 }
2565
Johannes Berg4c476992010-10-04 21:36:35 +02002566 if (!rdev->ops->get_key)
2567 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002568
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002569 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002570 if (!msg)
2571 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002572
Eric W. Biederman15e47302012-09-07 20:12:54 +00002573 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002574 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002575 if (IS_ERR(hdr))
2576 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002577
2578 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002579 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002580
David S. Miller9360ffd2012-03-29 04:41:26 -04002581 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2582 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2583 goto nla_put_failure;
2584 if (mac_addr &&
2585 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2586 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002587
Johannes Berge31b8212010-10-05 19:39:30 +02002588 if (pairwise && mac_addr &&
2589 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2590 return -ENOENT;
2591
Hila Gonene35e4d22012-06-27 17:19:42 +03002592 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2593 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002594
2595 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002596 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002597
2598 if (cookie.error)
2599 goto nla_put_failure;
2600
2601 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002602 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002603
2604 nla_put_failure:
2605 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002606 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002607 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002608 return err;
2609}
2610
2611static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2612{
Johannes Berg4c476992010-10-04 21:36:35 +02002613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002614 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002615 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002616 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002617
Johannes Bergb9454e82009-07-08 13:29:08 +02002618 err = nl80211_parse_key(info, &key);
2619 if (err)
2620 return err;
2621
2622 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002623 return -EINVAL;
2624
Johannes Bergb9454e82009-07-08 13:29:08 +02002625 /* only support setting default key */
2626 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002627 return -EINVAL;
2628
Johannes Bergfffd0932009-07-08 14:22:54 +02002629 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002630
2631 if (key.def) {
2632 if (!rdev->ops->set_default_key) {
2633 err = -EOPNOTSUPP;
2634 goto out;
2635 }
2636
2637 err = nl80211_key_allowed(dev->ieee80211_ptr);
2638 if (err)
2639 goto out;
2640
Hila Gonene35e4d22012-06-27 17:19:42 +03002641 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002642 key.def_uni, key.def_multi);
2643
2644 if (err)
2645 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002646
Johannes Berg3d23e342009-09-29 23:27:28 +02002647#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002648 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002649#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002650 } else {
2651 if (key.def_uni || !key.def_multi) {
2652 err = -EINVAL;
2653 goto out;
2654 }
2655
2656 if (!rdev->ops->set_default_mgmt_key) {
2657 err = -EOPNOTSUPP;
2658 goto out;
2659 }
2660
2661 err = nl80211_key_allowed(dev->ieee80211_ptr);
2662 if (err)
2663 goto out;
2664
Hila Gonene35e4d22012-06-27 17:19:42 +03002665 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002666 if (err)
2667 goto out;
2668
2669#ifdef CONFIG_CFG80211_WEXT
2670 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2671#endif
2672 }
2673
2674 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002675 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002676
Johannes Berg41ade002007-12-19 02:03:29 +01002677 return err;
2678}
2679
2680static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2681{
Johannes Berg4c476992010-10-04 21:36:35 +02002682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002683 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002684 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002685 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002686 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002687
Johannes Bergb9454e82009-07-08 13:29:08 +02002688 err = nl80211_parse_key(info, &key);
2689 if (err)
2690 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002691
Johannes Bergb9454e82009-07-08 13:29:08 +02002692 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002693 return -EINVAL;
2694
Johannes Berg41ade002007-12-19 02:03:29 +01002695 if (info->attrs[NL80211_ATTR_MAC])
2696 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2697
Johannes Berge31b8212010-10-05 19:39:30 +02002698 if (key.type == -1) {
2699 if (mac_addr)
2700 key.type = NL80211_KEYTYPE_PAIRWISE;
2701 else
2702 key.type = NL80211_KEYTYPE_GROUP;
2703 }
2704
2705 /* for now */
2706 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2707 key.type != NL80211_KEYTYPE_GROUP)
2708 return -EINVAL;
2709
Johannes Berg4c476992010-10-04 21:36:35 +02002710 if (!rdev->ops->add_key)
2711 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002712
Johannes Berge31b8212010-10-05 19:39:30 +02002713 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2714 key.type == NL80211_KEYTYPE_PAIRWISE,
2715 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002716 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002717
2718 wdev_lock(dev->ieee80211_ptr);
2719 err = nl80211_key_allowed(dev->ieee80211_ptr);
2720 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002721 err = rdev_add_key(rdev, dev, key.idx,
2722 key.type == NL80211_KEYTYPE_PAIRWISE,
2723 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002724 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002725
Johannes Berg41ade002007-12-19 02:03:29 +01002726 return err;
2727}
2728
2729static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2730{
Johannes Berg4c476992010-10-04 21:36:35 +02002731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002732 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002733 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002734 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002735 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002736
Johannes Bergb9454e82009-07-08 13:29:08 +02002737 err = nl80211_parse_key(info, &key);
2738 if (err)
2739 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002740
2741 if (info->attrs[NL80211_ATTR_MAC])
2742 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2743
Johannes Berge31b8212010-10-05 19:39:30 +02002744 if (key.type == -1) {
2745 if (mac_addr)
2746 key.type = NL80211_KEYTYPE_PAIRWISE;
2747 else
2748 key.type = NL80211_KEYTYPE_GROUP;
2749 }
2750
2751 /* for now */
2752 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2753 key.type != NL80211_KEYTYPE_GROUP)
2754 return -EINVAL;
2755
Johannes Berg4c476992010-10-04 21:36:35 +02002756 if (!rdev->ops->del_key)
2757 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002758
Johannes Bergfffd0932009-07-08 14:22:54 +02002759 wdev_lock(dev->ieee80211_ptr);
2760 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002761
2762 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2763 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2764 err = -ENOENT;
2765
Johannes Bergfffd0932009-07-08 14:22:54 +02002766 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002767 err = rdev_del_key(rdev, dev, key.idx,
2768 key.type == NL80211_KEYTYPE_PAIRWISE,
2769 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002770
Johannes Berg3d23e342009-09-29 23:27:28 +02002771#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002772 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002773 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002774 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002775 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002776 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2777 }
2778#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002779 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002780
Johannes Berg41ade002007-12-19 02:03:29 +01002781 return err;
2782}
2783
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302784/* This function returns an error or the number of nested attributes */
2785static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2786{
2787 struct nlattr *attr;
2788 int n_entries = 0, tmp;
2789
2790 nla_for_each_nested(attr, nl_attr, tmp) {
2791 if (nla_len(attr) != ETH_ALEN)
2792 return -EINVAL;
2793
2794 n_entries++;
2795 }
2796
2797 return n_entries;
2798}
2799
2800/*
2801 * This function parses ACL information and allocates memory for ACL data.
2802 * On successful return, the calling function is responsible to free the
2803 * ACL buffer returned by this function.
2804 */
2805static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2806 struct genl_info *info)
2807{
2808 enum nl80211_acl_policy acl_policy;
2809 struct nlattr *attr;
2810 struct cfg80211_acl_data *acl;
2811 int i = 0, n_entries, tmp;
2812
2813 if (!wiphy->max_acl_mac_addrs)
2814 return ERR_PTR(-EOPNOTSUPP);
2815
2816 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2817 return ERR_PTR(-EINVAL);
2818
2819 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2820 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2821 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2822 return ERR_PTR(-EINVAL);
2823
2824 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2825 return ERR_PTR(-EINVAL);
2826
2827 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2828 if (n_entries < 0)
2829 return ERR_PTR(n_entries);
2830
2831 if (n_entries > wiphy->max_acl_mac_addrs)
2832 return ERR_PTR(-ENOTSUPP);
2833
2834 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2835 GFP_KERNEL);
2836 if (!acl)
2837 return ERR_PTR(-ENOMEM);
2838
2839 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2840 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2841 i++;
2842 }
2843
2844 acl->n_acl_entries = n_entries;
2845 acl->acl_policy = acl_policy;
2846
2847 return acl;
2848}
2849
2850static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2851{
2852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2853 struct net_device *dev = info->user_ptr[1];
2854 struct cfg80211_acl_data *acl;
2855 int err;
2856
2857 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2858 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2859 return -EOPNOTSUPP;
2860
2861 if (!dev->ieee80211_ptr->beacon_interval)
2862 return -EINVAL;
2863
2864 acl = parse_acl_data(&rdev->wiphy, info);
2865 if (IS_ERR(acl))
2866 return PTR_ERR(acl);
2867
2868 err = rdev_set_mac_acl(rdev, dev, acl);
2869
2870 kfree(acl);
2871
2872 return err;
2873}
2874
Johannes Berg88600202012-02-13 15:17:18 +01002875static int nl80211_parse_beacon(struct genl_info *info,
2876 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002877{
Johannes Berg88600202012-02-13 15:17:18 +01002878 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002879
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002880 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2881 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2882 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2883 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002884 return -EINVAL;
2885
Johannes Berg88600202012-02-13 15:17:18 +01002886 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002887
Johannes Berged1b6cc2007-12-19 02:03:32 +01002888 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002889 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2890 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2891 if (!bcn->head_len)
2892 return -EINVAL;
2893 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002894 }
2895
2896 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002897 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2898 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002899 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002900 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002901 }
2902
Johannes Berg4c476992010-10-04 21:36:35 +02002903 if (!haveinfo)
2904 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002905
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002906 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002907 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2908 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002909 }
2910
2911 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002912 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002913 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002914 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002915 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2916 }
2917
2918 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002919 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002920 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002921 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002922 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2923 }
2924
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002925 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002926 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002927 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002928 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002929 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2930 }
2931
Johannes Berg88600202012-02-13 15:17:18 +01002932 return 0;
2933}
2934
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002935static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2936 struct cfg80211_ap_settings *params)
2937{
2938 struct wireless_dev *wdev;
2939 bool ret = false;
2940
2941 mutex_lock(&rdev->devlist_mtx);
2942
Johannes Berg89a54e42012-06-15 14:33:17 +02002943 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002944 if (wdev->iftype != NL80211_IFTYPE_AP &&
2945 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2946 continue;
2947
Johannes Berg683b6d32012-11-08 21:25:48 +01002948 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002949 continue;
2950
Johannes Berg683b6d32012-11-08 21:25:48 +01002951 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002952 ret = true;
2953 break;
2954 }
2955
2956 mutex_unlock(&rdev->devlist_mtx);
2957
2958 return ret;
2959}
2960
Jouni Malinene39e5b52012-09-30 19:29:39 +03002961static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2962 enum nl80211_auth_type auth_type,
2963 enum nl80211_commands cmd)
2964{
2965 if (auth_type > NL80211_AUTHTYPE_MAX)
2966 return false;
2967
2968 switch (cmd) {
2969 case NL80211_CMD_AUTHENTICATE:
2970 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2971 auth_type == NL80211_AUTHTYPE_SAE)
2972 return false;
2973 return true;
2974 case NL80211_CMD_CONNECT:
2975 case NL80211_CMD_START_AP:
2976 /* SAE not supported yet */
2977 if (auth_type == NL80211_AUTHTYPE_SAE)
2978 return false;
2979 return true;
2980 default:
2981 return false;
2982 }
2983}
2984
Johannes Berg88600202012-02-13 15:17:18 +01002985static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2986{
2987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2988 struct net_device *dev = info->user_ptr[1];
2989 struct wireless_dev *wdev = dev->ieee80211_ptr;
2990 struct cfg80211_ap_settings params;
2991 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01002992 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01002993
2994 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2995 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2996 return -EOPNOTSUPP;
2997
2998 if (!rdev->ops->start_ap)
2999 return -EOPNOTSUPP;
3000
3001 if (wdev->beacon_interval)
3002 return -EALREADY;
3003
3004 memset(&params, 0, sizeof(params));
3005
3006 /* these are required for START_AP */
3007 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3008 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3009 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3010 return -EINVAL;
3011
3012 err = nl80211_parse_beacon(info, &params.beacon);
3013 if (err)
3014 return err;
3015
3016 params.beacon_interval =
3017 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3018 params.dtim_period =
3019 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3020
3021 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3022 if (err)
3023 return err;
3024
3025 /*
3026 * In theory, some of these attributes should be required here
3027 * but since they were not used when the command was originally
3028 * added, keep them optional for old user space programs to let
3029 * them continue to work with drivers that do not need the
3030 * additional information -- drivers must check!
3031 */
3032 if (info->attrs[NL80211_ATTR_SSID]) {
3033 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3034 params.ssid_len =
3035 nla_len(info->attrs[NL80211_ATTR_SSID]);
3036 if (params.ssid_len == 0 ||
3037 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3038 return -EINVAL;
3039 }
3040
3041 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3042 params.hidden_ssid = nla_get_u32(
3043 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3044 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3045 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3046 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3047 return -EINVAL;
3048 }
3049
3050 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3051
3052 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3053 params.auth_type = nla_get_u32(
3054 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003055 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3056 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003057 return -EINVAL;
3058 } else
3059 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3060
3061 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3062 NL80211_MAX_NR_CIPHER_SUITES);
3063 if (err)
3064 return err;
3065
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303066 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3067 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3068 return -EOPNOTSUPP;
3069 params.inactivity_timeout = nla_get_u16(
3070 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3071 }
3072
Johannes Berg53cabad2012-11-14 15:17:28 +01003073 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3074 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3075 return -EINVAL;
3076 params.p2p_ctwindow =
3077 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3078 if (params.p2p_ctwindow > 127)
3079 return -EINVAL;
3080 if (params.p2p_ctwindow != 0 &&
3081 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3082 return -EINVAL;
3083 }
3084
3085 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3086 u8 tmp;
3087
3088 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3089 return -EINVAL;
3090 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3091 if (tmp > 1)
3092 return -EINVAL;
3093 params.p2p_opp_ps = tmp;
3094 if (params.p2p_opp_ps != 0 &&
3095 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3096 return -EINVAL;
3097 }
3098
Johannes Bergaa430da2012-05-16 23:50:18 +02003099 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003100 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3101 if (err)
3102 return err;
3103 } else if (wdev->preset_chandef.chan) {
3104 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003105 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003106 return -EINVAL;
3107
Johannes Berg683b6d32012-11-08 21:25:48 +01003108 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003109 return -EINVAL;
3110
Simon Wunderlich04f39042013-02-08 18:16:19 +01003111 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3112 if (err < 0)
3113 return err;
3114 if (err) {
3115 radar_detect_width = BIT(params.chandef.width);
3116 params.radar_required = true;
3117 }
3118
Michal Kaziore4e32452012-06-29 12:47:08 +02003119 mutex_lock(&rdev->devlist_mtx);
Simon Wunderlich04f39042013-02-08 18:16:19 +01003120 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3121 params.chandef.chan,
3122 CHAN_MODE_SHARED,
3123 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003124 mutex_unlock(&rdev->devlist_mtx);
3125
3126 if (err)
3127 return err;
3128
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303129 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3130 params.acl = parse_acl_data(&rdev->wiphy, info);
3131 if (IS_ERR(params.acl))
3132 return PTR_ERR(params.acl);
3133 }
3134
Hila Gonene35e4d22012-06-27 17:19:42 +03003135 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003136 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003137 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003138 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003139 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003140 wdev->ssid_len = params.ssid_len;
3141 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003142 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303143
3144 kfree(params.acl);
3145
Johannes Berg56d18932011-05-09 18:41:15 +02003146 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003147}
3148
Johannes Berg88600202012-02-13 15:17:18 +01003149static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3150{
3151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3152 struct net_device *dev = info->user_ptr[1];
3153 struct wireless_dev *wdev = dev->ieee80211_ptr;
3154 struct cfg80211_beacon_data params;
3155 int err;
3156
3157 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3158 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3159 return -EOPNOTSUPP;
3160
3161 if (!rdev->ops->change_beacon)
3162 return -EOPNOTSUPP;
3163
3164 if (!wdev->beacon_interval)
3165 return -EINVAL;
3166
3167 err = nl80211_parse_beacon(info, &params);
3168 if (err)
3169 return err;
3170
Hila Gonene35e4d22012-06-27 17:19:42 +03003171 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003172}
3173
3174static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003175{
Johannes Berg4c476992010-10-04 21:36:35 +02003176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3177 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003178
Michal Kazior60771782012-06-29 12:46:56 +02003179 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003180}
3181
Johannes Berg5727ef12007-12-19 02:03:34 +01003182static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3183 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3184 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3185 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003186 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003187 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003188 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003189};
3190
Johannes Bergeccb8e82009-05-11 21:57:56 +03003191static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003192 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003193 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003194{
3195 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003196 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003197 int flag;
3198
Johannes Bergeccb8e82009-05-11 21:57:56 +03003199 /*
3200 * Try parsing the new attribute first so userspace
3201 * can specify both for older kernels.
3202 */
3203 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3204 if (nla) {
3205 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003206
Johannes Bergeccb8e82009-05-11 21:57:56 +03003207 sta_flags = nla_data(nla);
3208 params->sta_flags_mask = sta_flags->mask;
3209 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003210 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003211 if ((params->sta_flags_mask |
3212 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3213 return -EINVAL;
3214 return 0;
3215 }
3216
3217 /* if present, parse the old attribute */
3218
3219 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003220 if (!nla)
3221 return 0;
3222
3223 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3224 nla, sta_flags_policy))
3225 return -EINVAL;
3226
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003227 /*
3228 * Only allow certain flags for interface types so that
3229 * other attributes are silently ignored. Remember that
3230 * this is backward compatibility code with old userspace
3231 * and shouldn't be hit in other cases anyway.
3232 */
3233 switch (iftype) {
3234 case NL80211_IFTYPE_AP:
3235 case NL80211_IFTYPE_AP_VLAN:
3236 case NL80211_IFTYPE_P2P_GO:
3237 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3238 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3239 BIT(NL80211_STA_FLAG_WME) |
3240 BIT(NL80211_STA_FLAG_MFP);
3241 break;
3242 case NL80211_IFTYPE_P2P_CLIENT:
3243 case NL80211_IFTYPE_STATION:
3244 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3245 BIT(NL80211_STA_FLAG_TDLS_PEER);
3246 break;
3247 case NL80211_IFTYPE_MESH_POINT:
3248 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3249 BIT(NL80211_STA_FLAG_MFP) |
3250 BIT(NL80211_STA_FLAG_AUTHORIZED);
3251 default:
3252 return -EINVAL;
3253 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003254
Johannes Berg3383b5a2012-05-10 20:14:43 +02003255 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3256 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003257 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003258
Johannes Berg3383b5a2012-05-10 20:14:43 +02003259 /* no longer support new API additions in old API */
3260 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3261 return -EINVAL;
3262 }
3263 }
3264
Johannes Berg5727ef12007-12-19 02:03:34 +01003265 return 0;
3266}
3267
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003268static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3269 int attr)
3270{
3271 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003272 u32 bitrate;
3273 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003274
3275 rate = nla_nest_start(msg, attr);
3276 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003277 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003278
3279 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3280 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003281 /* report 16-bit bitrate only if we can */
3282 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003283 if (bitrate > 0 &&
3284 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3285 return false;
3286 if (bitrate_compat > 0 &&
3287 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3288 return false;
3289
3290 if (info->flags & RATE_INFO_FLAGS_MCS) {
3291 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3292 return false;
3293 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3294 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3295 return false;
3296 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3297 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3298 return false;
3299 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3300 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3301 return false;
3302 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3303 return false;
3304 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3305 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3306 return false;
3307 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3308 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3309 return false;
3310 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3311 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3312 return false;
3313 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3314 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3315 return false;
3316 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3317 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3318 return false;
3319 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003320
3321 nla_nest_end(msg, rate);
3322 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003323}
3324
Eric W. Biederman15e47302012-09-07 20:12:54 +00003325static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003326 int flags,
3327 struct cfg80211_registered_device *rdev,
3328 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003329 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003330{
3331 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003332 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003333
Eric W. Biederman15e47302012-09-07 20:12:54 +00003334 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003335 if (!hdr)
3336 return -1;
3337
David S. Miller9360ffd2012-03-29 04:41:26 -04003338 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3339 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3340 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3341 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003342
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003343 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3344 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003345 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003346 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3347 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3348 sinfo->connected_time))
3349 goto nla_put_failure;
3350 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3351 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3352 sinfo->inactive_time))
3353 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003354 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3355 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003356 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003357 (u32)sinfo->rx_bytes))
3358 goto nla_put_failure;
3359 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3360 NL80211_STA_INFO_TX_BYTES64)) &&
3361 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3362 (u32)sinfo->tx_bytes))
3363 goto nla_put_failure;
3364 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3365 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003366 sinfo->rx_bytes))
3367 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003368 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3369 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003370 sinfo->tx_bytes))
3371 goto nla_put_failure;
3372 if ((sinfo->filled & STATION_INFO_LLID) &&
3373 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3374 goto nla_put_failure;
3375 if ((sinfo->filled & STATION_INFO_PLID) &&
3376 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3377 goto nla_put_failure;
3378 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3379 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3380 sinfo->plink_state))
3381 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003382 switch (rdev->wiphy.signal_type) {
3383 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003384 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3385 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3386 sinfo->signal))
3387 goto nla_put_failure;
3388 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3389 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3390 sinfo->signal_avg))
3391 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003392 break;
3393 default:
3394 break;
3395 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003396 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003397 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3398 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003399 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003400 }
3401 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3402 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3403 NL80211_STA_INFO_RX_BITRATE))
3404 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003405 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003406 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3407 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3408 sinfo->rx_packets))
3409 goto nla_put_failure;
3410 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3411 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3412 sinfo->tx_packets))
3413 goto nla_put_failure;
3414 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3415 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3416 sinfo->tx_retries))
3417 goto nla_put_failure;
3418 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3419 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3420 sinfo->tx_failed))
3421 goto nla_put_failure;
3422 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3423 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3424 sinfo->beacon_loss_count))
3425 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003426 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3427 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3428 sinfo->local_pm))
3429 goto nla_put_failure;
3430 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3431 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3432 sinfo->peer_pm))
3433 goto nla_put_failure;
3434 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3435 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3436 sinfo->nonpeer_pm))
3437 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003438 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3439 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3440 if (!bss_param)
3441 goto nla_put_failure;
3442
David S. Miller9360ffd2012-03-29 04:41:26 -04003443 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3444 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3445 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3446 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3447 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3448 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3449 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3450 sinfo->bss_param.dtim_period) ||
3451 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3452 sinfo->bss_param.beacon_interval))
3453 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003454
3455 nla_nest_end(msg, bss_param);
3456 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003457 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3458 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3459 sizeof(struct nl80211_sta_flag_update),
3460 &sinfo->sta_flags))
3461 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003462 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3463 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3464 sinfo->t_offset))
3465 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003466 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003467
David S. Miller9360ffd2012-03-29 04:41:26 -04003468 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3469 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3470 sinfo->assoc_req_ies))
3471 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003472
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003473 return genlmsg_end(msg, hdr);
3474
3475 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003476 genlmsg_cancel(msg, hdr);
3477 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003478}
3479
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003480static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003481 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003482{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003483 struct station_info sinfo;
3484 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003485 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003486 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003487 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003488 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003489
Johannes Berg67748892010-10-04 21:14:06 +02003490 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3491 if (err)
3492 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003493
3494 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003495 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003496 goto out_err;
3497 }
3498
Johannes Bergbba95fe2008-07-29 13:22:51 +02003499 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003500 memset(&sinfo, 0, sizeof(sinfo));
Hila Gonene35e4d22012-06-27 17:19:42 +03003501 err = rdev_dump_station(dev, netdev, sta_idx,
3502 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003503 if (err == -ENOENT)
3504 break;
3505 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003506 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003507
3508 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003509 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003510 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04003511 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003512 &sinfo) < 0)
3513 goto out;
3514
3515 sta_idx++;
3516 }
3517
3518
3519 out:
3520 cb->args[1] = sta_idx;
3521 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003522 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003523 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003524
3525 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003527
Johannes Berg5727ef12007-12-19 02:03:34 +01003528static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3529{
Johannes Berg4c476992010-10-04 21:36:35 +02003530 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3531 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003532 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003533 struct sk_buff *msg;
3534 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003535 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003536
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003537 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003538
3539 if (!info->attrs[NL80211_ATTR_MAC])
3540 return -EINVAL;
3541
3542 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3543
Johannes Berg4c476992010-10-04 21:36:35 +02003544 if (!rdev->ops->get_station)
3545 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003546
Hila Gonene35e4d22012-06-27 17:19:42 +03003547 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003548 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003549 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003550
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003551 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003552 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003553 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003554
Eric W. Biederman15e47302012-09-07 20:12:54 +00003555 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003556 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003557 nlmsg_free(msg);
3558 return -ENOBUFS;
3559 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003560
Johannes Berg4c476992010-10-04 21:36:35 +02003561 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003562}
3563
Johannes Berg77ee7c82013-02-15 00:48:33 +01003564int cfg80211_check_station_change(struct wiphy *wiphy,
3565 struct station_parameters *params,
3566 enum cfg80211_station_type statype)
3567{
3568 if (params->listen_interval != -1)
3569 return -EINVAL;
3570 if (params->aid)
3571 return -EINVAL;
3572
3573 /* When you run into this, adjust the code below for the new flag */
3574 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3575
3576 switch (statype) {
3577 case CFG80211_STA_MESH_PEER_NONSEC:
3578 case CFG80211_STA_MESH_PEER_SECURE:
3579 /*
3580 * No ignoring the TDLS flag here -- the userspace mesh
3581 * code doesn't have the bug of including TDLS in the
3582 * mask everywhere.
3583 */
3584 if (params->sta_flags_mask &
3585 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3586 BIT(NL80211_STA_FLAG_MFP) |
3587 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3588 return -EINVAL;
3589 break;
3590 case CFG80211_STA_TDLS_PEER_SETUP:
3591 case CFG80211_STA_TDLS_PEER_ACTIVE:
3592 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3593 return -EINVAL;
3594 /* ignore since it can't change */
3595 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3596 break;
3597 default:
3598 /* disallow mesh-specific things */
3599 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3600 return -EINVAL;
3601 if (params->local_pm)
3602 return -EINVAL;
3603 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3604 return -EINVAL;
3605 }
3606
3607 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3608 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3609 /* TDLS can't be set, ... */
3610 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3611 return -EINVAL;
3612 /*
3613 * ... but don't bother the driver with it. This works around
3614 * a hostapd/wpa_supplicant issue -- it always includes the
3615 * TLDS_PEER flag in the mask even for AP mode.
3616 */
3617 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3618 }
3619
3620 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3621 /* reject other things that can't change */
3622 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3623 return -EINVAL;
3624 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3625 return -EINVAL;
3626 if (params->supported_rates)
3627 return -EINVAL;
3628 if (params->ext_capab || params->ht_capa || params->vht_capa)
3629 return -EINVAL;
3630 }
3631
3632 if (statype != CFG80211_STA_AP_CLIENT) {
3633 if (params->vlan)
3634 return -EINVAL;
3635 }
3636
3637 switch (statype) {
3638 case CFG80211_STA_AP_MLME_CLIENT:
3639 /* Use this only for authorizing/unauthorizing a station */
3640 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3641 return -EOPNOTSUPP;
3642 break;
3643 case CFG80211_STA_AP_CLIENT:
3644 /* accept only the listed bits */
3645 if (params->sta_flags_mask &
3646 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3647 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3648 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3649 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3650 BIT(NL80211_STA_FLAG_WME) |
3651 BIT(NL80211_STA_FLAG_MFP)))
3652 return -EINVAL;
3653
3654 /* but authenticated/associated only if driver handles it */
3655 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3656 params->sta_flags_mask &
3657 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3658 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3659 return -EINVAL;
3660 break;
3661 case CFG80211_STA_IBSS:
3662 case CFG80211_STA_AP_STA:
3663 /* reject any changes other than AUTHORIZED */
3664 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3665 return -EINVAL;
3666 break;
3667 case CFG80211_STA_TDLS_PEER_SETUP:
3668 /* reject any changes other than AUTHORIZED or WME */
3669 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3670 BIT(NL80211_STA_FLAG_WME)))
3671 return -EINVAL;
3672 /* force (at least) rates when authorizing */
3673 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3674 !params->supported_rates)
3675 return -EINVAL;
3676 break;
3677 case CFG80211_STA_TDLS_PEER_ACTIVE:
3678 /* reject any changes */
3679 return -EINVAL;
3680 case CFG80211_STA_MESH_PEER_NONSEC:
3681 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3682 return -EINVAL;
3683 break;
3684 case CFG80211_STA_MESH_PEER_SECURE:
3685 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3686 return -EINVAL;
3687 break;
3688 }
3689
3690 return 0;
3691}
3692EXPORT_SYMBOL(cfg80211_check_station_change);
3693
Johannes Berg5727ef12007-12-19 02:03:34 +01003694/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003695 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003696 */
Johannes Berg80b99892011-11-18 16:23:01 +01003697static struct net_device *get_vlan(struct genl_info *info,
3698 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003699{
Johannes Berg463d0182009-07-14 00:33:35 +02003700 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003701 struct net_device *v;
3702 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003703
Johannes Berg80b99892011-11-18 16:23:01 +01003704 if (!vlanattr)
3705 return NULL;
3706
3707 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3708 if (!v)
3709 return ERR_PTR(-ENODEV);
3710
3711 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3712 ret = -EINVAL;
3713 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003714 }
Johannes Berg80b99892011-11-18 16:23:01 +01003715
Johannes Berg77ee7c82013-02-15 00:48:33 +01003716 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3717 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3718 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3719 ret = -EINVAL;
3720 goto error;
3721 }
3722
Johannes Berg80b99892011-11-18 16:23:01 +01003723 if (!netif_running(v)) {
3724 ret = -ENETDOWN;
3725 goto error;
3726 }
3727
3728 return v;
3729 error:
3730 dev_put(v);
3731 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003732}
3733
Jouni Malinendf881292013-02-14 21:10:54 +02003734static struct nla_policy
3735nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3736 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3737 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3738};
3739
Johannes Bergff276692013-02-15 00:09:01 +01003740static int nl80211_parse_sta_wme(struct genl_info *info,
3741 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003742{
Jouni Malinendf881292013-02-14 21:10:54 +02003743 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3744 struct nlattr *nla;
3745 int err;
3746
Jouni Malinendf881292013-02-14 21:10:54 +02003747 /* parse WME attributes if present */
3748 if (!info->attrs[NL80211_ATTR_STA_WME])
3749 return 0;
3750
3751 nla = info->attrs[NL80211_ATTR_STA_WME];
3752 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3753 nl80211_sta_wme_policy);
3754 if (err)
3755 return err;
3756
3757 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3758 params->uapsd_queues = nla_get_u8(
3759 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3760 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3761 return -EINVAL;
3762
3763 if (tb[NL80211_STA_WME_MAX_SP])
3764 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3765
3766 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3767 return -EINVAL;
3768
3769 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3770
3771 return 0;
3772}
3773
Johannes Bergff276692013-02-15 00:09:01 +01003774static int nl80211_set_station_tdls(struct genl_info *info,
3775 struct station_parameters *params)
3776{
3777 /* Dummy STA entry gets updated once the peer capabilities are known */
3778 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3779 params->ht_capa =
3780 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3781 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3782 params->vht_capa =
3783 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3784
3785 return nl80211_parse_sta_wme(info, params);
3786}
3787
Johannes Berg5727ef12007-12-19 02:03:34 +01003788static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3789{
Johannes Berg4c476992010-10-04 21:36:35 +02003790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003791 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003792 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003793 u8 *mac_addr;
3794 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003795
3796 memset(&params, 0, sizeof(params));
3797
3798 params.listen_interval = -1;
3799
Johannes Berg77ee7c82013-02-15 00:48:33 +01003800 if (!rdev->ops->change_station)
3801 return -EOPNOTSUPP;
3802
Johannes Berg5727ef12007-12-19 02:03:34 +01003803 if (info->attrs[NL80211_ATTR_STA_AID])
3804 return -EINVAL;
3805
3806 if (!info->attrs[NL80211_ATTR_MAC])
3807 return -EINVAL;
3808
3809 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3810
3811 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3812 params.supported_rates =
3813 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3814 params.supported_rates_len =
3815 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3816 }
3817
Jouni Malinen9d62a982013-02-14 21:10:13 +02003818 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3819 params.capability =
3820 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3821 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3822 }
3823
3824 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3825 params.ext_capab =
3826 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3827 params.ext_capab_len =
3828 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3829 }
3830
Jouni Malinendf881292013-02-14 21:10:54 +02003831 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003832 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003833
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003834 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003835 return -EINVAL;
3836
Johannes Bergf8bacc22013-02-14 23:27:01 +01003837 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003838 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003839 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3840 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3841 return -EINVAL;
3842 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003843
Johannes Bergf8bacc22013-02-14 23:27:01 +01003844 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003845 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003846 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3847 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3848 return -EINVAL;
3849 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3850 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003851
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003852 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3853 enum nl80211_mesh_power_mode pm = nla_get_u32(
3854 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3855
3856 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3857 pm > NL80211_MESH_POWER_MAX)
3858 return -EINVAL;
3859
3860 params.local_pm = pm;
3861 }
3862
Johannes Berg77ee7c82013-02-15 00:48:33 +01003863 /* Include parameters for TDLS peer (will check later) */
3864 err = nl80211_set_station_tdls(info, &params);
3865 if (err)
3866 return err;
3867
3868 params.vlan = get_vlan(info, rdev);
3869 if (IS_ERR(params.vlan))
3870 return PTR_ERR(params.vlan);
3871
Johannes Berga97f4422009-06-18 17:23:43 +02003872 switch (dev->ieee80211_ptr->iftype) {
3873 case NL80211_IFTYPE_AP:
3874 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003875 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003876 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003877 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003878 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003879 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003880 break;
3881 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003882 err = -EOPNOTSUPP;
3883 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003884 }
3885
Johannes Berg77ee7c82013-02-15 00:48:33 +01003886 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003887 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003888
Johannes Berg77ee7c82013-02-15 00:48:33 +01003889 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003890 if (params.vlan)
3891 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003892
Johannes Berg5727ef12007-12-19 02:03:34 +01003893 return err;
3894}
3895
3896static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3897{
Johannes Berg4c476992010-10-04 21:36:35 +02003898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003899 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003900 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003901 struct station_parameters params;
3902 u8 *mac_addr = NULL;
3903
3904 memset(&params, 0, sizeof(params));
3905
Johannes Berg984c3112013-02-14 23:43:25 +01003906 if (!rdev->ops->add_station)
3907 return -EOPNOTSUPP;
3908
Johannes Berg5727ef12007-12-19 02:03:34 +01003909 if (!info->attrs[NL80211_ATTR_MAC])
3910 return -EINVAL;
3911
Johannes Berg5727ef12007-12-19 02:03:34 +01003912 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3913 return -EINVAL;
3914
3915 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3916 return -EINVAL;
3917
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003918 if (!info->attrs[NL80211_ATTR_STA_AID])
3919 return -EINVAL;
3920
Johannes Berg5727ef12007-12-19 02:03:34 +01003921 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3922 params.supported_rates =
3923 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3924 params.supported_rates_len =
3925 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3926 params.listen_interval =
3927 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003928
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003929 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3930 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3931 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003932
Jouni Malinen9d62a982013-02-14 21:10:13 +02003933 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3934 params.capability =
3935 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3936 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3937 }
3938
3939 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3940 params.ext_capab =
3941 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3942 params.ext_capab_len =
3943 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3944 }
3945
Jouni Malinen36aedc902008-08-25 11:58:58 +03003946 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3947 params.ht_capa =
3948 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003949
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003950 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3951 params.vht_capa =
3952 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3953
Johannes Bergf8bacc22013-02-14 23:27:01 +01003954 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07003955 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003956 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3957 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3958 return -EINVAL;
3959 }
Javier Cardona96b78df2011-04-07 15:08:33 -07003960
Johannes Bergff276692013-02-15 00:09:01 +01003961 err = nl80211_parse_sta_wme(info, &params);
3962 if (err)
3963 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003964
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003965 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003966 return -EINVAL;
3967
Johannes Berg77ee7c82013-02-15 00:48:33 +01003968 /* When you run into this, adjust the code below for the new flag */
3969 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3970
Johannes Bergbdd90d52011-12-14 12:20:27 +01003971 switch (dev->ieee80211_ptr->iftype) {
3972 case NL80211_IFTYPE_AP:
3973 case NL80211_IFTYPE_AP_VLAN:
3974 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01003975 /* ignore WME attributes if iface/sta is not capable */
3976 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
3977 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
3978 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003979
Johannes Bergbdd90d52011-12-14 12:20:27 +01003980 /* TDLS peers cannot be added */
3981 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003982 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003983 /* but don't bother the driver with it */
3984 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003985
Johannes Bergd582cff2012-10-26 17:53:44 +02003986 /* allow authenticated/associated only if driver handles it */
3987 if (!(rdev->wiphy.features &
3988 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3989 params.sta_flags_mask &
3990 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3991 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3992 return -EINVAL;
3993
Johannes Bergbdd90d52011-12-14 12:20:27 +01003994 /* must be last in here for error handling */
3995 params.vlan = get_vlan(info, rdev);
3996 if (IS_ERR(params.vlan))
3997 return PTR_ERR(params.vlan);
3998 break;
3999 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004000 /* ignore uAPSD data */
4001 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4002
Johannes Bergd582cff2012-10-26 17:53:44 +02004003 /* associated is disallowed */
4004 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4005 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004006 /* TDLS peers cannot be added */
4007 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004008 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004009 break;
4010 case NL80211_IFTYPE_STATION:
Johannes Berg984c3112013-02-14 23:43:25 +01004011 /* ignore uAPSD data */
4012 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4013
Johannes Berg77ee7c82013-02-15 00:48:33 +01004014 /* these are disallowed */
4015 if (params.sta_flags_mask &
4016 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4017 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004018 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004019 /* Only TDLS peers can be added */
4020 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4021 return -EINVAL;
4022 /* Can only add if TDLS ... */
4023 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4024 return -EOPNOTSUPP;
4025 /* ... with external setup is supported */
4026 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4027 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004028 /*
4029 * Older wpa_supplicant versions always mark the TDLS peer
4030 * as authorized, but it shouldn't yet be.
4031 */
4032 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004033 break;
4034 default:
4035 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004036 }
4037
Johannes Bergbdd90d52011-12-14 12:20:27 +01004038 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004039
Hila Gonene35e4d22012-06-27 17:19:42 +03004040 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004041
Johannes Berg5727ef12007-12-19 02:03:34 +01004042 if (params.vlan)
4043 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004044 return err;
4045}
4046
4047static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4048{
Johannes Berg4c476992010-10-04 21:36:35 +02004049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4050 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004051 u8 *mac_addr = NULL;
4052
4053 if (info->attrs[NL80211_ATTR_MAC])
4054 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4055
Johannes Berge80cf852009-05-11 14:43:13 +02004056 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004057 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004058 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004059 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4060 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004061
Johannes Berg4c476992010-10-04 21:36:35 +02004062 if (!rdev->ops->del_station)
4063 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004064
Hila Gonene35e4d22012-06-27 17:19:42 +03004065 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004066}
4067
Eric W. Biederman15e47302012-09-07 20:12:54 +00004068static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004069 int flags, struct net_device *dev,
4070 u8 *dst, u8 *next_hop,
4071 struct mpath_info *pinfo)
4072{
4073 void *hdr;
4074 struct nlattr *pinfoattr;
4075
Eric W. Biederman15e47302012-09-07 20:12:54 +00004076 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004077 if (!hdr)
4078 return -1;
4079
David S. Miller9360ffd2012-03-29 04:41:26 -04004080 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4081 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4082 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4083 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4084 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004085
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004086 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4087 if (!pinfoattr)
4088 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004089 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4090 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4091 pinfo->frame_qlen))
4092 goto nla_put_failure;
4093 if (((pinfo->filled & MPATH_INFO_SN) &&
4094 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4095 ((pinfo->filled & MPATH_INFO_METRIC) &&
4096 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4097 pinfo->metric)) ||
4098 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4099 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4100 pinfo->exptime)) ||
4101 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4102 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4103 pinfo->flags)) ||
4104 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4105 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4106 pinfo->discovery_timeout)) ||
4107 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4108 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4109 pinfo->discovery_retries)))
4110 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004111
4112 nla_nest_end(msg, pinfoattr);
4113
4114 return genlmsg_end(msg, hdr);
4115
4116 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004117 genlmsg_cancel(msg, hdr);
4118 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004119}
4120
4121static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004122 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004123{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004124 struct mpath_info pinfo;
4125 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004126 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004127 u8 dst[ETH_ALEN];
4128 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02004129 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004130 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004131
Johannes Berg67748892010-10-04 21:14:06 +02004132 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4133 if (err)
4134 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004135
4136 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004137 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004138 goto out_err;
4139 }
4140
Jouni Malineneec60b02009-03-20 21:21:19 +02004141 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
4142 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004143 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004144 }
4145
Johannes Bergbba95fe2008-07-29 13:22:51 +02004146 while (1) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004147 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
4148 &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004149 if (err == -ENOENT)
4150 break;
4151 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004152 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004153
Eric W. Biederman15e47302012-09-07 20:12:54 +00004154 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004155 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4156 netdev, dst, next_hop,
4157 &pinfo) < 0)
4158 goto out;
4159
4160 path_idx++;
4161 }
4162
4163
4164 out:
4165 cb->args[1] = path_idx;
4166 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004167 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004168 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004169 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004170}
4171
4172static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4173{
Johannes Berg4c476992010-10-04 21:36:35 +02004174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004175 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004176 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004177 struct mpath_info pinfo;
4178 struct sk_buff *msg;
4179 u8 *dst = NULL;
4180 u8 next_hop[ETH_ALEN];
4181
4182 memset(&pinfo, 0, sizeof(pinfo));
4183
4184 if (!info->attrs[NL80211_ATTR_MAC])
4185 return -EINVAL;
4186
4187 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4188
Johannes Berg4c476992010-10-04 21:36:35 +02004189 if (!rdev->ops->get_mpath)
4190 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004191
Johannes Berg4c476992010-10-04 21:36:35 +02004192 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4193 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004194
Hila Gonene35e4d22012-06-27 17:19:42 +03004195 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004196 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004197 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004198
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004199 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004200 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004201 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004202
Eric W. Biederman15e47302012-09-07 20:12:54 +00004203 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004204 dev, dst, next_hop, &pinfo) < 0) {
4205 nlmsg_free(msg);
4206 return -ENOBUFS;
4207 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004208
Johannes Berg4c476992010-10-04 21:36:35 +02004209 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004210}
4211
4212static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4213{
Johannes Berg4c476992010-10-04 21:36:35 +02004214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4215 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004216 u8 *dst = NULL;
4217 u8 *next_hop = NULL;
4218
4219 if (!info->attrs[NL80211_ATTR_MAC])
4220 return -EINVAL;
4221
4222 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4223 return -EINVAL;
4224
4225 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4226 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4227
Johannes Berg4c476992010-10-04 21:36:35 +02004228 if (!rdev->ops->change_mpath)
4229 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004230
Johannes Berg4c476992010-10-04 21:36:35 +02004231 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4232 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004233
Hila Gonene35e4d22012-06-27 17:19:42 +03004234 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004235}
Johannes Berg4c476992010-10-04 21:36:35 +02004236
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004237static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4238{
Johannes Berg4c476992010-10-04 21:36:35 +02004239 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4240 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004241 u8 *dst = NULL;
4242 u8 *next_hop = NULL;
4243
4244 if (!info->attrs[NL80211_ATTR_MAC])
4245 return -EINVAL;
4246
4247 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4248 return -EINVAL;
4249
4250 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4251 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4252
Johannes Berg4c476992010-10-04 21:36:35 +02004253 if (!rdev->ops->add_mpath)
4254 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004255
Johannes Berg4c476992010-10-04 21:36:35 +02004256 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4257 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004258
Hila Gonene35e4d22012-06-27 17:19:42 +03004259 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260}
4261
4262static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4263{
Johannes Berg4c476992010-10-04 21:36:35 +02004264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4265 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004266 u8 *dst = NULL;
4267
4268 if (info->attrs[NL80211_ATTR_MAC])
4269 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4270
Johannes Berg4c476992010-10-04 21:36:35 +02004271 if (!rdev->ops->del_mpath)
4272 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004273
Hila Gonene35e4d22012-06-27 17:19:42 +03004274 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004275}
4276
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004277static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4278{
Johannes Berg4c476992010-10-04 21:36:35 +02004279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4280 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004281 struct bss_parameters params;
4282
4283 memset(&params, 0, sizeof(params));
4284 /* default to not changing parameters */
4285 params.use_cts_prot = -1;
4286 params.use_short_preamble = -1;
4287 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004288 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004289 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004290 params.p2p_ctwindow = -1;
4291 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004292
4293 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4294 params.use_cts_prot =
4295 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4296 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4297 params.use_short_preamble =
4298 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4299 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4300 params.use_short_slot_time =
4301 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004302 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4303 params.basic_rates =
4304 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4305 params.basic_rates_len =
4306 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4307 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004308 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4309 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004310 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4311 params.ht_opmode =
4312 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004313
Johannes Berg53cabad2012-11-14 15:17:28 +01004314 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4315 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4316 return -EINVAL;
4317 params.p2p_ctwindow =
4318 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4319 if (params.p2p_ctwindow < 0)
4320 return -EINVAL;
4321 if (params.p2p_ctwindow != 0 &&
4322 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4323 return -EINVAL;
4324 }
4325
4326 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4327 u8 tmp;
4328
4329 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4330 return -EINVAL;
4331 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4332 if (tmp > 1)
4333 return -EINVAL;
4334 params.p2p_opp_ps = tmp;
4335 if (params.p2p_opp_ps &&
4336 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4337 return -EINVAL;
4338 }
4339
Johannes Berg4c476992010-10-04 21:36:35 +02004340 if (!rdev->ops->change_bss)
4341 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004342
Johannes Berg074ac8d2010-09-16 14:58:22 +02004343 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004344 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4345 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004346
Hila Gonene35e4d22012-06-27 17:19:42 +03004347 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004348}
4349
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004350static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004351 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4352 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4353 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4354 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4355 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4356 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4357};
4358
4359static int parse_reg_rule(struct nlattr *tb[],
4360 struct ieee80211_reg_rule *reg_rule)
4361{
4362 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4363 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4364
4365 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4366 return -EINVAL;
4367 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4368 return -EINVAL;
4369 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4370 return -EINVAL;
4371 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4372 return -EINVAL;
4373 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4374 return -EINVAL;
4375
4376 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4377
4378 freq_range->start_freq_khz =
4379 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4380 freq_range->end_freq_khz =
4381 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4382 freq_range->max_bandwidth_khz =
4383 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4384
4385 power_rule->max_eirp =
4386 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4387
4388 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4389 power_rule->max_antenna_gain =
4390 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4391
4392 return 0;
4393}
4394
4395static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4396{
4397 int r;
4398 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004399 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004400
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004401 /*
4402 * You should only get this when cfg80211 hasn't yet initialized
4403 * completely when built-in to the kernel right between the time
4404 * window between nl80211_init() and regulatory_init(), if that is
4405 * even possible.
4406 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004407 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004408 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004409
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004410 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4411 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004412
4413 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4414
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004415 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4416 user_reg_hint_type =
4417 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4418 else
4419 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4420
4421 switch (user_reg_hint_type) {
4422 case NL80211_USER_REG_HINT_USER:
4423 case NL80211_USER_REG_HINT_CELL_BASE:
4424 break;
4425 default:
4426 return -EINVAL;
4427 }
4428
4429 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004430
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004431 return r;
4432}
4433
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004434static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004435 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004436{
Johannes Berg4c476992010-10-04 21:36:35 +02004437 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004438 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004439 struct wireless_dev *wdev = dev->ieee80211_ptr;
4440 struct mesh_config cur_params;
4441 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004442 void *hdr;
4443 struct nlattr *pinfoattr;
4444 struct sk_buff *msg;
4445
Johannes Berg29cbe682010-12-03 09:20:44 +01004446 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4447 return -EOPNOTSUPP;
4448
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004449 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004450 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004451
Johannes Berg29cbe682010-12-03 09:20:44 +01004452 wdev_lock(wdev);
4453 /* If not connected, get default parameters */
4454 if (!wdev->mesh_id_len)
4455 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4456 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004457 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004458 wdev_unlock(wdev);
4459
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004460 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004461 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004462
4463 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004464 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004465 if (!msg)
4466 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004467 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004468 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004469 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004470 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004471 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004472 if (!pinfoattr)
4473 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004474 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4475 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4476 cur_params.dot11MeshRetryTimeout) ||
4477 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4478 cur_params.dot11MeshConfirmTimeout) ||
4479 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4480 cur_params.dot11MeshHoldingTimeout) ||
4481 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4482 cur_params.dot11MeshMaxPeerLinks) ||
4483 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4484 cur_params.dot11MeshMaxRetries) ||
4485 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4486 cur_params.dot11MeshTTL) ||
4487 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4488 cur_params.element_ttl) ||
4489 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4490 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004491 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4492 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004493 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4494 cur_params.dot11MeshHWMPmaxPREQretries) ||
4495 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4496 cur_params.path_refresh_time) ||
4497 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4498 cur_params.min_discovery_timeout) ||
4499 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4500 cur_params.dot11MeshHWMPactivePathTimeout) ||
4501 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4502 cur_params.dot11MeshHWMPpreqMinInterval) ||
4503 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4504 cur_params.dot11MeshHWMPperrMinInterval) ||
4505 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4506 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4507 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4508 cur_params.dot11MeshHWMPRootMode) ||
4509 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4510 cur_params.dot11MeshHWMPRannInterval) ||
4511 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4512 cur_params.dot11MeshGateAnnouncementProtocol) ||
4513 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4514 cur_params.dot11MeshForwarding) ||
4515 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004516 cur_params.rssi_threshold) ||
4517 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004518 cur_params.ht_opmode) ||
4519 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4520 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4521 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004522 cur_params.dot11MeshHWMProotInterval) ||
4523 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004524 cur_params.dot11MeshHWMPconfirmationInterval) ||
4525 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4526 cur_params.power_mode) ||
4527 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4528 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004529 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004530 nla_nest_end(msg, pinfoattr);
4531 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004532 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004533
Johannes Berg3b858752009-03-12 09:55:09 +01004534 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004535 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004536 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004537 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004538 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004539}
4540
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004541static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004542 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4543 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4544 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4545 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4546 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4547 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004548 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004549 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004550 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004551 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4552 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4553 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4554 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4555 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004556 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004557 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004558 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004559 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004560 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004561 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004562 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4563 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004564 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4565 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004566 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004567 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4568 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004569};
4570
Javier Cardonac80d5452010-12-16 17:37:49 -08004571static const struct nla_policy
4572 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004573 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004574 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4575 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004576 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004577 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004578 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004579 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004580};
4581
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004582static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004583 struct mesh_config *cfg,
4584 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004585{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004586 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004587 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004588
Marco Porschea54fba2013-01-07 16:04:48 +01004589#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4590do { \
4591 if (tb[attr]) { \
4592 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4593 return -EINVAL; \
4594 cfg->param = fn(tb[attr]); \
4595 mask |= (1 << (attr - 1)); \
4596 } \
4597} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004598
4599
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004600 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004601 return -EINVAL;
4602 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004603 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004604 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004605 return -EINVAL;
4606
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004607 /* This makes sure that there aren't more than 32 mesh config
4608 * parameters (otherwise our bitfield scheme would not work.) */
4609 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4610
4611 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004612 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004613 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4614 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004615 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004616 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4617 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004618 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004619 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4620 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004621 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004622 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4623 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004624 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004625 mask, NL80211_MESHCONF_MAX_RETRIES,
4626 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004627 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004628 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004629 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004630 mask, NL80211_MESHCONF_ELEMENT_TTL,
4631 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004632 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004633 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4634 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004635 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4636 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004637 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4638 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004639 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004640 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4641 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004642 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004643 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4644 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004645 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004646 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4647 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004648 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4649 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004650 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4651 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004652 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004653 1, 65535, mask,
4654 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004655 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004656 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004657 1, 65535, mask,
4658 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004659 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004660 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004661 dot11MeshHWMPnetDiameterTraversalTime,
4662 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004663 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4664 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004665 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4666 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4667 nla_get_u8);
4668 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4669 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004670 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004671 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004672 dot11MeshGateAnnouncementProtocol, 0, 1,
4673 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004674 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004676 mask, NL80211_MESHCONF_FORWARDING,
4677 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004679 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4680 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004681 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004682 mask, NL80211_MESHCONF_HT_OPMODE,
4683 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004685 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004686 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4687 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004688 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004689 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4690 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004691 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004692 dot11MeshHWMPconfirmationInterval,
4693 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004694 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4695 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004696 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4697 NL80211_MESH_POWER_ACTIVE,
4698 NL80211_MESH_POWER_MAX,
4699 mask, NL80211_MESHCONF_POWER_MODE,
4700 nla_get_u32);
4701 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4702 0, 65535, mask,
4703 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004704 if (mask_out)
4705 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004706
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004707 return 0;
4708
4709#undef FILL_IN_MESH_PARAM_IF_SET
4710}
4711
Javier Cardonac80d5452010-12-16 17:37:49 -08004712static int nl80211_parse_mesh_setup(struct genl_info *info,
4713 struct mesh_setup *setup)
4714{
4715 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4716
4717 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4718 return -EINVAL;
4719 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4720 info->attrs[NL80211_ATTR_MESH_SETUP],
4721 nl80211_mesh_setup_params_policy))
4722 return -EINVAL;
4723
Javier Cardonad299a1f2012-03-31 11:31:33 -07004724 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4725 setup->sync_method =
4726 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4727 IEEE80211_SYNC_METHOD_VENDOR :
4728 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4729
Javier Cardonac80d5452010-12-16 17:37:49 -08004730 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4731 setup->path_sel_proto =
4732 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4733 IEEE80211_PATH_PROTOCOL_VENDOR :
4734 IEEE80211_PATH_PROTOCOL_HWMP;
4735
4736 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4737 setup->path_metric =
4738 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4739 IEEE80211_PATH_METRIC_VENDOR :
4740 IEEE80211_PATH_METRIC_AIRTIME;
4741
Javier Cardona581a8b02011-04-07 15:08:27 -07004742
4743 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004744 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004745 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004746 if (!is_valid_ie_attr(ieattr))
4747 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004748 setup->ie = nla_data(ieattr);
4749 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004750 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07004751 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4752 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08004753
4754 return 0;
4755}
4756
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004757static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004758 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004759{
4760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4761 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004762 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004763 struct mesh_config cfg;
4764 u32 mask;
4765 int err;
4766
Johannes Berg29cbe682010-12-03 09:20:44 +01004767 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4768 return -EOPNOTSUPP;
4769
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004770 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004771 return -EOPNOTSUPP;
4772
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004773 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004774 if (err)
4775 return err;
4776
Johannes Berg29cbe682010-12-03 09:20:44 +01004777 wdev_lock(wdev);
4778 if (!wdev->mesh_id_len)
4779 err = -ENOLINK;
4780
4781 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004782 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004783
4784 wdev_unlock(wdev);
4785
4786 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004787}
4788
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004789static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4790{
Johannes Berg458f4f92012-12-06 15:47:38 +01004791 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004792 struct sk_buff *msg;
4793 void *hdr = NULL;
4794 struct nlattr *nl_reg_rules;
4795 unsigned int i;
4796 int err = -EINVAL;
4797
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004798 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004799
4800 if (!cfg80211_regdomain)
4801 goto out;
4802
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004804 if (!msg) {
4805 err = -ENOBUFS;
4806 goto out;
4807 }
4808
Eric W. Biederman15e47302012-09-07 20:12:54 +00004809 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004810 NL80211_CMD_GET_REG);
4811 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004812 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004813
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004814 if (reg_last_request_cell_base() &&
4815 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4816 NL80211_USER_REG_HINT_CELL_BASE))
4817 goto nla_put_failure;
4818
Johannes Berg458f4f92012-12-06 15:47:38 +01004819 rcu_read_lock();
4820 regdom = rcu_dereference(cfg80211_regdomain);
4821
4822 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4823 (regdom->dfs_region &&
4824 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4825 goto nla_put_failure_rcu;
4826
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004827 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4828 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004829 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004830
Johannes Berg458f4f92012-12-06 15:47:38 +01004831 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004832 struct nlattr *nl_reg_rule;
4833 const struct ieee80211_reg_rule *reg_rule;
4834 const struct ieee80211_freq_range *freq_range;
4835 const struct ieee80211_power_rule *power_rule;
4836
Johannes Berg458f4f92012-12-06 15:47:38 +01004837 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004838 freq_range = &reg_rule->freq_range;
4839 power_rule = &reg_rule->power_rule;
4840
4841 nl_reg_rule = nla_nest_start(msg, i);
4842 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004843 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004844
David S. Miller9360ffd2012-03-29 04:41:26 -04004845 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4846 reg_rule->flags) ||
4847 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4848 freq_range->start_freq_khz) ||
4849 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4850 freq_range->end_freq_khz) ||
4851 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4852 freq_range->max_bandwidth_khz) ||
4853 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4854 power_rule->max_antenna_gain) ||
4855 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4856 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004857 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004858
4859 nla_nest_end(msg, nl_reg_rule);
4860 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004861 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004862
4863 nla_nest_end(msg, nl_reg_rules);
4864
4865 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004866 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004867 goto out;
4868
Johannes Berg458f4f92012-12-06 15:47:38 +01004869nla_put_failure_rcu:
4870 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004871nla_put_failure:
4872 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004873put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004874 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004875 err = -EMSGSIZE;
4876out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004877 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004878 return err;
4879}
4880
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004881static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4882{
4883 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4884 struct nlattr *nl_reg_rule;
4885 char *alpha2 = NULL;
4886 int rem_reg_rules = 0, r = 0;
4887 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004888 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004889 struct ieee80211_regdomain *rd = NULL;
4890
4891 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4892 return -EINVAL;
4893
4894 if (!info->attrs[NL80211_ATTR_REG_RULES])
4895 return -EINVAL;
4896
4897 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4898
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004899 if (info->attrs[NL80211_ATTR_DFS_REGION])
4900 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4901
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004902 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004903 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004904 num_rules++;
4905 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004906 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004907 }
4908
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004909 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004910 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004911
4912 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004913 if (!rd)
4914 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004915
4916 rd->n_reg_rules = num_rules;
4917 rd->alpha2[0] = alpha2[0];
4918 rd->alpha2[1] = alpha2[1];
4919
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004920 /*
4921 * Disable DFS master mode if the DFS region was
4922 * not supported or known on this kernel.
4923 */
4924 if (reg_supported_dfs_region(dfs_region))
4925 rd->dfs_region = dfs_region;
4926
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004927 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004928 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004929 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004930 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4931 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004932 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4933 if (r)
4934 goto bad_reg;
4935
4936 rule_idx++;
4937
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004938 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4939 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004940 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004941 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004942 }
4943
Johannes Berg6913b492012-12-04 00:48:59 +01004944 mutex_lock(&cfg80211_mutex);
4945
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004946 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01004947 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01004948 rd = NULL;
Johannes Berg6913b492012-12-04 00:48:59 +01004949 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004950
Johannes Bergd2372b32008-10-24 20:32:20 +02004951 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004952 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004953 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004954}
4955
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004956static int validate_scan_freqs(struct nlattr *freqs)
4957{
4958 struct nlattr *attr1, *attr2;
4959 int n_channels = 0, tmp1, tmp2;
4960
4961 nla_for_each_nested(attr1, freqs, tmp1) {
4962 n_channels++;
4963 /*
4964 * Some hardware has a limited channel list for
4965 * scanning, and it is pretty much nonsensical
4966 * to scan for a channel twice, so disallow that
4967 * and don't require drivers to check that the
4968 * channel list they get isn't longer than what
4969 * they can scan, as long as they can scan all
4970 * the channels they registered at once.
4971 */
4972 nla_for_each_nested(attr2, freqs, tmp2)
4973 if (attr1 != attr2 &&
4974 nla_get_u32(attr1) == nla_get_u32(attr2))
4975 return 0;
4976 }
4977
4978 return n_channels;
4979}
4980
Johannes Berg2a519312009-02-10 21:25:55 +01004981static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4982{
Johannes Berg4c476992010-10-04 21:36:35 +02004983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02004984 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004985 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004986 struct nlattr *attr;
4987 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004988 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004989 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004990
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004991 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4992 return -EINVAL;
4993
Johannes Berg79c97e92009-07-07 03:56:12 +02004994 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004995
Johannes Berg4c476992010-10-04 21:36:35 +02004996 if (!rdev->ops->scan)
4997 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004998
Johannes Berg4c476992010-10-04 21:36:35 +02004999 if (rdev->scan_req)
5000 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01005001
5002 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005003 n_channels = validate_scan_freqs(
5004 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02005005 if (!n_channels)
5006 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005007 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005008 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005009 n_channels = 0;
5010
Johannes Berg2a519312009-02-10 21:25:55 +01005011 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5012 if (wiphy->bands[band])
5013 n_channels += wiphy->bands[band]->n_channels;
5014 }
5015
5016 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5017 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5018 n_ssids++;
5019
Johannes Berg4c476992010-10-04 21:36:35 +02005020 if (n_ssids > wiphy->max_scan_ssids)
5021 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005022
Jouni Malinen70692ad2009-02-16 19:39:13 +02005023 if (info->attrs[NL80211_ATTR_IE])
5024 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5025 else
5026 ie_len = 0;
5027
Johannes Berg4c476992010-10-04 21:36:35 +02005028 if (ie_len > wiphy->max_scan_ie_len)
5029 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02005030
Johannes Berg2a519312009-02-10 21:25:55 +01005031 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005032 + sizeof(*request->ssids) * n_ssids
5033 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005034 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005035 if (!request)
5036 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01005037
Johannes Berg2a519312009-02-10 21:25:55 +01005038 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005039 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005040 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005041 if (ie_len) {
5042 if (request->ssids)
5043 request->ie = (void *)(request->ssids + n_ssids);
5044 else
5045 request->ie = (void *)(request->channels + n_channels);
5046 }
Johannes Berg2a519312009-02-10 21:25:55 +01005047
Johannes Berg584991d2009-11-02 13:32:03 +01005048 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005049 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5050 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005051 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005052 struct ieee80211_channel *chan;
5053
5054 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5055
5056 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005057 err = -EINVAL;
5058 goto out_free;
5059 }
Johannes Berg584991d2009-11-02 13:32:03 +01005060
5061 /* ignore disabled channels */
5062 if (chan->flags & IEEE80211_CHAN_DISABLED)
5063 continue;
5064
5065 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005066 i++;
5067 }
5068 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005069 enum ieee80211_band band;
5070
Johannes Berg2a519312009-02-10 21:25:55 +01005071 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005072 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5073 int j;
5074 if (!wiphy->bands[band])
5075 continue;
5076 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005077 struct ieee80211_channel *chan;
5078
5079 chan = &wiphy->bands[band]->channels[j];
5080
5081 if (chan->flags & IEEE80211_CHAN_DISABLED)
5082 continue;
5083
5084 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005085 i++;
5086 }
5087 }
5088 }
5089
Johannes Berg584991d2009-11-02 13:32:03 +01005090 if (!i) {
5091 err = -EINVAL;
5092 goto out_free;
5093 }
5094
5095 request->n_channels = i;
5096
Johannes Berg2a519312009-02-10 21:25:55 +01005097 i = 0;
5098 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5099 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005100 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005101 err = -EINVAL;
5102 goto out_free;
5103 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005104 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005105 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005106 i++;
5107 }
5108 }
5109
Jouni Malinen70692ad2009-02-16 19:39:13 +02005110 if (info->attrs[NL80211_ATTR_IE]) {
5111 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005112 memcpy((void *)request->ie,
5113 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005114 request->ie_len);
5115 }
5116
Johannes Berg34850ab2011-07-18 18:08:35 +02005117 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005118 if (wiphy->bands[i])
5119 request->rates[i] =
5120 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005121
5122 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5123 nla_for_each_nested(attr,
5124 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5125 tmp) {
5126 enum ieee80211_band band = nla_type(attr);
5127
Dan Carpenter84404622011-07-29 11:52:18 +03005128 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005129 err = -EINVAL;
5130 goto out_free;
5131 }
5132 err = ieee80211_get_ratemask(wiphy->bands[band],
5133 nla_data(attr),
5134 nla_len(attr),
5135 &request->rates[band]);
5136 if (err)
5137 goto out_free;
5138 }
5139 }
5140
Sam Leffler46856bb2012-10-11 21:03:32 -07005141 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005142 request->flags = nla_get_u32(
5143 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005144 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5145 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5146 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5147 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005148 err = -EOPNOTSUPP;
5149 goto out_free;
5150 }
5151 }
Sam Lefflered4737712012-10-11 21:03:31 -07005152
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305153 request->no_cck =
5154 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5155
Johannes Bergfd014282012-06-18 19:17:03 +02005156 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005157 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005158 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005159
Johannes Berg79c97e92009-07-07 03:56:12 +02005160 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005161 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005162
Johannes Berg463d0182009-07-14 00:33:35 +02005163 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005164 nl80211_send_scan_start(rdev, wdev);
5165 if (wdev->netdev)
5166 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005167 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005168 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005169 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005170 kfree(request);
5171 }
Johannes Berg3b858752009-03-12 09:55:09 +01005172
Johannes Berg2a519312009-02-10 21:25:55 +01005173 return err;
5174}
5175
Luciano Coelho807f8a82011-05-11 17:09:35 +03005176static int nl80211_start_sched_scan(struct sk_buff *skb,
5177 struct genl_info *info)
5178{
5179 struct cfg80211_sched_scan_request *request;
5180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5181 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005182 struct nlattr *attr;
5183 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005184 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005185 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005186 enum ieee80211_band band;
5187 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005188 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005189
5190 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5191 !rdev->ops->sched_scan_start)
5192 return -EOPNOTSUPP;
5193
5194 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5195 return -EINVAL;
5196
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005197 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5198 return -EINVAL;
5199
5200 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5201 if (interval == 0)
5202 return -EINVAL;
5203
Luciano Coelho807f8a82011-05-11 17:09:35 +03005204 wiphy = &rdev->wiphy;
5205
5206 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5207 n_channels = validate_scan_freqs(
5208 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5209 if (!n_channels)
5210 return -EINVAL;
5211 } else {
5212 n_channels = 0;
5213
5214 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5215 if (wiphy->bands[band])
5216 n_channels += wiphy->bands[band]->n_channels;
5217 }
5218
5219 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5220 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5221 tmp)
5222 n_ssids++;
5223
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005224 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005225 return -EINVAL;
5226
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005227 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5228 nla_for_each_nested(attr,
5229 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5230 tmp)
5231 n_match_sets++;
5232
5233 if (n_match_sets > wiphy->max_match_sets)
5234 return -EINVAL;
5235
Luciano Coelho807f8a82011-05-11 17:09:35 +03005236 if (info->attrs[NL80211_ATTR_IE])
5237 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5238 else
5239 ie_len = 0;
5240
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005241 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005242 return -EINVAL;
5243
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005244 mutex_lock(&rdev->sched_scan_mtx);
5245
5246 if (rdev->sched_scan_req) {
5247 err = -EINPROGRESS;
5248 goto out;
5249 }
5250
Luciano Coelho807f8a82011-05-11 17:09:35 +03005251 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005252 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005253 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005254 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005255 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005256 if (!request) {
5257 err = -ENOMEM;
5258 goto out;
5259 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005260
5261 if (n_ssids)
5262 request->ssids = (void *)&request->channels[n_channels];
5263 request->n_ssids = n_ssids;
5264 if (ie_len) {
5265 if (request->ssids)
5266 request->ie = (void *)(request->ssids + n_ssids);
5267 else
5268 request->ie = (void *)(request->channels + n_channels);
5269 }
5270
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005271 if (n_match_sets) {
5272 if (request->ie)
5273 request->match_sets = (void *)(request->ie + ie_len);
5274 else if (request->ssids)
5275 request->match_sets =
5276 (void *)(request->ssids + n_ssids);
5277 else
5278 request->match_sets =
5279 (void *)(request->channels + n_channels);
5280 }
5281 request->n_match_sets = n_match_sets;
5282
Luciano Coelho807f8a82011-05-11 17:09:35 +03005283 i = 0;
5284 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5285 /* user specified, bail out if channel not found */
5286 nla_for_each_nested(attr,
5287 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5288 tmp) {
5289 struct ieee80211_channel *chan;
5290
5291 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5292
5293 if (!chan) {
5294 err = -EINVAL;
5295 goto out_free;
5296 }
5297
5298 /* ignore disabled channels */
5299 if (chan->flags & IEEE80211_CHAN_DISABLED)
5300 continue;
5301
5302 request->channels[i] = chan;
5303 i++;
5304 }
5305 } else {
5306 /* all channels */
5307 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5308 int j;
5309 if (!wiphy->bands[band])
5310 continue;
5311 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5312 struct ieee80211_channel *chan;
5313
5314 chan = &wiphy->bands[band]->channels[j];
5315
5316 if (chan->flags & IEEE80211_CHAN_DISABLED)
5317 continue;
5318
5319 request->channels[i] = chan;
5320 i++;
5321 }
5322 }
5323 }
5324
5325 if (!i) {
5326 err = -EINVAL;
5327 goto out_free;
5328 }
5329
5330 request->n_channels = i;
5331
5332 i = 0;
5333 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5334 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5335 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005336 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005337 err = -EINVAL;
5338 goto out_free;
5339 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005340 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005341 memcpy(request->ssids[i].ssid, nla_data(attr),
5342 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005343 i++;
5344 }
5345 }
5346
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005347 i = 0;
5348 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5349 nla_for_each_nested(attr,
5350 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5351 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005352 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005353
5354 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5355 nla_data(attr), nla_len(attr),
5356 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005357 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005358 if (ssid) {
5359 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5360 err = -EINVAL;
5361 goto out_free;
5362 }
5363 memcpy(request->match_sets[i].ssid.ssid,
5364 nla_data(ssid), nla_len(ssid));
5365 request->match_sets[i].ssid.ssid_len =
5366 nla_len(ssid);
5367 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005368 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5369 if (rssi)
5370 request->rssi_thold = nla_get_u32(rssi);
5371 else
5372 request->rssi_thold =
5373 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005374 i++;
5375 }
5376 }
5377
Luciano Coelho807f8a82011-05-11 17:09:35 +03005378 if (info->attrs[NL80211_ATTR_IE]) {
5379 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5380 memcpy((void *)request->ie,
5381 nla_data(info->attrs[NL80211_ATTR_IE]),
5382 request->ie_len);
5383 }
5384
Sam Leffler46856bb2012-10-11 21:03:32 -07005385 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005386 request->flags = nla_get_u32(
5387 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005388 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5389 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5390 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5391 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005392 err = -EOPNOTSUPP;
5393 goto out_free;
5394 }
5395 }
Sam Lefflered4737712012-10-11 21:03:31 -07005396
Luciano Coelho807f8a82011-05-11 17:09:35 +03005397 request->dev = dev;
5398 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005399 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005400 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005401
Hila Gonene35e4d22012-06-27 17:19:42 +03005402 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005403 if (!err) {
5404 rdev->sched_scan_req = request;
5405 nl80211_send_sched_scan(rdev, dev,
5406 NL80211_CMD_START_SCHED_SCAN);
5407 goto out;
5408 }
5409
5410out_free:
5411 kfree(request);
5412out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005413 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005414 return err;
5415}
5416
5417static int nl80211_stop_sched_scan(struct sk_buff *skb,
5418 struct genl_info *info)
5419{
5420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005421 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005422
5423 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5424 !rdev->ops->sched_scan_stop)
5425 return -EOPNOTSUPP;
5426
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005427 mutex_lock(&rdev->sched_scan_mtx);
5428 err = __cfg80211_stop_sched_scan(rdev, false);
5429 mutex_unlock(&rdev->sched_scan_mtx);
5430
5431 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005432}
5433
Simon Wunderlich04f39042013-02-08 18:16:19 +01005434static int nl80211_start_radar_detection(struct sk_buff *skb,
5435 struct genl_info *info)
5436{
5437 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5438 struct net_device *dev = info->user_ptr[1];
5439 struct wireless_dev *wdev = dev->ieee80211_ptr;
5440 struct cfg80211_chan_def chandef;
5441 int err;
5442
5443 err = nl80211_parse_chandef(rdev, info, &chandef);
5444 if (err)
5445 return err;
5446
5447 if (wdev->cac_started)
5448 return -EBUSY;
5449
5450 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5451 if (err < 0)
5452 return err;
5453
5454 if (err == 0)
5455 return -EINVAL;
5456
5457 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5458 return -EINVAL;
5459
5460 if (!rdev->ops->start_radar_detection)
5461 return -EOPNOTSUPP;
5462
5463 mutex_lock(&rdev->devlist_mtx);
5464 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5465 chandef.chan, CHAN_MODE_SHARED,
5466 BIT(chandef.width));
5467 if (err)
5468 goto err_locked;
5469
5470 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5471 if (!err) {
5472 wdev->channel = chandef.chan;
5473 wdev->cac_started = true;
5474 wdev->cac_start_time = jiffies;
5475 }
5476err_locked:
5477 mutex_unlock(&rdev->devlist_mtx);
5478
5479 return err;
5480}
5481
Johannes Berg9720bb32011-06-21 09:45:33 +02005482static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5483 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005484 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005485 struct wireless_dev *wdev,
5486 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005487{
Johannes Berg48ab9052009-07-10 18:42:31 +02005488 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005489 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005490 void *hdr;
5491 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005492 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005493
5494 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005495
Eric W. Biederman15e47302012-09-07 20:12:54 +00005496 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005497 NL80211_CMD_NEW_SCAN_RESULTS);
5498 if (!hdr)
5499 return -1;
5500
Johannes Berg9720bb32011-06-21 09:45:33 +02005501 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5502
David S. Miller9360ffd2012-03-29 04:41:26 -04005503 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5504 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5505 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005506
5507 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5508 if (!bss)
5509 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005510 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005511 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005512 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005513
5514 rcu_read_lock();
5515 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005516 if (ies) {
5517 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5518 goto fail_unlock_rcu;
5519 tsf = true;
5520 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5521 ies->len, ies->data))
5522 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005523 }
5524 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005525 if (ies) {
5526 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5527 goto fail_unlock_rcu;
5528 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5529 ies->len, ies->data))
5530 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005531 }
5532 rcu_read_unlock();
5533
David S. Miller9360ffd2012-03-29 04:41:26 -04005534 if (res->beacon_interval &&
5535 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5536 goto nla_put_failure;
5537 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5538 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5539 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5540 jiffies_to_msecs(jiffies - intbss->ts)))
5541 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005542
Johannes Berg77965c92009-02-18 18:45:06 +01005543 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005544 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005545 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5546 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005547 break;
5548 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005549 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5550 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005551 break;
5552 default:
5553 break;
5554 }
5555
Johannes Berg48ab9052009-07-10 18:42:31 +02005556 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005557 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005558 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005559 if (intbss == wdev->current_bss &&
5560 nla_put_u32(msg, NL80211_BSS_STATUS,
5561 NL80211_BSS_STATUS_ASSOCIATED))
5562 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005563 break;
5564 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005565 if (intbss == wdev->current_bss &&
5566 nla_put_u32(msg, NL80211_BSS_STATUS,
5567 NL80211_BSS_STATUS_IBSS_JOINED))
5568 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005569 break;
5570 default:
5571 break;
5572 }
5573
Johannes Berg2a519312009-02-10 21:25:55 +01005574 nla_nest_end(msg, bss);
5575
5576 return genlmsg_end(msg, hdr);
5577
Johannes Berg8cef2c92013-02-05 16:54:31 +01005578 fail_unlock_rcu:
5579 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005580 nla_put_failure:
5581 genlmsg_cancel(msg, hdr);
5582 return -EMSGSIZE;
5583}
5584
5585static int nl80211_dump_scan(struct sk_buff *skb,
5586 struct netlink_callback *cb)
5587{
Johannes Berg48ab9052009-07-10 18:42:31 +02005588 struct cfg80211_registered_device *rdev;
5589 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01005590 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005591 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005592 int start = cb->args[1], idx = 0;
5593 int err;
5594
Johannes Berg67748892010-10-04 21:14:06 +02005595 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5596 if (err)
5597 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005598
Johannes Berg48ab9052009-07-10 18:42:31 +02005599 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01005600
Johannes Berg48ab9052009-07-10 18:42:31 +02005601 wdev_lock(wdev);
5602 spin_lock_bh(&rdev->bss_lock);
5603 cfg80211_bss_expire(rdev);
5604
Johannes Berg9720bb32011-06-21 09:45:33 +02005605 cb->seq = rdev->bss_generation;
5606
Johannes Berg48ab9052009-07-10 18:42:31 +02005607 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005608 if (++idx <= start)
5609 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005610 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005611 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005612 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005613 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005614 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005615 }
5616 }
5617
Johannes Berg48ab9052009-07-10 18:42:31 +02005618 spin_unlock_bh(&rdev->bss_lock);
5619 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005620
5621 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02005622 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005623
Johannes Berg67748892010-10-04 21:14:06 +02005624 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005625}
5626
Eric W. Biederman15e47302012-09-07 20:12:54 +00005627static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005628 int flags, struct net_device *dev,
5629 struct survey_info *survey)
5630{
5631 void *hdr;
5632 struct nlattr *infoattr;
5633
Eric W. Biederman15e47302012-09-07 20:12:54 +00005634 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005635 NL80211_CMD_NEW_SURVEY_RESULTS);
5636 if (!hdr)
5637 return -ENOMEM;
5638
David S. Miller9360ffd2012-03-29 04:41:26 -04005639 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5640 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005641
5642 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5643 if (!infoattr)
5644 goto nla_put_failure;
5645
David S. Miller9360ffd2012-03-29 04:41:26 -04005646 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5647 survey->channel->center_freq))
5648 goto nla_put_failure;
5649
5650 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5651 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5652 goto nla_put_failure;
5653 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5654 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5655 goto nla_put_failure;
5656 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5657 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5658 survey->channel_time))
5659 goto nla_put_failure;
5660 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5661 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5662 survey->channel_time_busy))
5663 goto nla_put_failure;
5664 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5665 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5666 survey->channel_time_ext_busy))
5667 goto nla_put_failure;
5668 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5669 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5670 survey->channel_time_rx))
5671 goto nla_put_failure;
5672 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5673 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5674 survey->channel_time_tx))
5675 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005676
5677 nla_nest_end(msg, infoattr);
5678
5679 return genlmsg_end(msg, hdr);
5680
5681 nla_put_failure:
5682 genlmsg_cancel(msg, hdr);
5683 return -EMSGSIZE;
5684}
5685
5686static int nl80211_dump_survey(struct sk_buff *skb,
5687 struct netlink_callback *cb)
5688{
5689 struct survey_info survey;
5690 struct cfg80211_registered_device *dev;
5691 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01005692 int survey_idx = cb->args[1];
5693 int res;
5694
Johannes Berg67748892010-10-04 21:14:06 +02005695 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5696 if (res)
5697 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005698
5699 if (!dev->ops->dump_survey) {
5700 res = -EOPNOTSUPP;
5701 goto out_err;
5702 }
5703
5704 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005705 struct ieee80211_channel *chan;
5706
Hila Gonene35e4d22012-06-27 17:19:42 +03005707 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005708 if (res == -ENOENT)
5709 break;
5710 if (res)
5711 goto out_err;
5712
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005713 /* Survey without a channel doesn't make sense */
5714 if (!survey.channel) {
5715 res = -EINVAL;
5716 goto out;
5717 }
5718
5719 chan = ieee80211_get_channel(&dev->wiphy,
5720 survey.channel->center_freq);
5721 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5722 survey_idx++;
5723 continue;
5724 }
5725
Holger Schurig61fa7132009-11-11 12:25:40 +01005726 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005727 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005728 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5729 netdev,
5730 &survey) < 0)
5731 goto out;
5732 survey_idx++;
5733 }
5734
5735 out:
5736 cb->args[1] = survey_idx;
5737 res = skb->len;
5738 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02005739 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005740 return res;
5741}
5742
Samuel Ortizb23aa672009-07-01 21:26:54 +02005743static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5744{
5745 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5746 NL80211_WPA_VERSION_2));
5747}
5748
Jouni Malinen636a5d32009-03-19 13:39:22 +02005749static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5750{
Johannes Berg4c476992010-10-04 21:36:35 +02005751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5752 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005753 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005754 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5755 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005756 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005757 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005758 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005759
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005760 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5761 return -EINVAL;
5762
5763 if (!info->attrs[NL80211_ATTR_MAC])
5764 return -EINVAL;
5765
Jouni Malinen17780922009-03-27 20:52:47 +02005766 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5767 return -EINVAL;
5768
Johannes Berg19957bb2009-07-02 17:20:43 +02005769 if (!info->attrs[NL80211_ATTR_SSID])
5770 return -EINVAL;
5771
5772 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5773 return -EINVAL;
5774
Johannes Bergfffd0932009-07-08 14:22:54 +02005775 err = nl80211_parse_key(info, &key);
5776 if (err)
5777 return err;
5778
5779 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005780 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5781 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005782 if (!key.p.key || !key.p.key_len)
5783 return -EINVAL;
5784 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5785 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5786 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5787 key.p.key_len != WLAN_KEY_LEN_WEP104))
5788 return -EINVAL;
5789 if (key.idx > 4)
5790 return -EINVAL;
5791 } else {
5792 key.p.key_len = 0;
5793 key.p.key = NULL;
5794 }
5795
Johannes Bergafea0b72010-08-10 09:46:42 +02005796 if (key.idx >= 0) {
5797 int i;
5798 bool ok = false;
5799 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5800 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5801 ok = true;
5802 break;
5803 }
5804 }
Johannes Berg4c476992010-10-04 21:36:35 +02005805 if (!ok)
5806 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005807 }
5808
Johannes Berg4c476992010-10-04 21:36:35 +02005809 if (!rdev->ops->auth)
5810 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005811
Johannes Berg074ac8d2010-09-16 14:58:22 +02005812 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005813 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5814 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005815
Johannes Berg19957bb2009-07-02 17:20:43 +02005816 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005817 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005818 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005819 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5820 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005821
Johannes Berg19957bb2009-07-02 17:20:43 +02005822 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5823 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5824
5825 if (info->attrs[NL80211_ATTR_IE]) {
5826 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5827 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5828 }
5829
5830 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005831 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005832 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005833
Jouni Malinene39e5b52012-09-30 19:29:39 +03005834 if (auth_type == NL80211_AUTHTYPE_SAE &&
5835 !info->attrs[NL80211_ATTR_SAE_DATA])
5836 return -EINVAL;
5837
5838 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5839 if (auth_type != NL80211_AUTHTYPE_SAE)
5840 return -EINVAL;
5841 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5842 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5843 /* need to include at least Auth Transaction and Status Code */
5844 if (sae_data_len < 4)
5845 return -EINVAL;
5846 }
5847
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005848 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5849
Johannes Berg95de8172012-01-20 13:55:25 +01005850 /*
5851 * Since we no longer track auth state, ignore
5852 * requests to only change local state.
5853 */
5854 if (local_state_change)
5855 return 0;
5856
Johannes Berg4c476992010-10-04 21:36:35 +02005857 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5858 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005859 key.p.key, key.p.key_len, key.idx,
5860 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005861}
5862
Johannes Bergc0692b82010-08-27 14:26:53 +03005863static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5864 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005865 struct cfg80211_crypto_settings *settings,
5866 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005867{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005868 memset(settings, 0, sizeof(*settings));
5869
Samuel Ortizb23aa672009-07-01 21:26:54 +02005870 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5871
Johannes Bergc0692b82010-08-27 14:26:53 +03005872 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5873 u16 proto;
5874 proto = nla_get_u16(
5875 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5876 settings->control_port_ethertype = cpu_to_be16(proto);
5877 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5878 proto != ETH_P_PAE)
5879 return -EINVAL;
5880 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5881 settings->control_port_no_encrypt = true;
5882 } else
5883 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5884
Samuel Ortizb23aa672009-07-01 21:26:54 +02005885 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5886 void *data;
5887 int len, i;
5888
5889 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5890 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5891 settings->n_ciphers_pairwise = len / sizeof(u32);
5892
5893 if (len % sizeof(u32))
5894 return -EINVAL;
5895
Johannes Berg3dc27d22009-07-02 21:36:37 +02005896 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005897 return -EINVAL;
5898
5899 memcpy(settings->ciphers_pairwise, data, len);
5900
5901 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005902 if (!cfg80211_supported_cipher_suite(
5903 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005904 settings->ciphers_pairwise[i]))
5905 return -EINVAL;
5906 }
5907
5908 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5909 settings->cipher_group =
5910 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005911 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5912 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005913 return -EINVAL;
5914 }
5915
5916 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5917 settings->wpa_versions =
5918 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5919 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5920 return -EINVAL;
5921 }
5922
5923 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5924 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005925 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005926
5927 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5928 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5929 settings->n_akm_suites = len / sizeof(u32);
5930
5931 if (len % sizeof(u32))
5932 return -EINVAL;
5933
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005934 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5935 return -EINVAL;
5936
Samuel Ortizb23aa672009-07-01 21:26:54 +02005937 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005938 }
5939
5940 return 0;
5941}
5942
Jouni Malinen636a5d32009-03-19 13:39:22 +02005943static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5944{
Johannes Berg4c476992010-10-04 21:36:35 +02005945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5946 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005947 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02005948 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02005949 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005950 int err, ssid_len, ie_len = 0;
5951 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08005952 u32 flags = 0;
5953 struct ieee80211_ht_cap *ht_capa = NULL;
5954 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005955
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005956 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5957 return -EINVAL;
5958
5959 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005960 !info->attrs[NL80211_ATTR_SSID] ||
5961 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005962 return -EINVAL;
5963
Johannes Berg4c476992010-10-04 21:36:35 +02005964 if (!rdev->ops->assoc)
5965 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005966
Johannes Berg074ac8d2010-09-16 14:58:22 +02005967 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005968 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5969 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005970
Johannes Berg19957bb2009-07-02 17:20:43 +02005971 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005972
Johannes Berg19957bb2009-07-02 17:20:43 +02005973 chan = ieee80211_get_channel(&rdev->wiphy,
5974 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005975 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5976 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005977
Johannes Berg19957bb2009-07-02 17:20:43 +02005978 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5979 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005980
5981 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005982 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5983 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005984 }
5985
Jouni Malinendc6382c2009-05-06 22:09:37 +03005986 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005987 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03005988 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005989 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02005990 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02005991 else if (mfp != NL80211_MFP_NO)
5992 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03005993 }
5994
Johannes Berg3e5d7642009-07-07 14:37:26 +02005995 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5996 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5997
Ben Greear7e7c8922011-11-18 11:31:59 -08005998 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5999 flags |= ASSOC_REQ_DISABLE_HT;
6000
6001 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6002 ht_capa_mask =
6003 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
6004
6005 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6006 if (!ht_capa_mask)
6007 return -EINVAL;
6008 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6009 }
6010
Johannes Bergc0692b82010-08-27 14:26:53 +03006011 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006012 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02006013 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
6014 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08006015 &crypto, flags, ht_capa,
6016 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006017
Jouni Malinen636a5d32009-03-19 13:39:22 +02006018 return err;
6019}
6020
6021static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6022{
Johannes Berg4c476992010-10-04 21:36:35 +02006023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6024 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006025 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006026 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006027 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006028 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006029
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006030 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6031 return -EINVAL;
6032
6033 if (!info->attrs[NL80211_ATTR_MAC])
6034 return -EINVAL;
6035
6036 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6037 return -EINVAL;
6038
Johannes Berg4c476992010-10-04 21:36:35 +02006039 if (!rdev->ops->deauth)
6040 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006041
Johannes Berg074ac8d2010-09-16 14:58:22 +02006042 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006043 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6044 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006045
Johannes Berg19957bb2009-07-02 17:20:43 +02006046 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006047
Johannes Berg19957bb2009-07-02 17:20:43 +02006048 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6049 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006050 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006051 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006052 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006053
6054 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006055 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6056 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006057 }
6058
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006059 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6060
Johannes Berg4c476992010-10-04 21:36:35 +02006061 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6062 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006063}
6064
6065static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6066{
Johannes Berg4c476992010-10-04 21:36:35 +02006067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6068 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006069 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006070 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006071 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006072 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006073
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006074 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6075 return -EINVAL;
6076
6077 if (!info->attrs[NL80211_ATTR_MAC])
6078 return -EINVAL;
6079
6080 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6081 return -EINVAL;
6082
Johannes Berg4c476992010-10-04 21:36:35 +02006083 if (!rdev->ops->disassoc)
6084 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006085
Johannes Berg074ac8d2010-09-16 14:58:22 +02006086 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006087 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6088 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006089
Johannes Berg19957bb2009-07-02 17:20:43 +02006090 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006091
Johannes Berg19957bb2009-07-02 17:20:43 +02006092 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6093 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006094 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006095 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006096 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006097
6098 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006099 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6100 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006101 }
6102
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006103 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6104
Johannes Berg4c476992010-10-04 21:36:35 +02006105 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6106 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006107}
6108
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006109static bool
6110nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6111 int mcast_rate[IEEE80211_NUM_BANDS],
6112 int rateval)
6113{
6114 struct wiphy *wiphy = &rdev->wiphy;
6115 bool found = false;
6116 int band, i;
6117
6118 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6119 struct ieee80211_supported_band *sband;
6120
6121 sband = wiphy->bands[band];
6122 if (!sband)
6123 continue;
6124
6125 for (i = 0; i < sband->n_bitrates; i++) {
6126 if (sband->bitrates[i].bitrate == rateval) {
6127 mcast_rate[band] = i + 1;
6128 found = true;
6129 break;
6130 }
6131 }
6132 }
6133
6134 return found;
6135}
6136
Johannes Berg04a773a2009-04-19 21:24:32 +02006137static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6138{
Johannes Berg4c476992010-10-04 21:36:35 +02006139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6140 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006141 struct cfg80211_ibss_params ibss;
6142 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006143 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006144 int err;
6145
Johannes Berg8e30bc52009-04-22 17:45:38 +02006146 memset(&ibss, 0, sizeof(ibss));
6147
Johannes Berg04a773a2009-04-19 21:24:32 +02006148 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6149 return -EINVAL;
6150
Johannes Berg683b6d32012-11-08 21:25:48 +01006151 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006152 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6153 return -EINVAL;
6154
Johannes Berg8e30bc52009-04-22 17:45:38 +02006155 ibss.beacon_interval = 100;
6156
6157 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6158 ibss.beacon_interval =
6159 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6160 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6161 return -EINVAL;
6162 }
6163
Johannes Berg4c476992010-10-04 21:36:35 +02006164 if (!rdev->ops->join_ibss)
6165 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006166
Johannes Berg4c476992010-10-04 21:36:35 +02006167 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6168 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006169
Johannes Berg79c97e92009-07-07 03:56:12 +02006170 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006171
Johannes Berg39193492011-09-16 13:45:25 +02006172 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006173 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006174
6175 if (!is_valid_ether_addr(ibss.bssid))
6176 return -EINVAL;
6177 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006178 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6179 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6180
6181 if (info->attrs[NL80211_ATTR_IE]) {
6182 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6183 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6184 }
6185
Johannes Berg683b6d32012-11-08 21:25:48 +01006186 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6187 if (err)
6188 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006189
Johannes Berg683b6d32012-11-08 21:25:48 +01006190 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006191 return -EINVAL;
6192
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006193 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6194 return -EINVAL;
6195 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6196 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006197 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006198
Johannes Berg04a773a2009-04-19 21:24:32 +02006199 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006200 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006201
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006202 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6203 u8 *rates =
6204 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6205 int n_rates =
6206 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6207 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006208 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006209
Johannes Berg34850ab2011-07-18 18:08:35 +02006210 err = ieee80211_get_ratemask(sband, rates, n_rates,
6211 &ibss.basic_rates);
6212 if (err)
6213 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006214 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006215
6216 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6217 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6218 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6219 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006220
Johannes Berg4c476992010-10-04 21:36:35 +02006221 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306222 bool no_ht = false;
6223
Johannes Berg4c476992010-10-04 21:36:35 +02006224 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306225 info->attrs[NL80211_ATTR_KEYS],
6226 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006227 if (IS_ERR(connkeys))
6228 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306229
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006230 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6231 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306232 kfree(connkeys);
6233 return -EINVAL;
6234 }
Johannes Berg4c476992010-10-04 21:36:35 +02006235 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006236
Antonio Quartulli267335d2012-01-31 20:25:47 +01006237 ibss.control_port =
6238 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6239
Johannes Berg4c476992010-10-04 21:36:35 +02006240 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006241 if (err)
6242 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006243 return err;
6244}
6245
6246static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6247{
Johannes Berg4c476992010-10-04 21:36:35 +02006248 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6249 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006250
Johannes Berg4c476992010-10-04 21:36:35 +02006251 if (!rdev->ops->leave_ibss)
6252 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006253
Johannes Berg4c476992010-10-04 21:36:35 +02006254 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6255 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006256
Johannes Berg4c476992010-10-04 21:36:35 +02006257 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006258}
6259
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006260static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6261{
6262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6263 struct net_device *dev = info->user_ptr[1];
6264 int mcast_rate[IEEE80211_NUM_BANDS];
6265 u32 nla_rate;
6266 int err;
6267
6268 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6269 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6270 return -EOPNOTSUPP;
6271
6272 if (!rdev->ops->set_mcast_rate)
6273 return -EOPNOTSUPP;
6274
6275 memset(mcast_rate, 0, sizeof(mcast_rate));
6276
6277 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6278 return -EINVAL;
6279
6280 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6281 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6282 return -EINVAL;
6283
6284 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6285
6286 return err;
6287}
6288
6289
Johannes Bergaff89a92009-07-01 21:26:51 +02006290#ifdef CONFIG_NL80211_TESTMODE
6291static struct genl_multicast_group nl80211_testmode_mcgrp = {
6292 .name = "testmode",
6293};
6294
6295static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6296{
Johannes Berg4c476992010-10-04 21:36:35 +02006297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006298 int err;
6299
6300 if (!info->attrs[NL80211_ATTR_TESTDATA])
6301 return -EINVAL;
6302
Johannes Bergaff89a92009-07-01 21:26:51 +02006303 err = -EOPNOTSUPP;
6304 if (rdev->ops->testmode_cmd) {
6305 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006306 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006307 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6308 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6309 rdev->testmode_info = NULL;
6310 }
6311
Johannes Bergaff89a92009-07-01 21:26:51 +02006312 return err;
6313}
6314
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006315static int nl80211_testmode_dump(struct sk_buff *skb,
6316 struct netlink_callback *cb)
6317{
Johannes Berg00918d32011-12-13 17:22:05 +01006318 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006319 int err;
6320 long phy_idx;
6321 void *data = NULL;
6322 int data_len = 0;
6323
6324 if (cb->args[0]) {
6325 /*
6326 * 0 is a valid index, but not valid for args[0],
6327 * so we need to offset by 1.
6328 */
6329 phy_idx = cb->args[0] - 1;
6330 } else {
6331 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6332 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6333 nl80211_policy);
6334 if (err)
6335 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01006336
Johannes Berg2bd7e352012-06-15 14:23:16 +02006337 mutex_lock(&cfg80211_mutex);
6338 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6339 nl80211_fam.attrbuf);
6340 if (IS_ERR(rdev)) {
6341 mutex_unlock(&cfg80211_mutex);
6342 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01006343 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006344 phy_idx = rdev->wiphy_idx;
6345 rdev = NULL;
6346 mutex_unlock(&cfg80211_mutex);
6347
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006348 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6349 cb->args[1] =
6350 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6351 }
6352
6353 if (cb->args[1]) {
6354 data = nla_data((void *)cb->args[1]);
6355 data_len = nla_len((void *)cb->args[1]);
6356 }
6357
6358 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01006359 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6360 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006361 mutex_unlock(&cfg80211_mutex);
6362 return -ENOENT;
6363 }
Johannes Berg00918d32011-12-13 17:22:05 +01006364 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006365 mutex_unlock(&cfg80211_mutex);
6366
Johannes Berg00918d32011-12-13 17:22:05 +01006367 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006368 err = -EOPNOTSUPP;
6369 goto out_err;
6370 }
6371
6372 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006373 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006374 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6375 NL80211_CMD_TESTMODE);
6376 struct nlattr *tmdata;
6377
David S. Miller9360ffd2012-03-29 04:41:26 -04006378 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006379 genlmsg_cancel(skb, hdr);
6380 break;
6381 }
6382
6383 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6384 if (!tmdata) {
6385 genlmsg_cancel(skb, hdr);
6386 break;
6387 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006388 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006389 nla_nest_end(skb, tmdata);
6390
6391 if (err == -ENOBUFS || err == -ENOENT) {
6392 genlmsg_cancel(skb, hdr);
6393 break;
6394 } else if (err) {
6395 genlmsg_cancel(skb, hdr);
6396 goto out_err;
6397 }
6398
6399 genlmsg_end(skb, hdr);
6400 }
6401
6402 err = skb->len;
6403 /* see above */
6404 cb->args[0] = phy_idx + 1;
6405 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01006406 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006407 return err;
6408}
6409
Johannes Bergaff89a92009-07-01 21:26:51 +02006410static struct sk_buff *
6411__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006412 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006413{
6414 struct sk_buff *skb;
6415 void *hdr;
6416 struct nlattr *data;
6417
6418 skb = nlmsg_new(approxlen + 100, gfp);
6419 if (!skb)
6420 return NULL;
6421
Eric W. Biederman15e47302012-09-07 20:12:54 +00006422 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006423 if (!hdr) {
6424 kfree_skb(skb);
6425 return NULL;
6426 }
6427
David S. Miller9360ffd2012-03-29 04:41:26 -04006428 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6429 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006430 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6431
6432 ((void **)skb->cb)[0] = rdev;
6433 ((void **)skb->cb)[1] = hdr;
6434 ((void **)skb->cb)[2] = data;
6435
6436 return skb;
6437
6438 nla_put_failure:
6439 kfree_skb(skb);
6440 return NULL;
6441}
6442
6443struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6444 int approxlen)
6445{
6446 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6447
6448 if (WARN_ON(!rdev->testmode_info))
6449 return NULL;
6450
6451 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006452 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006453 rdev->testmode_info->snd_seq,
6454 GFP_KERNEL);
6455}
6456EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6457
6458int cfg80211_testmode_reply(struct sk_buff *skb)
6459{
6460 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6461 void *hdr = ((void **)skb->cb)[1];
6462 struct nlattr *data = ((void **)skb->cb)[2];
6463
6464 if (WARN_ON(!rdev->testmode_info)) {
6465 kfree_skb(skb);
6466 return -EINVAL;
6467 }
6468
6469 nla_nest_end(skb, data);
6470 genlmsg_end(skb, hdr);
6471 return genlmsg_reply(skb, rdev->testmode_info);
6472}
6473EXPORT_SYMBOL(cfg80211_testmode_reply);
6474
6475struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6476 int approxlen, gfp_t gfp)
6477{
6478 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6479
6480 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6481}
6482EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6483
6484void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6485{
6486 void *hdr = ((void **)skb->cb)[1];
6487 struct nlattr *data = ((void **)skb->cb)[2];
6488
6489 nla_nest_end(skb, data);
6490 genlmsg_end(skb, hdr);
6491 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6492}
6493EXPORT_SYMBOL(cfg80211_testmode_event);
6494#endif
6495
Samuel Ortizb23aa672009-07-01 21:26:54 +02006496static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6497{
Johannes Berg4c476992010-10-04 21:36:35 +02006498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6499 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006500 struct cfg80211_connect_params connect;
6501 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006502 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006503 int err;
6504
6505 memset(&connect, 0, sizeof(connect));
6506
6507 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6508 return -EINVAL;
6509
6510 if (!info->attrs[NL80211_ATTR_SSID] ||
6511 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6512 return -EINVAL;
6513
6514 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6515 connect.auth_type =
6516 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006517 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6518 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006519 return -EINVAL;
6520 } else
6521 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6522
6523 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6524
Johannes Bergc0692b82010-08-27 14:26:53 +03006525 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006526 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006527 if (err)
6528 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006529
Johannes Berg074ac8d2010-09-16 14:58:22 +02006530 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006531 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6532 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006533
Johannes Berg79c97e92009-07-07 03:56:12 +02006534 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006535
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306536 connect.bg_scan_period = -1;
6537 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6538 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6539 connect.bg_scan_period =
6540 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6541 }
6542
Samuel Ortizb23aa672009-07-01 21:26:54 +02006543 if (info->attrs[NL80211_ATTR_MAC])
6544 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6545 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6546 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6547
6548 if (info->attrs[NL80211_ATTR_IE]) {
6549 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6550 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6551 }
6552
Jouni Malinencee00a92013-01-15 17:15:57 +02006553 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6554 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6555 if (connect.mfp != NL80211_MFP_REQUIRED &&
6556 connect.mfp != NL80211_MFP_NO)
6557 return -EINVAL;
6558 } else {
6559 connect.mfp = NL80211_MFP_NO;
6560 }
6561
Samuel Ortizb23aa672009-07-01 21:26:54 +02006562 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6563 connect.channel =
6564 ieee80211_get_channel(wiphy,
6565 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6566 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006567 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6568 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006569 }
6570
Johannes Bergfffd0932009-07-08 14:22:54 +02006571 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6572 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306573 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006574 if (IS_ERR(connkeys))
6575 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006576 }
6577
Ben Greear7e7c8922011-11-18 11:31:59 -08006578 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6579 connect.flags |= ASSOC_REQ_DISABLE_HT;
6580
6581 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6582 memcpy(&connect.ht_capa_mask,
6583 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6584 sizeof(connect.ht_capa_mask));
6585
6586 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006587 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6588 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006589 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006590 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006591 memcpy(&connect.ht_capa,
6592 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6593 sizeof(connect.ht_capa));
6594 }
6595
Johannes Bergfffd0932009-07-08 14:22:54 +02006596 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006597 if (err)
6598 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006599 return err;
6600}
6601
6602static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6603{
Johannes Berg4c476992010-10-04 21:36:35 +02006604 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6605 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006606 u16 reason;
6607
6608 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6609 reason = WLAN_REASON_DEAUTH_LEAVING;
6610 else
6611 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6612
6613 if (reason == 0)
6614 return -EINVAL;
6615
Johannes Berg074ac8d2010-09-16 14:58:22 +02006616 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006617 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6618 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006619
Johannes Berg4c476992010-10-04 21:36:35 +02006620 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006621}
6622
Johannes Berg463d0182009-07-14 00:33:35 +02006623static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6624{
Johannes Berg4c476992010-10-04 21:36:35 +02006625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006626 struct net *net;
6627 int err;
6628 u32 pid;
6629
6630 if (!info->attrs[NL80211_ATTR_PID])
6631 return -EINVAL;
6632
6633 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6634
Johannes Berg463d0182009-07-14 00:33:35 +02006635 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006636 if (IS_ERR(net))
6637 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006638
6639 err = 0;
6640
6641 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006642 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6643 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006644
Johannes Berg463d0182009-07-14 00:33:35 +02006645 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006646 return err;
6647}
6648
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006649static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6650{
Johannes Berg4c476992010-10-04 21:36:35 +02006651 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006652 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6653 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006654 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006655 struct cfg80211_pmksa pmksa;
6656
6657 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6658
6659 if (!info->attrs[NL80211_ATTR_MAC])
6660 return -EINVAL;
6661
6662 if (!info->attrs[NL80211_ATTR_PMKID])
6663 return -EINVAL;
6664
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006665 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6666 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6667
Johannes Berg074ac8d2010-09-16 14:58:22 +02006668 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006669 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6670 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006671
6672 switch (info->genlhdr->cmd) {
6673 case NL80211_CMD_SET_PMKSA:
6674 rdev_ops = rdev->ops->set_pmksa;
6675 break;
6676 case NL80211_CMD_DEL_PMKSA:
6677 rdev_ops = rdev->ops->del_pmksa;
6678 break;
6679 default:
6680 WARN_ON(1);
6681 break;
6682 }
6683
Johannes Berg4c476992010-10-04 21:36:35 +02006684 if (!rdev_ops)
6685 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006686
Johannes Berg4c476992010-10-04 21:36:35 +02006687 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006688}
6689
6690static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6691{
Johannes Berg4c476992010-10-04 21:36:35 +02006692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6693 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006694
Johannes Berg074ac8d2010-09-16 14:58:22 +02006695 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006696 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6697 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006698
Johannes Berg4c476992010-10-04 21:36:35 +02006699 if (!rdev->ops->flush_pmksa)
6700 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006701
Hila Gonene35e4d22012-06-27 17:19:42 +03006702 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006703}
6704
Arik Nemtsov109086c2011-09-28 14:12:50 +03006705static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6706{
6707 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6708 struct net_device *dev = info->user_ptr[1];
6709 u8 action_code, dialog_token;
6710 u16 status_code;
6711 u8 *peer;
6712
6713 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6714 !rdev->ops->tdls_mgmt)
6715 return -EOPNOTSUPP;
6716
6717 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6718 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6719 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6720 !info->attrs[NL80211_ATTR_IE] ||
6721 !info->attrs[NL80211_ATTR_MAC])
6722 return -EINVAL;
6723
6724 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6725 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6726 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6727 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6728
Hila Gonene35e4d22012-06-27 17:19:42 +03006729 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6730 dialog_token, status_code,
6731 nla_data(info->attrs[NL80211_ATTR_IE]),
6732 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006733}
6734
6735static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6736{
6737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6738 struct net_device *dev = info->user_ptr[1];
6739 enum nl80211_tdls_operation operation;
6740 u8 *peer;
6741
6742 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6743 !rdev->ops->tdls_oper)
6744 return -EOPNOTSUPP;
6745
6746 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6747 !info->attrs[NL80211_ATTR_MAC])
6748 return -EINVAL;
6749
6750 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6751 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6752
Hila Gonene35e4d22012-06-27 17:19:42 +03006753 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006754}
6755
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006756static int nl80211_remain_on_channel(struct sk_buff *skb,
6757 struct genl_info *info)
6758{
Johannes Berg4c476992010-10-04 21:36:35 +02006759 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006760 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006761 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006762 struct sk_buff *msg;
6763 void *hdr;
6764 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006765 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006766 int err;
6767
6768 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6769 !info->attrs[NL80211_ATTR_DURATION])
6770 return -EINVAL;
6771
6772 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6773
Johannes Berg7c4ef712011-11-18 15:33:48 +01006774 if (!rdev->ops->remain_on_channel ||
6775 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006776 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006777
Johannes Bergebf348f2012-06-01 12:50:54 +02006778 /*
6779 * We should be on that channel for at least a minimum amount of
6780 * time (10ms) but no longer than the driver supports.
6781 */
6782 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6783 duration > rdev->wiphy.max_remain_on_channel_duration)
6784 return -EINVAL;
6785
Johannes Berg683b6d32012-11-08 21:25:48 +01006786 err = nl80211_parse_chandef(rdev, info, &chandef);
6787 if (err)
6788 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006789
6790 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006791 if (!msg)
6792 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006793
Eric W. Biederman15e47302012-09-07 20:12:54 +00006794 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006795 NL80211_CMD_REMAIN_ON_CHANNEL);
6796
6797 if (IS_ERR(hdr)) {
6798 err = PTR_ERR(hdr);
6799 goto free_msg;
6800 }
6801
Johannes Berg683b6d32012-11-08 21:25:48 +01006802 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6803 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006804
6805 if (err)
6806 goto free_msg;
6807
David S. Miller9360ffd2012-03-29 04:41:26 -04006808 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6809 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006810
6811 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006812
6813 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006814
6815 nla_put_failure:
6816 err = -ENOBUFS;
6817 free_msg:
6818 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006819 return err;
6820}
6821
6822static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6823 struct genl_info *info)
6824{
Johannes Berg4c476992010-10-04 21:36:35 +02006825 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006826 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006827 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006828
6829 if (!info->attrs[NL80211_ATTR_COOKIE])
6830 return -EINVAL;
6831
Johannes Berg4c476992010-10-04 21:36:35 +02006832 if (!rdev->ops->cancel_remain_on_channel)
6833 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006834
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006835 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6836
Hila Gonene35e4d22012-06-27 17:19:42 +03006837 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006838}
6839
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006840static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6841 u8 *rates, u8 rates_len)
6842{
6843 u8 i;
6844 u32 mask = 0;
6845
6846 for (i = 0; i < rates_len; i++) {
6847 int rate = (rates[i] & 0x7f) * 5;
6848 int ridx;
6849 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6850 struct ieee80211_rate *srate =
6851 &sband->bitrates[ridx];
6852 if (rate == srate->bitrate) {
6853 mask |= 1 << ridx;
6854 break;
6855 }
6856 }
6857 if (ridx == sband->n_bitrates)
6858 return 0; /* rate not found */
6859 }
6860
6861 return mask;
6862}
6863
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006864static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6865 u8 *rates, u8 rates_len,
6866 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6867{
6868 u8 i;
6869
6870 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6871
6872 for (i = 0; i < rates_len; i++) {
6873 int ridx, rbit;
6874
6875 ridx = rates[i] / 8;
6876 rbit = BIT(rates[i] % 8);
6877
6878 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006879 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006880 return false;
6881
6882 /* check availability */
6883 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6884 mcs[ridx] |= rbit;
6885 else
6886 return false;
6887 }
6888
6889 return true;
6890}
6891
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006892static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006893 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6894 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006895 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6896 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006897};
6898
6899static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6900 struct genl_info *info)
6901{
6902 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006904 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006905 int rem, i;
6906 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006907 struct nlattr *tx_rates;
6908 struct ieee80211_supported_band *sband;
6909
6910 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6911 return -EINVAL;
6912
Johannes Berg4c476992010-10-04 21:36:35 +02006913 if (!rdev->ops->set_bitrate_mask)
6914 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006915
6916 memset(&mask, 0, sizeof(mask));
6917 /* Default to all rates enabled */
6918 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6919 sband = rdev->wiphy.bands[i];
6920 mask.control[i].legacy =
6921 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006922 if (sband)
6923 memcpy(mask.control[i].mcs,
6924 sband->ht_cap.mcs.rx_mask,
6925 sizeof(mask.control[i].mcs));
6926 else
6927 memset(mask.control[i].mcs, 0,
6928 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006929 }
6930
6931 /*
6932 * The nested attribute uses enum nl80211_band as the index. This maps
6933 * directly to the enum ieee80211_band values used in cfg80211.
6934 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006935 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006936 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6937 {
6938 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02006939 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6940 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006941 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02006942 if (sband == NULL)
6943 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006944 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6945 nla_len(tx_rates), nl80211_txattr_policy);
6946 if (tb[NL80211_TXRATE_LEGACY]) {
6947 mask.control[band].legacy = rateset_to_mask(
6948 sband,
6949 nla_data(tb[NL80211_TXRATE_LEGACY]),
6950 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05306951 if ((mask.control[band].legacy == 0) &&
6952 nla_len(tb[NL80211_TXRATE_LEGACY]))
6953 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006954 }
6955 if (tb[NL80211_TXRATE_MCS]) {
6956 if (!ht_rateset_to_mask(
6957 sband,
6958 nla_data(tb[NL80211_TXRATE_MCS]),
6959 nla_len(tb[NL80211_TXRATE_MCS]),
6960 mask.control[band].mcs))
6961 return -EINVAL;
6962 }
6963
6964 if (mask.control[band].legacy == 0) {
6965 /* don't allow empty legacy rates if HT
6966 * is not even supported. */
6967 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6968 return -EINVAL;
6969
6970 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6971 if (mask.control[band].mcs[i])
6972 break;
6973
6974 /* legacy and mcs rates may not be both empty */
6975 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02006976 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006977 }
6978 }
6979
Hila Gonene35e4d22012-06-27 17:19:42 +03006980 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006981}
6982
Johannes Berg2e161f72010-08-12 15:38:38 +02006983static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006984{
Johannes Berg4c476992010-10-04 21:36:35 +02006985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006986 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02006987 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02006988
6989 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6990 return -EINVAL;
6991
Johannes Berg2e161f72010-08-12 15:38:38 +02006992 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6993 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02006994
Johannes Berg71bbc992012-06-15 15:30:18 +02006995 switch (wdev->iftype) {
6996 case NL80211_IFTYPE_STATION:
6997 case NL80211_IFTYPE_ADHOC:
6998 case NL80211_IFTYPE_P2P_CLIENT:
6999 case NL80211_IFTYPE_AP:
7000 case NL80211_IFTYPE_AP_VLAN:
7001 case NL80211_IFTYPE_MESH_POINT:
7002 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007003 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007004 break;
7005 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007006 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007007 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007008
7009 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007010 if (!rdev->ops->mgmt_tx)
7011 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007012
Eric W. Biederman15e47302012-09-07 20:12:54 +00007013 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007014 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7015 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007016}
7017
Johannes Berg2e161f72010-08-12 15:38:38 +02007018static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007019{
Johannes Berg4c476992010-10-04 21:36:35 +02007020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007021 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007022 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007023 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007024 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007025 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007026 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007027 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007028 bool offchan, no_cck, dont_wait_for_ack;
7029
7030 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007031
Johannes Berg683b6d32012-11-08 21:25:48 +01007032 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007033 return -EINVAL;
7034
Johannes Berg4c476992010-10-04 21:36:35 +02007035 if (!rdev->ops->mgmt_tx)
7036 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007037
Johannes Berg71bbc992012-06-15 15:30:18 +02007038 switch (wdev->iftype) {
7039 case NL80211_IFTYPE_STATION:
7040 case NL80211_IFTYPE_ADHOC:
7041 case NL80211_IFTYPE_P2P_CLIENT:
7042 case NL80211_IFTYPE_AP:
7043 case NL80211_IFTYPE_AP_VLAN:
7044 case NL80211_IFTYPE_MESH_POINT:
7045 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007046 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007047 break;
7048 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007049 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007050 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007051
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007052 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007053 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007054 return -EINVAL;
7055 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007056
7057 /*
7058 * We should wait on the channel for at least a minimum amount
7059 * of time (10ms) but no longer than the driver supports.
7060 */
7061 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7062 wait > rdev->wiphy.max_remain_on_channel_duration)
7063 return -EINVAL;
7064
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007065 }
7066
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007067 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7068
Johannes Berg7c4ef712011-11-18 15:33:48 +01007069 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7070 return -EINVAL;
7071
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307072 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7073
Johannes Berg683b6d32012-11-08 21:25:48 +01007074 err = nl80211_parse_chandef(rdev, info, &chandef);
7075 if (err)
7076 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007077
Johannes Berge247bd902011-11-04 11:18:21 +01007078 if (!dont_wait_for_ack) {
7079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7080 if (!msg)
7081 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007082
Eric W. Biederman15e47302012-09-07 20:12:54 +00007083 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007084 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007085
Johannes Berge247bd902011-11-04 11:18:21 +01007086 if (IS_ERR(hdr)) {
7087 err = PTR_ERR(hdr);
7088 goto free_msg;
7089 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007090 }
Johannes Berge247bd902011-11-04 11:18:21 +01007091
Johannes Berg683b6d32012-11-08 21:25:48 +01007092 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007093 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7094 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007095 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007096 if (err)
7097 goto free_msg;
7098
Johannes Berge247bd902011-11-04 11:18:21 +01007099 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007100 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7101 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007102
Johannes Berge247bd902011-11-04 11:18:21 +01007103 genlmsg_end(msg, hdr);
7104 return genlmsg_reply(msg, info);
7105 }
7106
7107 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007108
7109 nla_put_failure:
7110 err = -ENOBUFS;
7111 free_msg:
7112 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007113 return err;
7114}
7115
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007116static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7117{
7118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007119 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007120 u64 cookie;
7121
7122 if (!info->attrs[NL80211_ATTR_COOKIE])
7123 return -EINVAL;
7124
7125 if (!rdev->ops->mgmt_tx_cancel_wait)
7126 return -EOPNOTSUPP;
7127
Johannes Berg71bbc992012-06-15 15:30:18 +02007128 switch (wdev->iftype) {
7129 case NL80211_IFTYPE_STATION:
7130 case NL80211_IFTYPE_ADHOC:
7131 case NL80211_IFTYPE_P2P_CLIENT:
7132 case NL80211_IFTYPE_AP:
7133 case NL80211_IFTYPE_AP_VLAN:
7134 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007135 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007136 break;
7137 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007138 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007139 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007140
7141 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7142
Hila Gonene35e4d22012-06-27 17:19:42 +03007143 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007144}
7145
Kalle Valoffb9eb32010-02-17 17:58:10 +02007146static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7147{
Johannes Berg4c476992010-10-04 21:36:35 +02007148 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007149 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007150 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007151 u8 ps_state;
7152 bool state;
7153 int err;
7154
Johannes Berg4c476992010-10-04 21:36:35 +02007155 if (!info->attrs[NL80211_ATTR_PS_STATE])
7156 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007157
7158 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7159
Johannes Berg4c476992010-10-04 21:36:35 +02007160 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7161 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007162
7163 wdev = dev->ieee80211_ptr;
7164
Johannes Berg4c476992010-10-04 21:36:35 +02007165 if (!rdev->ops->set_power_mgmt)
7166 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007167
7168 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7169
7170 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007171 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007172
Hila Gonene35e4d22012-06-27 17:19:42 +03007173 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007174 if (!err)
7175 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007176 return err;
7177}
7178
7179static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7180{
Johannes Berg4c476992010-10-04 21:36:35 +02007181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007182 enum nl80211_ps_state ps_state;
7183 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007184 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007185 struct sk_buff *msg;
7186 void *hdr;
7187 int err;
7188
Kalle Valoffb9eb32010-02-17 17:58:10 +02007189 wdev = dev->ieee80211_ptr;
7190
Johannes Berg4c476992010-10-04 21:36:35 +02007191 if (!rdev->ops->set_power_mgmt)
7192 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007193
7194 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007195 if (!msg)
7196 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007197
Eric W. Biederman15e47302012-09-07 20:12:54 +00007198 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007199 NL80211_CMD_GET_POWER_SAVE);
7200 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007201 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007202 goto free_msg;
7203 }
7204
7205 if (wdev->ps)
7206 ps_state = NL80211_PS_ENABLED;
7207 else
7208 ps_state = NL80211_PS_DISABLED;
7209
David S. Miller9360ffd2012-03-29 04:41:26 -04007210 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7211 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007212
7213 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007214 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007215
Johannes Berg4c476992010-10-04 21:36:35 +02007216 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007217 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007218 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007219 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007220 return err;
7221}
7222
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007223static struct nla_policy
7224nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7225 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7226 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7227 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007228 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7229 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7230 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007231};
7232
Thomas Pedersen84f10702012-07-12 16:17:33 -07007233static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007234 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007235{
7236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7237 struct wireless_dev *wdev;
7238 struct net_device *dev = info->user_ptr[1];
7239
Johannes Bergd9d8b012012-11-26 12:51:52 +01007240 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007241 return -EINVAL;
7242
7243 wdev = dev->ieee80211_ptr;
7244
7245 if (!rdev->ops->set_cqm_txe_config)
7246 return -EOPNOTSUPP;
7247
7248 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7249 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7250 return -EOPNOTSUPP;
7251
Hila Gonene35e4d22012-06-27 17:19:42 +03007252 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007253}
7254
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007255static int nl80211_set_cqm_rssi(struct genl_info *info,
7256 s32 threshold, u32 hysteresis)
7257{
Johannes Berg4c476992010-10-04 21:36:35 +02007258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007259 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007260 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007261
7262 if (threshold > 0)
7263 return -EINVAL;
7264
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007265 wdev = dev->ieee80211_ptr;
7266
Johannes Berg4c476992010-10-04 21:36:35 +02007267 if (!rdev->ops->set_cqm_rssi_config)
7268 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007269
Johannes Berg074ac8d2010-09-16 14:58:22 +02007270 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007271 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7272 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007273
Hila Gonene35e4d22012-06-27 17:19:42 +03007274 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007275}
7276
7277static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7278{
7279 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7280 struct nlattr *cqm;
7281 int err;
7282
7283 cqm = info->attrs[NL80211_ATTR_CQM];
7284 if (!cqm) {
7285 err = -EINVAL;
7286 goto out;
7287 }
7288
7289 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7290 nl80211_attr_cqm_policy);
7291 if (err)
7292 goto out;
7293
7294 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7295 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7296 s32 threshold;
7297 u32 hysteresis;
7298 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7299 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7300 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007301 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7302 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7303 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7304 u32 rate, pkts, intvl;
7305 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7306 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7307 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7308 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007309 } else
7310 err = -EINVAL;
7311
7312out:
7313 return err;
7314}
7315
Johannes Berg29cbe682010-12-03 09:20:44 +01007316static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7317{
7318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7319 struct net_device *dev = info->user_ptr[1];
7320 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007321 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007322 int err;
7323
7324 /* start with default */
7325 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007326 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007327
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007328 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007329 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007330 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007331 if (err)
7332 return err;
7333 }
7334
7335 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7336 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7337 return -EINVAL;
7338
Javier Cardonac80d5452010-12-16 17:37:49 -08007339 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7340 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7341
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007342 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7343 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7344 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7345 return -EINVAL;
7346
Marco Porsch9bdbf042013-01-07 16:04:51 +01007347 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7348 setup.beacon_interval =
7349 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7350 if (setup.beacon_interval < 10 ||
7351 setup.beacon_interval > 10000)
7352 return -EINVAL;
7353 }
7354
7355 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7356 setup.dtim_period =
7357 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7358 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7359 return -EINVAL;
7360 }
7361
Javier Cardonac80d5452010-12-16 17:37:49 -08007362 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7363 /* parse additional setup parameters if given */
7364 err = nl80211_parse_mesh_setup(info, &setup);
7365 if (err)
7366 return err;
7367 }
7368
Johannes Bergcc1d2802012-05-16 23:50:20 +02007369 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007370 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7371 if (err)
7372 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007373 } else {
7374 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007375 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007376 }
7377
Javier Cardonac80d5452010-12-16 17:37:49 -08007378 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007379}
7380
7381static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7382{
7383 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7384 struct net_device *dev = info->user_ptr[1];
7385
7386 return cfg80211_leave_mesh(rdev, dev);
7387}
7388
Johannes Bergdfb89c52012-06-27 09:23:48 +02007389#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007390static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7391 struct cfg80211_registered_device *rdev)
7392{
7393 struct nlattr *nl_pats, *nl_pat;
7394 int i, pat_len;
7395
7396 if (!rdev->wowlan->n_patterns)
7397 return 0;
7398
7399 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7400 if (!nl_pats)
7401 return -ENOBUFS;
7402
7403 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7404 nl_pat = nla_nest_start(msg, i + 1);
7405 if (!nl_pat)
7406 return -ENOBUFS;
7407 pat_len = rdev->wowlan->patterns[i].pattern_len;
7408 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7409 DIV_ROUND_UP(pat_len, 8),
7410 rdev->wowlan->patterns[i].mask) ||
7411 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7412 pat_len, rdev->wowlan->patterns[i].pattern) ||
7413 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7414 rdev->wowlan->patterns[i].pkt_offset))
7415 return -ENOBUFS;
7416 nla_nest_end(msg, nl_pat);
7417 }
7418 nla_nest_end(msg, nl_pats);
7419
7420 return 0;
7421}
7422
Johannes Berg2a0e0472013-01-23 22:57:40 +01007423static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7424 struct cfg80211_wowlan_tcp *tcp)
7425{
7426 struct nlattr *nl_tcp;
7427
7428 if (!tcp)
7429 return 0;
7430
7431 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7432 if (!nl_tcp)
7433 return -ENOBUFS;
7434
7435 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7436 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7437 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7438 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7439 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7440 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7441 tcp->payload_len, tcp->payload) ||
7442 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7443 tcp->data_interval) ||
7444 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7445 tcp->wake_len, tcp->wake_data) ||
7446 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7447 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7448 return -ENOBUFS;
7449
7450 if (tcp->payload_seq.len &&
7451 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7452 sizeof(tcp->payload_seq), &tcp->payload_seq))
7453 return -ENOBUFS;
7454
7455 if (tcp->payload_tok.len &&
7456 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7457 sizeof(tcp->payload_tok) + tcp->tokens_size,
7458 &tcp->payload_tok))
7459 return -ENOBUFS;
7460
7461 return 0;
7462}
7463
Johannes Bergff1b6e62011-05-04 15:37:28 +02007464static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7465{
7466 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7467 struct sk_buff *msg;
7468 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007469 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007470
Johannes Berg2a0e0472013-01-23 22:57:40 +01007471 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7472 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007473 return -EOPNOTSUPP;
7474
Johannes Berg2a0e0472013-01-23 22:57:40 +01007475 if (rdev->wowlan && rdev->wowlan->tcp) {
7476 /* adjust size to have room for all the data */
7477 size += rdev->wowlan->tcp->tokens_size +
7478 rdev->wowlan->tcp->payload_len +
7479 rdev->wowlan->tcp->wake_len +
7480 rdev->wowlan->tcp->wake_len / 8;
7481 }
7482
7483 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007484 if (!msg)
7485 return -ENOMEM;
7486
Eric W. Biederman15e47302012-09-07 20:12:54 +00007487 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007488 NL80211_CMD_GET_WOWLAN);
7489 if (!hdr)
7490 goto nla_put_failure;
7491
7492 if (rdev->wowlan) {
7493 struct nlattr *nl_wowlan;
7494
7495 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7496 if (!nl_wowlan)
7497 goto nla_put_failure;
7498
David S. Miller9360ffd2012-03-29 04:41:26 -04007499 if ((rdev->wowlan->any &&
7500 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7501 (rdev->wowlan->disconnect &&
7502 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7503 (rdev->wowlan->magic_pkt &&
7504 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7505 (rdev->wowlan->gtk_rekey_failure &&
7506 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7507 (rdev->wowlan->eap_identity_req &&
7508 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7509 (rdev->wowlan->four_way_handshake &&
7510 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7511 (rdev->wowlan->rfkill_release &&
7512 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7513 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007514
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007515 if (nl80211_send_wowlan_patterns(msg, rdev))
7516 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007517
7518 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7519 goto nla_put_failure;
7520
Johannes Bergff1b6e62011-05-04 15:37:28 +02007521 nla_nest_end(msg, nl_wowlan);
7522 }
7523
7524 genlmsg_end(msg, hdr);
7525 return genlmsg_reply(msg, info);
7526
7527nla_put_failure:
7528 nlmsg_free(msg);
7529 return -ENOBUFS;
7530}
7531
Johannes Berg2a0e0472013-01-23 22:57:40 +01007532static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7533 struct nlattr *attr,
7534 struct cfg80211_wowlan *trig)
7535{
7536 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7537 struct cfg80211_wowlan_tcp *cfg;
7538 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7539 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7540 u32 size;
7541 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7542 int err, port;
7543
7544 if (!rdev->wiphy.wowlan.tcp)
7545 return -EINVAL;
7546
7547 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7548 nla_data(attr), nla_len(attr),
7549 nl80211_wowlan_tcp_policy);
7550 if (err)
7551 return err;
7552
7553 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7554 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7555 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7556 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7557 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7558 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7559 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7560 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7561 return -EINVAL;
7562
7563 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7564 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7565 return -EINVAL;
7566
7567 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
7568 rdev->wiphy.wowlan.tcp->data_interval_max)
7569 return -EINVAL;
7570
7571 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7572 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7573 return -EINVAL;
7574
7575 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7576 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7577 return -EINVAL;
7578
7579 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7580 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7581
7582 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7583 tokens_size = tokln - sizeof(*tok);
7584
7585 if (!tok->len || tokens_size % tok->len)
7586 return -EINVAL;
7587 if (!rdev->wiphy.wowlan.tcp->tok)
7588 return -EINVAL;
7589 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7590 return -EINVAL;
7591 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7592 return -EINVAL;
7593 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7594 return -EINVAL;
7595 if (tok->offset + tok->len > data_size)
7596 return -EINVAL;
7597 }
7598
7599 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7600 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7601 if (!rdev->wiphy.wowlan.tcp->seq)
7602 return -EINVAL;
7603 if (seq->len == 0 || seq->len > 4)
7604 return -EINVAL;
7605 if (seq->len + seq->offset > data_size)
7606 return -EINVAL;
7607 }
7608
7609 size = sizeof(*cfg);
7610 size += data_size;
7611 size += wake_size + wake_mask_size;
7612 size += tokens_size;
7613
7614 cfg = kzalloc(size, GFP_KERNEL);
7615 if (!cfg)
7616 return -ENOMEM;
7617 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7618 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7619 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7620 ETH_ALEN);
7621 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7622 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7623 else
7624 port = 0;
7625#ifdef CONFIG_INET
7626 /* allocate a socket and port for it and use it */
7627 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7628 IPPROTO_TCP, &cfg->sock, 1);
7629 if (err) {
7630 kfree(cfg);
7631 return err;
7632 }
7633 if (inet_csk_get_port(cfg->sock->sk, port)) {
7634 sock_release(cfg->sock);
7635 kfree(cfg);
7636 return -EADDRINUSE;
7637 }
7638 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7639#else
7640 if (!port) {
7641 kfree(cfg);
7642 return -EINVAL;
7643 }
7644 cfg->src_port = port;
7645#endif
7646
7647 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7648 cfg->payload_len = data_size;
7649 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7650 memcpy((void *)cfg->payload,
7651 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7652 data_size);
7653 if (seq)
7654 cfg->payload_seq = *seq;
7655 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7656 cfg->wake_len = wake_size;
7657 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7658 memcpy((void *)cfg->wake_data,
7659 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7660 wake_size);
7661 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7662 data_size + wake_size;
7663 memcpy((void *)cfg->wake_mask,
7664 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7665 wake_mask_size);
7666 if (tok) {
7667 cfg->tokens_size = tokens_size;
7668 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7669 }
7670
7671 trig->tcp = cfg;
7672
7673 return 0;
7674}
7675
Johannes Bergff1b6e62011-05-04 15:37:28 +02007676static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7677{
7678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7679 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007680 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007681 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007682 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7683 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007684 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007685
Johannes Berg2a0e0472013-01-23 22:57:40 +01007686 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7687 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007688 return -EOPNOTSUPP;
7689
Johannes Bergae33bd82012-07-12 16:25:02 +02007690 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7691 cfg80211_rdev_free_wowlan(rdev);
7692 rdev->wowlan = NULL;
7693 goto set_wakeup;
7694 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007695
7696 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7697 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7698 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7699 nl80211_wowlan_policy);
7700 if (err)
7701 return err;
7702
7703 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7704 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7705 return -EINVAL;
7706 new_triggers.any = true;
7707 }
7708
7709 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7710 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7711 return -EINVAL;
7712 new_triggers.disconnect = true;
7713 }
7714
7715 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7716 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7717 return -EINVAL;
7718 new_triggers.magic_pkt = true;
7719 }
7720
Johannes Berg77dbbb12011-07-13 10:48:55 +02007721 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7722 return -EINVAL;
7723
7724 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7725 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7726 return -EINVAL;
7727 new_triggers.gtk_rekey_failure = true;
7728 }
7729
7730 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7731 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7732 return -EINVAL;
7733 new_triggers.eap_identity_req = true;
7734 }
7735
7736 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7737 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7738 return -EINVAL;
7739 new_triggers.four_way_handshake = true;
7740 }
7741
7742 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7743 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7744 return -EINVAL;
7745 new_triggers.rfkill_release = true;
7746 }
7747
Johannes Bergff1b6e62011-05-04 15:37:28 +02007748 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7749 struct nlattr *pat;
7750 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007751 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007752 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7753
7754 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7755 rem)
7756 n_patterns++;
7757 if (n_patterns > wowlan->n_patterns)
7758 return -EINVAL;
7759
7760 new_triggers.patterns = kcalloc(n_patterns,
7761 sizeof(new_triggers.patterns[0]),
7762 GFP_KERNEL);
7763 if (!new_triggers.patterns)
7764 return -ENOMEM;
7765
7766 new_triggers.n_patterns = n_patterns;
7767 i = 0;
7768
7769 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7770 rem) {
7771 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7772 nla_data(pat), nla_len(pat), NULL);
7773 err = -EINVAL;
7774 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7775 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7776 goto error;
7777 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7778 mask_len = DIV_ROUND_UP(pat_len, 8);
7779 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7780 mask_len)
7781 goto error;
7782 if (pat_len > wowlan->pattern_max_len ||
7783 pat_len < wowlan->pattern_min_len)
7784 goto error;
7785
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007786 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7787 pkt_offset = 0;
7788 else
7789 pkt_offset = nla_get_u32(
7790 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7791 if (pkt_offset > wowlan->max_pkt_offset)
7792 goto error;
7793 new_triggers.patterns[i].pkt_offset = pkt_offset;
7794
Johannes Bergff1b6e62011-05-04 15:37:28 +02007795 new_triggers.patterns[i].mask =
7796 kmalloc(mask_len + pat_len, GFP_KERNEL);
7797 if (!new_triggers.patterns[i].mask) {
7798 err = -ENOMEM;
7799 goto error;
7800 }
7801 new_triggers.patterns[i].pattern =
7802 new_triggers.patterns[i].mask + mask_len;
7803 memcpy(new_triggers.patterns[i].mask,
7804 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7805 mask_len);
7806 new_triggers.patterns[i].pattern_len = pat_len;
7807 memcpy(new_triggers.patterns[i].pattern,
7808 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7809 pat_len);
7810 i++;
7811 }
7812 }
7813
Johannes Berg2a0e0472013-01-23 22:57:40 +01007814 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7815 err = nl80211_parse_wowlan_tcp(
7816 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7817 &new_triggers);
7818 if (err)
7819 goto error;
7820 }
7821
Johannes Bergae33bd82012-07-12 16:25:02 +02007822 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7823 if (!ntrig) {
7824 err = -ENOMEM;
7825 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007826 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007827 cfg80211_rdev_free_wowlan(rdev);
7828 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007829
Johannes Bergae33bd82012-07-12 16:25:02 +02007830 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007831 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007832 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007833
Johannes Bergff1b6e62011-05-04 15:37:28 +02007834 return 0;
7835 error:
7836 for (i = 0; i < new_triggers.n_patterns; i++)
7837 kfree(new_triggers.patterns[i].mask);
7838 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007839 if (new_triggers.tcp && new_triggers.tcp->sock)
7840 sock_release(new_triggers.tcp->sock);
7841 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007842 return err;
7843}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007844#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007845
Johannes Berge5497d72011-07-05 16:35:40 +02007846static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7847{
7848 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7849 struct net_device *dev = info->user_ptr[1];
7850 struct wireless_dev *wdev = dev->ieee80211_ptr;
7851 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7852 struct cfg80211_gtk_rekey_data rekey_data;
7853 int err;
7854
7855 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7856 return -EINVAL;
7857
7858 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7859 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7860 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7861 nl80211_rekey_policy);
7862 if (err)
7863 return err;
7864
7865 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7866 return -ERANGE;
7867 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7868 return -ERANGE;
7869 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7870 return -ERANGE;
7871
7872 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7873 NL80211_KEK_LEN);
7874 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7875 NL80211_KCK_LEN);
7876 memcpy(rekey_data.replay_ctr,
7877 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7878 NL80211_REPLAY_CTR_LEN);
7879
7880 wdev_lock(wdev);
7881 if (!wdev->current_bss) {
7882 err = -ENOTCONN;
7883 goto out;
7884 }
7885
7886 if (!rdev->ops->set_rekey_data) {
7887 err = -EOPNOTSUPP;
7888 goto out;
7889 }
7890
Hila Gonene35e4d22012-06-27 17:19:42 +03007891 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007892 out:
7893 wdev_unlock(wdev);
7894 return err;
7895}
7896
Johannes Berg28946da2011-11-04 11:18:12 +01007897static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7898 struct genl_info *info)
7899{
7900 struct net_device *dev = info->user_ptr[1];
7901 struct wireless_dev *wdev = dev->ieee80211_ptr;
7902
7903 if (wdev->iftype != NL80211_IFTYPE_AP &&
7904 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7905 return -EINVAL;
7906
Eric W. Biederman15e47302012-09-07 20:12:54 +00007907 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01007908 return -EBUSY;
7909
Eric W. Biederman15e47302012-09-07 20:12:54 +00007910 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01007911 return 0;
7912}
7913
Johannes Berg7f6cf312011-11-04 11:18:15 +01007914static int nl80211_probe_client(struct sk_buff *skb,
7915 struct genl_info *info)
7916{
7917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7918 struct net_device *dev = info->user_ptr[1];
7919 struct wireless_dev *wdev = dev->ieee80211_ptr;
7920 struct sk_buff *msg;
7921 void *hdr;
7922 const u8 *addr;
7923 u64 cookie;
7924 int err;
7925
7926 if (wdev->iftype != NL80211_IFTYPE_AP &&
7927 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7928 return -EOPNOTSUPP;
7929
7930 if (!info->attrs[NL80211_ATTR_MAC])
7931 return -EINVAL;
7932
7933 if (!rdev->ops->probe_client)
7934 return -EOPNOTSUPP;
7935
7936 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7937 if (!msg)
7938 return -ENOMEM;
7939
Eric W. Biederman15e47302012-09-07 20:12:54 +00007940 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01007941 NL80211_CMD_PROBE_CLIENT);
7942
7943 if (IS_ERR(hdr)) {
7944 err = PTR_ERR(hdr);
7945 goto free_msg;
7946 }
7947
7948 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7949
Hila Gonene35e4d22012-06-27 17:19:42 +03007950 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01007951 if (err)
7952 goto free_msg;
7953
David S. Miller9360ffd2012-03-29 04:41:26 -04007954 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7955 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01007956
7957 genlmsg_end(msg, hdr);
7958
7959 return genlmsg_reply(msg, info);
7960
7961 nla_put_failure:
7962 err = -ENOBUFS;
7963 free_msg:
7964 nlmsg_free(msg);
7965 return err;
7966}
7967
Johannes Berg5e7602302011-11-04 11:18:17 +01007968static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
7969{
7970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07007971 struct cfg80211_beacon_registration *reg, *nreg;
7972 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01007973
7974 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
7975 return -EOPNOTSUPP;
7976
Ben Greear37c73b52012-10-26 14:49:25 -07007977 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
7978 if (!nreg)
7979 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01007980
Ben Greear37c73b52012-10-26 14:49:25 -07007981 /* First, check if already registered. */
7982 spin_lock_bh(&rdev->beacon_registrations_lock);
7983 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
7984 if (reg->nlportid == info->snd_portid) {
7985 rv = -EALREADY;
7986 goto out_err;
7987 }
7988 }
7989 /* Add it to the list */
7990 nreg->nlportid = info->snd_portid;
7991 list_add(&nreg->list, &rdev->beacon_registrations);
7992
7993 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01007994
7995 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07007996out_err:
7997 spin_unlock_bh(&rdev->beacon_registrations_lock);
7998 kfree(nreg);
7999 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008000}
8001
Johannes Berg98104fde2012-06-16 00:19:54 +02008002static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8003{
8004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8005 struct wireless_dev *wdev = info->user_ptr[1];
8006 int err;
8007
8008 if (!rdev->ops->start_p2p_device)
8009 return -EOPNOTSUPP;
8010
8011 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8012 return -EOPNOTSUPP;
8013
8014 if (wdev->p2p_started)
8015 return 0;
8016
8017 mutex_lock(&rdev->devlist_mtx);
8018 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8019 mutex_unlock(&rdev->devlist_mtx);
8020 if (err)
8021 return err;
8022
Johannes Bergeeb126e2012-10-23 15:16:50 +02008023 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008024 if (err)
8025 return err;
8026
8027 wdev->p2p_started = true;
8028 mutex_lock(&rdev->devlist_mtx);
8029 rdev->opencount++;
8030 mutex_unlock(&rdev->devlist_mtx);
8031
8032 return 0;
8033}
8034
8035static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8036{
8037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8038 struct wireless_dev *wdev = info->user_ptr[1];
8039
8040 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8041 return -EOPNOTSUPP;
8042
8043 if (!rdev->ops->stop_p2p_device)
8044 return -EOPNOTSUPP;
8045
8046 if (!wdev->p2p_started)
8047 return 0;
8048
Johannes Bergeeb126e2012-10-23 15:16:50 +02008049 rdev_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008050 wdev->p2p_started = false;
8051
8052 mutex_lock(&rdev->devlist_mtx);
8053 rdev->opencount--;
8054 mutex_unlock(&rdev->devlist_mtx);
8055
8056 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
8057 rdev->scan_req->aborted = true;
8058 ___cfg80211_scan_done(rdev, true);
8059 }
8060
8061 return 0;
8062}
8063
Johannes Berg3713b4e2013-02-14 16:19:38 +01008064static int nl80211_get_protocol_features(struct sk_buff *skb,
8065 struct genl_info *info)
8066{
8067 void *hdr;
8068 struct sk_buff *msg;
8069
8070 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8071 if (!msg)
8072 return -ENOMEM;
8073
8074 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8075 NL80211_CMD_GET_PROTOCOL_FEATURES);
8076 if (!hdr)
8077 goto nla_put_failure;
8078
8079 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8080 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8081 goto nla_put_failure;
8082
8083 genlmsg_end(msg, hdr);
8084 return genlmsg_reply(msg, info);
8085
8086 nla_put_failure:
8087 kfree_skb(msg);
8088 return -ENOBUFS;
8089}
8090
Johannes Berg4c476992010-10-04 21:36:35 +02008091#define NL80211_FLAG_NEED_WIPHY 0x01
8092#define NL80211_FLAG_NEED_NETDEV 0x02
8093#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008094#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8095#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8096 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008097#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008098/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008099#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8100 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008101
8102static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8103 struct genl_info *info)
8104{
8105 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008106 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008107 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008108 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8109
8110 if (rtnl)
8111 rtnl_lock();
8112
8113 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008114 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008115 if (IS_ERR(rdev)) {
8116 if (rtnl)
8117 rtnl_unlock();
8118 return PTR_ERR(rdev);
8119 }
8120 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008121 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8122 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008123 mutex_lock(&cfg80211_mutex);
8124 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8125 info->attrs);
8126 if (IS_ERR(wdev)) {
8127 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02008128 if (rtnl)
8129 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008130 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008131 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008132
Johannes Berg89a54e42012-06-15 14:33:17 +02008133 dev = wdev->netdev;
8134 rdev = wiphy_to_dev(wdev->wiphy);
8135
Johannes Berg1bf614e2012-06-15 15:23:36 +02008136 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8137 if (!dev) {
8138 mutex_unlock(&cfg80211_mutex);
8139 if (rtnl)
8140 rtnl_unlock();
8141 return -EINVAL;
8142 }
8143
8144 info->user_ptr[1] = dev;
8145 } else {
8146 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008147 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008148
Johannes Berg1bf614e2012-06-15 15:23:36 +02008149 if (dev) {
8150 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8151 !netif_running(dev)) {
8152 mutex_unlock(&cfg80211_mutex);
8153 if (rtnl)
8154 rtnl_unlock();
8155 return -ENETDOWN;
8156 }
8157
8158 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008159 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8160 if (!wdev->p2p_started) {
8161 mutex_unlock(&cfg80211_mutex);
8162 if (rtnl)
8163 rtnl_unlock();
8164 return -ENETDOWN;
8165 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008166 }
8167
Johannes Berg89a54e42012-06-15 14:33:17 +02008168 cfg80211_lock_rdev(rdev);
8169
8170 mutex_unlock(&cfg80211_mutex);
8171
Johannes Berg4c476992010-10-04 21:36:35 +02008172 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008173 }
8174
8175 return 0;
8176}
8177
8178static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8179 struct genl_info *info)
8180{
8181 if (info->user_ptr[0])
8182 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02008183 if (info->user_ptr[1]) {
8184 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8185 struct wireless_dev *wdev = info->user_ptr[1];
8186
8187 if (wdev->netdev)
8188 dev_put(wdev->netdev);
8189 } else {
8190 dev_put(info->user_ptr[1]);
8191 }
8192 }
Johannes Berg4c476992010-10-04 21:36:35 +02008193 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8194 rtnl_unlock();
8195}
8196
Johannes Berg55682962007-09-20 13:09:35 -04008197static struct genl_ops nl80211_ops[] = {
8198 {
8199 .cmd = NL80211_CMD_GET_WIPHY,
8200 .doit = nl80211_get_wiphy,
8201 .dumpit = nl80211_dump_wiphy,
8202 .policy = nl80211_policy,
8203 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008204 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04008205 },
8206 {
8207 .cmd = NL80211_CMD_SET_WIPHY,
8208 .doit = nl80211_set_wiphy,
8209 .policy = nl80211_policy,
8210 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008211 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008212 },
8213 {
8214 .cmd = NL80211_CMD_GET_INTERFACE,
8215 .doit = nl80211_get_interface,
8216 .dumpit = nl80211_dump_interface,
8217 .policy = nl80211_policy,
8218 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02008219 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04008220 },
8221 {
8222 .cmd = NL80211_CMD_SET_INTERFACE,
8223 .doit = nl80211_set_interface,
8224 .policy = nl80211_policy,
8225 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008226 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8227 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008228 },
8229 {
8230 .cmd = NL80211_CMD_NEW_INTERFACE,
8231 .doit = nl80211_new_interface,
8232 .policy = nl80211_policy,
8233 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008234 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8235 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008236 },
8237 {
8238 .cmd = NL80211_CMD_DEL_INTERFACE,
8239 .doit = nl80211_del_interface,
8240 .policy = nl80211_policy,
8241 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008242 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008243 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008244 },
Johannes Berg41ade002007-12-19 02:03:29 +01008245 {
8246 .cmd = NL80211_CMD_GET_KEY,
8247 .doit = nl80211_get_key,
8248 .policy = nl80211_policy,
8249 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008250 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008251 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008252 },
8253 {
8254 .cmd = NL80211_CMD_SET_KEY,
8255 .doit = nl80211_set_key,
8256 .policy = nl80211_policy,
8257 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008258 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008259 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008260 },
8261 {
8262 .cmd = NL80211_CMD_NEW_KEY,
8263 .doit = nl80211_new_key,
8264 .policy = nl80211_policy,
8265 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008266 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008267 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008268 },
8269 {
8270 .cmd = NL80211_CMD_DEL_KEY,
8271 .doit = nl80211_del_key,
8272 .policy = nl80211_policy,
8273 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008275 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008276 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008277 {
8278 .cmd = NL80211_CMD_SET_BEACON,
8279 .policy = nl80211_policy,
8280 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008281 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008282 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008283 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008284 },
8285 {
Johannes Berg88600202012-02-13 15:17:18 +01008286 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008287 .policy = nl80211_policy,
8288 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008289 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008290 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008291 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008292 },
8293 {
Johannes Berg88600202012-02-13 15:17:18 +01008294 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008295 .policy = nl80211_policy,
8296 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008297 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008299 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008300 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008301 {
8302 .cmd = NL80211_CMD_GET_STATION,
8303 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008304 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008305 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008306 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8307 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008308 },
8309 {
8310 .cmd = NL80211_CMD_SET_STATION,
8311 .doit = nl80211_set_station,
8312 .policy = nl80211_policy,
8313 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008314 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008315 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008316 },
8317 {
8318 .cmd = NL80211_CMD_NEW_STATION,
8319 .doit = nl80211_new_station,
8320 .policy = nl80211_policy,
8321 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008322 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008323 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008324 },
8325 {
8326 .cmd = NL80211_CMD_DEL_STATION,
8327 .doit = nl80211_del_station,
8328 .policy = nl80211_policy,
8329 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008330 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008331 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008332 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008333 {
8334 .cmd = NL80211_CMD_GET_MPATH,
8335 .doit = nl80211_get_mpath,
8336 .dumpit = nl80211_dump_mpath,
8337 .policy = nl80211_policy,
8338 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008339 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008340 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008341 },
8342 {
8343 .cmd = NL80211_CMD_SET_MPATH,
8344 .doit = nl80211_set_mpath,
8345 .policy = nl80211_policy,
8346 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008347 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008348 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008349 },
8350 {
8351 .cmd = NL80211_CMD_NEW_MPATH,
8352 .doit = nl80211_new_mpath,
8353 .policy = nl80211_policy,
8354 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008356 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008357 },
8358 {
8359 .cmd = NL80211_CMD_DEL_MPATH,
8360 .doit = nl80211_del_mpath,
8361 .policy = nl80211_policy,
8362 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008364 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008365 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008366 {
8367 .cmd = NL80211_CMD_SET_BSS,
8368 .doit = nl80211_set_bss,
8369 .policy = nl80211_policy,
8370 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008372 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008373 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008374 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008375 .cmd = NL80211_CMD_GET_REG,
8376 .doit = nl80211_get_reg,
8377 .policy = nl80211_policy,
8378 /* can be retrieved by unprivileged users */
8379 },
8380 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008381 .cmd = NL80211_CMD_SET_REG,
8382 .doit = nl80211_set_reg,
8383 .policy = nl80211_policy,
8384 .flags = GENL_ADMIN_PERM,
8385 },
8386 {
8387 .cmd = NL80211_CMD_REQ_SET_REG,
8388 .doit = nl80211_req_set_reg,
8389 .policy = nl80211_policy,
8390 .flags = GENL_ADMIN_PERM,
8391 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008392 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008393 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8394 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008395 .policy = nl80211_policy,
8396 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008398 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008399 },
8400 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008401 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8402 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008403 .policy = nl80211_policy,
8404 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008405 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008406 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008407 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008408 {
Johannes Berg2a519312009-02-10 21:25:55 +01008409 .cmd = NL80211_CMD_TRIGGER_SCAN,
8410 .doit = nl80211_trigger_scan,
8411 .policy = nl80211_policy,
8412 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008413 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008414 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008415 },
8416 {
8417 .cmd = NL80211_CMD_GET_SCAN,
8418 .policy = nl80211_policy,
8419 .dumpit = nl80211_dump_scan,
8420 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008421 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008422 .cmd = NL80211_CMD_START_SCHED_SCAN,
8423 .doit = nl80211_start_sched_scan,
8424 .policy = nl80211_policy,
8425 .flags = GENL_ADMIN_PERM,
8426 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8427 NL80211_FLAG_NEED_RTNL,
8428 },
8429 {
8430 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8431 .doit = nl80211_stop_sched_scan,
8432 .policy = nl80211_policy,
8433 .flags = GENL_ADMIN_PERM,
8434 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8435 NL80211_FLAG_NEED_RTNL,
8436 },
8437 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008438 .cmd = NL80211_CMD_AUTHENTICATE,
8439 .doit = nl80211_authenticate,
8440 .policy = nl80211_policy,
8441 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008442 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008443 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008444 },
8445 {
8446 .cmd = NL80211_CMD_ASSOCIATE,
8447 .doit = nl80211_associate,
8448 .policy = nl80211_policy,
8449 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008450 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008451 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008452 },
8453 {
8454 .cmd = NL80211_CMD_DEAUTHENTICATE,
8455 .doit = nl80211_deauthenticate,
8456 .policy = nl80211_policy,
8457 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008458 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008459 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008460 },
8461 {
8462 .cmd = NL80211_CMD_DISASSOCIATE,
8463 .doit = nl80211_disassociate,
8464 .policy = nl80211_policy,
8465 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008466 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008467 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008468 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008469 {
8470 .cmd = NL80211_CMD_JOIN_IBSS,
8471 .doit = nl80211_join_ibss,
8472 .policy = nl80211_policy,
8473 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008474 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008475 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008476 },
8477 {
8478 .cmd = NL80211_CMD_LEAVE_IBSS,
8479 .doit = nl80211_leave_ibss,
8480 .policy = nl80211_policy,
8481 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008482 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008483 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008484 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008485#ifdef CONFIG_NL80211_TESTMODE
8486 {
8487 .cmd = NL80211_CMD_TESTMODE,
8488 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008489 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008490 .policy = nl80211_policy,
8491 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008492 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8493 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008494 },
8495#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008496 {
8497 .cmd = NL80211_CMD_CONNECT,
8498 .doit = nl80211_connect,
8499 .policy = nl80211_policy,
8500 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008502 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008503 },
8504 {
8505 .cmd = NL80211_CMD_DISCONNECT,
8506 .doit = nl80211_disconnect,
8507 .policy = nl80211_policy,
8508 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008510 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008511 },
Johannes Berg463d0182009-07-14 00:33:35 +02008512 {
8513 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8514 .doit = nl80211_wiphy_netns,
8515 .policy = nl80211_policy,
8516 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008517 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8518 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008519 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008520 {
8521 .cmd = NL80211_CMD_GET_SURVEY,
8522 .policy = nl80211_policy,
8523 .dumpit = nl80211_dump_survey,
8524 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008525 {
8526 .cmd = NL80211_CMD_SET_PMKSA,
8527 .doit = nl80211_setdel_pmksa,
8528 .policy = nl80211_policy,
8529 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008531 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008532 },
8533 {
8534 .cmd = NL80211_CMD_DEL_PMKSA,
8535 .doit = nl80211_setdel_pmksa,
8536 .policy = nl80211_policy,
8537 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008539 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008540 },
8541 {
8542 .cmd = NL80211_CMD_FLUSH_PMKSA,
8543 .doit = nl80211_flush_pmksa,
8544 .policy = nl80211_policy,
8545 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008547 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008548 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008549 {
8550 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8551 .doit = nl80211_remain_on_channel,
8552 .policy = nl80211_policy,
8553 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008554 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008555 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008556 },
8557 {
8558 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8559 .doit = nl80211_cancel_remain_on_channel,
8560 .policy = nl80211_policy,
8561 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008562 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008563 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008564 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008565 {
8566 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8567 .doit = nl80211_set_tx_bitrate_mask,
8568 .policy = nl80211_policy,
8569 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008570 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8571 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008572 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008573 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008574 .cmd = NL80211_CMD_REGISTER_FRAME,
8575 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008576 .policy = nl80211_policy,
8577 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008578 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008579 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008580 },
8581 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008582 .cmd = NL80211_CMD_FRAME,
8583 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008584 .policy = nl80211_policy,
8585 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008586 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008587 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008588 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008589 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008590 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8591 .doit = nl80211_tx_mgmt_cancel_wait,
8592 .policy = nl80211_policy,
8593 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008594 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008595 NL80211_FLAG_NEED_RTNL,
8596 },
8597 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008598 .cmd = NL80211_CMD_SET_POWER_SAVE,
8599 .doit = nl80211_set_power_save,
8600 .policy = nl80211_policy,
8601 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008602 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8603 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008604 },
8605 {
8606 .cmd = NL80211_CMD_GET_POWER_SAVE,
8607 .doit = nl80211_get_power_save,
8608 .policy = nl80211_policy,
8609 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008610 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8611 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008612 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008613 {
8614 .cmd = NL80211_CMD_SET_CQM,
8615 .doit = nl80211_set_cqm,
8616 .policy = nl80211_policy,
8617 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008618 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8619 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008620 },
Johannes Bergf444de02010-05-05 15:25:02 +02008621 {
8622 .cmd = NL80211_CMD_SET_CHANNEL,
8623 .doit = nl80211_set_channel,
8624 .policy = nl80211_policy,
8625 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008626 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8627 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008628 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008629 {
8630 .cmd = NL80211_CMD_SET_WDS_PEER,
8631 .doit = nl80211_set_wds_peer,
8632 .policy = nl80211_policy,
8633 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008634 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8635 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008636 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008637 {
8638 .cmd = NL80211_CMD_JOIN_MESH,
8639 .doit = nl80211_join_mesh,
8640 .policy = nl80211_policy,
8641 .flags = GENL_ADMIN_PERM,
8642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8643 NL80211_FLAG_NEED_RTNL,
8644 },
8645 {
8646 .cmd = NL80211_CMD_LEAVE_MESH,
8647 .doit = nl80211_leave_mesh,
8648 .policy = nl80211_policy,
8649 .flags = GENL_ADMIN_PERM,
8650 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8651 NL80211_FLAG_NEED_RTNL,
8652 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008653#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008654 {
8655 .cmd = NL80211_CMD_GET_WOWLAN,
8656 .doit = nl80211_get_wowlan,
8657 .policy = nl80211_policy,
8658 /* can be retrieved by unprivileged users */
8659 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8660 NL80211_FLAG_NEED_RTNL,
8661 },
8662 {
8663 .cmd = NL80211_CMD_SET_WOWLAN,
8664 .doit = nl80211_set_wowlan,
8665 .policy = nl80211_policy,
8666 .flags = GENL_ADMIN_PERM,
8667 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8668 NL80211_FLAG_NEED_RTNL,
8669 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008670#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008671 {
8672 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8673 .doit = nl80211_set_rekey_data,
8674 .policy = nl80211_policy,
8675 .flags = GENL_ADMIN_PERM,
8676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8677 NL80211_FLAG_NEED_RTNL,
8678 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008679 {
8680 .cmd = NL80211_CMD_TDLS_MGMT,
8681 .doit = nl80211_tdls_mgmt,
8682 .policy = nl80211_policy,
8683 .flags = GENL_ADMIN_PERM,
8684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8685 NL80211_FLAG_NEED_RTNL,
8686 },
8687 {
8688 .cmd = NL80211_CMD_TDLS_OPER,
8689 .doit = nl80211_tdls_oper,
8690 .policy = nl80211_policy,
8691 .flags = GENL_ADMIN_PERM,
8692 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8693 NL80211_FLAG_NEED_RTNL,
8694 },
Johannes Berg28946da2011-11-04 11:18:12 +01008695 {
8696 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8697 .doit = nl80211_register_unexpected_frame,
8698 .policy = nl80211_policy,
8699 .flags = GENL_ADMIN_PERM,
8700 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8701 NL80211_FLAG_NEED_RTNL,
8702 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008703 {
8704 .cmd = NL80211_CMD_PROBE_CLIENT,
8705 .doit = nl80211_probe_client,
8706 .policy = nl80211_policy,
8707 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008708 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008709 NL80211_FLAG_NEED_RTNL,
8710 },
Johannes Berg5e7602302011-11-04 11:18:17 +01008711 {
8712 .cmd = NL80211_CMD_REGISTER_BEACONS,
8713 .doit = nl80211_register_beacons,
8714 .policy = nl80211_policy,
8715 .flags = GENL_ADMIN_PERM,
8716 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8717 NL80211_FLAG_NEED_RTNL,
8718 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008719 {
8720 .cmd = NL80211_CMD_SET_NOACK_MAP,
8721 .doit = nl80211_set_noack_map,
8722 .policy = nl80211_policy,
8723 .flags = GENL_ADMIN_PERM,
8724 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8725 NL80211_FLAG_NEED_RTNL,
8726 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008727 {
8728 .cmd = NL80211_CMD_START_P2P_DEVICE,
8729 .doit = nl80211_start_p2p_device,
8730 .policy = nl80211_policy,
8731 .flags = GENL_ADMIN_PERM,
8732 .internal_flags = NL80211_FLAG_NEED_WDEV |
8733 NL80211_FLAG_NEED_RTNL,
8734 },
8735 {
8736 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8737 .doit = nl80211_stop_p2p_device,
8738 .policy = nl80211_policy,
8739 .flags = GENL_ADMIN_PERM,
8740 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8741 NL80211_FLAG_NEED_RTNL,
8742 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008743 {
8744 .cmd = NL80211_CMD_SET_MCAST_RATE,
8745 .doit = nl80211_set_mcast_rate,
8746 .policy = nl80211_policy,
8747 .flags = GENL_ADMIN_PERM,
8748 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8749 NL80211_FLAG_NEED_RTNL,
8750 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308751 {
8752 .cmd = NL80211_CMD_SET_MAC_ACL,
8753 .doit = nl80211_set_mac_acl,
8754 .policy = nl80211_policy,
8755 .flags = GENL_ADMIN_PERM,
8756 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8757 NL80211_FLAG_NEED_RTNL,
8758 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008759 {
8760 .cmd = NL80211_CMD_RADAR_DETECT,
8761 .doit = nl80211_start_radar_detection,
8762 .policy = nl80211_policy,
8763 .flags = GENL_ADMIN_PERM,
8764 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8765 NL80211_FLAG_NEED_RTNL,
8766 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008767 {
8768 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8769 .doit = nl80211_get_protocol_features,
8770 .policy = nl80211_policy,
8771 },
Johannes Berg55682962007-09-20 13:09:35 -04008772};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008773
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008774static struct genl_multicast_group nl80211_mlme_mcgrp = {
8775 .name = "mlme",
8776};
Johannes Berg55682962007-09-20 13:09:35 -04008777
8778/* multicast groups */
8779static struct genl_multicast_group nl80211_config_mcgrp = {
8780 .name = "config",
8781};
Johannes Berg2a519312009-02-10 21:25:55 +01008782static struct genl_multicast_group nl80211_scan_mcgrp = {
8783 .name = "scan",
8784};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008785static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8786 .name = "regulatory",
8787};
Johannes Berg55682962007-09-20 13:09:35 -04008788
8789/* notification functions */
8790
8791void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8792{
8793 struct sk_buff *msg;
8794
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008795 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008796 if (!msg)
8797 return;
8798
Johannes Berg3713b4e2013-02-14 16:19:38 +01008799 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8800 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008801 nlmsg_free(msg);
8802 return;
8803 }
8804
Johannes Berg463d0182009-07-14 00:33:35 +02008805 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8806 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008807}
8808
Johannes Berg362a4152009-05-24 16:43:15 +02008809static int nl80211_add_scan_req(struct sk_buff *msg,
8810 struct cfg80211_registered_device *rdev)
8811{
8812 struct cfg80211_scan_request *req = rdev->scan_req;
8813 struct nlattr *nest;
8814 int i;
8815
Johannes Berg667503dd2009-07-07 03:56:11 +02008816 ASSERT_RDEV_LOCK(rdev);
8817
Johannes Berg362a4152009-05-24 16:43:15 +02008818 if (WARN_ON(!req))
8819 return 0;
8820
8821 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8822 if (!nest)
8823 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008824 for (i = 0; i < req->n_ssids; i++) {
8825 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8826 goto nla_put_failure;
8827 }
Johannes Berg362a4152009-05-24 16:43:15 +02008828 nla_nest_end(msg, nest);
8829
8830 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8831 if (!nest)
8832 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008833 for (i = 0; i < req->n_channels; i++) {
8834 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8835 goto nla_put_failure;
8836 }
Johannes Berg362a4152009-05-24 16:43:15 +02008837 nla_nest_end(msg, nest);
8838
David S. Miller9360ffd2012-03-29 04:41:26 -04008839 if (req->ie &&
8840 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8841 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008842
Sam Lefflered4737712012-10-11 21:03:31 -07008843 if (req->flags)
8844 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8845
Johannes Berg362a4152009-05-24 16:43:15 +02008846 return 0;
8847 nla_put_failure:
8848 return -ENOBUFS;
8849}
8850
Johannes Berga538e2d2009-06-16 19:56:42 +02008851static int nl80211_send_scan_msg(struct sk_buff *msg,
8852 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008853 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008854 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008855 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008856{
8857 void *hdr;
8858
Eric W. Biederman15e47302012-09-07 20:12:54 +00008859 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008860 if (!hdr)
8861 return -1;
8862
David S. Miller9360ffd2012-03-29 04:41:26 -04008863 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008864 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8865 wdev->netdev->ifindex)) ||
8866 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008867 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008868
Johannes Berg362a4152009-05-24 16:43:15 +02008869 /* ignore errors and send incomplete event anyway */
8870 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008871
8872 return genlmsg_end(msg, hdr);
8873
8874 nla_put_failure:
8875 genlmsg_cancel(msg, hdr);
8876 return -EMSGSIZE;
8877}
8878
Luciano Coelho807f8a82011-05-11 17:09:35 +03008879static int
8880nl80211_send_sched_scan_msg(struct sk_buff *msg,
8881 struct cfg80211_registered_device *rdev,
8882 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008883 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008884{
8885 void *hdr;
8886
Eric W. Biederman15e47302012-09-07 20:12:54 +00008887 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008888 if (!hdr)
8889 return -1;
8890
David S. Miller9360ffd2012-03-29 04:41:26 -04008891 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8892 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8893 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008894
8895 return genlmsg_end(msg, hdr);
8896
8897 nla_put_failure:
8898 genlmsg_cancel(msg, hdr);
8899 return -EMSGSIZE;
8900}
8901
Johannes Berga538e2d2009-06-16 19:56:42 +02008902void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008903 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02008904{
8905 struct sk_buff *msg;
8906
Thomas Graf58050fc2012-06-28 03:57:45 +00008907 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008908 if (!msg)
8909 return;
8910
Johannes Bergfd014282012-06-18 19:17:03 +02008911 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008912 NL80211_CMD_TRIGGER_SCAN) < 0) {
8913 nlmsg_free(msg);
8914 return;
8915 }
8916
Johannes Berg463d0182009-07-14 00:33:35 +02008917 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8918 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008919}
8920
Johannes Berg2a519312009-02-10 21:25:55 +01008921void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008922 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01008923{
8924 struct sk_buff *msg;
8925
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008926 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008927 if (!msg)
8928 return;
8929
Johannes Bergfd014282012-06-18 19:17:03 +02008930 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008931 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008932 nlmsg_free(msg);
8933 return;
8934 }
8935
Johannes Berg463d0182009-07-14 00:33:35 +02008936 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8937 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008938}
8939
8940void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008941 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01008942{
8943 struct sk_buff *msg;
8944
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008945 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008946 if (!msg)
8947 return;
8948
Johannes Bergfd014282012-06-18 19:17:03 +02008949 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008950 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008951 nlmsg_free(msg);
8952 return;
8953 }
8954
Johannes Berg463d0182009-07-14 00:33:35 +02008955 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8956 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008957}
8958
Luciano Coelho807f8a82011-05-11 17:09:35 +03008959void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
8960 struct net_device *netdev)
8961{
8962 struct sk_buff *msg;
8963
8964 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8965 if (!msg)
8966 return;
8967
8968 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
8969 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
8970 nlmsg_free(msg);
8971 return;
8972 }
8973
8974 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8975 nl80211_scan_mcgrp.id, GFP_KERNEL);
8976}
8977
8978void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
8979 struct net_device *netdev, u32 cmd)
8980{
8981 struct sk_buff *msg;
8982
Thomas Graf58050fc2012-06-28 03:57:45 +00008983 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008984 if (!msg)
8985 return;
8986
8987 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
8988 nlmsg_free(msg);
8989 return;
8990 }
8991
8992 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8993 nl80211_scan_mcgrp.id, GFP_KERNEL);
8994}
8995
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008996/*
8997 * This can happen on global regulatory changes or device specific settings
8998 * based on custom world regulatory domains.
8999 */
9000void nl80211_send_reg_change_event(struct regulatory_request *request)
9001{
9002 struct sk_buff *msg;
9003 void *hdr;
9004
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009005 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009006 if (!msg)
9007 return;
9008
9009 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9010 if (!hdr) {
9011 nlmsg_free(msg);
9012 return;
9013 }
9014
9015 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009016 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9017 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009018
David S. Miller9360ffd2012-03-29 04:41:26 -04009019 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9020 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9021 NL80211_REGDOM_TYPE_WORLD))
9022 goto nla_put_failure;
9023 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9024 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9025 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9026 goto nla_put_failure;
9027 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9028 request->intersect) {
9029 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9030 NL80211_REGDOM_TYPE_INTERSECTION))
9031 goto nla_put_failure;
9032 } else {
9033 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9034 NL80211_REGDOM_TYPE_COUNTRY) ||
9035 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9036 request->alpha2))
9037 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009038 }
9039
Johannes Bergf4173762012-12-03 18:23:37 +01009040 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009041 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9042 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009043
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009044 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009045
Johannes Bergbc43b282009-07-25 10:54:13 +02009046 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009047 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009048 GFP_ATOMIC);
9049 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009050
9051 return;
9052
9053nla_put_failure:
9054 genlmsg_cancel(msg, hdr);
9055 nlmsg_free(msg);
9056}
9057
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009058static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9059 struct net_device *netdev,
9060 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009061 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009062{
9063 struct sk_buff *msg;
9064 void *hdr;
9065
Johannes Berge6d6e342009-07-01 21:26:47 +02009066 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009067 if (!msg)
9068 return;
9069
9070 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9071 if (!hdr) {
9072 nlmsg_free(msg);
9073 return;
9074 }
9075
David S. Miller9360ffd2012-03-29 04:41:26 -04009076 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9077 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9078 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9079 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009080
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009081 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009082
Johannes Berg463d0182009-07-14 00:33:35 +02009083 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9084 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009085 return;
9086
9087 nla_put_failure:
9088 genlmsg_cancel(msg, hdr);
9089 nlmsg_free(msg);
9090}
9091
9092void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009093 struct net_device *netdev, const u8 *buf,
9094 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009095{
9096 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009097 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009098}
9099
9100void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9101 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009102 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009103{
Johannes Berge6d6e342009-07-01 21:26:47 +02009104 nl80211_send_mlme_event(rdev, netdev, buf, len,
9105 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009106}
9107
Jouni Malinen53b46b82009-03-27 20:53:56 +02009108void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009109 struct net_device *netdev, const u8 *buf,
9110 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009111{
9112 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009113 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009114}
9115
Jouni Malinen53b46b82009-03-27 20:53:56 +02009116void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9117 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009118 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009119{
9120 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009121 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009122}
9123
Jouni Malinencf4e5942010-12-16 00:52:40 +02009124void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
9125 struct net_device *netdev, const u8 *buf,
9126 size_t len, gfp_t gfp)
9127{
9128 nl80211_send_mlme_event(rdev, netdev, buf, len,
9129 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
9130}
9131
9132void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
9133 struct net_device *netdev, const u8 *buf,
9134 size_t len, gfp_t gfp)
9135{
9136 nl80211_send_mlme_event(rdev, netdev, buf, len,
9137 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
9138}
9139
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009140static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9141 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009142 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009143{
9144 struct sk_buff *msg;
9145 void *hdr;
9146
Johannes Berge6d6e342009-07-01 21:26:47 +02009147 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009148 if (!msg)
9149 return;
9150
9151 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9152 if (!hdr) {
9153 nlmsg_free(msg);
9154 return;
9155 }
9156
David S. Miller9360ffd2012-03-29 04:41:26 -04009157 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9158 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9159 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9160 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9161 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009162
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009163 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009164
Johannes Berg463d0182009-07-14 00:33:35 +02009165 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9166 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009167 return;
9168
9169 nla_put_failure:
9170 genlmsg_cancel(msg, hdr);
9171 nlmsg_free(msg);
9172}
9173
9174void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009175 struct net_device *netdev, const u8 *addr,
9176 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009177{
9178 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009179 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009180}
9181
9182void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009183 struct net_device *netdev, const u8 *addr,
9184 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009185{
Johannes Berge6d6e342009-07-01 21:26:47 +02009186 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9187 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009188}
9189
Samuel Ortizb23aa672009-07-01 21:26:54 +02009190void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9191 struct net_device *netdev, const u8 *bssid,
9192 const u8 *req_ie, size_t req_ie_len,
9193 const u8 *resp_ie, size_t resp_ie_len,
9194 u16 status, gfp_t gfp)
9195{
9196 struct sk_buff *msg;
9197 void *hdr;
9198
Thomas Graf58050fc2012-06-28 03:57:45 +00009199 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009200 if (!msg)
9201 return;
9202
9203 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9204 if (!hdr) {
9205 nlmsg_free(msg);
9206 return;
9207 }
9208
David S. Miller9360ffd2012-03-29 04:41:26 -04009209 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9210 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9211 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9212 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9213 (req_ie &&
9214 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9215 (resp_ie &&
9216 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9217 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009218
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009219 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009220
Johannes Berg463d0182009-07-14 00:33:35 +02009221 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9222 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009223 return;
9224
9225 nla_put_failure:
9226 genlmsg_cancel(msg, hdr);
9227 nlmsg_free(msg);
9228
9229}
9230
9231void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9232 struct net_device *netdev, const u8 *bssid,
9233 const u8 *req_ie, size_t req_ie_len,
9234 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9235{
9236 struct sk_buff *msg;
9237 void *hdr;
9238
Thomas Graf58050fc2012-06-28 03:57:45 +00009239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009240 if (!msg)
9241 return;
9242
9243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9244 if (!hdr) {
9245 nlmsg_free(msg);
9246 return;
9247 }
9248
David S. Miller9360ffd2012-03-29 04:41:26 -04009249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9250 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9251 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9252 (req_ie &&
9253 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9254 (resp_ie &&
9255 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9256 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009257
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009258 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009259
Johannes Berg463d0182009-07-14 00:33:35 +02009260 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9261 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009262 return;
9263
9264 nla_put_failure:
9265 genlmsg_cancel(msg, hdr);
9266 nlmsg_free(msg);
9267
9268}
9269
9270void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9271 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009272 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009273{
9274 struct sk_buff *msg;
9275 void *hdr;
9276
Thomas Graf58050fc2012-06-28 03:57:45 +00009277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009278 if (!msg)
9279 return;
9280
9281 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9282 if (!hdr) {
9283 nlmsg_free(msg);
9284 return;
9285 }
9286
David S. Miller9360ffd2012-03-29 04:41:26 -04009287 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9288 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9289 (from_ap && reason &&
9290 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9291 (from_ap &&
9292 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9293 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9294 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009295
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009296 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009297
Johannes Berg463d0182009-07-14 00:33:35 +02009298 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9299 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009300 return;
9301
9302 nla_put_failure:
9303 genlmsg_cancel(msg, hdr);
9304 nlmsg_free(msg);
9305
9306}
9307
Johannes Berg04a773a2009-04-19 21:24:32 +02009308void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9309 struct net_device *netdev, const u8 *bssid,
9310 gfp_t gfp)
9311{
9312 struct sk_buff *msg;
9313 void *hdr;
9314
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009315 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009316 if (!msg)
9317 return;
9318
9319 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9320 if (!hdr) {
9321 nlmsg_free(msg);
9322 return;
9323 }
9324
David S. Miller9360ffd2012-03-29 04:41:26 -04009325 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9326 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9327 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9328 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009329
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009330 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009331
Johannes Berg463d0182009-07-14 00:33:35 +02009332 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9333 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009334 return;
9335
9336 nla_put_failure:
9337 genlmsg_cancel(msg, hdr);
9338 nlmsg_free(msg);
9339}
9340
Javier Cardonac93b5e72011-04-07 15:08:34 -07009341void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
9342 struct net_device *netdev,
9343 const u8 *macaddr, const u8* ie, u8 ie_len,
9344 gfp_t gfp)
9345{
9346 struct sk_buff *msg;
9347 void *hdr;
9348
9349 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9350 if (!msg)
9351 return;
9352
9353 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9354 if (!hdr) {
9355 nlmsg_free(msg);
9356 return;
9357 }
9358
David S. Miller9360ffd2012-03-29 04:41:26 -04009359 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9360 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9361 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
9362 (ie_len && ie &&
9363 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9364 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009365
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009366 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009367
9368 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9369 nl80211_mlme_mcgrp.id, gfp);
9370 return;
9371
9372 nla_put_failure:
9373 genlmsg_cancel(msg, hdr);
9374 nlmsg_free(msg);
9375}
9376
Jouni Malinena3b8b052009-03-27 21:59:49 +02009377void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9378 struct net_device *netdev, const u8 *addr,
9379 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009380 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009381{
9382 struct sk_buff *msg;
9383 void *hdr;
9384
Johannes Berge6d6e342009-07-01 21:26:47 +02009385 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009386 if (!msg)
9387 return;
9388
9389 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9390 if (!hdr) {
9391 nlmsg_free(msg);
9392 return;
9393 }
9394
David S. Miller9360ffd2012-03-29 04:41:26 -04009395 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9396 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9397 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9398 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9399 (key_id != -1 &&
9400 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9401 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9402 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009403
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009404 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009405
Johannes Berg463d0182009-07-14 00:33:35 +02009406 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9407 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009408 return;
9409
9410 nla_put_failure:
9411 genlmsg_cancel(msg, hdr);
9412 nlmsg_free(msg);
9413}
9414
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009415void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9416 struct ieee80211_channel *channel_before,
9417 struct ieee80211_channel *channel_after)
9418{
9419 struct sk_buff *msg;
9420 void *hdr;
9421 struct nlattr *nl_freq;
9422
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009423 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009424 if (!msg)
9425 return;
9426
9427 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9428 if (!hdr) {
9429 nlmsg_free(msg);
9430 return;
9431 }
9432
9433 /*
9434 * Since we are applying the beacon hint to a wiphy we know its
9435 * wiphy_idx is valid
9436 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009437 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9438 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009439
9440 /* Before */
9441 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9442 if (!nl_freq)
9443 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009444 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009445 goto nla_put_failure;
9446 nla_nest_end(msg, nl_freq);
9447
9448 /* After */
9449 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9450 if (!nl_freq)
9451 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009452 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009453 goto nla_put_failure;
9454 nla_nest_end(msg, nl_freq);
9455
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009456 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009457
Johannes Berg463d0182009-07-14 00:33:35 +02009458 rcu_read_lock();
9459 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9460 GFP_ATOMIC);
9461 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009462
9463 return;
9464
9465nla_put_failure:
9466 genlmsg_cancel(msg, hdr);
9467 nlmsg_free(msg);
9468}
9469
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009470static void nl80211_send_remain_on_chan_event(
9471 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009472 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009473 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009474 unsigned int duration, gfp_t gfp)
9475{
9476 struct sk_buff *msg;
9477 void *hdr;
9478
9479 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9480 if (!msg)
9481 return;
9482
9483 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9484 if (!hdr) {
9485 nlmsg_free(msg);
9486 return;
9487 }
9488
David S. Miller9360ffd2012-03-29 04:41:26 -04009489 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009490 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9491 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009492 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009493 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009494 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9495 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009496 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9497 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009498
David S. Miller9360ffd2012-03-29 04:41:26 -04009499 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9500 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9501 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009502
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009503 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009504
9505 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9506 nl80211_mlme_mcgrp.id, gfp);
9507 return;
9508
9509 nla_put_failure:
9510 genlmsg_cancel(msg, hdr);
9511 nlmsg_free(msg);
9512}
9513
9514void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009515 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009516 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009517 unsigned int duration, gfp_t gfp)
9518{
9519 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009520 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009521 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009522}
9523
9524void nl80211_send_remain_on_channel_cancel(
Johannes Berg71bbc992012-06-15 15:30:18 +02009525 struct cfg80211_registered_device *rdev,
9526 struct wireless_dev *wdev,
Johannes Berg42d97a52012-11-08 18:31:02 +01009527 u64 cookie, struct ieee80211_channel *chan, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009528{
9529 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009530 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009531}
9532
Johannes Berg98b62182009-12-23 13:15:44 +01009533void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
9534 struct net_device *dev, const u8 *mac_addr,
9535 struct station_info *sinfo, gfp_t gfp)
9536{
9537 struct sk_buff *msg;
9538
Thomas Graf58050fc2012-06-28 03:57:45 +00009539 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009540 if (!msg)
9541 return;
9542
John W. Linville66266b32012-03-15 13:25:41 -04009543 if (nl80211_send_station(msg, 0, 0, 0,
9544 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009545 nlmsg_free(msg);
9546 return;
9547 }
9548
9549 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9550 nl80211_mlme_mcgrp.id, gfp);
9551}
9552
Jouni Malinenec15e682011-03-23 15:29:52 +02009553void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
9554 struct net_device *dev, const u8 *mac_addr,
9555 gfp_t gfp)
9556{
9557 struct sk_buff *msg;
9558 void *hdr;
9559
Thomas Graf58050fc2012-06-28 03:57:45 +00009560 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009561 if (!msg)
9562 return;
9563
9564 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9565 if (!hdr) {
9566 nlmsg_free(msg);
9567 return;
9568 }
9569
David S. Miller9360ffd2012-03-29 04:41:26 -04009570 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9571 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9572 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009573
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009574 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009575
9576 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9577 nl80211_mlme_mcgrp.id, gfp);
9578 return;
9579
9580 nla_put_failure:
9581 genlmsg_cancel(msg, hdr);
9582 nlmsg_free(msg);
9583}
9584
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309585void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
9586 struct net_device *dev, const u8 *mac_addr,
9587 enum nl80211_connect_failed_reason reason,
9588 gfp_t gfp)
9589{
9590 struct sk_buff *msg;
9591 void *hdr;
9592
9593 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9594 if (!msg)
9595 return;
9596
9597 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9598 if (!hdr) {
9599 nlmsg_free(msg);
9600 return;
9601 }
9602
9603 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9604 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9605 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9606 goto nla_put_failure;
9607
9608 genlmsg_end(msg, hdr);
9609
9610 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9611 nl80211_mlme_mcgrp.id, gfp);
9612 return;
9613
9614 nla_put_failure:
9615 genlmsg_cancel(msg, hdr);
9616 nlmsg_free(msg);
9617}
9618
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009619static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9620 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009621{
9622 struct wireless_dev *wdev = dev->ieee80211_ptr;
9623 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9624 struct sk_buff *msg;
9625 void *hdr;
9626 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009627 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009628
Eric W. Biederman15e47302012-09-07 20:12:54 +00009629 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009630 return false;
9631
9632 msg = nlmsg_new(100, gfp);
9633 if (!msg)
9634 return true;
9635
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009636 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009637 if (!hdr) {
9638 nlmsg_free(msg);
9639 return true;
9640 }
9641
David S. Miller9360ffd2012-03-29 04:41:26 -04009642 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9643 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9644 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9645 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009646
9647 err = genlmsg_end(msg, hdr);
9648 if (err < 0) {
9649 nlmsg_free(msg);
9650 return true;
9651 }
9652
Eric W. Biederman15e47302012-09-07 20:12:54 +00009653 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009654 return true;
9655
9656 nla_put_failure:
9657 genlmsg_cancel(msg, hdr);
9658 nlmsg_free(msg);
9659 return true;
9660}
9661
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009662bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
9663{
9664 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9665 addr, gfp);
9666}
9667
9668bool nl80211_unexpected_4addr_frame(struct net_device *dev,
9669 const u8 *addr, gfp_t gfp)
9670{
9671 return __nl80211_unexpected_frame(dev,
9672 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9673 addr, gfp);
9674}
9675
Johannes Berg2e161f72010-08-12 15:38:38 +02009676int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009677 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009678 int freq, int sig_dbm,
9679 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009680{
Johannes Berg71bbc992012-06-15 15:30:18 +02009681 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009682 struct sk_buff *msg;
9683 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009684
9685 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9686 if (!msg)
9687 return -ENOMEM;
9688
Johannes Berg2e161f72010-08-12 15:38:38 +02009689 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009690 if (!hdr) {
9691 nlmsg_free(msg);
9692 return -ENOMEM;
9693 }
9694
David S. Miller9360ffd2012-03-29 04:41:26 -04009695 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009696 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9697 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009698 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9699 (sig_dbm &&
9700 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9701 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9702 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009703
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009704 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009705
Eric W. Biederman15e47302012-09-07 20:12:54 +00009706 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009707
9708 nla_put_failure:
9709 genlmsg_cancel(msg, hdr);
9710 nlmsg_free(msg);
9711 return -ENOBUFS;
9712}
9713
Johannes Berg2e161f72010-08-12 15:38:38 +02009714void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009715 struct wireless_dev *wdev, u64 cookie,
Johannes Berg2e161f72010-08-12 15:38:38 +02009716 const u8 *buf, size_t len, bool ack,
9717 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009718{
Johannes Berg71bbc992012-06-15 15:30:18 +02009719 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009720 struct sk_buff *msg;
9721 void *hdr;
9722
9723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9724 if (!msg)
9725 return;
9726
Johannes Berg2e161f72010-08-12 15:38:38 +02009727 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009728 if (!hdr) {
9729 nlmsg_free(msg);
9730 return;
9731 }
9732
David S. Miller9360ffd2012-03-29 04:41:26 -04009733 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009734 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9735 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009736 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9737 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9738 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9739 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009740
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009741 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009742
9743 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9744 return;
9745
9746 nla_put_failure:
9747 genlmsg_cancel(msg, hdr);
9748 nlmsg_free(msg);
9749}
9750
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009751void
9752nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
9753 struct net_device *netdev,
9754 enum nl80211_cqm_rssi_threshold_event rssi_event,
9755 gfp_t gfp)
9756{
9757 struct sk_buff *msg;
9758 struct nlattr *pinfoattr;
9759 void *hdr;
9760
Thomas Graf58050fc2012-06-28 03:57:45 +00009761 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009762 if (!msg)
9763 return;
9764
9765 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9766 if (!hdr) {
9767 nlmsg_free(msg);
9768 return;
9769 }
9770
David S. Miller9360ffd2012-03-29 04:41:26 -04009771 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9772 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9773 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009774
9775 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9776 if (!pinfoattr)
9777 goto nla_put_failure;
9778
David S. Miller9360ffd2012-03-29 04:41:26 -04009779 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9780 rssi_event))
9781 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009782
9783 nla_nest_end(msg, pinfoattr);
9784
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009785 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009786
9787 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9788 nl80211_mlme_mcgrp.id, gfp);
9789 return;
9790
9791 nla_put_failure:
9792 genlmsg_cancel(msg, hdr);
9793 nlmsg_free(msg);
9794}
9795
Johannes Berge5497d72011-07-05 16:35:40 +02009796void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9797 struct net_device *netdev, const u8 *bssid,
9798 const u8 *replay_ctr, gfp_t gfp)
9799{
9800 struct sk_buff *msg;
9801 struct nlattr *rekey_attr;
9802 void *hdr;
9803
Thomas Graf58050fc2012-06-28 03:57:45 +00009804 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009805 if (!msg)
9806 return;
9807
9808 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9809 if (!hdr) {
9810 nlmsg_free(msg);
9811 return;
9812 }
9813
David S. Miller9360ffd2012-03-29 04:41:26 -04009814 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9815 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9816 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9817 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009818
9819 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9820 if (!rekey_attr)
9821 goto nla_put_failure;
9822
David S. Miller9360ffd2012-03-29 04:41:26 -04009823 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9824 NL80211_REPLAY_CTR_LEN, replay_ctr))
9825 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009826
9827 nla_nest_end(msg, rekey_attr);
9828
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009829 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02009830
9831 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9832 nl80211_mlme_mcgrp.id, gfp);
9833 return;
9834
9835 nla_put_failure:
9836 genlmsg_cancel(msg, hdr);
9837 nlmsg_free(msg);
9838}
9839
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009840void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
9841 struct net_device *netdev, int index,
9842 const u8 *bssid, bool preauth, gfp_t gfp)
9843{
9844 struct sk_buff *msg;
9845 struct nlattr *attr;
9846 void *hdr;
9847
Thomas Graf58050fc2012-06-28 03:57:45 +00009848 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009849 if (!msg)
9850 return;
9851
9852 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
9853 if (!hdr) {
9854 nlmsg_free(msg);
9855 return;
9856 }
9857
David S. Miller9360ffd2012-03-29 04:41:26 -04009858 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9859 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9860 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009861
9862 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
9863 if (!attr)
9864 goto nla_put_failure;
9865
David S. Miller9360ffd2012-03-29 04:41:26 -04009866 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
9867 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
9868 (preauth &&
9869 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
9870 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009871
9872 nla_nest_end(msg, attr);
9873
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009874 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009875
9876 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9877 nl80211_mlme_mcgrp.id, gfp);
9878 return;
9879
9880 nla_put_failure:
9881 genlmsg_cancel(msg, hdr);
9882 nlmsg_free(msg);
9883}
9884
Thomas Pedersen53145262012-04-06 13:35:47 -07009885void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
Johannes Berg683b6d32012-11-08 21:25:48 +01009886 struct net_device *netdev,
9887 struct cfg80211_chan_def *chandef, gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -07009888{
9889 struct sk_buff *msg;
9890 void *hdr;
9891
Thomas Graf58050fc2012-06-28 03:57:45 +00009892 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -07009893 if (!msg)
9894 return;
9895
9896 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
9897 if (!hdr) {
9898 nlmsg_free(msg);
9899 return;
9900 }
9901
Johannes Berg683b6d32012-11-08 21:25:48 +01009902 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9903 goto nla_put_failure;
9904
9905 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -04009906 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07009907
9908 genlmsg_end(msg, hdr);
9909
9910 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9911 nl80211_mlme_mcgrp.id, gfp);
9912 return;
9913
9914 nla_put_failure:
9915 genlmsg_cancel(msg, hdr);
9916 nlmsg_free(msg);
9917}
9918
Johannes Bergc063dbf2010-11-24 08:10:05 +01009919void
Thomas Pedersen84f10702012-07-12 16:17:33 -07009920nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
9921 struct net_device *netdev, const u8 *peer,
9922 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
9923{
9924 struct sk_buff *msg;
9925 struct nlattr *pinfoattr;
9926 void *hdr;
9927
9928 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9929 if (!msg)
9930 return;
9931
9932 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9933 if (!hdr) {
9934 nlmsg_free(msg);
9935 return;
9936 }
9937
9938 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9939 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9940 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9941 goto nla_put_failure;
9942
9943 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9944 if (!pinfoattr)
9945 goto nla_put_failure;
9946
9947 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
9948 goto nla_put_failure;
9949
9950 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
9951 goto nla_put_failure;
9952
9953 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
9954 goto nla_put_failure;
9955
9956 nla_nest_end(msg, pinfoattr);
9957
9958 genlmsg_end(msg, hdr);
9959
9960 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9961 nl80211_mlme_mcgrp.id, gfp);
9962 return;
9963
9964 nla_put_failure:
9965 genlmsg_cancel(msg, hdr);
9966 nlmsg_free(msg);
9967}
9968
9969void
Simon Wunderlich04f39042013-02-08 18:16:19 +01009970nl80211_radar_notify(struct cfg80211_registered_device *rdev,
9971 struct cfg80211_chan_def *chandef,
9972 enum nl80211_radar_event event,
9973 struct net_device *netdev, gfp_t gfp)
9974{
9975 struct sk_buff *msg;
9976 void *hdr;
9977
9978 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9979 if (!msg)
9980 return;
9981
9982 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
9983 if (!hdr) {
9984 nlmsg_free(msg);
9985 return;
9986 }
9987
9988 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9989 goto nla_put_failure;
9990
9991 /* NOP and radar events don't need a netdev parameter */
9992 if (netdev) {
9993 struct wireless_dev *wdev = netdev->ieee80211_ptr;
9994
9995 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9996 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9997 goto nla_put_failure;
9998 }
9999
10000 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10001 goto nla_put_failure;
10002
10003 if (nl80211_send_chandef(msg, chandef))
10004 goto nla_put_failure;
10005
10006 if (genlmsg_end(msg, hdr) < 0) {
10007 nlmsg_free(msg);
10008 return;
10009 }
10010
10011 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10012 nl80211_mlme_mcgrp.id, gfp);
10013 return;
10014
10015 nla_put_failure:
10016 genlmsg_cancel(msg, hdr);
10017 nlmsg_free(msg);
10018}
10019
10020void
Johannes Bergc063dbf2010-11-24 08:10:05 +010010021nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
10022 struct net_device *netdev, const u8 *peer,
10023 u32 num_packets, gfp_t gfp)
10024{
10025 struct sk_buff *msg;
10026 struct nlattr *pinfoattr;
10027 void *hdr;
10028
Thomas Graf58050fc2012-06-28 03:57:45 +000010029 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010030 if (!msg)
10031 return;
10032
10033 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10034 if (!hdr) {
10035 nlmsg_free(msg);
10036 return;
10037 }
10038
David S. Miller9360ffd2012-03-29 04:41:26 -040010039 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10040 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10041 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10042 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010043
10044 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10045 if (!pinfoattr)
10046 goto nla_put_failure;
10047
David S. Miller9360ffd2012-03-29 04:41:26 -040010048 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10049 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010050
10051 nla_nest_end(msg, pinfoattr);
10052
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010053 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010054
10055 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10056 nl80211_mlme_mcgrp.id, gfp);
10057 return;
10058
10059 nla_put_failure:
10060 genlmsg_cancel(msg, hdr);
10061 nlmsg_free(msg);
10062}
10063
Johannes Berg7f6cf312011-11-04 11:18:15 +010010064void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10065 u64 cookie, bool acked, gfp_t gfp)
10066{
10067 struct wireless_dev *wdev = dev->ieee80211_ptr;
10068 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10069 struct sk_buff *msg;
10070 void *hdr;
10071 int err;
10072
Beni Lev4ee3e062012-08-27 12:49:39 +030010073 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10074
Thomas Graf58050fc2012-06-28 03:57:45 +000010075 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010076
Johannes Berg7f6cf312011-11-04 11:18:15 +010010077 if (!msg)
10078 return;
10079
10080 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10081 if (!hdr) {
10082 nlmsg_free(msg);
10083 return;
10084 }
10085
David S. Miller9360ffd2012-03-29 04:41:26 -040010086 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10087 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10088 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10089 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10090 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10091 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010092
10093 err = genlmsg_end(msg, hdr);
10094 if (err < 0) {
10095 nlmsg_free(msg);
10096 return;
10097 }
10098
10099 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10100 nl80211_mlme_mcgrp.id, gfp);
10101 return;
10102
10103 nla_put_failure:
10104 genlmsg_cancel(msg, hdr);
10105 nlmsg_free(msg);
10106}
10107EXPORT_SYMBOL(cfg80211_probe_status);
10108
Johannes Berg5e7602302011-11-04 11:18:17 +010010109void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10110 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010111 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010112{
10113 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10114 struct sk_buff *msg;
10115 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010116 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010117
Beni Lev4ee3e062012-08-27 12:49:39 +030010118 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10119
Ben Greear37c73b52012-10-26 14:49:25 -070010120 spin_lock_bh(&rdev->beacon_registrations_lock);
10121 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10122 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10123 if (!msg) {
10124 spin_unlock_bh(&rdev->beacon_registrations_lock);
10125 return;
10126 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010127
Ben Greear37c73b52012-10-26 14:49:25 -070010128 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10129 if (!hdr)
10130 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010131
Ben Greear37c73b52012-10-26 14:49:25 -070010132 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10133 (freq &&
10134 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10135 (sig_dbm &&
10136 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10137 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10138 goto nla_put_failure;
10139
10140 genlmsg_end(msg, hdr);
10141
10142 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010143 }
Ben Greear37c73b52012-10-26 14:49:25 -070010144 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010145 return;
10146
10147 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010148 spin_unlock_bh(&rdev->beacon_registrations_lock);
10149 if (hdr)
10150 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010010151 nlmsg_free(msg);
10152}
10153EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10154
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010155#ifdef CONFIG_PM
10156void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10157 struct cfg80211_wowlan_wakeup *wakeup,
10158 gfp_t gfp)
10159{
10160 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10161 struct sk_buff *msg;
10162 void *hdr;
10163 int err, size = 200;
10164
10165 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10166
10167 if (wakeup)
10168 size += wakeup->packet_present_len;
10169
10170 msg = nlmsg_new(size, gfp);
10171 if (!msg)
10172 return;
10173
10174 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10175 if (!hdr)
10176 goto free_msg;
10177
10178 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10179 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10180 goto free_msg;
10181
10182 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10183 wdev->netdev->ifindex))
10184 goto free_msg;
10185
10186 if (wakeup) {
10187 struct nlattr *reasons;
10188
10189 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10190
10191 if (wakeup->disconnect &&
10192 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10193 goto free_msg;
10194 if (wakeup->magic_pkt &&
10195 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10196 goto free_msg;
10197 if (wakeup->gtk_rekey_failure &&
10198 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10199 goto free_msg;
10200 if (wakeup->eap_identity_req &&
10201 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10202 goto free_msg;
10203 if (wakeup->four_way_handshake &&
10204 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10205 goto free_msg;
10206 if (wakeup->rfkill_release &&
10207 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10208 goto free_msg;
10209
10210 if (wakeup->pattern_idx >= 0 &&
10211 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10212 wakeup->pattern_idx))
10213 goto free_msg;
10214
Johannes Berg2a0e0472013-01-23 22:57:40 +010010215 if (wakeup->tcp_match)
10216 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10217
10218 if (wakeup->tcp_connlost)
10219 nla_put_flag(msg,
10220 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10221
10222 if (wakeup->tcp_nomoretokens)
10223 nla_put_flag(msg,
10224 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10225
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010226 if (wakeup->packet) {
10227 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10228 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10229
10230 if (!wakeup->packet_80211) {
10231 pkt_attr =
10232 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10233 len_attr =
10234 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10235 }
10236
10237 if (wakeup->packet_len &&
10238 nla_put_u32(msg, len_attr, wakeup->packet_len))
10239 goto free_msg;
10240
10241 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10242 wakeup->packet))
10243 goto free_msg;
10244 }
10245
10246 nla_nest_end(msg, reasons);
10247 }
10248
10249 err = genlmsg_end(msg, hdr);
10250 if (err < 0)
10251 goto free_msg;
10252
10253 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10254 nl80211_mlme_mcgrp.id, gfp);
10255 return;
10256
10257 free_msg:
10258 nlmsg_free(msg);
10259}
10260EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10261#endif
10262
Jouni Malinen3475b092012-11-16 22:49:57 +020010263void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10264 enum nl80211_tdls_operation oper,
10265 u16 reason_code, gfp_t gfp)
10266{
10267 struct wireless_dev *wdev = dev->ieee80211_ptr;
10268 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10269 struct sk_buff *msg;
10270 void *hdr;
10271 int err;
10272
10273 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10274 reason_code);
10275
10276 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10277 if (!msg)
10278 return;
10279
10280 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10281 if (!hdr) {
10282 nlmsg_free(msg);
10283 return;
10284 }
10285
10286 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10287 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10288 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10289 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10290 (reason_code > 0 &&
10291 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10292 goto nla_put_failure;
10293
10294 err = genlmsg_end(msg, hdr);
10295 if (err < 0) {
10296 nlmsg_free(msg);
10297 return;
10298 }
10299
10300 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10301 nl80211_mlme_mcgrp.id, gfp);
10302 return;
10303
10304 nla_put_failure:
10305 genlmsg_cancel(msg, hdr);
10306 nlmsg_free(msg);
10307}
10308EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10309
Jouni Malinen026331c2010-02-15 12:53:10 +020010310static int nl80211_netlink_notify(struct notifier_block * nb,
10311 unsigned long state,
10312 void *_notify)
10313{
10314 struct netlink_notify *notify = _notify;
10315 struct cfg80211_registered_device *rdev;
10316 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010317 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010318
10319 if (state != NETLINK_URELEASE)
10320 return NOTIFY_DONE;
10321
10322 rcu_read_lock();
10323
Johannes Berg5e7602302011-11-04 11:18:17 +010010324 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010325 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010326 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010327
10328 spin_lock_bh(&rdev->beacon_registrations_lock);
10329 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10330 list) {
10331 if (reg->nlportid == notify->portid) {
10332 list_del(&reg->list);
10333 kfree(reg);
10334 break;
10335 }
10336 }
10337 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010338 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010339
10340 rcu_read_unlock();
10341
10342 return NOTIFY_DONE;
10343}
10344
10345static struct notifier_block nl80211_netlink_notifier = {
10346 .notifier_call = nl80211_netlink_notify,
10347};
10348
Johannes Berg55682962007-09-20 13:09:35 -040010349/* initialisation/exit functions */
10350
10351int nl80211_init(void)
10352{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010353 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010354
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010355 err = genl_register_family_with_ops(&nl80211_fam,
10356 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010357 if (err)
10358 return err;
10359
Johannes Berg55682962007-09-20 13:09:35 -040010360 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10361 if (err)
10362 goto err_out;
10363
Johannes Berg2a519312009-02-10 21:25:55 +010010364 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10365 if (err)
10366 goto err_out;
10367
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010368 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10369 if (err)
10370 goto err_out;
10371
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010372 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10373 if (err)
10374 goto err_out;
10375
Johannes Bergaff89a92009-07-01 21:26:51 +020010376#ifdef CONFIG_NL80211_TESTMODE
10377 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10378 if (err)
10379 goto err_out;
10380#endif
10381
Jouni Malinen026331c2010-02-15 12:53:10 +020010382 err = netlink_register_notifier(&nl80211_netlink_notifier);
10383 if (err)
10384 goto err_out;
10385
Johannes Berg55682962007-09-20 13:09:35 -040010386 return 0;
10387 err_out:
10388 genl_unregister_family(&nl80211_fam);
10389 return err;
10390}
10391
10392void nl80211_exit(void)
10393{
Jouni Malinen026331c2010-02-15 12:53:10 +020010394 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010395 genl_unregister_family(&nl80211_fam);
10396}