blob: 0e5176784b42137152dd0d4961fe4dc41ad62945 [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
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100576 if (large) {
577 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
578 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
579 goto nla_put_failure;
580 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
581 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
582 goto nla_put_failure;
583 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
584 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
585 goto nla_put_failure;
586 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
587 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
588 goto nla_put_failure;
589 }
590
David S. Miller9360ffd2012-03-29 04:41:26 -0400591 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
592 DBM_TO_MBM(chan->max_power)))
593 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400594
595 return 0;
596
597 nla_put_failure:
598 return -ENOBUFS;
599}
600
Johannes Berg55682962007-09-20 13:09:35 -0400601/* netlink command implementations */
602
Johannes Bergb9454e82009-07-08 13:29:08 +0200603struct key_parse {
604 struct key_params p;
605 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200606 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200607 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100608 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200609};
610
611static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
612{
613 struct nlattr *tb[NL80211_KEY_MAX + 1];
614 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
615 nl80211_key_policy);
616 if (err)
617 return err;
618
619 k->def = !!tb[NL80211_KEY_DEFAULT];
620 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
621
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100622 if (k->def) {
623 k->def_uni = true;
624 k->def_multi = true;
625 }
626 if (k->defmgmt)
627 k->def_multi = true;
628
Johannes Bergb9454e82009-07-08 13:29:08 +0200629 if (tb[NL80211_KEY_IDX])
630 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
631
632 if (tb[NL80211_KEY_DATA]) {
633 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
634 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
635 }
636
637 if (tb[NL80211_KEY_SEQ]) {
638 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
639 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
640 }
641
642 if (tb[NL80211_KEY_CIPHER])
643 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
644
Johannes Berge31b8212010-10-05 19:39:30 +0200645 if (tb[NL80211_KEY_TYPE]) {
646 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
647 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
648 return -EINVAL;
649 }
650
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100651 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
652 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100653 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
654 tb[NL80211_KEY_DEFAULT_TYPES],
655 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100656 if (err)
657 return err;
658
659 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
660 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
661 }
662
Johannes Bergb9454e82009-07-08 13:29:08 +0200663 return 0;
664}
665
666static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
667{
668 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
669 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
670 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
671 }
672
673 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
674 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
675 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
676 }
677
678 if (info->attrs[NL80211_ATTR_KEY_IDX])
679 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
680
681 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
682 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
683
684 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
685 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
686
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100687 if (k->def) {
688 k->def_uni = true;
689 k->def_multi = true;
690 }
691 if (k->defmgmt)
692 k->def_multi = true;
693
Johannes Berge31b8212010-10-05 19:39:30 +0200694 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
695 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
696 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
697 return -EINVAL;
698 }
699
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100700 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
701 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
702 int err = nla_parse_nested(
703 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
704 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
705 nl80211_key_default_policy);
706 if (err)
707 return err;
708
709 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
710 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
711 }
712
Johannes Bergb9454e82009-07-08 13:29:08 +0200713 return 0;
714}
715
716static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
717{
718 int err;
719
720 memset(k, 0, sizeof(*k));
721 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200722 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200723
724 if (info->attrs[NL80211_ATTR_KEY])
725 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
726 else
727 err = nl80211_parse_key_old(info, k);
728
729 if (err)
730 return err;
731
732 if (k->def && k->defmgmt)
733 return -EINVAL;
734
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100735 if (k->defmgmt) {
736 if (k->def_uni || !k->def_multi)
737 return -EINVAL;
738 }
739
Johannes Bergb9454e82009-07-08 13:29:08 +0200740 if (k->idx != -1) {
741 if (k->defmgmt) {
742 if (k->idx < 4 || k->idx > 5)
743 return -EINVAL;
744 } else if (k->def) {
745 if (k->idx < 0 || k->idx > 3)
746 return -EINVAL;
747 } else {
748 if (k->idx < 0 || k->idx > 5)
749 return -EINVAL;
750 }
751 }
752
753 return 0;
754}
755
Johannes Bergfffd0932009-07-08 14:22:54 +0200756static struct cfg80211_cached_keys *
757nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530758 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200759{
760 struct key_parse parse;
761 struct nlattr *key;
762 struct cfg80211_cached_keys *result;
763 int rem, err, def = 0;
764
765 result = kzalloc(sizeof(*result), GFP_KERNEL);
766 if (!result)
767 return ERR_PTR(-ENOMEM);
768
769 result->def = -1;
770 result->defmgmt = -1;
771
772 nla_for_each_nested(key, keys, rem) {
773 memset(&parse, 0, sizeof(parse));
774 parse.idx = -1;
775
776 err = nl80211_parse_key_new(key, &parse);
777 if (err)
778 goto error;
779 err = -EINVAL;
780 if (!parse.p.key)
781 goto error;
782 if (parse.idx < 0 || parse.idx > 4)
783 goto error;
784 if (parse.def) {
785 if (def)
786 goto error;
787 def = 1;
788 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100789 if (!parse.def_uni || !parse.def_multi)
790 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200791 } else if (parse.defmgmt)
792 goto error;
793 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200794 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200795 if (err)
796 goto error;
797 result->params[parse.idx].cipher = parse.p.cipher;
798 result->params[parse.idx].key_len = parse.p.key_len;
799 result->params[parse.idx].key = result->data[parse.idx];
800 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530801
802 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
803 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
804 if (no_ht)
805 *no_ht = true;
806 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200807 }
808
809 return result;
810 error:
811 kfree(result);
812 return ERR_PTR(err);
813}
814
815static int nl80211_key_allowed(struct wireless_dev *wdev)
816{
817 ASSERT_WDEV_LOCK(wdev);
818
Johannes Bergfffd0932009-07-08 14:22:54 +0200819 switch (wdev->iftype) {
820 case NL80211_IFTYPE_AP:
821 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200822 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700823 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200824 break;
825 case NL80211_IFTYPE_ADHOC:
826 if (!wdev->current_bss)
827 return -ENOLINK;
828 break;
829 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200830 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200831 if (wdev->sme_state != CFG80211_SME_CONNECTED)
832 return -ENOLINK;
833 break;
834 default:
835 return -EINVAL;
836 }
837
838 return 0;
839}
840
Johannes Berg7527a782011-05-13 10:58:57 +0200841static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
842{
843 struct nlattr *nl_modes = nla_nest_start(msg, attr);
844 int i;
845
846 if (!nl_modes)
847 goto nla_put_failure;
848
849 i = 0;
850 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400851 if ((ifmodes & 1) && nla_put_flag(msg, i))
852 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200853 ifmodes >>= 1;
854 i++;
855 }
856
857 nla_nest_end(msg, nl_modes);
858 return 0;
859
860nla_put_failure:
861 return -ENOBUFS;
862}
863
864static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100865 struct sk_buff *msg,
866 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200867{
868 struct nlattr *nl_combis;
869 int i, j;
870
871 nl_combis = nla_nest_start(msg,
872 NL80211_ATTR_INTERFACE_COMBINATIONS);
873 if (!nl_combis)
874 goto nla_put_failure;
875
876 for (i = 0; i < wiphy->n_iface_combinations; i++) {
877 const struct ieee80211_iface_combination *c;
878 struct nlattr *nl_combi, *nl_limits;
879
880 c = &wiphy->iface_combinations[i];
881
882 nl_combi = nla_nest_start(msg, i + 1);
883 if (!nl_combi)
884 goto nla_put_failure;
885
886 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
887 if (!nl_limits)
888 goto nla_put_failure;
889
890 for (j = 0; j < c->n_limits; j++) {
891 struct nlattr *nl_limit;
892
893 nl_limit = nla_nest_start(msg, j + 1);
894 if (!nl_limit)
895 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400896 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
897 c->limits[j].max))
898 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200899 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
900 c->limits[j].types))
901 goto nla_put_failure;
902 nla_nest_end(msg, nl_limit);
903 }
904
905 nla_nest_end(msg, nl_limits);
906
David S. Miller9360ffd2012-03-29 04:41:26 -0400907 if (c->beacon_int_infra_match &&
908 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
909 goto nla_put_failure;
910 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
911 c->num_different_channels) ||
912 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
913 c->max_interfaces))
914 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100915 if (large &&
916 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
917 c->radar_detect_widths))
918 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200919
920 nla_nest_end(msg, nl_combi);
921 }
922
923 nla_nest_end(msg, nl_combis);
924
925 return 0;
926nla_put_failure:
927 return -ENOBUFS;
928}
929
Johannes Berg3713b4e2013-02-14 16:19:38 +0100930#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100931static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
932 struct sk_buff *msg)
933{
934 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
935 struct nlattr *nl_tcp;
936
937 if (!tcp)
938 return 0;
939
940 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
941 if (!nl_tcp)
942 return -ENOBUFS;
943
944 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
945 tcp->data_payload_max))
946 return -ENOBUFS;
947
948 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
949 tcp->data_payload_max))
950 return -ENOBUFS;
951
952 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
953 return -ENOBUFS;
954
955 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
956 sizeof(*tcp->tok), tcp->tok))
957 return -ENOBUFS;
958
959 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
960 tcp->data_interval_max))
961 return -ENOBUFS;
962
963 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
964 tcp->wake_payload_max))
965 return -ENOBUFS;
966
967 nla_nest_end(msg, nl_tcp);
968 return 0;
969}
970
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100972 struct cfg80211_registered_device *dev,
973 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100974{
975 struct nlattr *nl_wowlan;
976
977 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
978 return 0;
979
980 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
981 if (!nl_wowlan)
982 return -ENOBUFS;
983
984 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
985 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
986 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
987 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
988 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
989 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
990 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
991 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
992 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
993 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
994 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
995 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
996 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
997 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
998 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
999 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1000 return -ENOBUFS;
1001
1002 if (dev->wiphy.wowlan.n_patterns) {
1003 struct nl80211_wowlan_pattern_support pat = {
1004 .max_patterns = dev->wiphy.wowlan.n_patterns,
1005 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
1006 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
1007 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
1008 };
1009
1010 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1011 sizeof(pat), &pat))
1012 return -ENOBUFS;
1013 }
1014
Johannes Bergb56cf722013-02-20 01:02:38 +01001015 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1016 return -ENOBUFS;
1017
Johannes Berg3713b4e2013-02-14 16:19:38 +01001018 nla_nest_end(msg, nl_wowlan);
1019
1020 return 0;
1021}
1022#endif
1023
1024static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1025 struct ieee80211_supported_band *sband)
1026{
1027 struct nlattr *nl_rates, *nl_rate;
1028 struct ieee80211_rate *rate;
1029 int i;
1030
1031 /* add HT info */
1032 if (sband->ht_cap.ht_supported &&
1033 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1034 sizeof(sband->ht_cap.mcs),
1035 &sband->ht_cap.mcs) ||
1036 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1037 sband->ht_cap.cap) ||
1038 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1039 sband->ht_cap.ampdu_factor) ||
1040 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1041 sband->ht_cap.ampdu_density)))
1042 return -ENOBUFS;
1043
1044 /* add VHT info */
1045 if (sband->vht_cap.vht_supported &&
1046 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1047 sizeof(sband->vht_cap.vht_mcs),
1048 &sband->vht_cap.vht_mcs) ||
1049 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1050 sband->vht_cap.cap)))
1051 return -ENOBUFS;
1052
1053 /* add bitrates */
1054 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1055 if (!nl_rates)
1056 return -ENOBUFS;
1057
1058 for (i = 0; i < sband->n_bitrates; i++) {
1059 nl_rate = nla_nest_start(msg, i);
1060 if (!nl_rate)
1061 return -ENOBUFS;
1062
1063 rate = &sband->bitrates[i];
1064 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1065 rate->bitrate))
1066 return -ENOBUFS;
1067 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1068 nla_put_flag(msg,
1069 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1070 return -ENOBUFS;
1071
1072 nla_nest_end(msg, nl_rate);
1073 }
1074
1075 nla_nest_end(msg, nl_rates);
1076
1077 return 0;
1078}
1079
1080static int
1081nl80211_send_mgmt_stypes(struct sk_buff *msg,
1082 const struct ieee80211_txrx_stypes *mgmt_stypes)
1083{
1084 u16 stypes;
1085 struct nlattr *nl_ftypes, *nl_ifs;
1086 enum nl80211_iftype ift;
1087 int i;
1088
1089 if (!mgmt_stypes)
1090 return 0;
1091
1092 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1093 if (!nl_ifs)
1094 return -ENOBUFS;
1095
1096 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1097 nl_ftypes = nla_nest_start(msg, ift);
1098 if (!nl_ftypes)
1099 return -ENOBUFS;
1100 i = 0;
1101 stypes = mgmt_stypes[ift].tx;
1102 while (stypes) {
1103 if ((stypes & 1) &&
1104 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1105 (i << 4) | IEEE80211_FTYPE_MGMT))
1106 return -ENOBUFS;
1107 stypes >>= 1;
1108 i++;
1109 }
1110 nla_nest_end(msg, nl_ftypes);
1111 }
1112
1113 nla_nest_end(msg, nl_ifs);
1114
1115 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1116 if (!nl_ifs)
1117 return -ENOBUFS;
1118
1119 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1120 nl_ftypes = nla_nest_start(msg, ift);
1121 if (!nl_ftypes)
1122 return -ENOBUFS;
1123 i = 0;
1124 stypes = mgmt_stypes[ift].rx;
1125 while (stypes) {
1126 if ((stypes & 1) &&
1127 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1128 (i << 4) | IEEE80211_FTYPE_MGMT))
1129 return -ENOBUFS;
1130 stypes >>= 1;
1131 i++;
1132 }
1133 nla_nest_end(msg, nl_ftypes);
1134 }
1135 nla_nest_end(msg, nl_ifs);
1136
1137 return 0;
1138}
1139
1140static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1141 struct sk_buff *msg, u32 portid, u32 seq,
1142 int flags, bool split, long *split_start,
1143 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001144{
1145 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001146 struct nlattr *nl_bands, *nl_band;
1147 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001148 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001149 enum ieee80211_band band;
1150 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001151 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001152 const struct ieee80211_txrx_stypes *mgmt_stypes =
1153 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001154 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001155 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001156
Eric W. Biederman15e47302012-09-07 20:12:54 +00001157 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001158 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001159 return -ENOBUFS;
1160
1161 /* allow always using the variables */
1162 if (!split) {
1163 split_start = &start;
1164 band_start = &start_band;
1165 chan_start = &start_chan;
1166 }
Johannes Berg55682962007-09-20 13:09:35 -04001167
David S. Miller9360ffd2012-03-29 04:41:26 -04001168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001169 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1170 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001171 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001172 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001173 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001174
Johannes Berg3713b4e2013-02-14 16:19:38 +01001175 switch (*split_start) {
1176 case 0:
1177 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1178 dev->wiphy.retry_short) ||
1179 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1180 dev->wiphy.retry_long) ||
1181 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1182 dev->wiphy.frag_threshold) ||
1183 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1184 dev->wiphy.rts_threshold) ||
1185 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1186 dev->wiphy.coverage_class) ||
1187 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1188 dev->wiphy.max_scan_ssids) ||
1189 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1190 dev->wiphy.max_sched_scan_ssids) ||
1191 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1192 dev->wiphy.max_scan_ie_len) ||
1193 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1194 dev->wiphy.max_sched_scan_ie_len) ||
1195 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1196 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001197 goto nla_put_failure;
1198
Johannes Berg3713b4e2013-02-14 16:19:38 +01001199 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1200 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1201 goto nla_put_failure;
1202 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1203 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1204 goto nla_put_failure;
1205 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1206 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1207 goto nla_put_failure;
1208 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1209 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1210 goto nla_put_failure;
1211 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1212 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1213 goto nla_put_failure;
1214 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1215 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001216 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001217
Johannes Berg3713b4e2013-02-14 16:19:38 +01001218 (*split_start)++;
1219 if (split)
1220 break;
1221 case 1:
1222 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1223 sizeof(u32) * dev->wiphy.n_cipher_suites,
1224 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001225 goto nla_put_failure;
1226
Johannes Berg3713b4e2013-02-14 16:19:38 +01001227 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1228 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001229 goto nla_put_failure;
1230
Johannes Berg3713b4e2013-02-14 16:19:38 +01001231 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1232 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1233 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001234
Johannes Berg3713b4e2013-02-14 16:19:38 +01001235 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1236 dev->wiphy.available_antennas_tx) ||
1237 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1238 dev->wiphy.available_antennas_rx))
1239 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001240
Johannes Berg3713b4e2013-02-14 16:19:38 +01001241 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1242 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1243 dev->wiphy.probe_resp_offload))
1244 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001245
Johannes Berg3713b4e2013-02-14 16:19:38 +01001246 if ((dev->wiphy.available_antennas_tx ||
1247 dev->wiphy.available_antennas_rx) &&
1248 dev->ops->get_antenna) {
1249 u32 tx_ant = 0, rx_ant = 0;
1250 int res;
1251 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1252 if (!res) {
1253 if (nla_put_u32(msg,
1254 NL80211_ATTR_WIPHY_ANTENNA_TX,
1255 tx_ant) ||
1256 nla_put_u32(msg,
1257 NL80211_ATTR_WIPHY_ANTENNA_RX,
1258 rx_ant))
1259 goto nla_put_failure;
1260 }
Johannes Bergee688b002008-01-24 19:38:39 +01001261 }
1262
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 (*split_start)++;
1264 if (split)
1265 break;
1266 case 2:
1267 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1268 dev->wiphy.interface_modes))
1269 goto nla_put_failure;
1270 (*split_start)++;
1271 if (split)
1272 break;
1273 case 3:
1274 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1275 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001276 goto nla_put_failure;
1277
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1279 struct ieee80211_supported_band *sband;
1280
1281 sband = dev->wiphy.bands[band];
1282
1283 if (!sband)
1284 continue;
1285
1286 nl_band = nla_nest_start(msg, band);
1287 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001288 goto nla_put_failure;
1289
Johannes Berg3713b4e2013-02-14 16:19:38 +01001290 switch (*chan_start) {
1291 case 0:
1292 if (nl80211_send_band_rateinfo(msg, sband))
1293 goto nla_put_failure;
1294 (*chan_start)++;
1295 if (split)
1296 break;
1297 default:
1298 /* add frequencies */
1299 nl_freqs = nla_nest_start(
1300 msg, NL80211_BAND_ATTR_FREQS);
1301 if (!nl_freqs)
1302 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001303
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 for (i = *chan_start - 1;
1305 i < sband->n_channels;
1306 i++) {
1307 nl_freq = nla_nest_start(msg, i);
1308 if (!nl_freq)
1309 goto nla_put_failure;
1310
1311 chan = &sband->channels[i];
1312
Johannes Bergcdc89b92013-02-18 23:54:36 +01001313 if (nl80211_msg_put_channel(msg, chan,
1314 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001315 goto nla_put_failure;
1316
1317 nla_nest_end(msg, nl_freq);
1318 if (split)
1319 break;
1320 }
1321 if (i < sband->n_channels)
1322 *chan_start = i + 2;
1323 else
1324 *chan_start = 0;
1325 nla_nest_end(msg, nl_freqs);
1326 }
1327
1328 nla_nest_end(msg, nl_band);
1329
1330 if (split) {
1331 /* start again here */
1332 if (*chan_start)
1333 band--;
1334 break;
1335 }
Johannes Bergee688b002008-01-24 19:38:39 +01001336 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001338
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 if (band < IEEE80211_NUM_BANDS)
1340 *band_start = band + 1;
1341 else
1342 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001343
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 /* if bands & channels are done, continue outside */
1345 if (*band_start == 0 && *chan_start == 0)
1346 (*split_start)++;
1347 if (split)
1348 break;
1349 case 4:
1350 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1351 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001352 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353
1354 i = 0;
1355#define CMD(op, n) \
1356 do { \
1357 if (dev->ops->op) { \
1358 i++; \
1359 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1360 goto nla_put_failure; \
1361 } \
1362 } while (0)
1363
1364 CMD(add_virtual_intf, NEW_INTERFACE);
1365 CMD(change_virtual_intf, SET_INTERFACE);
1366 CMD(add_key, NEW_KEY);
1367 CMD(start_ap, START_AP);
1368 CMD(add_station, NEW_STATION);
1369 CMD(add_mpath, NEW_MPATH);
1370 CMD(update_mesh_config, SET_MESH_CONFIG);
1371 CMD(change_bss, SET_BSS);
1372 CMD(auth, AUTHENTICATE);
1373 CMD(assoc, ASSOCIATE);
1374 CMD(deauth, DEAUTHENTICATE);
1375 CMD(disassoc, DISASSOCIATE);
1376 CMD(join_ibss, JOIN_IBSS);
1377 CMD(join_mesh, JOIN_MESH);
1378 CMD(set_pmksa, SET_PMKSA);
1379 CMD(del_pmksa, DEL_PMKSA);
1380 CMD(flush_pmksa, FLUSH_PMKSA);
1381 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1382 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1383 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1384 CMD(mgmt_tx, FRAME);
1385 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1386 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1387 i++;
1388 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1389 goto nla_put_failure;
1390 }
1391 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1392 dev->ops->join_mesh) {
1393 i++;
1394 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1395 goto nla_put_failure;
1396 }
1397 CMD(set_wds_peer, SET_WDS_PEER);
1398 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1399 CMD(tdls_mgmt, TDLS_MGMT);
1400 CMD(tdls_oper, TDLS_OPER);
1401 }
1402 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1403 CMD(sched_scan_start, START_SCHED_SCAN);
1404 CMD(probe_client, PROBE_CLIENT);
1405 CMD(set_noack_map, SET_NOACK_MAP);
1406 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1407 i++;
1408 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1409 goto nla_put_failure;
1410 }
1411 CMD(start_p2p_device, START_P2P_DEVICE);
1412 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001413
Kalle Valo4745fc02011-11-17 19:06:10 +02001414#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001415 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001416#endif
1417
Johannes Berg8fdc6212009-03-14 09:34:01 +01001418#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001419
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 if (dev->ops->connect || dev->ops->auth) {
1421 i++;
1422 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001423 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001424 }
1425
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 if (dev->ops->disconnect || dev->ops->deauth) {
1427 i++;
1428 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1429 goto nla_put_failure;
1430 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001431
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 nla_nest_end(msg, nl_cmds);
1433 (*split_start)++;
1434 if (split)
1435 break;
1436 case 5:
1437 if (dev->ops->remain_on_channel &&
1438 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1439 nla_put_u32(msg,
1440 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1441 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001442 goto nla_put_failure;
1443
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1445 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1446 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001447
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1449 goto nla_put_failure;
1450 (*split_start)++;
1451 if (split)
1452 break;
1453 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001454#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001455 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001456 goto nla_put_failure;
1457 (*split_start)++;
1458 if (split)
1459 break;
1460#else
1461 (*split_start)++;
1462#endif
1463 case 7:
1464 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1465 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001466 goto nla_put_failure;
1467
Johannes Bergcdc89b92013-02-18 23:54:36 +01001468 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001470
Johannes Berg3713b4e2013-02-14 16:19:38 +01001471 (*split_start)++;
1472 if (split)
1473 break;
1474 case 8:
1475 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1476 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1477 dev->wiphy.ap_sme_capa))
1478 goto nla_put_failure;
1479
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001480 features = dev->wiphy.features;
1481 /*
1482 * We can only add the per-channel limit information if the
1483 * dump is split, otherwise it makes it too big. Therefore
1484 * only advertise it in that case.
1485 */
1486 if (split)
1487 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1488 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001489 goto nla_put_failure;
1490
1491 if (dev->wiphy.ht_capa_mod_mask &&
1492 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1493 sizeof(*dev->wiphy.ht_capa_mod_mask),
1494 dev->wiphy.ht_capa_mod_mask))
1495 goto nla_put_failure;
1496
1497 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1498 dev->wiphy.max_acl_mac_addrs &&
1499 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1500 dev->wiphy.max_acl_mac_addrs))
1501 goto nla_put_failure;
1502
1503 /*
1504 * Any information below this point is only available to
1505 * applications that can deal with it being split. This
1506 * helps ensure that newly added capabilities don't break
1507 * older tools by overrunning their buffers.
1508 *
1509 * We still increment split_start so that in the split
1510 * case we'll continue with more data in the next round,
1511 * but break unconditionally so unsplit data stops here.
1512 */
1513 (*split_start)++;
1514 break;
1515 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001516 if (dev->wiphy.extended_capabilities &&
1517 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1518 dev->wiphy.extended_capabilities_len,
1519 dev->wiphy.extended_capabilities) ||
1520 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1521 dev->wiphy.extended_capabilities_len,
1522 dev->wiphy.extended_capabilities_mask)))
1523 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524
1525 /* done */
1526 *split_start = 0;
1527 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001528 }
Johannes Berg55682962007-09-20 13:09:35 -04001529 return genlmsg_end(msg, hdr);
1530
1531 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001532 genlmsg_cancel(msg, hdr);
1533 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001534}
1535
1536static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1537{
Johannes Berg645e77d2013-03-01 14:03:49 +01001538 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001539 int start = cb->args[0];
1540 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 s64 filter_wiphy = -1;
1542 bool split = false;
1543 struct nlattr **tb = nl80211_fam.attrbuf;
1544 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001545
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001546 mutex_lock(&cfg80211_mutex);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1548 tb, nl80211_fam.maxattr, nl80211_policy);
1549 if (res == 0) {
1550 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1551 if (tb[NL80211_ATTR_WIPHY])
1552 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1553 if (tb[NL80211_ATTR_WDEV])
1554 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1555 if (tb[NL80211_ATTR_IFINDEX]) {
1556 struct net_device *netdev;
1557 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1558
1559 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1560 if (!netdev) {
1561 mutex_unlock(&cfg80211_mutex);
1562 return -ENODEV;
1563 }
1564 if (netdev->ieee80211_ptr) {
1565 dev = wiphy_to_dev(
1566 netdev->ieee80211_ptr->wiphy);
1567 filter_wiphy = dev->wiphy_idx;
1568 }
1569 dev_put(netdev);
1570 }
1571 }
1572
Johannes Berg79c97e92009-07-07 03:56:12 +02001573 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001574 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1575 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001576 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001577 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001578 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1579 continue;
1580 /* attempt to fit multiple wiphy data chunks into the skb */
1581 do {
1582 ret = nl80211_send_wiphy(dev, skb,
1583 NETLINK_CB(cb->skb).portid,
1584 cb->nlh->nlmsg_seq,
1585 NLM_F_MULTI,
1586 split, &cb->args[1],
1587 &cb->args[2],
1588 &cb->args[3]);
1589 if (ret < 0) {
1590 /*
1591 * If sending the wiphy data didn't fit (ENOBUFS
1592 * or EMSGSIZE returned), this SKB is still
1593 * empty (so it's not too big because another
1594 * wiphy dataset is already in the skb) and
1595 * we've not tried to adjust the dump allocation
1596 * yet ... then adjust the alloc size to be
1597 * bigger, and return 1 but with the empty skb.
1598 * This results in an empty message being RX'ed
1599 * in userspace, but that is ignored.
1600 *
1601 * We can then retry with the larger buffer.
1602 */
1603 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1604 !skb->len &&
1605 cb->min_dump_alloc < 4096) {
1606 cb->min_dump_alloc = 4096;
1607 mutex_unlock(&cfg80211_mutex);
1608 return 1;
1609 }
1610 idx--;
1611 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001612 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 } while (cb->args[1] > 0);
1614 break;
Johannes Berg55682962007-09-20 13:09:35 -04001615 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001616 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001617
1618 cb->args[0] = idx;
1619
1620 return skb->len;
1621}
1622
1623static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1624{
1625 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001626 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001627
Johannes Berg645e77d2013-03-01 14:03:49 +01001628 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001629 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001630 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001631
Johannes Berg3713b4e2013-02-14 16:19:38 +01001632 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1633 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001634 nlmsg_free(msg);
1635 return -ENOBUFS;
1636 }
Johannes Berg55682962007-09-20 13:09:35 -04001637
Johannes Berg134e6372009-07-10 09:51:34 +00001638 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001639}
1640
Jouni Malinen31888482008-10-30 16:59:24 +02001641static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1642 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1643 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1644 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1645 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1646 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1647};
1648
1649static int parse_txq_params(struct nlattr *tb[],
1650 struct ieee80211_txq_params *txq_params)
1651{
Johannes Berga3304b02012-03-28 11:04:24 +02001652 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001653 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1654 !tb[NL80211_TXQ_ATTR_AIFS])
1655 return -EINVAL;
1656
Johannes Berga3304b02012-03-28 11:04:24 +02001657 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001658 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1659 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1660 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1661 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1662
Johannes Berga3304b02012-03-28 11:04:24 +02001663 if (txq_params->ac >= NL80211_NUM_ACS)
1664 return -EINVAL;
1665
Jouni Malinen31888482008-10-30 16:59:24 +02001666 return 0;
1667}
1668
Johannes Bergf444de02010-05-05 15:25:02 +02001669static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1670{
1671 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001672 * You can only set the channel explicitly for WDS interfaces,
1673 * all others have their channel managed via their respective
1674 * "establish a connection" command (connect, join, ...)
1675 *
1676 * For AP/GO and mesh mode, the channel can be set with the
1677 * channel userspace API, but is only stored and passed to the
1678 * low-level driver when the AP starts or the mesh is joined.
1679 * This is for backward compatibility, userspace can also give
1680 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001681 *
1682 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001683 * whatever else is going on, so they have their own special
1684 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001685 */
1686 return !wdev ||
1687 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001688 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001689 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1690 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001691}
1692
Johannes Berg683b6d32012-11-08 21:25:48 +01001693static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1694 struct genl_info *info,
1695 struct cfg80211_chan_def *chandef)
1696{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301697 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001698
1699 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1700 return -EINVAL;
1701
1702 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1703
1704 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001705 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1706 chandef->center_freq1 = control_freq;
1707 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001708
1709 /* Primary channel not allowed */
1710 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1711 return -EINVAL;
1712
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001713 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1714 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001715
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001716 chantype = nla_get_u32(
1717 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1718
1719 switch (chantype) {
1720 case NL80211_CHAN_NO_HT:
1721 case NL80211_CHAN_HT20:
1722 case NL80211_CHAN_HT40PLUS:
1723 case NL80211_CHAN_HT40MINUS:
1724 cfg80211_chandef_create(chandef, chandef->chan,
1725 chantype);
1726 break;
1727 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001728 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001729 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001730 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1731 chandef->width =
1732 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1733 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1734 chandef->center_freq1 =
1735 nla_get_u32(
1736 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1737 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1738 chandef->center_freq2 =
1739 nla_get_u32(
1740 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1741 }
1742
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001743 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001744 return -EINVAL;
1745
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001746 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1747 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001748 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001749
Johannes Berg683b6d32012-11-08 21:25:48 +01001750 return 0;
1751}
1752
Johannes Bergf444de02010-05-05 15:25:02 +02001753static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1754 struct wireless_dev *wdev,
1755 struct genl_info *info)
1756{
Johannes Berg683b6d32012-11-08 21:25:48 +01001757 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001758 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001759 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1760
1761 if (wdev)
1762 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001763
Johannes Bergf444de02010-05-05 15:25:02 +02001764 if (!nl80211_can_set_dev_channel(wdev))
1765 return -EOPNOTSUPP;
1766
Johannes Berg683b6d32012-11-08 21:25:48 +01001767 result = nl80211_parse_chandef(rdev, info, &chandef);
1768 if (result)
1769 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001770
1771 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001772 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001773 case NL80211_IFTYPE_AP:
1774 case NL80211_IFTYPE_P2P_GO:
1775 if (wdev->beacon_interval) {
1776 result = -EBUSY;
1777 break;
1778 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001779 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001780 result = -EINVAL;
1781 break;
1782 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001783 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001784 result = 0;
1785 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001786 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001787 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001788 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001789 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001790 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001791 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001792 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001793 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001794 }
1795 mutex_unlock(&rdev->devlist_mtx);
1796
1797 return result;
1798}
1799
1800static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1801{
Johannes Berg4c476992010-10-04 21:36:35 +02001802 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1803 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001804
Johannes Berg4c476992010-10-04 21:36:35 +02001805 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001806}
1807
Bill Jordane8347eb2010-10-01 13:54:28 -04001808static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1809{
Johannes Berg43b19952010-10-07 13:10:30 +02001810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1811 struct net_device *dev = info->user_ptr[1];
1812 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001813 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001814
1815 if (!info->attrs[NL80211_ATTR_MAC])
1816 return -EINVAL;
1817
Johannes Berg43b19952010-10-07 13:10:30 +02001818 if (netif_running(dev))
1819 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001820
Johannes Berg43b19952010-10-07 13:10:30 +02001821 if (!rdev->ops->set_wds_peer)
1822 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001823
Johannes Berg43b19952010-10-07 13:10:30 +02001824 if (wdev->iftype != NL80211_IFTYPE_WDS)
1825 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001826
1827 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001828 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001829}
1830
1831
Johannes Berg55682962007-09-20 13:09:35 -04001832static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1833{
1834 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001835 struct net_device *netdev = NULL;
1836 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001837 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001838 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001839 u32 changed;
1840 u8 retry_short = 0, retry_long = 0;
1841 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001842 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001843
Johannes Bergf444de02010-05-05 15:25:02 +02001844 /*
1845 * Try to find the wiphy and netdev. Normally this
1846 * function shouldn't need the netdev, but this is
1847 * done for backward compatibility -- previously
1848 * setting the channel was done per wiphy, but now
1849 * it is per netdev. Previous userland like hostapd
1850 * also passed a netdev to set_wiphy, so that it is
1851 * possible to let that go to the right netdev!
1852 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001853 mutex_lock(&cfg80211_mutex);
1854
Johannes Bergf444de02010-05-05 15:25:02 +02001855 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1856 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1857
1858 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1859 if (netdev && netdev->ieee80211_ptr) {
1860 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1861 mutex_lock(&rdev->mtx);
1862 } else
1863 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001864 }
1865
Johannes Bergf444de02010-05-05 15:25:02 +02001866 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001867 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1868 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001869 if (IS_ERR(rdev)) {
1870 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001871 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001872 }
1873 wdev = NULL;
1874 netdev = NULL;
1875 result = 0;
1876
1877 mutex_lock(&rdev->mtx);
Johannes Berg71fe96b2012-10-24 10:04:58 +02001878 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001879 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001880
1881 /*
1882 * end workaround code, by now the rdev is available
1883 * and locked, and wdev may or may not be NULL.
1884 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001885
1886 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001887 result = cfg80211_dev_rename(
1888 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001889
1890 mutex_unlock(&cfg80211_mutex);
1891
1892 if (result)
1893 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001894
Jouni Malinen31888482008-10-30 16:59:24 +02001895 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1896 struct ieee80211_txq_params txq_params;
1897 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1898
1899 if (!rdev->ops->set_txq_params) {
1900 result = -EOPNOTSUPP;
1901 goto bad_res;
1902 }
1903
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001904 if (!netdev) {
1905 result = -EINVAL;
1906 goto bad_res;
1907 }
1908
Johannes Berg133a3ff2011-11-03 14:50:13 +01001909 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1910 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1911 result = -EINVAL;
1912 goto bad_res;
1913 }
1914
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001915 if (!netif_running(netdev)) {
1916 result = -ENETDOWN;
1917 goto bad_res;
1918 }
1919
Jouni Malinen31888482008-10-30 16:59:24 +02001920 nla_for_each_nested(nl_txq_params,
1921 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1922 rem_txq_params) {
1923 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1924 nla_data(nl_txq_params),
1925 nla_len(nl_txq_params),
1926 txq_params_policy);
1927 result = parse_txq_params(tb, &txq_params);
1928 if (result)
1929 goto bad_res;
1930
Hila Gonene35e4d22012-06-27 17:19:42 +03001931 result = rdev_set_txq_params(rdev, netdev,
1932 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001933 if (result)
1934 goto bad_res;
1935 }
1936 }
1937
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001938 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001939 result = __nl80211_set_channel(rdev,
1940 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1941 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001942 if (result)
1943 goto bad_res;
1944 }
1945
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001946 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001947 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001948 enum nl80211_tx_power_setting type;
1949 int idx, mbm = 0;
1950
Johannes Bergc8442112012-10-24 10:17:18 +02001951 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1952 txp_wdev = NULL;
1953
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001954 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001955 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001956 goto bad_res;
1957 }
1958
1959 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1960 type = nla_get_u32(info->attrs[idx]);
1961
1962 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1963 (type != NL80211_TX_POWER_AUTOMATIC)) {
1964 result = -EINVAL;
1965 goto bad_res;
1966 }
1967
1968 if (type != NL80211_TX_POWER_AUTOMATIC) {
1969 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1970 mbm = nla_get_u32(info->attrs[idx]);
1971 }
1972
Johannes Bergc8442112012-10-24 10:17:18 +02001973 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001974 if (result)
1975 goto bad_res;
1976 }
1977
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001978 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1979 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1980 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001981 if ((!rdev->wiphy.available_antennas_tx &&
1982 !rdev->wiphy.available_antennas_rx) ||
1983 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001984 result = -EOPNOTSUPP;
1985 goto bad_res;
1986 }
1987
1988 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1989 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1990
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001991 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001992 * available antenna masks, except for the "all" mask */
1993 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1994 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001995 result = -EINVAL;
1996 goto bad_res;
1997 }
1998
Bruno Randolf7f531e02010-12-16 11:30:22 +09001999 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2000 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002001
Hila Gonene35e4d22012-06-27 17:19:42 +03002002 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002003 if (result)
2004 goto bad_res;
2005 }
2006
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002007 changed = 0;
2008
2009 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2010 retry_short = nla_get_u8(
2011 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2012 if (retry_short == 0) {
2013 result = -EINVAL;
2014 goto bad_res;
2015 }
2016 changed |= WIPHY_PARAM_RETRY_SHORT;
2017 }
2018
2019 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2020 retry_long = nla_get_u8(
2021 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2022 if (retry_long == 0) {
2023 result = -EINVAL;
2024 goto bad_res;
2025 }
2026 changed |= WIPHY_PARAM_RETRY_LONG;
2027 }
2028
2029 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2030 frag_threshold = nla_get_u32(
2031 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2032 if (frag_threshold < 256) {
2033 result = -EINVAL;
2034 goto bad_res;
2035 }
2036 if (frag_threshold != (u32) -1) {
2037 /*
2038 * Fragments (apart from the last one) are required to
2039 * have even length. Make the fragmentation code
2040 * simpler by stripping LSB should someone try to use
2041 * odd threshold value.
2042 */
2043 frag_threshold &= ~0x1;
2044 }
2045 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2046 }
2047
2048 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2049 rts_threshold = nla_get_u32(
2050 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2051 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2052 }
2053
Lukáš Turek81077e82009-12-21 22:50:47 +01002054 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2055 coverage_class = nla_get_u8(
2056 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2057 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2058 }
2059
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002060 if (changed) {
2061 u8 old_retry_short, old_retry_long;
2062 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002063 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002064
2065 if (!rdev->ops->set_wiphy_params) {
2066 result = -EOPNOTSUPP;
2067 goto bad_res;
2068 }
2069
2070 old_retry_short = rdev->wiphy.retry_short;
2071 old_retry_long = rdev->wiphy.retry_long;
2072 old_frag_threshold = rdev->wiphy.frag_threshold;
2073 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002074 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002075
2076 if (changed & WIPHY_PARAM_RETRY_SHORT)
2077 rdev->wiphy.retry_short = retry_short;
2078 if (changed & WIPHY_PARAM_RETRY_LONG)
2079 rdev->wiphy.retry_long = retry_long;
2080 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2081 rdev->wiphy.frag_threshold = frag_threshold;
2082 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2083 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002084 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2085 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002086
Hila Gonene35e4d22012-06-27 17:19:42 +03002087 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002088 if (result) {
2089 rdev->wiphy.retry_short = old_retry_short;
2090 rdev->wiphy.retry_long = old_retry_long;
2091 rdev->wiphy.frag_threshold = old_frag_threshold;
2092 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002093 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002094 }
2095 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002096
Johannes Berg306d6112008-12-08 12:39:04 +01002097 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002098 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02002099 if (netdev)
2100 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002101 return result;
2102}
2103
Johannes Berg71bbc992012-06-15 15:30:18 +02002104static inline u64 wdev_id(struct wireless_dev *wdev)
2105{
2106 return (u64)wdev->identifier |
2107 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2108}
Johannes Berg55682962007-09-20 13:09:35 -04002109
Johannes Berg683b6d32012-11-08 21:25:48 +01002110static int nl80211_send_chandef(struct sk_buff *msg,
2111 struct cfg80211_chan_def *chandef)
2112{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002113 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002114
Johannes Berg683b6d32012-11-08 21:25:48 +01002115 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2116 chandef->chan->center_freq))
2117 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002118 switch (chandef->width) {
2119 case NL80211_CHAN_WIDTH_20_NOHT:
2120 case NL80211_CHAN_WIDTH_20:
2121 case NL80211_CHAN_WIDTH_40:
2122 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2123 cfg80211_get_chandef_type(chandef)))
2124 return -ENOBUFS;
2125 break;
2126 default:
2127 break;
2128 }
2129 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2130 return -ENOBUFS;
2131 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2132 return -ENOBUFS;
2133 if (chandef->center_freq2 &&
2134 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002135 return -ENOBUFS;
2136 return 0;
2137}
2138
Eric W. Biederman15e47302012-09-07 20:12:54 +00002139static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002140 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002141 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002142{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002143 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002144 void *hdr;
2145
Eric W. Biederman15e47302012-09-07 20:12:54 +00002146 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002147 if (!hdr)
2148 return -1;
2149
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002150 if (dev &&
2151 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002152 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002153 goto nla_put_failure;
2154
2155 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2156 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002157 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002158 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002159 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2160 rdev->devlist_generation ^
2161 (cfg80211_rdev_list_generation << 2)))
2162 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002163
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002164 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002165 int ret;
2166 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002167
Johannes Berg683b6d32012-11-08 21:25:48 +01002168 ret = rdev_get_channel(rdev, wdev, &chandef);
2169 if (ret == 0) {
2170 if (nl80211_send_chandef(msg, &chandef))
2171 goto nla_put_failure;
2172 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002173 }
2174
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002175 if (wdev->ssid_len) {
2176 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2177 goto nla_put_failure;
2178 }
2179
Johannes Berg55682962007-09-20 13:09:35 -04002180 return genlmsg_end(msg, hdr);
2181
2182 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002183 genlmsg_cancel(msg, hdr);
2184 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002185}
2186
2187static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2188{
2189 int wp_idx = 0;
2190 int if_idx = 0;
2191 int wp_start = cb->args[0];
2192 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002193 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002194 struct wireless_dev *wdev;
2195
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002196 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02002197 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2198 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002199 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002200 if (wp_idx < wp_start) {
2201 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002202 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002203 }
Johannes Berg55682962007-09-20 13:09:35 -04002204 if_idx = 0;
2205
Johannes Bergf5ea9122009-08-07 16:17:38 +02002206 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02002207 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002208 if (if_idx < if_start) {
2209 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002210 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002211 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002212 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002213 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002214 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02002215 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002216 goto out;
2217 }
2218 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002219 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02002220 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002221
2222 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002223 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002224 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002225 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04002226
2227 cb->args[0] = wp_idx;
2228 cb->args[1] = if_idx;
2229
2230 return skb->len;
2231}
2232
2233static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2234{
2235 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002236 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002237 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002238
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002240 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002241 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002242
Eric W. Biederman15e47302012-09-07 20:12:54 +00002243 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002244 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002245 nlmsg_free(msg);
2246 return -ENOBUFS;
2247 }
Johannes Berg55682962007-09-20 13:09:35 -04002248
Johannes Berg134e6372009-07-10 09:51:34 +00002249 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002250}
2251
Michael Wu66f7ac52008-01-31 19:48:22 +01002252static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2253 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2254 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2255 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2256 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2257 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2258};
2259
2260static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2261{
2262 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2263 int flag;
2264
2265 *mntrflags = 0;
2266
2267 if (!nla)
2268 return -EINVAL;
2269
2270 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2271 nla, mntr_flags_policy))
2272 return -EINVAL;
2273
2274 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2275 if (flags[flag])
2276 *mntrflags |= (1<<flag);
2277
2278 return 0;
2279}
2280
Johannes Berg9bc383d2009-11-19 11:55:19 +01002281static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002282 struct net_device *netdev, u8 use_4addr,
2283 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002284{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002285 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002286 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002287 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002288 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002289 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002290
2291 switch (iftype) {
2292 case NL80211_IFTYPE_AP_VLAN:
2293 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2294 return 0;
2295 break;
2296 case NL80211_IFTYPE_STATION:
2297 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2298 return 0;
2299 break;
2300 default:
2301 break;
2302 }
2303
2304 return -EOPNOTSUPP;
2305}
2306
Johannes Berg55682962007-09-20 13:09:35 -04002307static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2308{
Johannes Berg4c476992010-10-04 21:36:35 +02002309 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002310 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002311 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002312 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002313 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002314 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002315 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002316
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002317 memset(&params, 0, sizeof(params));
2318
Johannes Berg04a773a2009-04-19 21:24:32 +02002319 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002320
Johannes Berg723b0382008-09-16 20:22:09 +02002321 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002322 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002323 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002324 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002325 if (ntype > NL80211_IFTYPE_MAX)
2326 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002327 }
2328
Johannes Berg92ffe052008-09-16 20:39:36 +02002329 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002330 struct wireless_dev *wdev = dev->ieee80211_ptr;
2331
Johannes Berg4c476992010-10-04 21:36:35 +02002332 if (ntype != NL80211_IFTYPE_MESH_POINT)
2333 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002334 if (netif_running(dev))
2335 return -EBUSY;
2336
2337 wdev_lock(wdev);
2338 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2339 IEEE80211_MAX_MESH_ID_LEN);
2340 wdev->mesh_id_up_len =
2341 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2342 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2343 wdev->mesh_id_up_len);
2344 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002345 }
2346
Felix Fietkau8b787642009-11-10 18:53:10 +01002347 if (info->attrs[NL80211_ATTR_4ADDR]) {
2348 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2349 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002350 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002351 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002352 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002353 } else {
2354 params.use_4addr = -1;
2355 }
2356
Johannes Berg92ffe052008-09-16 20:39:36 +02002357 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002358 if (ntype != NL80211_IFTYPE_MONITOR)
2359 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002360 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2361 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002362 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002363 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002364
2365 flags = &_flags;
2366 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002367 }
Johannes Berg3b858752009-03-12 09:55:09 +01002368
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002369 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002370 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002371 else
2372 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002373
Johannes Berg9bc383d2009-11-19 11:55:19 +01002374 if (!err && params.use_4addr != -1)
2375 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2376
Johannes Berg55682962007-09-20 13:09:35 -04002377 return err;
2378}
2379
2380static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2381{
Johannes Berg4c476992010-10-04 21:36:35 +02002382 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002383 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002384 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002385 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002386 int err;
2387 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002388 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002389
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002390 memset(&params, 0, sizeof(params));
2391
Johannes Berg55682962007-09-20 13:09:35 -04002392 if (!info->attrs[NL80211_ATTR_IFNAME])
2393 return -EINVAL;
2394
2395 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2396 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2397 if (type > NL80211_IFTYPE_MAX)
2398 return -EINVAL;
2399 }
2400
Johannes Berg79c97e92009-07-07 03:56:12 +02002401 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002402 !(rdev->wiphy.interface_modes & (1 << type)))
2403 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002404
Arend van Spriel1c18f142013-01-08 10:17:27 +01002405 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2406 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2407 ETH_ALEN);
2408 if (!is_valid_ether_addr(params.macaddr))
2409 return -EADDRNOTAVAIL;
2410 }
2411
Johannes Berg9bc383d2009-11-19 11:55:19 +01002412 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002413 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002414 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002415 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002416 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002417 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002418
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002419 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2420 if (!msg)
2421 return -ENOMEM;
2422
Michael Wu66f7ac52008-01-31 19:48:22 +01002423 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2424 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2425 &flags);
Hila Gonene35e4d22012-06-27 17:19:42 +03002426 wdev = rdev_add_virtual_intf(rdev,
2427 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2428 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002429 if (IS_ERR(wdev)) {
2430 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002431 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002432 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002433
Johannes Berg98104fde2012-06-16 00:19:54 +02002434 switch (type) {
2435 case NL80211_IFTYPE_MESH_POINT:
2436 if (!info->attrs[NL80211_ATTR_MESH_ID])
2437 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002438 wdev_lock(wdev);
2439 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2440 IEEE80211_MAX_MESH_ID_LEN);
2441 wdev->mesh_id_up_len =
2442 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2443 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2444 wdev->mesh_id_up_len);
2445 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002446 break;
2447 case NL80211_IFTYPE_P2P_DEVICE:
2448 /*
2449 * P2P Device doesn't have a netdev, so doesn't go
2450 * through the netdev notifier and must be added here
2451 */
2452 mutex_init(&wdev->mtx);
2453 INIT_LIST_HEAD(&wdev->event_list);
2454 spin_lock_init(&wdev->event_lock);
2455 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2456 spin_lock_init(&wdev->mgmt_registrations_lock);
2457
2458 mutex_lock(&rdev->devlist_mtx);
2459 wdev->identifier = ++rdev->wdev_id;
2460 list_add_rcu(&wdev->list, &rdev->wdev_list);
2461 rdev->devlist_generation++;
2462 mutex_unlock(&rdev->devlist_mtx);
2463 break;
2464 default:
2465 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002466 }
2467
Eric W. Biederman15e47302012-09-07 20:12:54 +00002468 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002469 rdev, wdev) < 0) {
2470 nlmsg_free(msg);
2471 return -ENOBUFS;
2472 }
2473
2474 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002475}
2476
2477static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2478{
Johannes Berg4c476992010-10-04 21:36:35 +02002479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002480 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002481
Johannes Berg4c476992010-10-04 21:36:35 +02002482 if (!rdev->ops->del_virtual_intf)
2483 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002484
Johannes Berg84efbb82012-06-16 00:00:26 +02002485 /*
2486 * If we remove a wireless device without a netdev then clear
2487 * user_ptr[1] so that nl80211_post_doit won't dereference it
2488 * to check if it needs to do dev_put(). Otherwise it crashes
2489 * since the wdev has been freed, unlike with a netdev where
2490 * we need the dev_put() for the netdev to really be freed.
2491 */
2492 if (!wdev->netdev)
2493 info->user_ptr[1] = NULL;
2494
Hila Gonene35e4d22012-06-27 17:19:42 +03002495 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002496}
2497
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002498static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2499{
2500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2501 struct net_device *dev = info->user_ptr[1];
2502 u16 noack_map;
2503
2504 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2505 return -EINVAL;
2506
2507 if (!rdev->ops->set_noack_map)
2508 return -EOPNOTSUPP;
2509
2510 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2511
Hila Gonene35e4d22012-06-27 17:19:42 +03002512 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002513}
2514
Johannes Berg41ade002007-12-19 02:03:29 +01002515struct get_key_cookie {
2516 struct sk_buff *msg;
2517 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002518 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002519};
2520
2521static void get_key_callback(void *c, struct key_params *params)
2522{
Johannes Bergb9454e82009-07-08 13:29:08 +02002523 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002524 struct get_key_cookie *cookie = c;
2525
David S. Miller9360ffd2012-03-29 04:41:26 -04002526 if ((params->key &&
2527 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2528 params->key_len, params->key)) ||
2529 (params->seq &&
2530 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2531 params->seq_len, params->seq)) ||
2532 (params->cipher &&
2533 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2534 params->cipher)))
2535 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002536
Johannes Bergb9454e82009-07-08 13:29:08 +02002537 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2538 if (!key)
2539 goto nla_put_failure;
2540
David S. Miller9360ffd2012-03-29 04:41:26 -04002541 if ((params->key &&
2542 nla_put(cookie->msg, NL80211_KEY_DATA,
2543 params->key_len, params->key)) ||
2544 (params->seq &&
2545 nla_put(cookie->msg, NL80211_KEY_SEQ,
2546 params->seq_len, params->seq)) ||
2547 (params->cipher &&
2548 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2549 params->cipher)))
2550 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002551
David S. Miller9360ffd2012-03-29 04:41:26 -04002552 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2553 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002554
2555 nla_nest_end(cookie->msg, key);
2556
Johannes Berg41ade002007-12-19 02:03:29 +01002557 return;
2558 nla_put_failure:
2559 cookie->error = 1;
2560}
2561
2562static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2563{
Johannes Berg4c476992010-10-04 21:36:35 +02002564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002565 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002566 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002567 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002568 const u8 *mac_addr = NULL;
2569 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002570 struct get_key_cookie cookie = {
2571 .error = 0,
2572 };
2573 void *hdr;
2574 struct sk_buff *msg;
2575
2576 if (info->attrs[NL80211_ATTR_KEY_IDX])
2577 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2578
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002579 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002580 return -EINVAL;
2581
2582 if (info->attrs[NL80211_ATTR_MAC])
2583 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2584
Johannes Berge31b8212010-10-05 19:39:30 +02002585 pairwise = !!mac_addr;
2586 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2587 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2588 if (kt >= NUM_NL80211_KEYTYPES)
2589 return -EINVAL;
2590 if (kt != NL80211_KEYTYPE_GROUP &&
2591 kt != NL80211_KEYTYPE_PAIRWISE)
2592 return -EINVAL;
2593 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2594 }
2595
Johannes Berg4c476992010-10-04 21:36:35 +02002596 if (!rdev->ops->get_key)
2597 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002598
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002599 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002600 if (!msg)
2601 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002602
Eric W. Biederman15e47302012-09-07 20:12:54 +00002603 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002604 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002605 if (IS_ERR(hdr))
2606 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002607
2608 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002609 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002610
David S. Miller9360ffd2012-03-29 04:41:26 -04002611 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2612 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2613 goto nla_put_failure;
2614 if (mac_addr &&
2615 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2616 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002617
Johannes Berge31b8212010-10-05 19:39:30 +02002618 if (pairwise && mac_addr &&
2619 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2620 return -ENOENT;
2621
Hila Gonene35e4d22012-06-27 17:19:42 +03002622 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2623 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002624
2625 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002626 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002627
2628 if (cookie.error)
2629 goto nla_put_failure;
2630
2631 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002632 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002633
2634 nla_put_failure:
2635 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002636 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002637 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002638 return err;
2639}
2640
2641static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2642{
Johannes Berg4c476992010-10-04 21:36:35 +02002643 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002644 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002645 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002646 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002647
Johannes Bergb9454e82009-07-08 13:29:08 +02002648 err = nl80211_parse_key(info, &key);
2649 if (err)
2650 return err;
2651
2652 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002653 return -EINVAL;
2654
Johannes Bergb9454e82009-07-08 13:29:08 +02002655 /* only support setting default key */
2656 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002657 return -EINVAL;
2658
Johannes Bergfffd0932009-07-08 14:22:54 +02002659 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002660
2661 if (key.def) {
2662 if (!rdev->ops->set_default_key) {
2663 err = -EOPNOTSUPP;
2664 goto out;
2665 }
2666
2667 err = nl80211_key_allowed(dev->ieee80211_ptr);
2668 if (err)
2669 goto out;
2670
Hila Gonene35e4d22012-06-27 17:19:42 +03002671 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002672 key.def_uni, key.def_multi);
2673
2674 if (err)
2675 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002676
Johannes Berg3d23e342009-09-29 23:27:28 +02002677#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002678 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002679#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002680 } else {
2681 if (key.def_uni || !key.def_multi) {
2682 err = -EINVAL;
2683 goto out;
2684 }
2685
2686 if (!rdev->ops->set_default_mgmt_key) {
2687 err = -EOPNOTSUPP;
2688 goto out;
2689 }
2690
2691 err = nl80211_key_allowed(dev->ieee80211_ptr);
2692 if (err)
2693 goto out;
2694
Hila Gonene35e4d22012-06-27 17:19:42 +03002695 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002696 if (err)
2697 goto out;
2698
2699#ifdef CONFIG_CFG80211_WEXT
2700 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2701#endif
2702 }
2703
2704 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002705 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002706
Johannes Berg41ade002007-12-19 02:03:29 +01002707 return err;
2708}
2709
2710static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2711{
Johannes Berg4c476992010-10-04 21:36:35 +02002712 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002713 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002714 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002715 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002716 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002717
Johannes Bergb9454e82009-07-08 13:29:08 +02002718 err = nl80211_parse_key(info, &key);
2719 if (err)
2720 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002721
Johannes Bergb9454e82009-07-08 13:29:08 +02002722 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002723 return -EINVAL;
2724
Johannes Berg41ade002007-12-19 02:03:29 +01002725 if (info->attrs[NL80211_ATTR_MAC])
2726 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2727
Johannes Berge31b8212010-10-05 19:39:30 +02002728 if (key.type == -1) {
2729 if (mac_addr)
2730 key.type = NL80211_KEYTYPE_PAIRWISE;
2731 else
2732 key.type = NL80211_KEYTYPE_GROUP;
2733 }
2734
2735 /* for now */
2736 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2737 key.type != NL80211_KEYTYPE_GROUP)
2738 return -EINVAL;
2739
Johannes Berg4c476992010-10-04 21:36:35 +02002740 if (!rdev->ops->add_key)
2741 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002742
Johannes Berge31b8212010-10-05 19:39:30 +02002743 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2744 key.type == NL80211_KEYTYPE_PAIRWISE,
2745 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002746 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002747
2748 wdev_lock(dev->ieee80211_ptr);
2749 err = nl80211_key_allowed(dev->ieee80211_ptr);
2750 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002751 err = rdev_add_key(rdev, dev, key.idx,
2752 key.type == NL80211_KEYTYPE_PAIRWISE,
2753 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002754 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002755
Johannes Berg41ade002007-12-19 02:03:29 +01002756 return err;
2757}
2758
2759static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2760{
Johannes Berg4c476992010-10-04 21:36:35 +02002761 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002762 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002763 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002764 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002765 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002766
Johannes Bergb9454e82009-07-08 13:29:08 +02002767 err = nl80211_parse_key(info, &key);
2768 if (err)
2769 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002770
2771 if (info->attrs[NL80211_ATTR_MAC])
2772 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2773
Johannes Berge31b8212010-10-05 19:39:30 +02002774 if (key.type == -1) {
2775 if (mac_addr)
2776 key.type = NL80211_KEYTYPE_PAIRWISE;
2777 else
2778 key.type = NL80211_KEYTYPE_GROUP;
2779 }
2780
2781 /* for now */
2782 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2783 key.type != NL80211_KEYTYPE_GROUP)
2784 return -EINVAL;
2785
Johannes Berg4c476992010-10-04 21:36:35 +02002786 if (!rdev->ops->del_key)
2787 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002788
Johannes Bergfffd0932009-07-08 14:22:54 +02002789 wdev_lock(dev->ieee80211_ptr);
2790 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002791
2792 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2793 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2794 err = -ENOENT;
2795
Johannes Bergfffd0932009-07-08 14:22:54 +02002796 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002797 err = rdev_del_key(rdev, dev, key.idx,
2798 key.type == NL80211_KEYTYPE_PAIRWISE,
2799 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002800
Johannes Berg3d23e342009-09-29 23:27:28 +02002801#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002802 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002803 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002804 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002805 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002806 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2807 }
2808#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002809 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002810
Johannes Berg41ade002007-12-19 02:03:29 +01002811 return err;
2812}
2813
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302814/* This function returns an error or the number of nested attributes */
2815static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2816{
2817 struct nlattr *attr;
2818 int n_entries = 0, tmp;
2819
2820 nla_for_each_nested(attr, nl_attr, tmp) {
2821 if (nla_len(attr) != ETH_ALEN)
2822 return -EINVAL;
2823
2824 n_entries++;
2825 }
2826
2827 return n_entries;
2828}
2829
2830/*
2831 * This function parses ACL information and allocates memory for ACL data.
2832 * On successful return, the calling function is responsible to free the
2833 * ACL buffer returned by this function.
2834 */
2835static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2836 struct genl_info *info)
2837{
2838 enum nl80211_acl_policy acl_policy;
2839 struct nlattr *attr;
2840 struct cfg80211_acl_data *acl;
2841 int i = 0, n_entries, tmp;
2842
2843 if (!wiphy->max_acl_mac_addrs)
2844 return ERR_PTR(-EOPNOTSUPP);
2845
2846 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2847 return ERR_PTR(-EINVAL);
2848
2849 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2850 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2851 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2852 return ERR_PTR(-EINVAL);
2853
2854 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2855 return ERR_PTR(-EINVAL);
2856
2857 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2858 if (n_entries < 0)
2859 return ERR_PTR(n_entries);
2860
2861 if (n_entries > wiphy->max_acl_mac_addrs)
2862 return ERR_PTR(-ENOTSUPP);
2863
2864 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2865 GFP_KERNEL);
2866 if (!acl)
2867 return ERR_PTR(-ENOMEM);
2868
2869 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2870 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2871 i++;
2872 }
2873
2874 acl->n_acl_entries = n_entries;
2875 acl->acl_policy = acl_policy;
2876
2877 return acl;
2878}
2879
2880static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2881{
2882 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2883 struct net_device *dev = info->user_ptr[1];
2884 struct cfg80211_acl_data *acl;
2885 int err;
2886
2887 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2888 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2889 return -EOPNOTSUPP;
2890
2891 if (!dev->ieee80211_ptr->beacon_interval)
2892 return -EINVAL;
2893
2894 acl = parse_acl_data(&rdev->wiphy, info);
2895 if (IS_ERR(acl))
2896 return PTR_ERR(acl);
2897
2898 err = rdev_set_mac_acl(rdev, dev, acl);
2899
2900 kfree(acl);
2901
2902 return err;
2903}
2904
Johannes Berg88600202012-02-13 15:17:18 +01002905static int nl80211_parse_beacon(struct genl_info *info,
2906 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002907{
Johannes Berg88600202012-02-13 15:17:18 +01002908 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002909
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002910 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2911 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2912 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2913 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002914 return -EINVAL;
2915
Johannes Berg88600202012-02-13 15:17:18 +01002916 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002917
Johannes Berged1b6cc2007-12-19 02:03:32 +01002918 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002919 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2920 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2921 if (!bcn->head_len)
2922 return -EINVAL;
2923 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002924 }
2925
2926 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002927 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2928 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002929 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002930 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002931 }
2932
Johannes Berg4c476992010-10-04 21:36:35 +02002933 if (!haveinfo)
2934 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002935
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002936 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002937 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2938 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002939 }
2940
2941 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002942 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002943 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002944 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002945 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2946 }
2947
2948 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002949 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002950 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002951 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002952 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2953 }
2954
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002955 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002956 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002957 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002958 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002959 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2960 }
2961
Johannes Berg88600202012-02-13 15:17:18 +01002962 return 0;
2963}
2964
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002965static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2966 struct cfg80211_ap_settings *params)
2967{
2968 struct wireless_dev *wdev;
2969 bool ret = false;
2970
2971 mutex_lock(&rdev->devlist_mtx);
2972
Johannes Berg89a54e42012-06-15 14:33:17 +02002973 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002974 if (wdev->iftype != NL80211_IFTYPE_AP &&
2975 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2976 continue;
2977
Johannes Berg683b6d32012-11-08 21:25:48 +01002978 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002979 continue;
2980
Johannes Berg683b6d32012-11-08 21:25:48 +01002981 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002982 ret = true;
2983 break;
2984 }
2985
2986 mutex_unlock(&rdev->devlist_mtx);
2987
2988 return ret;
2989}
2990
Jouni Malinene39e5b52012-09-30 19:29:39 +03002991static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2992 enum nl80211_auth_type auth_type,
2993 enum nl80211_commands cmd)
2994{
2995 if (auth_type > NL80211_AUTHTYPE_MAX)
2996 return false;
2997
2998 switch (cmd) {
2999 case NL80211_CMD_AUTHENTICATE:
3000 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3001 auth_type == NL80211_AUTHTYPE_SAE)
3002 return false;
3003 return true;
3004 case NL80211_CMD_CONNECT:
3005 case NL80211_CMD_START_AP:
3006 /* SAE not supported yet */
3007 if (auth_type == NL80211_AUTHTYPE_SAE)
3008 return false;
3009 return true;
3010 default:
3011 return false;
3012 }
3013}
3014
Johannes Berg88600202012-02-13 15:17:18 +01003015static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3016{
3017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3018 struct net_device *dev = info->user_ptr[1];
3019 struct wireless_dev *wdev = dev->ieee80211_ptr;
3020 struct cfg80211_ap_settings params;
3021 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003022 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003023
3024 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3025 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3026 return -EOPNOTSUPP;
3027
3028 if (!rdev->ops->start_ap)
3029 return -EOPNOTSUPP;
3030
3031 if (wdev->beacon_interval)
3032 return -EALREADY;
3033
3034 memset(&params, 0, sizeof(params));
3035
3036 /* these are required for START_AP */
3037 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3038 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3039 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3040 return -EINVAL;
3041
3042 err = nl80211_parse_beacon(info, &params.beacon);
3043 if (err)
3044 return err;
3045
3046 params.beacon_interval =
3047 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3048 params.dtim_period =
3049 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3050
3051 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3052 if (err)
3053 return err;
3054
3055 /*
3056 * In theory, some of these attributes should be required here
3057 * but since they were not used when the command was originally
3058 * added, keep them optional for old user space programs to let
3059 * them continue to work with drivers that do not need the
3060 * additional information -- drivers must check!
3061 */
3062 if (info->attrs[NL80211_ATTR_SSID]) {
3063 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3064 params.ssid_len =
3065 nla_len(info->attrs[NL80211_ATTR_SSID]);
3066 if (params.ssid_len == 0 ||
3067 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3068 return -EINVAL;
3069 }
3070
3071 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3072 params.hidden_ssid = nla_get_u32(
3073 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3074 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3075 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3076 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3077 return -EINVAL;
3078 }
3079
3080 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3081
3082 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3083 params.auth_type = nla_get_u32(
3084 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003085 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3086 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003087 return -EINVAL;
3088 } else
3089 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3090
3091 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3092 NL80211_MAX_NR_CIPHER_SUITES);
3093 if (err)
3094 return err;
3095
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303096 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3097 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3098 return -EOPNOTSUPP;
3099 params.inactivity_timeout = nla_get_u16(
3100 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3101 }
3102
Johannes Berg53cabad2012-11-14 15:17:28 +01003103 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3104 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3105 return -EINVAL;
3106 params.p2p_ctwindow =
3107 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3108 if (params.p2p_ctwindow > 127)
3109 return -EINVAL;
3110 if (params.p2p_ctwindow != 0 &&
3111 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3112 return -EINVAL;
3113 }
3114
3115 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3116 u8 tmp;
3117
3118 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3119 return -EINVAL;
3120 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3121 if (tmp > 1)
3122 return -EINVAL;
3123 params.p2p_opp_ps = tmp;
3124 if (params.p2p_opp_ps != 0 &&
3125 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3126 return -EINVAL;
3127 }
3128
Johannes Bergaa430da2012-05-16 23:50:18 +02003129 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003130 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3131 if (err)
3132 return err;
3133 } else if (wdev->preset_chandef.chan) {
3134 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003135 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003136 return -EINVAL;
3137
Johannes Berg683b6d32012-11-08 21:25:48 +01003138 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003139 return -EINVAL;
3140
Simon Wunderlich04f39042013-02-08 18:16:19 +01003141 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3142 if (err < 0)
3143 return err;
3144 if (err) {
3145 radar_detect_width = BIT(params.chandef.width);
3146 params.radar_required = true;
3147 }
3148
Michal Kaziore4e32452012-06-29 12:47:08 +02003149 mutex_lock(&rdev->devlist_mtx);
Simon Wunderlich04f39042013-02-08 18:16:19 +01003150 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3151 params.chandef.chan,
3152 CHAN_MODE_SHARED,
3153 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003154 mutex_unlock(&rdev->devlist_mtx);
3155
3156 if (err)
3157 return err;
3158
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303159 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3160 params.acl = parse_acl_data(&rdev->wiphy, info);
3161 if (IS_ERR(params.acl))
3162 return PTR_ERR(params.acl);
3163 }
3164
Hila Gonene35e4d22012-06-27 17:19:42 +03003165 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003166 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003167 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003168 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003169 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003170 wdev->ssid_len = params.ssid_len;
3171 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003172 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303173
3174 kfree(params.acl);
3175
Johannes Berg56d18932011-05-09 18:41:15 +02003176 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003177}
3178
Johannes Berg88600202012-02-13 15:17:18 +01003179static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3180{
3181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3182 struct net_device *dev = info->user_ptr[1];
3183 struct wireless_dev *wdev = dev->ieee80211_ptr;
3184 struct cfg80211_beacon_data params;
3185 int err;
3186
3187 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3188 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3189 return -EOPNOTSUPP;
3190
3191 if (!rdev->ops->change_beacon)
3192 return -EOPNOTSUPP;
3193
3194 if (!wdev->beacon_interval)
3195 return -EINVAL;
3196
3197 err = nl80211_parse_beacon(info, &params);
3198 if (err)
3199 return err;
3200
Hila Gonene35e4d22012-06-27 17:19:42 +03003201 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003202}
3203
3204static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003205{
Johannes Berg4c476992010-10-04 21:36:35 +02003206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3207 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003208
Michal Kazior60771782012-06-29 12:46:56 +02003209 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003210}
3211
Johannes Berg5727ef12007-12-19 02:03:34 +01003212static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3213 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3214 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3215 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003216 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003217 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003218 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003219};
3220
Johannes Bergeccb8e82009-05-11 21:57:56 +03003221static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003222 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003223 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003224{
3225 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003226 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003227 int flag;
3228
Johannes Bergeccb8e82009-05-11 21:57:56 +03003229 /*
3230 * Try parsing the new attribute first so userspace
3231 * can specify both for older kernels.
3232 */
3233 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3234 if (nla) {
3235 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003236
Johannes Bergeccb8e82009-05-11 21:57:56 +03003237 sta_flags = nla_data(nla);
3238 params->sta_flags_mask = sta_flags->mask;
3239 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003240 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003241 if ((params->sta_flags_mask |
3242 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3243 return -EINVAL;
3244 return 0;
3245 }
3246
3247 /* if present, parse the old attribute */
3248
3249 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003250 if (!nla)
3251 return 0;
3252
3253 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3254 nla, sta_flags_policy))
3255 return -EINVAL;
3256
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003257 /*
3258 * Only allow certain flags for interface types so that
3259 * other attributes are silently ignored. Remember that
3260 * this is backward compatibility code with old userspace
3261 * and shouldn't be hit in other cases anyway.
3262 */
3263 switch (iftype) {
3264 case NL80211_IFTYPE_AP:
3265 case NL80211_IFTYPE_AP_VLAN:
3266 case NL80211_IFTYPE_P2P_GO:
3267 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3268 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3269 BIT(NL80211_STA_FLAG_WME) |
3270 BIT(NL80211_STA_FLAG_MFP);
3271 break;
3272 case NL80211_IFTYPE_P2P_CLIENT:
3273 case NL80211_IFTYPE_STATION:
3274 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3275 BIT(NL80211_STA_FLAG_TDLS_PEER);
3276 break;
3277 case NL80211_IFTYPE_MESH_POINT:
3278 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3279 BIT(NL80211_STA_FLAG_MFP) |
3280 BIT(NL80211_STA_FLAG_AUTHORIZED);
3281 default:
3282 return -EINVAL;
3283 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003284
Johannes Berg3383b5a2012-05-10 20:14:43 +02003285 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3286 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003287 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003288
Johannes Berg3383b5a2012-05-10 20:14:43 +02003289 /* no longer support new API additions in old API */
3290 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3291 return -EINVAL;
3292 }
3293 }
3294
Johannes Berg5727ef12007-12-19 02:03:34 +01003295 return 0;
3296}
3297
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003298static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3299 int attr)
3300{
3301 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003302 u32 bitrate;
3303 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003304
3305 rate = nla_nest_start(msg, attr);
3306 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003307 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003308
3309 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3310 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003311 /* report 16-bit bitrate only if we can */
3312 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003313 if (bitrate > 0 &&
3314 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3315 return false;
3316 if (bitrate_compat > 0 &&
3317 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3318 return false;
3319
3320 if (info->flags & RATE_INFO_FLAGS_MCS) {
3321 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3322 return false;
3323 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3324 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3325 return false;
3326 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3327 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3328 return false;
3329 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3330 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3331 return false;
3332 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3333 return false;
3334 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3335 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3336 return false;
3337 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3338 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3339 return false;
3340 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3341 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3342 return false;
3343 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3344 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3345 return false;
3346 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3347 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3348 return false;
3349 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003350
3351 nla_nest_end(msg, rate);
3352 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003353}
3354
Eric W. Biederman15e47302012-09-07 20:12:54 +00003355static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003356 int flags,
3357 struct cfg80211_registered_device *rdev,
3358 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003359 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003360{
3361 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003362 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003363
Eric W. Biederman15e47302012-09-07 20:12:54 +00003364 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003365 if (!hdr)
3366 return -1;
3367
David S. Miller9360ffd2012-03-29 04:41:26 -04003368 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3369 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3370 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3371 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003372
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003373 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3374 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003375 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003376 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3377 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3378 sinfo->connected_time))
3379 goto nla_put_failure;
3380 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3381 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3382 sinfo->inactive_time))
3383 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003384 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3385 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003386 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003387 (u32)sinfo->rx_bytes))
3388 goto nla_put_failure;
3389 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3390 NL80211_STA_INFO_TX_BYTES64)) &&
3391 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3392 (u32)sinfo->tx_bytes))
3393 goto nla_put_failure;
3394 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3395 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003396 sinfo->rx_bytes))
3397 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003398 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3399 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003400 sinfo->tx_bytes))
3401 goto nla_put_failure;
3402 if ((sinfo->filled & STATION_INFO_LLID) &&
3403 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3404 goto nla_put_failure;
3405 if ((sinfo->filled & STATION_INFO_PLID) &&
3406 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3407 goto nla_put_failure;
3408 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3409 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3410 sinfo->plink_state))
3411 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003412 switch (rdev->wiphy.signal_type) {
3413 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003414 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3415 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3416 sinfo->signal))
3417 goto nla_put_failure;
3418 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3419 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3420 sinfo->signal_avg))
3421 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003422 break;
3423 default:
3424 break;
3425 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003426 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003427 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3428 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003429 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003430 }
3431 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3432 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3433 NL80211_STA_INFO_RX_BITRATE))
3434 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003435 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003436 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3437 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3438 sinfo->rx_packets))
3439 goto nla_put_failure;
3440 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3441 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3442 sinfo->tx_packets))
3443 goto nla_put_failure;
3444 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3445 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3446 sinfo->tx_retries))
3447 goto nla_put_failure;
3448 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3449 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3450 sinfo->tx_failed))
3451 goto nla_put_failure;
3452 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3453 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3454 sinfo->beacon_loss_count))
3455 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003456 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3457 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3458 sinfo->local_pm))
3459 goto nla_put_failure;
3460 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3461 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3462 sinfo->peer_pm))
3463 goto nla_put_failure;
3464 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3465 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3466 sinfo->nonpeer_pm))
3467 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003468 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3469 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3470 if (!bss_param)
3471 goto nla_put_failure;
3472
David S. Miller9360ffd2012-03-29 04:41:26 -04003473 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3474 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3475 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3476 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3477 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3478 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3479 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3480 sinfo->bss_param.dtim_period) ||
3481 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3482 sinfo->bss_param.beacon_interval))
3483 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003484
3485 nla_nest_end(msg, bss_param);
3486 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003487 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3488 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3489 sizeof(struct nl80211_sta_flag_update),
3490 &sinfo->sta_flags))
3491 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003492 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3493 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3494 sinfo->t_offset))
3495 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003496 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003497
David S. Miller9360ffd2012-03-29 04:41:26 -04003498 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3499 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3500 sinfo->assoc_req_ies))
3501 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003502
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003503 return genlmsg_end(msg, hdr);
3504
3505 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003506 genlmsg_cancel(msg, hdr);
3507 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003508}
3509
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003510static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003511 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003512{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003513 struct station_info sinfo;
3514 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003515 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003516 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003517 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003518 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003519
Johannes Berg67748892010-10-04 21:14:06 +02003520 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3521 if (err)
3522 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003523
3524 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003525 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003526 goto out_err;
3527 }
3528
Johannes Bergbba95fe2008-07-29 13:22:51 +02003529 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003530 memset(&sinfo, 0, sizeof(sinfo));
Hila Gonene35e4d22012-06-27 17:19:42 +03003531 err = rdev_dump_station(dev, netdev, sta_idx,
3532 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003533 if (err == -ENOENT)
3534 break;
3535 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003536 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003537
3538 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003539 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003540 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04003541 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003542 &sinfo) < 0)
3543 goto out;
3544
3545 sta_idx++;
3546 }
3547
3548
3549 out:
3550 cb->args[1] = sta_idx;
3551 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003552 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003553 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003554
3555 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003556}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003557
Johannes Berg5727ef12007-12-19 02:03:34 +01003558static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3559{
Johannes Berg4c476992010-10-04 21:36:35 +02003560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3561 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003562 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003563 struct sk_buff *msg;
3564 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003565 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003566
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003567 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003568
3569 if (!info->attrs[NL80211_ATTR_MAC])
3570 return -EINVAL;
3571
3572 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3573
Johannes Berg4c476992010-10-04 21:36:35 +02003574 if (!rdev->ops->get_station)
3575 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003576
Hila Gonene35e4d22012-06-27 17:19:42 +03003577 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003578 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003579 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003580
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003581 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003582 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003583 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003584
Eric W. Biederman15e47302012-09-07 20:12:54 +00003585 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003586 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003587 nlmsg_free(msg);
3588 return -ENOBUFS;
3589 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003590
Johannes Berg4c476992010-10-04 21:36:35 +02003591 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003592}
3593
Johannes Berg77ee7c82013-02-15 00:48:33 +01003594int cfg80211_check_station_change(struct wiphy *wiphy,
3595 struct station_parameters *params,
3596 enum cfg80211_station_type statype)
3597{
3598 if (params->listen_interval != -1)
3599 return -EINVAL;
3600 if (params->aid)
3601 return -EINVAL;
3602
3603 /* When you run into this, adjust the code below for the new flag */
3604 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3605
3606 switch (statype) {
3607 case CFG80211_STA_MESH_PEER_NONSEC:
3608 case CFG80211_STA_MESH_PEER_SECURE:
3609 /*
3610 * No ignoring the TDLS flag here -- the userspace mesh
3611 * code doesn't have the bug of including TDLS in the
3612 * mask everywhere.
3613 */
3614 if (params->sta_flags_mask &
3615 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3616 BIT(NL80211_STA_FLAG_MFP) |
3617 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3618 return -EINVAL;
3619 break;
3620 case CFG80211_STA_TDLS_PEER_SETUP:
3621 case CFG80211_STA_TDLS_PEER_ACTIVE:
3622 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3623 return -EINVAL;
3624 /* ignore since it can't change */
3625 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3626 break;
3627 default:
3628 /* disallow mesh-specific things */
3629 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3630 return -EINVAL;
3631 if (params->local_pm)
3632 return -EINVAL;
3633 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3634 return -EINVAL;
3635 }
3636
3637 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3638 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3639 /* TDLS can't be set, ... */
3640 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3641 return -EINVAL;
3642 /*
3643 * ... but don't bother the driver with it. This works around
3644 * a hostapd/wpa_supplicant issue -- it always includes the
3645 * TLDS_PEER flag in the mask even for AP mode.
3646 */
3647 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3648 }
3649
3650 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3651 /* reject other things that can't change */
3652 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3653 return -EINVAL;
3654 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3655 return -EINVAL;
3656 if (params->supported_rates)
3657 return -EINVAL;
3658 if (params->ext_capab || params->ht_capa || params->vht_capa)
3659 return -EINVAL;
3660 }
3661
3662 if (statype != CFG80211_STA_AP_CLIENT) {
3663 if (params->vlan)
3664 return -EINVAL;
3665 }
3666
3667 switch (statype) {
3668 case CFG80211_STA_AP_MLME_CLIENT:
3669 /* Use this only for authorizing/unauthorizing a station */
3670 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3671 return -EOPNOTSUPP;
3672 break;
3673 case CFG80211_STA_AP_CLIENT:
3674 /* accept only the listed bits */
3675 if (params->sta_flags_mask &
3676 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3677 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3678 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3679 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3680 BIT(NL80211_STA_FLAG_WME) |
3681 BIT(NL80211_STA_FLAG_MFP)))
3682 return -EINVAL;
3683
3684 /* but authenticated/associated only if driver handles it */
3685 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3686 params->sta_flags_mask &
3687 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3688 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3689 return -EINVAL;
3690 break;
3691 case CFG80211_STA_IBSS:
3692 case CFG80211_STA_AP_STA:
3693 /* reject any changes other than AUTHORIZED */
3694 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3695 return -EINVAL;
3696 break;
3697 case CFG80211_STA_TDLS_PEER_SETUP:
3698 /* reject any changes other than AUTHORIZED or WME */
3699 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3700 BIT(NL80211_STA_FLAG_WME)))
3701 return -EINVAL;
3702 /* force (at least) rates when authorizing */
3703 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3704 !params->supported_rates)
3705 return -EINVAL;
3706 break;
3707 case CFG80211_STA_TDLS_PEER_ACTIVE:
3708 /* reject any changes */
3709 return -EINVAL;
3710 case CFG80211_STA_MESH_PEER_NONSEC:
3711 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3712 return -EINVAL;
3713 break;
3714 case CFG80211_STA_MESH_PEER_SECURE:
3715 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3716 return -EINVAL;
3717 break;
3718 }
3719
3720 return 0;
3721}
3722EXPORT_SYMBOL(cfg80211_check_station_change);
3723
Johannes Berg5727ef12007-12-19 02:03:34 +01003724/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003725 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003726 */
Johannes Berg80b99892011-11-18 16:23:01 +01003727static struct net_device *get_vlan(struct genl_info *info,
3728 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003729{
Johannes Berg463d0182009-07-14 00:33:35 +02003730 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003731 struct net_device *v;
3732 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003733
Johannes Berg80b99892011-11-18 16:23:01 +01003734 if (!vlanattr)
3735 return NULL;
3736
3737 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3738 if (!v)
3739 return ERR_PTR(-ENODEV);
3740
3741 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3742 ret = -EINVAL;
3743 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003744 }
Johannes Berg80b99892011-11-18 16:23:01 +01003745
Johannes Berg77ee7c82013-02-15 00:48:33 +01003746 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3747 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3748 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3749 ret = -EINVAL;
3750 goto error;
3751 }
3752
Johannes Berg80b99892011-11-18 16:23:01 +01003753 if (!netif_running(v)) {
3754 ret = -ENETDOWN;
3755 goto error;
3756 }
3757
3758 return v;
3759 error:
3760 dev_put(v);
3761 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003762}
3763
Jouni Malinendf881292013-02-14 21:10:54 +02003764static struct nla_policy
3765nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3766 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3767 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3768};
3769
Johannes Bergff276692013-02-15 00:09:01 +01003770static int nl80211_parse_sta_wme(struct genl_info *info,
3771 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003772{
Jouni Malinendf881292013-02-14 21:10:54 +02003773 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3774 struct nlattr *nla;
3775 int err;
3776
Jouni Malinendf881292013-02-14 21:10:54 +02003777 /* parse WME attributes if present */
3778 if (!info->attrs[NL80211_ATTR_STA_WME])
3779 return 0;
3780
3781 nla = info->attrs[NL80211_ATTR_STA_WME];
3782 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3783 nl80211_sta_wme_policy);
3784 if (err)
3785 return err;
3786
3787 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3788 params->uapsd_queues = nla_get_u8(
3789 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3790 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3791 return -EINVAL;
3792
3793 if (tb[NL80211_STA_WME_MAX_SP])
3794 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3795
3796 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3797 return -EINVAL;
3798
3799 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3800
3801 return 0;
3802}
3803
Johannes Bergff276692013-02-15 00:09:01 +01003804static int nl80211_set_station_tdls(struct genl_info *info,
3805 struct station_parameters *params)
3806{
3807 /* Dummy STA entry gets updated once the peer capabilities are known */
3808 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3809 params->ht_capa =
3810 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3811 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3812 params->vht_capa =
3813 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3814
3815 return nl80211_parse_sta_wme(info, params);
3816}
3817
Johannes Berg5727ef12007-12-19 02:03:34 +01003818static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3819{
Johannes Berg4c476992010-10-04 21:36:35 +02003820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003821 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003822 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003823 u8 *mac_addr;
3824 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003825
3826 memset(&params, 0, sizeof(params));
3827
3828 params.listen_interval = -1;
3829
Johannes Berg77ee7c82013-02-15 00:48:33 +01003830 if (!rdev->ops->change_station)
3831 return -EOPNOTSUPP;
3832
Johannes Berg5727ef12007-12-19 02:03:34 +01003833 if (info->attrs[NL80211_ATTR_STA_AID])
3834 return -EINVAL;
3835
3836 if (!info->attrs[NL80211_ATTR_MAC])
3837 return -EINVAL;
3838
3839 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3840
3841 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3842 params.supported_rates =
3843 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3844 params.supported_rates_len =
3845 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3846 }
3847
Jouni Malinen9d62a982013-02-14 21:10:13 +02003848 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3849 params.capability =
3850 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3851 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3852 }
3853
3854 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3855 params.ext_capab =
3856 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3857 params.ext_capab_len =
3858 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3859 }
3860
Jouni Malinendf881292013-02-14 21:10:54 +02003861 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003862 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003863
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003864 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003865 return -EINVAL;
3866
Johannes Bergf8bacc22013-02-14 23:27:01 +01003867 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003868 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003869 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3870 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3871 return -EINVAL;
3872 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003873
Johannes Bergf8bacc22013-02-14 23:27:01 +01003874 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003875 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003876 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3877 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3878 return -EINVAL;
3879 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3880 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003881
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003882 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3883 enum nl80211_mesh_power_mode pm = nla_get_u32(
3884 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3885
3886 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3887 pm > NL80211_MESH_POWER_MAX)
3888 return -EINVAL;
3889
3890 params.local_pm = pm;
3891 }
3892
Johannes Berg77ee7c82013-02-15 00:48:33 +01003893 /* Include parameters for TDLS peer (will check later) */
3894 err = nl80211_set_station_tdls(info, &params);
3895 if (err)
3896 return err;
3897
3898 params.vlan = get_vlan(info, rdev);
3899 if (IS_ERR(params.vlan))
3900 return PTR_ERR(params.vlan);
3901
Johannes Berga97f4422009-06-18 17:23:43 +02003902 switch (dev->ieee80211_ptr->iftype) {
3903 case NL80211_IFTYPE_AP:
3904 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003905 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003906 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003907 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003908 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003909 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003910 break;
3911 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003912 err = -EOPNOTSUPP;
3913 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003914 }
3915
Johannes Berg77ee7c82013-02-15 00:48:33 +01003916 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003917 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003918
Johannes Berg77ee7c82013-02-15 00:48:33 +01003919 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003920 if (params.vlan)
3921 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003922
Johannes Berg5727ef12007-12-19 02:03:34 +01003923 return err;
3924}
3925
3926static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3927{
Johannes Berg4c476992010-10-04 21:36:35 +02003928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003929 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003930 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003931 struct station_parameters params;
3932 u8 *mac_addr = NULL;
3933
3934 memset(&params, 0, sizeof(params));
3935
Johannes Berg984c3112013-02-14 23:43:25 +01003936 if (!rdev->ops->add_station)
3937 return -EOPNOTSUPP;
3938
Johannes Berg5727ef12007-12-19 02:03:34 +01003939 if (!info->attrs[NL80211_ATTR_MAC])
3940 return -EINVAL;
3941
Johannes Berg5727ef12007-12-19 02:03:34 +01003942 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3943 return -EINVAL;
3944
3945 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3946 return -EINVAL;
3947
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003948 if (!info->attrs[NL80211_ATTR_STA_AID])
3949 return -EINVAL;
3950
Johannes Berg5727ef12007-12-19 02:03:34 +01003951 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3952 params.supported_rates =
3953 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3954 params.supported_rates_len =
3955 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3956 params.listen_interval =
3957 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003958
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003959 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3960 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3961 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003962
Jouni Malinen9d62a982013-02-14 21:10:13 +02003963 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3964 params.capability =
3965 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3966 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3967 }
3968
3969 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3970 params.ext_capab =
3971 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3972 params.ext_capab_len =
3973 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3974 }
3975
Jouni Malinen36aedc902008-08-25 11:58:58 +03003976 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3977 params.ht_capa =
3978 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003979
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003980 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3981 params.vht_capa =
3982 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3983
Johannes Bergf8bacc22013-02-14 23:27:01 +01003984 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07003985 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003986 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3987 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3988 return -EINVAL;
3989 }
Javier Cardona96b78df2011-04-07 15:08:33 -07003990
Johannes Bergff276692013-02-15 00:09:01 +01003991 err = nl80211_parse_sta_wme(info, &params);
3992 if (err)
3993 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003994
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003995 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003996 return -EINVAL;
3997
Johannes Berg77ee7c82013-02-15 00:48:33 +01003998 /* When you run into this, adjust the code below for the new flag */
3999 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4000
Johannes Bergbdd90d52011-12-14 12:20:27 +01004001 switch (dev->ieee80211_ptr->iftype) {
4002 case NL80211_IFTYPE_AP:
4003 case NL80211_IFTYPE_AP_VLAN:
4004 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004005 /* ignore WME attributes if iface/sta is not capable */
4006 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4007 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4008 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004009
Johannes Bergbdd90d52011-12-14 12:20:27 +01004010 /* TDLS peers cannot be added */
4011 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004012 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004013 /* but don't bother the driver with it */
4014 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004015
Johannes Bergd582cff2012-10-26 17:53:44 +02004016 /* allow authenticated/associated only if driver handles it */
4017 if (!(rdev->wiphy.features &
4018 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4019 params.sta_flags_mask &
4020 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4021 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4022 return -EINVAL;
4023
Johannes Bergbdd90d52011-12-14 12:20:27 +01004024 /* must be last in here for error handling */
4025 params.vlan = get_vlan(info, rdev);
4026 if (IS_ERR(params.vlan))
4027 return PTR_ERR(params.vlan);
4028 break;
4029 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004030 /* ignore uAPSD data */
4031 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4032
Johannes Bergd582cff2012-10-26 17:53:44 +02004033 /* associated is disallowed */
4034 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4035 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004036 /* TDLS peers cannot be added */
4037 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004038 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004039 break;
4040 case NL80211_IFTYPE_STATION:
Johannes Berg984c3112013-02-14 23:43:25 +01004041 /* ignore uAPSD data */
4042 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4043
Johannes Berg77ee7c82013-02-15 00:48:33 +01004044 /* these are disallowed */
4045 if (params.sta_flags_mask &
4046 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4047 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004048 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004049 /* Only TDLS peers can be added */
4050 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4051 return -EINVAL;
4052 /* Can only add if TDLS ... */
4053 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4054 return -EOPNOTSUPP;
4055 /* ... with external setup is supported */
4056 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4057 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004058 /*
4059 * Older wpa_supplicant versions always mark the TDLS peer
4060 * as authorized, but it shouldn't yet be.
4061 */
4062 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004063 break;
4064 default:
4065 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004066 }
4067
Johannes Bergbdd90d52011-12-14 12:20:27 +01004068 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004069
Hila Gonene35e4d22012-06-27 17:19:42 +03004070 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004071
Johannes Berg5727ef12007-12-19 02:03:34 +01004072 if (params.vlan)
4073 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004074 return err;
4075}
4076
4077static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4078{
Johannes Berg4c476992010-10-04 21:36:35 +02004079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4080 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004081 u8 *mac_addr = NULL;
4082
4083 if (info->attrs[NL80211_ATTR_MAC])
4084 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4085
Johannes Berge80cf852009-05-11 14:43:13 +02004086 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004087 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004088 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004089 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4090 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004091
Johannes Berg4c476992010-10-04 21:36:35 +02004092 if (!rdev->ops->del_station)
4093 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004094
Hila Gonene35e4d22012-06-27 17:19:42 +03004095 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004096}
4097
Eric W. Biederman15e47302012-09-07 20:12:54 +00004098static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004099 int flags, struct net_device *dev,
4100 u8 *dst, u8 *next_hop,
4101 struct mpath_info *pinfo)
4102{
4103 void *hdr;
4104 struct nlattr *pinfoattr;
4105
Eric W. Biederman15e47302012-09-07 20:12:54 +00004106 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004107 if (!hdr)
4108 return -1;
4109
David S. Miller9360ffd2012-03-29 04:41:26 -04004110 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4111 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4112 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4113 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4114 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004115
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004116 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4117 if (!pinfoattr)
4118 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004119 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4120 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4121 pinfo->frame_qlen))
4122 goto nla_put_failure;
4123 if (((pinfo->filled & MPATH_INFO_SN) &&
4124 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4125 ((pinfo->filled & MPATH_INFO_METRIC) &&
4126 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4127 pinfo->metric)) ||
4128 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4129 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4130 pinfo->exptime)) ||
4131 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4132 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4133 pinfo->flags)) ||
4134 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4135 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4136 pinfo->discovery_timeout)) ||
4137 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4138 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4139 pinfo->discovery_retries)))
4140 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004141
4142 nla_nest_end(msg, pinfoattr);
4143
4144 return genlmsg_end(msg, hdr);
4145
4146 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004147 genlmsg_cancel(msg, hdr);
4148 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004149}
4150
4151static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004152 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004153{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004154 struct mpath_info pinfo;
4155 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004156 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004157 u8 dst[ETH_ALEN];
4158 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02004159 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004160 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004161
Johannes Berg67748892010-10-04 21:14:06 +02004162 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4163 if (err)
4164 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004165
4166 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004167 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004168 goto out_err;
4169 }
4170
Jouni Malineneec60b02009-03-20 21:21:19 +02004171 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
4172 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004173 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004174 }
4175
Johannes Bergbba95fe2008-07-29 13:22:51 +02004176 while (1) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004177 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
4178 &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004179 if (err == -ENOENT)
4180 break;
4181 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004182 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004183
Eric W. Biederman15e47302012-09-07 20:12:54 +00004184 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004185 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4186 netdev, dst, next_hop,
4187 &pinfo) < 0)
4188 goto out;
4189
4190 path_idx++;
4191 }
4192
4193
4194 out:
4195 cb->args[1] = path_idx;
4196 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004197 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004198 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004199 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004200}
4201
4202static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4203{
Johannes Berg4c476992010-10-04 21:36:35 +02004204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004205 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004206 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004207 struct mpath_info pinfo;
4208 struct sk_buff *msg;
4209 u8 *dst = NULL;
4210 u8 next_hop[ETH_ALEN];
4211
4212 memset(&pinfo, 0, sizeof(pinfo));
4213
4214 if (!info->attrs[NL80211_ATTR_MAC])
4215 return -EINVAL;
4216
4217 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4218
Johannes Berg4c476992010-10-04 21:36:35 +02004219 if (!rdev->ops->get_mpath)
4220 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004221
Johannes Berg4c476992010-10-04 21:36:35 +02004222 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4223 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004224
Hila Gonene35e4d22012-06-27 17:19:42 +03004225 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004226 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004227 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004228
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004229 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004230 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004231 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004232
Eric W. Biederman15e47302012-09-07 20:12:54 +00004233 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004234 dev, dst, next_hop, &pinfo) < 0) {
4235 nlmsg_free(msg);
4236 return -ENOBUFS;
4237 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004238
Johannes Berg4c476992010-10-04 21:36:35 +02004239 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004240}
4241
4242static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4243{
Johannes Berg4c476992010-10-04 21:36:35 +02004244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4245 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004246 u8 *dst = NULL;
4247 u8 *next_hop = NULL;
4248
4249 if (!info->attrs[NL80211_ATTR_MAC])
4250 return -EINVAL;
4251
4252 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4253 return -EINVAL;
4254
4255 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4256 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4257
Johannes Berg4c476992010-10-04 21:36:35 +02004258 if (!rdev->ops->change_mpath)
4259 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004260
Johannes Berg4c476992010-10-04 21:36:35 +02004261 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4262 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004263
Hila Gonene35e4d22012-06-27 17:19:42 +03004264 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004265}
Johannes Berg4c476992010-10-04 21:36:35 +02004266
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004267static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4268{
Johannes Berg4c476992010-10-04 21:36:35 +02004269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4270 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004271 u8 *dst = NULL;
4272 u8 *next_hop = NULL;
4273
4274 if (!info->attrs[NL80211_ATTR_MAC])
4275 return -EINVAL;
4276
4277 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4278 return -EINVAL;
4279
4280 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4281 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4282
Johannes Berg4c476992010-10-04 21:36:35 +02004283 if (!rdev->ops->add_mpath)
4284 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004285
Johannes Berg4c476992010-10-04 21:36:35 +02004286 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4287 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004288
Hila Gonene35e4d22012-06-27 17:19:42 +03004289 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004290}
4291
4292static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4293{
Johannes Berg4c476992010-10-04 21:36:35 +02004294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4295 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004296 u8 *dst = NULL;
4297
4298 if (info->attrs[NL80211_ATTR_MAC])
4299 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4300
Johannes Berg4c476992010-10-04 21:36:35 +02004301 if (!rdev->ops->del_mpath)
4302 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004303
Hila Gonene35e4d22012-06-27 17:19:42 +03004304 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004305}
4306
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004307static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4308{
Johannes Berg4c476992010-10-04 21:36:35 +02004309 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4310 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004311 struct bss_parameters params;
4312
4313 memset(&params, 0, sizeof(params));
4314 /* default to not changing parameters */
4315 params.use_cts_prot = -1;
4316 params.use_short_preamble = -1;
4317 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004318 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004319 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004320 params.p2p_ctwindow = -1;
4321 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004322
4323 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4324 params.use_cts_prot =
4325 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4326 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4327 params.use_short_preamble =
4328 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4329 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4330 params.use_short_slot_time =
4331 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004332 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4333 params.basic_rates =
4334 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4335 params.basic_rates_len =
4336 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4337 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004338 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4339 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004340 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4341 params.ht_opmode =
4342 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004343
Johannes Berg53cabad2012-11-14 15:17:28 +01004344 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4345 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4346 return -EINVAL;
4347 params.p2p_ctwindow =
4348 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4349 if (params.p2p_ctwindow < 0)
4350 return -EINVAL;
4351 if (params.p2p_ctwindow != 0 &&
4352 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4353 return -EINVAL;
4354 }
4355
4356 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4357 u8 tmp;
4358
4359 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4360 return -EINVAL;
4361 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4362 if (tmp > 1)
4363 return -EINVAL;
4364 params.p2p_opp_ps = tmp;
4365 if (params.p2p_opp_ps &&
4366 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4367 return -EINVAL;
4368 }
4369
Johannes Berg4c476992010-10-04 21:36:35 +02004370 if (!rdev->ops->change_bss)
4371 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004372
Johannes Berg074ac8d2010-09-16 14:58:22 +02004373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004374 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4375 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004376
Hila Gonene35e4d22012-06-27 17:19:42 +03004377 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004378}
4379
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004380static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004381 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4382 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4383 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4384 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4385 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4386 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4387};
4388
4389static int parse_reg_rule(struct nlattr *tb[],
4390 struct ieee80211_reg_rule *reg_rule)
4391{
4392 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4393 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4394
4395 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4396 return -EINVAL;
4397 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4398 return -EINVAL;
4399 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4400 return -EINVAL;
4401 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4402 return -EINVAL;
4403 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4404 return -EINVAL;
4405
4406 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4407
4408 freq_range->start_freq_khz =
4409 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4410 freq_range->end_freq_khz =
4411 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4412 freq_range->max_bandwidth_khz =
4413 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4414
4415 power_rule->max_eirp =
4416 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4417
4418 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4419 power_rule->max_antenna_gain =
4420 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4421
4422 return 0;
4423}
4424
4425static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4426{
4427 int r;
4428 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004429 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004430
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004431 /*
4432 * You should only get this when cfg80211 hasn't yet initialized
4433 * completely when built-in to the kernel right between the time
4434 * window between nl80211_init() and regulatory_init(), if that is
4435 * even possible.
4436 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004437 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004438 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004439
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004440 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4441 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004442
4443 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4444
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004445 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4446 user_reg_hint_type =
4447 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4448 else
4449 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4450
4451 switch (user_reg_hint_type) {
4452 case NL80211_USER_REG_HINT_USER:
4453 case NL80211_USER_REG_HINT_CELL_BASE:
4454 break;
4455 default:
4456 return -EINVAL;
4457 }
4458
4459 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004460
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004461 return r;
4462}
4463
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004464static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004465 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004466{
Johannes Berg4c476992010-10-04 21:36:35 +02004467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004468 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004469 struct wireless_dev *wdev = dev->ieee80211_ptr;
4470 struct mesh_config cur_params;
4471 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004472 void *hdr;
4473 struct nlattr *pinfoattr;
4474 struct sk_buff *msg;
4475
Johannes Berg29cbe682010-12-03 09:20:44 +01004476 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4477 return -EOPNOTSUPP;
4478
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004479 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004480 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004481
Johannes Berg29cbe682010-12-03 09:20:44 +01004482 wdev_lock(wdev);
4483 /* If not connected, get default parameters */
4484 if (!wdev->mesh_id_len)
4485 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4486 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004487 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004488 wdev_unlock(wdev);
4489
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004490 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004491 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004492
4493 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004494 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004495 if (!msg)
4496 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004497 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004498 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004499 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004500 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004501 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004502 if (!pinfoattr)
4503 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004504 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4505 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4506 cur_params.dot11MeshRetryTimeout) ||
4507 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4508 cur_params.dot11MeshConfirmTimeout) ||
4509 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4510 cur_params.dot11MeshHoldingTimeout) ||
4511 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4512 cur_params.dot11MeshMaxPeerLinks) ||
4513 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4514 cur_params.dot11MeshMaxRetries) ||
4515 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4516 cur_params.dot11MeshTTL) ||
4517 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4518 cur_params.element_ttl) ||
4519 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4520 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004521 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4522 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004523 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4524 cur_params.dot11MeshHWMPmaxPREQretries) ||
4525 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4526 cur_params.path_refresh_time) ||
4527 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4528 cur_params.min_discovery_timeout) ||
4529 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4530 cur_params.dot11MeshHWMPactivePathTimeout) ||
4531 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4532 cur_params.dot11MeshHWMPpreqMinInterval) ||
4533 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4534 cur_params.dot11MeshHWMPperrMinInterval) ||
4535 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4536 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4537 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4538 cur_params.dot11MeshHWMPRootMode) ||
4539 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4540 cur_params.dot11MeshHWMPRannInterval) ||
4541 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4542 cur_params.dot11MeshGateAnnouncementProtocol) ||
4543 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4544 cur_params.dot11MeshForwarding) ||
4545 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004546 cur_params.rssi_threshold) ||
4547 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004548 cur_params.ht_opmode) ||
4549 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4550 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4551 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004552 cur_params.dot11MeshHWMProotInterval) ||
4553 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004554 cur_params.dot11MeshHWMPconfirmationInterval) ||
4555 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4556 cur_params.power_mode) ||
4557 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4558 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004559 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004560 nla_nest_end(msg, pinfoattr);
4561 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004562 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004563
Johannes Berg3b858752009-03-12 09:55:09 +01004564 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004565 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004566 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004567 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004568 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004569}
4570
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004571static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004572 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4573 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4574 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4575 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4576 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4577 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004578 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004579 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004580 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004581 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4582 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4583 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4584 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4585 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004586 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004587 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004588 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004589 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004590 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004591 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004592 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4593 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004594 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4595 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004596 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004597 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4598 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004599};
4600
Javier Cardonac80d5452010-12-16 17:37:49 -08004601static const struct nla_policy
4602 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004603 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004604 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4605 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004606 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004607 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004608 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004609 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004610};
4611
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004612static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004613 struct mesh_config *cfg,
4614 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004615{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004616 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004617 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004618
Marco Porschea54fba2013-01-07 16:04:48 +01004619#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4620do { \
4621 if (tb[attr]) { \
4622 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4623 return -EINVAL; \
4624 cfg->param = fn(tb[attr]); \
4625 mask |= (1 << (attr - 1)); \
4626 } \
4627} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004628
4629
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004630 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004631 return -EINVAL;
4632 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004633 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004634 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004635 return -EINVAL;
4636
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004637 /* This makes sure that there aren't more than 32 mesh config
4638 * parameters (otherwise our bitfield scheme would not work.) */
4639 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4640
4641 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004642 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004643 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4644 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004645 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004646 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4647 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004648 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004649 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4650 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004651 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004652 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4653 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004654 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004655 mask, NL80211_MESHCONF_MAX_RETRIES,
4656 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004657 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004658 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004659 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004660 mask, NL80211_MESHCONF_ELEMENT_TTL,
4661 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004662 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004663 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4664 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004665 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4666 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004667 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4668 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004669 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004670 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4671 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004673 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4674 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004676 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4677 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4679 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004680 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4681 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004682 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004683 1, 65535, mask,
4684 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004685 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004686 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004687 1, 65535, mask,
4688 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004689 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004691 dot11MeshHWMPnetDiameterTraversalTime,
4692 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004693 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4694 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4696 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4697 nla_get_u8);
4698 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4699 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004700 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004701 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004702 dot11MeshGateAnnouncementProtocol, 0, 1,
4703 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004704 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004706 mask, NL80211_MESHCONF_FORWARDING,
4707 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004708 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004709 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4710 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004711 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004712 mask, NL80211_MESHCONF_HT_OPMODE,
4713 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004714 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004715 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004716 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4717 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004719 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4720 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004721 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004722 dot11MeshHWMPconfirmationInterval,
4723 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004724 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4725 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004726 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4727 NL80211_MESH_POWER_ACTIVE,
4728 NL80211_MESH_POWER_MAX,
4729 mask, NL80211_MESHCONF_POWER_MODE,
4730 nla_get_u32);
4731 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4732 0, 65535, mask,
4733 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004734 if (mask_out)
4735 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004736
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004737 return 0;
4738
4739#undef FILL_IN_MESH_PARAM_IF_SET
4740}
4741
Javier Cardonac80d5452010-12-16 17:37:49 -08004742static int nl80211_parse_mesh_setup(struct genl_info *info,
4743 struct mesh_setup *setup)
4744{
4745 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4746
4747 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4748 return -EINVAL;
4749 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4750 info->attrs[NL80211_ATTR_MESH_SETUP],
4751 nl80211_mesh_setup_params_policy))
4752 return -EINVAL;
4753
Javier Cardonad299a1f2012-03-31 11:31:33 -07004754 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4755 setup->sync_method =
4756 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4757 IEEE80211_SYNC_METHOD_VENDOR :
4758 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4759
Javier Cardonac80d5452010-12-16 17:37:49 -08004760 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4761 setup->path_sel_proto =
4762 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4763 IEEE80211_PATH_PROTOCOL_VENDOR :
4764 IEEE80211_PATH_PROTOCOL_HWMP;
4765
4766 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4767 setup->path_metric =
4768 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4769 IEEE80211_PATH_METRIC_VENDOR :
4770 IEEE80211_PATH_METRIC_AIRTIME;
4771
Javier Cardona581a8b02011-04-07 15:08:27 -07004772
4773 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004774 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004775 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004776 if (!is_valid_ie_attr(ieattr))
4777 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004778 setup->ie = nla_data(ieattr);
4779 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004780 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07004781 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4782 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08004783
4784 return 0;
4785}
4786
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004787static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004788 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004789{
4790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4791 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004792 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004793 struct mesh_config cfg;
4794 u32 mask;
4795 int err;
4796
Johannes Berg29cbe682010-12-03 09:20:44 +01004797 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4798 return -EOPNOTSUPP;
4799
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004800 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004801 return -EOPNOTSUPP;
4802
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004803 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004804 if (err)
4805 return err;
4806
Johannes Berg29cbe682010-12-03 09:20:44 +01004807 wdev_lock(wdev);
4808 if (!wdev->mesh_id_len)
4809 err = -ENOLINK;
4810
4811 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004812 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004813
4814 wdev_unlock(wdev);
4815
4816 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004817}
4818
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004819static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4820{
Johannes Berg458f4f92012-12-06 15:47:38 +01004821 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004822 struct sk_buff *msg;
4823 void *hdr = NULL;
4824 struct nlattr *nl_reg_rules;
4825 unsigned int i;
4826 int err = -EINVAL;
4827
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004828 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004829
4830 if (!cfg80211_regdomain)
4831 goto out;
4832
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004833 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004834 if (!msg) {
4835 err = -ENOBUFS;
4836 goto out;
4837 }
4838
Eric W. Biederman15e47302012-09-07 20:12:54 +00004839 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004840 NL80211_CMD_GET_REG);
4841 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004842 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004843
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004844 if (reg_last_request_cell_base() &&
4845 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4846 NL80211_USER_REG_HINT_CELL_BASE))
4847 goto nla_put_failure;
4848
Johannes Berg458f4f92012-12-06 15:47:38 +01004849 rcu_read_lock();
4850 regdom = rcu_dereference(cfg80211_regdomain);
4851
4852 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4853 (regdom->dfs_region &&
4854 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4855 goto nla_put_failure_rcu;
4856
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004857 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4858 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004859 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004860
Johannes Berg458f4f92012-12-06 15:47:38 +01004861 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004862 struct nlattr *nl_reg_rule;
4863 const struct ieee80211_reg_rule *reg_rule;
4864 const struct ieee80211_freq_range *freq_range;
4865 const struct ieee80211_power_rule *power_rule;
4866
Johannes Berg458f4f92012-12-06 15:47:38 +01004867 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004868 freq_range = &reg_rule->freq_range;
4869 power_rule = &reg_rule->power_rule;
4870
4871 nl_reg_rule = nla_nest_start(msg, i);
4872 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004873 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004874
David S. Miller9360ffd2012-03-29 04:41:26 -04004875 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4876 reg_rule->flags) ||
4877 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4878 freq_range->start_freq_khz) ||
4879 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4880 freq_range->end_freq_khz) ||
4881 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4882 freq_range->max_bandwidth_khz) ||
4883 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4884 power_rule->max_antenna_gain) ||
4885 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4886 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004887 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004888
4889 nla_nest_end(msg, nl_reg_rule);
4890 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004891 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004892
4893 nla_nest_end(msg, nl_reg_rules);
4894
4895 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004896 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004897 goto out;
4898
Johannes Berg458f4f92012-12-06 15:47:38 +01004899nla_put_failure_rcu:
4900 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004901nla_put_failure:
4902 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004903put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004904 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004905 err = -EMSGSIZE;
4906out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004907 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004908 return err;
4909}
4910
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004911static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4912{
4913 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4914 struct nlattr *nl_reg_rule;
4915 char *alpha2 = NULL;
4916 int rem_reg_rules = 0, r = 0;
4917 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004918 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004919 struct ieee80211_regdomain *rd = NULL;
4920
4921 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4922 return -EINVAL;
4923
4924 if (!info->attrs[NL80211_ATTR_REG_RULES])
4925 return -EINVAL;
4926
4927 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4928
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004929 if (info->attrs[NL80211_ATTR_DFS_REGION])
4930 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4931
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004932 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004933 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004934 num_rules++;
4935 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004936 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004937 }
4938
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004939 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004940 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004941
4942 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004943 if (!rd)
4944 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004945
4946 rd->n_reg_rules = num_rules;
4947 rd->alpha2[0] = alpha2[0];
4948 rd->alpha2[1] = alpha2[1];
4949
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004950 /*
4951 * Disable DFS master mode if the DFS region was
4952 * not supported or known on this kernel.
4953 */
4954 if (reg_supported_dfs_region(dfs_region))
4955 rd->dfs_region = dfs_region;
4956
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004957 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004958 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004959 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004960 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4961 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004962 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4963 if (r)
4964 goto bad_reg;
4965
4966 rule_idx++;
4967
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004968 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4969 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004970 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004971 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004972 }
4973
Johannes Berg6913b492012-12-04 00:48:59 +01004974 mutex_lock(&cfg80211_mutex);
4975
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004976 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01004977 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01004978 rd = NULL;
Johannes Berg6913b492012-12-04 00:48:59 +01004979 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004980
Johannes Bergd2372b32008-10-24 20:32:20 +02004981 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004982 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004983 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004984}
4985
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004986static int validate_scan_freqs(struct nlattr *freqs)
4987{
4988 struct nlattr *attr1, *attr2;
4989 int n_channels = 0, tmp1, tmp2;
4990
4991 nla_for_each_nested(attr1, freqs, tmp1) {
4992 n_channels++;
4993 /*
4994 * Some hardware has a limited channel list for
4995 * scanning, and it is pretty much nonsensical
4996 * to scan for a channel twice, so disallow that
4997 * and don't require drivers to check that the
4998 * channel list they get isn't longer than what
4999 * they can scan, as long as they can scan all
5000 * the channels they registered at once.
5001 */
5002 nla_for_each_nested(attr2, freqs, tmp2)
5003 if (attr1 != attr2 &&
5004 nla_get_u32(attr1) == nla_get_u32(attr2))
5005 return 0;
5006 }
5007
5008 return n_channels;
5009}
5010
Johannes Berg2a519312009-02-10 21:25:55 +01005011static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5012{
Johannes Berg4c476992010-10-04 21:36:35 +02005013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005014 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005015 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005016 struct nlattr *attr;
5017 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005018 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005019 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005020
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005021 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5022 return -EINVAL;
5023
Johannes Berg79c97e92009-07-07 03:56:12 +02005024 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005025
Johannes Berg4c476992010-10-04 21:36:35 +02005026 if (!rdev->ops->scan)
5027 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005028
Johannes Berg4c476992010-10-04 21:36:35 +02005029 if (rdev->scan_req)
5030 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01005031
5032 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005033 n_channels = validate_scan_freqs(
5034 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02005035 if (!n_channels)
5036 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005037 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005038 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005039 n_channels = 0;
5040
Johannes Berg2a519312009-02-10 21:25:55 +01005041 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5042 if (wiphy->bands[band])
5043 n_channels += wiphy->bands[band]->n_channels;
5044 }
5045
5046 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5047 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5048 n_ssids++;
5049
Johannes Berg4c476992010-10-04 21:36:35 +02005050 if (n_ssids > wiphy->max_scan_ssids)
5051 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01005052
Jouni Malinen70692ad2009-02-16 19:39:13 +02005053 if (info->attrs[NL80211_ATTR_IE])
5054 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5055 else
5056 ie_len = 0;
5057
Johannes Berg4c476992010-10-04 21:36:35 +02005058 if (ie_len > wiphy->max_scan_ie_len)
5059 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02005060
Johannes Berg2a519312009-02-10 21:25:55 +01005061 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005062 + sizeof(*request->ssids) * n_ssids
5063 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005064 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005065 if (!request)
5066 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01005067
Johannes Berg2a519312009-02-10 21:25:55 +01005068 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005069 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005070 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005071 if (ie_len) {
5072 if (request->ssids)
5073 request->ie = (void *)(request->ssids + n_ssids);
5074 else
5075 request->ie = (void *)(request->channels + n_channels);
5076 }
Johannes Berg2a519312009-02-10 21:25:55 +01005077
Johannes Berg584991d2009-11-02 13:32:03 +01005078 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005079 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5080 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005081 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005082 struct ieee80211_channel *chan;
5083
5084 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5085
5086 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005087 err = -EINVAL;
5088 goto out_free;
5089 }
Johannes Berg584991d2009-11-02 13:32:03 +01005090
5091 /* ignore disabled channels */
5092 if (chan->flags & IEEE80211_CHAN_DISABLED)
5093 continue;
5094
5095 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005096 i++;
5097 }
5098 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005099 enum ieee80211_band band;
5100
Johannes Berg2a519312009-02-10 21:25:55 +01005101 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005102 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5103 int j;
5104 if (!wiphy->bands[band])
5105 continue;
5106 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005107 struct ieee80211_channel *chan;
5108
5109 chan = &wiphy->bands[band]->channels[j];
5110
5111 if (chan->flags & IEEE80211_CHAN_DISABLED)
5112 continue;
5113
5114 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005115 i++;
5116 }
5117 }
5118 }
5119
Johannes Berg584991d2009-11-02 13:32:03 +01005120 if (!i) {
5121 err = -EINVAL;
5122 goto out_free;
5123 }
5124
5125 request->n_channels = i;
5126
Johannes Berg2a519312009-02-10 21:25:55 +01005127 i = 0;
5128 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5129 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005130 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005131 err = -EINVAL;
5132 goto out_free;
5133 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005134 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005135 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005136 i++;
5137 }
5138 }
5139
Jouni Malinen70692ad2009-02-16 19:39:13 +02005140 if (info->attrs[NL80211_ATTR_IE]) {
5141 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005142 memcpy((void *)request->ie,
5143 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005144 request->ie_len);
5145 }
5146
Johannes Berg34850ab2011-07-18 18:08:35 +02005147 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005148 if (wiphy->bands[i])
5149 request->rates[i] =
5150 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005151
5152 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5153 nla_for_each_nested(attr,
5154 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5155 tmp) {
5156 enum ieee80211_band band = nla_type(attr);
5157
Dan Carpenter84404622011-07-29 11:52:18 +03005158 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005159 err = -EINVAL;
5160 goto out_free;
5161 }
5162 err = ieee80211_get_ratemask(wiphy->bands[band],
5163 nla_data(attr),
5164 nla_len(attr),
5165 &request->rates[band]);
5166 if (err)
5167 goto out_free;
5168 }
5169 }
5170
Sam Leffler46856bb2012-10-11 21:03:32 -07005171 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005172 request->flags = nla_get_u32(
5173 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005174 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5175 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5176 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5177 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005178 err = -EOPNOTSUPP;
5179 goto out_free;
5180 }
5181 }
Sam Lefflered4737712012-10-11 21:03:31 -07005182
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305183 request->no_cck =
5184 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5185
Johannes Bergfd014282012-06-18 19:17:03 +02005186 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005187 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005188 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005189
Johannes Berg79c97e92009-07-07 03:56:12 +02005190 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005191 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005192
Johannes Berg463d0182009-07-14 00:33:35 +02005193 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005194 nl80211_send_scan_start(rdev, wdev);
5195 if (wdev->netdev)
5196 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005197 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005198 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005199 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005200 kfree(request);
5201 }
Johannes Berg3b858752009-03-12 09:55:09 +01005202
Johannes Berg2a519312009-02-10 21:25:55 +01005203 return err;
5204}
5205
Luciano Coelho807f8a82011-05-11 17:09:35 +03005206static int nl80211_start_sched_scan(struct sk_buff *skb,
5207 struct genl_info *info)
5208{
5209 struct cfg80211_sched_scan_request *request;
5210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5211 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005212 struct nlattr *attr;
5213 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005214 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005215 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005216 enum ieee80211_band band;
5217 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005218 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005219
5220 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5221 !rdev->ops->sched_scan_start)
5222 return -EOPNOTSUPP;
5223
5224 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5225 return -EINVAL;
5226
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005227 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5228 return -EINVAL;
5229
5230 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5231 if (interval == 0)
5232 return -EINVAL;
5233
Luciano Coelho807f8a82011-05-11 17:09:35 +03005234 wiphy = &rdev->wiphy;
5235
5236 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5237 n_channels = validate_scan_freqs(
5238 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5239 if (!n_channels)
5240 return -EINVAL;
5241 } else {
5242 n_channels = 0;
5243
5244 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5245 if (wiphy->bands[band])
5246 n_channels += wiphy->bands[band]->n_channels;
5247 }
5248
5249 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5250 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5251 tmp)
5252 n_ssids++;
5253
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005254 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005255 return -EINVAL;
5256
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005257 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5258 nla_for_each_nested(attr,
5259 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5260 tmp)
5261 n_match_sets++;
5262
5263 if (n_match_sets > wiphy->max_match_sets)
5264 return -EINVAL;
5265
Luciano Coelho807f8a82011-05-11 17:09:35 +03005266 if (info->attrs[NL80211_ATTR_IE])
5267 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5268 else
5269 ie_len = 0;
5270
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005271 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005272 return -EINVAL;
5273
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005274 mutex_lock(&rdev->sched_scan_mtx);
5275
5276 if (rdev->sched_scan_req) {
5277 err = -EINPROGRESS;
5278 goto out;
5279 }
5280
Luciano Coelho807f8a82011-05-11 17:09:35 +03005281 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005282 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005283 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005284 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005285 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005286 if (!request) {
5287 err = -ENOMEM;
5288 goto out;
5289 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005290
5291 if (n_ssids)
5292 request->ssids = (void *)&request->channels[n_channels];
5293 request->n_ssids = n_ssids;
5294 if (ie_len) {
5295 if (request->ssids)
5296 request->ie = (void *)(request->ssids + n_ssids);
5297 else
5298 request->ie = (void *)(request->channels + n_channels);
5299 }
5300
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005301 if (n_match_sets) {
5302 if (request->ie)
5303 request->match_sets = (void *)(request->ie + ie_len);
5304 else if (request->ssids)
5305 request->match_sets =
5306 (void *)(request->ssids + n_ssids);
5307 else
5308 request->match_sets =
5309 (void *)(request->channels + n_channels);
5310 }
5311 request->n_match_sets = n_match_sets;
5312
Luciano Coelho807f8a82011-05-11 17:09:35 +03005313 i = 0;
5314 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5315 /* user specified, bail out if channel not found */
5316 nla_for_each_nested(attr,
5317 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5318 tmp) {
5319 struct ieee80211_channel *chan;
5320
5321 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5322
5323 if (!chan) {
5324 err = -EINVAL;
5325 goto out_free;
5326 }
5327
5328 /* ignore disabled channels */
5329 if (chan->flags & IEEE80211_CHAN_DISABLED)
5330 continue;
5331
5332 request->channels[i] = chan;
5333 i++;
5334 }
5335 } else {
5336 /* all channels */
5337 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5338 int j;
5339 if (!wiphy->bands[band])
5340 continue;
5341 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5342 struct ieee80211_channel *chan;
5343
5344 chan = &wiphy->bands[band]->channels[j];
5345
5346 if (chan->flags & IEEE80211_CHAN_DISABLED)
5347 continue;
5348
5349 request->channels[i] = chan;
5350 i++;
5351 }
5352 }
5353 }
5354
5355 if (!i) {
5356 err = -EINVAL;
5357 goto out_free;
5358 }
5359
5360 request->n_channels = i;
5361
5362 i = 0;
5363 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5364 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5365 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005366 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005367 err = -EINVAL;
5368 goto out_free;
5369 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005370 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005371 memcpy(request->ssids[i].ssid, nla_data(attr),
5372 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005373 i++;
5374 }
5375 }
5376
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005377 i = 0;
5378 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5379 nla_for_each_nested(attr,
5380 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5381 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005382 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005383
5384 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5385 nla_data(attr), nla_len(attr),
5386 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005387 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005388 if (ssid) {
5389 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5390 err = -EINVAL;
5391 goto out_free;
5392 }
5393 memcpy(request->match_sets[i].ssid.ssid,
5394 nla_data(ssid), nla_len(ssid));
5395 request->match_sets[i].ssid.ssid_len =
5396 nla_len(ssid);
5397 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005398 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5399 if (rssi)
5400 request->rssi_thold = nla_get_u32(rssi);
5401 else
5402 request->rssi_thold =
5403 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005404 i++;
5405 }
5406 }
5407
Luciano Coelho807f8a82011-05-11 17:09:35 +03005408 if (info->attrs[NL80211_ATTR_IE]) {
5409 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5410 memcpy((void *)request->ie,
5411 nla_data(info->attrs[NL80211_ATTR_IE]),
5412 request->ie_len);
5413 }
5414
Sam Leffler46856bb2012-10-11 21:03:32 -07005415 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005416 request->flags = nla_get_u32(
5417 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005418 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5419 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5420 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5421 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005422 err = -EOPNOTSUPP;
5423 goto out_free;
5424 }
5425 }
Sam Lefflered4737712012-10-11 21:03:31 -07005426
Luciano Coelho807f8a82011-05-11 17:09:35 +03005427 request->dev = dev;
5428 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005429 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005430 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005431
Hila Gonene35e4d22012-06-27 17:19:42 +03005432 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005433 if (!err) {
5434 rdev->sched_scan_req = request;
5435 nl80211_send_sched_scan(rdev, dev,
5436 NL80211_CMD_START_SCHED_SCAN);
5437 goto out;
5438 }
5439
5440out_free:
5441 kfree(request);
5442out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005443 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005444 return err;
5445}
5446
5447static int nl80211_stop_sched_scan(struct sk_buff *skb,
5448 struct genl_info *info)
5449{
5450 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005451 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005452
5453 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5454 !rdev->ops->sched_scan_stop)
5455 return -EOPNOTSUPP;
5456
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005457 mutex_lock(&rdev->sched_scan_mtx);
5458 err = __cfg80211_stop_sched_scan(rdev, false);
5459 mutex_unlock(&rdev->sched_scan_mtx);
5460
5461 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005462}
5463
Simon Wunderlich04f39042013-02-08 18:16:19 +01005464static int nl80211_start_radar_detection(struct sk_buff *skb,
5465 struct genl_info *info)
5466{
5467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5468 struct net_device *dev = info->user_ptr[1];
5469 struct wireless_dev *wdev = dev->ieee80211_ptr;
5470 struct cfg80211_chan_def chandef;
5471 int err;
5472
5473 err = nl80211_parse_chandef(rdev, info, &chandef);
5474 if (err)
5475 return err;
5476
5477 if (wdev->cac_started)
5478 return -EBUSY;
5479
5480 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5481 if (err < 0)
5482 return err;
5483
5484 if (err == 0)
5485 return -EINVAL;
5486
5487 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5488 return -EINVAL;
5489
5490 if (!rdev->ops->start_radar_detection)
5491 return -EOPNOTSUPP;
5492
5493 mutex_lock(&rdev->devlist_mtx);
5494 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5495 chandef.chan, CHAN_MODE_SHARED,
5496 BIT(chandef.width));
5497 if (err)
5498 goto err_locked;
5499
5500 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5501 if (!err) {
5502 wdev->channel = chandef.chan;
5503 wdev->cac_started = true;
5504 wdev->cac_start_time = jiffies;
5505 }
5506err_locked:
5507 mutex_unlock(&rdev->devlist_mtx);
5508
5509 return err;
5510}
5511
Johannes Berg9720bb32011-06-21 09:45:33 +02005512static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5513 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005514 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005515 struct wireless_dev *wdev,
5516 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005517{
Johannes Berg48ab9052009-07-10 18:42:31 +02005518 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005519 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005520 void *hdr;
5521 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005522 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005523
5524 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005525
Eric W. Biederman15e47302012-09-07 20:12:54 +00005526 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005527 NL80211_CMD_NEW_SCAN_RESULTS);
5528 if (!hdr)
5529 return -1;
5530
Johannes Berg9720bb32011-06-21 09:45:33 +02005531 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5532
David S. Miller9360ffd2012-03-29 04:41:26 -04005533 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5534 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5535 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005536
5537 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5538 if (!bss)
5539 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005540 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005541 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005542 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005543
5544 rcu_read_lock();
5545 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005546 if (ies) {
5547 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5548 goto fail_unlock_rcu;
5549 tsf = true;
5550 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5551 ies->len, ies->data))
5552 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005553 }
5554 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005555 if (ies) {
5556 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5557 goto fail_unlock_rcu;
5558 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5559 ies->len, ies->data))
5560 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005561 }
5562 rcu_read_unlock();
5563
David S. Miller9360ffd2012-03-29 04:41:26 -04005564 if (res->beacon_interval &&
5565 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5566 goto nla_put_failure;
5567 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5568 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5569 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5570 jiffies_to_msecs(jiffies - intbss->ts)))
5571 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005572
Johannes Berg77965c92009-02-18 18:45:06 +01005573 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005574 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005575 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5576 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005577 break;
5578 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005579 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5580 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005581 break;
5582 default:
5583 break;
5584 }
5585
Johannes Berg48ab9052009-07-10 18:42:31 +02005586 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005587 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005588 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005589 if (intbss == wdev->current_bss &&
5590 nla_put_u32(msg, NL80211_BSS_STATUS,
5591 NL80211_BSS_STATUS_ASSOCIATED))
5592 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005593 break;
5594 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005595 if (intbss == wdev->current_bss &&
5596 nla_put_u32(msg, NL80211_BSS_STATUS,
5597 NL80211_BSS_STATUS_IBSS_JOINED))
5598 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005599 break;
5600 default:
5601 break;
5602 }
5603
Johannes Berg2a519312009-02-10 21:25:55 +01005604 nla_nest_end(msg, bss);
5605
5606 return genlmsg_end(msg, hdr);
5607
Johannes Berg8cef2c92013-02-05 16:54:31 +01005608 fail_unlock_rcu:
5609 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005610 nla_put_failure:
5611 genlmsg_cancel(msg, hdr);
5612 return -EMSGSIZE;
5613}
5614
5615static int nl80211_dump_scan(struct sk_buff *skb,
5616 struct netlink_callback *cb)
5617{
Johannes Berg48ab9052009-07-10 18:42:31 +02005618 struct cfg80211_registered_device *rdev;
5619 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01005620 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005621 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005622 int start = cb->args[1], idx = 0;
5623 int err;
5624
Johannes Berg67748892010-10-04 21:14:06 +02005625 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5626 if (err)
5627 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005628
Johannes Berg48ab9052009-07-10 18:42:31 +02005629 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01005630
Johannes Berg48ab9052009-07-10 18:42:31 +02005631 wdev_lock(wdev);
5632 spin_lock_bh(&rdev->bss_lock);
5633 cfg80211_bss_expire(rdev);
5634
Johannes Berg9720bb32011-06-21 09:45:33 +02005635 cb->seq = rdev->bss_generation;
5636
Johannes Berg48ab9052009-07-10 18:42:31 +02005637 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005638 if (++idx <= start)
5639 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005640 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005641 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005642 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005643 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005644 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005645 }
5646 }
5647
Johannes Berg48ab9052009-07-10 18:42:31 +02005648 spin_unlock_bh(&rdev->bss_lock);
5649 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005650
5651 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02005652 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005653
Johannes Berg67748892010-10-04 21:14:06 +02005654 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005655}
5656
Eric W. Biederman15e47302012-09-07 20:12:54 +00005657static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005658 int flags, struct net_device *dev,
5659 struct survey_info *survey)
5660{
5661 void *hdr;
5662 struct nlattr *infoattr;
5663
Eric W. Biederman15e47302012-09-07 20:12:54 +00005664 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005665 NL80211_CMD_NEW_SURVEY_RESULTS);
5666 if (!hdr)
5667 return -ENOMEM;
5668
David S. Miller9360ffd2012-03-29 04:41:26 -04005669 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5670 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005671
5672 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5673 if (!infoattr)
5674 goto nla_put_failure;
5675
David S. Miller9360ffd2012-03-29 04:41:26 -04005676 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5677 survey->channel->center_freq))
5678 goto nla_put_failure;
5679
5680 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5681 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5682 goto nla_put_failure;
5683 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5684 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5685 goto nla_put_failure;
5686 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5687 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5688 survey->channel_time))
5689 goto nla_put_failure;
5690 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5691 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5692 survey->channel_time_busy))
5693 goto nla_put_failure;
5694 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5695 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5696 survey->channel_time_ext_busy))
5697 goto nla_put_failure;
5698 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5699 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5700 survey->channel_time_rx))
5701 goto nla_put_failure;
5702 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5703 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5704 survey->channel_time_tx))
5705 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005706
5707 nla_nest_end(msg, infoattr);
5708
5709 return genlmsg_end(msg, hdr);
5710
5711 nla_put_failure:
5712 genlmsg_cancel(msg, hdr);
5713 return -EMSGSIZE;
5714}
5715
5716static int nl80211_dump_survey(struct sk_buff *skb,
5717 struct netlink_callback *cb)
5718{
5719 struct survey_info survey;
5720 struct cfg80211_registered_device *dev;
5721 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01005722 int survey_idx = cb->args[1];
5723 int res;
5724
Johannes Berg67748892010-10-04 21:14:06 +02005725 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5726 if (res)
5727 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005728
5729 if (!dev->ops->dump_survey) {
5730 res = -EOPNOTSUPP;
5731 goto out_err;
5732 }
5733
5734 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005735 struct ieee80211_channel *chan;
5736
Hila Gonene35e4d22012-06-27 17:19:42 +03005737 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005738 if (res == -ENOENT)
5739 break;
5740 if (res)
5741 goto out_err;
5742
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005743 /* Survey without a channel doesn't make sense */
5744 if (!survey.channel) {
5745 res = -EINVAL;
5746 goto out;
5747 }
5748
5749 chan = ieee80211_get_channel(&dev->wiphy,
5750 survey.channel->center_freq);
5751 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5752 survey_idx++;
5753 continue;
5754 }
5755
Holger Schurig61fa7132009-11-11 12:25:40 +01005756 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005757 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005758 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5759 netdev,
5760 &survey) < 0)
5761 goto out;
5762 survey_idx++;
5763 }
5764
5765 out:
5766 cb->args[1] = survey_idx;
5767 res = skb->len;
5768 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02005769 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005770 return res;
5771}
5772
Samuel Ortizb23aa672009-07-01 21:26:54 +02005773static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5774{
5775 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5776 NL80211_WPA_VERSION_2));
5777}
5778
Jouni Malinen636a5d32009-03-19 13:39:22 +02005779static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5780{
Johannes Berg4c476992010-10-04 21:36:35 +02005781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5782 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005783 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005784 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5785 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005786 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005787 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005788 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005789
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005790 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5791 return -EINVAL;
5792
5793 if (!info->attrs[NL80211_ATTR_MAC])
5794 return -EINVAL;
5795
Jouni Malinen17780922009-03-27 20:52:47 +02005796 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5797 return -EINVAL;
5798
Johannes Berg19957bb2009-07-02 17:20:43 +02005799 if (!info->attrs[NL80211_ATTR_SSID])
5800 return -EINVAL;
5801
5802 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5803 return -EINVAL;
5804
Johannes Bergfffd0932009-07-08 14:22:54 +02005805 err = nl80211_parse_key(info, &key);
5806 if (err)
5807 return err;
5808
5809 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005810 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5811 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005812 if (!key.p.key || !key.p.key_len)
5813 return -EINVAL;
5814 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5815 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5816 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5817 key.p.key_len != WLAN_KEY_LEN_WEP104))
5818 return -EINVAL;
5819 if (key.idx > 4)
5820 return -EINVAL;
5821 } else {
5822 key.p.key_len = 0;
5823 key.p.key = NULL;
5824 }
5825
Johannes Bergafea0b72010-08-10 09:46:42 +02005826 if (key.idx >= 0) {
5827 int i;
5828 bool ok = false;
5829 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5830 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5831 ok = true;
5832 break;
5833 }
5834 }
Johannes Berg4c476992010-10-04 21:36:35 +02005835 if (!ok)
5836 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005837 }
5838
Johannes Berg4c476992010-10-04 21:36:35 +02005839 if (!rdev->ops->auth)
5840 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005841
Johannes Berg074ac8d2010-09-16 14:58:22 +02005842 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005843 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5844 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005845
Johannes Berg19957bb2009-07-02 17:20:43 +02005846 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005847 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005848 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005849 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5850 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005851
Johannes Berg19957bb2009-07-02 17:20:43 +02005852 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5853 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5854
5855 if (info->attrs[NL80211_ATTR_IE]) {
5856 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5857 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5858 }
5859
5860 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005861 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005862 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005863
Jouni Malinene39e5b52012-09-30 19:29:39 +03005864 if (auth_type == NL80211_AUTHTYPE_SAE &&
5865 !info->attrs[NL80211_ATTR_SAE_DATA])
5866 return -EINVAL;
5867
5868 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5869 if (auth_type != NL80211_AUTHTYPE_SAE)
5870 return -EINVAL;
5871 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5872 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5873 /* need to include at least Auth Transaction and Status Code */
5874 if (sae_data_len < 4)
5875 return -EINVAL;
5876 }
5877
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005878 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5879
Johannes Berg95de8172012-01-20 13:55:25 +01005880 /*
5881 * Since we no longer track auth state, ignore
5882 * requests to only change local state.
5883 */
5884 if (local_state_change)
5885 return 0;
5886
Johannes Berg4c476992010-10-04 21:36:35 +02005887 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5888 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005889 key.p.key, key.p.key_len, key.idx,
5890 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005891}
5892
Johannes Bergc0692b82010-08-27 14:26:53 +03005893static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5894 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005895 struct cfg80211_crypto_settings *settings,
5896 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005897{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005898 memset(settings, 0, sizeof(*settings));
5899
Samuel Ortizb23aa672009-07-01 21:26:54 +02005900 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5901
Johannes Bergc0692b82010-08-27 14:26:53 +03005902 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5903 u16 proto;
5904 proto = nla_get_u16(
5905 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5906 settings->control_port_ethertype = cpu_to_be16(proto);
5907 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5908 proto != ETH_P_PAE)
5909 return -EINVAL;
5910 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5911 settings->control_port_no_encrypt = true;
5912 } else
5913 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5914
Samuel Ortizb23aa672009-07-01 21:26:54 +02005915 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5916 void *data;
5917 int len, i;
5918
5919 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5920 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5921 settings->n_ciphers_pairwise = len / sizeof(u32);
5922
5923 if (len % sizeof(u32))
5924 return -EINVAL;
5925
Johannes Berg3dc27d22009-07-02 21:36:37 +02005926 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005927 return -EINVAL;
5928
5929 memcpy(settings->ciphers_pairwise, data, len);
5930
5931 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005932 if (!cfg80211_supported_cipher_suite(
5933 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005934 settings->ciphers_pairwise[i]))
5935 return -EINVAL;
5936 }
5937
5938 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5939 settings->cipher_group =
5940 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005941 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5942 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005943 return -EINVAL;
5944 }
5945
5946 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5947 settings->wpa_versions =
5948 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5949 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5950 return -EINVAL;
5951 }
5952
5953 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5954 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005955 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005956
5957 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5958 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5959 settings->n_akm_suites = len / sizeof(u32);
5960
5961 if (len % sizeof(u32))
5962 return -EINVAL;
5963
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005964 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5965 return -EINVAL;
5966
Samuel Ortizb23aa672009-07-01 21:26:54 +02005967 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005968 }
5969
5970 return 0;
5971}
5972
Jouni Malinen636a5d32009-03-19 13:39:22 +02005973static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5974{
Johannes Berg4c476992010-10-04 21:36:35 +02005975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5976 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005977 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02005978 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02005979 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005980 int err, ssid_len, ie_len = 0;
5981 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08005982 u32 flags = 0;
5983 struct ieee80211_ht_cap *ht_capa = NULL;
5984 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005985
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005986 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5987 return -EINVAL;
5988
5989 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005990 !info->attrs[NL80211_ATTR_SSID] ||
5991 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005992 return -EINVAL;
5993
Johannes Berg4c476992010-10-04 21:36:35 +02005994 if (!rdev->ops->assoc)
5995 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005996
Johannes Berg074ac8d2010-09-16 14:58:22 +02005997 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005998 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5999 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006000
Johannes Berg19957bb2009-07-02 17:20:43 +02006001 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006002
Johannes Berg19957bb2009-07-02 17:20:43 +02006003 chan = ieee80211_get_channel(&rdev->wiphy,
6004 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006005 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6006 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006007
Johannes Berg19957bb2009-07-02 17:20:43 +02006008 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6009 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006010
6011 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006012 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6013 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006014 }
6015
Jouni Malinendc6382c2009-05-06 22:09:37 +03006016 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006017 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006018 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006019 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02006020 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006021 else if (mfp != NL80211_MFP_NO)
6022 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006023 }
6024
Johannes Berg3e5d7642009-07-07 14:37:26 +02006025 if (info->attrs[NL80211_ATTR_PREV_BSSID])
6026 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
6027
Ben Greear7e7c8922011-11-18 11:31:59 -08006028 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6029 flags |= ASSOC_REQ_DISABLE_HT;
6030
6031 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6032 ht_capa_mask =
6033 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
6034
6035 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6036 if (!ht_capa_mask)
6037 return -EINVAL;
6038 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6039 }
6040
Johannes Bergc0692b82010-08-27 14:26:53 +03006041 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006042 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02006043 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
6044 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08006045 &crypto, flags, ht_capa,
6046 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006047
Jouni Malinen636a5d32009-03-19 13:39:22 +02006048 return err;
6049}
6050
6051static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6052{
Johannes Berg4c476992010-10-04 21:36:35 +02006053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6054 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006055 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006056 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006057 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006058 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006059
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006060 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6061 return -EINVAL;
6062
6063 if (!info->attrs[NL80211_ATTR_MAC])
6064 return -EINVAL;
6065
6066 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6067 return -EINVAL;
6068
Johannes Berg4c476992010-10-04 21:36:35 +02006069 if (!rdev->ops->deauth)
6070 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006071
Johannes Berg074ac8d2010-09-16 14:58:22 +02006072 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006073 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6074 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006075
Johannes Berg19957bb2009-07-02 17:20:43 +02006076 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006077
Johannes Berg19957bb2009-07-02 17:20:43 +02006078 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6079 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006080 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006081 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006082 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006083
6084 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006085 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6086 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006087 }
6088
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006089 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6090
Johannes Berg4c476992010-10-04 21:36:35 +02006091 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6092 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006093}
6094
6095static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6096{
Johannes Berg4c476992010-10-04 21:36:35 +02006097 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6098 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006099 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02006100 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006101 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006102 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006103
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006104 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6105 return -EINVAL;
6106
6107 if (!info->attrs[NL80211_ATTR_MAC])
6108 return -EINVAL;
6109
6110 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6111 return -EINVAL;
6112
Johannes Berg4c476992010-10-04 21:36:35 +02006113 if (!rdev->ops->disassoc)
6114 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006115
Johannes Berg074ac8d2010-09-16 14:58:22 +02006116 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006117 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6118 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006119
Johannes Berg19957bb2009-07-02 17:20:43 +02006120 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006121
Johannes Berg19957bb2009-07-02 17:20:43 +02006122 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6123 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006124 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006125 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006126 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006127
6128 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006129 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6130 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006131 }
6132
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006133 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6134
Johannes Berg4c476992010-10-04 21:36:35 +02006135 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6136 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006137}
6138
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006139static bool
6140nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6141 int mcast_rate[IEEE80211_NUM_BANDS],
6142 int rateval)
6143{
6144 struct wiphy *wiphy = &rdev->wiphy;
6145 bool found = false;
6146 int band, i;
6147
6148 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6149 struct ieee80211_supported_band *sband;
6150
6151 sband = wiphy->bands[band];
6152 if (!sband)
6153 continue;
6154
6155 for (i = 0; i < sband->n_bitrates; i++) {
6156 if (sband->bitrates[i].bitrate == rateval) {
6157 mcast_rate[band] = i + 1;
6158 found = true;
6159 break;
6160 }
6161 }
6162 }
6163
6164 return found;
6165}
6166
Johannes Berg04a773a2009-04-19 21:24:32 +02006167static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6168{
Johannes Berg4c476992010-10-04 21:36:35 +02006169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6170 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006171 struct cfg80211_ibss_params ibss;
6172 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006173 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006174 int err;
6175
Johannes Berg8e30bc52009-04-22 17:45:38 +02006176 memset(&ibss, 0, sizeof(ibss));
6177
Johannes Berg04a773a2009-04-19 21:24:32 +02006178 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6179 return -EINVAL;
6180
Johannes Berg683b6d32012-11-08 21:25:48 +01006181 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006182 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6183 return -EINVAL;
6184
Johannes Berg8e30bc52009-04-22 17:45:38 +02006185 ibss.beacon_interval = 100;
6186
6187 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6188 ibss.beacon_interval =
6189 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6190 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6191 return -EINVAL;
6192 }
6193
Johannes Berg4c476992010-10-04 21:36:35 +02006194 if (!rdev->ops->join_ibss)
6195 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006196
Johannes Berg4c476992010-10-04 21:36:35 +02006197 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6198 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006199
Johannes Berg79c97e92009-07-07 03:56:12 +02006200 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006201
Johannes Berg39193492011-09-16 13:45:25 +02006202 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006203 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006204
6205 if (!is_valid_ether_addr(ibss.bssid))
6206 return -EINVAL;
6207 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006208 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6209 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6210
6211 if (info->attrs[NL80211_ATTR_IE]) {
6212 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6213 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6214 }
6215
Johannes Berg683b6d32012-11-08 21:25:48 +01006216 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6217 if (err)
6218 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006219
Johannes Berg683b6d32012-11-08 21:25:48 +01006220 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006221 return -EINVAL;
6222
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006223 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6224 return -EINVAL;
6225 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6226 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006227 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006228
Johannes Berg04a773a2009-04-19 21:24:32 +02006229 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006230 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006231
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006232 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6233 u8 *rates =
6234 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6235 int n_rates =
6236 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6237 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006238 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006239
Johannes Berg34850ab2011-07-18 18:08:35 +02006240 err = ieee80211_get_ratemask(sband, rates, n_rates,
6241 &ibss.basic_rates);
6242 if (err)
6243 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006244 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006245
6246 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6247 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6248 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6249 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006250
Johannes Berg4c476992010-10-04 21:36:35 +02006251 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306252 bool no_ht = false;
6253
Johannes Berg4c476992010-10-04 21:36:35 +02006254 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306255 info->attrs[NL80211_ATTR_KEYS],
6256 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006257 if (IS_ERR(connkeys))
6258 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306259
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006260 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6261 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306262 kfree(connkeys);
6263 return -EINVAL;
6264 }
Johannes Berg4c476992010-10-04 21:36:35 +02006265 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006266
Antonio Quartulli267335d2012-01-31 20:25:47 +01006267 ibss.control_port =
6268 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6269
Johannes Berg4c476992010-10-04 21:36:35 +02006270 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006271 if (err)
6272 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006273 return err;
6274}
6275
6276static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6277{
Johannes Berg4c476992010-10-04 21:36:35 +02006278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6279 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006280
Johannes Berg4c476992010-10-04 21:36:35 +02006281 if (!rdev->ops->leave_ibss)
6282 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006283
Johannes Berg4c476992010-10-04 21:36:35 +02006284 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6285 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006286
Johannes Berg4c476992010-10-04 21:36:35 +02006287 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006288}
6289
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006290static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6291{
6292 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6293 struct net_device *dev = info->user_ptr[1];
6294 int mcast_rate[IEEE80211_NUM_BANDS];
6295 u32 nla_rate;
6296 int err;
6297
6298 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6299 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6300 return -EOPNOTSUPP;
6301
6302 if (!rdev->ops->set_mcast_rate)
6303 return -EOPNOTSUPP;
6304
6305 memset(mcast_rate, 0, sizeof(mcast_rate));
6306
6307 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6308 return -EINVAL;
6309
6310 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6311 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6312 return -EINVAL;
6313
6314 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6315
6316 return err;
6317}
6318
6319
Johannes Bergaff89a92009-07-01 21:26:51 +02006320#ifdef CONFIG_NL80211_TESTMODE
6321static struct genl_multicast_group nl80211_testmode_mcgrp = {
6322 .name = "testmode",
6323};
6324
6325static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6326{
Johannes Berg4c476992010-10-04 21:36:35 +02006327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006328 int err;
6329
6330 if (!info->attrs[NL80211_ATTR_TESTDATA])
6331 return -EINVAL;
6332
Johannes Bergaff89a92009-07-01 21:26:51 +02006333 err = -EOPNOTSUPP;
6334 if (rdev->ops->testmode_cmd) {
6335 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006336 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006337 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6338 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6339 rdev->testmode_info = NULL;
6340 }
6341
Johannes Bergaff89a92009-07-01 21:26:51 +02006342 return err;
6343}
6344
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006345static int nl80211_testmode_dump(struct sk_buff *skb,
6346 struct netlink_callback *cb)
6347{
Johannes Berg00918d32011-12-13 17:22:05 +01006348 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006349 int err;
6350 long phy_idx;
6351 void *data = NULL;
6352 int data_len = 0;
6353
6354 if (cb->args[0]) {
6355 /*
6356 * 0 is a valid index, but not valid for args[0],
6357 * so we need to offset by 1.
6358 */
6359 phy_idx = cb->args[0] - 1;
6360 } else {
6361 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6362 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6363 nl80211_policy);
6364 if (err)
6365 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01006366
Johannes Berg2bd7e352012-06-15 14:23:16 +02006367 mutex_lock(&cfg80211_mutex);
6368 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6369 nl80211_fam.attrbuf);
6370 if (IS_ERR(rdev)) {
6371 mutex_unlock(&cfg80211_mutex);
6372 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01006373 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006374 phy_idx = rdev->wiphy_idx;
6375 rdev = NULL;
6376 mutex_unlock(&cfg80211_mutex);
6377
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006378 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6379 cb->args[1] =
6380 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6381 }
6382
6383 if (cb->args[1]) {
6384 data = nla_data((void *)cb->args[1]);
6385 data_len = nla_len((void *)cb->args[1]);
6386 }
6387
6388 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01006389 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6390 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006391 mutex_unlock(&cfg80211_mutex);
6392 return -ENOENT;
6393 }
Johannes Berg00918d32011-12-13 17:22:05 +01006394 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006395 mutex_unlock(&cfg80211_mutex);
6396
Johannes Berg00918d32011-12-13 17:22:05 +01006397 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006398 err = -EOPNOTSUPP;
6399 goto out_err;
6400 }
6401
6402 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006403 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006404 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6405 NL80211_CMD_TESTMODE);
6406 struct nlattr *tmdata;
6407
David S. Miller9360ffd2012-03-29 04:41:26 -04006408 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006409 genlmsg_cancel(skb, hdr);
6410 break;
6411 }
6412
6413 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6414 if (!tmdata) {
6415 genlmsg_cancel(skb, hdr);
6416 break;
6417 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006418 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006419 nla_nest_end(skb, tmdata);
6420
6421 if (err == -ENOBUFS || err == -ENOENT) {
6422 genlmsg_cancel(skb, hdr);
6423 break;
6424 } else if (err) {
6425 genlmsg_cancel(skb, hdr);
6426 goto out_err;
6427 }
6428
6429 genlmsg_end(skb, hdr);
6430 }
6431
6432 err = skb->len;
6433 /* see above */
6434 cb->args[0] = phy_idx + 1;
6435 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01006436 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006437 return err;
6438}
6439
Johannes Bergaff89a92009-07-01 21:26:51 +02006440static struct sk_buff *
6441__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006442 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006443{
6444 struct sk_buff *skb;
6445 void *hdr;
6446 struct nlattr *data;
6447
6448 skb = nlmsg_new(approxlen + 100, gfp);
6449 if (!skb)
6450 return NULL;
6451
Eric W. Biederman15e47302012-09-07 20:12:54 +00006452 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006453 if (!hdr) {
6454 kfree_skb(skb);
6455 return NULL;
6456 }
6457
David S. Miller9360ffd2012-03-29 04:41:26 -04006458 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6459 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006460 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6461
6462 ((void **)skb->cb)[0] = rdev;
6463 ((void **)skb->cb)[1] = hdr;
6464 ((void **)skb->cb)[2] = data;
6465
6466 return skb;
6467
6468 nla_put_failure:
6469 kfree_skb(skb);
6470 return NULL;
6471}
6472
6473struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6474 int approxlen)
6475{
6476 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6477
6478 if (WARN_ON(!rdev->testmode_info))
6479 return NULL;
6480
6481 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006482 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006483 rdev->testmode_info->snd_seq,
6484 GFP_KERNEL);
6485}
6486EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6487
6488int cfg80211_testmode_reply(struct sk_buff *skb)
6489{
6490 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6491 void *hdr = ((void **)skb->cb)[1];
6492 struct nlattr *data = ((void **)skb->cb)[2];
6493
6494 if (WARN_ON(!rdev->testmode_info)) {
6495 kfree_skb(skb);
6496 return -EINVAL;
6497 }
6498
6499 nla_nest_end(skb, data);
6500 genlmsg_end(skb, hdr);
6501 return genlmsg_reply(skb, rdev->testmode_info);
6502}
6503EXPORT_SYMBOL(cfg80211_testmode_reply);
6504
6505struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6506 int approxlen, gfp_t gfp)
6507{
6508 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6509
6510 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6511}
6512EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6513
6514void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6515{
6516 void *hdr = ((void **)skb->cb)[1];
6517 struct nlattr *data = ((void **)skb->cb)[2];
6518
6519 nla_nest_end(skb, data);
6520 genlmsg_end(skb, hdr);
6521 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6522}
6523EXPORT_SYMBOL(cfg80211_testmode_event);
6524#endif
6525
Samuel Ortizb23aa672009-07-01 21:26:54 +02006526static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6527{
Johannes Berg4c476992010-10-04 21:36:35 +02006528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6529 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006530 struct cfg80211_connect_params connect;
6531 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006532 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006533 int err;
6534
6535 memset(&connect, 0, sizeof(connect));
6536
6537 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6538 return -EINVAL;
6539
6540 if (!info->attrs[NL80211_ATTR_SSID] ||
6541 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6542 return -EINVAL;
6543
6544 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6545 connect.auth_type =
6546 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006547 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6548 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006549 return -EINVAL;
6550 } else
6551 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6552
6553 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6554
Johannes Bergc0692b82010-08-27 14:26:53 +03006555 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006556 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006557 if (err)
6558 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006559
Johannes Berg074ac8d2010-09-16 14:58:22 +02006560 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006561 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6562 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006563
Johannes Berg79c97e92009-07-07 03:56:12 +02006564 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006565
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306566 connect.bg_scan_period = -1;
6567 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6568 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6569 connect.bg_scan_period =
6570 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6571 }
6572
Samuel Ortizb23aa672009-07-01 21:26:54 +02006573 if (info->attrs[NL80211_ATTR_MAC])
6574 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6575 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6576 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6577
6578 if (info->attrs[NL80211_ATTR_IE]) {
6579 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6580 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6581 }
6582
Jouni Malinencee00a92013-01-15 17:15:57 +02006583 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6584 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6585 if (connect.mfp != NL80211_MFP_REQUIRED &&
6586 connect.mfp != NL80211_MFP_NO)
6587 return -EINVAL;
6588 } else {
6589 connect.mfp = NL80211_MFP_NO;
6590 }
6591
Samuel Ortizb23aa672009-07-01 21:26:54 +02006592 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6593 connect.channel =
6594 ieee80211_get_channel(wiphy,
6595 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6596 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006597 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6598 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006599 }
6600
Johannes Bergfffd0932009-07-08 14:22:54 +02006601 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6602 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306603 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006604 if (IS_ERR(connkeys))
6605 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006606 }
6607
Ben Greear7e7c8922011-11-18 11:31:59 -08006608 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6609 connect.flags |= ASSOC_REQ_DISABLE_HT;
6610
6611 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6612 memcpy(&connect.ht_capa_mask,
6613 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6614 sizeof(connect.ht_capa_mask));
6615
6616 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006617 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6618 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006619 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006620 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006621 memcpy(&connect.ht_capa,
6622 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6623 sizeof(connect.ht_capa));
6624 }
6625
Johannes Bergfffd0932009-07-08 14:22:54 +02006626 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006627 if (err)
6628 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006629 return err;
6630}
6631
6632static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6633{
Johannes Berg4c476992010-10-04 21:36:35 +02006634 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6635 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006636 u16 reason;
6637
6638 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6639 reason = WLAN_REASON_DEAUTH_LEAVING;
6640 else
6641 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6642
6643 if (reason == 0)
6644 return -EINVAL;
6645
Johannes Berg074ac8d2010-09-16 14:58:22 +02006646 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006647 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6648 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006649
Johannes Berg4c476992010-10-04 21:36:35 +02006650 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006651}
6652
Johannes Berg463d0182009-07-14 00:33:35 +02006653static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6654{
Johannes Berg4c476992010-10-04 21:36:35 +02006655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006656 struct net *net;
6657 int err;
6658 u32 pid;
6659
6660 if (!info->attrs[NL80211_ATTR_PID])
6661 return -EINVAL;
6662
6663 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6664
Johannes Berg463d0182009-07-14 00:33:35 +02006665 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006666 if (IS_ERR(net))
6667 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006668
6669 err = 0;
6670
6671 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006672 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6673 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006674
Johannes Berg463d0182009-07-14 00:33:35 +02006675 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006676 return err;
6677}
6678
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006679static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6680{
Johannes Berg4c476992010-10-04 21:36:35 +02006681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006682 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6683 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006684 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006685 struct cfg80211_pmksa pmksa;
6686
6687 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6688
6689 if (!info->attrs[NL80211_ATTR_MAC])
6690 return -EINVAL;
6691
6692 if (!info->attrs[NL80211_ATTR_PMKID])
6693 return -EINVAL;
6694
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006695 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6696 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6697
Johannes Berg074ac8d2010-09-16 14:58:22 +02006698 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006699 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6700 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006701
6702 switch (info->genlhdr->cmd) {
6703 case NL80211_CMD_SET_PMKSA:
6704 rdev_ops = rdev->ops->set_pmksa;
6705 break;
6706 case NL80211_CMD_DEL_PMKSA:
6707 rdev_ops = rdev->ops->del_pmksa;
6708 break;
6709 default:
6710 WARN_ON(1);
6711 break;
6712 }
6713
Johannes Berg4c476992010-10-04 21:36:35 +02006714 if (!rdev_ops)
6715 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006716
Johannes Berg4c476992010-10-04 21:36:35 +02006717 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006718}
6719
6720static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6721{
Johannes Berg4c476992010-10-04 21:36:35 +02006722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6723 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006724
Johannes Berg074ac8d2010-09-16 14:58:22 +02006725 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006726 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6727 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006728
Johannes Berg4c476992010-10-04 21:36:35 +02006729 if (!rdev->ops->flush_pmksa)
6730 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006731
Hila Gonene35e4d22012-06-27 17:19:42 +03006732 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006733}
6734
Arik Nemtsov109086c2011-09-28 14:12:50 +03006735static int nl80211_tdls_mgmt(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 u8 action_code, dialog_token;
6740 u16 status_code;
6741 u8 *peer;
6742
6743 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6744 !rdev->ops->tdls_mgmt)
6745 return -EOPNOTSUPP;
6746
6747 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6748 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6749 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6750 !info->attrs[NL80211_ATTR_IE] ||
6751 !info->attrs[NL80211_ATTR_MAC])
6752 return -EINVAL;
6753
6754 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6755 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6756 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6757 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6758
Hila Gonene35e4d22012-06-27 17:19:42 +03006759 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6760 dialog_token, status_code,
6761 nla_data(info->attrs[NL80211_ATTR_IE]),
6762 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006763}
6764
6765static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6766{
6767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6768 struct net_device *dev = info->user_ptr[1];
6769 enum nl80211_tdls_operation operation;
6770 u8 *peer;
6771
6772 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6773 !rdev->ops->tdls_oper)
6774 return -EOPNOTSUPP;
6775
6776 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6777 !info->attrs[NL80211_ATTR_MAC])
6778 return -EINVAL;
6779
6780 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6781 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6782
Hila Gonene35e4d22012-06-27 17:19:42 +03006783 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006784}
6785
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006786static int nl80211_remain_on_channel(struct sk_buff *skb,
6787 struct genl_info *info)
6788{
Johannes Berg4c476992010-10-04 21:36:35 +02006789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006790 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006791 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006792 struct sk_buff *msg;
6793 void *hdr;
6794 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006795 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006796 int err;
6797
6798 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6799 !info->attrs[NL80211_ATTR_DURATION])
6800 return -EINVAL;
6801
6802 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6803
Johannes Berg7c4ef712011-11-18 15:33:48 +01006804 if (!rdev->ops->remain_on_channel ||
6805 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006806 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006807
Johannes Bergebf348f2012-06-01 12:50:54 +02006808 /*
6809 * We should be on that channel for at least a minimum amount of
6810 * time (10ms) but no longer than the driver supports.
6811 */
6812 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6813 duration > rdev->wiphy.max_remain_on_channel_duration)
6814 return -EINVAL;
6815
Johannes Berg683b6d32012-11-08 21:25:48 +01006816 err = nl80211_parse_chandef(rdev, info, &chandef);
6817 if (err)
6818 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006819
6820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006821 if (!msg)
6822 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006823
Eric W. Biederman15e47302012-09-07 20:12:54 +00006824 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006825 NL80211_CMD_REMAIN_ON_CHANNEL);
6826
6827 if (IS_ERR(hdr)) {
6828 err = PTR_ERR(hdr);
6829 goto free_msg;
6830 }
6831
Johannes Berg683b6d32012-11-08 21:25:48 +01006832 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6833 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006834
6835 if (err)
6836 goto free_msg;
6837
David S. Miller9360ffd2012-03-29 04:41:26 -04006838 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6839 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006840
6841 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006842
6843 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006844
6845 nla_put_failure:
6846 err = -ENOBUFS;
6847 free_msg:
6848 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006849 return err;
6850}
6851
6852static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6853 struct genl_info *info)
6854{
Johannes Berg4c476992010-10-04 21:36:35 +02006855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006856 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006857 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006858
6859 if (!info->attrs[NL80211_ATTR_COOKIE])
6860 return -EINVAL;
6861
Johannes Berg4c476992010-10-04 21:36:35 +02006862 if (!rdev->ops->cancel_remain_on_channel)
6863 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006864
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006865 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6866
Hila Gonene35e4d22012-06-27 17:19:42 +03006867 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006868}
6869
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006870static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6871 u8 *rates, u8 rates_len)
6872{
6873 u8 i;
6874 u32 mask = 0;
6875
6876 for (i = 0; i < rates_len; i++) {
6877 int rate = (rates[i] & 0x7f) * 5;
6878 int ridx;
6879 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6880 struct ieee80211_rate *srate =
6881 &sband->bitrates[ridx];
6882 if (rate == srate->bitrate) {
6883 mask |= 1 << ridx;
6884 break;
6885 }
6886 }
6887 if (ridx == sband->n_bitrates)
6888 return 0; /* rate not found */
6889 }
6890
6891 return mask;
6892}
6893
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006894static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6895 u8 *rates, u8 rates_len,
6896 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6897{
6898 u8 i;
6899
6900 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6901
6902 for (i = 0; i < rates_len; i++) {
6903 int ridx, rbit;
6904
6905 ridx = rates[i] / 8;
6906 rbit = BIT(rates[i] % 8);
6907
6908 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006909 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006910 return false;
6911
6912 /* check availability */
6913 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6914 mcs[ridx] |= rbit;
6915 else
6916 return false;
6917 }
6918
6919 return true;
6920}
6921
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006922static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006923 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6924 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006925 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6926 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006927};
6928
6929static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6930 struct genl_info *info)
6931{
6932 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006933 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006934 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006935 int rem, i;
6936 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006937 struct nlattr *tx_rates;
6938 struct ieee80211_supported_band *sband;
6939
6940 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6941 return -EINVAL;
6942
Johannes Berg4c476992010-10-04 21:36:35 +02006943 if (!rdev->ops->set_bitrate_mask)
6944 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006945
6946 memset(&mask, 0, sizeof(mask));
6947 /* Default to all rates enabled */
6948 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6949 sband = rdev->wiphy.bands[i];
6950 mask.control[i].legacy =
6951 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006952 if (sband)
6953 memcpy(mask.control[i].mcs,
6954 sband->ht_cap.mcs.rx_mask,
6955 sizeof(mask.control[i].mcs));
6956 else
6957 memset(mask.control[i].mcs, 0,
6958 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006959 }
6960
6961 /*
6962 * The nested attribute uses enum nl80211_band as the index. This maps
6963 * directly to the enum ieee80211_band values used in cfg80211.
6964 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006965 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006966 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6967 {
6968 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02006969 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6970 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006971 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02006972 if (sband == NULL)
6973 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006974 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6975 nla_len(tx_rates), nl80211_txattr_policy);
6976 if (tb[NL80211_TXRATE_LEGACY]) {
6977 mask.control[band].legacy = rateset_to_mask(
6978 sband,
6979 nla_data(tb[NL80211_TXRATE_LEGACY]),
6980 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05306981 if ((mask.control[band].legacy == 0) &&
6982 nla_len(tb[NL80211_TXRATE_LEGACY]))
6983 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006984 }
6985 if (tb[NL80211_TXRATE_MCS]) {
6986 if (!ht_rateset_to_mask(
6987 sband,
6988 nla_data(tb[NL80211_TXRATE_MCS]),
6989 nla_len(tb[NL80211_TXRATE_MCS]),
6990 mask.control[band].mcs))
6991 return -EINVAL;
6992 }
6993
6994 if (mask.control[band].legacy == 0) {
6995 /* don't allow empty legacy rates if HT
6996 * is not even supported. */
6997 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6998 return -EINVAL;
6999
7000 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7001 if (mask.control[band].mcs[i])
7002 break;
7003
7004 /* legacy and mcs rates may not be both empty */
7005 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007006 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007007 }
7008 }
7009
Hila Gonene35e4d22012-06-27 17:19:42 +03007010 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007011}
7012
Johannes Berg2e161f72010-08-12 15:38:38 +02007013static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007014{
Johannes Berg4c476992010-10-04 21:36:35 +02007015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007016 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007017 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007018
7019 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7020 return -EINVAL;
7021
Johannes Berg2e161f72010-08-12 15:38:38 +02007022 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7023 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007024
Johannes Berg71bbc992012-06-15 15:30:18 +02007025 switch (wdev->iftype) {
7026 case NL80211_IFTYPE_STATION:
7027 case NL80211_IFTYPE_ADHOC:
7028 case NL80211_IFTYPE_P2P_CLIENT:
7029 case NL80211_IFTYPE_AP:
7030 case NL80211_IFTYPE_AP_VLAN:
7031 case NL80211_IFTYPE_MESH_POINT:
7032 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007033 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007034 break;
7035 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007036 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007037 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007038
7039 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007040 if (!rdev->ops->mgmt_tx)
7041 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007042
Eric W. Biederman15e47302012-09-07 20:12:54 +00007043 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007044 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7045 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007046}
7047
Johannes Berg2e161f72010-08-12 15:38:38 +02007048static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007049{
Johannes Berg4c476992010-10-04 21:36:35 +02007050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007051 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007052 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007053 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007054 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007055 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007056 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007057 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007058 bool offchan, no_cck, dont_wait_for_ack;
7059
7060 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007061
Johannes Berg683b6d32012-11-08 21:25:48 +01007062 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007063 return -EINVAL;
7064
Johannes Berg4c476992010-10-04 21:36:35 +02007065 if (!rdev->ops->mgmt_tx)
7066 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007067
Johannes Berg71bbc992012-06-15 15:30:18 +02007068 switch (wdev->iftype) {
7069 case NL80211_IFTYPE_STATION:
7070 case NL80211_IFTYPE_ADHOC:
7071 case NL80211_IFTYPE_P2P_CLIENT:
7072 case NL80211_IFTYPE_AP:
7073 case NL80211_IFTYPE_AP_VLAN:
7074 case NL80211_IFTYPE_MESH_POINT:
7075 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007076 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007077 break;
7078 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007079 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007080 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007081
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007082 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007083 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007084 return -EINVAL;
7085 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007086
7087 /*
7088 * We should wait on the channel for at least a minimum amount
7089 * of time (10ms) but no longer than the driver supports.
7090 */
7091 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7092 wait > rdev->wiphy.max_remain_on_channel_duration)
7093 return -EINVAL;
7094
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007095 }
7096
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007097 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7098
Johannes Berg7c4ef712011-11-18 15:33:48 +01007099 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7100 return -EINVAL;
7101
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307102 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7103
Johannes Berg683b6d32012-11-08 21:25:48 +01007104 err = nl80211_parse_chandef(rdev, info, &chandef);
7105 if (err)
7106 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007107
Johannes Berge247bd902011-11-04 11:18:21 +01007108 if (!dont_wait_for_ack) {
7109 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7110 if (!msg)
7111 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007112
Eric W. Biederman15e47302012-09-07 20:12:54 +00007113 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007114 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007115
Johannes Berge247bd902011-11-04 11:18:21 +01007116 if (IS_ERR(hdr)) {
7117 err = PTR_ERR(hdr);
7118 goto free_msg;
7119 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007120 }
Johannes Berge247bd902011-11-04 11:18:21 +01007121
Johannes Berg683b6d32012-11-08 21:25:48 +01007122 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007123 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7124 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007125 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007126 if (err)
7127 goto free_msg;
7128
Johannes Berge247bd902011-11-04 11:18:21 +01007129 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007130 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7131 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007132
Johannes Berge247bd902011-11-04 11:18:21 +01007133 genlmsg_end(msg, hdr);
7134 return genlmsg_reply(msg, info);
7135 }
7136
7137 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007138
7139 nla_put_failure:
7140 err = -ENOBUFS;
7141 free_msg:
7142 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007143 return err;
7144}
7145
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007146static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7147{
7148 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007149 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007150 u64 cookie;
7151
7152 if (!info->attrs[NL80211_ATTR_COOKIE])
7153 return -EINVAL;
7154
7155 if (!rdev->ops->mgmt_tx_cancel_wait)
7156 return -EOPNOTSUPP;
7157
Johannes Berg71bbc992012-06-15 15:30:18 +02007158 switch (wdev->iftype) {
7159 case NL80211_IFTYPE_STATION:
7160 case NL80211_IFTYPE_ADHOC:
7161 case NL80211_IFTYPE_P2P_CLIENT:
7162 case NL80211_IFTYPE_AP:
7163 case NL80211_IFTYPE_AP_VLAN:
7164 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007165 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007166 break;
7167 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007168 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007169 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007170
7171 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7172
Hila Gonene35e4d22012-06-27 17:19:42 +03007173 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007174}
7175
Kalle Valoffb9eb32010-02-17 17:58:10 +02007176static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7177{
Johannes Berg4c476992010-10-04 21:36:35 +02007178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007179 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007180 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007181 u8 ps_state;
7182 bool state;
7183 int err;
7184
Johannes Berg4c476992010-10-04 21:36:35 +02007185 if (!info->attrs[NL80211_ATTR_PS_STATE])
7186 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007187
7188 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7189
Johannes Berg4c476992010-10-04 21:36:35 +02007190 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7191 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007192
7193 wdev = dev->ieee80211_ptr;
7194
Johannes Berg4c476992010-10-04 21:36:35 +02007195 if (!rdev->ops->set_power_mgmt)
7196 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007197
7198 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7199
7200 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007201 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007202
Hila Gonene35e4d22012-06-27 17:19:42 +03007203 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007204 if (!err)
7205 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007206 return err;
7207}
7208
7209static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7210{
Johannes Berg4c476992010-10-04 21:36:35 +02007211 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007212 enum nl80211_ps_state ps_state;
7213 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007214 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007215 struct sk_buff *msg;
7216 void *hdr;
7217 int err;
7218
Kalle Valoffb9eb32010-02-17 17:58:10 +02007219 wdev = dev->ieee80211_ptr;
7220
Johannes Berg4c476992010-10-04 21:36:35 +02007221 if (!rdev->ops->set_power_mgmt)
7222 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007223
7224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007225 if (!msg)
7226 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007227
Eric W. Biederman15e47302012-09-07 20:12:54 +00007228 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007229 NL80211_CMD_GET_POWER_SAVE);
7230 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007231 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007232 goto free_msg;
7233 }
7234
7235 if (wdev->ps)
7236 ps_state = NL80211_PS_ENABLED;
7237 else
7238 ps_state = NL80211_PS_DISABLED;
7239
David S. Miller9360ffd2012-03-29 04:41:26 -04007240 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7241 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007242
7243 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007244 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007245
Johannes Berg4c476992010-10-04 21:36:35 +02007246 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007247 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007248 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007249 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007250 return err;
7251}
7252
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007253static struct nla_policy
7254nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7255 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7256 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7257 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007258 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7259 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7260 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007261};
7262
Thomas Pedersen84f10702012-07-12 16:17:33 -07007263static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007264 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007265{
7266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7267 struct wireless_dev *wdev;
7268 struct net_device *dev = info->user_ptr[1];
7269
Johannes Bergd9d8b012012-11-26 12:51:52 +01007270 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007271 return -EINVAL;
7272
7273 wdev = dev->ieee80211_ptr;
7274
7275 if (!rdev->ops->set_cqm_txe_config)
7276 return -EOPNOTSUPP;
7277
7278 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7279 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7280 return -EOPNOTSUPP;
7281
Hila Gonene35e4d22012-06-27 17:19:42 +03007282 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007283}
7284
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007285static int nl80211_set_cqm_rssi(struct genl_info *info,
7286 s32 threshold, u32 hysteresis)
7287{
Johannes Berg4c476992010-10-04 21:36:35 +02007288 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007289 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007290 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007291
7292 if (threshold > 0)
7293 return -EINVAL;
7294
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007295 wdev = dev->ieee80211_ptr;
7296
Johannes Berg4c476992010-10-04 21:36:35 +02007297 if (!rdev->ops->set_cqm_rssi_config)
7298 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007299
Johannes Berg074ac8d2010-09-16 14:58:22 +02007300 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007301 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7302 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007303
Hila Gonene35e4d22012-06-27 17:19:42 +03007304 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007305}
7306
7307static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7308{
7309 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7310 struct nlattr *cqm;
7311 int err;
7312
7313 cqm = info->attrs[NL80211_ATTR_CQM];
7314 if (!cqm) {
7315 err = -EINVAL;
7316 goto out;
7317 }
7318
7319 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7320 nl80211_attr_cqm_policy);
7321 if (err)
7322 goto out;
7323
7324 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7325 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7326 s32 threshold;
7327 u32 hysteresis;
7328 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7329 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7330 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007331 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7332 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7333 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7334 u32 rate, pkts, intvl;
7335 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7336 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7337 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7338 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007339 } else
7340 err = -EINVAL;
7341
7342out:
7343 return err;
7344}
7345
Johannes Berg29cbe682010-12-03 09:20:44 +01007346static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7347{
7348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7349 struct net_device *dev = info->user_ptr[1];
7350 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007351 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007352 int err;
7353
7354 /* start with default */
7355 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007356 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007357
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007358 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007359 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007360 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007361 if (err)
7362 return err;
7363 }
7364
7365 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7366 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7367 return -EINVAL;
7368
Javier Cardonac80d5452010-12-16 17:37:49 -08007369 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7370 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7371
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007372 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7373 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7374 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7375 return -EINVAL;
7376
Marco Porsch9bdbf042013-01-07 16:04:51 +01007377 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7378 setup.beacon_interval =
7379 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7380 if (setup.beacon_interval < 10 ||
7381 setup.beacon_interval > 10000)
7382 return -EINVAL;
7383 }
7384
7385 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7386 setup.dtim_period =
7387 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7388 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7389 return -EINVAL;
7390 }
7391
Javier Cardonac80d5452010-12-16 17:37:49 -08007392 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7393 /* parse additional setup parameters if given */
7394 err = nl80211_parse_mesh_setup(info, &setup);
7395 if (err)
7396 return err;
7397 }
7398
Johannes Bergcc1d2802012-05-16 23:50:20 +02007399 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007400 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7401 if (err)
7402 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007403 } else {
7404 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007405 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007406 }
7407
Javier Cardonac80d5452010-12-16 17:37:49 -08007408 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007409}
7410
7411static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7412{
7413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7414 struct net_device *dev = info->user_ptr[1];
7415
7416 return cfg80211_leave_mesh(rdev, dev);
7417}
7418
Johannes Bergdfb89c52012-06-27 09:23:48 +02007419#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007420static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7421 struct cfg80211_registered_device *rdev)
7422{
7423 struct nlattr *nl_pats, *nl_pat;
7424 int i, pat_len;
7425
7426 if (!rdev->wowlan->n_patterns)
7427 return 0;
7428
7429 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7430 if (!nl_pats)
7431 return -ENOBUFS;
7432
7433 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7434 nl_pat = nla_nest_start(msg, i + 1);
7435 if (!nl_pat)
7436 return -ENOBUFS;
7437 pat_len = rdev->wowlan->patterns[i].pattern_len;
7438 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7439 DIV_ROUND_UP(pat_len, 8),
7440 rdev->wowlan->patterns[i].mask) ||
7441 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7442 pat_len, rdev->wowlan->patterns[i].pattern) ||
7443 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7444 rdev->wowlan->patterns[i].pkt_offset))
7445 return -ENOBUFS;
7446 nla_nest_end(msg, nl_pat);
7447 }
7448 nla_nest_end(msg, nl_pats);
7449
7450 return 0;
7451}
7452
Johannes Berg2a0e0472013-01-23 22:57:40 +01007453static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7454 struct cfg80211_wowlan_tcp *tcp)
7455{
7456 struct nlattr *nl_tcp;
7457
7458 if (!tcp)
7459 return 0;
7460
7461 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7462 if (!nl_tcp)
7463 return -ENOBUFS;
7464
7465 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7466 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7467 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7468 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7469 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7470 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7471 tcp->payload_len, tcp->payload) ||
7472 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7473 tcp->data_interval) ||
7474 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7475 tcp->wake_len, tcp->wake_data) ||
7476 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7477 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7478 return -ENOBUFS;
7479
7480 if (tcp->payload_seq.len &&
7481 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7482 sizeof(tcp->payload_seq), &tcp->payload_seq))
7483 return -ENOBUFS;
7484
7485 if (tcp->payload_tok.len &&
7486 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7487 sizeof(tcp->payload_tok) + tcp->tokens_size,
7488 &tcp->payload_tok))
7489 return -ENOBUFS;
7490
7491 return 0;
7492}
7493
Johannes Bergff1b6e62011-05-04 15:37:28 +02007494static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7495{
7496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7497 struct sk_buff *msg;
7498 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007499 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007500
Johannes Berg2a0e0472013-01-23 22:57:40 +01007501 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7502 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007503 return -EOPNOTSUPP;
7504
Johannes Berg2a0e0472013-01-23 22:57:40 +01007505 if (rdev->wowlan && rdev->wowlan->tcp) {
7506 /* adjust size to have room for all the data */
7507 size += rdev->wowlan->tcp->tokens_size +
7508 rdev->wowlan->tcp->payload_len +
7509 rdev->wowlan->tcp->wake_len +
7510 rdev->wowlan->tcp->wake_len / 8;
7511 }
7512
7513 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007514 if (!msg)
7515 return -ENOMEM;
7516
Eric W. Biederman15e47302012-09-07 20:12:54 +00007517 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007518 NL80211_CMD_GET_WOWLAN);
7519 if (!hdr)
7520 goto nla_put_failure;
7521
7522 if (rdev->wowlan) {
7523 struct nlattr *nl_wowlan;
7524
7525 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7526 if (!nl_wowlan)
7527 goto nla_put_failure;
7528
David S. Miller9360ffd2012-03-29 04:41:26 -04007529 if ((rdev->wowlan->any &&
7530 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7531 (rdev->wowlan->disconnect &&
7532 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7533 (rdev->wowlan->magic_pkt &&
7534 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7535 (rdev->wowlan->gtk_rekey_failure &&
7536 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7537 (rdev->wowlan->eap_identity_req &&
7538 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7539 (rdev->wowlan->four_way_handshake &&
7540 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7541 (rdev->wowlan->rfkill_release &&
7542 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7543 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007544
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007545 if (nl80211_send_wowlan_patterns(msg, rdev))
7546 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007547
7548 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7549 goto nla_put_failure;
7550
Johannes Bergff1b6e62011-05-04 15:37:28 +02007551 nla_nest_end(msg, nl_wowlan);
7552 }
7553
7554 genlmsg_end(msg, hdr);
7555 return genlmsg_reply(msg, info);
7556
7557nla_put_failure:
7558 nlmsg_free(msg);
7559 return -ENOBUFS;
7560}
7561
Johannes Berg2a0e0472013-01-23 22:57:40 +01007562static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7563 struct nlattr *attr,
7564 struct cfg80211_wowlan *trig)
7565{
7566 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7567 struct cfg80211_wowlan_tcp *cfg;
7568 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7569 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7570 u32 size;
7571 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7572 int err, port;
7573
7574 if (!rdev->wiphy.wowlan.tcp)
7575 return -EINVAL;
7576
7577 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7578 nla_data(attr), nla_len(attr),
7579 nl80211_wowlan_tcp_policy);
7580 if (err)
7581 return err;
7582
7583 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7584 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7585 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7586 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7587 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7588 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7589 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7590 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7591 return -EINVAL;
7592
7593 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7594 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7595 return -EINVAL;
7596
7597 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
7598 rdev->wiphy.wowlan.tcp->data_interval_max)
7599 return -EINVAL;
7600
7601 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7602 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7603 return -EINVAL;
7604
7605 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7606 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7607 return -EINVAL;
7608
7609 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7610 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7611
7612 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7613 tokens_size = tokln - sizeof(*tok);
7614
7615 if (!tok->len || tokens_size % tok->len)
7616 return -EINVAL;
7617 if (!rdev->wiphy.wowlan.tcp->tok)
7618 return -EINVAL;
7619 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7620 return -EINVAL;
7621 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7622 return -EINVAL;
7623 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7624 return -EINVAL;
7625 if (tok->offset + tok->len > data_size)
7626 return -EINVAL;
7627 }
7628
7629 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7630 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7631 if (!rdev->wiphy.wowlan.tcp->seq)
7632 return -EINVAL;
7633 if (seq->len == 0 || seq->len > 4)
7634 return -EINVAL;
7635 if (seq->len + seq->offset > data_size)
7636 return -EINVAL;
7637 }
7638
7639 size = sizeof(*cfg);
7640 size += data_size;
7641 size += wake_size + wake_mask_size;
7642 size += tokens_size;
7643
7644 cfg = kzalloc(size, GFP_KERNEL);
7645 if (!cfg)
7646 return -ENOMEM;
7647 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7648 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7649 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7650 ETH_ALEN);
7651 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7652 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7653 else
7654 port = 0;
7655#ifdef CONFIG_INET
7656 /* allocate a socket and port for it and use it */
7657 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7658 IPPROTO_TCP, &cfg->sock, 1);
7659 if (err) {
7660 kfree(cfg);
7661 return err;
7662 }
7663 if (inet_csk_get_port(cfg->sock->sk, port)) {
7664 sock_release(cfg->sock);
7665 kfree(cfg);
7666 return -EADDRINUSE;
7667 }
7668 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7669#else
7670 if (!port) {
7671 kfree(cfg);
7672 return -EINVAL;
7673 }
7674 cfg->src_port = port;
7675#endif
7676
7677 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7678 cfg->payload_len = data_size;
7679 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7680 memcpy((void *)cfg->payload,
7681 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7682 data_size);
7683 if (seq)
7684 cfg->payload_seq = *seq;
7685 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7686 cfg->wake_len = wake_size;
7687 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7688 memcpy((void *)cfg->wake_data,
7689 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7690 wake_size);
7691 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7692 data_size + wake_size;
7693 memcpy((void *)cfg->wake_mask,
7694 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7695 wake_mask_size);
7696 if (tok) {
7697 cfg->tokens_size = tokens_size;
7698 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7699 }
7700
7701 trig->tcp = cfg;
7702
7703 return 0;
7704}
7705
Johannes Bergff1b6e62011-05-04 15:37:28 +02007706static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7707{
7708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7709 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007710 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007711 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007712 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7713 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007714 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007715
Johannes Berg2a0e0472013-01-23 22:57:40 +01007716 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7717 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007718 return -EOPNOTSUPP;
7719
Johannes Bergae33bd82012-07-12 16:25:02 +02007720 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7721 cfg80211_rdev_free_wowlan(rdev);
7722 rdev->wowlan = NULL;
7723 goto set_wakeup;
7724 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007725
7726 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7727 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7728 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7729 nl80211_wowlan_policy);
7730 if (err)
7731 return err;
7732
7733 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7734 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7735 return -EINVAL;
7736 new_triggers.any = true;
7737 }
7738
7739 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7740 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7741 return -EINVAL;
7742 new_triggers.disconnect = true;
7743 }
7744
7745 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7746 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7747 return -EINVAL;
7748 new_triggers.magic_pkt = true;
7749 }
7750
Johannes Berg77dbbb12011-07-13 10:48:55 +02007751 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7752 return -EINVAL;
7753
7754 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7755 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7756 return -EINVAL;
7757 new_triggers.gtk_rekey_failure = true;
7758 }
7759
7760 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7761 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7762 return -EINVAL;
7763 new_triggers.eap_identity_req = true;
7764 }
7765
7766 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7767 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7768 return -EINVAL;
7769 new_triggers.four_way_handshake = true;
7770 }
7771
7772 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7773 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7774 return -EINVAL;
7775 new_triggers.rfkill_release = true;
7776 }
7777
Johannes Bergff1b6e62011-05-04 15:37:28 +02007778 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7779 struct nlattr *pat;
7780 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007781 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007782 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7783
7784 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7785 rem)
7786 n_patterns++;
7787 if (n_patterns > wowlan->n_patterns)
7788 return -EINVAL;
7789
7790 new_triggers.patterns = kcalloc(n_patterns,
7791 sizeof(new_triggers.patterns[0]),
7792 GFP_KERNEL);
7793 if (!new_triggers.patterns)
7794 return -ENOMEM;
7795
7796 new_triggers.n_patterns = n_patterns;
7797 i = 0;
7798
7799 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7800 rem) {
7801 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7802 nla_data(pat), nla_len(pat), NULL);
7803 err = -EINVAL;
7804 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7805 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7806 goto error;
7807 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7808 mask_len = DIV_ROUND_UP(pat_len, 8);
7809 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7810 mask_len)
7811 goto error;
7812 if (pat_len > wowlan->pattern_max_len ||
7813 pat_len < wowlan->pattern_min_len)
7814 goto error;
7815
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007816 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7817 pkt_offset = 0;
7818 else
7819 pkt_offset = nla_get_u32(
7820 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7821 if (pkt_offset > wowlan->max_pkt_offset)
7822 goto error;
7823 new_triggers.patterns[i].pkt_offset = pkt_offset;
7824
Johannes Bergff1b6e62011-05-04 15:37:28 +02007825 new_triggers.patterns[i].mask =
7826 kmalloc(mask_len + pat_len, GFP_KERNEL);
7827 if (!new_triggers.patterns[i].mask) {
7828 err = -ENOMEM;
7829 goto error;
7830 }
7831 new_triggers.patterns[i].pattern =
7832 new_triggers.patterns[i].mask + mask_len;
7833 memcpy(new_triggers.patterns[i].mask,
7834 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7835 mask_len);
7836 new_triggers.patterns[i].pattern_len = pat_len;
7837 memcpy(new_triggers.patterns[i].pattern,
7838 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7839 pat_len);
7840 i++;
7841 }
7842 }
7843
Johannes Berg2a0e0472013-01-23 22:57:40 +01007844 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7845 err = nl80211_parse_wowlan_tcp(
7846 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7847 &new_triggers);
7848 if (err)
7849 goto error;
7850 }
7851
Johannes Bergae33bd82012-07-12 16:25:02 +02007852 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7853 if (!ntrig) {
7854 err = -ENOMEM;
7855 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007856 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007857 cfg80211_rdev_free_wowlan(rdev);
7858 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007859
Johannes Bergae33bd82012-07-12 16:25:02 +02007860 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007861 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007862 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007863
Johannes Bergff1b6e62011-05-04 15:37:28 +02007864 return 0;
7865 error:
7866 for (i = 0; i < new_triggers.n_patterns; i++)
7867 kfree(new_triggers.patterns[i].mask);
7868 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007869 if (new_triggers.tcp && new_triggers.tcp->sock)
7870 sock_release(new_triggers.tcp->sock);
7871 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007872 return err;
7873}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007874#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007875
Johannes Berge5497d72011-07-05 16:35:40 +02007876static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7877{
7878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7879 struct net_device *dev = info->user_ptr[1];
7880 struct wireless_dev *wdev = dev->ieee80211_ptr;
7881 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7882 struct cfg80211_gtk_rekey_data rekey_data;
7883 int err;
7884
7885 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7886 return -EINVAL;
7887
7888 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7889 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7890 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7891 nl80211_rekey_policy);
7892 if (err)
7893 return err;
7894
7895 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7896 return -ERANGE;
7897 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7898 return -ERANGE;
7899 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7900 return -ERANGE;
7901
7902 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7903 NL80211_KEK_LEN);
7904 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7905 NL80211_KCK_LEN);
7906 memcpy(rekey_data.replay_ctr,
7907 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7908 NL80211_REPLAY_CTR_LEN);
7909
7910 wdev_lock(wdev);
7911 if (!wdev->current_bss) {
7912 err = -ENOTCONN;
7913 goto out;
7914 }
7915
7916 if (!rdev->ops->set_rekey_data) {
7917 err = -EOPNOTSUPP;
7918 goto out;
7919 }
7920
Hila Gonene35e4d22012-06-27 17:19:42 +03007921 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007922 out:
7923 wdev_unlock(wdev);
7924 return err;
7925}
7926
Johannes Berg28946da2011-11-04 11:18:12 +01007927static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7928 struct genl_info *info)
7929{
7930 struct net_device *dev = info->user_ptr[1];
7931 struct wireless_dev *wdev = dev->ieee80211_ptr;
7932
7933 if (wdev->iftype != NL80211_IFTYPE_AP &&
7934 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7935 return -EINVAL;
7936
Eric W. Biederman15e47302012-09-07 20:12:54 +00007937 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01007938 return -EBUSY;
7939
Eric W. Biederman15e47302012-09-07 20:12:54 +00007940 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01007941 return 0;
7942}
7943
Johannes Berg7f6cf312011-11-04 11:18:15 +01007944static int nl80211_probe_client(struct sk_buff *skb,
7945 struct genl_info *info)
7946{
7947 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7948 struct net_device *dev = info->user_ptr[1];
7949 struct wireless_dev *wdev = dev->ieee80211_ptr;
7950 struct sk_buff *msg;
7951 void *hdr;
7952 const u8 *addr;
7953 u64 cookie;
7954 int err;
7955
7956 if (wdev->iftype != NL80211_IFTYPE_AP &&
7957 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7958 return -EOPNOTSUPP;
7959
7960 if (!info->attrs[NL80211_ATTR_MAC])
7961 return -EINVAL;
7962
7963 if (!rdev->ops->probe_client)
7964 return -EOPNOTSUPP;
7965
7966 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7967 if (!msg)
7968 return -ENOMEM;
7969
Eric W. Biederman15e47302012-09-07 20:12:54 +00007970 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01007971 NL80211_CMD_PROBE_CLIENT);
7972
7973 if (IS_ERR(hdr)) {
7974 err = PTR_ERR(hdr);
7975 goto free_msg;
7976 }
7977
7978 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7979
Hila Gonene35e4d22012-06-27 17:19:42 +03007980 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01007981 if (err)
7982 goto free_msg;
7983
David S. Miller9360ffd2012-03-29 04:41:26 -04007984 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7985 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01007986
7987 genlmsg_end(msg, hdr);
7988
7989 return genlmsg_reply(msg, info);
7990
7991 nla_put_failure:
7992 err = -ENOBUFS;
7993 free_msg:
7994 nlmsg_free(msg);
7995 return err;
7996}
7997
Johannes Berg5e7602302011-11-04 11:18:17 +01007998static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
7999{
8000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008001 struct cfg80211_beacon_registration *reg, *nreg;
8002 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008003
8004 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8005 return -EOPNOTSUPP;
8006
Ben Greear37c73b52012-10-26 14:49:25 -07008007 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8008 if (!nreg)
8009 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008010
Ben Greear37c73b52012-10-26 14:49:25 -07008011 /* First, check if already registered. */
8012 spin_lock_bh(&rdev->beacon_registrations_lock);
8013 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8014 if (reg->nlportid == info->snd_portid) {
8015 rv = -EALREADY;
8016 goto out_err;
8017 }
8018 }
8019 /* Add it to the list */
8020 nreg->nlportid = info->snd_portid;
8021 list_add(&nreg->list, &rdev->beacon_registrations);
8022
8023 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008024
8025 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008026out_err:
8027 spin_unlock_bh(&rdev->beacon_registrations_lock);
8028 kfree(nreg);
8029 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008030}
8031
Johannes Berg98104fde2012-06-16 00:19:54 +02008032static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8033{
8034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8035 struct wireless_dev *wdev = info->user_ptr[1];
8036 int err;
8037
8038 if (!rdev->ops->start_p2p_device)
8039 return -EOPNOTSUPP;
8040
8041 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8042 return -EOPNOTSUPP;
8043
8044 if (wdev->p2p_started)
8045 return 0;
8046
8047 mutex_lock(&rdev->devlist_mtx);
8048 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8049 mutex_unlock(&rdev->devlist_mtx);
8050 if (err)
8051 return err;
8052
Johannes Bergeeb126e2012-10-23 15:16:50 +02008053 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008054 if (err)
8055 return err;
8056
8057 wdev->p2p_started = true;
8058 mutex_lock(&rdev->devlist_mtx);
8059 rdev->opencount++;
8060 mutex_unlock(&rdev->devlist_mtx);
8061
8062 return 0;
8063}
8064
8065static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8066{
8067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8068 struct wireless_dev *wdev = info->user_ptr[1];
8069
8070 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8071 return -EOPNOTSUPP;
8072
8073 if (!rdev->ops->stop_p2p_device)
8074 return -EOPNOTSUPP;
8075
8076 if (!wdev->p2p_started)
8077 return 0;
8078
Johannes Bergeeb126e2012-10-23 15:16:50 +02008079 rdev_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008080 wdev->p2p_started = false;
8081
8082 mutex_lock(&rdev->devlist_mtx);
8083 rdev->opencount--;
8084 mutex_unlock(&rdev->devlist_mtx);
8085
8086 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
8087 rdev->scan_req->aborted = true;
8088 ___cfg80211_scan_done(rdev, true);
8089 }
8090
8091 return 0;
8092}
8093
Johannes Berg3713b4e2013-02-14 16:19:38 +01008094static int nl80211_get_protocol_features(struct sk_buff *skb,
8095 struct genl_info *info)
8096{
8097 void *hdr;
8098 struct sk_buff *msg;
8099
8100 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8101 if (!msg)
8102 return -ENOMEM;
8103
8104 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8105 NL80211_CMD_GET_PROTOCOL_FEATURES);
8106 if (!hdr)
8107 goto nla_put_failure;
8108
8109 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8110 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8111 goto nla_put_failure;
8112
8113 genlmsg_end(msg, hdr);
8114 return genlmsg_reply(msg, info);
8115
8116 nla_put_failure:
8117 kfree_skb(msg);
8118 return -ENOBUFS;
8119}
8120
Johannes Berg4c476992010-10-04 21:36:35 +02008121#define NL80211_FLAG_NEED_WIPHY 0x01
8122#define NL80211_FLAG_NEED_NETDEV 0x02
8123#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008124#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8125#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8126 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008127#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008128/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008129#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8130 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008131
8132static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8133 struct genl_info *info)
8134{
8135 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008136 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008137 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008138 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8139
8140 if (rtnl)
8141 rtnl_lock();
8142
8143 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008144 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008145 if (IS_ERR(rdev)) {
8146 if (rtnl)
8147 rtnl_unlock();
8148 return PTR_ERR(rdev);
8149 }
8150 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008151 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8152 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008153 mutex_lock(&cfg80211_mutex);
8154 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8155 info->attrs);
8156 if (IS_ERR(wdev)) {
8157 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02008158 if (rtnl)
8159 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008160 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008161 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008162
Johannes Berg89a54e42012-06-15 14:33:17 +02008163 dev = wdev->netdev;
8164 rdev = wiphy_to_dev(wdev->wiphy);
8165
Johannes Berg1bf614e2012-06-15 15:23:36 +02008166 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8167 if (!dev) {
8168 mutex_unlock(&cfg80211_mutex);
8169 if (rtnl)
8170 rtnl_unlock();
8171 return -EINVAL;
8172 }
8173
8174 info->user_ptr[1] = dev;
8175 } else {
8176 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008177 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008178
Johannes Berg1bf614e2012-06-15 15:23:36 +02008179 if (dev) {
8180 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8181 !netif_running(dev)) {
8182 mutex_unlock(&cfg80211_mutex);
8183 if (rtnl)
8184 rtnl_unlock();
8185 return -ENETDOWN;
8186 }
8187
8188 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008189 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8190 if (!wdev->p2p_started) {
8191 mutex_unlock(&cfg80211_mutex);
8192 if (rtnl)
8193 rtnl_unlock();
8194 return -ENETDOWN;
8195 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008196 }
8197
Johannes Berg89a54e42012-06-15 14:33:17 +02008198 cfg80211_lock_rdev(rdev);
8199
8200 mutex_unlock(&cfg80211_mutex);
8201
Johannes Berg4c476992010-10-04 21:36:35 +02008202 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008203 }
8204
8205 return 0;
8206}
8207
8208static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8209 struct genl_info *info)
8210{
8211 if (info->user_ptr[0])
8212 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02008213 if (info->user_ptr[1]) {
8214 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8215 struct wireless_dev *wdev = info->user_ptr[1];
8216
8217 if (wdev->netdev)
8218 dev_put(wdev->netdev);
8219 } else {
8220 dev_put(info->user_ptr[1]);
8221 }
8222 }
Johannes Berg4c476992010-10-04 21:36:35 +02008223 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8224 rtnl_unlock();
8225}
8226
Johannes Berg55682962007-09-20 13:09:35 -04008227static struct genl_ops nl80211_ops[] = {
8228 {
8229 .cmd = NL80211_CMD_GET_WIPHY,
8230 .doit = nl80211_get_wiphy,
8231 .dumpit = nl80211_dump_wiphy,
8232 .policy = nl80211_policy,
8233 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008234 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04008235 },
8236 {
8237 .cmd = NL80211_CMD_SET_WIPHY,
8238 .doit = nl80211_set_wiphy,
8239 .policy = nl80211_policy,
8240 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008241 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008242 },
8243 {
8244 .cmd = NL80211_CMD_GET_INTERFACE,
8245 .doit = nl80211_get_interface,
8246 .dumpit = nl80211_dump_interface,
8247 .policy = nl80211_policy,
8248 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02008249 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04008250 },
8251 {
8252 .cmd = NL80211_CMD_SET_INTERFACE,
8253 .doit = nl80211_set_interface,
8254 .policy = nl80211_policy,
8255 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008256 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8257 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008258 },
8259 {
8260 .cmd = NL80211_CMD_NEW_INTERFACE,
8261 .doit = nl80211_new_interface,
8262 .policy = nl80211_policy,
8263 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008264 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8265 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008266 },
8267 {
8268 .cmd = NL80211_CMD_DEL_INTERFACE,
8269 .doit = nl80211_del_interface,
8270 .policy = nl80211_policy,
8271 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008272 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008273 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008274 },
Johannes Berg41ade002007-12-19 02:03:29 +01008275 {
8276 .cmd = NL80211_CMD_GET_KEY,
8277 .doit = nl80211_get_key,
8278 .policy = nl80211_policy,
8279 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008280 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008281 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008282 },
8283 {
8284 .cmd = NL80211_CMD_SET_KEY,
8285 .doit = nl80211_set_key,
8286 .policy = nl80211_policy,
8287 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008288 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008289 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008290 },
8291 {
8292 .cmd = NL80211_CMD_NEW_KEY,
8293 .doit = nl80211_new_key,
8294 .policy = nl80211_policy,
8295 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008296 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008297 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008298 },
8299 {
8300 .cmd = NL80211_CMD_DEL_KEY,
8301 .doit = nl80211_del_key,
8302 .policy = nl80211_policy,
8303 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008304 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008305 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008306 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008307 {
8308 .cmd = NL80211_CMD_SET_BEACON,
8309 .policy = nl80211_policy,
8310 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008311 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008312 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008313 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008314 },
8315 {
Johannes Berg88600202012-02-13 15:17:18 +01008316 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008317 .policy = nl80211_policy,
8318 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008319 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008320 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008321 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008322 },
8323 {
Johannes Berg88600202012-02-13 15:17:18 +01008324 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008325 .policy = nl80211_policy,
8326 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008327 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008328 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008329 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008330 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008331 {
8332 .cmd = NL80211_CMD_GET_STATION,
8333 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008334 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008335 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008336 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8337 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008338 },
8339 {
8340 .cmd = NL80211_CMD_SET_STATION,
8341 .doit = nl80211_set_station,
8342 .policy = nl80211_policy,
8343 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008344 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008345 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008346 },
8347 {
8348 .cmd = NL80211_CMD_NEW_STATION,
8349 .doit = nl80211_new_station,
8350 .policy = nl80211_policy,
8351 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008352 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008353 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008354 },
8355 {
8356 .cmd = NL80211_CMD_DEL_STATION,
8357 .doit = nl80211_del_station,
8358 .policy = nl80211_policy,
8359 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008360 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008361 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008362 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008363 {
8364 .cmd = NL80211_CMD_GET_MPATH,
8365 .doit = nl80211_get_mpath,
8366 .dumpit = nl80211_dump_mpath,
8367 .policy = nl80211_policy,
8368 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008369 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008370 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008371 },
8372 {
8373 .cmd = NL80211_CMD_SET_MPATH,
8374 .doit = nl80211_set_mpath,
8375 .policy = nl80211_policy,
8376 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008377 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008378 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008379 },
8380 {
8381 .cmd = NL80211_CMD_NEW_MPATH,
8382 .doit = nl80211_new_mpath,
8383 .policy = nl80211_policy,
8384 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008385 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008386 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008387 },
8388 {
8389 .cmd = NL80211_CMD_DEL_MPATH,
8390 .doit = nl80211_del_mpath,
8391 .policy = nl80211_policy,
8392 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008393 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008394 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008395 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008396 {
8397 .cmd = NL80211_CMD_SET_BSS,
8398 .doit = nl80211_set_bss,
8399 .policy = nl80211_policy,
8400 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008401 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008402 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008403 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008404 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008405 .cmd = NL80211_CMD_GET_REG,
8406 .doit = nl80211_get_reg,
8407 .policy = nl80211_policy,
8408 /* can be retrieved by unprivileged users */
8409 },
8410 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008411 .cmd = NL80211_CMD_SET_REG,
8412 .doit = nl80211_set_reg,
8413 .policy = nl80211_policy,
8414 .flags = GENL_ADMIN_PERM,
8415 },
8416 {
8417 .cmd = NL80211_CMD_REQ_SET_REG,
8418 .doit = nl80211_req_set_reg,
8419 .policy = nl80211_policy,
8420 .flags = GENL_ADMIN_PERM,
8421 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008422 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008423 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8424 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008425 .policy = nl80211_policy,
8426 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008428 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008429 },
8430 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008431 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8432 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008433 .policy = nl80211_policy,
8434 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008436 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008437 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008438 {
Johannes Berg2a519312009-02-10 21:25:55 +01008439 .cmd = NL80211_CMD_TRIGGER_SCAN,
8440 .doit = nl80211_trigger_scan,
8441 .policy = nl80211_policy,
8442 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008443 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008444 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008445 },
8446 {
8447 .cmd = NL80211_CMD_GET_SCAN,
8448 .policy = nl80211_policy,
8449 .dumpit = nl80211_dump_scan,
8450 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008451 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008452 .cmd = NL80211_CMD_START_SCHED_SCAN,
8453 .doit = nl80211_start_sched_scan,
8454 .policy = nl80211_policy,
8455 .flags = GENL_ADMIN_PERM,
8456 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8457 NL80211_FLAG_NEED_RTNL,
8458 },
8459 {
8460 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8461 .doit = nl80211_stop_sched_scan,
8462 .policy = nl80211_policy,
8463 .flags = GENL_ADMIN_PERM,
8464 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8465 NL80211_FLAG_NEED_RTNL,
8466 },
8467 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008468 .cmd = NL80211_CMD_AUTHENTICATE,
8469 .doit = nl80211_authenticate,
8470 .policy = nl80211_policy,
8471 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008473 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008474 },
8475 {
8476 .cmd = NL80211_CMD_ASSOCIATE,
8477 .doit = nl80211_associate,
8478 .policy = nl80211_policy,
8479 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008480 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008481 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008482 },
8483 {
8484 .cmd = NL80211_CMD_DEAUTHENTICATE,
8485 .doit = nl80211_deauthenticate,
8486 .policy = nl80211_policy,
8487 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008488 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008489 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008490 },
8491 {
8492 .cmd = NL80211_CMD_DISASSOCIATE,
8493 .doit = nl80211_disassociate,
8494 .policy = nl80211_policy,
8495 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008496 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008497 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008498 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008499 {
8500 .cmd = NL80211_CMD_JOIN_IBSS,
8501 .doit = nl80211_join_ibss,
8502 .policy = nl80211_policy,
8503 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008504 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008505 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008506 },
8507 {
8508 .cmd = NL80211_CMD_LEAVE_IBSS,
8509 .doit = nl80211_leave_ibss,
8510 .policy = nl80211_policy,
8511 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008512 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008513 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008514 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008515#ifdef CONFIG_NL80211_TESTMODE
8516 {
8517 .cmd = NL80211_CMD_TESTMODE,
8518 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008519 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008520 .policy = nl80211_policy,
8521 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008522 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8523 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008524 },
8525#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008526 {
8527 .cmd = NL80211_CMD_CONNECT,
8528 .doit = nl80211_connect,
8529 .policy = nl80211_policy,
8530 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008531 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008532 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008533 },
8534 {
8535 .cmd = NL80211_CMD_DISCONNECT,
8536 .doit = nl80211_disconnect,
8537 .policy = nl80211_policy,
8538 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008539 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008540 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008541 },
Johannes Berg463d0182009-07-14 00:33:35 +02008542 {
8543 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8544 .doit = nl80211_wiphy_netns,
8545 .policy = nl80211_policy,
8546 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008547 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8548 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008549 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008550 {
8551 .cmd = NL80211_CMD_GET_SURVEY,
8552 .policy = nl80211_policy,
8553 .dumpit = nl80211_dump_survey,
8554 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008555 {
8556 .cmd = NL80211_CMD_SET_PMKSA,
8557 .doit = nl80211_setdel_pmksa,
8558 .policy = nl80211_policy,
8559 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008560 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008561 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008562 },
8563 {
8564 .cmd = NL80211_CMD_DEL_PMKSA,
8565 .doit = nl80211_setdel_pmksa,
8566 .policy = nl80211_policy,
8567 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008568 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008569 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008570 },
8571 {
8572 .cmd = NL80211_CMD_FLUSH_PMKSA,
8573 .doit = nl80211_flush_pmksa,
8574 .policy = nl80211_policy,
8575 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008576 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008577 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008578 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008579 {
8580 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8581 .doit = nl80211_remain_on_channel,
8582 .policy = nl80211_policy,
8583 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008584 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008585 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008586 },
8587 {
8588 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8589 .doit = nl80211_cancel_remain_on_channel,
8590 .policy = nl80211_policy,
8591 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008592 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008593 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008594 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008595 {
8596 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8597 .doit = nl80211_set_tx_bitrate_mask,
8598 .policy = nl80211_policy,
8599 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008600 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8601 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008602 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008603 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008604 .cmd = NL80211_CMD_REGISTER_FRAME,
8605 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008606 .policy = nl80211_policy,
8607 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008608 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008609 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008610 },
8611 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008612 .cmd = NL80211_CMD_FRAME,
8613 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008614 .policy = nl80211_policy,
8615 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008616 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008617 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008618 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008619 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008620 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8621 .doit = nl80211_tx_mgmt_cancel_wait,
8622 .policy = nl80211_policy,
8623 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008624 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008625 NL80211_FLAG_NEED_RTNL,
8626 },
8627 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008628 .cmd = NL80211_CMD_SET_POWER_SAVE,
8629 .doit = nl80211_set_power_save,
8630 .policy = nl80211_policy,
8631 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008632 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8633 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008634 },
8635 {
8636 .cmd = NL80211_CMD_GET_POWER_SAVE,
8637 .doit = nl80211_get_power_save,
8638 .policy = nl80211_policy,
8639 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008640 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8641 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008642 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008643 {
8644 .cmd = NL80211_CMD_SET_CQM,
8645 .doit = nl80211_set_cqm,
8646 .policy = nl80211_policy,
8647 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008648 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8649 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008650 },
Johannes Bergf444de02010-05-05 15:25:02 +02008651 {
8652 .cmd = NL80211_CMD_SET_CHANNEL,
8653 .doit = nl80211_set_channel,
8654 .policy = nl80211_policy,
8655 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008656 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8657 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008658 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008659 {
8660 .cmd = NL80211_CMD_SET_WDS_PEER,
8661 .doit = nl80211_set_wds_peer,
8662 .policy = nl80211_policy,
8663 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008664 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8665 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008666 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008667 {
8668 .cmd = NL80211_CMD_JOIN_MESH,
8669 .doit = nl80211_join_mesh,
8670 .policy = nl80211_policy,
8671 .flags = GENL_ADMIN_PERM,
8672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8673 NL80211_FLAG_NEED_RTNL,
8674 },
8675 {
8676 .cmd = NL80211_CMD_LEAVE_MESH,
8677 .doit = nl80211_leave_mesh,
8678 .policy = nl80211_policy,
8679 .flags = GENL_ADMIN_PERM,
8680 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8681 NL80211_FLAG_NEED_RTNL,
8682 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008683#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008684 {
8685 .cmd = NL80211_CMD_GET_WOWLAN,
8686 .doit = nl80211_get_wowlan,
8687 .policy = nl80211_policy,
8688 /* can be retrieved by unprivileged users */
8689 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8690 NL80211_FLAG_NEED_RTNL,
8691 },
8692 {
8693 .cmd = NL80211_CMD_SET_WOWLAN,
8694 .doit = nl80211_set_wowlan,
8695 .policy = nl80211_policy,
8696 .flags = GENL_ADMIN_PERM,
8697 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8698 NL80211_FLAG_NEED_RTNL,
8699 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008700#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008701 {
8702 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8703 .doit = nl80211_set_rekey_data,
8704 .policy = nl80211_policy,
8705 .flags = GENL_ADMIN_PERM,
8706 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8707 NL80211_FLAG_NEED_RTNL,
8708 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008709 {
8710 .cmd = NL80211_CMD_TDLS_MGMT,
8711 .doit = nl80211_tdls_mgmt,
8712 .policy = nl80211_policy,
8713 .flags = GENL_ADMIN_PERM,
8714 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8715 NL80211_FLAG_NEED_RTNL,
8716 },
8717 {
8718 .cmd = NL80211_CMD_TDLS_OPER,
8719 .doit = nl80211_tdls_oper,
8720 .policy = nl80211_policy,
8721 .flags = GENL_ADMIN_PERM,
8722 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8723 NL80211_FLAG_NEED_RTNL,
8724 },
Johannes Berg28946da2011-11-04 11:18:12 +01008725 {
8726 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8727 .doit = nl80211_register_unexpected_frame,
8728 .policy = nl80211_policy,
8729 .flags = GENL_ADMIN_PERM,
8730 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8731 NL80211_FLAG_NEED_RTNL,
8732 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008733 {
8734 .cmd = NL80211_CMD_PROBE_CLIENT,
8735 .doit = nl80211_probe_client,
8736 .policy = nl80211_policy,
8737 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008738 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008739 NL80211_FLAG_NEED_RTNL,
8740 },
Johannes Berg5e7602302011-11-04 11:18:17 +01008741 {
8742 .cmd = NL80211_CMD_REGISTER_BEACONS,
8743 .doit = nl80211_register_beacons,
8744 .policy = nl80211_policy,
8745 .flags = GENL_ADMIN_PERM,
8746 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8747 NL80211_FLAG_NEED_RTNL,
8748 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008749 {
8750 .cmd = NL80211_CMD_SET_NOACK_MAP,
8751 .doit = nl80211_set_noack_map,
8752 .policy = nl80211_policy,
8753 .flags = GENL_ADMIN_PERM,
8754 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8755 NL80211_FLAG_NEED_RTNL,
8756 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008757 {
8758 .cmd = NL80211_CMD_START_P2P_DEVICE,
8759 .doit = nl80211_start_p2p_device,
8760 .policy = nl80211_policy,
8761 .flags = GENL_ADMIN_PERM,
8762 .internal_flags = NL80211_FLAG_NEED_WDEV |
8763 NL80211_FLAG_NEED_RTNL,
8764 },
8765 {
8766 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8767 .doit = nl80211_stop_p2p_device,
8768 .policy = nl80211_policy,
8769 .flags = GENL_ADMIN_PERM,
8770 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8771 NL80211_FLAG_NEED_RTNL,
8772 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008773 {
8774 .cmd = NL80211_CMD_SET_MCAST_RATE,
8775 .doit = nl80211_set_mcast_rate,
8776 .policy = nl80211_policy,
8777 .flags = GENL_ADMIN_PERM,
8778 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8779 NL80211_FLAG_NEED_RTNL,
8780 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308781 {
8782 .cmd = NL80211_CMD_SET_MAC_ACL,
8783 .doit = nl80211_set_mac_acl,
8784 .policy = nl80211_policy,
8785 .flags = GENL_ADMIN_PERM,
8786 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8787 NL80211_FLAG_NEED_RTNL,
8788 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008789 {
8790 .cmd = NL80211_CMD_RADAR_DETECT,
8791 .doit = nl80211_start_radar_detection,
8792 .policy = nl80211_policy,
8793 .flags = GENL_ADMIN_PERM,
8794 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8795 NL80211_FLAG_NEED_RTNL,
8796 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008797 {
8798 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8799 .doit = nl80211_get_protocol_features,
8800 .policy = nl80211_policy,
8801 },
Johannes Berg55682962007-09-20 13:09:35 -04008802};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008803
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008804static struct genl_multicast_group nl80211_mlme_mcgrp = {
8805 .name = "mlme",
8806};
Johannes Berg55682962007-09-20 13:09:35 -04008807
8808/* multicast groups */
8809static struct genl_multicast_group nl80211_config_mcgrp = {
8810 .name = "config",
8811};
Johannes Berg2a519312009-02-10 21:25:55 +01008812static struct genl_multicast_group nl80211_scan_mcgrp = {
8813 .name = "scan",
8814};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008815static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8816 .name = "regulatory",
8817};
Johannes Berg55682962007-09-20 13:09:35 -04008818
8819/* notification functions */
8820
8821void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8822{
8823 struct sk_buff *msg;
8824
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008825 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008826 if (!msg)
8827 return;
8828
Johannes Berg3713b4e2013-02-14 16:19:38 +01008829 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8830 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008831 nlmsg_free(msg);
8832 return;
8833 }
8834
Johannes Berg463d0182009-07-14 00:33:35 +02008835 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8836 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008837}
8838
Johannes Berg362a4152009-05-24 16:43:15 +02008839static int nl80211_add_scan_req(struct sk_buff *msg,
8840 struct cfg80211_registered_device *rdev)
8841{
8842 struct cfg80211_scan_request *req = rdev->scan_req;
8843 struct nlattr *nest;
8844 int i;
8845
Johannes Berg667503dd2009-07-07 03:56:11 +02008846 ASSERT_RDEV_LOCK(rdev);
8847
Johannes Berg362a4152009-05-24 16:43:15 +02008848 if (WARN_ON(!req))
8849 return 0;
8850
8851 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8852 if (!nest)
8853 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008854 for (i = 0; i < req->n_ssids; i++) {
8855 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8856 goto nla_put_failure;
8857 }
Johannes Berg362a4152009-05-24 16:43:15 +02008858 nla_nest_end(msg, nest);
8859
8860 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8861 if (!nest)
8862 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008863 for (i = 0; i < req->n_channels; i++) {
8864 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8865 goto nla_put_failure;
8866 }
Johannes Berg362a4152009-05-24 16:43:15 +02008867 nla_nest_end(msg, nest);
8868
David S. Miller9360ffd2012-03-29 04:41:26 -04008869 if (req->ie &&
8870 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8871 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008872
Sam Lefflered4737712012-10-11 21:03:31 -07008873 if (req->flags)
8874 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8875
Johannes Berg362a4152009-05-24 16:43:15 +02008876 return 0;
8877 nla_put_failure:
8878 return -ENOBUFS;
8879}
8880
Johannes Berga538e2d2009-06-16 19:56:42 +02008881static int nl80211_send_scan_msg(struct sk_buff *msg,
8882 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008883 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008884 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008885 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008886{
8887 void *hdr;
8888
Eric W. Biederman15e47302012-09-07 20:12:54 +00008889 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008890 if (!hdr)
8891 return -1;
8892
David S. Miller9360ffd2012-03-29 04:41:26 -04008893 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008894 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8895 wdev->netdev->ifindex)) ||
8896 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008897 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008898
Johannes Berg362a4152009-05-24 16:43:15 +02008899 /* ignore errors and send incomplete event anyway */
8900 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008901
8902 return genlmsg_end(msg, hdr);
8903
8904 nla_put_failure:
8905 genlmsg_cancel(msg, hdr);
8906 return -EMSGSIZE;
8907}
8908
Luciano Coelho807f8a82011-05-11 17:09:35 +03008909static int
8910nl80211_send_sched_scan_msg(struct sk_buff *msg,
8911 struct cfg80211_registered_device *rdev,
8912 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008913 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008914{
8915 void *hdr;
8916
Eric W. Biederman15e47302012-09-07 20:12:54 +00008917 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008918 if (!hdr)
8919 return -1;
8920
David S. Miller9360ffd2012-03-29 04:41:26 -04008921 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8922 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8923 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008924
8925 return genlmsg_end(msg, hdr);
8926
8927 nla_put_failure:
8928 genlmsg_cancel(msg, hdr);
8929 return -EMSGSIZE;
8930}
8931
Johannes Berga538e2d2009-06-16 19:56:42 +02008932void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008933 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02008934{
8935 struct sk_buff *msg;
8936
Thomas Graf58050fc2012-06-28 03:57:45 +00008937 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008938 if (!msg)
8939 return;
8940
Johannes Bergfd014282012-06-18 19:17:03 +02008941 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008942 NL80211_CMD_TRIGGER_SCAN) < 0) {
8943 nlmsg_free(msg);
8944 return;
8945 }
8946
Johannes Berg463d0182009-07-14 00:33:35 +02008947 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8948 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008949}
8950
Johannes Berg2a519312009-02-10 21:25:55 +01008951void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008952 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01008953{
8954 struct sk_buff *msg;
8955
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008956 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008957 if (!msg)
8958 return;
8959
Johannes Bergfd014282012-06-18 19:17:03 +02008960 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008961 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008962 nlmsg_free(msg);
8963 return;
8964 }
8965
Johannes Berg463d0182009-07-14 00:33:35 +02008966 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8967 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008968}
8969
8970void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008971 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01008972{
8973 struct sk_buff *msg;
8974
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008975 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008976 if (!msg)
8977 return;
8978
Johannes Bergfd014282012-06-18 19:17:03 +02008979 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008980 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008981 nlmsg_free(msg);
8982 return;
8983 }
8984
Johannes Berg463d0182009-07-14 00:33:35 +02008985 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8986 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008987}
8988
Luciano Coelho807f8a82011-05-11 17:09:35 +03008989void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
8990 struct net_device *netdev)
8991{
8992 struct sk_buff *msg;
8993
8994 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8995 if (!msg)
8996 return;
8997
8998 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
8999 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9000 nlmsg_free(msg);
9001 return;
9002 }
9003
9004 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9005 nl80211_scan_mcgrp.id, GFP_KERNEL);
9006}
9007
9008void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9009 struct net_device *netdev, u32 cmd)
9010{
9011 struct sk_buff *msg;
9012
Thomas Graf58050fc2012-06-28 03:57:45 +00009013 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009014 if (!msg)
9015 return;
9016
9017 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9018 nlmsg_free(msg);
9019 return;
9020 }
9021
9022 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9023 nl80211_scan_mcgrp.id, GFP_KERNEL);
9024}
9025
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009026/*
9027 * This can happen on global regulatory changes or device specific settings
9028 * based on custom world regulatory domains.
9029 */
9030void nl80211_send_reg_change_event(struct regulatory_request *request)
9031{
9032 struct sk_buff *msg;
9033 void *hdr;
9034
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009036 if (!msg)
9037 return;
9038
9039 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9040 if (!hdr) {
9041 nlmsg_free(msg);
9042 return;
9043 }
9044
9045 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009046 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9047 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009048
David S. Miller9360ffd2012-03-29 04:41:26 -04009049 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9050 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9051 NL80211_REGDOM_TYPE_WORLD))
9052 goto nla_put_failure;
9053 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9054 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9055 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9056 goto nla_put_failure;
9057 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9058 request->intersect) {
9059 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9060 NL80211_REGDOM_TYPE_INTERSECTION))
9061 goto nla_put_failure;
9062 } else {
9063 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9064 NL80211_REGDOM_TYPE_COUNTRY) ||
9065 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9066 request->alpha2))
9067 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009068 }
9069
Johannes Bergf4173762012-12-03 18:23:37 +01009070 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009071 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9072 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009073
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009074 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009075
Johannes Bergbc43b282009-07-25 10:54:13 +02009076 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009077 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009078 GFP_ATOMIC);
9079 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009080
9081 return;
9082
9083nla_put_failure:
9084 genlmsg_cancel(msg, hdr);
9085 nlmsg_free(msg);
9086}
9087
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009088static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9089 struct net_device *netdev,
9090 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009091 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009092{
9093 struct sk_buff *msg;
9094 void *hdr;
9095
Johannes Berge6d6e342009-07-01 21:26:47 +02009096 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009097 if (!msg)
9098 return;
9099
9100 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9101 if (!hdr) {
9102 nlmsg_free(msg);
9103 return;
9104 }
9105
David S. Miller9360ffd2012-03-29 04:41:26 -04009106 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9107 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9108 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9109 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009110
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009111 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009112
Johannes Berg463d0182009-07-14 00:33:35 +02009113 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9114 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009115 return;
9116
9117 nla_put_failure:
9118 genlmsg_cancel(msg, hdr);
9119 nlmsg_free(msg);
9120}
9121
9122void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009123 struct net_device *netdev, const u8 *buf,
9124 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009125{
9126 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009127 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009128}
9129
9130void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9131 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009132 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009133{
Johannes Berge6d6e342009-07-01 21:26:47 +02009134 nl80211_send_mlme_event(rdev, netdev, buf, len,
9135 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009136}
9137
Jouni Malinen53b46b82009-03-27 20:53:56 +02009138void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009139 struct net_device *netdev, const u8 *buf,
9140 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009141{
9142 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009143 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009144}
9145
Jouni Malinen53b46b82009-03-27 20:53:56 +02009146void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9147 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009148 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009149{
9150 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009151 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009152}
9153
Johannes Berg947add32013-02-22 22:05:20 +01009154void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9155 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009156{
Johannes Berg947add32013-02-22 22:05:20 +01009157 struct wireless_dev *wdev = dev->ieee80211_ptr;
9158 struct wiphy *wiphy = wdev->wiphy;
9159 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009160
Johannes Berg947add32013-02-22 22:05:20 +01009161 trace_cfg80211_send_unprot_deauth(dev);
9162 nl80211_send_mlme_event(rdev, dev, buf, len,
9163 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009164}
Johannes Berg947add32013-02-22 22:05:20 +01009165EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9166
9167void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9168 size_t len)
9169{
9170 struct wireless_dev *wdev = dev->ieee80211_ptr;
9171 struct wiphy *wiphy = wdev->wiphy;
9172 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9173
9174 trace_cfg80211_send_unprot_disassoc(dev);
9175 nl80211_send_mlme_event(rdev, dev, buf, len,
9176 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9177}
9178EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009179
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009180static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9181 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009182 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009183{
9184 struct sk_buff *msg;
9185 void *hdr;
9186
Johannes Berge6d6e342009-07-01 21:26:47 +02009187 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009188 if (!msg)
9189 return;
9190
9191 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9192 if (!hdr) {
9193 nlmsg_free(msg);
9194 return;
9195 }
9196
David S. Miller9360ffd2012-03-29 04:41:26 -04009197 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9198 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9199 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9200 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9201 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009202
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009203 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009204
Johannes Berg463d0182009-07-14 00:33:35 +02009205 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9206 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009207 return;
9208
9209 nla_put_failure:
9210 genlmsg_cancel(msg, hdr);
9211 nlmsg_free(msg);
9212}
9213
9214void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009215 struct net_device *netdev, const u8 *addr,
9216 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009217{
9218 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009219 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009220}
9221
9222void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009223 struct net_device *netdev, const u8 *addr,
9224 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009225{
Johannes Berge6d6e342009-07-01 21:26:47 +02009226 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9227 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009228}
9229
Samuel Ortizb23aa672009-07-01 21:26:54 +02009230void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9231 struct net_device *netdev, const u8 *bssid,
9232 const u8 *req_ie, size_t req_ie_len,
9233 const u8 *resp_ie, size_t resp_ie_len,
9234 u16 status, 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_CONNECT);
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 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9252 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9253 (req_ie &&
9254 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9255 (resp_ie &&
9256 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9257 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009258
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009259 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009260
Johannes Berg463d0182009-07-14 00:33:35 +02009261 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9262 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009263 return;
9264
9265 nla_put_failure:
9266 genlmsg_cancel(msg, hdr);
9267 nlmsg_free(msg);
9268
9269}
9270
9271void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9272 struct net_device *netdev, const u8 *bssid,
9273 const u8 *req_ie, size_t req_ie_len,
9274 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9275{
9276 struct sk_buff *msg;
9277 void *hdr;
9278
Thomas Graf58050fc2012-06-28 03:57:45 +00009279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009280 if (!msg)
9281 return;
9282
9283 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9284 if (!hdr) {
9285 nlmsg_free(msg);
9286 return;
9287 }
9288
David S. Miller9360ffd2012-03-29 04:41:26 -04009289 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9290 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9291 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9292 (req_ie &&
9293 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9294 (resp_ie &&
9295 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9296 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009297
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009298 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009299
Johannes Berg463d0182009-07-14 00:33:35 +02009300 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9301 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009302 return;
9303
9304 nla_put_failure:
9305 genlmsg_cancel(msg, hdr);
9306 nlmsg_free(msg);
9307
9308}
9309
9310void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9311 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009312 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009313{
9314 struct sk_buff *msg;
9315 void *hdr;
9316
Thomas Graf58050fc2012-06-28 03:57:45 +00009317 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009318 if (!msg)
9319 return;
9320
9321 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9322 if (!hdr) {
9323 nlmsg_free(msg);
9324 return;
9325 }
9326
David S. Miller9360ffd2012-03-29 04:41:26 -04009327 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9328 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9329 (from_ap && reason &&
9330 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9331 (from_ap &&
9332 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9333 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9334 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009335
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009336 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009337
Johannes Berg463d0182009-07-14 00:33:35 +02009338 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9339 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009340 return;
9341
9342 nla_put_failure:
9343 genlmsg_cancel(msg, hdr);
9344 nlmsg_free(msg);
9345
9346}
9347
Johannes Berg04a773a2009-04-19 21:24:32 +02009348void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9349 struct net_device *netdev, const u8 *bssid,
9350 gfp_t gfp)
9351{
9352 struct sk_buff *msg;
9353 void *hdr;
9354
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009355 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009356 if (!msg)
9357 return;
9358
9359 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9360 if (!hdr) {
9361 nlmsg_free(msg);
9362 return;
9363 }
9364
David S. Miller9360ffd2012-03-29 04:41:26 -04009365 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9366 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9367 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9368 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009369
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009370 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009371
Johannes Berg463d0182009-07-14 00:33:35 +02009372 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9373 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009374 return;
9375
9376 nla_put_failure:
9377 genlmsg_cancel(msg, hdr);
9378 nlmsg_free(msg);
9379}
9380
Johannes Berg947add32013-02-22 22:05:20 +01009381void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9382 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009383{
Johannes Berg947add32013-02-22 22:05:20 +01009384 struct wireless_dev *wdev = dev->ieee80211_ptr;
9385 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009386 struct sk_buff *msg;
9387 void *hdr;
9388
Johannes Berg947add32013-02-22 22:05:20 +01009389 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9390 return;
9391
9392 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9393
Javier Cardonac93b5e72011-04-07 15:08:34 -07009394 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9395 if (!msg)
9396 return;
9397
9398 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9399 if (!hdr) {
9400 nlmsg_free(msg);
9401 return;
9402 }
9403
David S. Miller9360ffd2012-03-29 04:41:26 -04009404 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009405 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9406 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009407 (ie_len && ie &&
9408 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9409 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009410
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009411 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009412
9413 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9414 nl80211_mlme_mcgrp.id, gfp);
9415 return;
9416
9417 nla_put_failure:
9418 genlmsg_cancel(msg, hdr);
9419 nlmsg_free(msg);
9420}
Johannes Berg947add32013-02-22 22:05:20 +01009421EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009422
Jouni Malinena3b8b052009-03-27 21:59:49 +02009423void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9424 struct net_device *netdev, const u8 *addr,
9425 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009426 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009427{
9428 struct sk_buff *msg;
9429 void *hdr;
9430
Johannes Berge6d6e342009-07-01 21:26:47 +02009431 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009432 if (!msg)
9433 return;
9434
9435 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9436 if (!hdr) {
9437 nlmsg_free(msg);
9438 return;
9439 }
9440
David S. Miller9360ffd2012-03-29 04:41:26 -04009441 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9442 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9443 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9444 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9445 (key_id != -1 &&
9446 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9447 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9448 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009449
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009450 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009451
Johannes Berg463d0182009-07-14 00:33:35 +02009452 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9453 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009454 return;
9455
9456 nla_put_failure:
9457 genlmsg_cancel(msg, hdr);
9458 nlmsg_free(msg);
9459}
9460
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009461void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9462 struct ieee80211_channel *channel_before,
9463 struct ieee80211_channel *channel_after)
9464{
9465 struct sk_buff *msg;
9466 void *hdr;
9467 struct nlattr *nl_freq;
9468
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009470 if (!msg)
9471 return;
9472
9473 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9474 if (!hdr) {
9475 nlmsg_free(msg);
9476 return;
9477 }
9478
9479 /*
9480 * Since we are applying the beacon hint to a wiphy we know its
9481 * wiphy_idx is valid
9482 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009483 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9484 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009485
9486 /* Before */
9487 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9488 if (!nl_freq)
9489 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009490 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009491 goto nla_put_failure;
9492 nla_nest_end(msg, nl_freq);
9493
9494 /* After */
9495 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9496 if (!nl_freq)
9497 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009498 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009499 goto nla_put_failure;
9500 nla_nest_end(msg, nl_freq);
9501
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009502 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009503
Johannes Berg463d0182009-07-14 00:33:35 +02009504 rcu_read_lock();
9505 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9506 GFP_ATOMIC);
9507 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009508
9509 return;
9510
9511nla_put_failure:
9512 genlmsg_cancel(msg, hdr);
9513 nlmsg_free(msg);
9514}
9515
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009516static void nl80211_send_remain_on_chan_event(
9517 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009518 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009519 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009520 unsigned int duration, gfp_t gfp)
9521{
9522 struct sk_buff *msg;
9523 void *hdr;
9524
9525 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9526 if (!msg)
9527 return;
9528
9529 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9530 if (!hdr) {
9531 nlmsg_free(msg);
9532 return;
9533 }
9534
David S. Miller9360ffd2012-03-29 04:41:26 -04009535 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009536 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9537 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009538 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009539 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009540 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9541 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009542 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9543 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009544
David S. Miller9360ffd2012-03-29 04:41:26 -04009545 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9546 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9547 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009548
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009549 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009550
9551 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9552 nl80211_mlme_mcgrp.id, gfp);
9553 return;
9554
9555 nla_put_failure:
9556 genlmsg_cancel(msg, hdr);
9557 nlmsg_free(msg);
9558}
9559
Johannes Berg947add32013-02-22 22:05:20 +01009560void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9561 struct ieee80211_channel *chan,
9562 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009563{
Johannes Berg947add32013-02-22 22:05:20 +01009564 struct wiphy *wiphy = wdev->wiphy;
9565 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9566
9567 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009568 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009569 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009570 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009571}
Johannes Berg947add32013-02-22 22:05:20 +01009572EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009573
Johannes Berg947add32013-02-22 22:05:20 +01009574void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9575 struct ieee80211_channel *chan,
9576 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009577{
Johannes Berg947add32013-02-22 22:05:20 +01009578 struct wiphy *wiphy = wdev->wiphy;
9579 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9580
9581 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009582 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009583 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009584}
Johannes Berg947add32013-02-22 22:05:20 +01009585EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009586
Johannes Berg947add32013-02-22 22:05:20 +01009587void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9588 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009589{
Johannes Berg947add32013-02-22 22:05:20 +01009590 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9591 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009592 struct sk_buff *msg;
9593
Johannes Berg947add32013-02-22 22:05:20 +01009594 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9595
Thomas Graf58050fc2012-06-28 03:57:45 +00009596 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009597 if (!msg)
9598 return;
9599
John W. Linville66266b32012-03-15 13:25:41 -04009600 if (nl80211_send_station(msg, 0, 0, 0,
9601 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009602 nlmsg_free(msg);
9603 return;
9604 }
9605
9606 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9607 nl80211_mlme_mcgrp.id, gfp);
9608}
Johannes Berg947add32013-02-22 22:05:20 +01009609EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009610
Johannes Berg947add32013-02-22 22:05:20 +01009611void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009612{
Johannes Berg947add32013-02-22 22:05:20 +01009613 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9614 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009615 struct sk_buff *msg;
9616 void *hdr;
9617
Johannes Berg947add32013-02-22 22:05:20 +01009618 trace_cfg80211_del_sta(dev, mac_addr);
9619
Thomas Graf58050fc2012-06-28 03:57:45 +00009620 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009621 if (!msg)
9622 return;
9623
9624 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9625 if (!hdr) {
9626 nlmsg_free(msg);
9627 return;
9628 }
9629
David S. Miller9360ffd2012-03-29 04:41:26 -04009630 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9631 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9632 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009633
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009634 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009635
9636 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9637 nl80211_mlme_mcgrp.id, gfp);
9638 return;
9639
9640 nla_put_failure:
9641 genlmsg_cancel(msg, hdr);
9642 nlmsg_free(msg);
9643}
Johannes Berg947add32013-02-22 22:05:20 +01009644EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009645
Johannes Berg947add32013-02-22 22:05:20 +01009646void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9647 enum nl80211_connect_failed_reason reason,
9648 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309649{
Johannes Berg947add32013-02-22 22:05:20 +01009650 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9651 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309652 struct sk_buff *msg;
9653 void *hdr;
9654
9655 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9656 if (!msg)
9657 return;
9658
9659 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9660 if (!hdr) {
9661 nlmsg_free(msg);
9662 return;
9663 }
9664
9665 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9666 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9667 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9668 goto nla_put_failure;
9669
9670 genlmsg_end(msg, hdr);
9671
9672 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9673 nl80211_mlme_mcgrp.id, gfp);
9674 return;
9675
9676 nla_put_failure:
9677 genlmsg_cancel(msg, hdr);
9678 nlmsg_free(msg);
9679}
Johannes Berg947add32013-02-22 22:05:20 +01009680EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309681
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009682static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9683 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009684{
9685 struct wireless_dev *wdev = dev->ieee80211_ptr;
9686 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9687 struct sk_buff *msg;
9688 void *hdr;
9689 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009690 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009691
Eric W. Biederman15e47302012-09-07 20:12:54 +00009692 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009693 return false;
9694
9695 msg = nlmsg_new(100, gfp);
9696 if (!msg)
9697 return true;
9698
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009699 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009700 if (!hdr) {
9701 nlmsg_free(msg);
9702 return true;
9703 }
9704
David S. Miller9360ffd2012-03-29 04:41:26 -04009705 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9707 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9708 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009709
9710 err = genlmsg_end(msg, hdr);
9711 if (err < 0) {
9712 nlmsg_free(msg);
9713 return true;
9714 }
9715
Eric W. Biederman15e47302012-09-07 20:12:54 +00009716 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009717 return true;
9718
9719 nla_put_failure:
9720 genlmsg_cancel(msg, hdr);
9721 nlmsg_free(msg);
9722 return true;
9723}
9724
Johannes Berg947add32013-02-22 22:05:20 +01009725bool cfg80211_rx_spurious_frame(struct net_device *dev,
9726 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009727{
Johannes Berg947add32013-02-22 22:05:20 +01009728 struct wireless_dev *wdev = dev->ieee80211_ptr;
9729 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009730
Johannes Berg947add32013-02-22 22:05:20 +01009731 trace_cfg80211_rx_spurious_frame(dev, addr);
9732
9733 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9734 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9735 trace_cfg80211_return_bool(false);
9736 return false;
9737 }
9738 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9739 addr, gfp);
9740 trace_cfg80211_return_bool(ret);
9741 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009742}
Johannes Berg947add32013-02-22 22:05:20 +01009743EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9744
9745bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9746 const u8 *addr, gfp_t gfp)
9747{
9748 struct wireless_dev *wdev = dev->ieee80211_ptr;
9749 bool ret;
9750
9751 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9752
9753 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9754 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9755 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9756 trace_cfg80211_return_bool(false);
9757 return false;
9758 }
9759 ret = __nl80211_unexpected_frame(dev,
9760 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9761 addr, gfp);
9762 trace_cfg80211_return_bool(ret);
9763 return ret;
9764}
9765EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009766
Johannes Berg2e161f72010-08-12 15:38:38 +02009767int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009768 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009769 int freq, int sig_dbm,
9770 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009771{
Johannes Berg71bbc992012-06-15 15:30:18 +02009772 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009773 struct sk_buff *msg;
9774 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009775
9776 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9777 if (!msg)
9778 return -ENOMEM;
9779
Johannes Berg2e161f72010-08-12 15:38:38 +02009780 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009781 if (!hdr) {
9782 nlmsg_free(msg);
9783 return -ENOMEM;
9784 }
9785
David S. Miller9360ffd2012-03-29 04:41:26 -04009786 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009787 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9788 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009789 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9790 (sig_dbm &&
9791 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9792 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9793 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009794
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009795 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009796
Eric W. Biederman15e47302012-09-07 20:12:54 +00009797 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009798
9799 nla_put_failure:
9800 genlmsg_cancel(msg, hdr);
9801 nlmsg_free(msg);
9802 return -ENOBUFS;
9803}
9804
Johannes Berg947add32013-02-22 22:05:20 +01009805void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9806 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009807{
Johannes Berg947add32013-02-22 22:05:20 +01009808 struct wiphy *wiphy = wdev->wiphy;
9809 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009810 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009811 struct sk_buff *msg;
9812 void *hdr;
9813
Johannes Berg947add32013-02-22 22:05:20 +01009814 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9815
Jouni Malinen026331c2010-02-15 12:53:10 +02009816 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9817 if (!msg)
9818 return;
9819
Johannes Berg2e161f72010-08-12 15:38:38 +02009820 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009821 if (!hdr) {
9822 nlmsg_free(msg);
9823 return;
9824 }
9825
David S. Miller9360ffd2012-03-29 04:41:26 -04009826 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009827 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9828 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009829 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9830 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9831 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9832 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009833
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009834 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009835
9836 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9837 return;
9838
9839 nla_put_failure:
9840 genlmsg_cancel(msg, hdr);
9841 nlmsg_free(msg);
9842}
Johannes Berg947add32013-02-22 22:05:20 +01009843EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009844
Johannes Berg947add32013-02-22 22:05:20 +01009845void cfg80211_cqm_rssi_notify(struct net_device *dev,
9846 enum nl80211_cqm_rssi_threshold_event rssi_event,
9847 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009848{
Johannes Berg947add32013-02-22 22:05:20 +01009849 struct wireless_dev *wdev = dev->ieee80211_ptr;
9850 struct wiphy *wiphy = wdev->wiphy;
9851 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009852 struct sk_buff *msg;
9853 struct nlattr *pinfoattr;
9854 void *hdr;
9855
Johannes Berg947add32013-02-22 22:05:20 +01009856 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
9857
Thomas Graf58050fc2012-06-28 03:57:45 +00009858 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009859 if (!msg)
9860 return;
9861
9862 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9863 if (!hdr) {
9864 nlmsg_free(msg);
9865 return;
9866 }
9867
David S. Miller9360ffd2012-03-29 04:41:26 -04009868 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009869 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -04009870 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009871
9872 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9873 if (!pinfoattr)
9874 goto nla_put_failure;
9875
David S. Miller9360ffd2012-03-29 04:41:26 -04009876 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9877 rssi_event))
9878 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009879
9880 nla_nest_end(msg, pinfoattr);
9881
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009882 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009883
9884 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9885 nl80211_mlme_mcgrp.id, gfp);
9886 return;
9887
9888 nla_put_failure:
9889 genlmsg_cancel(msg, hdr);
9890 nlmsg_free(msg);
9891}
Johannes Berg947add32013-02-22 22:05:20 +01009892EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009893
Johannes Berg947add32013-02-22 22:05:20 +01009894static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9895 struct net_device *netdev, const u8 *bssid,
9896 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +02009897{
9898 struct sk_buff *msg;
9899 struct nlattr *rekey_attr;
9900 void *hdr;
9901
Thomas Graf58050fc2012-06-28 03:57:45 +00009902 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009903 if (!msg)
9904 return;
9905
9906 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9907 if (!hdr) {
9908 nlmsg_free(msg);
9909 return;
9910 }
9911
David S. Miller9360ffd2012-03-29 04:41:26 -04009912 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9913 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9914 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9915 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009916
9917 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9918 if (!rekey_attr)
9919 goto nla_put_failure;
9920
David S. Miller9360ffd2012-03-29 04:41:26 -04009921 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9922 NL80211_REPLAY_CTR_LEN, replay_ctr))
9923 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009924
9925 nla_nest_end(msg, rekey_attr);
9926
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009927 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02009928
9929 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9930 nl80211_mlme_mcgrp.id, gfp);
9931 return;
9932
9933 nla_put_failure:
9934 genlmsg_cancel(msg, hdr);
9935 nlmsg_free(msg);
9936}
9937
Johannes Berg947add32013-02-22 22:05:20 +01009938void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
9939 const u8 *replay_ctr, gfp_t gfp)
9940{
9941 struct wireless_dev *wdev = dev->ieee80211_ptr;
9942 struct wiphy *wiphy = wdev->wiphy;
9943 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9944
9945 trace_cfg80211_gtk_rekey_notify(dev, bssid);
9946 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
9947}
9948EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
9949
9950static void
9951nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
9952 struct net_device *netdev, int index,
9953 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009954{
9955 struct sk_buff *msg;
9956 struct nlattr *attr;
9957 void *hdr;
9958
Thomas Graf58050fc2012-06-28 03:57:45 +00009959 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009960 if (!msg)
9961 return;
9962
9963 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
9964 if (!hdr) {
9965 nlmsg_free(msg);
9966 return;
9967 }
9968
David S. Miller9360ffd2012-03-29 04:41:26 -04009969 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9970 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9971 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009972
9973 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
9974 if (!attr)
9975 goto nla_put_failure;
9976
David S. Miller9360ffd2012-03-29 04:41:26 -04009977 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
9978 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
9979 (preauth &&
9980 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
9981 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009982
9983 nla_nest_end(msg, attr);
9984
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009985 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009986
9987 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9988 nl80211_mlme_mcgrp.id, gfp);
9989 return;
9990
9991 nla_put_failure:
9992 genlmsg_cancel(msg, hdr);
9993 nlmsg_free(msg);
9994}
9995
Johannes Berg947add32013-02-22 22:05:20 +01009996void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
9997 const u8 *bssid, bool preauth, gfp_t gfp)
9998{
9999 struct wireless_dev *wdev = dev->ieee80211_ptr;
10000 struct wiphy *wiphy = wdev->wiphy;
10001 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10002
10003 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10004 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10005}
10006EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10007
10008static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10009 struct net_device *netdev,
10010 struct cfg80211_chan_def *chandef,
10011 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010012{
10013 struct sk_buff *msg;
10014 void *hdr;
10015
Thomas Graf58050fc2012-06-28 03:57:45 +000010016 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010017 if (!msg)
10018 return;
10019
10020 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10021 if (!hdr) {
10022 nlmsg_free(msg);
10023 return;
10024 }
10025
Johannes Berg683b6d32012-11-08 21:25:48 +010010026 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10027 goto nla_put_failure;
10028
10029 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010030 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010031
10032 genlmsg_end(msg, hdr);
10033
10034 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10035 nl80211_mlme_mcgrp.id, gfp);
10036 return;
10037
10038 nla_put_failure:
10039 genlmsg_cancel(msg, hdr);
10040 nlmsg_free(msg);
10041}
10042
Johannes Berg947add32013-02-22 22:05:20 +010010043void cfg80211_ch_switch_notify(struct net_device *dev,
10044 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010045{
Johannes Berg947add32013-02-22 22:05:20 +010010046 struct wireless_dev *wdev = dev->ieee80211_ptr;
10047 struct wiphy *wiphy = wdev->wiphy;
10048 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10049
10050 trace_cfg80211_ch_switch_notify(dev, chandef);
10051
10052 wdev_lock(wdev);
10053
10054 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10055 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10056 goto out;
10057
10058 wdev->channel = chandef->chan;
10059 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10060out:
10061 wdev_unlock(wdev);
10062 return;
10063}
10064EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10065
10066void cfg80211_cqm_txe_notify(struct net_device *dev,
10067 const u8 *peer, u32 num_packets,
10068 u32 rate, u32 intvl, gfp_t gfp)
10069{
10070 struct wireless_dev *wdev = dev->ieee80211_ptr;
10071 struct wiphy *wiphy = wdev->wiphy;
10072 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010073 struct sk_buff *msg;
10074 struct nlattr *pinfoattr;
10075 void *hdr;
10076
10077 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10078 if (!msg)
10079 return;
10080
10081 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10082 if (!hdr) {
10083 nlmsg_free(msg);
10084 return;
10085 }
10086
10087 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010088 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010089 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10090 goto nla_put_failure;
10091
10092 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10093 if (!pinfoattr)
10094 goto nla_put_failure;
10095
10096 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10097 goto nla_put_failure;
10098
10099 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10100 goto nla_put_failure;
10101
10102 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10103 goto nla_put_failure;
10104
10105 nla_nest_end(msg, pinfoattr);
10106
10107 genlmsg_end(msg, hdr);
10108
10109 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10110 nl80211_mlme_mcgrp.id, gfp);
10111 return;
10112
10113 nla_put_failure:
10114 genlmsg_cancel(msg, hdr);
10115 nlmsg_free(msg);
10116}
Johannes Berg947add32013-02-22 22:05:20 +010010117EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010118
10119void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010120nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10121 struct cfg80211_chan_def *chandef,
10122 enum nl80211_radar_event event,
10123 struct net_device *netdev, gfp_t gfp)
10124{
10125 struct sk_buff *msg;
10126 void *hdr;
10127
10128 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10129 if (!msg)
10130 return;
10131
10132 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10133 if (!hdr) {
10134 nlmsg_free(msg);
10135 return;
10136 }
10137
10138 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10139 goto nla_put_failure;
10140
10141 /* NOP and radar events don't need a netdev parameter */
10142 if (netdev) {
10143 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10144
10145 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10146 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10147 goto nla_put_failure;
10148 }
10149
10150 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10151 goto nla_put_failure;
10152
10153 if (nl80211_send_chandef(msg, chandef))
10154 goto nla_put_failure;
10155
10156 if (genlmsg_end(msg, hdr) < 0) {
10157 nlmsg_free(msg);
10158 return;
10159 }
10160
10161 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10162 nl80211_mlme_mcgrp.id, gfp);
10163 return;
10164
10165 nla_put_failure:
10166 genlmsg_cancel(msg, hdr);
10167 nlmsg_free(msg);
10168}
10169
Johannes Berg947add32013-02-22 22:05:20 +010010170void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10171 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010172{
Johannes Berg947add32013-02-22 22:05:20 +010010173 struct wireless_dev *wdev = dev->ieee80211_ptr;
10174 struct wiphy *wiphy = wdev->wiphy;
10175 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010176 struct sk_buff *msg;
10177 struct nlattr *pinfoattr;
10178 void *hdr;
10179
Johannes Berg947add32013-02-22 22:05:20 +010010180 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10181
Thomas Graf58050fc2012-06-28 03:57:45 +000010182 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010183 if (!msg)
10184 return;
10185
10186 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10187 if (!hdr) {
10188 nlmsg_free(msg);
10189 return;
10190 }
10191
David S. Miller9360ffd2012-03-29 04:41:26 -040010192 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010193 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010194 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10195 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010196
10197 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10198 if (!pinfoattr)
10199 goto nla_put_failure;
10200
David S. Miller9360ffd2012-03-29 04:41:26 -040010201 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10202 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010203
10204 nla_nest_end(msg, pinfoattr);
10205
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010206 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010207
10208 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10209 nl80211_mlme_mcgrp.id, gfp);
10210 return;
10211
10212 nla_put_failure:
10213 genlmsg_cancel(msg, hdr);
10214 nlmsg_free(msg);
10215}
Johannes Berg947add32013-02-22 22:05:20 +010010216EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010217
Johannes Berg7f6cf312011-11-04 11:18:15 +010010218void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10219 u64 cookie, bool acked, gfp_t gfp)
10220{
10221 struct wireless_dev *wdev = dev->ieee80211_ptr;
10222 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10223 struct sk_buff *msg;
10224 void *hdr;
10225 int err;
10226
Beni Lev4ee3e062012-08-27 12:49:39 +030010227 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10228
Thomas Graf58050fc2012-06-28 03:57:45 +000010229 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010230
Johannes Berg7f6cf312011-11-04 11:18:15 +010010231 if (!msg)
10232 return;
10233
10234 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10235 if (!hdr) {
10236 nlmsg_free(msg);
10237 return;
10238 }
10239
David S. Miller9360ffd2012-03-29 04:41:26 -040010240 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10241 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10242 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10243 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10244 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10245 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010246
10247 err = genlmsg_end(msg, hdr);
10248 if (err < 0) {
10249 nlmsg_free(msg);
10250 return;
10251 }
10252
10253 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10254 nl80211_mlme_mcgrp.id, gfp);
10255 return;
10256
10257 nla_put_failure:
10258 genlmsg_cancel(msg, hdr);
10259 nlmsg_free(msg);
10260}
10261EXPORT_SYMBOL(cfg80211_probe_status);
10262
Johannes Berg5e7602302011-11-04 11:18:17 +010010263void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10264 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010265 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010266{
10267 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10268 struct sk_buff *msg;
10269 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010270 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010271
Beni Lev4ee3e062012-08-27 12:49:39 +030010272 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10273
Ben Greear37c73b52012-10-26 14:49:25 -070010274 spin_lock_bh(&rdev->beacon_registrations_lock);
10275 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10276 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10277 if (!msg) {
10278 spin_unlock_bh(&rdev->beacon_registrations_lock);
10279 return;
10280 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010281
Ben Greear37c73b52012-10-26 14:49:25 -070010282 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10283 if (!hdr)
10284 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010285
Ben Greear37c73b52012-10-26 14:49:25 -070010286 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10287 (freq &&
10288 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10289 (sig_dbm &&
10290 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10291 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10292 goto nla_put_failure;
10293
10294 genlmsg_end(msg, hdr);
10295
10296 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010297 }
Ben Greear37c73b52012-10-26 14:49:25 -070010298 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010299 return;
10300
10301 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010302 spin_unlock_bh(&rdev->beacon_registrations_lock);
10303 if (hdr)
10304 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010010305 nlmsg_free(msg);
10306}
10307EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10308
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010309#ifdef CONFIG_PM
10310void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10311 struct cfg80211_wowlan_wakeup *wakeup,
10312 gfp_t gfp)
10313{
10314 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10315 struct sk_buff *msg;
10316 void *hdr;
10317 int err, size = 200;
10318
10319 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10320
10321 if (wakeup)
10322 size += wakeup->packet_present_len;
10323
10324 msg = nlmsg_new(size, gfp);
10325 if (!msg)
10326 return;
10327
10328 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10329 if (!hdr)
10330 goto free_msg;
10331
10332 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10333 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10334 goto free_msg;
10335
10336 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10337 wdev->netdev->ifindex))
10338 goto free_msg;
10339
10340 if (wakeup) {
10341 struct nlattr *reasons;
10342
10343 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10344
10345 if (wakeup->disconnect &&
10346 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10347 goto free_msg;
10348 if (wakeup->magic_pkt &&
10349 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10350 goto free_msg;
10351 if (wakeup->gtk_rekey_failure &&
10352 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10353 goto free_msg;
10354 if (wakeup->eap_identity_req &&
10355 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10356 goto free_msg;
10357 if (wakeup->four_way_handshake &&
10358 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10359 goto free_msg;
10360 if (wakeup->rfkill_release &&
10361 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10362 goto free_msg;
10363
10364 if (wakeup->pattern_idx >= 0 &&
10365 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10366 wakeup->pattern_idx))
10367 goto free_msg;
10368
Johannes Berg2a0e0472013-01-23 22:57:40 +010010369 if (wakeup->tcp_match)
10370 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10371
10372 if (wakeup->tcp_connlost)
10373 nla_put_flag(msg,
10374 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10375
10376 if (wakeup->tcp_nomoretokens)
10377 nla_put_flag(msg,
10378 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10379
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010380 if (wakeup->packet) {
10381 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10382 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10383
10384 if (!wakeup->packet_80211) {
10385 pkt_attr =
10386 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10387 len_attr =
10388 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10389 }
10390
10391 if (wakeup->packet_len &&
10392 nla_put_u32(msg, len_attr, wakeup->packet_len))
10393 goto free_msg;
10394
10395 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10396 wakeup->packet))
10397 goto free_msg;
10398 }
10399
10400 nla_nest_end(msg, reasons);
10401 }
10402
10403 err = genlmsg_end(msg, hdr);
10404 if (err < 0)
10405 goto free_msg;
10406
10407 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10408 nl80211_mlme_mcgrp.id, gfp);
10409 return;
10410
10411 free_msg:
10412 nlmsg_free(msg);
10413}
10414EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10415#endif
10416
Jouni Malinen3475b092012-11-16 22:49:57 +020010417void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10418 enum nl80211_tdls_operation oper,
10419 u16 reason_code, gfp_t gfp)
10420{
10421 struct wireless_dev *wdev = dev->ieee80211_ptr;
10422 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10423 struct sk_buff *msg;
10424 void *hdr;
10425 int err;
10426
10427 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10428 reason_code);
10429
10430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10431 if (!msg)
10432 return;
10433
10434 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10435 if (!hdr) {
10436 nlmsg_free(msg);
10437 return;
10438 }
10439
10440 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10441 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10442 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10443 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10444 (reason_code > 0 &&
10445 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10446 goto nla_put_failure;
10447
10448 err = genlmsg_end(msg, hdr);
10449 if (err < 0) {
10450 nlmsg_free(msg);
10451 return;
10452 }
10453
10454 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10455 nl80211_mlme_mcgrp.id, gfp);
10456 return;
10457
10458 nla_put_failure:
10459 genlmsg_cancel(msg, hdr);
10460 nlmsg_free(msg);
10461}
10462EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10463
Jouni Malinen026331c2010-02-15 12:53:10 +020010464static int nl80211_netlink_notify(struct notifier_block * nb,
10465 unsigned long state,
10466 void *_notify)
10467{
10468 struct netlink_notify *notify = _notify;
10469 struct cfg80211_registered_device *rdev;
10470 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010471 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010472
10473 if (state != NETLINK_URELEASE)
10474 return NOTIFY_DONE;
10475
10476 rcu_read_lock();
10477
Johannes Berg5e7602302011-11-04 11:18:17 +010010478 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010479 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010480 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010481
10482 spin_lock_bh(&rdev->beacon_registrations_lock);
10483 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10484 list) {
10485 if (reg->nlportid == notify->portid) {
10486 list_del(&reg->list);
10487 kfree(reg);
10488 break;
10489 }
10490 }
10491 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010492 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010493
10494 rcu_read_unlock();
10495
10496 return NOTIFY_DONE;
10497}
10498
10499static struct notifier_block nl80211_netlink_notifier = {
10500 .notifier_call = nl80211_netlink_notify,
10501};
10502
Johannes Berg55682962007-09-20 13:09:35 -040010503/* initialisation/exit functions */
10504
10505int nl80211_init(void)
10506{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010507 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010508
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010509 err = genl_register_family_with_ops(&nl80211_fam,
10510 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010511 if (err)
10512 return err;
10513
Johannes Berg55682962007-09-20 13:09:35 -040010514 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10515 if (err)
10516 goto err_out;
10517
Johannes Berg2a519312009-02-10 21:25:55 +010010518 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10519 if (err)
10520 goto err_out;
10521
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010522 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10523 if (err)
10524 goto err_out;
10525
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010526 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10527 if (err)
10528 goto err_out;
10529
Johannes Bergaff89a92009-07-01 21:26:51 +020010530#ifdef CONFIG_NL80211_TESTMODE
10531 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10532 if (err)
10533 goto err_out;
10534#endif
10535
Jouni Malinen026331c2010-02-15 12:53:10 +020010536 err = netlink_register_notifier(&nl80211_netlink_notifier);
10537 if (err)
10538 goto err_out;
10539
Johannes Berg55682962007-09-20 13:09:35 -040010540 return 0;
10541 err_out:
10542 genl_unregister_family(&nl80211_fam);
10543 return err;
10544}
10545
10546void nl80211_exit(void)
10547{
Jouni Malinen026331c2010-02-15 12:53:10 +020010548 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010549 genl_unregister_family(&nl80211_fam);
10550}