blob: d29a461b4981befaea8b350be7281c19583b0711 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
40 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = "nl80211", /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
44 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg89a54e42012-06-15 14:33:17 +020062 assert_cfg80211_lock();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
83 mutex_lock(&rdev->devlist_mtx);
84 list_for_each_entry(wdev, &rdev->wdev_list, list) {
85 if (have_ifidx && wdev->netdev &&
86 wdev->netdev->ifindex == ifidx) {
87 result = wdev;
88 break;
89 }
90 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
91 result = wdev;
92 break;
93 }
94 }
95 mutex_unlock(&rdev->devlist_mtx);
96
97 if (result)
98 break;
99 }
100
101 if (result)
102 return result;
103 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400104}
105
Johannes Berga9455402012-06-15 13:32:49 +0200106static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200107__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200108{
Johannes Berg7fee4772012-06-15 14:09:58 +0200109 struct cfg80211_registered_device *rdev = NULL, *tmp;
110 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200111
112 assert_cfg80211_lock();
113
Johannes Berg878d9ec2012-06-15 14:18:32 +0200114 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200115 !attrs[NL80211_ATTR_IFINDEX] &&
116 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200117 return ERR_PTR(-EINVAL);
118
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200120 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200121 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg89a54e42012-06-15 14:33:17 +0200123 if (attrs[NL80211_ATTR_WDEV]) {
124 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
125 struct wireless_dev *wdev;
126 bool found = false;
127
128 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
129 if (tmp) {
130 /* make sure wdev exists */
131 mutex_lock(&tmp->devlist_mtx);
132 list_for_each_entry(wdev, &tmp->wdev_list, list) {
133 if (wdev->identifier != (u32)wdev_id)
134 continue;
135 found = true;
136 break;
137 }
138 mutex_unlock(&tmp->devlist_mtx);
139
140 if (!found)
141 tmp = NULL;
142
143 if (rdev && tmp != rdev)
144 return ERR_PTR(-EINVAL);
145 rdev = tmp;
146 }
147 }
148
Johannes Berg878d9ec2012-06-15 14:18:32 +0200149 if (attrs[NL80211_ATTR_IFINDEX]) {
150 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200151 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200152 if (netdev) {
153 if (netdev->ieee80211_ptr)
154 tmp = wiphy_to_dev(
155 netdev->ieee80211_ptr->wiphy);
156 else
157 tmp = NULL;
158
159 dev_put(netdev);
160
161 /* not wireless device -- return error */
162 if (!tmp)
163 return ERR_PTR(-EINVAL);
164
165 /* mismatch -- return error */
166 if (rdev && tmp != rdev)
167 return ERR_PTR(-EINVAL);
168
169 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200170 }
Johannes Berga9455402012-06-15 13:32:49 +0200171 }
172
Johannes Berg4f7eff12012-06-15 14:14:22 +0200173 if (!rdev)
174 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200175
Johannes Berg4f7eff12012-06-15 14:14:22 +0200176 if (netns != wiphy_net(&rdev->wiphy))
177 return ERR_PTR(-ENODEV);
178
179 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200180}
181
182/*
183 * This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 * If successful, it returns non-NULL and also locks
186 * the driver's mutex!
187 *
188 * This means that you need to call cfg80211_unlock_rdev()
189 * before being allowed to acquire &cfg80211_mutex!
190 *
191 * This is necessary because we need to lock the global
192 * mutex to get an item off the list safely, and then
193 * we lock the rdev mutex so it doesn't go away under us.
194 *
195 * We don't want to keep cfg80211_mutex locked
196 * for all the time in order to allow requests on
197 * other interfaces to go through at the same time.
198 *
199 * The result of this can be a PTR_ERR and hence must
200 * be checked with IS_ERR() for errors.
201 */
202static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200203cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200204{
205 struct cfg80211_registered_device *rdev;
206
207 mutex_lock(&cfg80211_mutex);
Johannes Berg878d9ec2012-06-15 14:18:32 +0200208 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209
210 /* if it is not an error we grab the lock on
211 * it to assure it won't be going away while
212 * we operate on it */
213 if (!IS_ERR(rdev))
214 mutex_lock(&rdev->mtx);
215
216 mutex_unlock(&cfg80211_mutex);
217
218 return rdev;
219}
220
Johannes Berg55682962007-09-20 13:09:35 -0400221/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000222static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400223 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
224 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700225 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200226 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100227
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200228 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530229 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100230 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
231 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
232 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
233
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200234 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
235 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
236 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
237 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100238 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400239
240 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
241 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
242 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100243
Eliad Pellere007b852011-11-24 18:13:56 +0200244 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
245 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100246
Johannes Bergb9454e82009-07-08 13:29:08 +0200247 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100248 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
249 .len = WLAN_MAX_KEY_LEN },
250 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
251 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
252 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200253 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200254 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100255
256 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
257 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
258 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
259 .len = IEEE80211_MAX_DATA_LEN },
260 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100262 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
263 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
264 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
265 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
266 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100267 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100268 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200269 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100270 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800271 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100272 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300273
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700274 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
275 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
276
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300277 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
278 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
279 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200280 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
281 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100282 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300283
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800284 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700285 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700286
Johannes Berg6c739412011-11-03 09:27:01 +0100287 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200288
289 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
290 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
291 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100292 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
293 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200294
295 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
296 .len = IEEE80211_MAX_SSID_LEN },
297 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
298 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200299 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300300 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300301 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300302 [NL80211_ATTR_STA_FLAGS2] = {
303 .len = sizeof(struct nl80211_sta_flag_update),
304 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300305 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200308 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
309 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
310 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200311 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100312 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100313 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
314 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100315 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
316 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200317 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200318 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
319 .len = IEEE80211_MAX_DATA_LEN },
320 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200321 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200322 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300323 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200324 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200327 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900328 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
329 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100330 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100331 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100332 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200333 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700334 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300335 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200336 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200337 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300338 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300339 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
340 .len = IEEE80211_MAX_DATA_LEN },
341 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530343 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300344 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530345 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300346 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
348 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
349 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100351 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200352 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
353 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700354 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800355 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
356 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
357 .len = NL80211_HT_CAPABILITY_LEN
358 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100359 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530360 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530361 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200362 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700363 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300364 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000365 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700366 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100367 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
368 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530369 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
370 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Johannes Berg55682962007-09-20 13:09:35 -0400371};
372
Johannes Berge31b8212010-10-05 19:39:30 +0200373/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000374static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200375 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200376 [NL80211_KEY_IDX] = { .type = NLA_U8 },
377 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200378 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200379 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
380 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200381 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100382 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
383};
384
385/* policy for the key default flags */
386static const struct nla_policy
387nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
388 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
389 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200390};
391
Johannes Bergff1b6e62011-05-04 15:37:28 +0200392/* policy for WoWLAN attributes */
393static const struct nla_policy
394nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
395 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
396 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
397 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
398 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb132011-07-13 10:48:55 +0200399 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
400 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
401 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
402 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100403 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
404};
405
406static const struct nla_policy
407nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
408 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
409 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
410 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
411 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
412 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
413 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
414 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
415 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
416 },
417 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
418 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
419 },
420 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
421 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
422 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200423};
424
Johannes Berge5497d72011-07-05 16:35:40 +0200425/* policy for GTK rekey offload attributes */
426static const struct nla_policy
427nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
428 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
429 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
430 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
431};
432
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300433static const struct nla_policy
434nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200435 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300436 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700437 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300438};
439
Holger Schuriga0438972009-11-11 11:30:02 +0100440/* ifidx get helper */
441static int nl80211_get_ifidx(struct netlink_callback *cb)
442{
443 int res;
444
445 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
446 nl80211_fam.attrbuf, nl80211_fam.maxattr,
447 nl80211_policy);
448 if (res)
449 return res;
450
451 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
452 return -EINVAL;
453
454 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
455 if (!res)
456 return -EINVAL;
457 return res;
458}
459
Johannes Berg67748892010-10-04 21:14:06 +0200460static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
461 struct netlink_callback *cb,
462 struct cfg80211_registered_device **rdev,
463 struct net_device **dev)
464{
465 int ifidx = cb->args[0];
466 int err;
467
468 if (!ifidx)
469 ifidx = nl80211_get_ifidx(cb);
470 if (ifidx < 0)
471 return ifidx;
472
473 cb->args[0] = ifidx;
474
475 rtnl_lock();
476
477 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
478 if (!*dev) {
479 err = -ENODEV;
480 goto out_rtnl;
481 }
482
483 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100484 if (IS_ERR(*rdev)) {
485 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200486 goto out_rtnl;
487 }
488
489 return 0;
490 out_rtnl:
491 rtnl_unlock();
492 return err;
493}
494
495static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
496{
497 cfg80211_unlock_rdev(rdev);
498 rtnl_unlock();
499}
500
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100501/* IE validation */
502static bool is_valid_ie_attr(const struct nlattr *attr)
503{
504 const u8 *pos;
505 int len;
506
507 if (!attr)
508 return true;
509
510 pos = nla_data(attr);
511 len = nla_len(attr);
512
513 while (len) {
514 u8 elemlen;
515
516 if (len < 2)
517 return false;
518 len -= 2;
519
520 elemlen = pos[1];
521 if (elemlen > len)
522 return false;
523
524 len -= elemlen;
525 pos += 2 + elemlen;
526 }
527
528 return true;
529}
530
Johannes Berg55682962007-09-20 13:09:35 -0400531/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000532static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400533 int flags, u8 cmd)
534{
535 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000536 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400537}
538
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400539static int nl80211_msg_put_channel(struct sk_buff *msg,
540 struct ieee80211_channel *chan)
541{
David S. Miller9360ffd2012-03-29 04:41:26 -0400542 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
543 chan->center_freq))
544 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400545
David S. Miller9360ffd2012-03-29 04:41:26 -0400546 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
547 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
548 goto nla_put_failure;
549 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
550 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
551 goto nla_put_failure;
552 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
553 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
554 goto nla_put_failure;
555 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
556 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
557 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400558
David S. Miller9360ffd2012-03-29 04:41:26 -0400559 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
560 DBM_TO_MBM(chan->max_power)))
561 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400562
563 return 0;
564
565 nla_put_failure:
566 return -ENOBUFS;
567}
568
Johannes Berg55682962007-09-20 13:09:35 -0400569/* netlink command implementations */
570
Johannes Bergb9454e82009-07-08 13:29:08 +0200571struct key_parse {
572 struct key_params p;
573 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200574 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200575 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100576 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200577};
578
579static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
580{
581 struct nlattr *tb[NL80211_KEY_MAX + 1];
582 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
583 nl80211_key_policy);
584 if (err)
585 return err;
586
587 k->def = !!tb[NL80211_KEY_DEFAULT];
588 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
589
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100590 if (k->def) {
591 k->def_uni = true;
592 k->def_multi = true;
593 }
594 if (k->defmgmt)
595 k->def_multi = true;
596
Johannes Bergb9454e82009-07-08 13:29:08 +0200597 if (tb[NL80211_KEY_IDX])
598 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
599
600 if (tb[NL80211_KEY_DATA]) {
601 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
602 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
603 }
604
605 if (tb[NL80211_KEY_SEQ]) {
606 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
607 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
608 }
609
610 if (tb[NL80211_KEY_CIPHER])
611 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
612
Johannes Berge31b8212010-10-05 19:39:30 +0200613 if (tb[NL80211_KEY_TYPE]) {
614 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
615 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
616 return -EINVAL;
617 }
618
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100619 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
620 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100621 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
622 tb[NL80211_KEY_DEFAULT_TYPES],
623 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100624 if (err)
625 return err;
626
627 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
628 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
629 }
630
Johannes Bergb9454e82009-07-08 13:29:08 +0200631 return 0;
632}
633
634static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
635{
636 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
637 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
638 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
639 }
640
641 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
642 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
643 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
644 }
645
646 if (info->attrs[NL80211_ATTR_KEY_IDX])
647 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
648
649 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
650 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
651
652 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
653 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
654
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100655 if (k->def) {
656 k->def_uni = true;
657 k->def_multi = true;
658 }
659 if (k->defmgmt)
660 k->def_multi = true;
661
Johannes Berge31b8212010-10-05 19:39:30 +0200662 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
663 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
664 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
665 return -EINVAL;
666 }
667
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100668 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
669 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
670 int err = nla_parse_nested(
671 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
672 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
673 nl80211_key_default_policy);
674 if (err)
675 return err;
676
677 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
678 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
679 }
680
Johannes Bergb9454e82009-07-08 13:29:08 +0200681 return 0;
682}
683
684static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
685{
686 int err;
687
688 memset(k, 0, sizeof(*k));
689 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200690 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200691
692 if (info->attrs[NL80211_ATTR_KEY])
693 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
694 else
695 err = nl80211_parse_key_old(info, k);
696
697 if (err)
698 return err;
699
700 if (k->def && k->defmgmt)
701 return -EINVAL;
702
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100703 if (k->defmgmt) {
704 if (k->def_uni || !k->def_multi)
705 return -EINVAL;
706 }
707
Johannes Bergb9454e82009-07-08 13:29:08 +0200708 if (k->idx != -1) {
709 if (k->defmgmt) {
710 if (k->idx < 4 || k->idx > 5)
711 return -EINVAL;
712 } else if (k->def) {
713 if (k->idx < 0 || k->idx > 3)
714 return -EINVAL;
715 } else {
716 if (k->idx < 0 || k->idx > 5)
717 return -EINVAL;
718 }
719 }
720
721 return 0;
722}
723
Johannes Bergfffd0932009-07-08 14:22:54 +0200724static struct cfg80211_cached_keys *
725nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530726 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200727{
728 struct key_parse parse;
729 struct nlattr *key;
730 struct cfg80211_cached_keys *result;
731 int rem, err, def = 0;
732
733 result = kzalloc(sizeof(*result), GFP_KERNEL);
734 if (!result)
735 return ERR_PTR(-ENOMEM);
736
737 result->def = -1;
738 result->defmgmt = -1;
739
740 nla_for_each_nested(key, keys, rem) {
741 memset(&parse, 0, sizeof(parse));
742 parse.idx = -1;
743
744 err = nl80211_parse_key_new(key, &parse);
745 if (err)
746 goto error;
747 err = -EINVAL;
748 if (!parse.p.key)
749 goto error;
750 if (parse.idx < 0 || parse.idx > 4)
751 goto error;
752 if (parse.def) {
753 if (def)
754 goto error;
755 def = 1;
756 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100757 if (!parse.def_uni || !parse.def_multi)
758 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200759 } else if (parse.defmgmt)
760 goto error;
761 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200762 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200763 if (err)
764 goto error;
765 result->params[parse.idx].cipher = parse.p.cipher;
766 result->params[parse.idx].key_len = parse.p.key_len;
767 result->params[parse.idx].key = result->data[parse.idx];
768 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530769
770 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
771 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
772 if (no_ht)
773 *no_ht = true;
774 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200775 }
776
777 return result;
778 error:
779 kfree(result);
780 return ERR_PTR(err);
781}
782
783static int nl80211_key_allowed(struct wireless_dev *wdev)
784{
785 ASSERT_WDEV_LOCK(wdev);
786
Johannes Bergfffd0932009-07-08 14:22:54 +0200787 switch (wdev->iftype) {
788 case NL80211_IFTYPE_AP:
789 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200790 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700791 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200792 break;
793 case NL80211_IFTYPE_ADHOC:
794 if (!wdev->current_bss)
795 return -ENOLINK;
796 break;
797 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200798 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200799 if (wdev->sme_state != CFG80211_SME_CONNECTED)
800 return -ENOLINK;
801 break;
802 default:
803 return -EINVAL;
804 }
805
806 return 0;
807}
808
Johannes Berg7527a782011-05-13 10:58:57 +0200809static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
810{
811 struct nlattr *nl_modes = nla_nest_start(msg, attr);
812 int i;
813
814 if (!nl_modes)
815 goto nla_put_failure;
816
817 i = 0;
818 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400819 if ((ifmodes & 1) && nla_put_flag(msg, i))
820 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200821 ifmodes >>= 1;
822 i++;
823 }
824
825 nla_nest_end(msg, nl_modes);
826 return 0;
827
828nla_put_failure:
829 return -ENOBUFS;
830}
831
832static int nl80211_put_iface_combinations(struct wiphy *wiphy,
833 struct sk_buff *msg)
834{
835 struct nlattr *nl_combis;
836 int i, j;
837
838 nl_combis = nla_nest_start(msg,
839 NL80211_ATTR_INTERFACE_COMBINATIONS);
840 if (!nl_combis)
841 goto nla_put_failure;
842
843 for (i = 0; i < wiphy->n_iface_combinations; i++) {
844 const struct ieee80211_iface_combination *c;
845 struct nlattr *nl_combi, *nl_limits;
846
847 c = &wiphy->iface_combinations[i];
848
849 nl_combi = nla_nest_start(msg, i + 1);
850 if (!nl_combi)
851 goto nla_put_failure;
852
853 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
854 if (!nl_limits)
855 goto nla_put_failure;
856
857 for (j = 0; j < c->n_limits; j++) {
858 struct nlattr *nl_limit;
859
860 nl_limit = nla_nest_start(msg, j + 1);
861 if (!nl_limit)
862 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400863 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
864 c->limits[j].max))
865 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200866 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
867 c->limits[j].types))
868 goto nla_put_failure;
869 nla_nest_end(msg, nl_limit);
870 }
871
872 nla_nest_end(msg, nl_limits);
873
David S. Miller9360ffd2012-03-29 04:41:26 -0400874 if (c->beacon_int_infra_match &&
875 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
876 goto nla_put_failure;
877 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
878 c->num_different_channels) ||
879 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
880 c->max_interfaces))
881 goto nla_put_failure;
Simon Wunderlich11c4a072013-01-08 14:04:07 +0100882 if (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
883 c->radar_detect_widths))
884 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200885
886 nla_nest_end(msg, nl_combi);
887 }
888
889 nla_nest_end(msg, nl_combis);
890
891 return 0;
892nla_put_failure:
893 return -ENOBUFS;
894}
895
Johannes Berg2a0e0472013-01-23 22:57:40 +0100896#ifdef CONFIG_PM
897static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
898 struct sk_buff *msg)
899{
900 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
901 struct nlattr *nl_tcp;
902
903 if (!tcp)
904 return 0;
905
906 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
907 if (!nl_tcp)
908 return -ENOBUFS;
909
910 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
911 tcp->data_payload_max))
912 return -ENOBUFS;
913
914 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
915 tcp->data_payload_max))
916 return -ENOBUFS;
917
918 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
919 return -ENOBUFS;
920
921 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
922 sizeof(*tcp->tok), tcp->tok))
923 return -ENOBUFS;
924
925 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
926 tcp->data_interval_max))
927 return -ENOBUFS;
928
929 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
930 tcp->wake_payload_max))
931 return -ENOBUFS;
932
933 nla_nest_end(msg, nl_tcp);
934 return 0;
935}
936#endif
937
Eric W. Biederman15e47302012-09-07 20:12:54 +0000938static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Berg55682962007-09-20 13:09:35 -0400939 struct cfg80211_registered_device *dev)
940{
941 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100942 struct nlattr *nl_bands, *nl_band;
943 struct nlattr *nl_freqs, *nl_freq;
944 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100945 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100946 enum ieee80211_band band;
947 struct ieee80211_channel *chan;
948 struct ieee80211_rate *rate;
949 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200950 const struct ieee80211_txrx_stypes *mgmt_stypes =
951 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400952
Eric W. Biederman15e47302012-09-07 20:12:54 +0000953 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -0400954 if (!hdr)
955 return -1;
956
David S. Miller9360ffd2012-03-29 04:41:26 -0400957 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
958 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
959 nla_put_u32(msg, NL80211_ATTR_GENERATION,
960 cfg80211_rdev_list_generation) ||
961 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
962 dev->wiphy.retry_short) ||
963 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
964 dev->wiphy.retry_long) ||
965 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
966 dev->wiphy.frag_threshold) ||
967 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
968 dev->wiphy.rts_threshold) ||
969 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
970 dev->wiphy.coverage_class) ||
971 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
972 dev->wiphy.max_scan_ssids) ||
973 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
974 dev->wiphy.max_sched_scan_ssids) ||
975 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
976 dev->wiphy.max_scan_ie_len) ||
977 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
978 dev->wiphy.max_sched_scan_ie_len) ||
979 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
980 dev->wiphy.max_match_sets))
981 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200982
David S. Miller9360ffd2012-03-29 04:41:26 -0400983 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
984 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
985 goto nla_put_failure;
986 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
987 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
988 goto nla_put_failure;
989 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
990 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
991 goto nla_put_failure;
992 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
993 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
994 goto nla_put_failure;
995 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
996 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
997 goto nla_put_failure;
998 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
999 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
1000 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001001
David S. Miller9360ffd2012-03-29 04:41:26 -04001002 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1003 sizeof(u32) * dev->wiphy.n_cipher_suites,
1004 dev->wiphy.cipher_suites))
1005 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001006
David S. Miller9360ffd2012-03-29 04:41:26 -04001007 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1008 dev->wiphy.max_num_pmkids))
1009 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +05301010
David S. Miller9360ffd2012-03-29 04:41:26 -04001011 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1012 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1013 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +02001014
David S. Miller9360ffd2012-03-29 04:41:26 -04001015 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1016 dev->wiphy.available_antennas_tx) ||
1017 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1018 dev->wiphy.available_antennas_rx))
1019 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001020
David S. Miller9360ffd2012-03-29 04:41:26 -04001021 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1022 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1023 dev->wiphy.probe_resp_offload))
1024 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +02001025
Bruno Randolf7f531e02010-12-16 11:30:22 +09001026 if ((dev->wiphy.available_antennas_tx ||
1027 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001028 u32 tx_ant = 0, rx_ant = 0;
1029 int res;
Hila Gonene35e4d22012-06-27 17:19:42 +03001030 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001031 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001032 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
1033 tx_ant) ||
1034 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
1035 rx_ant))
1036 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001037 }
1038 }
1039
Johannes Berg7527a782011-05-13 10:58:57 +02001040 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1041 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07001042 goto nla_put_failure;
1043
Johannes Bergee688b002008-01-24 19:38:39 +01001044 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1045 if (!nl_bands)
1046 goto nla_put_failure;
1047
1048 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1049 if (!dev->wiphy.bands[band])
1050 continue;
1051
1052 nl_band = nla_nest_start(msg, band);
1053 if (!nl_band)
1054 goto nla_put_failure;
1055
Johannes Bergd51626d2008-10-09 12:20:13 +02001056 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -04001057 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
1058 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1059 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
1060 &dev->wiphy.bands[band]->ht_cap.mcs) ||
1061 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1062 dev->wiphy.bands[band]->ht_cap.cap) ||
1063 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1064 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
1065 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1066 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
1067 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001068
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001069 /* add VHT info */
1070 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
1071 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1072 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
1073 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
1074 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1075 dev->wiphy.bands[band]->vht_cap.cap)))
1076 goto nla_put_failure;
1077
Johannes Bergee688b002008-01-24 19:38:39 +01001078 /* add frequencies */
1079 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
1080 if (!nl_freqs)
1081 goto nla_put_failure;
1082
1083 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
1084 nl_freq = nla_nest_start(msg, i);
1085 if (!nl_freq)
1086 goto nla_put_failure;
1087
1088 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +01001089
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001090 if (nl80211_msg_put_channel(msg, chan))
1091 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001092
Johannes Bergee688b002008-01-24 19:38:39 +01001093 nla_nest_end(msg, nl_freq);
1094 }
1095
1096 nla_nest_end(msg, nl_freqs);
1097
1098 /* add bitrates */
1099 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1100 if (!nl_rates)
1101 goto nla_put_failure;
1102
1103 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
1104 nl_rate = nla_nest_start(msg, i);
1105 if (!nl_rate)
1106 goto nla_put_failure;
1107
1108 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -04001109 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1110 rate->bitrate))
1111 goto nla_put_failure;
1112 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1113 nla_put_flag(msg,
1114 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1115 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001116
1117 nla_nest_end(msg, nl_rate);
1118 }
1119
1120 nla_nest_end(msg, nl_rates);
1121
1122 nla_nest_end(msg, nl_band);
1123 }
1124 nla_nest_end(msg, nl_bands);
1125
Johannes Berg8fdc6212009-03-14 09:34:01 +01001126 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1127 if (!nl_cmds)
1128 goto nla_put_failure;
1129
1130 i = 0;
1131#define CMD(op, n) \
1132 do { \
1133 if (dev->ops->op) { \
1134 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -04001135 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1136 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +01001137 } \
1138 } while (0)
1139
1140 CMD(add_virtual_intf, NEW_INTERFACE);
1141 CMD(change_virtual_intf, SET_INTERFACE);
1142 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +01001143 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001144 CMD(add_station, NEW_STATION);
1145 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001146 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001147 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001148 CMD(auth, AUTHENTICATE);
1149 CMD(assoc, ASSOCIATE);
1150 CMD(deauth, DEAUTHENTICATE);
1151 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +02001152 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +01001153 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001154 CMD(set_pmksa, SET_PMKSA);
1155 CMD(del_pmksa, DEL_PMKSA);
1156 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001157 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1158 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001159 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001160 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001161 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001162 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001163 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001164 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1165 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001166 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001167 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001168 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001169 i++;
1170 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1171 goto nla_put_failure;
1172 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001173 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001174 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1175 CMD(tdls_mgmt, TDLS_MGMT);
1176 CMD(tdls_oper, TDLS_OPER);
1177 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001178 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1179 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001180 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001181 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +01001182 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1183 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001184 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1185 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01001186 }
Johannes Berg98104fde2012-06-16 00:19:54 +02001187 CMD(start_p2p_device, START_P2P_DEVICE);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01001188 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001189
Kalle Valo4745fc02011-11-17 19:06:10 +02001190#ifdef CONFIG_NL80211_TESTMODE
1191 CMD(testmode_cmd, TESTMODE);
1192#endif
1193
Johannes Berg8fdc6212009-03-14 09:34:01 +01001194#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001195
Johannes Berg6829c872009-07-02 09:13:27 +02001196 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001197 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001198 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1199 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001200 }
1201
Johannes Berg6829c872009-07-02 09:13:27 +02001202 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001203 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001204 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1205 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001206 }
1207
Johannes Berg8fdc6212009-03-14 09:34:01 +01001208 nla_nest_end(msg, nl_cmds);
1209
Johannes Berg7c4ef712011-11-18 15:33:48 +01001210 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001211 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1212 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1213 dev->wiphy.max_remain_on_channel_duration))
1214 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001215
David S. Miller9360ffd2012-03-29 04:41:26 -04001216 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1217 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1218 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001219
Johannes Berg2e161f72010-08-12 15:38:38 +02001220 if (mgmt_stypes) {
1221 u16 stypes;
1222 struct nlattr *nl_ftypes, *nl_ifs;
1223 enum nl80211_iftype ift;
1224
1225 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1226 if (!nl_ifs)
1227 goto nla_put_failure;
1228
1229 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1230 nl_ftypes = nla_nest_start(msg, ift);
1231 if (!nl_ftypes)
1232 goto nla_put_failure;
1233 i = 0;
1234 stypes = mgmt_stypes[ift].tx;
1235 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001236 if ((stypes & 1) &&
1237 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1238 (i << 4) | IEEE80211_FTYPE_MGMT))
1239 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001240 stypes >>= 1;
1241 i++;
1242 }
1243 nla_nest_end(msg, nl_ftypes);
1244 }
1245
Johannes Berg74b70a42010-08-24 12:15:53 +02001246 nla_nest_end(msg, nl_ifs);
1247
Johannes Berg2e161f72010-08-12 15:38:38 +02001248 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1249 if (!nl_ifs)
1250 goto nla_put_failure;
1251
1252 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1253 nl_ftypes = nla_nest_start(msg, ift);
1254 if (!nl_ftypes)
1255 goto nla_put_failure;
1256 i = 0;
1257 stypes = mgmt_stypes[ift].rx;
1258 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001259 if ((stypes & 1) &&
1260 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1261 (i << 4) | IEEE80211_FTYPE_MGMT))
1262 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001263 stypes >>= 1;
1264 i++;
1265 }
1266 nla_nest_end(msg, nl_ftypes);
1267 }
1268 nla_nest_end(msg, nl_ifs);
1269 }
1270
Johannes Bergdfb89c52012-06-27 09:23:48 +02001271#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001272 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1273 struct nlattr *nl_wowlan;
1274
1275 nl_wowlan = nla_nest_start(msg,
1276 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1277 if (!nl_wowlan)
1278 goto nla_put_failure;
1279
David S. Miller9360ffd2012-03-29 04:41:26 -04001280 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1281 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1282 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1283 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1284 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1285 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1286 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1287 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1288 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1289 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1290 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1291 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1292 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1293 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1294 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1295 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1296 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001297 if (dev->wiphy.wowlan.n_patterns) {
1298 struct nl80211_wowlan_pattern_support pat = {
1299 .max_patterns = dev->wiphy.wowlan.n_patterns,
1300 .min_pattern_len =
1301 dev->wiphy.wowlan.pattern_min_len,
1302 .max_pattern_len =
1303 dev->wiphy.wowlan.pattern_max_len,
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08001304 .max_pkt_offset =
1305 dev->wiphy.wowlan.max_pkt_offset,
Johannes Bergff1b6e62011-05-04 15:37:28 +02001306 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001307 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1308 sizeof(pat), &pat))
1309 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001310 }
1311
Johannes Berg2a0e0472013-01-23 22:57:40 +01001312 if (nl80211_send_wowlan_tcp_caps(dev, msg))
1313 goto nla_put_failure;
1314
Johannes Bergff1b6e62011-05-04 15:37:28 +02001315 nla_nest_end(msg, nl_wowlan);
1316 }
Johannes Bergdfb89c52012-06-27 09:23:48 +02001317#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02001318
Johannes Berg7527a782011-05-13 10:58:57 +02001319 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1320 dev->wiphy.software_iftypes))
1321 goto nla_put_failure;
1322
1323 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1324 goto nla_put_failure;
1325
David S. Miller9360ffd2012-03-29 04:41:26 -04001326 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1327 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1328 dev->wiphy.ap_sme_capa))
1329 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001330
David S. Miller9360ffd2012-03-29 04:41:26 -04001331 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1332 dev->wiphy.features))
1333 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001334
David S. Miller9360ffd2012-03-29 04:41:26 -04001335 if (dev->wiphy.ht_capa_mod_mask &&
1336 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1337 sizeof(*dev->wiphy.ht_capa_mod_mask),
1338 dev->wiphy.ht_capa_mod_mask))
1339 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001340
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05301341 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1342 dev->wiphy.max_acl_mac_addrs &&
1343 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1344 dev->wiphy.max_acl_mac_addrs))
1345 goto nla_put_failure;
1346
Johannes Berg55682962007-09-20 13:09:35 -04001347 return genlmsg_end(msg, hdr);
1348
1349 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001350 genlmsg_cancel(msg, hdr);
1351 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001352}
1353
1354static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1355{
1356 int idx = 0;
1357 int start = cb->args[0];
1358 struct cfg80211_registered_device *dev;
1359
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001360 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001361 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001362 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1363 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001364 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001365 continue;
Eric W. Biederman15e47302012-09-07 20:12:54 +00001366 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04001367 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001368 dev) < 0) {
1369 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001370 break;
Julius Volzb4637272008-07-08 14:02:19 +02001371 }
Johannes Berg55682962007-09-20 13:09:35 -04001372 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001373 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001374
1375 cb->args[0] = idx;
1376
1377 return skb->len;
1378}
1379
1380static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1381{
1382 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001383 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001384
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001385 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001386 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001387 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001388
Eric W. Biederman15e47302012-09-07 20:12:54 +00001389 if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001390 nlmsg_free(msg);
1391 return -ENOBUFS;
1392 }
Johannes Berg55682962007-09-20 13:09:35 -04001393
Johannes Berg134e6372009-07-10 09:51:34 +00001394 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001395}
1396
Jouni Malinen31888482008-10-30 16:59:24 +02001397static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1398 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1399 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1400 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1401 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1402 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1403};
1404
1405static int parse_txq_params(struct nlattr *tb[],
1406 struct ieee80211_txq_params *txq_params)
1407{
Johannes Berga3304b02012-03-28 11:04:24 +02001408 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001409 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1410 !tb[NL80211_TXQ_ATTR_AIFS])
1411 return -EINVAL;
1412
Johannes Berga3304b02012-03-28 11:04:24 +02001413 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001414 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1415 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1416 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1417 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1418
Johannes Berga3304b02012-03-28 11:04:24 +02001419 if (txq_params->ac >= NL80211_NUM_ACS)
1420 return -EINVAL;
1421
Jouni Malinen31888482008-10-30 16:59:24 +02001422 return 0;
1423}
1424
Johannes Bergf444de02010-05-05 15:25:02 +02001425static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1426{
1427 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001428 * You can only set the channel explicitly for WDS interfaces,
1429 * all others have their channel managed via their respective
1430 * "establish a connection" command (connect, join, ...)
1431 *
1432 * For AP/GO and mesh mode, the channel can be set with the
1433 * channel userspace API, but is only stored and passed to the
1434 * low-level driver when the AP starts or the mesh is joined.
1435 * This is for backward compatibility, userspace can also give
1436 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001437 *
1438 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001439 * whatever else is going on, so they have their own special
1440 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001441 */
1442 return !wdev ||
1443 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001444 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001445 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1446 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001447}
1448
Johannes Berg683b6d32012-11-08 21:25:48 +01001449static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1450 struct genl_info *info,
1451 struct cfg80211_chan_def *chandef)
1452{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301453 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001454
1455 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1456 return -EINVAL;
1457
1458 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1459
1460 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001461 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1462 chandef->center_freq1 = control_freq;
1463 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001464
1465 /* Primary channel not allowed */
1466 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1467 return -EINVAL;
1468
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001469 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1470 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001471
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001472 chantype = nla_get_u32(
1473 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1474
1475 switch (chantype) {
1476 case NL80211_CHAN_NO_HT:
1477 case NL80211_CHAN_HT20:
1478 case NL80211_CHAN_HT40PLUS:
1479 case NL80211_CHAN_HT40MINUS:
1480 cfg80211_chandef_create(chandef, chandef->chan,
1481 chantype);
1482 break;
1483 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001484 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001485 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001486 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1487 chandef->width =
1488 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1489 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1490 chandef->center_freq1 =
1491 nla_get_u32(
1492 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1493 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1494 chandef->center_freq2 =
1495 nla_get_u32(
1496 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1497 }
1498
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001499 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001500 return -EINVAL;
1501
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001502 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1503 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001504 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001505
Johannes Berg683b6d32012-11-08 21:25:48 +01001506 return 0;
1507}
1508
Johannes Bergf444de02010-05-05 15:25:02 +02001509static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1510 struct wireless_dev *wdev,
1511 struct genl_info *info)
1512{
Johannes Berg683b6d32012-11-08 21:25:48 +01001513 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001514 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001515 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1516
1517 if (wdev)
1518 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001519
Johannes Bergf444de02010-05-05 15:25:02 +02001520 if (!nl80211_can_set_dev_channel(wdev))
1521 return -EOPNOTSUPP;
1522
Johannes Berg683b6d32012-11-08 21:25:48 +01001523 result = nl80211_parse_chandef(rdev, info, &chandef);
1524 if (result)
1525 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001526
1527 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001528 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001529 case NL80211_IFTYPE_AP:
1530 case NL80211_IFTYPE_P2P_GO:
1531 if (wdev->beacon_interval) {
1532 result = -EBUSY;
1533 break;
1534 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001535 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001536 result = -EINVAL;
1537 break;
1538 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001539 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001540 result = 0;
1541 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001542 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001543 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001544 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001545 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001546 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001547 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001548 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001549 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001550 }
1551 mutex_unlock(&rdev->devlist_mtx);
1552
1553 return result;
1554}
1555
1556static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1557{
Johannes Berg4c476992010-10-04 21:36:35 +02001558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1559 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001560
Johannes Berg4c476992010-10-04 21:36:35 +02001561 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001562}
1563
Bill Jordane8347eb2010-10-01 13:54:28 -04001564static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1565{
Johannes Berg43b19952010-10-07 13:10:30 +02001566 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1567 struct net_device *dev = info->user_ptr[1];
1568 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001569 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001570
1571 if (!info->attrs[NL80211_ATTR_MAC])
1572 return -EINVAL;
1573
Johannes Berg43b19952010-10-07 13:10:30 +02001574 if (netif_running(dev))
1575 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001576
Johannes Berg43b19952010-10-07 13:10:30 +02001577 if (!rdev->ops->set_wds_peer)
1578 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001579
Johannes Berg43b19952010-10-07 13:10:30 +02001580 if (wdev->iftype != NL80211_IFTYPE_WDS)
1581 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001582
1583 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001584 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001585}
1586
1587
Johannes Berg55682962007-09-20 13:09:35 -04001588static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1589{
1590 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001591 struct net_device *netdev = NULL;
1592 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001593 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001594 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001595 u32 changed;
1596 u8 retry_short = 0, retry_long = 0;
1597 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001598 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001599
Johannes Bergf444de02010-05-05 15:25:02 +02001600 /*
1601 * Try to find the wiphy and netdev. Normally this
1602 * function shouldn't need the netdev, but this is
1603 * done for backward compatibility -- previously
1604 * setting the channel was done per wiphy, but now
1605 * it is per netdev. Previous userland like hostapd
1606 * also passed a netdev to set_wiphy, so that it is
1607 * possible to let that go to the right netdev!
1608 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001609 mutex_lock(&cfg80211_mutex);
1610
Johannes Bergf444de02010-05-05 15:25:02 +02001611 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1612 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1613
1614 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1615 if (netdev && netdev->ieee80211_ptr) {
1616 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1617 mutex_lock(&rdev->mtx);
1618 } else
1619 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001620 }
1621
Johannes Bergf444de02010-05-05 15:25:02 +02001622 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001623 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1624 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001625 if (IS_ERR(rdev)) {
1626 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001627 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001628 }
1629 wdev = NULL;
1630 netdev = NULL;
1631 result = 0;
1632
1633 mutex_lock(&rdev->mtx);
Johannes Berg71fe96b2012-10-24 10:04:58 +02001634 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001635 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001636
1637 /*
1638 * end workaround code, by now the rdev is available
1639 * and locked, and wdev may or may not be NULL.
1640 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001641
1642 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001643 result = cfg80211_dev_rename(
1644 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001645
1646 mutex_unlock(&cfg80211_mutex);
1647
1648 if (result)
1649 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001650
Jouni Malinen31888482008-10-30 16:59:24 +02001651 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1652 struct ieee80211_txq_params txq_params;
1653 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1654
1655 if (!rdev->ops->set_txq_params) {
1656 result = -EOPNOTSUPP;
1657 goto bad_res;
1658 }
1659
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001660 if (!netdev) {
1661 result = -EINVAL;
1662 goto bad_res;
1663 }
1664
Johannes Berg133a3ff2011-11-03 14:50:13 +01001665 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1666 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1667 result = -EINVAL;
1668 goto bad_res;
1669 }
1670
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001671 if (!netif_running(netdev)) {
1672 result = -ENETDOWN;
1673 goto bad_res;
1674 }
1675
Jouni Malinen31888482008-10-30 16:59:24 +02001676 nla_for_each_nested(nl_txq_params,
1677 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1678 rem_txq_params) {
1679 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1680 nla_data(nl_txq_params),
1681 nla_len(nl_txq_params),
1682 txq_params_policy);
1683 result = parse_txq_params(tb, &txq_params);
1684 if (result)
1685 goto bad_res;
1686
Hila Gonene35e4d22012-06-27 17:19:42 +03001687 result = rdev_set_txq_params(rdev, netdev,
1688 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001689 if (result)
1690 goto bad_res;
1691 }
1692 }
1693
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001694 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001695 result = __nl80211_set_channel(rdev,
1696 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1697 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001698 if (result)
1699 goto bad_res;
1700 }
1701
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001702 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001703 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001704 enum nl80211_tx_power_setting type;
1705 int idx, mbm = 0;
1706
Johannes Bergc8442112012-10-24 10:17:18 +02001707 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1708 txp_wdev = NULL;
1709
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001710 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001711 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001712 goto bad_res;
1713 }
1714
1715 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1716 type = nla_get_u32(info->attrs[idx]);
1717
1718 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1719 (type != NL80211_TX_POWER_AUTOMATIC)) {
1720 result = -EINVAL;
1721 goto bad_res;
1722 }
1723
1724 if (type != NL80211_TX_POWER_AUTOMATIC) {
1725 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1726 mbm = nla_get_u32(info->attrs[idx]);
1727 }
1728
Johannes Bergc8442112012-10-24 10:17:18 +02001729 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001730 if (result)
1731 goto bad_res;
1732 }
1733
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001734 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1735 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1736 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001737 if ((!rdev->wiphy.available_antennas_tx &&
1738 !rdev->wiphy.available_antennas_rx) ||
1739 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001740 result = -EOPNOTSUPP;
1741 goto bad_res;
1742 }
1743
1744 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1745 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1746
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001747 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001748 * available antenna masks, except for the "all" mask */
1749 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1750 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001751 result = -EINVAL;
1752 goto bad_res;
1753 }
1754
Bruno Randolf7f531e02010-12-16 11:30:22 +09001755 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1756 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001757
Hila Gonene35e4d22012-06-27 17:19:42 +03001758 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001759 if (result)
1760 goto bad_res;
1761 }
1762
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001763 changed = 0;
1764
1765 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1766 retry_short = nla_get_u8(
1767 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1768 if (retry_short == 0) {
1769 result = -EINVAL;
1770 goto bad_res;
1771 }
1772 changed |= WIPHY_PARAM_RETRY_SHORT;
1773 }
1774
1775 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1776 retry_long = nla_get_u8(
1777 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1778 if (retry_long == 0) {
1779 result = -EINVAL;
1780 goto bad_res;
1781 }
1782 changed |= WIPHY_PARAM_RETRY_LONG;
1783 }
1784
1785 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1786 frag_threshold = nla_get_u32(
1787 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1788 if (frag_threshold < 256) {
1789 result = -EINVAL;
1790 goto bad_res;
1791 }
1792 if (frag_threshold != (u32) -1) {
1793 /*
1794 * Fragments (apart from the last one) are required to
1795 * have even length. Make the fragmentation code
1796 * simpler by stripping LSB should someone try to use
1797 * odd threshold value.
1798 */
1799 frag_threshold &= ~0x1;
1800 }
1801 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1802 }
1803
1804 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1805 rts_threshold = nla_get_u32(
1806 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1807 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1808 }
1809
Lukáš Turek81077e82009-12-21 22:50:47 +01001810 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1811 coverage_class = nla_get_u8(
1812 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1813 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1814 }
1815
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001816 if (changed) {
1817 u8 old_retry_short, old_retry_long;
1818 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001819 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001820
1821 if (!rdev->ops->set_wiphy_params) {
1822 result = -EOPNOTSUPP;
1823 goto bad_res;
1824 }
1825
1826 old_retry_short = rdev->wiphy.retry_short;
1827 old_retry_long = rdev->wiphy.retry_long;
1828 old_frag_threshold = rdev->wiphy.frag_threshold;
1829 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001830 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001831
1832 if (changed & WIPHY_PARAM_RETRY_SHORT)
1833 rdev->wiphy.retry_short = retry_short;
1834 if (changed & WIPHY_PARAM_RETRY_LONG)
1835 rdev->wiphy.retry_long = retry_long;
1836 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1837 rdev->wiphy.frag_threshold = frag_threshold;
1838 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1839 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001840 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1841 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001842
Hila Gonene35e4d22012-06-27 17:19:42 +03001843 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001844 if (result) {
1845 rdev->wiphy.retry_short = old_retry_short;
1846 rdev->wiphy.retry_long = old_retry_long;
1847 rdev->wiphy.frag_threshold = old_frag_threshold;
1848 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001849 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001850 }
1851 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001852
Johannes Berg306d6112008-12-08 12:39:04 +01001853 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001854 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001855 if (netdev)
1856 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001857 return result;
1858}
1859
Johannes Berg71bbc992012-06-15 15:30:18 +02001860static inline u64 wdev_id(struct wireless_dev *wdev)
1861{
1862 return (u64)wdev->identifier |
1863 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
1864}
Johannes Berg55682962007-09-20 13:09:35 -04001865
Johannes Berg683b6d32012-11-08 21:25:48 +01001866static int nl80211_send_chandef(struct sk_buff *msg,
1867 struct cfg80211_chan_def *chandef)
1868{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001869 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001870
Johannes Berg683b6d32012-11-08 21:25:48 +01001871 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1872 chandef->chan->center_freq))
1873 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001874 switch (chandef->width) {
1875 case NL80211_CHAN_WIDTH_20_NOHT:
1876 case NL80211_CHAN_WIDTH_20:
1877 case NL80211_CHAN_WIDTH_40:
1878 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1879 cfg80211_get_chandef_type(chandef)))
1880 return -ENOBUFS;
1881 break;
1882 default:
1883 break;
1884 }
1885 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
1886 return -ENOBUFS;
1887 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
1888 return -ENOBUFS;
1889 if (chandef->center_freq2 &&
1890 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01001891 return -ENOBUFS;
1892 return 0;
1893}
1894
Eric W. Biederman15e47302012-09-07 20:12:54 +00001895static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001896 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001897 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04001898{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001899 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04001900 void *hdr;
1901
Eric W. Biederman15e47302012-09-07 20:12:54 +00001902 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04001903 if (!hdr)
1904 return -1;
1905
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001906 if (dev &&
1907 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001908 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001909 goto nla_put_failure;
1910
1911 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1912 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02001913 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001914 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001915 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1916 rdev->devlist_generation ^
1917 (cfg80211_rdev_list_generation << 2)))
1918 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001919
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02001920 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01001921 int ret;
1922 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02001923
Johannes Berg683b6d32012-11-08 21:25:48 +01001924 ret = rdev_get_channel(rdev, wdev, &chandef);
1925 if (ret == 0) {
1926 if (nl80211_send_chandef(msg, &chandef))
1927 goto nla_put_failure;
1928 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001929 }
1930
Antonio Quartullib84e7a02012-11-07 12:52:20 +01001931 if (wdev->ssid_len) {
1932 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
1933 goto nla_put_failure;
1934 }
1935
Johannes Berg55682962007-09-20 13:09:35 -04001936 return genlmsg_end(msg, hdr);
1937
1938 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001939 genlmsg_cancel(msg, hdr);
1940 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001941}
1942
1943static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1944{
1945 int wp_idx = 0;
1946 int if_idx = 0;
1947 int wp_start = cb->args[0];
1948 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001949 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001950 struct wireless_dev *wdev;
1951
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001952 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001953 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1954 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001955 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001956 if (wp_idx < wp_start) {
1957 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001958 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001959 }
Johannes Berg55682962007-09-20 13:09:35 -04001960 if_idx = 0;
1961
Johannes Bergf5ea9122009-08-07 16:17:38 +02001962 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02001963 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001964 if (if_idx < if_start) {
1965 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001966 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001967 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00001968 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04001969 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001970 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02001971 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001972 goto out;
1973 }
1974 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001975 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001976 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001977
1978 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001979 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001980 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001981 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001982
1983 cb->args[0] = wp_idx;
1984 cb->args[1] = if_idx;
1985
1986 return skb->len;
1987}
1988
1989static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1990{
1991 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001992 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001993 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001994
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001995 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001996 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001997 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001998
Eric W. Biederman15e47302012-09-07 20:12:54 +00001999 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002000 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002001 nlmsg_free(msg);
2002 return -ENOBUFS;
2003 }
Johannes Berg55682962007-09-20 13:09:35 -04002004
Johannes Berg134e6372009-07-10 09:51:34 +00002005 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002006}
2007
Michael Wu66f7ac52008-01-31 19:48:22 +01002008static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2009 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2010 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2011 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2012 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2013 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2014};
2015
2016static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2017{
2018 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2019 int flag;
2020
2021 *mntrflags = 0;
2022
2023 if (!nla)
2024 return -EINVAL;
2025
2026 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2027 nla, mntr_flags_policy))
2028 return -EINVAL;
2029
2030 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2031 if (flags[flag])
2032 *mntrflags |= (1<<flag);
2033
2034 return 0;
2035}
2036
Johannes Berg9bc383d2009-11-19 11:55:19 +01002037static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002038 struct net_device *netdev, u8 use_4addr,
2039 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002040{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002041 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002042 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002043 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002044 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002045 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002046
2047 switch (iftype) {
2048 case NL80211_IFTYPE_AP_VLAN:
2049 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2050 return 0;
2051 break;
2052 case NL80211_IFTYPE_STATION:
2053 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2054 return 0;
2055 break;
2056 default:
2057 break;
2058 }
2059
2060 return -EOPNOTSUPP;
2061}
2062
Johannes Berg55682962007-09-20 13:09:35 -04002063static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2064{
Johannes Berg4c476992010-10-04 21:36:35 +02002065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002066 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002067 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002068 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002069 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002070 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002071 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002072
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002073 memset(&params, 0, sizeof(params));
2074
Johannes Berg04a773a2009-04-19 21:24:32 +02002075 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002076
Johannes Berg723b0382008-09-16 20:22:09 +02002077 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002078 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002079 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002080 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002081 if (ntype > NL80211_IFTYPE_MAX)
2082 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002083 }
2084
Johannes Berg92ffe052008-09-16 20:39:36 +02002085 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002086 struct wireless_dev *wdev = dev->ieee80211_ptr;
2087
Johannes Berg4c476992010-10-04 21:36:35 +02002088 if (ntype != NL80211_IFTYPE_MESH_POINT)
2089 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002090 if (netif_running(dev))
2091 return -EBUSY;
2092
2093 wdev_lock(wdev);
2094 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2095 IEEE80211_MAX_MESH_ID_LEN);
2096 wdev->mesh_id_up_len =
2097 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2098 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2099 wdev->mesh_id_up_len);
2100 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002101 }
2102
Felix Fietkau8b787642009-11-10 18:53:10 +01002103 if (info->attrs[NL80211_ATTR_4ADDR]) {
2104 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2105 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002106 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002107 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002108 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002109 } else {
2110 params.use_4addr = -1;
2111 }
2112
Johannes Berg92ffe052008-09-16 20:39:36 +02002113 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002114 if (ntype != NL80211_IFTYPE_MONITOR)
2115 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002116 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2117 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002118 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002119 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002120
2121 flags = &_flags;
2122 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002123 }
Johannes Berg3b858752009-03-12 09:55:09 +01002124
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002125 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002126 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002127 else
2128 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002129
Johannes Berg9bc383d2009-11-19 11:55:19 +01002130 if (!err && params.use_4addr != -1)
2131 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2132
Johannes Berg55682962007-09-20 13:09:35 -04002133 return err;
2134}
2135
2136static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2137{
Johannes Berg4c476992010-10-04 21:36:35 +02002138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002139 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002140 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002141 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002142 int err;
2143 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002144 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002145
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002146 memset(&params, 0, sizeof(params));
2147
Johannes Berg55682962007-09-20 13:09:35 -04002148 if (!info->attrs[NL80211_ATTR_IFNAME])
2149 return -EINVAL;
2150
2151 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2152 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2153 if (type > NL80211_IFTYPE_MAX)
2154 return -EINVAL;
2155 }
2156
Johannes Berg79c97e92009-07-07 03:56:12 +02002157 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002158 !(rdev->wiphy.interface_modes & (1 << type)))
2159 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002160
Arend van Spriel1c18f142013-01-08 10:17:27 +01002161 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2162 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2163 ETH_ALEN);
2164 if (!is_valid_ether_addr(params.macaddr))
2165 return -EADDRNOTAVAIL;
2166 }
2167
Johannes Berg9bc383d2009-11-19 11:55:19 +01002168 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002169 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002170 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002171 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002172 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002173 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002174
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2176 if (!msg)
2177 return -ENOMEM;
2178
Michael Wu66f7ac52008-01-31 19:48:22 +01002179 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2180 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2181 &flags);
Hila Gonene35e4d22012-06-27 17:19:42 +03002182 wdev = rdev_add_virtual_intf(rdev,
2183 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2184 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002185 if (IS_ERR(wdev)) {
2186 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002187 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002188 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002189
Johannes Berg98104fde2012-06-16 00:19:54 +02002190 switch (type) {
2191 case NL80211_IFTYPE_MESH_POINT:
2192 if (!info->attrs[NL80211_ATTR_MESH_ID])
2193 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002194 wdev_lock(wdev);
2195 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2196 IEEE80211_MAX_MESH_ID_LEN);
2197 wdev->mesh_id_up_len =
2198 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2199 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2200 wdev->mesh_id_up_len);
2201 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002202 break;
2203 case NL80211_IFTYPE_P2P_DEVICE:
2204 /*
2205 * P2P Device doesn't have a netdev, so doesn't go
2206 * through the netdev notifier and must be added here
2207 */
2208 mutex_init(&wdev->mtx);
2209 INIT_LIST_HEAD(&wdev->event_list);
2210 spin_lock_init(&wdev->event_lock);
2211 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2212 spin_lock_init(&wdev->mgmt_registrations_lock);
2213
2214 mutex_lock(&rdev->devlist_mtx);
2215 wdev->identifier = ++rdev->wdev_id;
2216 list_add_rcu(&wdev->list, &rdev->wdev_list);
2217 rdev->devlist_generation++;
2218 mutex_unlock(&rdev->devlist_mtx);
2219 break;
2220 default:
2221 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002222 }
2223
Eric W. Biederman15e47302012-09-07 20:12:54 +00002224 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002225 rdev, wdev) < 0) {
2226 nlmsg_free(msg);
2227 return -ENOBUFS;
2228 }
2229
2230 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002231}
2232
2233static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2234{
Johannes Berg4c476992010-10-04 21:36:35 +02002235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002236 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002237
Johannes Berg4c476992010-10-04 21:36:35 +02002238 if (!rdev->ops->del_virtual_intf)
2239 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002240
Johannes Berg84efbb82012-06-16 00:00:26 +02002241 /*
2242 * If we remove a wireless device without a netdev then clear
2243 * user_ptr[1] so that nl80211_post_doit won't dereference it
2244 * to check if it needs to do dev_put(). Otherwise it crashes
2245 * since the wdev has been freed, unlike with a netdev where
2246 * we need the dev_put() for the netdev to really be freed.
2247 */
2248 if (!wdev->netdev)
2249 info->user_ptr[1] = NULL;
2250
Hila Gonene35e4d22012-06-27 17:19:42 +03002251 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002252}
2253
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002254static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2255{
2256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2257 struct net_device *dev = info->user_ptr[1];
2258 u16 noack_map;
2259
2260 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2261 return -EINVAL;
2262
2263 if (!rdev->ops->set_noack_map)
2264 return -EOPNOTSUPP;
2265
2266 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2267
Hila Gonene35e4d22012-06-27 17:19:42 +03002268 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002269}
2270
Johannes Berg41ade002007-12-19 02:03:29 +01002271struct get_key_cookie {
2272 struct sk_buff *msg;
2273 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002274 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002275};
2276
2277static void get_key_callback(void *c, struct key_params *params)
2278{
Johannes Bergb9454e82009-07-08 13:29:08 +02002279 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002280 struct get_key_cookie *cookie = c;
2281
David S. Miller9360ffd2012-03-29 04:41:26 -04002282 if ((params->key &&
2283 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2284 params->key_len, params->key)) ||
2285 (params->seq &&
2286 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2287 params->seq_len, params->seq)) ||
2288 (params->cipher &&
2289 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2290 params->cipher)))
2291 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002292
Johannes Bergb9454e82009-07-08 13:29:08 +02002293 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2294 if (!key)
2295 goto nla_put_failure;
2296
David S. Miller9360ffd2012-03-29 04:41:26 -04002297 if ((params->key &&
2298 nla_put(cookie->msg, NL80211_KEY_DATA,
2299 params->key_len, params->key)) ||
2300 (params->seq &&
2301 nla_put(cookie->msg, NL80211_KEY_SEQ,
2302 params->seq_len, params->seq)) ||
2303 (params->cipher &&
2304 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2305 params->cipher)))
2306 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002307
David S. Miller9360ffd2012-03-29 04:41:26 -04002308 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2309 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002310
2311 nla_nest_end(cookie->msg, key);
2312
Johannes Berg41ade002007-12-19 02:03:29 +01002313 return;
2314 nla_put_failure:
2315 cookie->error = 1;
2316}
2317
2318static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2319{
Johannes Berg4c476992010-10-04 21:36:35 +02002320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002321 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002322 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002323 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002324 const u8 *mac_addr = NULL;
2325 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002326 struct get_key_cookie cookie = {
2327 .error = 0,
2328 };
2329 void *hdr;
2330 struct sk_buff *msg;
2331
2332 if (info->attrs[NL80211_ATTR_KEY_IDX])
2333 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2334
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002335 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002336 return -EINVAL;
2337
2338 if (info->attrs[NL80211_ATTR_MAC])
2339 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2340
Johannes Berge31b8212010-10-05 19:39:30 +02002341 pairwise = !!mac_addr;
2342 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2343 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2344 if (kt >= NUM_NL80211_KEYTYPES)
2345 return -EINVAL;
2346 if (kt != NL80211_KEYTYPE_GROUP &&
2347 kt != NL80211_KEYTYPE_PAIRWISE)
2348 return -EINVAL;
2349 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2350 }
2351
Johannes Berg4c476992010-10-04 21:36:35 +02002352 if (!rdev->ops->get_key)
2353 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002354
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002355 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002356 if (!msg)
2357 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002358
Eric W. Biederman15e47302012-09-07 20:12:54 +00002359 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002360 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002361 if (IS_ERR(hdr))
2362 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002363
2364 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002365 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002366
David S. Miller9360ffd2012-03-29 04:41:26 -04002367 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2368 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2369 goto nla_put_failure;
2370 if (mac_addr &&
2371 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2372 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002373
Johannes Berge31b8212010-10-05 19:39:30 +02002374 if (pairwise && mac_addr &&
2375 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2376 return -ENOENT;
2377
Hila Gonene35e4d22012-06-27 17:19:42 +03002378 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2379 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002380
2381 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002382 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002383
2384 if (cookie.error)
2385 goto nla_put_failure;
2386
2387 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002388 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002389
2390 nla_put_failure:
2391 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002392 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002393 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002394 return err;
2395}
2396
2397static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2398{
Johannes Berg4c476992010-10-04 21:36:35 +02002399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002400 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002401 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002402 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002403
Johannes Bergb9454e82009-07-08 13:29:08 +02002404 err = nl80211_parse_key(info, &key);
2405 if (err)
2406 return err;
2407
2408 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002409 return -EINVAL;
2410
Johannes Bergb9454e82009-07-08 13:29:08 +02002411 /* only support setting default key */
2412 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002413 return -EINVAL;
2414
Johannes Bergfffd0932009-07-08 14:22:54 +02002415 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002416
2417 if (key.def) {
2418 if (!rdev->ops->set_default_key) {
2419 err = -EOPNOTSUPP;
2420 goto out;
2421 }
2422
2423 err = nl80211_key_allowed(dev->ieee80211_ptr);
2424 if (err)
2425 goto out;
2426
Hila Gonene35e4d22012-06-27 17:19:42 +03002427 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002428 key.def_uni, key.def_multi);
2429
2430 if (err)
2431 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002432
Johannes Berg3d23e342009-09-29 23:27:28 +02002433#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002434 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002435#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002436 } else {
2437 if (key.def_uni || !key.def_multi) {
2438 err = -EINVAL;
2439 goto out;
2440 }
2441
2442 if (!rdev->ops->set_default_mgmt_key) {
2443 err = -EOPNOTSUPP;
2444 goto out;
2445 }
2446
2447 err = nl80211_key_allowed(dev->ieee80211_ptr);
2448 if (err)
2449 goto out;
2450
Hila Gonene35e4d22012-06-27 17:19:42 +03002451 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002452 if (err)
2453 goto out;
2454
2455#ifdef CONFIG_CFG80211_WEXT
2456 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2457#endif
2458 }
2459
2460 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002461 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002462
Johannes Berg41ade002007-12-19 02:03:29 +01002463 return err;
2464}
2465
2466static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2467{
Johannes Berg4c476992010-10-04 21:36:35 +02002468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002469 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002470 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002471 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002472 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002473
Johannes Bergb9454e82009-07-08 13:29:08 +02002474 err = nl80211_parse_key(info, &key);
2475 if (err)
2476 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002477
Johannes Bergb9454e82009-07-08 13:29:08 +02002478 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002479 return -EINVAL;
2480
Johannes Berg41ade002007-12-19 02:03:29 +01002481 if (info->attrs[NL80211_ATTR_MAC])
2482 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2483
Johannes Berge31b8212010-10-05 19:39:30 +02002484 if (key.type == -1) {
2485 if (mac_addr)
2486 key.type = NL80211_KEYTYPE_PAIRWISE;
2487 else
2488 key.type = NL80211_KEYTYPE_GROUP;
2489 }
2490
2491 /* for now */
2492 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2493 key.type != NL80211_KEYTYPE_GROUP)
2494 return -EINVAL;
2495
Johannes Berg4c476992010-10-04 21:36:35 +02002496 if (!rdev->ops->add_key)
2497 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002498
Johannes Berge31b8212010-10-05 19:39:30 +02002499 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2500 key.type == NL80211_KEYTYPE_PAIRWISE,
2501 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002502 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002503
2504 wdev_lock(dev->ieee80211_ptr);
2505 err = nl80211_key_allowed(dev->ieee80211_ptr);
2506 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002507 err = rdev_add_key(rdev, dev, key.idx,
2508 key.type == NL80211_KEYTYPE_PAIRWISE,
2509 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002510 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002511
Johannes Berg41ade002007-12-19 02:03:29 +01002512 return err;
2513}
2514
2515static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2516{
Johannes Berg4c476992010-10-04 21:36:35 +02002517 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002518 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002519 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002520 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002521 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002522
Johannes Bergb9454e82009-07-08 13:29:08 +02002523 err = nl80211_parse_key(info, &key);
2524 if (err)
2525 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002526
2527 if (info->attrs[NL80211_ATTR_MAC])
2528 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2529
Johannes Berge31b8212010-10-05 19:39:30 +02002530 if (key.type == -1) {
2531 if (mac_addr)
2532 key.type = NL80211_KEYTYPE_PAIRWISE;
2533 else
2534 key.type = NL80211_KEYTYPE_GROUP;
2535 }
2536
2537 /* for now */
2538 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2539 key.type != NL80211_KEYTYPE_GROUP)
2540 return -EINVAL;
2541
Johannes Berg4c476992010-10-04 21:36:35 +02002542 if (!rdev->ops->del_key)
2543 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002544
Johannes Bergfffd0932009-07-08 14:22:54 +02002545 wdev_lock(dev->ieee80211_ptr);
2546 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002547
2548 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2549 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2550 err = -ENOENT;
2551
Johannes Bergfffd0932009-07-08 14:22:54 +02002552 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002553 err = rdev_del_key(rdev, dev, key.idx,
2554 key.type == NL80211_KEYTYPE_PAIRWISE,
2555 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002556
Johannes Berg3d23e342009-09-29 23:27:28 +02002557#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002558 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002559 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002560 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002561 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002562 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2563 }
2564#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002565 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002566
Johannes Berg41ade002007-12-19 02:03:29 +01002567 return err;
2568}
2569
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302570/* This function returns an error or the number of nested attributes */
2571static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2572{
2573 struct nlattr *attr;
2574 int n_entries = 0, tmp;
2575
2576 nla_for_each_nested(attr, nl_attr, tmp) {
2577 if (nla_len(attr) != ETH_ALEN)
2578 return -EINVAL;
2579
2580 n_entries++;
2581 }
2582
2583 return n_entries;
2584}
2585
2586/*
2587 * This function parses ACL information and allocates memory for ACL data.
2588 * On successful return, the calling function is responsible to free the
2589 * ACL buffer returned by this function.
2590 */
2591static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2592 struct genl_info *info)
2593{
2594 enum nl80211_acl_policy acl_policy;
2595 struct nlattr *attr;
2596 struct cfg80211_acl_data *acl;
2597 int i = 0, n_entries, tmp;
2598
2599 if (!wiphy->max_acl_mac_addrs)
2600 return ERR_PTR(-EOPNOTSUPP);
2601
2602 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2603 return ERR_PTR(-EINVAL);
2604
2605 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2606 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2607 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2608 return ERR_PTR(-EINVAL);
2609
2610 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2611 return ERR_PTR(-EINVAL);
2612
2613 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2614 if (n_entries < 0)
2615 return ERR_PTR(n_entries);
2616
2617 if (n_entries > wiphy->max_acl_mac_addrs)
2618 return ERR_PTR(-ENOTSUPP);
2619
2620 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2621 GFP_KERNEL);
2622 if (!acl)
2623 return ERR_PTR(-ENOMEM);
2624
2625 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2626 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2627 i++;
2628 }
2629
2630 acl->n_acl_entries = n_entries;
2631 acl->acl_policy = acl_policy;
2632
2633 return acl;
2634}
2635
2636static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2637{
2638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2639 struct net_device *dev = info->user_ptr[1];
2640 struct cfg80211_acl_data *acl;
2641 int err;
2642
2643 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2644 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2645 return -EOPNOTSUPP;
2646
2647 if (!dev->ieee80211_ptr->beacon_interval)
2648 return -EINVAL;
2649
2650 acl = parse_acl_data(&rdev->wiphy, info);
2651 if (IS_ERR(acl))
2652 return PTR_ERR(acl);
2653
2654 err = rdev_set_mac_acl(rdev, dev, acl);
2655
2656 kfree(acl);
2657
2658 return err;
2659}
2660
Johannes Berg88600202012-02-13 15:17:18 +01002661static int nl80211_parse_beacon(struct genl_info *info,
2662 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002663{
Johannes Berg88600202012-02-13 15:17:18 +01002664 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002665
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002666 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2667 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2668 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2669 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002670 return -EINVAL;
2671
Johannes Berg88600202012-02-13 15:17:18 +01002672 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002673
Johannes Berged1b6cc2007-12-19 02:03:32 +01002674 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002675 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2676 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2677 if (!bcn->head_len)
2678 return -EINVAL;
2679 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002680 }
2681
2682 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002683 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2684 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002685 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002686 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002687 }
2688
Johannes Berg4c476992010-10-04 21:36:35 +02002689 if (!haveinfo)
2690 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002691
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002692 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002693 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2694 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002695 }
2696
2697 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002698 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002699 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002700 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002701 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2702 }
2703
2704 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002705 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002706 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002707 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002708 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2709 }
2710
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002711 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002712 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002713 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002714 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002715 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2716 }
2717
Johannes Berg88600202012-02-13 15:17:18 +01002718 return 0;
2719}
2720
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002721static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2722 struct cfg80211_ap_settings *params)
2723{
2724 struct wireless_dev *wdev;
2725 bool ret = false;
2726
2727 mutex_lock(&rdev->devlist_mtx);
2728
Johannes Berg89a54e42012-06-15 14:33:17 +02002729 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002730 if (wdev->iftype != NL80211_IFTYPE_AP &&
2731 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2732 continue;
2733
Johannes Berg683b6d32012-11-08 21:25:48 +01002734 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002735 continue;
2736
Johannes Berg683b6d32012-11-08 21:25:48 +01002737 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002738 ret = true;
2739 break;
2740 }
2741
2742 mutex_unlock(&rdev->devlist_mtx);
2743
2744 return ret;
2745}
2746
Jouni Malinene39e5b52012-09-30 19:29:39 +03002747static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2748 enum nl80211_auth_type auth_type,
2749 enum nl80211_commands cmd)
2750{
2751 if (auth_type > NL80211_AUTHTYPE_MAX)
2752 return false;
2753
2754 switch (cmd) {
2755 case NL80211_CMD_AUTHENTICATE:
2756 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2757 auth_type == NL80211_AUTHTYPE_SAE)
2758 return false;
2759 return true;
2760 case NL80211_CMD_CONNECT:
2761 case NL80211_CMD_START_AP:
2762 /* SAE not supported yet */
2763 if (auth_type == NL80211_AUTHTYPE_SAE)
2764 return false;
2765 return true;
2766 default:
2767 return false;
2768 }
2769}
2770
Johannes Berg88600202012-02-13 15:17:18 +01002771static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2772{
2773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2774 struct net_device *dev = info->user_ptr[1];
2775 struct wireless_dev *wdev = dev->ieee80211_ptr;
2776 struct cfg80211_ap_settings params;
2777 int err;
2778
2779 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2780 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2781 return -EOPNOTSUPP;
2782
2783 if (!rdev->ops->start_ap)
2784 return -EOPNOTSUPP;
2785
2786 if (wdev->beacon_interval)
2787 return -EALREADY;
2788
2789 memset(&params, 0, sizeof(params));
2790
2791 /* these are required for START_AP */
2792 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2793 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2794 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2795 return -EINVAL;
2796
2797 err = nl80211_parse_beacon(info, &params.beacon);
2798 if (err)
2799 return err;
2800
2801 params.beacon_interval =
2802 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2803 params.dtim_period =
2804 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2805
2806 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2807 if (err)
2808 return err;
2809
2810 /*
2811 * In theory, some of these attributes should be required here
2812 * but since they were not used when the command was originally
2813 * added, keep them optional for old user space programs to let
2814 * them continue to work with drivers that do not need the
2815 * additional information -- drivers must check!
2816 */
2817 if (info->attrs[NL80211_ATTR_SSID]) {
2818 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2819 params.ssid_len =
2820 nla_len(info->attrs[NL80211_ATTR_SSID]);
2821 if (params.ssid_len == 0 ||
2822 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2823 return -EINVAL;
2824 }
2825
2826 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2827 params.hidden_ssid = nla_get_u32(
2828 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2829 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2830 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2831 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2832 return -EINVAL;
2833 }
2834
2835 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2836
2837 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2838 params.auth_type = nla_get_u32(
2839 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03002840 if (!nl80211_valid_auth_type(rdev, params.auth_type,
2841 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01002842 return -EINVAL;
2843 } else
2844 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2845
2846 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2847 NL80211_MAX_NR_CIPHER_SUITES);
2848 if (err)
2849 return err;
2850
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302851 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2852 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2853 return -EOPNOTSUPP;
2854 params.inactivity_timeout = nla_get_u16(
2855 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2856 }
2857
Johannes Berg53cabad2012-11-14 15:17:28 +01002858 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
2859 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2860 return -EINVAL;
2861 params.p2p_ctwindow =
2862 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
2863 if (params.p2p_ctwindow > 127)
2864 return -EINVAL;
2865 if (params.p2p_ctwindow != 0 &&
2866 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
2867 return -EINVAL;
2868 }
2869
2870 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
2871 u8 tmp;
2872
2873 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2874 return -EINVAL;
2875 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
2876 if (tmp > 1)
2877 return -EINVAL;
2878 params.p2p_opp_ps = tmp;
2879 if (params.p2p_opp_ps != 0 &&
2880 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
2881 return -EINVAL;
2882 }
2883
Johannes Bergaa430da2012-05-16 23:50:18 +02002884 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002885 err = nl80211_parse_chandef(rdev, info, &params.chandef);
2886 if (err)
2887 return err;
2888 } else if (wdev->preset_chandef.chan) {
2889 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002890 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002891 return -EINVAL;
2892
Johannes Berg683b6d32012-11-08 21:25:48 +01002893 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02002894 return -EINVAL;
2895
Michal Kaziore4e32452012-06-29 12:47:08 +02002896 mutex_lock(&rdev->devlist_mtx);
Johannes Berg683b6d32012-11-08 21:25:48 +01002897 err = cfg80211_can_use_chan(rdev, wdev, params.chandef.chan,
Michal Kaziore4e32452012-06-29 12:47:08 +02002898 CHAN_MODE_SHARED);
2899 mutex_unlock(&rdev->devlist_mtx);
2900
2901 if (err)
2902 return err;
2903
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302904 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
2905 params.acl = parse_acl_data(&rdev->wiphy, info);
2906 if (IS_ERR(params.acl))
2907 return PTR_ERR(params.acl);
2908 }
2909
Hila Gonene35e4d22012-06-27 17:19:42 +03002910 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002911 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002912 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01002913 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01002914 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01002915 wdev->ssid_len = params.ssid_len;
2916 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002917 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302918
2919 kfree(params.acl);
2920
Johannes Berg56d18932011-05-09 18:41:15 +02002921 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002922}
2923
Johannes Berg88600202012-02-13 15:17:18 +01002924static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2925{
2926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2927 struct net_device *dev = info->user_ptr[1];
2928 struct wireless_dev *wdev = dev->ieee80211_ptr;
2929 struct cfg80211_beacon_data params;
2930 int err;
2931
2932 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2933 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2934 return -EOPNOTSUPP;
2935
2936 if (!rdev->ops->change_beacon)
2937 return -EOPNOTSUPP;
2938
2939 if (!wdev->beacon_interval)
2940 return -EINVAL;
2941
2942 err = nl80211_parse_beacon(info, &params);
2943 if (err)
2944 return err;
2945
Hila Gonene35e4d22012-06-27 17:19:42 +03002946 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01002947}
2948
2949static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002950{
Johannes Berg4c476992010-10-04 21:36:35 +02002951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2952 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01002953
Michal Kazior60771782012-06-29 12:46:56 +02002954 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01002955}
2956
Johannes Berg5727ef12007-12-19 02:03:34 +01002957static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2958 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2959 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2960 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002961 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002962 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002963 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002964};
2965
Johannes Bergeccb8e82009-05-11 21:57:56 +03002966static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002967 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002968 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002969{
2970 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002971 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002972 int flag;
2973
Johannes Bergeccb8e82009-05-11 21:57:56 +03002974 /*
2975 * Try parsing the new attribute first so userspace
2976 * can specify both for older kernels.
2977 */
2978 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2979 if (nla) {
2980 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002981
Johannes Bergeccb8e82009-05-11 21:57:56 +03002982 sta_flags = nla_data(nla);
2983 params->sta_flags_mask = sta_flags->mask;
2984 params->sta_flags_set = sta_flags->set;
2985 if ((params->sta_flags_mask |
2986 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2987 return -EINVAL;
2988 return 0;
2989 }
2990
2991 /* if present, parse the old attribute */
2992
2993 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002994 if (!nla)
2995 return 0;
2996
2997 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2998 nla, sta_flags_policy))
2999 return -EINVAL;
3000
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003001 /*
3002 * Only allow certain flags for interface types so that
3003 * other attributes are silently ignored. Remember that
3004 * this is backward compatibility code with old userspace
3005 * and shouldn't be hit in other cases anyway.
3006 */
3007 switch (iftype) {
3008 case NL80211_IFTYPE_AP:
3009 case NL80211_IFTYPE_AP_VLAN:
3010 case NL80211_IFTYPE_P2P_GO:
3011 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3012 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3013 BIT(NL80211_STA_FLAG_WME) |
3014 BIT(NL80211_STA_FLAG_MFP);
3015 break;
3016 case NL80211_IFTYPE_P2P_CLIENT:
3017 case NL80211_IFTYPE_STATION:
3018 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3019 BIT(NL80211_STA_FLAG_TDLS_PEER);
3020 break;
3021 case NL80211_IFTYPE_MESH_POINT:
3022 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3023 BIT(NL80211_STA_FLAG_MFP) |
3024 BIT(NL80211_STA_FLAG_AUTHORIZED);
3025 default:
3026 return -EINVAL;
3027 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003028
Johannes Berg3383b5a2012-05-10 20:14:43 +02003029 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3030 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003031 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003032
Johannes Berg3383b5a2012-05-10 20:14:43 +02003033 /* no longer support new API additions in old API */
3034 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3035 return -EINVAL;
3036 }
3037 }
3038
Johannes Berg5727ef12007-12-19 02:03:34 +01003039 return 0;
3040}
3041
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003042static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3043 int attr)
3044{
3045 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003046 u32 bitrate;
3047 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003048
3049 rate = nla_nest_start(msg, attr);
3050 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003051 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003052
3053 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3054 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003055 /* report 16-bit bitrate only if we can */
3056 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003057 if (bitrate > 0 &&
3058 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3059 return false;
3060 if (bitrate_compat > 0 &&
3061 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3062 return false;
3063
3064 if (info->flags & RATE_INFO_FLAGS_MCS) {
3065 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3066 return false;
3067 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3068 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3069 return false;
3070 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3071 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3072 return false;
3073 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3074 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3075 return false;
3076 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3077 return false;
3078 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3079 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3080 return false;
3081 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3082 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3083 return false;
3084 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3085 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3086 return false;
3087 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3088 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3089 return false;
3090 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3091 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3092 return false;
3093 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003094
3095 nla_nest_end(msg, rate);
3096 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003097}
3098
Eric W. Biederman15e47302012-09-07 20:12:54 +00003099static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003100 int flags,
3101 struct cfg80211_registered_device *rdev,
3102 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003103 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003104{
3105 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003106 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003107
Eric W. Biederman15e47302012-09-07 20:12:54 +00003108 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003109 if (!hdr)
3110 return -1;
3111
David S. Miller9360ffd2012-03-29 04:41:26 -04003112 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3113 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3114 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3115 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003116
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003117 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3118 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003119 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003120 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3121 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3122 sinfo->connected_time))
3123 goto nla_put_failure;
3124 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3125 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3126 sinfo->inactive_time))
3127 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003128 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3129 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003130 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003131 (u32)sinfo->rx_bytes))
3132 goto nla_put_failure;
3133 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3134 NL80211_STA_INFO_TX_BYTES64)) &&
3135 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3136 (u32)sinfo->tx_bytes))
3137 goto nla_put_failure;
3138 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3139 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003140 sinfo->rx_bytes))
3141 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003142 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3143 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003144 sinfo->tx_bytes))
3145 goto nla_put_failure;
3146 if ((sinfo->filled & STATION_INFO_LLID) &&
3147 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3148 goto nla_put_failure;
3149 if ((sinfo->filled & STATION_INFO_PLID) &&
3150 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3151 goto nla_put_failure;
3152 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3153 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3154 sinfo->plink_state))
3155 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003156 switch (rdev->wiphy.signal_type) {
3157 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003158 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3159 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3160 sinfo->signal))
3161 goto nla_put_failure;
3162 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3163 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3164 sinfo->signal_avg))
3165 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003166 break;
3167 default:
3168 break;
3169 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003170 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003171 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3172 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003173 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003174 }
3175 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3176 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3177 NL80211_STA_INFO_RX_BITRATE))
3178 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003179 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003180 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3181 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3182 sinfo->rx_packets))
3183 goto nla_put_failure;
3184 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3185 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3186 sinfo->tx_packets))
3187 goto nla_put_failure;
3188 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3189 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3190 sinfo->tx_retries))
3191 goto nla_put_failure;
3192 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3193 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3194 sinfo->tx_failed))
3195 goto nla_put_failure;
3196 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3197 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3198 sinfo->beacon_loss_count))
3199 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003200 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3201 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3202 sinfo->local_pm))
3203 goto nla_put_failure;
3204 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3205 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3206 sinfo->peer_pm))
3207 goto nla_put_failure;
3208 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3209 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3210 sinfo->nonpeer_pm))
3211 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003212 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3213 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3214 if (!bss_param)
3215 goto nla_put_failure;
3216
David S. Miller9360ffd2012-03-29 04:41:26 -04003217 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3218 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3219 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3220 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3221 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3222 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3223 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3224 sinfo->bss_param.dtim_period) ||
3225 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3226 sinfo->bss_param.beacon_interval))
3227 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003228
3229 nla_nest_end(msg, bss_param);
3230 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003231 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3232 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3233 sizeof(struct nl80211_sta_flag_update),
3234 &sinfo->sta_flags))
3235 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003236 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3237 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3238 sinfo->t_offset))
3239 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003240 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003241
David S. Miller9360ffd2012-03-29 04:41:26 -04003242 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3243 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3244 sinfo->assoc_req_ies))
3245 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003246
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003247 return genlmsg_end(msg, hdr);
3248
3249 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003250 genlmsg_cancel(msg, hdr);
3251 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003252}
3253
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003254static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003255 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003256{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003257 struct station_info sinfo;
3258 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003259 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003260 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003261 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003262 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003263
Johannes Berg67748892010-10-04 21:14:06 +02003264 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3265 if (err)
3266 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003267
3268 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003269 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003270 goto out_err;
3271 }
3272
Johannes Bergbba95fe2008-07-29 13:22:51 +02003273 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003274 memset(&sinfo, 0, sizeof(sinfo));
Hila Gonene35e4d22012-06-27 17:19:42 +03003275 err = rdev_dump_station(dev, netdev, sta_idx,
3276 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003277 if (err == -ENOENT)
3278 break;
3279 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003280 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003281
3282 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003283 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003284 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04003285 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003286 &sinfo) < 0)
3287 goto out;
3288
3289 sta_idx++;
3290 }
3291
3292
3293 out:
3294 cb->args[1] = sta_idx;
3295 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003296 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003297 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003298
3299 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003300}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003301
Johannes Berg5727ef12007-12-19 02:03:34 +01003302static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3303{
Johannes Berg4c476992010-10-04 21:36:35 +02003304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3305 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003306 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003307 struct sk_buff *msg;
3308 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003309 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003310
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003311 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003312
3313 if (!info->attrs[NL80211_ATTR_MAC])
3314 return -EINVAL;
3315
3316 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3317
Johannes Berg4c476992010-10-04 21:36:35 +02003318 if (!rdev->ops->get_station)
3319 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003320
Hila Gonene35e4d22012-06-27 17:19:42 +03003321 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003322 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003323 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003324
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003325 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003326 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003327 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003328
Eric W. Biederman15e47302012-09-07 20:12:54 +00003329 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003330 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003331 nlmsg_free(msg);
3332 return -ENOBUFS;
3333 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003334
Johannes Berg4c476992010-10-04 21:36:35 +02003335 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003336}
3337
3338/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003339 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003340 */
Johannes Berg80b99892011-11-18 16:23:01 +01003341static struct net_device *get_vlan(struct genl_info *info,
3342 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003343{
Johannes Berg463d0182009-07-14 00:33:35 +02003344 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003345 struct net_device *v;
3346 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003347
Johannes Berg80b99892011-11-18 16:23:01 +01003348 if (!vlanattr)
3349 return NULL;
3350
3351 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3352 if (!v)
3353 return ERR_PTR(-ENODEV);
3354
3355 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3356 ret = -EINVAL;
3357 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003358 }
Johannes Berg80b99892011-11-18 16:23:01 +01003359
3360 if (!netif_running(v)) {
3361 ret = -ENETDOWN;
3362 goto error;
3363 }
3364
3365 return v;
3366 error:
3367 dev_put(v);
3368 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003369}
3370
3371static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3372{
Johannes Berg4c476992010-10-04 21:36:35 +02003373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003374 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003375 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003376 struct station_parameters params;
3377 u8 *mac_addr = NULL;
3378
3379 memset(&params, 0, sizeof(params));
3380
3381 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07003382 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01003383
3384 if (info->attrs[NL80211_ATTR_STA_AID])
3385 return -EINVAL;
3386
3387 if (!info->attrs[NL80211_ATTR_MAC])
3388 return -EINVAL;
3389
3390 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3391
3392 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3393 params.supported_rates =
3394 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3395 params.supported_rates_len =
3396 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3397 }
3398
Johannes Bergba23d202012-12-27 17:32:09 +01003399 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL] ||
3400 info->attrs[NL80211_ATTR_HT_CAPABILITY])
3401 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003402
Johannes Bergbdd90d52011-12-14 12:20:27 +01003403 if (!rdev->ops->change_station)
3404 return -EOPNOTSUPP;
3405
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003406 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003407 return -EINVAL;
3408
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003409 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3410 params.plink_action =
3411 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3412
Javier Cardona9c3990a2011-05-03 16:57:11 -07003413 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
3414 params.plink_state =
3415 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3416
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003417 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3418 enum nl80211_mesh_power_mode pm = nla_get_u32(
3419 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3420
3421 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3422 pm > NL80211_MESH_POWER_MAX)
3423 return -EINVAL;
3424
3425 params.local_pm = pm;
3426 }
3427
Johannes Berga97f4422009-06-18 17:23:43 +02003428 switch (dev->ieee80211_ptr->iftype) {
3429 case NL80211_IFTYPE_AP:
3430 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003431 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02003432 /* disallow mesh-specific things */
3433 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003434 return -EINVAL;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003435 if (params.local_pm)
3436 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003437
3438 /* TDLS can't be set, ... */
3439 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3440 return -EINVAL;
3441 /*
3442 * ... but don't bother the driver with it. This works around
3443 * a hostapd/wpa_supplicant issue -- it always includes the
3444 * TLDS_PEER flag in the mask even for AP mode.
3445 */
3446 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3447
3448 /* accept only the listed bits */
3449 if (params.sta_flags_mask &
3450 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
Johannes Bergd582cff2012-10-26 17:53:44 +02003451 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3452 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Johannes Bergbdd90d52011-12-14 12:20:27 +01003453 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3454 BIT(NL80211_STA_FLAG_WME) |
3455 BIT(NL80211_STA_FLAG_MFP)))
3456 return -EINVAL;
3457
Johannes Bergd582cff2012-10-26 17:53:44 +02003458 /* but authenticated/associated only if driver handles it */
3459 if (!(rdev->wiphy.features &
3460 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3461 params.sta_flags_mask &
3462 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3463 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3464 return -EINVAL;
3465
Johannes Bergba23d202012-12-27 17:32:09 +01003466 /* reject other things that can't change */
3467 if (params.supported_rates)
3468 return -EINVAL;
3469
Johannes Bergbdd90d52011-12-14 12:20:27 +01003470 /* must be last in here for error handling */
3471 params.vlan = get_vlan(info, rdev);
3472 if (IS_ERR(params.vlan))
3473 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02003474 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02003475 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003476 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003477 /*
3478 * Don't allow userspace to change the TDLS_PEER flag,
3479 * but silently ignore attempts to change it since we
3480 * don't have state here to verify that it doesn't try
3481 * to change the flag.
3482 */
3483 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01003484 /* fall through */
3485 case NL80211_IFTYPE_ADHOC:
3486 /* disallow things sta doesn't support */
3487 if (params.plink_action)
3488 return -EINVAL;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003489 if (params.local_pm)
3490 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003491 /* reject any changes other than AUTHORIZED */
3492 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3493 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003494 break;
3495 case NL80211_IFTYPE_MESH_POINT:
3496 /* disallow things mesh doesn't support */
3497 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003498 return -EINVAL;
Johannes Bergba23d202012-12-27 17:32:09 +01003499 if (params.supported_rates)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003500 return -EINVAL;
3501 /*
3502 * No special handling for TDLS here -- the userspace
3503 * mesh code doesn't have this bug.
3504 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003505 if (params.sta_flags_mask &
3506 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003507 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003508 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003509 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003510 break;
3511 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003512 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003513 }
3514
Johannes Bergbdd90d52011-12-14 12:20:27 +01003515 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003516
Hila Gonene35e4d22012-06-27 17:19:42 +03003517 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003518
Johannes Berg5727ef12007-12-19 02:03:34 +01003519 if (params.vlan)
3520 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003521
Johannes Berg5727ef12007-12-19 02:03:34 +01003522 return err;
3523}
3524
Eliad Pellerc75786c2011-08-23 14:37:46 +03003525static struct nla_policy
3526nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3527 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3528 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3529};
3530
Johannes Berg5727ef12007-12-19 02:03:34 +01003531static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3532{
Johannes Berg4c476992010-10-04 21:36:35 +02003533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003534 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003535 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003536 struct station_parameters params;
3537 u8 *mac_addr = NULL;
3538
3539 memset(&params, 0, sizeof(params));
3540
3541 if (!info->attrs[NL80211_ATTR_MAC])
3542 return -EINVAL;
3543
Johannes Berg5727ef12007-12-19 02:03:34 +01003544 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3545 return -EINVAL;
3546
3547 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3548 return -EINVAL;
3549
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003550 if (!info->attrs[NL80211_ATTR_STA_AID])
3551 return -EINVAL;
3552
Johannes Berg5727ef12007-12-19 02:03:34 +01003553 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3554 params.supported_rates =
3555 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3556 params.supported_rates_len =
3557 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3558 params.listen_interval =
3559 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003560
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003561 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3562 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3563 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003564
Jouni Malinen36aedc92008-08-25 11:58:58 +03003565 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3566 params.ht_capa =
3567 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003568
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003569 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3570 params.vht_capa =
3571 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3572
Javier Cardona96b78df2011-04-07 15:08:33 -07003573 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3574 params.plink_action =
3575 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3576
Johannes Bergbdd90d52011-12-14 12:20:27 +01003577 if (!rdev->ops->add_station)
3578 return -EOPNOTSUPP;
3579
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003580 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003581 return -EINVAL;
3582
Johannes Bergbdd90d52011-12-14 12:20:27 +01003583 switch (dev->ieee80211_ptr->iftype) {
3584 case NL80211_IFTYPE_AP:
3585 case NL80211_IFTYPE_AP_VLAN:
3586 case NL80211_IFTYPE_P2P_GO:
3587 /* parse WME attributes if sta is WME capable */
3588 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3589 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3590 info->attrs[NL80211_ATTR_STA_WME]) {
3591 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3592 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003593
Johannes Bergbdd90d52011-12-14 12:20:27 +01003594 nla = info->attrs[NL80211_ATTR_STA_WME];
3595 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3596 nl80211_sta_wme_policy);
3597 if (err)
3598 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003599
Johannes Bergbdd90d52011-12-14 12:20:27 +01003600 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3601 params.uapsd_queues =
3602 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3603 if (params.uapsd_queues &
3604 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3605 return -EINVAL;
3606
3607 if (tb[NL80211_STA_WME_MAX_SP])
3608 params.max_sp =
3609 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3610
3611 if (params.max_sp &
3612 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3613 return -EINVAL;
3614
3615 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3616 }
3617 /* TDLS peers cannot be added */
3618 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003619 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003620 /* but don't bother the driver with it */
3621 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003622
Johannes Bergd582cff2012-10-26 17:53:44 +02003623 /* allow authenticated/associated only if driver handles it */
3624 if (!(rdev->wiphy.features &
3625 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3626 params.sta_flags_mask &
3627 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3628 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3629 return -EINVAL;
3630
Johannes Bergbdd90d52011-12-14 12:20:27 +01003631 /* must be last in here for error handling */
3632 params.vlan = get_vlan(info, rdev);
3633 if (IS_ERR(params.vlan))
3634 return PTR_ERR(params.vlan);
3635 break;
3636 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergd582cff2012-10-26 17:53:44 +02003637 /* associated is disallowed */
3638 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3639 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003640 /* TDLS peers cannot be added */
3641 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003642 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003643 break;
3644 case NL80211_IFTYPE_STATION:
Johannes Bergd582cff2012-10-26 17:53:44 +02003645 /* associated is disallowed */
3646 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3647 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003648 /* Only TDLS peers can be added */
3649 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3650 return -EINVAL;
3651 /* Can only add if TDLS ... */
3652 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3653 return -EOPNOTSUPP;
3654 /* ... with external setup is supported */
3655 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3656 return -EOPNOTSUPP;
3657 break;
3658 default:
3659 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003660 }
3661
Johannes Bergbdd90d52011-12-14 12:20:27 +01003662 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003663
Hila Gonene35e4d22012-06-27 17:19:42 +03003664 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003665
Johannes Berg5727ef12007-12-19 02:03:34 +01003666 if (params.vlan)
3667 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003668 return err;
3669}
3670
3671static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3672{
Johannes Berg4c476992010-10-04 21:36:35 +02003673 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3674 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003675 u8 *mac_addr = NULL;
3676
3677 if (info->attrs[NL80211_ATTR_MAC])
3678 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3679
Johannes Berge80cf852009-05-11 14:43:13 +02003680 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003681 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003682 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003683 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3684 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003685
Johannes Berg4c476992010-10-04 21:36:35 +02003686 if (!rdev->ops->del_station)
3687 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003688
Hila Gonene35e4d22012-06-27 17:19:42 +03003689 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003690}
3691
Eric W. Biederman15e47302012-09-07 20:12:54 +00003692static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003693 int flags, struct net_device *dev,
3694 u8 *dst, u8 *next_hop,
3695 struct mpath_info *pinfo)
3696{
3697 void *hdr;
3698 struct nlattr *pinfoattr;
3699
Eric W. Biederman15e47302012-09-07 20:12:54 +00003700 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003701 if (!hdr)
3702 return -1;
3703
David S. Miller9360ffd2012-03-29 04:41:26 -04003704 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3705 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3706 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3707 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3708 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003709
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003710 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3711 if (!pinfoattr)
3712 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003713 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3714 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3715 pinfo->frame_qlen))
3716 goto nla_put_failure;
3717 if (((pinfo->filled & MPATH_INFO_SN) &&
3718 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3719 ((pinfo->filled & MPATH_INFO_METRIC) &&
3720 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3721 pinfo->metric)) ||
3722 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3723 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3724 pinfo->exptime)) ||
3725 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3726 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3727 pinfo->flags)) ||
3728 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3729 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3730 pinfo->discovery_timeout)) ||
3731 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3732 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3733 pinfo->discovery_retries)))
3734 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003735
3736 nla_nest_end(msg, pinfoattr);
3737
3738 return genlmsg_end(msg, hdr);
3739
3740 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003741 genlmsg_cancel(msg, hdr);
3742 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003743}
3744
3745static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003746 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003747{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003748 struct mpath_info pinfo;
3749 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003750 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003751 u8 dst[ETH_ALEN];
3752 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003753 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003754 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003755
Johannes Berg67748892010-10-04 21:14:06 +02003756 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3757 if (err)
3758 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003759
3760 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003761 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003762 goto out_err;
3763 }
3764
Jouni Malineneec60b02009-03-20 21:21:19 +02003765 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3766 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003767 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003768 }
3769
Johannes Bergbba95fe2008-07-29 13:22:51 +02003770 while (1) {
Hila Gonene35e4d22012-06-27 17:19:42 +03003771 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
3772 &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003773 if (err == -ENOENT)
3774 break;
3775 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003776 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003777
Eric W. Biederman15e47302012-09-07 20:12:54 +00003778 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003779 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3780 netdev, dst, next_hop,
3781 &pinfo) < 0)
3782 goto out;
3783
3784 path_idx++;
3785 }
3786
3787
3788 out:
3789 cb->args[1] = path_idx;
3790 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003791 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003792 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003793 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003794}
3795
3796static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3797{
Johannes Berg4c476992010-10-04 21:36:35 +02003798 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003799 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003800 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003801 struct mpath_info pinfo;
3802 struct sk_buff *msg;
3803 u8 *dst = NULL;
3804 u8 next_hop[ETH_ALEN];
3805
3806 memset(&pinfo, 0, sizeof(pinfo));
3807
3808 if (!info->attrs[NL80211_ATTR_MAC])
3809 return -EINVAL;
3810
3811 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3812
Johannes Berg4c476992010-10-04 21:36:35 +02003813 if (!rdev->ops->get_mpath)
3814 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003815
Johannes Berg4c476992010-10-04 21:36:35 +02003816 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3817 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003818
Hila Gonene35e4d22012-06-27 17:19:42 +03003819 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003820 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003821 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003822
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003823 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003824 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003825 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003826
Eric W. Biederman15e47302012-09-07 20:12:54 +00003827 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003828 dev, dst, next_hop, &pinfo) < 0) {
3829 nlmsg_free(msg);
3830 return -ENOBUFS;
3831 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003832
Johannes Berg4c476992010-10-04 21:36:35 +02003833 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003834}
3835
3836static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3837{
Johannes Berg4c476992010-10-04 21:36:35 +02003838 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3839 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003840 u8 *dst = NULL;
3841 u8 *next_hop = NULL;
3842
3843 if (!info->attrs[NL80211_ATTR_MAC])
3844 return -EINVAL;
3845
3846 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3847 return -EINVAL;
3848
3849 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3850 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3851
Johannes Berg4c476992010-10-04 21:36:35 +02003852 if (!rdev->ops->change_mpath)
3853 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003854
Johannes Berg4c476992010-10-04 21:36:35 +02003855 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3856 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003857
Hila Gonene35e4d22012-06-27 17:19:42 +03003858 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003859}
Johannes Berg4c476992010-10-04 21:36:35 +02003860
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003861static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3862{
Johannes Berg4c476992010-10-04 21:36:35 +02003863 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3864 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003865 u8 *dst = NULL;
3866 u8 *next_hop = NULL;
3867
3868 if (!info->attrs[NL80211_ATTR_MAC])
3869 return -EINVAL;
3870
3871 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3872 return -EINVAL;
3873
3874 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3875 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3876
Johannes Berg4c476992010-10-04 21:36:35 +02003877 if (!rdev->ops->add_mpath)
3878 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003879
Johannes Berg4c476992010-10-04 21:36:35 +02003880 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3881 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003882
Hila Gonene35e4d22012-06-27 17:19:42 +03003883 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003884}
3885
3886static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3887{
Johannes Berg4c476992010-10-04 21:36:35 +02003888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3889 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003890 u8 *dst = NULL;
3891
3892 if (info->attrs[NL80211_ATTR_MAC])
3893 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3894
Johannes Berg4c476992010-10-04 21:36:35 +02003895 if (!rdev->ops->del_mpath)
3896 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003897
Hila Gonene35e4d22012-06-27 17:19:42 +03003898 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003899}
3900
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003901static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3902{
Johannes Berg4c476992010-10-04 21:36:35 +02003903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3904 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003905 struct bss_parameters params;
3906
3907 memset(&params, 0, sizeof(params));
3908 /* default to not changing parameters */
3909 params.use_cts_prot = -1;
3910 params.use_short_preamble = -1;
3911 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003912 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003913 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01003914 params.p2p_ctwindow = -1;
3915 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003916
3917 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3918 params.use_cts_prot =
3919 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3920 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3921 params.use_short_preamble =
3922 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3923 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3924 params.use_short_slot_time =
3925 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003926 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3927 params.basic_rates =
3928 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3929 params.basic_rates_len =
3930 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3931 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003932 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3933 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003934 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3935 params.ht_opmode =
3936 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003937
Johannes Berg53cabad2012-11-14 15:17:28 +01003938 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3939 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3940 return -EINVAL;
3941 params.p2p_ctwindow =
3942 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3943 if (params.p2p_ctwindow < 0)
3944 return -EINVAL;
3945 if (params.p2p_ctwindow != 0 &&
3946 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3947 return -EINVAL;
3948 }
3949
3950 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3951 u8 tmp;
3952
3953 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3954 return -EINVAL;
3955 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3956 if (tmp > 1)
3957 return -EINVAL;
3958 params.p2p_opp_ps = tmp;
3959 if (params.p2p_opp_ps &&
3960 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3961 return -EINVAL;
3962 }
3963
Johannes Berg4c476992010-10-04 21:36:35 +02003964 if (!rdev->ops->change_bss)
3965 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003966
Johannes Berg074ac8d2010-09-16 14:58:22 +02003967 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003968 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3969 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003970
Hila Gonene35e4d22012-06-27 17:19:42 +03003971 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003972}
3973
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003974static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003975 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3976 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3977 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3978 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3979 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3980 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3981};
3982
3983static int parse_reg_rule(struct nlattr *tb[],
3984 struct ieee80211_reg_rule *reg_rule)
3985{
3986 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3987 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3988
3989 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3990 return -EINVAL;
3991 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3992 return -EINVAL;
3993 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3994 return -EINVAL;
3995 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3996 return -EINVAL;
3997 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3998 return -EINVAL;
3999
4000 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4001
4002 freq_range->start_freq_khz =
4003 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4004 freq_range->end_freq_khz =
4005 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4006 freq_range->max_bandwidth_khz =
4007 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4008
4009 power_rule->max_eirp =
4010 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4011
4012 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4013 power_rule->max_antenna_gain =
4014 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4015
4016 return 0;
4017}
4018
4019static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4020{
4021 int r;
4022 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004023 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004024
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004025 /*
4026 * You should only get this when cfg80211 hasn't yet initialized
4027 * completely when built-in to the kernel right between the time
4028 * window between nl80211_init() and regulatory_init(), if that is
4029 * even possible.
4030 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004031 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004032 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004033
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004034 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4035 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004036
4037 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4038
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004039 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4040 user_reg_hint_type =
4041 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4042 else
4043 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4044
4045 switch (user_reg_hint_type) {
4046 case NL80211_USER_REG_HINT_USER:
4047 case NL80211_USER_REG_HINT_CELL_BASE:
4048 break;
4049 default:
4050 return -EINVAL;
4051 }
4052
4053 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004054
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004055 return r;
4056}
4057
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004058static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004059 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004060{
Johannes Berg4c476992010-10-04 21:36:35 +02004061 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004062 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004063 struct wireless_dev *wdev = dev->ieee80211_ptr;
4064 struct mesh_config cur_params;
4065 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004066 void *hdr;
4067 struct nlattr *pinfoattr;
4068 struct sk_buff *msg;
4069
Johannes Berg29cbe682010-12-03 09:20:44 +01004070 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4071 return -EOPNOTSUPP;
4072
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004073 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004074 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004075
Johannes Berg29cbe682010-12-03 09:20:44 +01004076 wdev_lock(wdev);
4077 /* If not connected, get default parameters */
4078 if (!wdev->mesh_id_len)
4079 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4080 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004081 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004082 wdev_unlock(wdev);
4083
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004084 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004085 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004086
4087 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004088 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004089 if (!msg)
4090 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004091 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004092 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004093 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004094 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004095 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004096 if (!pinfoattr)
4097 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004098 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4099 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4100 cur_params.dot11MeshRetryTimeout) ||
4101 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4102 cur_params.dot11MeshConfirmTimeout) ||
4103 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4104 cur_params.dot11MeshHoldingTimeout) ||
4105 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4106 cur_params.dot11MeshMaxPeerLinks) ||
4107 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4108 cur_params.dot11MeshMaxRetries) ||
4109 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4110 cur_params.dot11MeshTTL) ||
4111 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4112 cur_params.element_ttl) ||
4113 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4114 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004115 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4116 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004117 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4118 cur_params.dot11MeshHWMPmaxPREQretries) ||
4119 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4120 cur_params.path_refresh_time) ||
4121 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4122 cur_params.min_discovery_timeout) ||
4123 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4124 cur_params.dot11MeshHWMPactivePathTimeout) ||
4125 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4126 cur_params.dot11MeshHWMPpreqMinInterval) ||
4127 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4128 cur_params.dot11MeshHWMPperrMinInterval) ||
4129 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4130 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4131 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4132 cur_params.dot11MeshHWMPRootMode) ||
4133 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4134 cur_params.dot11MeshHWMPRannInterval) ||
4135 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4136 cur_params.dot11MeshGateAnnouncementProtocol) ||
4137 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4138 cur_params.dot11MeshForwarding) ||
4139 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004140 cur_params.rssi_threshold) ||
4141 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004142 cur_params.ht_opmode) ||
4143 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4144 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4145 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004146 cur_params.dot11MeshHWMProotInterval) ||
4147 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004148 cur_params.dot11MeshHWMPconfirmationInterval) ||
4149 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4150 cur_params.power_mode) ||
4151 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4152 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004153 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004154 nla_nest_end(msg, pinfoattr);
4155 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004156 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004157
Johannes Berg3b858752009-03-12 09:55:09 +01004158 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004159 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004160 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004161 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004162 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004163}
4164
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004165static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004166 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4167 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4168 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4169 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4170 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4171 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004172 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004173 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004174 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004175 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4176 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4177 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4178 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4179 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004180 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004181 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004182 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004183 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004184 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004185 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004186 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4187 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004188 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4189 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004190 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004191 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4192 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004193};
4194
Javier Cardonac80d5452010-12-16 17:37:49 -08004195static const struct nla_policy
4196 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004197 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004198 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4199 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004200 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004201 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004202 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004203 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004204};
4205
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004206static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004207 struct mesh_config *cfg,
4208 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004209{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004210 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004211 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004212
Marco Porschea54fba2013-01-07 16:04:48 +01004213#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4214do { \
4215 if (tb[attr]) { \
4216 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4217 return -EINVAL; \
4218 cfg->param = fn(tb[attr]); \
4219 mask |= (1 << (attr - 1)); \
4220 } \
4221} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004222
4223
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004224 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004225 return -EINVAL;
4226 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004227 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004228 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004229 return -EINVAL;
4230
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004231 /* This makes sure that there aren't more than 32 mesh config
4232 * parameters (otherwise our bitfield scheme would not work.) */
4233 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4234
4235 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004236 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004237 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4238 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004239 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004240 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4241 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004242 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004243 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4244 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004245 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004246 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4247 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004248 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004249 mask, NL80211_MESHCONF_MAX_RETRIES,
4250 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004251 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004252 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004253 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004254 mask, NL80211_MESHCONF_ELEMENT_TTL,
4255 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004256 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004257 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4258 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004259 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4260 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004261 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4262 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004263 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004264 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4265 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004266 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004267 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4268 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004269 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004270 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4271 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004272 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4273 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004274 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4275 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004276 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004277 1, 65535, mask,
4278 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004279 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004280 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004281 1, 65535, mask,
4282 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004283 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004284 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004285 dot11MeshHWMPnetDiameterTraversalTime,
4286 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004287 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4288 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004289 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4290 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4291 nla_get_u8);
4292 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4293 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004294 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004295 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004296 dot11MeshGateAnnouncementProtocol, 0, 1,
4297 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004298 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004299 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004300 mask, NL80211_MESHCONF_FORWARDING,
4301 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004302 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004303 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4304 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004305 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004306 mask, NL80211_MESHCONF_HT_OPMODE,
4307 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004308 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004309 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004310 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4311 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004312 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004313 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4314 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004315 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004316 dot11MeshHWMPconfirmationInterval,
4317 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004318 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4319 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004320 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4321 NL80211_MESH_POWER_ACTIVE,
4322 NL80211_MESH_POWER_MAX,
4323 mask, NL80211_MESHCONF_POWER_MODE,
4324 nla_get_u32);
4325 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4326 0, 65535, mask,
4327 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004328 if (mask_out)
4329 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004330
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004331 return 0;
4332
4333#undef FILL_IN_MESH_PARAM_IF_SET
4334}
4335
Javier Cardonac80d5452010-12-16 17:37:49 -08004336static int nl80211_parse_mesh_setup(struct genl_info *info,
4337 struct mesh_setup *setup)
4338{
4339 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4340
4341 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4342 return -EINVAL;
4343 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4344 info->attrs[NL80211_ATTR_MESH_SETUP],
4345 nl80211_mesh_setup_params_policy))
4346 return -EINVAL;
4347
Javier Cardonad299a1f2012-03-31 11:31:33 -07004348 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4349 setup->sync_method =
4350 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4351 IEEE80211_SYNC_METHOD_VENDOR :
4352 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4353
Javier Cardonac80d5452010-12-16 17:37:49 -08004354 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4355 setup->path_sel_proto =
4356 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4357 IEEE80211_PATH_PROTOCOL_VENDOR :
4358 IEEE80211_PATH_PROTOCOL_HWMP;
4359
4360 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4361 setup->path_metric =
4362 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4363 IEEE80211_PATH_METRIC_VENDOR :
4364 IEEE80211_PATH_METRIC_AIRTIME;
4365
Javier Cardona581a8b02011-04-07 15:08:27 -07004366
4367 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004368 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004369 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004370 if (!is_valid_ie_attr(ieattr))
4371 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004372 setup->ie = nla_data(ieattr);
4373 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004374 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07004375 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4376 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08004377
4378 return 0;
4379}
4380
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004381static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004382 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004383{
4384 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4385 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004386 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004387 struct mesh_config cfg;
4388 u32 mask;
4389 int err;
4390
Johannes Berg29cbe682010-12-03 09:20:44 +01004391 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4392 return -EOPNOTSUPP;
4393
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004394 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004395 return -EOPNOTSUPP;
4396
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004397 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004398 if (err)
4399 return err;
4400
Johannes Berg29cbe682010-12-03 09:20:44 +01004401 wdev_lock(wdev);
4402 if (!wdev->mesh_id_len)
4403 err = -ENOLINK;
4404
4405 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004406 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004407
4408 wdev_unlock(wdev);
4409
4410 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004411}
4412
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004413static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4414{
Johannes Berg458f4f92012-12-06 15:47:38 +01004415 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004416 struct sk_buff *msg;
4417 void *hdr = NULL;
4418 struct nlattr *nl_reg_rules;
4419 unsigned int i;
4420 int err = -EINVAL;
4421
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004422 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004423
4424 if (!cfg80211_regdomain)
4425 goto out;
4426
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004428 if (!msg) {
4429 err = -ENOBUFS;
4430 goto out;
4431 }
4432
Eric W. Biederman15e47302012-09-07 20:12:54 +00004433 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004434 NL80211_CMD_GET_REG);
4435 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004436 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004437
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004438 if (reg_last_request_cell_base() &&
4439 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4440 NL80211_USER_REG_HINT_CELL_BASE))
4441 goto nla_put_failure;
4442
Johannes Berg458f4f92012-12-06 15:47:38 +01004443 rcu_read_lock();
4444 regdom = rcu_dereference(cfg80211_regdomain);
4445
4446 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4447 (regdom->dfs_region &&
4448 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4449 goto nla_put_failure_rcu;
4450
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004451 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4452 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004453 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004454
Johannes Berg458f4f92012-12-06 15:47:38 +01004455 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004456 struct nlattr *nl_reg_rule;
4457 const struct ieee80211_reg_rule *reg_rule;
4458 const struct ieee80211_freq_range *freq_range;
4459 const struct ieee80211_power_rule *power_rule;
4460
Johannes Berg458f4f92012-12-06 15:47:38 +01004461 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004462 freq_range = &reg_rule->freq_range;
4463 power_rule = &reg_rule->power_rule;
4464
4465 nl_reg_rule = nla_nest_start(msg, i);
4466 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004467 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004468
David S. Miller9360ffd2012-03-29 04:41:26 -04004469 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4470 reg_rule->flags) ||
4471 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4472 freq_range->start_freq_khz) ||
4473 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4474 freq_range->end_freq_khz) ||
4475 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4476 freq_range->max_bandwidth_khz) ||
4477 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4478 power_rule->max_antenna_gain) ||
4479 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4480 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004481 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004482
4483 nla_nest_end(msg, nl_reg_rule);
4484 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004485 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004486
4487 nla_nest_end(msg, nl_reg_rules);
4488
4489 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004490 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004491 goto out;
4492
Johannes Berg458f4f92012-12-06 15:47:38 +01004493nla_put_failure_rcu:
4494 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004495nla_put_failure:
4496 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004497put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004498 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004499 err = -EMSGSIZE;
4500out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004501 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004502 return err;
4503}
4504
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004505static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4506{
4507 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4508 struct nlattr *nl_reg_rule;
4509 char *alpha2 = NULL;
4510 int rem_reg_rules = 0, r = 0;
4511 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004512 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004513 struct ieee80211_regdomain *rd = NULL;
4514
4515 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4516 return -EINVAL;
4517
4518 if (!info->attrs[NL80211_ATTR_REG_RULES])
4519 return -EINVAL;
4520
4521 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4522
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004523 if (info->attrs[NL80211_ATTR_DFS_REGION])
4524 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4525
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004526 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004527 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004528 num_rules++;
4529 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004530 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004531 }
4532
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004533 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004534 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004535
4536 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004537 if (!rd)
4538 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004539
4540 rd->n_reg_rules = num_rules;
4541 rd->alpha2[0] = alpha2[0];
4542 rd->alpha2[1] = alpha2[1];
4543
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004544 /*
4545 * Disable DFS master mode if the DFS region was
4546 * not supported or known on this kernel.
4547 */
4548 if (reg_supported_dfs_region(dfs_region))
4549 rd->dfs_region = dfs_region;
4550
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004551 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004552 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004553 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004554 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4555 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004556 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4557 if (r)
4558 goto bad_reg;
4559
4560 rule_idx++;
4561
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004562 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4563 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004564 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004565 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004566 }
4567
Johannes Berg6913b492012-12-04 00:48:59 +01004568 mutex_lock(&cfg80211_mutex);
4569
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004570 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01004571 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01004572 rd = NULL;
Johannes Berg6913b492012-12-04 00:48:59 +01004573 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004574
Johannes Bergd2372b32008-10-24 20:32:20 +02004575 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004576 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004577 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004578}
4579
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004580static int validate_scan_freqs(struct nlattr *freqs)
4581{
4582 struct nlattr *attr1, *attr2;
4583 int n_channels = 0, tmp1, tmp2;
4584
4585 nla_for_each_nested(attr1, freqs, tmp1) {
4586 n_channels++;
4587 /*
4588 * Some hardware has a limited channel list for
4589 * scanning, and it is pretty much nonsensical
4590 * to scan for a channel twice, so disallow that
4591 * and don't require drivers to check that the
4592 * channel list they get isn't longer than what
4593 * they can scan, as long as they can scan all
4594 * the channels they registered at once.
4595 */
4596 nla_for_each_nested(attr2, freqs, tmp2)
4597 if (attr1 != attr2 &&
4598 nla_get_u32(attr1) == nla_get_u32(attr2))
4599 return 0;
4600 }
4601
4602 return n_channels;
4603}
4604
Johannes Berg2a519312009-02-10 21:25:55 +01004605static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4606{
Johannes Berg4c476992010-10-04 21:36:35 +02004607 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02004608 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004609 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004610 struct nlattr *attr;
4611 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004612 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004613 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004614
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004615 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4616 return -EINVAL;
4617
Johannes Berg79c97e92009-07-07 03:56:12 +02004618 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004619
Johannes Berg4c476992010-10-04 21:36:35 +02004620 if (!rdev->ops->scan)
4621 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004622
Johannes Berg4c476992010-10-04 21:36:35 +02004623 if (rdev->scan_req)
4624 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004625
4626 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004627 n_channels = validate_scan_freqs(
4628 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004629 if (!n_channels)
4630 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004631 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004632 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004633 n_channels = 0;
4634
Johannes Berg2a519312009-02-10 21:25:55 +01004635 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4636 if (wiphy->bands[band])
4637 n_channels += wiphy->bands[band]->n_channels;
4638 }
4639
4640 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4641 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4642 n_ssids++;
4643
Johannes Berg4c476992010-10-04 21:36:35 +02004644 if (n_ssids > wiphy->max_scan_ssids)
4645 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004646
Jouni Malinen70692ad2009-02-16 19:39:13 +02004647 if (info->attrs[NL80211_ATTR_IE])
4648 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4649 else
4650 ie_len = 0;
4651
Johannes Berg4c476992010-10-04 21:36:35 +02004652 if (ie_len > wiphy->max_scan_ie_len)
4653 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004654
Johannes Berg2a519312009-02-10 21:25:55 +01004655 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004656 + sizeof(*request->ssids) * n_ssids
4657 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004658 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004659 if (!request)
4660 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004661
Johannes Berg2a519312009-02-10 21:25:55 +01004662 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004663 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004664 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004665 if (ie_len) {
4666 if (request->ssids)
4667 request->ie = (void *)(request->ssids + n_ssids);
4668 else
4669 request->ie = (void *)(request->channels + n_channels);
4670 }
Johannes Berg2a519312009-02-10 21:25:55 +01004671
Johannes Berg584991d2009-11-02 13:32:03 +01004672 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004673 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4674 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004675 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004676 struct ieee80211_channel *chan;
4677
4678 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4679
4680 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004681 err = -EINVAL;
4682 goto out_free;
4683 }
Johannes Berg584991d2009-11-02 13:32:03 +01004684
4685 /* ignore disabled channels */
4686 if (chan->flags & IEEE80211_CHAN_DISABLED)
4687 continue;
4688
4689 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004690 i++;
4691 }
4692 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004693 enum ieee80211_band band;
4694
Johannes Berg2a519312009-02-10 21:25:55 +01004695 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004696 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4697 int j;
4698 if (!wiphy->bands[band])
4699 continue;
4700 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004701 struct ieee80211_channel *chan;
4702
4703 chan = &wiphy->bands[band]->channels[j];
4704
4705 if (chan->flags & IEEE80211_CHAN_DISABLED)
4706 continue;
4707
4708 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004709 i++;
4710 }
4711 }
4712 }
4713
Johannes Berg584991d2009-11-02 13:32:03 +01004714 if (!i) {
4715 err = -EINVAL;
4716 goto out_free;
4717 }
4718
4719 request->n_channels = i;
4720
Johannes Berg2a519312009-02-10 21:25:55 +01004721 i = 0;
4722 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4723 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004724 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004725 err = -EINVAL;
4726 goto out_free;
4727 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004728 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004729 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004730 i++;
4731 }
4732 }
4733
Jouni Malinen70692ad2009-02-16 19:39:13 +02004734 if (info->attrs[NL80211_ATTR_IE]) {
4735 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004736 memcpy((void *)request->ie,
4737 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004738 request->ie_len);
4739 }
4740
Johannes Berg34850ab2011-07-18 18:08:35 +02004741 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004742 if (wiphy->bands[i])
4743 request->rates[i] =
4744 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004745
4746 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4747 nla_for_each_nested(attr,
4748 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4749 tmp) {
4750 enum ieee80211_band band = nla_type(attr);
4751
Dan Carpenter84404622011-07-29 11:52:18 +03004752 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004753 err = -EINVAL;
4754 goto out_free;
4755 }
4756 err = ieee80211_get_ratemask(wiphy->bands[band],
4757 nla_data(attr),
4758 nla_len(attr),
4759 &request->rates[band]);
4760 if (err)
4761 goto out_free;
4762 }
4763 }
4764
Sam Leffler46856bb2012-10-11 21:03:32 -07004765 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07004766 request->flags = nla_get_u32(
4767 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07004768 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
4769 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
4770 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
4771 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07004772 err = -EOPNOTSUPP;
4773 goto out_free;
4774 }
4775 }
Sam Lefflered4737712012-10-11 21:03:31 -07004776
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304777 request->no_cck =
4778 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4779
Johannes Bergfd014282012-06-18 19:17:03 +02004780 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004781 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07004782 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01004783
Johannes Berg79c97e92009-07-07 03:56:12 +02004784 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03004785 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004786
Johannes Berg463d0182009-07-14 00:33:35 +02004787 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02004788 nl80211_send_scan_start(rdev, wdev);
4789 if (wdev->netdev)
4790 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02004791 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004792 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004793 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004794 kfree(request);
4795 }
Johannes Berg3b858752009-03-12 09:55:09 +01004796
Johannes Berg2a519312009-02-10 21:25:55 +01004797 return err;
4798}
4799
Luciano Coelho807f8a82011-05-11 17:09:35 +03004800static int nl80211_start_sched_scan(struct sk_buff *skb,
4801 struct genl_info *info)
4802{
4803 struct cfg80211_sched_scan_request *request;
4804 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4805 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004806 struct nlattr *attr;
4807 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004808 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004809 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004810 enum ieee80211_band band;
4811 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004812 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004813
4814 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4815 !rdev->ops->sched_scan_start)
4816 return -EOPNOTSUPP;
4817
4818 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4819 return -EINVAL;
4820
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004821 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4822 return -EINVAL;
4823
4824 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4825 if (interval == 0)
4826 return -EINVAL;
4827
Luciano Coelho807f8a82011-05-11 17:09:35 +03004828 wiphy = &rdev->wiphy;
4829
4830 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4831 n_channels = validate_scan_freqs(
4832 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4833 if (!n_channels)
4834 return -EINVAL;
4835 } else {
4836 n_channels = 0;
4837
4838 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4839 if (wiphy->bands[band])
4840 n_channels += wiphy->bands[band]->n_channels;
4841 }
4842
4843 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4844 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4845 tmp)
4846 n_ssids++;
4847
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004848 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004849 return -EINVAL;
4850
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004851 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4852 nla_for_each_nested(attr,
4853 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4854 tmp)
4855 n_match_sets++;
4856
4857 if (n_match_sets > wiphy->max_match_sets)
4858 return -EINVAL;
4859
Luciano Coelho807f8a82011-05-11 17:09:35 +03004860 if (info->attrs[NL80211_ATTR_IE])
4861 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4862 else
4863 ie_len = 0;
4864
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004865 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004866 return -EINVAL;
4867
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004868 mutex_lock(&rdev->sched_scan_mtx);
4869
4870 if (rdev->sched_scan_req) {
4871 err = -EINPROGRESS;
4872 goto out;
4873 }
4874
Luciano Coelho807f8a82011-05-11 17:09:35 +03004875 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004876 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004877 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004878 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004879 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004880 if (!request) {
4881 err = -ENOMEM;
4882 goto out;
4883 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004884
4885 if (n_ssids)
4886 request->ssids = (void *)&request->channels[n_channels];
4887 request->n_ssids = n_ssids;
4888 if (ie_len) {
4889 if (request->ssids)
4890 request->ie = (void *)(request->ssids + n_ssids);
4891 else
4892 request->ie = (void *)(request->channels + n_channels);
4893 }
4894
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004895 if (n_match_sets) {
4896 if (request->ie)
4897 request->match_sets = (void *)(request->ie + ie_len);
4898 else if (request->ssids)
4899 request->match_sets =
4900 (void *)(request->ssids + n_ssids);
4901 else
4902 request->match_sets =
4903 (void *)(request->channels + n_channels);
4904 }
4905 request->n_match_sets = n_match_sets;
4906
Luciano Coelho807f8a82011-05-11 17:09:35 +03004907 i = 0;
4908 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4909 /* user specified, bail out if channel not found */
4910 nla_for_each_nested(attr,
4911 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4912 tmp) {
4913 struct ieee80211_channel *chan;
4914
4915 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4916
4917 if (!chan) {
4918 err = -EINVAL;
4919 goto out_free;
4920 }
4921
4922 /* ignore disabled channels */
4923 if (chan->flags & IEEE80211_CHAN_DISABLED)
4924 continue;
4925
4926 request->channels[i] = chan;
4927 i++;
4928 }
4929 } else {
4930 /* all channels */
4931 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4932 int j;
4933 if (!wiphy->bands[band])
4934 continue;
4935 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4936 struct ieee80211_channel *chan;
4937
4938 chan = &wiphy->bands[band]->channels[j];
4939
4940 if (chan->flags & IEEE80211_CHAN_DISABLED)
4941 continue;
4942
4943 request->channels[i] = chan;
4944 i++;
4945 }
4946 }
4947 }
4948
4949 if (!i) {
4950 err = -EINVAL;
4951 goto out_free;
4952 }
4953
4954 request->n_channels = i;
4955
4956 i = 0;
4957 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4958 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4959 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004960 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004961 err = -EINVAL;
4962 goto out_free;
4963 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004964 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004965 memcpy(request->ssids[i].ssid, nla_data(attr),
4966 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004967 i++;
4968 }
4969 }
4970
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004971 i = 0;
4972 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4973 nla_for_each_nested(attr,
4974 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4975 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004976 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004977
4978 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4979 nla_data(attr), nla_len(attr),
4980 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004981 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004982 if (ssid) {
4983 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4984 err = -EINVAL;
4985 goto out_free;
4986 }
4987 memcpy(request->match_sets[i].ssid.ssid,
4988 nla_data(ssid), nla_len(ssid));
4989 request->match_sets[i].ssid.ssid_len =
4990 nla_len(ssid);
4991 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004992 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4993 if (rssi)
4994 request->rssi_thold = nla_get_u32(rssi);
4995 else
4996 request->rssi_thold =
4997 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004998 i++;
4999 }
5000 }
5001
Luciano Coelho807f8a82011-05-11 17:09:35 +03005002 if (info->attrs[NL80211_ATTR_IE]) {
5003 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5004 memcpy((void *)request->ie,
5005 nla_data(info->attrs[NL80211_ATTR_IE]),
5006 request->ie_len);
5007 }
5008
Sam Leffler46856bb2012-10-11 21:03:32 -07005009 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005010 request->flags = nla_get_u32(
5011 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005012 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5013 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5014 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5015 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005016 err = -EOPNOTSUPP;
5017 goto out_free;
5018 }
5019 }
Sam Lefflered4737712012-10-11 21:03:31 -07005020
Luciano Coelho807f8a82011-05-11 17:09:35 +03005021 request->dev = dev;
5022 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005023 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005024 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005025
Hila Gonene35e4d22012-06-27 17:19:42 +03005026 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005027 if (!err) {
5028 rdev->sched_scan_req = request;
5029 nl80211_send_sched_scan(rdev, dev,
5030 NL80211_CMD_START_SCHED_SCAN);
5031 goto out;
5032 }
5033
5034out_free:
5035 kfree(request);
5036out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005037 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005038 return err;
5039}
5040
5041static int nl80211_stop_sched_scan(struct sk_buff *skb,
5042 struct genl_info *info)
5043{
5044 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005045 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005046
5047 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5048 !rdev->ops->sched_scan_stop)
5049 return -EOPNOTSUPP;
5050
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005051 mutex_lock(&rdev->sched_scan_mtx);
5052 err = __cfg80211_stop_sched_scan(rdev, false);
5053 mutex_unlock(&rdev->sched_scan_mtx);
5054
5055 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005056}
5057
Johannes Berg9720bb32011-06-21 09:45:33 +02005058static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5059 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005060 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005061 struct wireless_dev *wdev,
5062 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005063{
Johannes Berg48ab9052009-07-10 18:42:31 +02005064 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005065 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005066 void *hdr;
5067 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005068 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005069
5070 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005071
Eric W. Biederman15e47302012-09-07 20:12:54 +00005072 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005073 NL80211_CMD_NEW_SCAN_RESULTS);
5074 if (!hdr)
5075 return -1;
5076
Johannes Berg9720bb32011-06-21 09:45:33 +02005077 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5078
David S. Miller9360ffd2012-03-29 04:41:26 -04005079 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5080 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5081 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005082
5083 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5084 if (!bss)
5085 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005086 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005087 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005088 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005089
5090 rcu_read_lock();
5091 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005092 if (ies) {
5093 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5094 goto fail_unlock_rcu;
5095 tsf = true;
5096 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5097 ies->len, ies->data))
5098 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005099 }
5100 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005101 if (ies) {
5102 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5103 goto fail_unlock_rcu;
5104 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5105 ies->len, ies->data))
5106 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005107 }
5108 rcu_read_unlock();
5109
David S. Miller9360ffd2012-03-29 04:41:26 -04005110 if (res->beacon_interval &&
5111 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5112 goto nla_put_failure;
5113 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5114 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5115 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5116 jiffies_to_msecs(jiffies - intbss->ts)))
5117 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005118
Johannes Berg77965c92009-02-18 18:45:06 +01005119 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005120 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005121 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5122 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005123 break;
5124 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005125 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5126 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005127 break;
5128 default:
5129 break;
5130 }
5131
Johannes Berg48ab9052009-07-10 18:42:31 +02005132 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005133 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005134 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005135 if (intbss == wdev->current_bss &&
5136 nla_put_u32(msg, NL80211_BSS_STATUS,
5137 NL80211_BSS_STATUS_ASSOCIATED))
5138 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005139 break;
5140 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005141 if (intbss == wdev->current_bss &&
5142 nla_put_u32(msg, NL80211_BSS_STATUS,
5143 NL80211_BSS_STATUS_IBSS_JOINED))
5144 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005145 break;
5146 default:
5147 break;
5148 }
5149
Johannes Berg2a519312009-02-10 21:25:55 +01005150 nla_nest_end(msg, bss);
5151
5152 return genlmsg_end(msg, hdr);
5153
Johannes Berg8cef2c92013-02-05 16:54:31 +01005154 fail_unlock_rcu:
5155 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005156 nla_put_failure:
5157 genlmsg_cancel(msg, hdr);
5158 return -EMSGSIZE;
5159}
5160
5161static int nl80211_dump_scan(struct sk_buff *skb,
5162 struct netlink_callback *cb)
5163{
Johannes Berg48ab9052009-07-10 18:42:31 +02005164 struct cfg80211_registered_device *rdev;
5165 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01005166 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005167 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005168 int start = cb->args[1], idx = 0;
5169 int err;
5170
Johannes Berg67748892010-10-04 21:14:06 +02005171 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5172 if (err)
5173 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005174
Johannes Berg48ab9052009-07-10 18:42:31 +02005175 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01005176
Johannes Berg48ab9052009-07-10 18:42:31 +02005177 wdev_lock(wdev);
5178 spin_lock_bh(&rdev->bss_lock);
5179 cfg80211_bss_expire(rdev);
5180
Johannes Berg9720bb32011-06-21 09:45:33 +02005181 cb->seq = rdev->bss_generation;
5182
Johannes Berg48ab9052009-07-10 18:42:31 +02005183 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005184 if (++idx <= start)
5185 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005186 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005187 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005188 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005189 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005190 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005191 }
5192 }
5193
Johannes Berg48ab9052009-07-10 18:42:31 +02005194 spin_unlock_bh(&rdev->bss_lock);
5195 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005196
5197 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02005198 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005199
Johannes Berg67748892010-10-04 21:14:06 +02005200 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005201}
5202
Eric W. Biederman15e47302012-09-07 20:12:54 +00005203static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005204 int flags, struct net_device *dev,
5205 struct survey_info *survey)
5206{
5207 void *hdr;
5208 struct nlattr *infoattr;
5209
Eric W. Biederman15e47302012-09-07 20:12:54 +00005210 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005211 NL80211_CMD_NEW_SURVEY_RESULTS);
5212 if (!hdr)
5213 return -ENOMEM;
5214
David S. Miller9360ffd2012-03-29 04:41:26 -04005215 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5216 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005217
5218 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5219 if (!infoattr)
5220 goto nla_put_failure;
5221
David S. Miller9360ffd2012-03-29 04:41:26 -04005222 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5223 survey->channel->center_freq))
5224 goto nla_put_failure;
5225
5226 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5227 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5228 goto nla_put_failure;
5229 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5230 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5231 goto nla_put_failure;
5232 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5233 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5234 survey->channel_time))
5235 goto nla_put_failure;
5236 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5237 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5238 survey->channel_time_busy))
5239 goto nla_put_failure;
5240 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5241 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5242 survey->channel_time_ext_busy))
5243 goto nla_put_failure;
5244 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5245 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5246 survey->channel_time_rx))
5247 goto nla_put_failure;
5248 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5249 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5250 survey->channel_time_tx))
5251 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005252
5253 nla_nest_end(msg, infoattr);
5254
5255 return genlmsg_end(msg, hdr);
5256
5257 nla_put_failure:
5258 genlmsg_cancel(msg, hdr);
5259 return -EMSGSIZE;
5260}
5261
5262static int nl80211_dump_survey(struct sk_buff *skb,
5263 struct netlink_callback *cb)
5264{
5265 struct survey_info survey;
5266 struct cfg80211_registered_device *dev;
5267 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01005268 int survey_idx = cb->args[1];
5269 int res;
5270
Johannes Berg67748892010-10-04 21:14:06 +02005271 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5272 if (res)
5273 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005274
5275 if (!dev->ops->dump_survey) {
5276 res = -EOPNOTSUPP;
5277 goto out_err;
5278 }
5279
5280 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005281 struct ieee80211_channel *chan;
5282
Hila Gonene35e4d22012-06-27 17:19:42 +03005283 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005284 if (res == -ENOENT)
5285 break;
5286 if (res)
5287 goto out_err;
5288
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005289 /* Survey without a channel doesn't make sense */
5290 if (!survey.channel) {
5291 res = -EINVAL;
5292 goto out;
5293 }
5294
5295 chan = ieee80211_get_channel(&dev->wiphy,
5296 survey.channel->center_freq);
5297 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5298 survey_idx++;
5299 continue;
5300 }
5301
Holger Schurig61fa7132009-11-11 12:25:40 +01005302 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005303 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005304 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5305 netdev,
5306 &survey) < 0)
5307 goto out;
5308 survey_idx++;
5309 }
5310
5311 out:
5312 cb->args[1] = survey_idx;
5313 res = skb->len;
5314 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02005315 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005316 return res;
5317}
5318
Samuel Ortizb23aa672009-07-01 21:26:54 +02005319static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5320{
5321 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5322 NL80211_WPA_VERSION_2));
5323}
5324
Jouni Malinen636a5d32009-03-19 13:39:22 +02005325static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5326{
Johannes Berg4c476992010-10-04 21:36:35 +02005327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5328 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005329 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005330 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5331 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005332 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005333 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005334 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005335
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005336 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5337 return -EINVAL;
5338
5339 if (!info->attrs[NL80211_ATTR_MAC])
5340 return -EINVAL;
5341
Jouni Malinen17780922009-03-27 20:52:47 +02005342 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5343 return -EINVAL;
5344
Johannes Berg19957bb2009-07-02 17:20:43 +02005345 if (!info->attrs[NL80211_ATTR_SSID])
5346 return -EINVAL;
5347
5348 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5349 return -EINVAL;
5350
Johannes Bergfffd0932009-07-08 14:22:54 +02005351 err = nl80211_parse_key(info, &key);
5352 if (err)
5353 return err;
5354
5355 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005356 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5357 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005358 if (!key.p.key || !key.p.key_len)
5359 return -EINVAL;
5360 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5361 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5362 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5363 key.p.key_len != WLAN_KEY_LEN_WEP104))
5364 return -EINVAL;
5365 if (key.idx > 4)
5366 return -EINVAL;
5367 } else {
5368 key.p.key_len = 0;
5369 key.p.key = NULL;
5370 }
5371
Johannes Bergafea0b72010-08-10 09:46:42 +02005372 if (key.idx >= 0) {
5373 int i;
5374 bool ok = false;
5375 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5376 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5377 ok = true;
5378 break;
5379 }
5380 }
Johannes Berg4c476992010-10-04 21:36:35 +02005381 if (!ok)
5382 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005383 }
5384
Johannes Berg4c476992010-10-04 21:36:35 +02005385 if (!rdev->ops->auth)
5386 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005387
Johannes Berg074ac8d2010-09-16 14:58:22 +02005388 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005389 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5390 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005391
Johannes Berg19957bb2009-07-02 17:20:43 +02005392 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005393 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005394 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005395 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5396 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005397
Johannes Berg19957bb2009-07-02 17:20:43 +02005398 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5399 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5400
5401 if (info->attrs[NL80211_ATTR_IE]) {
5402 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5403 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5404 }
5405
5406 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005407 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005408 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005409
Jouni Malinene39e5b52012-09-30 19:29:39 +03005410 if (auth_type == NL80211_AUTHTYPE_SAE &&
5411 !info->attrs[NL80211_ATTR_SAE_DATA])
5412 return -EINVAL;
5413
5414 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5415 if (auth_type != NL80211_AUTHTYPE_SAE)
5416 return -EINVAL;
5417 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5418 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5419 /* need to include at least Auth Transaction and Status Code */
5420 if (sae_data_len < 4)
5421 return -EINVAL;
5422 }
5423
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005424 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5425
Johannes Berg95de8172012-01-20 13:55:25 +01005426 /*
5427 * Since we no longer track auth state, ignore
5428 * requests to only change local state.
5429 */
5430 if (local_state_change)
5431 return 0;
5432
Johannes Berg4c476992010-10-04 21:36:35 +02005433 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5434 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005435 key.p.key, key.p.key_len, key.idx,
5436 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005437}
5438
Johannes Bergc0692b82010-08-27 14:26:53 +03005439static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5440 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005441 struct cfg80211_crypto_settings *settings,
5442 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005443{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005444 memset(settings, 0, sizeof(*settings));
5445
Samuel Ortizb23aa672009-07-01 21:26:54 +02005446 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5447
Johannes Bergc0692b82010-08-27 14:26:53 +03005448 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5449 u16 proto;
5450 proto = nla_get_u16(
5451 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5452 settings->control_port_ethertype = cpu_to_be16(proto);
5453 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5454 proto != ETH_P_PAE)
5455 return -EINVAL;
5456 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5457 settings->control_port_no_encrypt = true;
5458 } else
5459 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5460
Samuel Ortizb23aa672009-07-01 21:26:54 +02005461 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5462 void *data;
5463 int len, i;
5464
5465 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5466 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5467 settings->n_ciphers_pairwise = len / sizeof(u32);
5468
5469 if (len % sizeof(u32))
5470 return -EINVAL;
5471
Johannes Berg3dc27d22009-07-02 21:36:37 +02005472 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005473 return -EINVAL;
5474
5475 memcpy(settings->ciphers_pairwise, data, len);
5476
5477 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005478 if (!cfg80211_supported_cipher_suite(
5479 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005480 settings->ciphers_pairwise[i]))
5481 return -EINVAL;
5482 }
5483
5484 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5485 settings->cipher_group =
5486 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005487 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5488 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005489 return -EINVAL;
5490 }
5491
5492 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5493 settings->wpa_versions =
5494 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5495 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5496 return -EINVAL;
5497 }
5498
5499 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5500 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005501 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005502
5503 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5504 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5505 settings->n_akm_suites = len / sizeof(u32);
5506
5507 if (len % sizeof(u32))
5508 return -EINVAL;
5509
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005510 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5511 return -EINVAL;
5512
Samuel Ortizb23aa672009-07-01 21:26:54 +02005513 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005514 }
5515
5516 return 0;
5517}
5518
Jouni Malinen636a5d32009-03-19 13:39:22 +02005519static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5520{
Johannes Berg4c476992010-10-04 21:36:35 +02005521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5522 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005523 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02005524 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02005525 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005526 int err, ssid_len, ie_len = 0;
5527 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08005528 u32 flags = 0;
5529 struct ieee80211_ht_cap *ht_capa = NULL;
5530 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005531
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005532 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5533 return -EINVAL;
5534
5535 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005536 !info->attrs[NL80211_ATTR_SSID] ||
5537 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005538 return -EINVAL;
5539
Johannes Berg4c476992010-10-04 21:36:35 +02005540 if (!rdev->ops->assoc)
5541 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005542
Johannes Berg074ac8d2010-09-16 14:58:22 +02005543 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005544 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5545 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005546
Johannes Berg19957bb2009-07-02 17:20:43 +02005547 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005548
Johannes Berg19957bb2009-07-02 17:20:43 +02005549 chan = ieee80211_get_channel(&rdev->wiphy,
5550 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005551 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5552 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005553
Johannes Berg19957bb2009-07-02 17:20:43 +02005554 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5555 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005556
5557 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005558 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5559 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005560 }
5561
Jouni Malinendc6382c2009-05-06 22:09:37 +03005562 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005563 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03005564 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005565 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02005566 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02005567 else if (mfp != NL80211_MFP_NO)
5568 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03005569 }
5570
Johannes Berg3e5d7642009-07-07 14:37:26 +02005571 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5572 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5573
Ben Greear7e7c8922011-11-18 11:31:59 -08005574 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5575 flags |= ASSOC_REQ_DISABLE_HT;
5576
5577 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5578 ht_capa_mask =
5579 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5580
5581 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5582 if (!ht_capa_mask)
5583 return -EINVAL;
5584 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5585 }
5586
Johannes Bergc0692b82010-08-27 14:26:53 +03005587 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005588 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02005589 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5590 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08005591 &crypto, flags, ht_capa,
5592 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005593
Jouni Malinen636a5d32009-03-19 13:39:22 +02005594 return err;
5595}
5596
5597static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5598{
Johannes Berg4c476992010-10-04 21:36:35 +02005599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5600 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005601 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005602 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005603 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005604 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005605
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005606 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5607 return -EINVAL;
5608
5609 if (!info->attrs[NL80211_ATTR_MAC])
5610 return -EINVAL;
5611
5612 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5613 return -EINVAL;
5614
Johannes Berg4c476992010-10-04 21:36:35 +02005615 if (!rdev->ops->deauth)
5616 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005617
Johannes Berg074ac8d2010-09-16 14:58:22 +02005618 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005619 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5620 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005621
Johannes Berg19957bb2009-07-02 17:20:43 +02005622 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005623
Johannes Berg19957bb2009-07-02 17:20:43 +02005624 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5625 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005626 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005627 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005628 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005629
5630 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005631 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5632 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005633 }
5634
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005635 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5636
Johannes Berg4c476992010-10-04 21:36:35 +02005637 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5638 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005639}
5640
5641static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5642{
Johannes Berg4c476992010-10-04 21:36:35 +02005643 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5644 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005645 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005646 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005647 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005648 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005649
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005650 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5651 return -EINVAL;
5652
5653 if (!info->attrs[NL80211_ATTR_MAC])
5654 return -EINVAL;
5655
5656 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5657 return -EINVAL;
5658
Johannes Berg4c476992010-10-04 21:36:35 +02005659 if (!rdev->ops->disassoc)
5660 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005661
Johannes Berg074ac8d2010-09-16 14:58:22 +02005662 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005663 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5664 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005665
Johannes Berg19957bb2009-07-02 17:20:43 +02005666 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005667
Johannes Berg19957bb2009-07-02 17:20:43 +02005668 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5669 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005670 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005671 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005672 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005673
5674 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005675 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5676 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005677 }
5678
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005679 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5680
Johannes Berg4c476992010-10-04 21:36:35 +02005681 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5682 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005683}
5684
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005685static bool
5686nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5687 int mcast_rate[IEEE80211_NUM_BANDS],
5688 int rateval)
5689{
5690 struct wiphy *wiphy = &rdev->wiphy;
5691 bool found = false;
5692 int band, i;
5693
5694 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5695 struct ieee80211_supported_band *sband;
5696
5697 sband = wiphy->bands[band];
5698 if (!sband)
5699 continue;
5700
5701 for (i = 0; i < sband->n_bitrates; i++) {
5702 if (sband->bitrates[i].bitrate == rateval) {
5703 mcast_rate[band] = i + 1;
5704 found = true;
5705 break;
5706 }
5707 }
5708 }
5709
5710 return found;
5711}
5712
Johannes Berg04a773a2009-04-19 21:24:32 +02005713static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5714{
Johannes Berg4c476992010-10-04 21:36:35 +02005715 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5716 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005717 struct cfg80211_ibss_params ibss;
5718 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005719 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005720 int err;
5721
Johannes Berg8e30bc52009-04-22 17:45:38 +02005722 memset(&ibss, 0, sizeof(ibss));
5723
Johannes Berg04a773a2009-04-19 21:24:32 +02005724 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5725 return -EINVAL;
5726
Johannes Berg683b6d32012-11-08 21:25:48 +01005727 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02005728 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5729 return -EINVAL;
5730
Johannes Berg8e30bc52009-04-22 17:45:38 +02005731 ibss.beacon_interval = 100;
5732
5733 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5734 ibss.beacon_interval =
5735 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5736 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5737 return -EINVAL;
5738 }
5739
Johannes Berg4c476992010-10-04 21:36:35 +02005740 if (!rdev->ops->join_ibss)
5741 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005742
Johannes Berg4c476992010-10-04 21:36:35 +02005743 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5744 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005745
Johannes Berg79c97e92009-07-07 03:56:12 +02005746 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005747
Johannes Berg39193492011-09-16 13:45:25 +02005748 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005749 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005750
5751 if (!is_valid_ether_addr(ibss.bssid))
5752 return -EINVAL;
5753 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005754 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5755 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5756
5757 if (info->attrs[NL80211_ATTR_IE]) {
5758 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5759 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5760 }
5761
Johannes Berg683b6d32012-11-08 21:25:48 +01005762 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
5763 if (err)
5764 return err;
Alexander Simon54858ee2011-11-30 16:56:32 +01005765
Johannes Berg683b6d32012-11-08 21:25:48 +01005766 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee2011-11-30 16:56:32 +01005767 return -EINVAL;
5768
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005769 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
5770 return -EINVAL;
5771 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
5772 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01005773 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005774
Johannes Berg04a773a2009-04-19 21:24:32 +02005775 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005776 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005777
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005778 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5779 u8 *rates =
5780 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5781 int n_rates =
5782 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5783 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01005784 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005785
Johannes Berg34850ab2011-07-18 18:08:35 +02005786 err = ieee80211_get_ratemask(sband, rates, n_rates,
5787 &ibss.basic_rates);
5788 if (err)
5789 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005790 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005791
5792 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5793 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5794 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5795 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005796
Johannes Berg4c476992010-10-04 21:36:35 +02005797 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05305798 bool no_ht = false;
5799
Johannes Berg4c476992010-10-04 21:36:35 +02005800 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05305801 info->attrs[NL80211_ATTR_KEYS],
5802 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02005803 if (IS_ERR(connkeys))
5804 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05305805
Johannes Berg3d9d1d62012-11-08 23:14:50 +01005806 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
5807 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05305808 kfree(connkeys);
5809 return -EINVAL;
5810 }
Johannes Berg4c476992010-10-04 21:36:35 +02005811 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005812
Antonio Quartulli267335d2012-01-31 20:25:47 +01005813 ibss.control_port =
5814 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5815
Johannes Berg4c476992010-10-04 21:36:35 +02005816 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005817 if (err)
5818 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005819 return err;
5820}
5821
5822static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5823{
Johannes Berg4c476992010-10-04 21:36:35 +02005824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5825 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005826
Johannes Berg4c476992010-10-04 21:36:35 +02005827 if (!rdev->ops->leave_ibss)
5828 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005829
Johannes Berg4c476992010-10-04 21:36:35 +02005830 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5831 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005832
Johannes Berg4c476992010-10-04 21:36:35 +02005833 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005834}
5835
Antonio Quartullif4e583c2012-11-02 13:27:48 +01005836static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
5837{
5838 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5839 struct net_device *dev = info->user_ptr[1];
5840 int mcast_rate[IEEE80211_NUM_BANDS];
5841 u32 nla_rate;
5842 int err;
5843
5844 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5845 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5846 return -EOPNOTSUPP;
5847
5848 if (!rdev->ops->set_mcast_rate)
5849 return -EOPNOTSUPP;
5850
5851 memset(mcast_rate, 0, sizeof(mcast_rate));
5852
5853 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
5854 return -EINVAL;
5855
5856 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
5857 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
5858 return -EINVAL;
5859
5860 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
5861
5862 return err;
5863}
5864
5865
Johannes Bergaff89a92009-07-01 21:26:51 +02005866#ifdef CONFIG_NL80211_TESTMODE
5867static struct genl_multicast_group nl80211_testmode_mcgrp = {
5868 .name = "testmode",
5869};
5870
5871static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5872{
Johannes Berg4c476992010-10-04 21:36:35 +02005873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005874 int err;
5875
5876 if (!info->attrs[NL80211_ATTR_TESTDATA])
5877 return -EINVAL;
5878
Johannes Bergaff89a92009-07-01 21:26:51 +02005879 err = -EOPNOTSUPP;
5880 if (rdev->ops->testmode_cmd) {
5881 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03005882 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02005883 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5884 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5885 rdev->testmode_info = NULL;
5886 }
5887
Johannes Bergaff89a92009-07-01 21:26:51 +02005888 return err;
5889}
5890
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005891static int nl80211_testmode_dump(struct sk_buff *skb,
5892 struct netlink_callback *cb)
5893{
Johannes Berg00918d32011-12-13 17:22:05 +01005894 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005895 int err;
5896 long phy_idx;
5897 void *data = NULL;
5898 int data_len = 0;
5899
5900 if (cb->args[0]) {
5901 /*
5902 * 0 is a valid index, but not valid for args[0],
5903 * so we need to offset by 1.
5904 */
5905 phy_idx = cb->args[0] - 1;
5906 } else {
5907 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5908 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5909 nl80211_policy);
5910 if (err)
5911 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005912
Johannes Berg2bd7e352012-06-15 14:23:16 +02005913 mutex_lock(&cfg80211_mutex);
5914 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5915 nl80211_fam.attrbuf);
5916 if (IS_ERR(rdev)) {
5917 mutex_unlock(&cfg80211_mutex);
5918 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005919 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005920 phy_idx = rdev->wiphy_idx;
5921 rdev = NULL;
5922 mutex_unlock(&cfg80211_mutex);
5923
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005924 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5925 cb->args[1] =
5926 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5927 }
5928
5929 if (cb->args[1]) {
5930 data = nla_data((void *)cb->args[1]);
5931 data_len = nla_len((void *)cb->args[1]);
5932 }
5933
5934 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005935 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5936 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005937 mutex_unlock(&cfg80211_mutex);
5938 return -ENOENT;
5939 }
Johannes Berg00918d32011-12-13 17:22:05 +01005940 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005941 mutex_unlock(&cfg80211_mutex);
5942
Johannes Berg00918d32011-12-13 17:22:05 +01005943 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005944 err = -EOPNOTSUPP;
5945 goto out_err;
5946 }
5947
5948 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00005949 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005950 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5951 NL80211_CMD_TESTMODE);
5952 struct nlattr *tmdata;
5953
David S. Miller9360ffd2012-03-29 04:41:26 -04005954 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005955 genlmsg_cancel(skb, hdr);
5956 break;
5957 }
5958
5959 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5960 if (!tmdata) {
5961 genlmsg_cancel(skb, hdr);
5962 break;
5963 }
Hila Gonene35e4d22012-06-27 17:19:42 +03005964 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005965 nla_nest_end(skb, tmdata);
5966
5967 if (err == -ENOBUFS || err == -ENOENT) {
5968 genlmsg_cancel(skb, hdr);
5969 break;
5970 } else if (err) {
5971 genlmsg_cancel(skb, hdr);
5972 goto out_err;
5973 }
5974
5975 genlmsg_end(skb, hdr);
5976 }
5977
5978 err = skb->len;
5979 /* see above */
5980 cb->args[0] = phy_idx + 1;
5981 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005982 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005983 return err;
5984}
5985
Johannes Bergaff89a92009-07-01 21:26:51 +02005986static struct sk_buff *
5987__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005988 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02005989{
5990 struct sk_buff *skb;
5991 void *hdr;
5992 struct nlattr *data;
5993
5994 skb = nlmsg_new(approxlen + 100, gfp);
5995 if (!skb)
5996 return NULL;
5997
Eric W. Biederman15e47302012-09-07 20:12:54 +00005998 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02005999 if (!hdr) {
6000 kfree_skb(skb);
6001 return NULL;
6002 }
6003
David S. Miller9360ffd2012-03-29 04:41:26 -04006004 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6005 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006006 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6007
6008 ((void **)skb->cb)[0] = rdev;
6009 ((void **)skb->cb)[1] = hdr;
6010 ((void **)skb->cb)[2] = data;
6011
6012 return skb;
6013
6014 nla_put_failure:
6015 kfree_skb(skb);
6016 return NULL;
6017}
6018
6019struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6020 int approxlen)
6021{
6022 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6023
6024 if (WARN_ON(!rdev->testmode_info))
6025 return NULL;
6026
6027 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006028 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006029 rdev->testmode_info->snd_seq,
6030 GFP_KERNEL);
6031}
6032EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6033
6034int cfg80211_testmode_reply(struct sk_buff *skb)
6035{
6036 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6037 void *hdr = ((void **)skb->cb)[1];
6038 struct nlattr *data = ((void **)skb->cb)[2];
6039
6040 if (WARN_ON(!rdev->testmode_info)) {
6041 kfree_skb(skb);
6042 return -EINVAL;
6043 }
6044
6045 nla_nest_end(skb, data);
6046 genlmsg_end(skb, hdr);
6047 return genlmsg_reply(skb, rdev->testmode_info);
6048}
6049EXPORT_SYMBOL(cfg80211_testmode_reply);
6050
6051struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6052 int approxlen, gfp_t gfp)
6053{
6054 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6055
6056 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6057}
6058EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6059
6060void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6061{
6062 void *hdr = ((void **)skb->cb)[1];
6063 struct nlattr *data = ((void **)skb->cb)[2];
6064
6065 nla_nest_end(skb, data);
6066 genlmsg_end(skb, hdr);
6067 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6068}
6069EXPORT_SYMBOL(cfg80211_testmode_event);
6070#endif
6071
Samuel Ortizb23aa672009-07-01 21:26:54 +02006072static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6073{
Johannes Berg4c476992010-10-04 21:36:35 +02006074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6075 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006076 struct cfg80211_connect_params connect;
6077 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006078 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006079 int err;
6080
6081 memset(&connect, 0, sizeof(connect));
6082
6083 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6084 return -EINVAL;
6085
6086 if (!info->attrs[NL80211_ATTR_SSID] ||
6087 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6088 return -EINVAL;
6089
6090 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6091 connect.auth_type =
6092 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006093 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6094 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006095 return -EINVAL;
6096 } else
6097 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6098
6099 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6100
Johannes Bergc0692b82010-08-27 14:26:53 +03006101 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006102 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006103 if (err)
6104 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006105
Johannes Berg074ac8d2010-09-16 14:58:22 +02006106 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006107 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6108 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006109
Johannes Berg79c97e92009-07-07 03:56:12 +02006110 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006111
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306112 connect.bg_scan_period = -1;
6113 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6114 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6115 connect.bg_scan_period =
6116 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6117 }
6118
Samuel Ortizb23aa672009-07-01 21:26:54 +02006119 if (info->attrs[NL80211_ATTR_MAC])
6120 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6121 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6122 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6123
6124 if (info->attrs[NL80211_ATTR_IE]) {
6125 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6126 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6127 }
6128
Jouni Malinencee00a92013-01-15 17:15:57 +02006129 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6130 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6131 if (connect.mfp != NL80211_MFP_REQUIRED &&
6132 connect.mfp != NL80211_MFP_NO)
6133 return -EINVAL;
6134 } else {
6135 connect.mfp = NL80211_MFP_NO;
6136 }
6137
Samuel Ortizb23aa672009-07-01 21:26:54 +02006138 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6139 connect.channel =
6140 ieee80211_get_channel(wiphy,
6141 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6142 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006143 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6144 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006145 }
6146
Johannes Bergfffd0932009-07-08 14:22:54 +02006147 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6148 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306149 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006150 if (IS_ERR(connkeys))
6151 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006152 }
6153
Ben Greear7e7c8922011-11-18 11:31:59 -08006154 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6155 connect.flags |= ASSOC_REQ_DISABLE_HT;
6156
6157 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6158 memcpy(&connect.ht_capa_mask,
6159 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6160 sizeof(connect.ht_capa_mask));
6161
6162 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006163 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6164 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006165 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006166 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006167 memcpy(&connect.ht_capa,
6168 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6169 sizeof(connect.ht_capa));
6170 }
6171
Johannes Bergfffd0932009-07-08 14:22:54 +02006172 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006173 if (err)
6174 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006175 return err;
6176}
6177
6178static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6179{
Johannes Berg4c476992010-10-04 21:36:35 +02006180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6181 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006182 u16 reason;
6183
6184 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6185 reason = WLAN_REASON_DEAUTH_LEAVING;
6186 else
6187 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6188
6189 if (reason == 0)
6190 return -EINVAL;
6191
Johannes Berg074ac8d2010-09-16 14:58:22 +02006192 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006193 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6194 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006195
Johannes Berg4c476992010-10-04 21:36:35 +02006196 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006197}
6198
Johannes Berg463d0182009-07-14 00:33:35 +02006199static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6200{
Johannes Berg4c476992010-10-04 21:36:35 +02006201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006202 struct net *net;
6203 int err;
6204 u32 pid;
6205
6206 if (!info->attrs[NL80211_ATTR_PID])
6207 return -EINVAL;
6208
6209 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6210
Johannes Berg463d0182009-07-14 00:33:35 +02006211 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006212 if (IS_ERR(net))
6213 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006214
6215 err = 0;
6216
6217 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006218 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6219 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006220
Johannes Berg463d0182009-07-14 00:33:35 +02006221 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006222 return err;
6223}
6224
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006225static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6226{
Johannes Berg4c476992010-10-04 21:36:35 +02006227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006228 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6229 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006230 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006231 struct cfg80211_pmksa pmksa;
6232
6233 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6234
6235 if (!info->attrs[NL80211_ATTR_MAC])
6236 return -EINVAL;
6237
6238 if (!info->attrs[NL80211_ATTR_PMKID])
6239 return -EINVAL;
6240
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006241 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6242 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6243
Johannes Berg074ac8d2010-09-16 14:58:22 +02006244 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006245 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6246 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006247
6248 switch (info->genlhdr->cmd) {
6249 case NL80211_CMD_SET_PMKSA:
6250 rdev_ops = rdev->ops->set_pmksa;
6251 break;
6252 case NL80211_CMD_DEL_PMKSA:
6253 rdev_ops = rdev->ops->del_pmksa;
6254 break;
6255 default:
6256 WARN_ON(1);
6257 break;
6258 }
6259
Johannes Berg4c476992010-10-04 21:36:35 +02006260 if (!rdev_ops)
6261 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006262
Johannes Berg4c476992010-10-04 21:36:35 +02006263 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006264}
6265
6266static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6267{
Johannes Berg4c476992010-10-04 21:36:35 +02006268 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6269 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006270
Johannes Berg074ac8d2010-09-16 14:58:22 +02006271 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006272 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6273 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006274
Johannes Berg4c476992010-10-04 21:36:35 +02006275 if (!rdev->ops->flush_pmksa)
6276 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006277
Hila Gonene35e4d22012-06-27 17:19:42 +03006278 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006279}
6280
Arik Nemtsov109086c2011-09-28 14:12:50 +03006281static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6282{
6283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6284 struct net_device *dev = info->user_ptr[1];
6285 u8 action_code, dialog_token;
6286 u16 status_code;
6287 u8 *peer;
6288
6289 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6290 !rdev->ops->tdls_mgmt)
6291 return -EOPNOTSUPP;
6292
6293 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6294 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6295 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6296 !info->attrs[NL80211_ATTR_IE] ||
6297 !info->attrs[NL80211_ATTR_MAC])
6298 return -EINVAL;
6299
6300 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6301 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6302 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6303 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6304
Hila Gonene35e4d22012-06-27 17:19:42 +03006305 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6306 dialog_token, status_code,
6307 nla_data(info->attrs[NL80211_ATTR_IE]),
6308 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006309}
6310
6311static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6312{
6313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6314 struct net_device *dev = info->user_ptr[1];
6315 enum nl80211_tdls_operation operation;
6316 u8 *peer;
6317
6318 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6319 !rdev->ops->tdls_oper)
6320 return -EOPNOTSUPP;
6321
6322 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6323 !info->attrs[NL80211_ATTR_MAC])
6324 return -EINVAL;
6325
6326 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6327 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6328
Hila Gonene35e4d22012-06-27 17:19:42 +03006329 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006330}
6331
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006332static int nl80211_remain_on_channel(struct sk_buff *skb,
6333 struct genl_info *info)
6334{
Johannes Berg4c476992010-10-04 21:36:35 +02006335 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006336 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006337 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006338 struct sk_buff *msg;
6339 void *hdr;
6340 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006341 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006342 int err;
6343
6344 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6345 !info->attrs[NL80211_ATTR_DURATION])
6346 return -EINVAL;
6347
6348 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6349
Johannes Berg7c4ef712011-11-18 15:33:48 +01006350 if (!rdev->ops->remain_on_channel ||
6351 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006352 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006353
Johannes Bergebf348f2012-06-01 12:50:54 +02006354 /*
6355 * We should be on that channel for at least a minimum amount of
6356 * time (10ms) but no longer than the driver supports.
6357 */
6358 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6359 duration > rdev->wiphy.max_remain_on_channel_duration)
6360 return -EINVAL;
6361
Johannes Berg683b6d32012-11-08 21:25:48 +01006362 err = nl80211_parse_chandef(rdev, info, &chandef);
6363 if (err)
6364 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006365
6366 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006367 if (!msg)
6368 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006369
Eric W. Biederman15e47302012-09-07 20:12:54 +00006370 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006371 NL80211_CMD_REMAIN_ON_CHANNEL);
6372
6373 if (IS_ERR(hdr)) {
6374 err = PTR_ERR(hdr);
6375 goto free_msg;
6376 }
6377
Johannes Berg683b6d32012-11-08 21:25:48 +01006378 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6379 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006380
6381 if (err)
6382 goto free_msg;
6383
David S. Miller9360ffd2012-03-29 04:41:26 -04006384 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6385 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006386
6387 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006388
6389 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006390
6391 nla_put_failure:
6392 err = -ENOBUFS;
6393 free_msg:
6394 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006395 return err;
6396}
6397
6398static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6399 struct genl_info *info)
6400{
Johannes Berg4c476992010-10-04 21:36:35 +02006401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006402 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006403 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006404
6405 if (!info->attrs[NL80211_ATTR_COOKIE])
6406 return -EINVAL;
6407
Johannes Berg4c476992010-10-04 21:36:35 +02006408 if (!rdev->ops->cancel_remain_on_channel)
6409 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006410
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006411 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6412
Hila Gonene35e4d22012-06-27 17:19:42 +03006413 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006414}
6415
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006416static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6417 u8 *rates, u8 rates_len)
6418{
6419 u8 i;
6420 u32 mask = 0;
6421
6422 for (i = 0; i < rates_len; i++) {
6423 int rate = (rates[i] & 0x7f) * 5;
6424 int ridx;
6425 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6426 struct ieee80211_rate *srate =
6427 &sband->bitrates[ridx];
6428 if (rate == srate->bitrate) {
6429 mask |= 1 << ridx;
6430 break;
6431 }
6432 }
6433 if (ridx == sband->n_bitrates)
6434 return 0; /* rate not found */
6435 }
6436
6437 return mask;
6438}
6439
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006440static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6441 u8 *rates, u8 rates_len,
6442 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6443{
6444 u8 i;
6445
6446 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6447
6448 for (i = 0; i < rates_len; i++) {
6449 int ridx, rbit;
6450
6451 ridx = rates[i] / 8;
6452 rbit = BIT(rates[i] % 8);
6453
6454 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006455 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006456 return false;
6457
6458 /* check availability */
6459 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6460 mcs[ridx] |= rbit;
6461 else
6462 return false;
6463 }
6464
6465 return true;
6466}
6467
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006468static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006469 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6470 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006471 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6472 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006473};
6474
6475static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6476 struct genl_info *info)
6477{
6478 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006480 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006481 int rem, i;
6482 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006483 struct nlattr *tx_rates;
6484 struct ieee80211_supported_band *sband;
6485
6486 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6487 return -EINVAL;
6488
Johannes Berg4c476992010-10-04 21:36:35 +02006489 if (!rdev->ops->set_bitrate_mask)
6490 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006491
6492 memset(&mask, 0, sizeof(mask));
6493 /* Default to all rates enabled */
6494 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6495 sband = rdev->wiphy.bands[i];
6496 mask.control[i].legacy =
6497 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006498 if (sband)
6499 memcpy(mask.control[i].mcs,
6500 sband->ht_cap.mcs.rx_mask,
6501 sizeof(mask.control[i].mcs));
6502 else
6503 memset(mask.control[i].mcs, 0,
6504 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006505 }
6506
6507 /*
6508 * The nested attribute uses enum nl80211_band as the index. This maps
6509 * directly to the enum ieee80211_band values used in cfg80211.
6510 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006511 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006512 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6513 {
6514 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02006515 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6516 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006517 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02006518 if (sband == NULL)
6519 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006520 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6521 nla_len(tx_rates), nl80211_txattr_policy);
6522 if (tb[NL80211_TXRATE_LEGACY]) {
6523 mask.control[band].legacy = rateset_to_mask(
6524 sband,
6525 nla_data(tb[NL80211_TXRATE_LEGACY]),
6526 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05306527 if ((mask.control[band].legacy == 0) &&
6528 nla_len(tb[NL80211_TXRATE_LEGACY]))
6529 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006530 }
6531 if (tb[NL80211_TXRATE_MCS]) {
6532 if (!ht_rateset_to_mask(
6533 sband,
6534 nla_data(tb[NL80211_TXRATE_MCS]),
6535 nla_len(tb[NL80211_TXRATE_MCS]),
6536 mask.control[band].mcs))
6537 return -EINVAL;
6538 }
6539
6540 if (mask.control[band].legacy == 0) {
6541 /* don't allow empty legacy rates if HT
6542 * is not even supported. */
6543 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6544 return -EINVAL;
6545
6546 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6547 if (mask.control[band].mcs[i])
6548 break;
6549
6550 /* legacy and mcs rates may not be both empty */
6551 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02006552 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006553 }
6554 }
6555
Hila Gonene35e4d22012-06-27 17:19:42 +03006556 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006557}
6558
Johannes Berg2e161f72010-08-12 15:38:38 +02006559static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006560{
Johannes Berg4c476992010-10-04 21:36:35 +02006561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006562 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02006563 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02006564
6565 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6566 return -EINVAL;
6567
Johannes Berg2e161f72010-08-12 15:38:38 +02006568 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6569 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02006570
Johannes Berg71bbc992012-06-15 15:30:18 +02006571 switch (wdev->iftype) {
6572 case NL80211_IFTYPE_STATION:
6573 case NL80211_IFTYPE_ADHOC:
6574 case NL80211_IFTYPE_P2P_CLIENT:
6575 case NL80211_IFTYPE_AP:
6576 case NL80211_IFTYPE_AP_VLAN:
6577 case NL80211_IFTYPE_MESH_POINT:
6578 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006579 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006580 break;
6581 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006582 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006583 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006584
6585 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02006586 if (!rdev->ops->mgmt_tx)
6587 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006588
Eric W. Biederman15e47302012-09-07 20:12:54 +00006589 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02006590 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6591 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02006592}
6593
Johannes Berg2e161f72010-08-12 15:38:38 +02006594static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006595{
Johannes Berg4c476992010-10-04 21:36:35 +02006596 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006597 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006598 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02006599 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01006600 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006601 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01006602 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006603 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01006604 bool offchan, no_cck, dont_wait_for_ack;
6605
6606 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02006607
Johannes Berg683b6d32012-11-08 21:25:48 +01006608 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02006609 return -EINVAL;
6610
Johannes Berg4c476992010-10-04 21:36:35 +02006611 if (!rdev->ops->mgmt_tx)
6612 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006613
Johannes Berg71bbc992012-06-15 15:30:18 +02006614 switch (wdev->iftype) {
6615 case NL80211_IFTYPE_STATION:
6616 case NL80211_IFTYPE_ADHOC:
6617 case NL80211_IFTYPE_P2P_CLIENT:
6618 case NL80211_IFTYPE_AP:
6619 case NL80211_IFTYPE_AP_VLAN:
6620 case NL80211_IFTYPE_MESH_POINT:
6621 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006622 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006623 break;
6624 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006625 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006626 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006627
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006628 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01006629 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006630 return -EINVAL;
6631 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02006632
6633 /*
6634 * We should wait on the channel for at least a minimum amount
6635 * of time (10ms) but no longer than the driver supports.
6636 */
6637 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6638 wait > rdev->wiphy.max_remain_on_channel_duration)
6639 return -EINVAL;
6640
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006641 }
6642
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006643 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6644
Johannes Berg7c4ef712011-11-18 15:33:48 +01006645 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6646 return -EINVAL;
6647
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306648 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6649
Johannes Berg683b6d32012-11-08 21:25:48 +01006650 err = nl80211_parse_chandef(rdev, info, &chandef);
6651 if (err)
6652 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02006653
Johannes Berge247bd902011-11-04 11:18:21 +01006654 if (!dont_wait_for_ack) {
6655 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6656 if (!msg)
6657 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006658
Eric W. Biederman15e47302012-09-07 20:12:54 +00006659 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01006660 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006661
Johannes Berge247bd902011-11-04 11:18:21 +01006662 if (IS_ERR(hdr)) {
6663 err = PTR_ERR(hdr);
6664 goto free_msg;
6665 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006666 }
Johannes Berge247bd902011-11-04 11:18:21 +01006667
Johannes Berg683b6d32012-11-08 21:25:48 +01006668 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006669 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6670 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006671 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006672 if (err)
6673 goto free_msg;
6674
Johannes Berge247bd902011-11-04 11:18:21 +01006675 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006676 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6677 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006678
Johannes Berge247bd902011-11-04 11:18:21 +01006679 genlmsg_end(msg, hdr);
6680 return genlmsg_reply(msg, info);
6681 }
6682
6683 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006684
6685 nla_put_failure:
6686 err = -ENOBUFS;
6687 free_msg:
6688 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006689 return err;
6690}
6691
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006692static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6693{
6694 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006695 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006696 u64 cookie;
6697
6698 if (!info->attrs[NL80211_ATTR_COOKIE])
6699 return -EINVAL;
6700
6701 if (!rdev->ops->mgmt_tx_cancel_wait)
6702 return -EOPNOTSUPP;
6703
Johannes Berg71bbc992012-06-15 15:30:18 +02006704 switch (wdev->iftype) {
6705 case NL80211_IFTYPE_STATION:
6706 case NL80211_IFTYPE_ADHOC:
6707 case NL80211_IFTYPE_P2P_CLIENT:
6708 case NL80211_IFTYPE_AP:
6709 case NL80211_IFTYPE_AP_VLAN:
6710 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006711 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006712 break;
6713 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006714 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006715 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006716
6717 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6718
Hila Gonene35e4d22012-06-27 17:19:42 +03006719 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006720}
6721
Kalle Valoffb9eb32010-02-17 17:58:10 +02006722static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6723{
Johannes Berg4c476992010-10-04 21:36:35 +02006724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006725 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006726 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006727 u8 ps_state;
6728 bool state;
6729 int err;
6730
Johannes Berg4c476992010-10-04 21:36:35 +02006731 if (!info->attrs[NL80211_ATTR_PS_STATE])
6732 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006733
6734 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6735
Johannes Berg4c476992010-10-04 21:36:35 +02006736 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6737 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006738
6739 wdev = dev->ieee80211_ptr;
6740
Johannes Berg4c476992010-10-04 21:36:35 +02006741 if (!rdev->ops->set_power_mgmt)
6742 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006743
6744 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6745
6746 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006747 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006748
Hila Gonene35e4d22012-06-27 17:19:42 +03006749 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02006750 if (!err)
6751 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006752 return err;
6753}
6754
6755static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6756{
Johannes Berg4c476992010-10-04 21:36:35 +02006757 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006758 enum nl80211_ps_state ps_state;
6759 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006760 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006761 struct sk_buff *msg;
6762 void *hdr;
6763 int err;
6764
Kalle Valoffb9eb32010-02-17 17:58:10 +02006765 wdev = dev->ieee80211_ptr;
6766
Johannes Berg4c476992010-10-04 21:36:35 +02006767 if (!rdev->ops->set_power_mgmt)
6768 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006769
6770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006771 if (!msg)
6772 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006773
Eric W. Biederman15e47302012-09-07 20:12:54 +00006774 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006775 NL80211_CMD_GET_POWER_SAVE);
6776 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006777 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006778 goto free_msg;
6779 }
6780
6781 if (wdev->ps)
6782 ps_state = NL80211_PS_ENABLED;
6783 else
6784 ps_state = NL80211_PS_DISABLED;
6785
David S. Miller9360ffd2012-03-29 04:41:26 -04006786 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6787 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006788
6789 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006790 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006791
Johannes Berg4c476992010-10-04 21:36:35 +02006792 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006793 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006794 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006795 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006796 return err;
6797}
6798
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006799static struct nla_policy
6800nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6801 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6802 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6803 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07006804 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6805 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6806 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006807};
6808
Thomas Pedersen84f10702012-07-12 16:17:33 -07006809static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01006810 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07006811{
6812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6813 struct wireless_dev *wdev;
6814 struct net_device *dev = info->user_ptr[1];
6815
Johannes Bergd9d8b012012-11-26 12:51:52 +01006816 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07006817 return -EINVAL;
6818
6819 wdev = dev->ieee80211_ptr;
6820
6821 if (!rdev->ops->set_cqm_txe_config)
6822 return -EOPNOTSUPP;
6823
6824 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6825 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6826 return -EOPNOTSUPP;
6827
Hila Gonene35e4d22012-06-27 17:19:42 +03006828 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07006829}
6830
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006831static int nl80211_set_cqm_rssi(struct genl_info *info,
6832 s32 threshold, u32 hysteresis)
6833{
Johannes Berg4c476992010-10-04 21:36:35 +02006834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006835 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006836 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006837
6838 if (threshold > 0)
6839 return -EINVAL;
6840
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006841 wdev = dev->ieee80211_ptr;
6842
Johannes Berg4c476992010-10-04 21:36:35 +02006843 if (!rdev->ops->set_cqm_rssi_config)
6844 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006845
Johannes Berg074ac8d2010-09-16 14:58:22 +02006846 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006847 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6848 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006849
Hila Gonene35e4d22012-06-27 17:19:42 +03006850 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006851}
6852
6853static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6854{
6855 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6856 struct nlattr *cqm;
6857 int err;
6858
6859 cqm = info->attrs[NL80211_ATTR_CQM];
6860 if (!cqm) {
6861 err = -EINVAL;
6862 goto out;
6863 }
6864
6865 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6866 nl80211_attr_cqm_policy);
6867 if (err)
6868 goto out;
6869
6870 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6871 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6872 s32 threshold;
6873 u32 hysteresis;
6874 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6875 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6876 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07006877 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
6878 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
6879 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
6880 u32 rate, pkts, intvl;
6881 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
6882 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
6883 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
6884 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006885 } else
6886 err = -EINVAL;
6887
6888out:
6889 return err;
6890}
6891
Johannes Berg29cbe682010-12-03 09:20:44 +01006892static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6893{
6894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6895 struct net_device *dev = info->user_ptr[1];
6896 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006897 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006898 int err;
6899
6900 /* start with default */
6901 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006902 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006903
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006904 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006905 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006906 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006907 if (err)
6908 return err;
6909 }
6910
6911 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6912 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6913 return -EINVAL;
6914
Javier Cardonac80d5452010-12-16 17:37:49 -08006915 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6916 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6917
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006918 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6919 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6920 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6921 return -EINVAL;
6922
Marco Porsch9bdbf042013-01-07 16:04:51 +01006923 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6924 setup.beacon_interval =
6925 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6926 if (setup.beacon_interval < 10 ||
6927 setup.beacon_interval > 10000)
6928 return -EINVAL;
6929 }
6930
6931 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
6932 setup.dtim_period =
6933 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
6934 if (setup.dtim_period < 1 || setup.dtim_period > 100)
6935 return -EINVAL;
6936 }
6937
Javier Cardonac80d5452010-12-16 17:37:49 -08006938 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6939 /* parse additional setup parameters if given */
6940 err = nl80211_parse_mesh_setup(info, &setup);
6941 if (err)
6942 return err;
6943 }
6944
Johannes Bergcc1d2802012-05-16 23:50:20 +02006945 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01006946 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
6947 if (err)
6948 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02006949 } else {
6950 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01006951 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02006952 }
6953
Javier Cardonac80d5452010-12-16 17:37:49 -08006954 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006955}
6956
6957static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6958{
6959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6960 struct net_device *dev = info->user_ptr[1];
6961
6962 return cfg80211_leave_mesh(rdev, dev);
6963}
6964
Johannes Bergdfb89c52012-06-27 09:23:48 +02006965#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08006966static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
6967 struct cfg80211_registered_device *rdev)
6968{
6969 struct nlattr *nl_pats, *nl_pat;
6970 int i, pat_len;
6971
6972 if (!rdev->wowlan->n_patterns)
6973 return 0;
6974
6975 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
6976 if (!nl_pats)
6977 return -ENOBUFS;
6978
6979 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6980 nl_pat = nla_nest_start(msg, i + 1);
6981 if (!nl_pat)
6982 return -ENOBUFS;
6983 pat_len = rdev->wowlan->patterns[i].pattern_len;
6984 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6985 DIV_ROUND_UP(pat_len, 8),
6986 rdev->wowlan->patterns[i].mask) ||
6987 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6988 pat_len, rdev->wowlan->patterns[i].pattern) ||
6989 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
6990 rdev->wowlan->patterns[i].pkt_offset))
6991 return -ENOBUFS;
6992 nla_nest_end(msg, nl_pat);
6993 }
6994 nla_nest_end(msg, nl_pats);
6995
6996 return 0;
6997}
6998
Johannes Berg2a0e0472013-01-23 22:57:40 +01006999static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7000 struct cfg80211_wowlan_tcp *tcp)
7001{
7002 struct nlattr *nl_tcp;
7003
7004 if (!tcp)
7005 return 0;
7006
7007 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7008 if (!nl_tcp)
7009 return -ENOBUFS;
7010
7011 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7012 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7013 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7014 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7015 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7016 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7017 tcp->payload_len, tcp->payload) ||
7018 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7019 tcp->data_interval) ||
7020 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7021 tcp->wake_len, tcp->wake_data) ||
7022 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7023 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7024 return -ENOBUFS;
7025
7026 if (tcp->payload_seq.len &&
7027 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7028 sizeof(tcp->payload_seq), &tcp->payload_seq))
7029 return -ENOBUFS;
7030
7031 if (tcp->payload_tok.len &&
7032 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7033 sizeof(tcp->payload_tok) + tcp->tokens_size,
7034 &tcp->payload_tok))
7035 return -ENOBUFS;
7036
7037 return 0;
7038}
7039
Johannes Bergff1b6e62011-05-04 15:37:28 +02007040static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7041{
7042 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7043 struct sk_buff *msg;
7044 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007045 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007046
Johannes Berg2a0e0472013-01-23 22:57:40 +01007047 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7048 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007049 return -EOPNOTSUPP;
7050
Johannes Berg2a0e0472013-01-23 22:57:40 +01007051 if (rdev->wowlan && rdev->wowlan->tcp) {
7052 /* adjust size to have room for all the data */
7053 size += rdev->wowlan->tcp->tokens_size +
7054 rdev->wowlan->tcp->payload_len +
7055 rdev->wowlan->tcp->wake_len +
7056 rdev->wowlan->tcp->wake_len / 8;
7057 }
7058
7059 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007060 if (!msg)
7061 return -ENOMEM;
7062
Eric W. Biederman15e47302012-09-07 20:12:54 +00007063 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007064 NL80211_CMD_GET_WOWLAN);
7065 if (!hdr)
7066 goto nla_put_failure;
7067
7068 if (rdev->wowlan) {
7069 struct nlattr *nl_wowlan;
7070
7071 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7072 if (!nl_wowlan)
7073 goto nla_put_failure;
7074
David S. Miller9360ffd2012-03-29 04:41:26 -04007075 if ((rdev->wowlan->any &&
7076 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7077 (rdev->wowlan->disconnect &&
7078 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7079 (rdev->wowlan->magic_pkt &&
7080 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7081 (rdev->wowlan->gtk_rekey_failure &&
7082 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7083 (rdev->wowlan->eap_identity_req &&
7084 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7085 (rdev->wowlan->four_way_handshake &&
7086 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7087 (rdev->wowlan->rfkill_release &&
7088 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7089 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007090
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007091 if (nl80211_send_wowlan_patterns(msg, rdev))
7092 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007093
7094 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7095 goto nla_put_failure;
7096
Johannes Bergff1b6e62011-05-04 15:37:28 +02007097 nla_nest_end(msg, nl_wowlan);
7098 }
7099
7100 genlmsg_end(msg, hdr);
7101 return genlmsg_reply(msg, info);
7102
7103nla_put_failure:
7104 nlmsg_free(msg);
7105 return -ENOBUFS;
7106}
7107
Johannes Berg2a0e0472013-01-23 22:57:40 +01007108static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7109 struct nlattr *attr,
7110 struct cfg80211_wowlan *trig)
7111{
7112 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7113 struct cfg80211_wowlan_tcp *cfg;
7114 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7115 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7116 u32 size;
7117 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7118 int err, port;
7119
7120 if (!rdev->wiphy.wowlan.tcp)
7121 return -EINVAL;
7122
7123 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7124 nla_data(attr), nla_len(attr),
7125 nl80211_wowlan_tcp_policy);
7126 if (err)
7127 return err;
7128
7129 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7130 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7131 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7132 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7133 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7134 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7135 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7136 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7137 return -EINVAL;
7138
7139 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7140 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7141 return -EINVAL;
7142
7143 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
7144 rdev->wiphy.wowlan.tcp->data_interval_max)
7145 return -EINVAL;
7146
7147 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7148 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7149 return -EINVAL;
7150
7151 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7152 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7153 return -EINVAL;
7154
7155 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7156 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7157
7158 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7159 tokens_size = tokln - sizeof(*tok);
7160
7161 if (!tok->len || tokens_size % tok->len)
7162 return -EINVAL;
7163 if (!rdev->wiphy.wowlan.tcp->tok)
7164 return -EINVAL;
7165 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7166 return -EINVAL;
7167 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7168 return -EINVAL;
7169 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7170 return -EINVAL;
7171 if (tok->offset + tok->len > data_size)
7172 return -EINVAL;
7173 }
7174
7175 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7176 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7177 if (!rdev->wiphy.wowlan.tcp->seq)
7178 return -EINVAL;
7179 if (seq->len == 0 || seq->len > 4)
7180 return -EINVAL;
7181 if (seq->len + seq->offset > data_size)
7182 return -EINVAL;
7183 }
7184
7185 size = sizeof(*cfg);
7186 size += data_size;
7187 size += wake_size + wake_mask_size;
7188 size += tokens_size;
7189
7190 cfg = kzalloc(size, GFP_KERNEL);
7191 if (!cfg)
7192 return -ENOMEM;
7193 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7194 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7195 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7196 ETH_ALEN);
7197 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7198 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7199 else
7200 port = 0;
7201#ifdef CONFIG_INET
7202 /* allocate a socket and port for it and use it */
7203 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7204 IPPROTO_TCP, &cfg->sock, 1);
7205 if (err) {
7206 kfree(cfg);
7207 return err;
7208 }
7209 if (inet_csk_get_port(cfg->sock->sk, port)) {
7210 sock_release(cfg->sock);
7211 kfree(cfg);
7212 return -EADDRINUSE;
7213 }
7214 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7215#else
7216 if (!port) {
7217 kfree(cfg);
7218 return -EINVAL;
7219 }
7220 cfg->src_port = port;
7221#endif
7222
7223 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7224 cfg->payload_len = data_size;
7225 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7226 memcpy((void *)cfg->payload,
7227 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7228 data_size);
7229 if (seq)
7230 cfg->payload_seq = *seq;
7231 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7232 cfg->wake_len = wake_size;
7233 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7234 memcpy((void *)cfg->wake_data,
7235 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7236 wake_size);
7237 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7238 data_size + wake_size;
7239 memcpy((void *)cfg->wake_mask,
7240 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7241 wake_mask_size);
7242 if (tok) {
7243 cfg->tokens_size = tokens_size;
7244 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7245 }
7246
7247 trig->tcp = cfg;
7248
7249 return 0;
7250}
7251
Johannes Bergff1b6e62011-05-04 15:37:28 +02007252static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7253{
7254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7255 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007256 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007257 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007258 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7259 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007260 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007261
Johannes Berg2a0e0472013-01-23 22:57:40 +01007262 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7263 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007264 return -EOPNOTSUPP;
7265
Johannes Bergae33bd82012-07-12 16:25:02 +02007266 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7267 cfg80211_rdev_free_wowlan(rdev);
7268 rdev->wowlan = NULL;
7269 goto set_wakeup;
7270 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007271
7272 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7273 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7274 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7275 nl80211_wowlan_policy);
7276 if (err)
7277 return err;
7278
7279 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7280 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7281 return -EINVAL;
7282 new_triggers.any = true;
7283 }
7284
7285 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7286 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7287 return -EINVAL;
7288 new_triggers.disconnect = true;
7289 }
7290
7291 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7292 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7293 return -EINVAL;
7294 new_triggers.magic_pkt = true;
7295 }
7296
Johannes Berg77dbbb132011-07-13 10:48:55 +02007297 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7298 return -EINVAL;
7299
7300 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7301 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7302 return -EINVAL;
7303 new_triggers.gtk_rekey_failure = true;
7304 }
7305
7306 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7307 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7308 return -EINVAL;
7309 new_triggers.eap_identity_req = true;
7310 }
7311
7312 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7313 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7314 return -EINVAL;
7315 new_triggers.four_way_handshake = true;
7316 }
7317
7318 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7319 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7320 return -EINVAL;
7321 new_triggers.rfkill_release = true;
7322 }
7323
Johannes Bergff1b6e62011-05-04 15:37:28 +02007324 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7325 struct nlattr *pat;
7326 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007327 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007328 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7329
7330 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7331 rem)
7332 n_patterns++;
7333 if (n_patterns > wowlan->n_patterns)
7334 return -EINVAL;
7335
7336 new_triggers.patterns = kcalloc(n_patterns,
7337 sizeof(new_triggers.patterns[0]),
7338 GFP_KERNEL);
7339 if (!new_triggers.patterns)
7340 return -ENOMEM;
7341
7342 new_triggers.n_patterns = n_patterns;
7343 i = 0;
7344
7345 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7346 rem) {
7347 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7348 nla_data(pat), nla_len(pat), NULL);
7349 err = -EINVAL;
7350 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7351 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7352 goto error;
7353 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7354 mask_len = DIV_ROUND_UP(pat_len, 8);
7355 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7356 mask_len)
7357 goto error;
7358 if (pat_len > wowlan->pattern_max_len ||
7359 pat_len < wowlan->pattern_min_len)
7360 goto error;
7361
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007362 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7363 pkt_offset = 0;
7364 else
7365 pkt_offset = nla_get_u32(
7366 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7367 if (pkt_offset > wowlan->max_pkt_offset)
7368 goto error;
7369 new_triggers.patterns[i].pkt_offset = pkt_offset;
7370
Johannes Bergff1b6e62011-05-04 15:37:28 +02007371 new_triggers.patterns[i].mask =
7372 kmalloc(mask_len + pat_len, GFP_KERNEL);
7373 if (!new_triggers.patterns[i].mask) {
7374 err = -ENOMEM;
7375 goto error;
7376 }
7377 new_triggers.patterns[i].pattern =
7378 new_triggers.patterns[i].mask + mask_len;
7379 memcpy(new_triggers.patterns[i].mask,
7380 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7381 mask_len);
7382 new_triggers.patterns[i].pattern_len = pat_len;
7383 memcpy(new_triggers.patterns[i].pattern,
7384 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7385 pat_len);
7386 i++;
7387 }
7388 }
7389
Johannes Berg2a0e0472013-01-23 22:57:40 +01007390 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7391 err = nl80211_parse_wowlan_tcp(
7392 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7393 &new_triggers);
7394 if (err)
7395 goto error;
7396 }
7397
Johannes Bergae33bd82012-07-12 16:25:02 +02007398 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7399 if (!ntrig) {
7400 err = -ENOMEM;
7401 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007402 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007403 cfg80211_rdev_free_wowlan(rdev);
7404 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007405
Johannes Bergae33bd82012-07-12 16:25:02 +02007406 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007407 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007408 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007409
Johannes Bergff1b6e62011-05-04 15:37:28 +02007410 return 0;
7411 error:
7412 for (i = 0; i < new_triggers.n_patterns; i++)
7413 kfree(new_triggers.patterns[i].mask);
7414 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007415 if (new_triggers.tcp && new_triggers.tcp->sock)
7416 sock_release(new_triggers.tcp->sock);
7417 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007418 return err;
7419}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007420#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007421
Johannes Berge5497d72011-07-05 16:35:40 +02007422static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7423{
7424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7425 struct net_device *dev = info->user_ptr[1];
7426 struct wireless_dev *wdev = dev->ieee80211_ptr;
7427 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7428 struct cfg80211_gtk_rekey_data rekey_data;
7429 int err;
7430
7431 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7432 return -EINVAL;
7433
7434 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7435 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7436 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7437 nl80211_rekey_policy);
7438 if (err)
7439 return err;
7440
7441 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7442 return -ERANGE;
7443 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7444 return -ERANGE;
7445 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7446 return -ERANGE;
7447
7448 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7449 NL80211_KEK_LEN);
7450 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7451 NL80211_KCK_LEN);
7452 memcpy(rekey_data.replay_ctr,
7453 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7454 NL80211_REPLAY_CTR_LEN);
7455
7456 wdev_lock(wdev);
7457 if (!wdev->current_bss) {
7458 err = -ENOTCONN;
7459 goto out;
7460 }
7461
7462 if (!rdev->ops->set_rekey_data) {
7463 err = -EOPNOTSUPP;
7464 goto out;
7465 }
7466
Hila Gonene35e4d22012-06-27 17:19:42 +03007467 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007468 out:
7469 wdev_unlock(wdev);
7470 return err;
7471}
7472
Johannes Berg28946da2011-11-04 11:18:12 +01007473static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7474 struct genl_info *info)
7475{
7476 struct net_device *dev = info->user_ptr[1];
7477 struct wireless_dev *wdev = dev->ieee80211_ptr;
7478
7479 if (wdev->iftype != NL80211_IFTYPE_AP &&
7480 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7481 return -EINVAL;
7482
Eric W. Biederman15e47302012-09-07 20:12:54 +00007483 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01007484 return -EBUSY;
7485
Eric W. Biederman15e47302012-09-07 20:12:54 +00007486 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01007487 return 0;
7488}
7489
Johannes Berg7f6cf312011-11-04 11:18:15 +01007490static int nl80211_probe_client(struct sk_buff *skb,
7491 struct genl_info *info)
7492{
7493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7494 struct net_device *dev = info->user_ptr[1];
7495 struct wireless_dev *wdev = dev->ieee80211_ptr;
7496 struct sk_buff *msg;
7497 void *hdr;
7498 const u8 *addr;
7499 u64 cookie;
7500 int err;
7501
7502 if (wdev->iftype != NL80211_IFTYPE_AP &&
7503 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7504 return -EOPNOTSUPP;
7505
7506 if (!info->attrs[NL80211_ATTR_MAC])
7507 return -EINVAL;
7508
7509 if (!rdev->ops->probe_client)
7510 return -EOPNOTSUPP;
7511
7512 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7513 if (!msg)
7514 return -ENOMEM;
7515
Eric W. Biederman15e47302012-09-07 20:12:54 +00007516 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01007517 NL80211_CMD_PROBE_CLIENT);
7518
7519 if (IS_ERR(hdr)) {
7520 err = PTR_ERR(hdr);
7521 goto free_msg;
7522 }
7523
7524 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7525
Hila Gonene35e4d22012-06-27 17:19:42 +03007526 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01007527 if (err)
7528 goto free_msg;
7529
David S. Miller9360ffd2012-03-29 04:41:26 -04007530 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7531 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01007532
7533 genlmsg_end(msg, hdr);
7534
7535 return genlmsg_reply(msg, info);
7536
7537 nla_put_failure:
7538 err = -ENOBUFS;
7539 free_msg:
7540 nlmsg_free(msg);
7541 return err;
7542}
7543
Johannes Berg5e760232011-11-04 11:18:17 +01007544static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
7545{
7546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07007547 struct cfg80211_beacon_registration *reg, *nreg;
7548 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01007549
7550 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
7551 return -EOPNOTSUPP;
7552
Ben Greear37c73b52012-10-26 14:49:25 -07007553 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
7554 if (!nreg)
7555 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01007556
Ben Greear37c73b52012-10-26 14:49:25 -07007557 /* First, check if already registered. */
7558 spin_lock_bh(&rdev->beacon_registrations_lock);
7559 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
7560 if (reg->nlportid == info->snd_portid) {
7561 rv = -EALREADY;
7562 goto out_err;
7563 }
7564 }
7565 /* Add it to the list */
7566 nreg->nlportid = info->snd_portid;
7567 list_add(&nreg->list, &rdev->beacon_registrations);
7568
7569 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01007570
7571 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07007572out_err:
7573 spin_unlock_bh(&rdev->beacon_registrations_lock);
7574 kfree(nreg);
7575 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01007576}
7577
Johannes Berg98104fde2012-06-16 00:19:54 +02007578static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
7579{
7580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7581 struct wireless_dev *wdev = info->user_ptr[1];
7582 int err;
7583
7584 if (!rdev->ops->start_p2p_device)
7585 return -EOPNOTSUPP;
7586
7587 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
7588 return -EOPNOTSUPP;
7589
7590 if (wdev->p2p_started)
7591 return 0;
7592
7593 mutex_lock(&rdev->devlist_mtx);
7594 err = cfg80211_can_add_interface(rdev, wdev->iftype);
7595 mutex_unlock(&rdev->devlist_mtx);
7596 if (err)
7597 return err;
7598
Johannes Bergeeb126e2012-10-23 15:16:50 +02007599 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02007600 if (err)
7601 return err;
7602
7603 wdev->p2p_started = true;
7604 mutex_lock(&rdev->devlist_mtx);
7605 rdev->opencount++;
7606 mutex_unlock(&rdev->devlist_mtx);
7607
7608 return 0;
7609}
7610
7611static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
7612{
7613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7614 struct wireless_dev *wdev = info->user_ptr[1];
7615
7616 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
7617 return -EOPNOTSUPP;
7618
7619 if (!rdev->ops->stop_p2p_device)
7620 return -EOPNOTSUPP;
7621
7622 if (!wdev->p2p_started)
7623 return 0;
7624
Johannes Bergeeb126e2012-10-23 15:16:50 +02007625 rdev_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02007626 wdev->p2p_started = false;
7627
7628 mutex_lock(&rdev->devlist_mtx);
7629 rdev->opencount--;
7630 mutex_unlock(&rdev->devlist_mtx);
7631
7632 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
7633 rdev->scan_req->aborted = true;
7634 ___cfg80211_scan_done(rdev, true);
7635 }
7636
7637 return 0;
7638}
7639
Johannes Berg4c476992010-10-04 21:36:35 +02007640#define NL80211_FLAG_NEED_WIPHY 0x01
7641#define NL80211_FLAG_NEED_NETDEV 0x02
7642#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02007643#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
7644#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
7645 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02007646#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02007647/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02007648#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
7649 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02007650
7651static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
7652 struct genl_info *info)
7653{
7654 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02007655 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007656 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02007657 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
7658
7659 if (rtnl)
7660 rtnl_lock();
7661
7662 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02007663 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02007664 if (IS_ERR(rdev)) {
7665 if (rtnl)
7666 rtnl_unlock();
7667 return PTR_ERR(rdev);
7668 }
7669 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02007670 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
7671 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02007672 mutex_lock(&cfg80211_mutex);
7673 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
7674 info->attrs);
7675 if (IS_ERR(wdev)) {
7676 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02007677 if (rtnl)
7678 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02007679 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007680 }
Johannes Berg89a54e42012-06-15 14:33:17 +02007681
Johannes Berg89a54e42012-06-15 14:33:17 +02007682 dev = wdev->netdev;
7683 rdev = wiphy_to_dev(wdev->wiphy);
7684
Johannes Berg1bf614e2012-06-15 15:23:36 +02007685 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
7686 if (!dev) {
7687 mutex_unlock(&cfg80211_mutex);
7688 if (rtnl)
7689 rtnl_unlock();
7690 return -EINVAL;
7691 }
7692
7693 info->user_ptr[1] = dev;
7694 } else {
7695 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02007696 }
Johannes Berg89a54e42012-06-15 14:33:17 +02007697
Johannes Berg1bf614e2012-06-15 15:23:36 +02007698 if (dev) {
7699 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
7700 !netif_running(dev)) {
7701 mutex_unlock(&cfg80211_mutex);
7702 if (rtnl)
7703 rtnl_unlock();
7704 return -ENETDOWN;
7705 }
7706
7707 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02007708 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
7709 if (!wdev->p2p_started) {
7710 mutex_unlock(&cfg80211_mutex);
7711 if (rtnl)
7712 rtnl_unlock();
7713 return -ENETDOWN;
7714 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02007715 }
7716
Johannes Berg89a54e42012-06-15 14:33:17 +02007717 cfg80211_lock_rdev(rdev);
7718
7719 mutex_unlock(&cfg80211_mutex);
7720
Johannes Berg4c476992010-10-04 21:36:35 +02007721 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007722 }
7723
7724 return 0;
7725}
7726
7727static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
7728 struct genl_info *info)
7729{
7730 if (info->user_ptr[0])
7731 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02007732 if (info->user_ptr[1]) {
7733 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7734 struct wireless_dev *wdev = info->user_ptr[1];
7735
7736 if (wdev->netdev)
7737 dev_put(wdev->netdev);
7738 } else {
7739 dev_put(info->user_ptr[1]);
7740 }
7741 }
Johannes Berg4c476992010-10-04 21:36:35 +02007742 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
7743 rtnl_unlock();
7744}
7745
Johannes Berg55682962007-09-20 13:09:35 -04007746static struct genl_ops nl80211_ops[] = {
7747 {
7748 .cmd = NL80211_CMD_GET_WIPHY,
7749 .doit = nl80211_get_wiphy,
7750 .dumpit = nl80211_dump_wiphy,
7751 .policy = nl80211_policy,
7752 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007753 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04007754 },
7755 {
7756 .cmd = NL80211_CMD_SET_WIPHY,
7757 .doit = nl80211_set_wiphy,
7758 .policy = nl80211_policy,
7759 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007760 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007761 },
7762 {
7763 .cmd = NL80211_CMD_GET_INTERFACE,
7764 .doit = nl80211_get_interface,
7765 .dumpit = nl80211_dump_interface,
7766 .policy = nl80211_policy,
7767 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02007768 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04007769 },
7770 {
7771 .cmd = NL80211_CMD_SET_INTERFACE,
7772 .doit = nl80211_set_interface,
7773 .policy = nl80211_policy,
7774 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007775 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7776 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007777 },
7778 {
7779 .cmd = NL80211_CMD_NEW_INTERFACE,
7780 .doit = nl80211_new_interface,
7781 .policy = nl80211_policy,
7782 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007783 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7784 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007785 },
7786 {
7787 .cmd = NL80211_CMD_DEL_INTERFACE,
7788 .doit = nl80211_del_interface,
7789 .policy = nl80211_policy,
7790 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02007791 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007792 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007793 },
Johannes Berg41ade002007-12-19 02:03:29 +01007794 {
7795 .cmd = NL80211_CMD_GET_KEY,
7796 .doit = nl80211_get_key,
7797 .policy = nl80211_policy,
7798 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007799 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007800 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007801 },
7802 {
7803 .cmd = NL80211_CMD_SET_KEY,
7804 .doit = nl80211_set_key,
7805 .policy = nl80211_policy,
7806 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007807 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007808 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007809 },
7810 {
7811 .cmd = NL80211_CMD_NEW_KEY,
7812 .doit = nl80211_new_key,
7813 .policy = nl80211_policy,
7814 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007815 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007816 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007817 },
7818 {
7819 .cmd = NL80211_CMD_DEL_KEY,
7820 .doit = nl80211_del_key,
7821 .policy = nl80211_policy,
7822 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007824 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007825 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01007826 {
7827 .cmd = NL80211_CMD_SET_BEACON,
7828 .policy = nl80211_policy,
7829 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007830 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007831 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007832 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007833 },
7834 {
Johannes Berg88600202012-02-13 15:17:18 +01007835 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007836 .policy = nl80211_policy,
7837 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007838 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007839 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007840 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007841 },
7842 {
Johannes Berg88600202012-02-13 15:17:18 +01007843 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007844 .policy = nl80211_policy,
7845 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007846 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007847 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007848 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007849 },
Johannes Berg5727ef12007-12-19 02:03:34 +01007850 {
7851 .cmd = NL80211_CMD_GET_STATION,
7852 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007853 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01007854 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02007855 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7856 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007857 },
7858 {
7859 .cmd = NL80211_CMD_SET_STATION,
7860 .doit = nl80211_set_station,
7861 .policy = nl80211_policy,
7862 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007863 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007864 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007865 },
7866 {
7867 .cmd = NL80211_CMD_NEW_STATION,
7868 .doit = nl80211_new_station,
7869 .policy = nl80211_policy,
7870 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007871 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007872 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007873 },
7874 {
7875 .cmd = NL80211_CMD_DEL_STATION,
7876 .doit = nl80211_del_station,
7877 .policy = nl80211_policy,
7878 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007879 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007880 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007881 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007882 {
7883 .cmd = NL80211_CMD_GET_MPATH,
7884 .doit = nl80211_get_mpath,
7885 .dumpit = nl80211_dump_mpath,
7886 .policy = nl80211_policy,
7887 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007888 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007889 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007890 },
7891 {
7892 .cmd = NL80211_CMD_SET_MPATH,
7893 .doit = nl80211_set_mpath,
7894 .policy = nl80211_policy,
7895 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007896 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007897 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007898 },
7899 {
7900 .cmd = NL80211_CMD_NEW_MPATH,
7901 .doit = nl80211_new_mpath,
7902 .policy = nl80211_policy,
7903 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007904 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007905 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007906 },
7907 {
7908 .cmd = NL80211_CMD_DEL_MPATH,
7909 .doit = nl80211_del_mpath,
7910 .policy = nl80211_policy,
7911 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007912 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007913 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007914 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007915 {
7916 .cmd = NL80211_CMD_SET_BSS,
7917 .doit = nl80211_set_bss,
7918 .policy = nl80211_policy,
7919 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007920 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007921 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007922 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007923 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007924 .cmd = NL80211_CMD_GET_REG,
7925 .doit = nl80211_get_reg,
7926 .policy = nl80211_policy,
7927 /* can be retrieved by unprivileged users */
7928 },
7929 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007930 .cmd = NL80211_CMD_SET_REG,
7931 .doit = nl80211_set_reg,
7932 .policy = nl80211_policy,
7933 .flags = GENL_ADMIN_PERM,
7934 },
7935 {
7936 .cmd = NL80211_CMD_REQ_SET_REG,
7937 .doit = nl80211_req_set_reg,
7938 .policy = nl80211_policy,
7939 .flags = GENL_ADMIN_PERM,
7940 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007941 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007942 .cmd = NL80211_CMD_GET_MESH_CONFIG,
7943 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007944 .policy = nl80211_policy,
7945 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007946 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007947 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007948 },
7949 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007950 .cmd = NL80211_CMD_SET_MESH_CONFIG,
7951 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007952 .policy = nl80211_policy,
7953 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01007954 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007955 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007956 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02007957 {
Johannes Berg2a519312009-02-10 21:25:55 +01007958 .cmd = NL80211_CMD_TRIGGER_SCAN,
7959 .doit = nl80211_trigger_scan,
7960 .policy = nl80211_policy,
7961 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02007962 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007963 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01007964 },
7965 {
7966 .cmd = NL80211_CMD_GET_SCAN,
7967 .policy = nl80211_policy,
7968 .dumpit = nl80211_dump_scan,
7969 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02007970 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007971 .cmd = NL80211_CMD_START_SCHED_SCAN,
7972 .doit = nl80211_start_sched_scan,
7973 .policy = nl80211_policy,
7974 .flags = GENL_ADMIN_PERM,
7975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7976 NL80211_FLAG_NEED_RTNL,
7977 },
7978 {
7979 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
7980 .doit = nl80211_stop_sched_scan,
7981 .policy = nl80211_policy,
7982 .flags = GENL_ADMIN_PERM,
7983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7984 NL80211_FLAG_NEED_RTNL,
7985 },
7986 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02007987 .cmd = NL80211_CMD_AUTHENTICATE,
7988 .doit = nl80211_authenticate,
7989 .policy = nl80211_policy,
7990 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007991 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007992 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007993 },
7994 {
7995 .cmd = NL80211_CMD_ASSOCIATE,
7996 .doit = nl80211_associate,
7997 .policy = nl80211_policy,
7998 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007999 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008000 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008001 },
8002 {
8003 .cmd = NL80211_CMD_DEAUTHENTICATE,
8004 .doit = nl80211_deauthenticate,
8005 .policy = nl80211_policy,
8006 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008007 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008008 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008009 },
8010 {
8011 .cmd = NL80211_CMD_DISASSOCIATE,
8012 .doit = nl80211_disassociate,
8013 .policy = nl80211_policy,
8014 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008016 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008017 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008018 {
8019 .cmd = NL80211_CMD_JOIN_IBSS,
8020 .doit = nl80211_join_ibss,
8021 .policy = nl80211_policy,
8022 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008024 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008025 },
8026 {
8027 .cmd = NL80211_CMD_LEAVE_IBSS,
8028 .doit = nl80211_leave_ibss,
8029 .policy = nl80211_policy,
8030 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008032 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008033 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008034#ifdef CONFIG_NL80211_TESTMODE
8035 {
8036 .cmd = NL80211_CMD_TESTMODE,
8037 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008038 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008039 .policy = nl80211_policy,
8040 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008041 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8042 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008043 },
8044#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008045 {
8046 .cmd = NL80211_CMD_CONNECT,
8047 .doit = nl80211_connect,
8048 .policy = nl80211_policy,
8049 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008050 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008051 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008052 },
8053 {
8054 .cmd = NL80211_CMD_DISCONNECT,
8055 .doit = nl80211_disconnect,
8056 .policy = nl80211_policy,
8057 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008058 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008059 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008060 },
Johannes Berg463d0182009-07-14 00:33:35 +02008061 {
8062 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8063 .doit = nl80211_wiphy_netns,
8064 .policy = nl80211_policy,
8065 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008066 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8067 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008068 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008069 {
8070 .cmd = NL80211_CMD_GET_SURVEY,
8071 .policy = nl80211_policy,
8072 .dumpit = nl80211_dump_survey,
8073 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008074 {
8075 .cmd = NL80211_CMD_SET_PMKSA,
8076 .doit = nl80211_setdel_pmksa,
8077 .policy = nl80211_policy,
8078 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008079 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008080 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008081 },
8082 {
8083 .cmd = NL80211_CMD_DEL_PMKSA,
8084 .doit = nl80211_setdel_pmksa,
8085 .policy = nl80211_policy,
8086 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008087 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008088 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008089 },
8090 {
8091 .cmd = NL80211_CMD_FLUSH_PMKSA,
8092 .doit = nl80211_flush_pmksa,
8093 .policy = nl80211_policy,
8094 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008095 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008096 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008097 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008098 {
8099 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8100 .doit = nl80211_remain_on_channel,
8101 .policy = nl80211_policy,
8102 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008103 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008104 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008105 },
8106 {
8107 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8108 .doit = nl80211_cancel_remain_on_channel,
8109 .policy = nl80211_policy,
8110 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008111 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008112 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008113 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008114 {
8115 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8116 .doit = nl80211_set_tx_bitrate_mask,
8117 .policy = nl80211_policy,
8118 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008119 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8120 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008121 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008122 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008123 .cmd = NL80211_CMD_REGISTER_FRAME,
8124 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008125 .policy = nl80211_policy,
8126 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008127 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008128 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008129 },
8130 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008131 .cmd = NL80211_CMD_FRAME,
8132 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008133 .policy = nl80211_policy,
8134 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008135 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008136 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008137 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008138 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008139 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8140 .doit = nl80211_tx_mgmt_cancel_wait,
8141 .policy = nl80211_policy,
8142 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008143 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008144 NL80211_FLAG_NEED_RTNL,
8145 },
8146 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008147 .cmd = NL80211_CMD_SET_POWER_SAVE,
8148 .doit = nl80211_set_power_save,
8149 .policy = nl80211_policy,
8150 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008151 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8152 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008153 },
8154 {
8155 .cmd = NL80211_CMD_GET_POWER_SAVE,
8156 .doit = nl80211_get_power_save,
8157 .policy = nl80211_policy,
8158 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008159 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8160 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008161 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008162 {
8163 .cmd = NL80211_CMD_SET_CQM,
8164 .doit = nl80211_set_cqm,
8165 .policy = nl80211_policy,
8166 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008167 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8168 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008169 },
Johannes Bergf444de02010-05-05 15:25:02 +02008170 {
8171 .cmd = NL80211_CMD_SET_CHANNEL,
8172 .doit = nl80211_set_channel,
8173 .policy = nl80211_policy,
8174 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008175 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8176 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008177 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008178 {
8179 .cmd = NL80211_CMD_SET_WDS_PEER,
8180 .doit = nl80211_set_wds_peer,
8181 .policy = nl80211_policy,
8182 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008183 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8184 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008185 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008186 {
8187 .cmd = NL80211_CMD_JOIN_MESH,
8188 .doit = nl80211_join_mesh,
8189 .policy = nl80211_policy,
8190 .flags = GENL_ADMIN_PERM,
8191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8192 NL80211_FLAG_NEED_RTNL,
8193 },
8194 {
8195 .cmd = NL80211_CMD_LEAVE_MESH,
8196 .doit = nl80211_leave_mesh,
8197 .policy = nl80211_policy,
8198 .flags = GENL_ADMIN_PERM,
8199 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8200 NL80211_FLAG_NEED_RTNL,
8201 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008202#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008203 {
8204 .cmd = NL80211_CMD_GET_WOWLAN,
8205 .doit = nl80211_get_wowlan,
8206 .policy = nl80211_policy,
8207 /* can be retrieved by unprivileged users */
8208 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8209 NL80211_FLAG_NEED_RTNL,
8210 },
8211 {
8212 .cmd = NL80211_CMD_SET_WOWLAN,
8213 .doit = nl80211_set_wowlan,
8214 .policy = nl80211_policy,
8215 .flags = GENL_ADMIN_PERM,
8216 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8217 NL80211_FLAG_NEED_RTNL,
8218 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008219#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008220 {
8221 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8222 .doit = nl80211_set_rekey_data,
8223 .policy = nl80211_policy,
8224 .flags = GENL_ADMIN_PERM,
8225 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8226 NL80211_FLAG_NEED_RTNL,
8227 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008228 {
8229 .cmd = NL80211_CMD_TDLS_MGMT,
8230 .doit = nl80211_tdls_mgmt,
8231 .policy = nl80211_policy,
8232 .flags = GENL_ADMIN_PERM,
8233 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8234 NL80211_FLAG_NEED_RTNL,
8235 },
8236 {
8237 .cmd = NL80211_CMD_TDLS_OPER,
8238 .doit = nl80211_tdls_oper,
8239 .policy = nl80211_policy,
8240 .flags = GENL_ADMIN_PERM,
8241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8242 NL80211_FLAG_NEED_RTNL,
8243 },
Johannes Berg28946da2011-11-04 11:18:12 +01008244 {
8245 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8246 .doit = nl80211_register_unexpected_frame,
8247 .policy = nl80211_policy,
8248 .flags = GENL_ADMIN_PERM,
8249 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8250 NL80211_FLAG_NEED_RTNL,
8251 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008252 {
8253 .cmd = NL80211_CMD_PROBE_CLIENT,
8254 .doit = nl80211_probe_client,
8255 .policy = nl80211_policy,
8256 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008258 NL80211_FLAG_NEED_RTNL,
8259 },
Johannes Berg5e760232011-11-04 11:18:17 +01008260 {
8261 .cmd = NL80211_CMD_REGISTER_BEACONS,
8262 .doit = nl80211_register_beacons,
8263 .policy = nl80211_policy,
8264 .flags = GENL_ADMIN_PERM,
8265 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8266 NL80211_FLAG_NEED_RTNL,
8267 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008268 {
8269 .cmd = NL80211_CMD_SET_NOACK_MAP,
8270 .doit = nl80211_set_noack_map,
8271 .policy = nl80211_policy,
8272 .flags = GENL_ADMIN_PERM,
8273 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8274 NL80211_FLAG_NEED_RTNL,
8275 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008276 {
8277 .cmd = NL80211_CMD_START_P2P_DEVICE,
8278 .doit = nl80211_start_p2p_device,
8279 .policy = nl80211_policy,
8280 .flags = GENL_ADMIN_PERM,
8281 .internal_flags = NL80211_FLAG_NEED_WDEV |
8282 NL80211_FLAG_NEED_RTNL,
8283 },
8284 {
8285 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8286 .doit = nl80211_stop_p2p_device,
8287 .policy = nl80211_policy,
8288 .flags = GENL_ADMIN_PERM,
8289 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8290 NL80211_FLAG_NEED_RTNL,
8291 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008292 {
8293 .cmd = NL80211_CMD_SET_MCAST_RATE,
8294 .doit = nl80211_set_mcast_rate,
8295 .policy = nl80211_policy,
8296 .flags = GENL_ADMIN_PERM,
8297 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8298 NL80211_FLAG_NEED_RTNL,
8299 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308300 {
8301 .cmd = NL80211_CMD_SET_MAC_ACL,
8302 .doit = nl80211_set_mac_acl,
8303 .policy = nl80211_policy,
8304 .flags = GENL_ADMIN_PERM,
8305 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8306 NL80211_FLAG_NEED_RTNL,
8307 },
Johannes Berg55682962007-09-20 13:09:35 -04008308};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008309
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008310static struct genl_multicast_group nl80211_mlme_mcgrp = {
8311 .name = "mlme",
8312};
Johannes Berg55682962007-09-20 13:09:35 -04008313
8314/* multicast groups */
8315static struct genl_multicast_group nl80211_config_mcgrp = {
8316 .name = "config",
8317};
Johannes Berg2a519312009-02-10 21:25:55 +01008318static struct genl_multicast_group nl80211_scan_mcgrp = {
8319 .name = "scan",
8320};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008321static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8322 .name = "regulatory",
8323};
Johannes Berg55682962007-09-20 13:09:35 -04008324
8325/* notification functions */
8326
8327void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8328{
8329 struct sk_buff *msg;
8330
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008331 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008332 if (!msg)
8333 return;
8334
8335 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
8336 nlmsg_free(msg);
8337 return;
8338 }
8339
Johannes Berg463d0182009-07-14 00:33:35 +02008340 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8341 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008342}
8343
Johannes Berg362a4152009-05-24 16:43:15 +02008344static int nl80211_add_scan_req(struct sk_buff *msg,
8345 struct cfg80211_registered_device *rdev)
8346{
8347 struct cfg80211_scan_request *req = rdev->scan_req;
8348 struct nlattr *nest;
8349 int i;
8350
Johannes Berg667503d2009-07-07 03:56:11 +02008351 ASSERT_RDEV_LOCK(rdev);
8352
Johannes Berg362a4152009-05-24 16:43:15 +02008353 if (WARN_ON(!req))
8354 return 0;
8355
8356 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8357 if (!nest)
8358 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008359 for (i = 0; i < req->n_ssids; i++) {
8360 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8361 goto nla_put_failure;
8362 }
Johannes Berg362a4152009-05-24 16:43:15 +02008363 nla_nest_end(msg, nest);
8364
8365 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8366 if (!nest)
8367 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008368 for (i = 0; i < req->n_channels; i++) {
8369 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8370 goto nla_put_failure;
8371 }
Johannes Berg362a4152009-05-24 16:43:15 +02008372 nla_nest_end(msg, nest);
8373
David S. Miller9360ffd2012-03-29 04:41:26 -04008374 if (req->ie &&
8375 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8376 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02008377
Sam Lefflered4737712012-10-11 21:03:31 -07008378 if (req->flags)
8379 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8380
Johannes Berg362a4152009-05-24 16:43:15 +02008381 return 0;
8382 nla_put_failure:
8383 return -ENOBUFS;
8384}
8385
Johannes Berga538e2d2009-06-16 19:56:42 +02008386static int nl80211_send_scan_msg(struct sk_buff *msg,
8387 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008388 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008389 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02008390 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01008391{
8392 void *hdr;
8393
Eric W. Biederman15e47302012-09-07 20:12:54 +00008394 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01008395 if (!hdr)
8396 return -1;
8397
David S. Miller9360ffd2012-03-29 04:41:26 -04008398 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02008399 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8400 wdev->netdev->ifindex)) ||
8401 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008402 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008403
Johannes Berg362a4152009-05-24 16:43:15 +02008404 /* ignore errors and send incomplete event anyway */
8405 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008406
8407 return genlmsg_end(msg, hdr);
8408
8409 nla_put_failure:
8410 genlmsg_cancel(msg, hdr);
8411 return -EMSGSIZE;
8412}
8413
Luciano Coelho807f8a82011-05-11 17:09:35 +03008414static int
8415nl80211_send_sched_scan_msg(struct sk_buff *msg,
8416 struct cfg80211_registered_device *rdev,
8417 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008418 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008419{
8420 void *hdr;
8421
Eric W. Biederman15e47302012-09-07 20:12:54 +00008422 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008423 if (!hdr)
8424 return -1;
8425
David S. Miller9360ffd2012-03-29 04:41:26 -04008426 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8427 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8428 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008429
8430 return genlmsg_end(msg, hdr);
8431
8432 nla_put_failure:
8433 genlmsg_cancel(msg, hdr);
8434 return -EMSGSIZE;
8435}
8436
Johannes Berga538e2d2009-06-16 19:56:42 +02008437void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008438 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02008439{
8440 struct sk_buff *msg;
8441
Thomas Graf58050fc2012-06-28 03:57:45 +00008442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008443 if (!msg)
8444 return;
8445
Johannes Bergfd014282012-06-18 19:17:03 +02008446 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008447 NL80211_CMD_TRIGGER_SCAN) < 0) {
8448 nlmsg_free(msg);
8449 return;
8450 }
8451
Johannes Berg463d0182009-07-14 00:33:35 +02008452 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8453 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02008454}
8455
Johannes Berg2a519312009-02-10 21:25:55 +01008456void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008457 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01008458{
8459 struct sk_buff *msg;
8460
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008461 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008462 if (!msg)
8463 return;
8464
Johannes Bergfd014282012-06-18 19:17:03 +02008465 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008466 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008467 nlmsg_free(msg);
8468 return;
8469 }
8470
Johannes Berg463d0182009-07-14 00:33:35 +02008471 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8472 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008473}
8474
8475void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02008476 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01008477{
8478 struct sk_buff *msg;
8479
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008480 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008481 if (!msg)
8482 return;
8483
Johannes Bergfd014282012-06-18 19:17:03 +02008484 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02008485 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008486 nlmsg_free(msg);
8487 return;
8488 }
8489
Johannes Berg463d0182009-07-14 00:33:35 +02008490 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8491 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01008492}
8493
Luciano Coelho807f8a82011-05-11 17:09:35 +03008494void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
8495 struct net_device *netdev)
8496{
8497 struct sk_buff *msg;
8498
8499 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8500 if (!msg)
8501 return;
8502
8503 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
8504 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
8505 nlmsg_free(msg);
8506 return;
8507 }
8508
8509 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8510 nl80211_scan_mcgrp.id, GFP_KERNEL);
8511}
8512
8513void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
8514 struct net_device *netdev, u32 cmd)
8515{
8516 struct sk_buff *msg;
8517
Thomas Graf58050fc2012-06-28 03:57:45 +00008518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008519 if (!msg)
8520 return;
8521
8522 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
8523 nlmsg_free(msg);
8524 return;
8525 }
8526
8527 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8528 nl80211_scan_mcgrp.id, GFP_KERNEL);
8529}
8530
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008531/*
8532 * This can happen on global regulatory changes or device specific settings
8533 * based on custom world regulatory domains.
8534 */
8535void nl80211_send_reg_change_event(struct regulatory_request *request)
8536{
8537 struct sk_buff *msg;
8538 void *hdr;
8539
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008540 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008541 if (!msg)
8542 return;
8543
8544 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
8545 if (!hdr) {
8546 nlmsg_free(msg);
8547 return;
8548 }
8549
8550 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04008551 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
8552 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008553
David S. Miller9360ffd2012-03-29 04:41:26 -04008554 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
8555 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8556 NL80211_REGDOM_TYPE_WORLD))
8557 goto nla_put_failure;
8558 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
8559 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8560 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
8561 goto nla_put_failure;
8562 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
8563 request->intersect) {
8564 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8565 NL80211_REGDOM_TYPE_INTERSECTION))
8566 goto nla_put_failure;
8567 } else {
8568 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8569 NL80211_REGDOM_TYPE_COUNTRY) ||
8570 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
8571 request->alpha2))
8572 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008573 }
8574
Johannes Bergf4173762012-12-03 18:23:37 +01008575 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008576 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
8577 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008578
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008579 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008580
Johannes Bergbc43b282009-07-25 10:54:13 +02008581 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02008582 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02008583 GFP_ATOMIC);
8584 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008585
8586 return;
8587
8588nla_put_failure:
8589 genlmsg_cancel(msg, hdr);
8590 nlmsg_free(msg);
8591}
8592
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008593static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
8594 struct net_device *netdev,
8595 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02008596 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008597{
8598 struct sk_buff *msg;
8599 void *hdr;
8600
Johannes Berge6d6e342009-07-01 21:26:47 +02008601 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008602 if (!msg)
8603 return;
8604
8605 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8606 if (!hdr) {
8607 nlmsg_free(msg);
8608 return;
8609 }
8610
David S. Miller9360ffd2012-03-29 04:41:26 -04008611 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8612 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8613 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8614 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008615
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008616 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008617
Johannes Berg463d0182009-07-14 00:33:35 +02008618 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8619 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008620 return;
8621
8622 nla_put_failure:
8623 genlmsg_cancel(msg, hdr);
8624 nlmsg_free(msg);
8625}
8626
8627void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02008628 struct net_device *netdev, const u8 *buf,
8629 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008630{
8631 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02008632 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008633}
8634
8635void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
8636 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02008637 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008638{
Johannes Berge6d6e342009-07-01 21:26:47 +02008639 nl80211_send_mlme_event(rdev, netdev, buf, len,
8640 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008641}
8642
Jouni Malinen53b46b82009-03-27 20:53:56 +02008643void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02008644 struct net_device *netdev, const u8 *buf,
8645 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008646{
8647 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02008648 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008649}
8650
Jouni Malinen53b46b82009-03-27 20:53:56 +02008651void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
8652 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02008653 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008654{
8655 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02008656 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008657}
8658
Jouni Malinencf4e5942010-12-16 00:52:40 +02008659void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
8660 struct net_device *netdev, const u8 *buf,
8661 size_t len, gfp_t gfp)
8662{
8663 nl80211_send_mlme_event(rdev, netdev, buf, len,
8664 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
8665}
8666
8667void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
8668 struct net_device *netdev, const u8 *buf,
8669 size_t len, gfp_t gfp)
8670{
8671 nl80211_send_mlme_event(rdev, netdev, buf, len,
8672 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
8673}
8674
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04008675static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
8676 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02008677 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03008678{
8679 struct sk_buff *msg;
8680 void *hdr;
8681
Johannes Berge6d6e342009-07-01 21:26:47 +02008682 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008683 if (!msg)
8684 return;
8685
8686 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8687 if (!hdr) {
8688 nlmsg_free(msg);
8689 return;
8690 }
8691
David S. Miller9360ffd2012-03-29 04:41:26 -04008692 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8693 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8694 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
8695 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8696 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03008697
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008698 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03008699
Johannes Berg463d0182009-07-14 00:33:35 +02008700 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8701 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008702 return;
8703
8704 nla_put_failure:
8705 genlmsg_cancel(msg, hdr);
8706 nlmsg_free(msg);
8707}
8708
8709void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02008710 struct net_device *netdev, const u8 *addr,
8711 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03008712{
8713 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02008714 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008715}
8716
8717void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02008718 struct net_device *netdev, const u8 *addr,
8719 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03008720{
Johannes Berge6d6e342009-07-01 21:26:47 +02008721 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
8722 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008723}
8724
Samuel Ortizb23aa672009-07-01 21:26:54 +02008725void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
8726 struct net_device *netdev, const u8 *bssid,
8727 const u8 *req_ie, size_t req_ie_len,
8728 const u8 *resp_ie, size_t resp_ie_len,
8729 u16 status, gfp_t gfp)
8730{
8731 struct sk_buff *msg;
8732 void *hdr;
8733
Thomas Graf58050fc2012-06-28 03:57:45 +00008734 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008735 if (!msg)
8736 return;
8737
8738 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
8739 if (!hdr) {
8740 nlmsg_free(msg);
8741 return;
8742 }
8743
David S. Miller9360ffd2012-03-29 04:41:26 -04008744 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8745 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8746 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
8747 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
8748 (req_ie &&
8749 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8750 (resp_ie &&
8751 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8752 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008753
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008754 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008755
Johannes Berg463d0182009-07-14 00:33:35 +02008756 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8757 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008758 return;
8759
8760 nla_put_failure:
8761 genlmsg_cancel(msg, hdr);
8762 nlmsg_free(msg);
8763
8764}
8765
8766void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
8767 struct net_device *netdev, const u8 *bssid,
8768 const u8 *req_ie, size_t req_ie_len,
8769 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
8770{
8771 struct sk_buff *msg;
8772 void *hdr;
8773
Thomas Graf58050fc2012-06-28 03:57:45 +00008774 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008775 if (!msg)
8776 return;
8777
8778 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
8779 if (!hdr) {
8780 nlmsg_free(msg);
8781 return;
8782 }
8783
David S. Miller9360ffd2012-03-29 04:41:26 -04008784 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8785 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8786 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
8787 (req_ie &&
8788 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8789 (resp_ie &&
8790 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8791 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008792
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008793 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008794
Johannes Berg463d0182009-07-14 00:33:35 +02008795 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8796 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008797 return;
8798
8799 nla_put_failure:
8800 genlmsg_cancel(msg, hdr);
8801 nlmsg_free(msg);
8802
8803}
8804
8805void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
8806 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02008807 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008808{
8809 struct sk_buff *msg;
8810 void *hdr;
8811
Thomas Graf58050fc2012-06-28 03:57:45 +00008812 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008813 if (!msg)
8814 return;
8815
8816 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
8817 if (!hdr) {
8818 nlmsg_free(msg);
8819 return;
8820 }
8821
David S. Miller9360ffd2012-03-29 04:41:26 -04008822 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8823 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8824 (from_ap && reason &&
8825 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
8826 (from_ap &&
8827 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
8828 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
8829 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008830
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008831 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008832
Johannes Berg463d0182009-07-14 00:33:35 +02008833 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8834 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008835 return;
8836
8837 nla_put_failure:
8838 genlmsg_cancel(msg, hdr);
8839 nlmsg_free(msg);
8840
8841}
8842
Johannes Berg04a773a2009-04-19 21:24:32 +02008843void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
8844 struct net_device *netdev, const u8 *bssid,
8845 gfp_t gfp)
8846{
8847 struct sk_buff *msg;
8848 void *hdr;
8849
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008851 if (!msg)
8852 return;
8853
8854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
8855 if (!hdr) {
8856 nlmsg_free(msg);
8857 return;
8858 }
8859
David S. Miller9360ffd2012-03-29 04:41:26 -04008860 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8861 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8862 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8863 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02008864
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008865 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02008866
Johannes Berg463d0182009-07-14 00:33:35 +02008867 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8868 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008869 return;
8870
8871 nla_put_failure:
8872 genlmsg_cancel(msg, hdr);
8873 nlmsg_free(msg);
8874}
8875
Javier Cardonac93b5e72011-04-07 15:08:34 -07008876void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
8877 struct net_device *netdev,
8878 const u8 *macaddr, const u8* ie, u8 ie_len,
8879 gfp_t gfp)
8880{
8881 struct sk_buff *msg;
8882 void *hdr;
8883
8884 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8885 if (!msg)
8886 return;
8887
8888 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
8889 if (!hdr) {
8890 nlmsg_free(msg);
8891 return;
8892 }
8893
David S. Miller9360ffd2012-03-29 04:41:26 -04008894 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8895 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8896 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
8897 (ie_len && ie &&
8898 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
8899 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07008900
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008901 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07008902
8903 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8904 nl80211_mlme_mcgrp.id, gfp);
8905 return;
8906
8907 nla_put_failure:
8908 genlmsg_cancel(msg, hdr);
8909 nlmsg_free(msg);
8910}
8911
Jouni Malinena3b8b052009-03-27 21:59:49 +02008912void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
8913 struct net_device *netdev, const u8 *addr,
8914 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02008915 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02008916{
8917 struct sk_buff *msg;
8918 void *hdr;
8919
Johannes Berge6d6e342009-07-01 21:26:47 +02008920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008921 if (!msg)
8922 return;
8923
8924 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
8925 if (!hdr) {
8926 nlmsg_free(msg);
8927 return;
8928 }
8929
David S. Miller9360ffd2012-03-29 04:41:26 -04008930 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8931 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8932 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
8933 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
8934 (key_id != -1 &&
8935 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
8936 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
8937 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02008938
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008939 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008940
Johannes Berg463d0182009-07-14 00:33:35 +02008941 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8942 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008943 return;
8944
8945 nla_put_failure:
8946 genlmsg_cancel(msg, hdr);
8947 nlmsg_free(msg);
8948}
8949
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008950void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
8951 struct ieee80211_channel *channel_before,
8952 struct ieee80211_channel *channel_after)
8953{
8954 struct sk_buff *msg;
8955 void *hdr;
8956 struct nlattr *nl_freq;
8957
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008958 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008959 if (!msg)
8960 return;
8961
8962 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
8963 if (!hdr) {
8964 nlmsg_free(msg);
8965 return;
8966 }
8967
8968 /*
8969 * Since we are applying the beacon hint to a wiphy we know its
8970 * wiphy_idx is valid
8971 */
David S. Miller9360ffd2012-03-29 04:41:26 -04008972 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8973 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008974
8975 /* Before */
8976 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
8977 if (!nl_freq)
8978 goto nla_put_failure;
8979 if (nl80211_msg_put_channel(msg, channel_before))
8980 goto nla_put_failure;
8981 nla_nest_end(msg, nl_freq);
8982
8983 /* After */
8984 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
8985 if (!nl_freq)
8986 goto nla_put_failure;
8987 if (nl80211_msg_put_channel(msg, channel_after))
8988 goto nla_put_failure;
8989 nla_nest_end(msg, nl_freq);
8990
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008991 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008992
Johannes Berg463d0182009-07-14 00:33:35 +02008993 rcu_read_lock();
8994 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8995 GFP_ATOMIC);
8996 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008997
8998 return;
8999
9000nla_put_failure:
9001 genlmsg_cancel(msg, hdr);
9002 nlmsg_free(msg);
9003}
9004
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009005static void nl80211_send_remain_on_chan_event(
9006 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009007 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009008 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009009 unsigned int duration, gfp_t gfp)
9010{
9011 struct sk_buff *msg;
9012 void *hdr;
9013
9014 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9015 if (!msg)
9016 return;
9017
9018 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9019 if (!hdr) {
9020 nlmsg_free(msg);
9021 return;
9022 }
9023
David S. Miller9360ffd2012-03-29 04:41:26 -04009024 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009025 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9026 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009027 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009028 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009029 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9030 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009031 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9032 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009033
David S. Miller9360ffd2012-03-29 04:41:26 -04009034 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9035 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9036 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009037
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009038 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009039
9040 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9041 nl80211_mlme_mcgrp.id, gfp);
9042 return;
9043
9044 nla_put_failure:
9045 genlmsg_cancel(msg, hdr);
9046 nlmsg_free(msg);
9047}
9048
9049void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009050 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009051 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009052 unsigned int duration, gfp_t gfp)
9053{
9054 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009055 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009056 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009057}
9058
9059void nl80211_send_remain_on_channel_cancel(
Johannes Berg71bbc992012-06-15 15:30:18 +02009060 struct cfg80211_registered_device *rdev,
9061 struct wireless_dev *wdev,
Johannes Berg42d97a52012-11-08 18:31:02 +01009062 u64 cookie, struct ieee80211_channel *chan, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009063{
9064 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009065 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009066}
9067
Johannes Berg98b62182009-12-23 13:15:44 +01009068void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
9069 struct net_device *dev, const u8 *mac_addr,
9070 struct station_info *sinfo, gfp_t gfp)
9071{
9072 struct sk_buff *msg;
9073
Thomas Graf58050fc2012-06-28 03:57:45 +00009074 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009075 if (!msg)
9076 return;
9077
John W. Linville66266b32012-03-15 13:25:41 -04009078 if (nl80211_send_station(msg, 0, 0, 0,
9079 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009080 nlmsg_free(msg);
9081 return;
9082 }
9083
9084 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9085 nl80211_mlme_mcgrp.id, gfp);
9086}
9087
Jouni Malinenec15e682011-03-23 15:29:52 +02009088void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
9089 struct net_device *dev, const u8 *mac_addr,
9090 gfp_t gfp)
9091{
9092 struct sk_buff *msg;
9093 void *hdr;
9094
Thomas Graf58050fc2012-06-28 03:57:45 +00009095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009096 if (!msg)
9097 return;
9098
9099 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9100 if (!hdr) {
9101 nlmsg_free(msg);
9102 return;
9103 }
9104
David S. Miller9360ffd2012-03-29 04:41:26 -04009105 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9106 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9107 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009108
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009109 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009110
9111 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9112 nl80211_mlme_mcgrp.id, gfp);
9113 return;
9114
9115 nla_put_failure:
9116 genlmsg_cancel(msg, hdr);
9117 nlmsg_free(msg);
9118}
9119
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309120void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
9121 struct net_device *dev, const u8 *mac_addr,
9122 enum nl80211_connect_failed_reason reason,
9123 gfp_t gfp)
9124{
9125 struct sk_buff *msg;
9126 void *hdr;
9127
9128 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9129 if (!msg)
9130 return;
9131
9132 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9133 if (!hdr) {
9134 nlmsg_free(msg);
9135 return;
9136 }
9137
9138 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9139 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9140 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9141 goto nla_put_failure;
9142
9143 genlmsg_end(msg, hdr);
9144
9145 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9146 nl80211_mlme_mcgrp.id, gfp);
9147 return;
9148
9149 nla_put_failure:
9150 genlmsg_cancel(msg, hdr);
9151 nlmsg_free(msg);
9152}
9153
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009154static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9155 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009156{
9157 struct wireless_dev *wdev = dev->ieee80211_ptr;
9158 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9159 struct sk_buff *msg;
9160 void *hdr;
9161 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009162 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009163
Eric W. Biederman15e47302012-09-07 20:12:54 +00009164 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009165 return false;
9166
9167 msg = nlmsg_new(100, gfp);
9168 if (!msg)
9169 return true;
9170
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009171 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009172 if (!hdr) {
9173 nlmsg_free(msg);
9174 return true;
9175 }
9176
David S. Miller9360ffd2012-03-29 04:41:26 -04009177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9178 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9179 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9180 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009181
9182 err = genlmsg_end(msg, hdr);
9183 if (err < 0) {
9184 nlmsg_free(msg);
9185 return true;
9186 }
9187
Eric W. Biederman15e47302012-09-07 20:12:54 +00009188 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009189 return true;
9190
9191 nla_put_failure:
9192 genlmsg_cancel(msg, hdr);
9193 nlmsg_free(msg);
9194 return true;
9195}
9196
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009197bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
9198{
9199 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9200 addr, gfp);
9201}
9202
9203bool nl80211_unexpected_4addr_frame(struct net_device *dev,
9204 const u8 *addr, gfp_t gfp)
9205{
9206 return __nl80211_unexpected_frame(dev,
9207 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9208 addr, gfp);
9209}
9210
Johannes Berg2e161f72010-08-12 15:38:38 +02009211int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009212 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009213 int freq, int sig_dbm,
9214 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009215{
Johannes Berg71bbc992012-06-15 15:30:18 +02009216 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009217 struct sk_buff *msg;
9218 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009219
9220 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9221 if (!msg)
9222 return -ENOMEM;
9223
Johannes Berg2e161f72010-08-12 15:38:38 +02009224 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009225 if (!hdr) {
9226 nlmsg_free(msg);
9227 return -ENOMEM;
9228 }
9229
David S. Miller9360ffd2012-03-29 04:41:26 -04009230 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009231 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9232 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009233 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9234 (sig_dbm &&
9235 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9236 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9237 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009238
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009239 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009240
Eric W. Biederman15e47302012-09-07 20:12:54 +00009241 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009242
9243 nla_put_failure:
9244 genlmsg_cancel(msg, hdr);
9245 nlmsg_free(msg);
9246 return -ENOBUFS;
9247}
9248
Johannes Berg2e161f72010-08-12 15:38:38 +02009249void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009250 struct wireless_dev *wdev, u64 cookie,
Johannes Berg2e161f72010-08-12 15:38:38 +02009251 const u8 *buf, size_t len, bool ack,
9252 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009253{
Johannes Berg71bbc992012-06-15 15:30:18 +02009254 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009255 struct sk_buff *msg;
9256 void *hdr;
9257
9258 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9259 if (!msg)
9260 return;
9261
Johannes Berg2e161f72010-08-12 15:38:38 +02009262 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009263 if (!hdr) {
9264 nlmsg_free(msg);
9265 return;
9266 }
9267
David S. Miller9360ffd2012-03-29 04:41:26 -04009268 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009269 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9270 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009271 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9272 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9273 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9274 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009275
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009276 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009277
9278 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9279 return;
9280
9281 nla_put_failure:
9282 genlmsg_cancel(msg, hdr);
9283 nlmsg_free(msg);
9284}
9285
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009286void
9287nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
9288 struct net_device *netdev,
9289 enum nl80211_cqm_rssi_threshold_event rssi_event,
9290 gfp_t gfp)
9291{
9292 struct sk_buff *msg;
9293 struct nlattr *pinfoattr;
9294 void *hdr;
9295
Thomas Graf58050fc2012-06-28 03:57:45 +00009296 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009297 if (!msg)
9298 return;
9299
9300 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9301 if (!hdr) {
9302 nlmsg_free(msg);
9303 return;
9304 }
9305
David S. Miller9360ffd2012-03-29 04:41:26 -04009306 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9307 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9308 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009309
9310 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9311 if (!pinfoattr)
9312 goto nla_put_failure;
9313
David S. Miller9360ffd2012-03-29 04:41:26 -04009314 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9315 rssi_event))
9316 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009317
9318 nla_nest_end(msg, pinfoattr);
9319
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009320 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009321
9322 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9323 nl80211_mlme_mcgrp.id, gfp);
9324 return;
9325
9326 nla_put_failure:
9327 genlmsg_cancel(msg, hdr);
9328 nlmsg_free(msg);
9329}
9330
Johannes Berge5497d72011-07-05 16:35:40 +02009331void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9332 struct net_device *netdev, const u8 *bssid,
9333 const u8 *replay_ctr, gfp_t gfp)
9334{
9335 struct sk_buff *msg;
9336 struct nlattr *rekey_attr;
9337 void *hdr;
9338
Thomas Graf58050fc2012-06-28 03:57:45 +00009339 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02009340 if (!msg)
9341 return;
9342
9343 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9344 if (!hdr) {
9345 nlmsg_free(msg);
9346 return;
9347 }
9348
David S. Miller9360ffd2012-03-29 04:41:26 -04009349 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9350 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9351 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9352 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009353
9354 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9355 if (!rekey_attr)
9356 goto nla_put_failure;
9357
David S. Miller9360ffd2012-03-29 04:41:26 -04009358 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9359 NL80211_REPLAY_CTR_LEN, replay_ctr))
9360 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02009361
9362 nla_nest_end(msg, rekey_attr);
9363
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009364 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02009365
9366 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9367 nl80211_mlme_mcgrp.id, gfp);
9368 return;
9369
9370 nla_put_failure:
9371 genlmsg_cancel(msg, hdr);
9372 nlmsg_free(msg);
9373}
9374
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009375void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
9376 struct net_device *netdev, int index,
9377 const u8 *bssid, bool preauth, gfp_t gfp)
9378{
9379 struct sk_buff *msg;
9380 struct nlattr *attr;
9381 void *hdr;
9382
Thomas Graf58050fc2012-06-28 03:57:45 +00009383 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009384 if (!msg)
9385 return;
9386
9387 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
9388 if (!hdr) {
9389 nlmsg_free(msg);
9390 return;
9391 }
9392
David S. Miller9360ffd2012-03-29 04:41:26 -04009393 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9394 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9395 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009396
9397 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
9398 if (!attr)
9399 goto nla_put_failure;
9400
David S. Miller9360ffd2012-03-29 04:41:26 -04009401 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
9402 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
9403 (preauth &&
9404 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
9405 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009406
9407 nla_nest_end(msg, attr);
9408
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009409 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03009410
9411 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9412 nl80211_mlme_mcgrp.id, gfp);
9413 return;
9414
9415 nla_put_failure:
9416 genlmsg_cancel(msg, hdr);
9417 nlmsg_free(msg);
9418}
9419
Thomas Pedersen53145262012-04-06 13:35:47 -07009420void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
Johannes Berg683b6d32012-11-08 21:25:48 +01009421 struct net_device *netdev,
9422 struct cfg80211_chan_def *chandef, gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -07009423{
9424 struct sk_buff *msg;
9425 void *hdr;
9426
Thomas Graf58050fc2012-06-28 03:57:45 +00009427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -07009428 if (!msg)
9429 return;
9430
9431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
9432 if (!hdr) {
9433 nlmsg_free(msg);
9434 return;
9435 }
9436
Johannes Berg683b6d32012-11-08 21:25:48 +01009437 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9438 goto nla_put_failure;
9439
9440 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -04009441 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07009442
9443 genlmsg_end(msg, hdr);
9444
9445 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9446 nl80211_mlme_mcgrp.id, gfp);
9447 return;
9448
9449 nla_put_failure:
9450 genlmsg_cancel(msg, hdr);
9451 nlmsg_free(msg);
9452}
9453
Johannes Bergc063dbf2010-11-24 08:10:05 +01009454void
Thomas Pedersen84f10702012-07-12 16:17:33 -07009455nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
9456 struct net_device *netdev, const u8 *peer,
9457 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
9458{
9459 struct sk_buff *msg;
9460 struct nlattr *pinfoattr;
9461 void *hdr;
9462
9463 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9464 if (!msg)
9465 return;
9466
9467 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9468 if (!hdr) {
9469 nlmsg_free(msg);
9470 return;
9471 }
9472
9473 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9474 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9475 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9476 goto nla_put_failure;
9477
9478 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9479 if (!pinfoattr)
9480 goto nla_put_failure;
9481
9482 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
9483 goto nla_put_failure;
9484
9485 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
9486 goto nla_put_failure;
9487
9488 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
9489 goto nla_put_failure;
9490
9491 nla_nest_end(msg, pinfoattr);
9492
9493 genlmsg_end(msg, hdr);
9494
9495 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9496 nl80211_mlme_mcgrp.id, gfp);
9497 return;
9498
9499 nla_put_failure:
9500 genlmsg_cancel(msg, hdr);
9501 nlmsg_free(msg);
9502}
9503
9504void
Johannes Bergc063dbf2010-11-24 08:10:05 +01009505nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
9506 struct net_device *netdev, const u8 *peer,
9507 u32 num_packets, gfp_t gfp)
9508{
9509 struct sk_buff *msg;
9510 struct nlattr *pinfoattr;
9511 void *hdr;
9512
Thomas Graf58050fc2012-06-28 03:57:45 +00009513 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +01009514 if (!msg)
9515 return;
9516
9517 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9518 if (!hdr) {
9519 nlmsg_free(msg);
9520 return;
9521 }
9522
David S. Miller9360ffd2012-03-29 04:41:26 -04009523 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9524 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9525 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9526 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01009527
9528 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9529 if (!pinfoattr)
9530 goto nla_put_failure;
9531
David S. Miller9360ffd2012-03-29 04:41:26 -04009532 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
9533 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01009534
9535 nla_nest_end(msg, pinfoattr);
9536
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009537 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01009538
9539 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9540 nl80211_mlme_mcgrp.id, gfp);
9541 return;
9542
9543 nla_put_failure:
9544 genlmsg_cancel(msg, hdr);
9545 nlmsg_free(msg);
9546}
9547
Johannes Berg7f6cf312011-11-04 11:18:15 +01009548void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
9549 u64 cookie, bool acked, gfp_t gfp)
9550{
9551 struct wireless_dev *wdev = dev->ieee80211_ptr;
9552 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9553 struct sk_buff *msg;
9554 void *hdr;
9555 int err;
9556
Beni Lev4ee3e062012-08-27 12:49:39 +03009557 trace_cfg80211_probe_status(dev, addr, cookie, acked);
9558
Thomas Graf58050fc2012-06-28 03:57:45 +00009559 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +03009560
Johannes Berg7f6cf312011-11-04 11:18:15 +01009561 if (!msg)
9562 return;
9563
9564 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
9565 if (!hdr) {
9566 nlmsg_free(msg);
9567 return;
9568 }
9569
David S. Miller9360ffd2012-03-29 04:41:26 -04009570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9571 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9572 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9573 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9574 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
9575 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009576
9577 err = genlmsg_end(msg, hdr);
9578 if (err < 0) {
9579 nlmsg_free(msg);
9580 return;
9581 }
9582
9583 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9584 nl80211_mlme_mcgrp.id, gfp);
9585 return;
9586
9587 nla_put_failure:
9588 genlmsg_cancel(msg, hdr);
9589 nlmsg_free(msg);
9590}
9591EXPORT_SYMBOL(cfg80211_probe_status);
9592
Johannes Berg5e760232011-11-04 11:18:17 +01009593void cfg80211_report_obss_beacon(struct wiphy *wiphy,
9594 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -07009595 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +01009596{
9597 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9598 struct sk_buff *msg;
9599 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -07009600 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +01009601
Beni Lev4ee3e062012-08-27 12:49:39 +03009602 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
9603
Ben Greear37c73b52012-10-26 14:49:25 -07009604 spin_lock_bh(&rdev->beacon_registrations_lock);
9605 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9606 msg = nlmsg_new(len + 100, GFP_ATOMIC);
9607 if (!msg) {
9608 spin_unlock_bh(&rdev->beacon_registrations_lock);
9609 return;
9610 }
Johannes Berg5e760232011-11-04 11:18:17 +01009611
Ben Greear37c73b52012-10-26 14:49:25 -07009612 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
9613 if (!hdr)
9614 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01009615
Ben Greear37c73b52012-10-26 14:49:25 -07009616 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9617 (freq &&
9618 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9619 (sig_dbm &&
9620 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9621 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
9622 goto nla_put_failure;
9623
9624 genlmsg_end(msg, hdr);
9625
9626 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +01009627 }
Ben Greear37c73b52012-10-26 14:49:25 -07009628 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009629 return;
9630
9631 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -07009632 spin_unlock_bh(&rdev->beacon_registrations_lock);
9633 if (hdr)
9634 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +01009635 nlmsg_free(msg);
9636}
9637EXPORT_SYMBOL(cfg80211_report_obss_beacon);
9638
Johannes Bergcd8f7cb2013-01-22 12:34:29 +01009639#ifdef CONFIG_PM
9640void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
9641 struct cfg80211_wowlan_wakeup *wakeup,
9642 gfp_t gfp)
9643{
9644 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9645 struct sk_buff *msg;
9646 void *hdr;
9647 int err, size = 200;
9648
9649 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
9650
9651 if (wakeup)
9652 size += wakeup->packet_present_len;
9653
9654 msg = nlmsg_new(size, gfp);
9655 if (!msg)
9656 return;
9657
9658 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
9659 if (!hdr)
9660 goto free_msg;
9661
9662 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9663 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9664 goto free_msg;
9665
9666 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9667 wdev->netdev->ifindex))
9668 goto free_msg;
9669
9670 if (wakeup) {
9671 struct nlattr *reasons;
9672
9673 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9674
9675 if (wakeup->disconnect &&
9676 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
9677 goto free_msg;
9678 if (wakeup->magic_pkt &&
9679 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
9680 goto free_msg;
9681 if (wakeup->gtk_rekey_failure &&
9682 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
9683 goto free_msg;
9684 if (wakeup->eap_identity_req &&
9685 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
9686 goto free_msg;
9687 if (wakeup->four_way_handshake &&
9688 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
9689 goto free_msg;
9690 if (wakeup->rfkill_release &&
9691 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
9692 goto free_msg;
9693
9694 if (wakeup->pattern_idx >= 0 &&
9695 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
9696 wakeup->pattern_idx))
9697 goto free_msg;
9698
Johannes Berg2a0e0472013-01-23 22:57:40 +01009699 if (wakeup->tcp_match)
9700 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
9701
9702 if (wakeup->tcp_connlost)
9703 nla_put_flag(msg,
9704 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
9705
9706 if (wakeup->tcp_nomoretokens)
9707 nla_put_flag(msg,
9708 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
9709
Johannes Bergcd8f7cb2013-01-22 12:34:29 +01009710 if (wakeup->packet) {
9711 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
9712 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
9713
9714 if (!wakeup->packet_80211) {
9715 pkt_attr =
9716 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
9717 len_attr =
9718 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
9719 }
9720
9721 if (wakeup->packet_len &&
9722 nla_put_u32(msg, len_attr, wakeup->packet_len))
9723 goto free_msg;
9724
9725 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
9726 wakeup->packet))
9727 goto free_msg;
9728 }
9729
9730 nla_nest_end(msg, reasons);
9731 }
9732
9733 err = genlmsg_end(msg, hdr);
9734 if (err < 0)
9735 goto free_msg;
9736
9737 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9738 nl80211_mlme_mcgrp.id, gfp);
9739 return;
9740
9741 free_msg:
9742 nlmsg_free(msg);
9743}
9744EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
9745#endif
9746
Jouni Malinen3475b092012-11-16 22:49:57 +02009747void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
9748 enum nl80211_tdls_operation oper,
9749 u16 reason_code, gfp_t gfp)
9750{
9751 struct wireless_dev *wdev = dev->ieee80211_ptr;
9752 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9753 struct sk_buff *msg;
9754 void *hdr;
9755 int err;
9756
9757 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
9758 reason_code);
9759
9760 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9761 if (!msg)
9762 return;
9763
9764 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
9765 if (!hdr) {
9766 nlmsg_free(msg);
9767 return;
9768 }
9769
9770 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9771 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9772 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
9773 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
9774 (reason_code > 0 &&
9775 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
9776 goto nla_put_failure;
9777
9778 err = genlmsg_end(msg, hdr);
9779 if (err < 0) {
9780 nlmsg_free(msg);
9781 return;
9782 }
9783
9784 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9785 nl80211_mlme_mcgrp.id, gfp);
9786 return;
9787
9788 nla_put_failure:
9789 genlmsg_cancel(msg, hdr);
9790 nlmsg_free(msg);
9791}
9792EXPORT_SYMBOL(cfg80211_tdls_oper_request);
9793
Jouni Malinen026331c2010-02-15 12:53:10 +02009794static int nl80211_netlink_notify(struct notifier_block * nb,
9795 unsigned long state,
9796 void *_notify)
9797{
9798 struct netlink_notify *notify = _notify;
9799 struct cfg80211_registered_device *rdev;
9800 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -07009801 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +02009802
9803 if (state != NETLINK_URELEASE)
9804 return NOTIFY_DONE;
9805
9806 rcu_read_lock();
9807
Johannes Berg5e760232011-11-04 11:18:17 +01009808 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +02009809 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +00009810 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -07009811
9812 spin_lock_bh(&rdev->beacon_registrations_lock);
9813 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
9814 list) {
9815 if (reg->nlportid == notify->portid) {
9816 list_del(&reg->list);
9817 kfree(reg);
9818 break;
9819 }
9820 }
9821 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009822 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009823
9824 rcu_read_unlock();
9825
9826 return NOTIFY_DONE;
9827}
9828
9829static struct notifier_block nl80211_netlink_notifier = {
9830 .notifier_call = nl80211_netlink_notify,
9831};
9832
Johannes Berg55682962007-09-20 13:09:35 -04009833/* initialisation/exit functions */
9834
9835int nl80211_init(void)
9836{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00009837 int err;
Johannes Berg55682962007-09-20 13:09:35 -04009838
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00009839 err = genl_register_family_with_ops(&nl80211_fam,
9840 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04009841 if (err)
9842 return err;
9843
Johannes Berg55682962007-09-20 13:09:35 -04009844 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
9845 if (err)
9846 goto err_out;
9847
Johannes Berg2a519312009-02-10 21:25:55 +01009848 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
9849 if (err)
9850 goto err_out;
9851
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009852 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
9853 if (err)
9854 goto err_out;
9855
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009856 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
9857 if (err)
9858 goto err_out;
9859
Johannes Bergaff89a92009-07-01 21:26:51 +02009860#ifdef CONFIG_NL80211_TESTMODE
9861 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
9862 if (err)
9863 goto err_out;
9864#endif
9865
Jouni Malinen026331c2010-02-15 12:53:10 +02009866 err = netlink_register_notifier(&nl80211_netlink_notifier);
9867 if (err)
9868 goto err_out;
9869
Johannes Berg55682962007-09-20 13:09:35 -04009870 return 0;
9871 err_out:
9872 genl_unregister_family(&nl80211_fam);
9873 return err;
9874}
9875
9876void nl80211_exit(void)
9877{
Jouni Malinen026331c2010-02-15 12:53:10 +02009878 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04009879 genl_unregister_family(&nl80211_fam);
9880}