blob: 5e4dda4c0fd3617ac6f3fae1752ef31ac7ecf91b [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 Berg55682962007-09-20 13:09:35 -040022#include "core.h"
23#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070024#include "reg.h"
Johannes Berg55682962007-09-20 13:09:35 -040025
Johannes Berg4c476992010-10-04 21:36:35 +020026static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
27 struct genl_info *info);
28static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
29 struct genl_info *info);
30
Johannes Berg55682962007-09-20 13:09:35 -040031/* the netlink family */
32static struct genl_family nl80211_fam = {
33 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
34 .name = "nl80211", /* have users key off the name instead */
35 .hdrsize = 0, /* no private header */
36 .version = 1, /* no particular meaning now */
37 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020038 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020039 .pre_doit = nl80211_pre_doit,
40 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040041};
42
Johannes Berg79c97e92009-07-07 03:56:12 +020043/* internal helper: get rdev and dev */
Johannes Berg463d0182009-07-14 00:33:35 +020044static int get_rdev_dev_by_info_ifindex(struct genl_info *info,
Johannes Berg79c97e92009-07-07 03:56:12 +020045 struct cfg80211_registered_device **rdev,
Johannes Berg55682962007-09-20 13:09:35 -040046 struct net_device **dev)
47{
Johannes Berg463d0182009-07-14 00:33:35 +020048 struct nlattr **attrs = info->attrs;
Johannes Berg55682962007-09-20 13:09:35 -040049 int ifindex;
50
Johannes Bergbba95fe2008-07-29 13:22:51 +020051 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040052 return -EINVAL;
53
Johannes Bergbba95fe2008-07-29 13:22:51 +020054 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg463d0182009-07-14 00:33:35 +020055 *dev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg55682962007-09-20 13:09:35 -040056 if (!*dev)
57 return -ENODEV;
58
Johannes Berg463d0182009-07-14 00:33:35 +020059 *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex);
Johannes Berg79c97e92009-07-07 03:56:12 +020060 if (IS_ERR(*rdev)) {
Johannes Berg55682962007-09-20 13:09:35 -040061 dev_put(*dev);
Johannes Berg79c97e92009-07-07 03:56:12 +020062 return PTR_ERR(*rdev);
Johannes Berg55682962007-09-20 13:09:35 -040063 }
64
65 return 0;
66}
67
68/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000069static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -040070 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
71 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -070072 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +020073 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +020074 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +053075 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020076 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
77 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
78 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
79 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +010080 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -040081
82 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
83 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
84 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +010085
86 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
Johannes Berg3e5d7642009-07-07 14:37:26 +020087 [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +010088
Johannes Bergb9454e82009-07-08 13:29:08 +020089 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +010090 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
91 .len = WLAN_MAX_KEY_LEN },
92 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
93 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
94 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen9f26a952009-05-15 12:38:32 +030095 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
Johannes Berge31b8212010-10-05 19:39:30 +020096 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010097
98 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
99 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
100 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
101 .len = IEEE80211_MAX_DATA_LEN },
102 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
103 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100104 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
105 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
106 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
107 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
108 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100109 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100110 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200111 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100112 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
113 .len = IEEE80211_MAX_MESH_ID_LEN },
114 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300115
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700116 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
117 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
118
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300119 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
120 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200122 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
123 .len = NL80211_MAX_SUPP_RATES },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300124
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700125 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED },
126
Jouni Malinen36aedc92008-08-25 11:58:58 +0300127 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
128 .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200129
130 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
131 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
132 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100133 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
134 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200135
136 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
137 .len = IEEE80211_MAX_SSID_LEN },
138 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
139 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200140 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300141 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300142 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300143 [NL80211_ATTR_STA_FLAGS2] = {
144 .len = sizeof(struct nl80211_sta_flag_update),
145 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300146 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300147 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
148 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200149 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
150 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
151 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200152 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100153 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100154 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
155 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100156 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
157 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200158 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200159 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
160 .len = IEEE80211_MAX_DATA_LEN },
161 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200162 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200163 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300164 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200165 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300166
167 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
168 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900169
Johannes Berg2e161f72010-08-12 15:38:38 +0200170 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900171
172 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
173 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Johannes Berg55682962007-09-20 13:09:35 -0400174};
175
Johannes Berge31b8212010-10-05 19:39:30 +0200176/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000177static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200178 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200179 [NL80211_KEY_IDX] = { .type = NLA_U8 },
180 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
181 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
182 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
183 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200184 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200185};
186
Holger Schuriga0438972009-11-11 11:30:02 +0100187/* ifidx get helper */
188static int nl80211_get_ifidx(struct netlink_callback *cb)
189{
190 int res;
191
192 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
193 nl80211_fam.attrbuf, nl80211_fam.maxattr,
194 nl80211_policy);
195 if (res)
196 return res;
197
198 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
199 return -EINVAL;
200
201 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
202 if (!res)
203 return -EINVAL;
204 return res;
205}
206
Johannes Berg67748892010-10-04 21:14:06 +0200207static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
208 struct netlink_callback *cb,
209 struct cfg80211_registered_device **rdev,
210 struct net_device **dev)
211{
212 int ifidx = cb->args[0];
213 int err;
214
215 if (!ifidx)
216 ifidx = nl80211_get_ifidx(cb);
217 if (ifidx < 0)
218 return ifidx;
219
220 cb->args[0] = ifidx;
221
222 rtnl_lock();
223
224 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
225 if (!*dev) {
226 err = -ENODEV;
227 goto out_rtnl;
228 }
229
230 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
231 if (IS_ERR(dev)) {
232 err = PTR_ERR(dev);
233 goto out_rtnl;
234 }
235
236 return 0;
237 out_rtnl:
238 rtnl_unlock();
239 return err;
240}
241
242static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
243{
244 cfg80211_unlock_rdev(rdev);
245 rtnl_unlock();
246}
247
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100248/* IE validation */
249static bool is_valid_ie_attr(const struct nlattr *attr)
250{
251 const u8 *pos;
252 int len;
253
254 if (!attr)
255 return true;
256
257 pos = nla_data(attr);
258 len = nla_len(attr);
259
260 while (len) {
261 u8 elemlen;
262
263 if (len < 2)
264 return false;
265 len -= 2;
266
267 elemlen = pos[1];
268 if (elemlen > len)
269 return false;
270
271 len -= elemlen;
272 pos += 2 + elemlen;
273 }
274
275 return true;
276}
277
Johannes Berg55682962007-09-20 13:09:35 -0400278/* message building helper */
279static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
280 int flags, u8 cmd)
281{
282 /* since there is no private header just add the generic one */
283 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
284}
285
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400286static int nl80211_msg_put_channel(struct sk_buff *msg,
287 struct ieee80211_channel *chan)
288{
289 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
290 chan->center_freq);
291
292 if (chan->flags & IEEE80211_CHAN_DISABLED)
293 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
294 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
295 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
296 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
297 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
298 if (chan->flags & IEEE80211_CHAN_RADAR)
299 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
300
301 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
302 DBM_TO_MBM(chan->max_power));
303
304 return 0;
305
306 nla_put_failure:
307 return -ENOBUFS;
308}
309
Johannes Berg55682962007-09-20 13:09:35 -0400310/* netlink command implementations */
311
Johannes Bergb9454e82009-07-08 13:29:08 +0200312struct key_parse {
313 struct key_params p;
314 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200315 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200316 bool def, defmgmt;
317};
318
319static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
320{
321 struct nlattr *tb[NL80211_KEY_MAX + 1];
322 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
323 nl80211_key_policy);
324 if (err)
325 return err;
326
327 k->def = !!tb[NL80211_KEY_DEFAULT];
328 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
329
330 if (tb[NL80211_KEY_IDX])
331 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
332
333 if (tb[NL80211_KEY_DATA]) {
334 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
335 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
336 }
337
338 if (tb[NL80211_KEY_SEQ]) {
339 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
340 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
341 }
342
343 if (tb[NL80211_KEY_CIPHER])
344 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
345
Johannes Berge31b8212010-10-05 19:39:30 +0200346 if (tb[NL80211_KEY_TYPE]) {
347 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
348 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
349 return -EINVAL;
350 }
351
Johannes Bergb9454e82009-07-08 13:29:08 +0200352 return 0;
353}
354
355static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
356{
357 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
358 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
359 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
360 }
361
362 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
363 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
364 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
365 }
366
367 if (info->attrs[NL80211_ATTR_KEY_IDX])
368 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
369
370 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
371 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
372
373 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
374 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
375
Johannes Berge31b8212010-10-05 19:39:30 +0200376 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
377 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
378 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
379 return -EINVAL;
380 }
381
Johannes Bergb9454e82009-07-08 13:29:08 +0200382 return 0;
383}
384
385static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
386{
387 int err;
388
389 memset(k, 0, sizeof(*k));
390 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200391 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200392
393 if (info->attrs[NL80211_ATTR_KEY])
394 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
395 else
396 err = nl80211_parse_key_old(info, k);
397
398 if (err)
399 return err;
400
401 if (k->def && k->defmgmt)
402 return -EINVAL;
403
404 if (k->idx != -1) {
405 if (k->defmgmt) {
406 if (k->idx < 4 || k->idx > 5)
407 return -EINVAL;
408 } else if (k->def) {
409 if (k->idx < 0 || k->idx > 3)
410 return -EINVAL;
411 } else {
412 if (k->idx < 0 || k->idx > 5)
413 return -EINVAL;
414 }
415 }
416
417 return 0;
418}
419
Johannes Bergfffd0932009-07-08 14:22:54 +0200420static struct cfg80211_cached_keys *
421nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
422 struct nlattr *keys)
423{
424 struct key_parse parse;
425 struct nlattr *key;
426 struct cfg80211_cached_keys *result;
427 int rem, err, def = 0;
428
429 result = kzalloc(sizeof(*result), GFP_KERNEL);
430 if (!result)
431 return ERR_PTR(-ENOMEM);
432
433 result->def = -1;
434 result->defmgmt = -1;
435
436 nla_for_each_nested(key, keys, rem) {
437 memset(&parse, 0, sizeof(parse));
438 parse.idx = -1;
439
440 err = nl80211_parse_key_new(key, &parse);
441 if (err)
442 goto error;
443 err = -EINVAL;
444 if (!parse.p.key)
445 goto error;
446 if (parse.idx < 0 || parse.idx > 4)
447 goto error;
448 if (parse.def) {
449 if (def)
450 goto error;
451 def = 1;
452 result->def = parse.idx;
453 } else if (parse.defmgmt)
454 goto error;
455 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200456 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200457 if (err)
458 goto error;
459 result->params[parse.idx].cipher = parse.p.cipher;
460 result->params[parse.idx].key_len = parse.p.key_len;
461 result->params[parse.idx].key = result->data[parse.idx];
462 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
463 }
464
465 return result;
466 error:
467 kfree(result);
468 return ERR_PTR(err);
469}
470
471static int nl80211_key_allowed(struct wireless_dev *wdev)
472{
473 ASSERT_WDEV_LOCK(wdev);
474
Johannes Bergfffd0932009-07-08 14:22:54 +0200475 switch (wdev->iftype) {
476 case NL80211_IFTYPE_AP:
477 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200478 case NL80211_IFTYPE_P2P_GO:
Johannes Bergfffd0932009-07-08 14:22:54 +0200479 break;
480 case NL80211_IFTYPE_ADHOC:
481 if (!wdev->current_bss)
482 return -ENOLINK;
483 break;
484 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200485 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200486 if (wdev->sme_state != CFG80211_SME_CONNECTED)
487 return -ENOLINK;
488 break;
489 default:
490 return -EINVAL;
491 }
492
493 return 0;
494}
495
Johannes Berg55682962007-09-20 13:09:35 -0400496static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
497 struct cfg80211_registered_device *dev)
498{
499 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100500 struct nlattr *nl_bands, *nl_band;
501 struct nlattr *nl_freqs, *nl_freq;
502 struct nlattr *nl_rates, *nl_rate;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700503 struct nlattr *nl_modes;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100504 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100505 enum ieee80211_band band;
506 struct ieee80211_channel *chan;
507 struct ieee80211_rate *rate;
508 int i;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700509 u16 ifmodes = dev->wiphy.interface_modes;
Johannes Berg2e161f72010-08-12 15:38:38 +0200510 const struct ieee80211_txrx_stypes *mgmt_stypes =
511 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400512
513 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
514 if (!hdr)
515 return -1;
516
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500517 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400518 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200519
Johannes Bergf5ea9122009-08-07 16:17:38 +0200520 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
521 cfg80211_rdev_list_generation);
522
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200523 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
524 dev->wiphy.retry_short);
525 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
526 dev->wiphy.retry_long);
527 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
528 dev->wiphy.frag_threshold);
529 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
530 dev->wiphy.rts_threshold);
Lukáš Turek81077e82009-12-21 22:50:47 +0100531 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
532 dev->wiphy.coverage_class);
Johannes Berg2a519312009-02-10 21:25:55 +0100533 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
534 dev->wiphy.max_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200535 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
536 dev->wiphy.max_scan_ie_len);
Johannes Bergee688b002008-01-24 19:38:39 +0100537
Johannes Berge31b8212010-10-05 19:39:30 +0200538 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
539 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
540
Johannes Berg25e47c182009-04-02 20:14:06 +0200541 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
542 sizeof(u32) * dev->wiphy.n_cipher_suites,
543 dev->wiphy.cipher_suites);
544
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100545 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
546 dev->wiphy.max_num_pmkids);
547
Johannes Bergc0692b82010-08-27 14:26:53 +0300548 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
549 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
550
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900551 if (dev->ops->get_antenna) {
552 u32 tx_ant = 0, rx_ant = 0;
553 int res;
554 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
555 if (!res) {
556 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
557 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
558 }
559 }
560
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700561 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
562 if (!nl_modes)
563 goto nla_put_failure;
564
565 i = 0;
566 while (ifmodes) {
567 if (ifmodes & 1)
568 NLA_PUT_FLAG(msg, i);
569 ifmodes >>= 1;
570 i++;
571 }
572
573 nla_nest_end(msg, nl_modes);
574
Johannes Bergee688b002008-01-24 19:38:39 +0100575 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
576 if (!nl_bands)
577 goto nla_put_failure;
578
579 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
580 if (!dev->wiphy.bands[band])
581 continue;
582
583 nl_band = nla_nest_start(msg, band);
584 if (!nl_band)
585 goto nla_put_failure;
586
Johannes Bergd51626d2008-10-09 12:20:13 +0200587 /* add HT info */
588 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
589 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
590 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
591 &dev->wiphy.bands[band]->ht_cap.mcs);
592 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
593 dev->wiphy.bands[band]->ht_cap.cap);
594 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
595 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
596 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
597 dev->wiphy.bands[band]->ht_cap.ampdu_density);
598 }
599
Johannes Bergee688b002008-01-24 19:38:39 +0100600 /* add frequencies */
601 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
602 if (!nl_freqs)
603 goto nla_put_failure;
604
605 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
606 nl_freq = nla_nest_start(msg, i);
607 if (!nl_freq)
608 goto nla_put_failure;
609
610 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100611
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400612 if (nl80211_msg_put_channel(msg, chan))
613 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200614
Johannes Bergee688b002008-01-24 19:38:39 +0100615 nla_nest_end(msg, nl_freq);
616 }
617
618 nla_nest_end(msg, nl_freqs);
619
620 /* add bitrates */
621 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
622 if (!nl_rates)
623 goto nla_put_failure;
624
625 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
626 nl_rate = nla_nest_start(msg, i);
627 if (!nl_rate)
628 goto nla_put_failure;
629
630 rate = &dev->wiphy.bands[band]->bitrates[i];
631 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
632 rate->bitrate);
633 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
634 NLA_PUT_FLAG(msg,
635 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
636
637 nla_nest_end(msg, nl_rate);
638 }
639
640 nla_nest_end(msg, nl_rates);
641
642 nla_nest_end(msg, nl_band);
643 }
644 nla_nest_end(msg, nl_bands);
645
Johannes Berg8fdc6212009-03-14 09:34:01 +0100646 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
647 if (!nl_cmds)
648 goto nla_put_failure;
649
650 i = 0;
651#define CMD(op, n) \
652 do { \
653 if (dev->ops->op) { \
654 i++; \
655 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
656 } \
657 } while (0)
658
659 CMD(add_virtual_intf, NEW_INTERFACE);
660 CMD(change_virtual_intf, SET_INTERFACE);
661 CMD(add_key, NEW_KEY);
662 CMD(add_beacon, NEW_BEACON);
663 CMD(add_station, NEW_STATION);
664 CMD(add_mpath, NEW_MPATH);
665 CMD(set_mesh_params, SET_MESH_PARAMS);
666 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200667 CMD(auth, AUTHENTICATE);
668 CMD(assoc, ASSOCIATE);
669 CMD(deauth, DEAUTHENTICATE);
670 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200671 CMD(join_ibss, JOIN_IBSS);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100672 CMD(set_pmksa, SET_PMKSA);
673 CMD(del_pmksa, DEL_PMKSA);
674 CMD(flush_pmksa, FLUSH_PMKSA);
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100675 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200676 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +0200677 CMD(mgmt_tx, FRAME);
Johannes Berg5be83de2009-11-19 00:56:28 +0100678 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +0200679 i++;
680 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
681 }
Johannes Bergf444de02010-05-05 15:25:02 +0200682 CMD(set_channel, SET_CHANNEL);
Bill Jordane8347eb2010-10-01 13:54:28 -0400683 CMD(set_wds_peer, SET_WDS_PEER);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100684
685#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +0200686
Johannes Berg6829c8782009-07-02 09:13:27 +0200687 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200688 i++;
689 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
690 }
691
Johannes Berg6829c8782009-07-02 09:13:27 +0200692 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200693 i++;
694 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
695 }
696
Johannes Berg8fdc6212009-03-14 09:34:01 +0100697 nla_nest_end(msg, nl_cmds);
698
Johannes Berg2e161f72010-08-12 15:38:38 +0200699 if (mgmt_stypes) {
700 u16 stypes;
701 struct nlattr *nl_ftypes, *nl_ifs;
702 enum nl80211_iftype ift;
703
704 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
705 if (!nl_ifs)
706 goto nla_put_failure;
707
708 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
709 nl_ftypes = nla_nest_start(msg, ift);
710 if (!nl_ftypes)
711 goto nla_put_failure;
712 i = 0;
713 stypes = mgmt_stypes[ift].tx;
714 while (stypes) {
715 if (stypes & 1)
716 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
717 (i << 4) | IEEE80211_FTYPE_MGMT);
718 stypes >>= 1;
719 i++;
720 }
721 nla_nest_end(msg, nl_ftypes);
722 }
723
Johannes Berg74b70a42010-08-24 12:15:53 +0200724 nla_nest_end(msg, nl_ifs);
725
Johannes Berg2e161f72010-08-12 15:38:38 +0200726 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
727 if (!nl_ifs)
728 goto nla_put_failure;
729
730 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
731 nl_ftypes = nla_nest_start(msg, ift);
732 if (!nl_ftypes)
733 goto nla_put_failure;
734 i = 0;
735 stypes = mgmt_stypes[ift].rx;
736 while (stypes) {
737 if (stypes & 1)
738 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
739 (i << 4) | IEEE80211_FTYPE_MGMT);
740 stypes >>= 1;
741 i++;
742 }
743 nla_nest_end(msg, nl_ftypes);
744 }
745 nla_nest_end(msg, nl_ifs);
746 }
747
Johannes Berg55682962007-09-20 13:09:35 -0400748 return genlmsg_end(msg, hdr);
749
750 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -0700751 genlmsg_cancel(msg, hdr);
752 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -0400753}
754
755static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
756{
757 int idx = 0;
758 int start = cb->args[0];
759 struct cfg80211_registered_device *dev;
760
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500761 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +0200762 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +0200763 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
764 continue;
Julius Volzb4637272008-07-08 14:02:19 +0200765 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -0400766 continue;
767 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
768 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +0200769 dev) < 0) {
770 idx--;
Johannes Berg55682962007-09-20 13:09:35 -0400771 break;
Julius Volzb4637272008-07-08 14:02:19 +0200772 }
Johannes Berg55682962007-09-20 13:09:35 -0400773 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500774 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400775
776 cb->args[0] = idx;
777
778 return skb->len;
779}
780
781static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
782{
783 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +0200784 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -0400785
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -0700786 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -0400787 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +0200788 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -0400789
Johannes Berg4c476992010-10-04 21:36:35 +0200790 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
791 nlmsg_free(msg);
792 return -ENOBUFS;
793 }
Johannes Berg55682962007-09-20 13:09:35 -0400794
Johannes Berg134e6372009-07-10 09:51:34 +0000795 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -0400796}
797
Jouni Malinen31888482008-10-30 16:59:24 +0200798static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
799 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
800 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
801 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
802 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
803 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
804};
805
806static int parse_txq_params(struct nlattr *tb[],
807 struct ieee80211_txq_params *txq_params)
808{
809 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
810 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
811 !tb[NL80211_TXQ_ATTR_AIFS])
812 return -EINVAL;
813
814 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
815 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
816 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
817 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
818 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
819
820 return 0;
821}
822
Johannes Bergf444de02010-05-05 15:25:02 +0200823static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
824{
825 /*
826 * You can only set the channel explicitly for AP, mesh
827 * and WDS type interfaces; all others have their channel
828 * managed via their respective "establish a connection"
829 * command (connect, join, ...)
830 *
831 * Monitors are special as they are normally slaved to
832 * whatever else is going on, so they behave as though
833 * you tried setting the wiphy channel itself.
834 */
835 return !wdev ||
836 wdev->iftype == NL80211_IFTYPE_AP ||
837 wdev->iftype == NL80211_IFTYPE_WDS ||
838 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +0200839 wdev->iftype == NL80211_IFTYPE_MONITOR ||
840 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +0200841}
842
843static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
844 struct wireless_dev *wdev,
845 struct genl_info *info)
846{
847 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
848 u32 freq;
849 int result;
850
851 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
852 return -EINVAL;
853
854 if (!nl80211_can_set_dev_channel(wdev))
855 return -EOPNOTSUPP;
856
857 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
858 channel_type = nla_get_u32(info->attrs[
859 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
860 if (channel_type != NL80211_CHAN_NO_HT &&
861 channel_type != NL80211_CHAN_HT20 &&
862 channel_type != NL80211_CHAN_HT40PLUS &&
863 channel_type != NL80211_CHAN_HT40MINUS)
864 return -EINVAL;
865 }
866
867 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
868
869 mutex_lock(&rdev->devlist_mtx);
870 if (wdev) {
871 wdev_lock(wdev);
872 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
873 wdev_unlock(wdev);
874 } else {
875 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
876 }
877 mutex_unlock(&rdev->devlist_mtx);
878
879 return result;
880}
881
882static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
883{
Johannes Berg4c476992010-10-04 21:36:35 +0200884 struct cfg80211_registered_device *rdev = info->user_ptr[0];
885 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +0200886
Johannes Berg4c476992010-10-04 21:36:35 +0200887 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +0200888}
889
Bill Jordane8347eb2010-10-01 13:54:28 -0400890static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
891{
Johannes Berg43b19952010-10-07 13:10:30 +0200892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
893 struct net_device *dev = info->user_ptr[1];
894 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +0200895 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -0400896
897 if (!info->attrs[NL80211_ATTR_MAC])
898 return -EINVAL;
899
Johannes Berg43b19952010-10-07 13:10:30 +0200900 if (netif_running(dev))
901 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -0400902
Johannes Berg43b19952010-10-07 13:10:30 +0200903 if (!rdev->ops->set_wds_peer)
904 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -0400905
Johannes Berg43b19952010-10-07 13:10:30 +0200906 if (wdev->iftype != NL80211_IFTYPE_WDS)
907 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -0400908
909 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +0200910 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -0400911}
912
913
Johannes Berg55682962007-09-20 13:09:35 -0400914static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
915{
916 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +0200917 struct net_device *netdev = NULL;
918 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -0400919 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +0200920 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200921 u32 changed;
922 u8 retry_short = 0, retry_long = 0;
923 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +0100924 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -0400925
Johannes Bergf444de02010-05-05 15:25:02 +0200926 /*
927 * Try to find the wiphy and netdev. Normally this
928 * function shouldn't need the netdev, but this is
929 * done for backward compatibility -- previously
930 * setting the channel was done per wiphy, but now
931 * it is per netdev. Previous userland like hostapd
932 * also passed a netdev to set_wiphy, so that it is
933 * possible to let that go to the right netdev!
934 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100935 mutex_lock(&cfg80211_mutex);
936
Johannes Bergf444de02010-05-05 15:25:02 +0200937 if (info->attrs[NL80211_ATTR_IFINDEX]) {
938 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
939
940 netdev = dev_get_by_index(genl_info_net(info), ifindex);
941 if (netdev && netdev->ieee80211_ptr) {
942 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
943 mutex_lock(&rdev->mtx);
944 } else
945 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100946 }
947
Johannes Bergf444de02010-05-05 15:25:02 +0200948 if (!netdev) {
949 rdev = __cfg80211_rdev_from_info(info);
950 if (IS_ERR(rdev)) {
951 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +0200952 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +0200953 }
954 wdev = NULL;
955 netdev = NULL;
956 result = 0;
957
958 mutex_lock(&rdev->mtx);
959 } else if (netif_running(netdev) &&
960 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
961 wdev = netdev->ieee80211_ptr;
962 else
963 wdev = NULL;
964
965 /*
966 * end workaround code, by now the rdev is available
967 * and locked, and wdev may or may not be NULL.
968 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100969
970 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +0200971 result = cfg80211_dev_rename(
972 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100973
974 mutex_unlock(&cfg80211_mutex);
975
976 if (result)
977 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -0400978
Jouni Malinen31888482008-10-30 16:59:24 +0200979 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
980 struct ieee80211_txq_params txq_params;
981 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
982
983 if (!rdev->ops->set_txq_params) {
984 result = -EOPNOTSUPP;
985 goto bad_res;
986 }
987
988 nla_for_each_nested(nl_txq_params,
989 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
990 rem_txq_params) {
991 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
992 nla_data(nl_txq_params),
993 nla_len(nl_txq_params),
994 txq_params_policy);
995 result = parse_txq_params(tb, &txq_params);
996 if (result)
997 goto bad_res;
998
999 result = rdev->ops->set_txq_params(&rdev->wiphy,
1000 &txq_params);
1001 if (result)
1002 goto bad_res;
1003 }
1004 }
1005
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001006 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001007 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001008 if (result)
1009 goto bad_res;
1010 }
1011
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001012 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1013 enum nl80211_tx_power_setting type;
1014 int idx, mbm = 0;
1015
1016 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001017 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001018 goto bad_res;
1019 }
1020
1021 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1022 type = nla_get_u32(info->attrs[idx]);
1023
1024 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1025 (type != NL80211_TX_POWER_AUTOMATIC)) {
1026 result = -EINVAL;
1027 goto bad_res;
1028 }
1029
1030 if (type != NL80211_TX_POWER_AUTOMATIC) {
1031 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1032 mbm = nla_get_u32(info->attrs[idx]);
1033 }
1034
1035 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1036 if (result)
1037 goto bad_res;
1038 }
1039
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001040 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1041 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1042 u32 tx_ant, rx_ant;
1043 if (!rdev->ops->set_antenna) {
1044 result = -EOPNOTSUPP;
1045 goto bad_res;
1046 }
1047
1048 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1049 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1050
1051 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1052 if (result)
1053 goto bad_res;
1054 }
1055
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001056 changed = 0;
1057
1058 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1059 retry_short = nla_get_u8(
1060 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1061 if (retry_short == 0) {
1062 result = -EINVAL;
1063 goto bad_res;
1064 }
1065 changed |= WIPHY_PARAM_RETRY_SHORT;
1066 }
1067
1068 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1069 retry_long = nla_get_u8(
1070 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1071 if (retry_long == 0) {
1072 result = -EINVAL;
1073 goto bad_res;
1074 }
1075 changed |= WIPHY_PARAM_RETRY_LONG;
1076 }
1077
1078 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1079 frag_threshold = nla_get_u32(
1080 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1081 if (frag_threshold < 256) {
1082 result = -EINVAL;
1083 goto bad_res;
1084 }
1085 if (frag_threshold != (u32) -1) {
1086 /*
1087 * Fragments (apart from the last one) are required to
1088 * have even length. Make the fragmentation code
1089 * simpler by stripping LSB should someone try to use
1090 * odd threshold value.
1091 */
1092 frag_threshold &= ~0x1;
1093 }
1094 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1095 }
1096
1097 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1098 rts_threshold = nla_get_u32(
1099 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1100 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1101 }
1102
Lukáš Turek81077e82009-12-21 22:50:47 +01001103 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1104 coverage_class = nla_get_u8(
1105 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1106 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1107 }
1108
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001109 if (changed) {
1110 u8 old_retry_short, old_retry_long;
1111 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001112 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001113
1114 if (!rdev->ops->set_wiphy_params) {
1115 result = -EOPNOTSUPP;
1116 goto bad_res;
1117 }
1118
1119 old_retry_short = rdev->wiphy.retry_short;
1120 old_retry_long = rdev->wiphy.retry_long;
1121 old_frag_threshold = rdev->wiphy.frag_threshold;
1122 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001123 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001124
1125 if (changed & WIPHY_PARAM_RETRY_SHORT)
1126 rdev->wiphy.retry_short = retry_short;
1127 if (changed & WIPHY_PARAM_RETRY_LONG)
1128 rdev->wiphy.retry_long = retry_long;
1129 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1130 rdev->wiphy.frag_threshold = frag_threshold;
1131 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1132 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001133 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1134 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001135
1136 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1137 if (result) {
1138 rdev->wiphy.retry_short = old_retry_short;
1139 rdev->wiphy.retry_long = old_retry_long;
1140 rdev->wiphy.frag_threshold = old_frag_threshold;
1141 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001142 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001143 }
1144 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001145
Johannes Berg306d6112008-12-08 12:39:04 +01001146 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001147 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001148 if (netdev)
1149 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001150 return result;
1151}
1152
1153
1154static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001155 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001156 struct net_device *dev)
1157{
1158 void *hdr;
1159
1160 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1161 if (!hdr)
1162 return -1;
1163
1164 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001165 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001166 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001167 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001168
1169 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1170 rdev->devlist_generation ^
1171 (cfg80211_rdev_list_generation << 2));
1172
Johannes Berg55682962007-09-20 13:09:35 -04001173 return genlmsg_end(msg, hdr);
1174
1175 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001176 genlmsg_cancel(msg, hdr);
1177 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001178}
1179
1180static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1181{
1182 int wp_idx = 0;
1183 int if_idx = 0;
1184 int wp_start = cb->args[0];
1185 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001186 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001187 struct wireless_dev *wdev;
1188
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001189 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001190 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1191 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001192 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001193 if (wp_idx < wp_start) {
1194 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001195 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001196 }
Johannes Berg55682962007-09-20 13:09:35 -04001197 if_idx = 0;
1198
Johannes Bergf5ea9122009-08-07 16:17:38 +02001199 mutex_lock(&rdev->devlist_mtx);
1200 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001201 if (if_idx < if_start) {
1202 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001203 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001204 }
Johannes Berg55682962007-09-20 13:09:35 -04001205 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1206 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001207 rdev, wdev->netdev) < 0) {
1208 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001209 goto out;
1210 }
1211 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001212 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001213 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001214
1215 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001216 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001217 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001218 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001219
1220 cb->args[0] = wp_idx;
1221 cb->args[1] = if_idx;
1222
1223 return skb->len;
1224}
1225
1226static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1227{
1228 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001229 struct cfg80211_registered_device *dev = info->user_ptr[0];
1230 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001231
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001232 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001233 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001234 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001235
Johannes Bergd7264052009-04-19 16:23:20 +02001236 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001237 dev, netdev) < 0) {
1238 nlmsg_free(msg);
1239 return -ENOBUFS;
1240 }
Johannes Berg55682962007-09-20 13:09:35 -04001241
Johannes Berg134e6372009-07-10 09:51:34 +00001242 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001243}
1244
Michael Wu66f7ac52008-01-31 19:48:22 +01001245static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1246 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1247 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1248 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1249 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1250 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1251};
1252
1253static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1254{
1255 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1256 int flag;
1257
1258 *mntrflags = 0;
1259
1260 if (!nla)
1261 return -EINVAL;
1262
1263 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1264 nla, mntr_flags_policy))
1265 return -EINVAL;
1266
1267 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1268 if (flags[flag])
1269 *mntrflags |= (1<<flag);
1270
1271 return 0;
1272}
1273
Johannes Berg9bc383d2009-11-19 11:55:19 +01001274static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001275 struct net_device *netdev, u8 use_4addr,
1276 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001277{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001278 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001279 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001280 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001281 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001282 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001283
1284 switch (iftype) {
1285 case NL80211_IFTYPE_AP_VLAN:
1286 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1287 return 0;
1288 break;
1289 case NL80211_IFTYPE_STATION:
1290 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1291 return 0;
1292 break;
1293 default:
1294 break;
1295 }
1296
1297 return -EOPNOTSUPP;
1298}
1299
Johannes Berg55682962007-09-20 13:09:35 -04001300static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1301{
Johannes Berg4c476992010-10-04 21:36:35 +02001302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001303 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001304 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001305 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001306 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001307 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001308 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001309
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001310 memset(&params, 0, sizeof(params));
1311
Johannes Berg04a773a2009-04-19 21:24:32 +02001312 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001313
Johannes Berg723b0382008-09-16 20:22:09 +02001314 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001315 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001316 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001317 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001318 if (ntype > NL80211_IFTYPE_MAX)
1319 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001320 }
1321
Johannes Berg92ffe052008-09-16 20:39:36 +02001322 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001323 if (ntype != NL80211_IFTYPE_MESH_POINT)
1324 return -EINVAL;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001325 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
1326 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001327 change = true;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001328 }
1329
Felix Fietkau8b787642009-11-10 18:53:10 +01001330 if (info->attrs[NL80211_ATTR_4ADDR]) {
1331 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1332 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001333 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001334 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001335 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001336 } else {
1337 params.use_4addr = -1;
1338 }
1339
Johannes Berg92ffe052008-09-16 20:39:36 +02001340 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001341 if (ntype != NL80211_IFTYPE_MONITOR)
1342 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001343 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1344 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001345 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001346 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001347
1348 flags = &_flags;
1349 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001350 }
Johannes Berg3b858752009-03-12 09:55:09 +01001351
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001352 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001353 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001354 else
1355 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001356
Johannes Berg9bc383d2009-11-19 11:55:19 +01001357 if (!err && params.use_4addr != -1)
1358 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1359
Johannes Berg55682962007-09-20 13:09:35 -04001360 return err;
1361}
1362
1363static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1364{
Johannes Berg4c476992010-10-04 21:36:35 +02001365 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001366 struct vif_params params;
Johannes Berg55682962007-09-20 13:09:35 -04001367 int err;
1368 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001369 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001370
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001371 memset(&params, 0, sizeof(params));
1372
Johannes Berg55682962007-09-20 13:09:35 -04001373 if (!info->attrs[NL80211_ATTR_IFNAME])
1374 return -EINVAL;
1375
1376 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1377 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1378 if (type > NL80211_IFTYPE_MAX)
1379 return -EINVAL;
1380 }
1381
Johannes Berg79c97e92009-07-07 03:56:12 +02001382 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001383 !(rdev->wiphy.interface_modes & (1 << type)))
1384 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001385
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001386 if (type == NL80211_IFTYPE_MESH_POINT &&
1387 info->attrs[NL80211_ATTR_MESH_ID]) {
1388 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
1389 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1390 }
1391
Johannes Berg9bc383d2009-11-19 11:55:19 +01001392 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001393 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001394 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001395 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001396 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001397 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001398
Michael Wu66f7ac52008-01-31 19:48:22 +01001399 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1400 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1401 &flags);
Johannes Berg79c97e92009-07-07 03:56:12 +02001402 err = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001403 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001404 type, err ? NULL : &flags, &params);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001405
Johannes Berg55682962007-09-20 13:09:35 -04001406 return err;
1407}
1408
1409static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1410{
Johannes Berg4c476992010-10-04 21:36:35 +02001411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1412 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001413
Johannes Berg4c476992010-10-04 21:36:35 +02001414 if (!rdev->ops->del_virtual_intf)
1415 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001416
Johannes Berg4c476992010-10-04 21:36:35 +02001417 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001418}
1419
Johannes Berg41ade002007-12-19 02:03:29 +01001420struct get_key_cookie {
1421 struct sk_buff *msg;
1422 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001423 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001424};
1425
1426static void get_key_callback(void *c, struct key_params *params)
1427{
Johannes Bergb9454e82009-07-08 13:29:08 +02001428 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001429 struct get_key_cookie *cookie = c;
1430
1431 if (params->key)
1432 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1433 params->key_len, params->key);
1434
1435 if (params->seq)
1436 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1437 params->seq_len, params->seq);
1438
1439 if (params->cipher)
1440 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1441 params->cipher);
1442
Johannes Bergb9454e82009-07-08 13:29:08 +02001443 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1444 if (!key)
1445 goto nla_put_failure;
1446
1447 if (params->key)
1448 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1449 params->key_len, params->key);
1450
1451 if (params->seq)
1452 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1453 params->seq_len, params->seq);
1454
1455 if (params->cipher)
1456 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1457 params->cipher);
1458
1459 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1460
1461 nla_nest_end(cookie->msg, key);
1462
Johannes Berg41ade002007-12-19 02:03:29 +01001463 return;
1464 nla_put_failure:
1465 cookie->error = 1;
1466}
1467
1468static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1469{
Johannes Berg4c476992010-10-04 21:36:35 +02001470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001471 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001472 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001473 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001474 const u8 *mac_addr = NULL;
1475 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001476 struct get_key_cookie cookie = {
1477 .error = 0,
1478 };
1479 void *hdr;
1480 struct sk_buff *msg;
1481
1482 if (info->attrs[NL80211_ATTR_KEY_IDX])
1483 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1484
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001485 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001486 return -EINVAL;
1487
1488 if (info->attrs[NL80211_ATTR_MAC])
1489 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1490
Johannes Berge31b8212010-10-05 19:39:30 +02001491 pairwise = !!mac_addr;
1492 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1493 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1494 if (kt >= NUM_NL80211_KEYTYPES)
1495 return -EINVAL;
1496 if (kt != NL80211_KEYTYPE_GROUP &&
1497 kt != NL80211_KEYTYPE_PAIRWISE)
1498 return -EINVAL;
1499 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1500 }
1501
Johannes Berg4c476992010-10-04 21:36:35 +02001502 if (!rdev->ops->get_key)
1503 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001504
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001506 if (!msg)
1507 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001508
1509 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1510 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001511 if (IS_ERR(hdr))
1512 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001513
1514 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001515 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001516
1517 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1518 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1519 if (mac_addr)
1520 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1521
Johannes Berge31b8212010-10-05 19:39:30 +02001522 if (pairwise && mac_addr &&
1523 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1524 return -ENOENT;
1525
1526 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1527 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001528
1529 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001530 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001531
1532 if (cookie.error)
1533 goto nla_put_failure;
1534
1535 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001536 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001537
1538 nla_put_failure:
1539 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001540 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001541 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001542 return err;
1543}
1544
1545static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1546{
Johannes Berg4c476992010-10-04 21:36:35 +02001547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001548 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001549 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001550 struct net_device *dev = info->user_ptr[1];
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001551 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
1552 u8 key_index);
Johannes Berg41ade002007-12-19 02:03:29 +01001553
Johannes Bergb9454e82009-07-08 13:29:08 +02001554 err = nl80211_parse_key(info, &key);
1555 if (err)
1556 return err;
1557
1558 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001559 return -EINVAL;
1560
Johannes Bergb9454e82009-07-08 13:29:08 +02001561 /* only support setting default key */
1562 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001563 return -EINVAL;
1564
Johannes Bergb9454e82009-07-08 13:29:08 +02001565 if (key.def)
Johannes Berg79c97e92009-07-07 03:56:12 +02001566 func = rdev->ops->set_default_key;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001567 else
Johannes Berg79c97e92009-07-07 03:56:12 +02001568 func = rdev->ops->set_default_mgmt_key;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001569
Johannes Berg4c476992010-10-04 21:36:35 +02001570 if (!func)
1571 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001572
Johannes Bergfffd0932009-07-08 14:22:54 +02001573 wdev_lock(dev->ieee80211_ptr);
1574 err = nl80211_key_allowed(dev->ieee80211_ptr);
1575 if (!err)
1576 err = func(&rdev->wiphy, dev, key.idx);
1577
Johannes Berg3d23e342009-09-29 23:27:28 +02001578#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02001579 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02001580 if (func == rdev->ops->set_default_key)
Johannes Bergb9454e82009-07-08 13:29:08 +02001581 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001582 else
Johannes Bergb9454e82009-07-08 13:29:08 +02001583 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001584 }
1585#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02001586 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001587
Johannes Berg41ade002007-12-19 02:03:29 +01001588 return err;
1589}
1590
1591static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1592{
Johannes Berg4c476992010-10-04 21:36:35 +02001593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001594 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001595 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001596 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001597 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001598
Johannes Bergb9454e82009-07-08 13:29:08 +02001599 err = nl80211_parse_key(info, &key);
1600 if (err)
1601 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001602
Johannes Bergb9454e82009-07-08 13:29:08 +02001603 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001604 return -EINVAL;
1605
Johannes Berg41ade002007-12-19 02:03:29 +01001606 if (info->attrs[NL80211_ATTR_MAC])
1607 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1608
Johannes Berge31b8212010-10-05 19:39:30 +02001609 if (key.type == -1) {
1610 if (mac_addr)
1611 key.type = NL80211_KEYTYPE_PAIRWISE;
1612 else
1613 key.type = NL80211_KEYTYPE_GROUP;
1614 }
1615
1616 /* for now */
1617 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1618 key.type != NL80211_KEYTYPE_GROUP)
1619 return -EINVAL;
1620
Johannes Berg4c476992010-10-04 21:36:35 +02001621 if (!rdev->ops->add_key)
1622 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001623
Johannes Berge31b8212010-10-05 19:39:30 +02001624 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
1625 key.type == NL80211_KEYTYPE_PAIRWISE,
1626 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02001627 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001628
1629 wdev_lock(dev->ieee80211_ptr);
1630 err = nl80211_key_allowed(dev->ieee80211_ptr);
1631 if (!err)
1632 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02001633 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02001634 mac_addr, &key.p);
1635 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001636
Johannes Berg41ade002007-12-19 02:03:29 +01001637 return err;
1638}
1639
1640static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1641{
Johannes Berg4c476992010-10-04 21:36:35 +02001642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001643 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001644 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001645 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02001646 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001647
Johannes Bergb9454e82009-07-08 13:29:08 +02001648 err = nl80211_parse_key(info, &key);
1649 if (err)
1650 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001651
1652 if (info->attrs[NL80211_ATTR_MAC])
1653 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1654
Johannes Berge31b8212010-10-05 19:39:30 +02001655 if (key.type == -1) {
1656 if (mac_addr)
1657 key.type = NL80211_KEYTYPE_PAIRWISE;
1658 else
1659 key.type = NL80211_KEYTYPE_GROUP;
1660 }
1661
1662 /* for now */
1663 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1664 key.type != NL80211_KEYTYPE_GROUP)
1665 return -EINVAL;
1666
Johannes Berg4c476992010-10-04 21:36:35 +02001667 if (!rdev->ops->del_key)
1668 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001669
Johannes Bergfffd0932009-07-08 14:22:54 +02001670 wdev_lock(dev->ieee80211_ptr);
1671 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02001672
1673 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
1674 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1675 err = -ENOENT;
1676
Johannes Bergfffd0932009-07-08 14:22:54 +02001677 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02001678 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
1679 key.type == NL80211_KEYTYPE_PAIRWISE,
1680 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01001681
Johannes Berg3d23e342009-09-29 23:27:28 +02001682#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02001683 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02001684 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02001685 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001686 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02001687 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
1688 }
1689#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02001690 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02001691
Johannes Berg41ade002007-12-19 02:03:29 +01001692 return err;
1693}
1694
Johannes Berged1b6cc2007-12-19 02:03:32 +01001695static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1696{
1697 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1698 struct beacon_parameters *info);
Johannes Berg4c476992010-10-04 21:36:35 +02001699 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1700 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01001701 struct beacon_parameters params;
1702 int haveinfo = 0;
1703
Johannes Bergf4a11bb2009-03-27 12:40:28 +01001704 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1705 return -EINVAL;
1706
Johannes Berg074ac8d2010-09-16 14:58:22 +02001707 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02001708 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
1709 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02001710
Johannes Berged1b6cc2007-12-19 02:03:32 +01001711 switch (info->genlhdr->cmd) {
1712 case NL80211_CMD_NEW_BEACON:
1713 /* these are required for NEW_BEACON */
1714 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1715 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
Johannes Berg4c476992010-10-04 21:36:35 +02001716 !info->attrs[NL80211_ATTR_BEACON_HEAD])
1717 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001718
Johannes Berg79c97e92009-07-07 03:56:12 +02001719 call = rdev->ops->add_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001720 break;
1721 case NL80211_CMD_SET_BEACON:
Johannes Berg79c97e92009-07-07 03:56:12 +02001722 call = rdev->ops->set_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001723 break;
1724 default:
1725 WARN_ON(1);
Johannes Berg4c476992010-10-04 21:36:35 +02001726 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001727 }
1728
Johannes Berg4c476992010-10-04 21:36:35 +02001729 if (!call)
1730 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001731
1732 memset(&params, 0, sizeof(params));
1733
1734 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1735 params.interval =
1736 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1737 haveinfo = 1;
1738 }
1739
1740 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
1741 params.dtim_period =
1742 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1743 haveinfo = 1;
1744 }
1745
1746 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1747 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1748 params.head_len =
1749 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1750 haveinfo = 1;
1751 }
1752
1753 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
1754 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1755 params.tail_len =
1756 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1757 haveinfo = 1;
1758 }
1759
Johannes Berg4c476992010-10-04 21:36:35 +02001760 if (!haveinfo)
1761 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001762
Johannes Berg4c476992010-10-04 21:36:35 +02001763 return call(&rdev->wiphy, dev, &params);
Johannes Berged1b6cc2007-12-19 02:03:32 +01001764}
1765
1766static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1767{
Johannes Berg4c476992010-10-04 21:36:35 +02001768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1769 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01001770
Johannes Berg4c476992010-10-04 21:36:35 +02001771 if (!rdev->ops->del_beacon)
1772 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001773
Johannes Berg074ac8d2010-09-16 14:58:22 +02001774 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02001775 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
1776 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001777
Johannes Berg4c476992010-10-04 21:36:35 +02001778 return rdev->ops->del_beacon(&rdev->wiphy, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01001779}
1780
Johannes Berg5727ef12007-12-19 02:03:34 +01001781static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1782 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
1783 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1784 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03001785 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01001786};
1787
Johannes Bergeccb8e82009-05-11 21:57:56 +03001788static int parse_station_flags(struct genl_info *info,
1789 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01001790{
1791 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03001792 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01001793 int flag;
1794
Johannes Bergeccb8e82009-05-11 21:57:56 +03001795 /*
1796 * Try parsing the new attribute first so userspace
1797 * can specify both for older kernels.
1798 */
1799 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
1800 if (nla) {
1801 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01001802
Johannes Bergeccb8e82009-05-11 21:57:56 +03001803 sta_flags = nla_data(nla);
1804 params->sta_flags_mask = sta_flags->mask;
1805 params->sta_flags_set = sta_flags->set;
1806 if ((params->sta_flags_mask |
1807 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
1808 return -EINVAL;
1809 return 0;
1810 }
1811
1812 /* if present, parse the old attribute */
1813
1814 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01001815 if (!nla)
1816 return 0;
1817
1818 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
1819 nla, sta_flags_policy))
1820 return -EINVAL;
1821
Johannes Bergeccb8e82009-05-11 21:57:56 +03001822 params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1;
1823 params->sta_flags_mask &= ~1;
Johannes Berg5727ef12007-12-19 02:03:34 +01001824
1825 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
1826 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03001827 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01001828
1829 return 0;
1830}
1831
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001832static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1833 int flags, struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01001834 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001835{
1836 void *hdr;
Henning Rogge420e7fa2008-12-11 22:04:19 +01001837 struct nlattr *sinfoattr, *txrate;
1838 u16 bitrate;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001839
1840 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1841 if (!hdr)
1842 return -1;
1843
1844 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1845 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1846
Johannes Bergf5ea9122009-08-07 16:17:38 +02001847 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
1848
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001849 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1850 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001851 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001852 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1853 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1854 sinfo->inactive_time);
1855 if (sinfo->filled & STATION_INFO_RX_BYTES)
1856 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
1857 sinfo->rx_bytes);
1858 if (sinfo->filled & STATION_INFO_TX_BYTES)
1859 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
1860 sinfo->tx_bytes);
1861 if (sinfo->filled & STATION_INFO_LLID)
1862 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
1863 sinfo->llid);
1864 if (sinfo->filled & STATION_INFO_PLID)
1865 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
1866 sinfo->plid);
1867 if (sinfo->filled & STATION_INFO_PLINK_STATE)
1868 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
1869 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01001870 if (sinfo->filled & STATION_INFO_SIGNAL)
1871 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1872 sinfo->signal);
1873 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1874 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1875 if (!txrate)
1876 goto nla_put_failure;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001877
John W. Linville254416a2009-12-09 16:43:52 -05001878 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1879 bitrate = cfg80211_calculate_bitrate(&sinfo->txrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +01001880 if (bitrate > 0)
1881 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1882
1883 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1884 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1885 sinfo->txrate.mcs);
1886 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1887 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1888 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1889 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
1890
1891 nla_nest_end(msg, txrate);
1892 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02001893 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1894 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
1895 sinfo->rx_packets);
1896 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1897 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1898 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09001899 if (sinfo->filled & STATION_INFO_TX_RETRIES)
1900 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
1901 sinfo->tx_retries);
1902 if (sinfo->filled & STATION_INFO_TX_FAILED)
1903 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
1904 sinfo->tx_failed);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001905 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001906
1907 return genlmsg_end(msg, hdr);
1908
1909 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001910 genlmsg_cancel(msg, hdr);
1911 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001912}
1913
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001914static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02001915 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001916{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001917 struct station_info sinfo;
1918 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001919 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001920 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02001921 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001922 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001923
Johannes Berg67748892010-10-04 21:14:06 +02001924 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
1925 if (err)
1926 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001927
1928 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02001929 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001930 goto out_err;
1931 }
1932
Johannes Bergbba95fe2008-07-29 13:22:51 +02001933 while (1) {
1934 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
1935 mac_addr, &sinfo);
1936 if (err == -ENOENT)
1937 break;
1938 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001939 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001940
1941 if (nl80211_send_station(skb,
1942 NETLINK_CB(cb->skb).pid,
1943 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1944 netdev, mac_addr,
1945 &sinfo) < 0)
1946 goto out;
1947
1948 sta_idx++;
1949 }
1950
1951
1952 out:
1953 cb->args[1] = sta_idx;
1954 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001955 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02001956 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001957
1958 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001959}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001960
Johannes Berg5727ef12007-12-19 02:03:34 +01001961static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1962{
Johannes Berg4c476992010-10-04 21:36:35 +02001963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1964 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001965 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001966 struct sk_buff *msg;
1967 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02001968 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001969
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001970 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001971
1972 if (!info->attrs[NL80211_ATTR_MAC])
1973 return -EINVAL;
1974
1975 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1976
Johannes Berg4c476992010-10-04 21:36:35 +02001977 if (!rdev->ops->get_station)
1978 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001979
Johannes Berg79c97e92009-07-07 03:56:12 +02001980 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001981 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001982 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001983
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001984 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001985 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001986 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001987
1988 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001989 dev, mac_addr, &sinfo) < 0) {
1990 nlmsg_free(msg);
1991 return -ENOBUFS;
1992 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001993
Johannes Berg4c476992010-10-04 21:36:35 +02001994 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01001995}
1996
1997/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01001998 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01001999 */
Johannes Berg463d0182009-07-14 00:33:35 +02002000static int get_vlan(struct genl_info *info,
Johannes Berg5727ef12007-12-19 02:03:34 +01002001 struct cfg80211_registered_device *rdev,
2002 struct net_device **vlan)
2003{
Johannes Berg463d0182009-07-14 00:33:35 +02002004 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg5727ef12007-12-19 02:03:34 +01002005 *vlan = NULL;
2006
2007 if (vlanattr) {
Johannes Berg463d0182009-07-14 00:33:35 +02002008 *vlan = dev_get_by_index(genl_info_net(info),
2009 nla_get_u32(vlanattr));
Johannes Berg5727ef12007-12-19 02:03:34 +01002010 if (!*vlan)
2011 return -ENODEV;
2012 if (!(*vlan)->ieee80211_ptr)
2013 return -EINVAL;
2014 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
2015 return -EINVAL;
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002016 if (!netif_running(*vlan))
2017 return -ENETDOWN;
Johannes Berg5727ef12007-12-19 02:03:34 +01002018 }
2019 return 0;
2020}
2021
2022static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2023{
Johannes Berg4c476992010-10-04 21:36:35 +02002024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002025 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002026 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002027 struct station_parameters params;
2028 u8 *mac_addr = NULL;
2029
2030 memset(&params, 0, sizeof(params));
2031
2032 params.listen_interval = -1;
2033
2034 if (info->attrs[NL80211_ATTR_STA_AID])
2035 return -EINVAL;
2036
2037 if (!info->attrs[NL80211_ATTR_MAC])
2038 return -EINVAL;
2039
2040 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2041
2042 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2043 params.supported_rates =
2044 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2045 params.supported_rates_len =
2046 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2047 }
2048
2049 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2050 params.listen_interval =
2051 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2052
Jouni Malinen36aedc92008-08-25 11:58:58 +03002053 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2054 params.ht_capa =
2055 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2056
Johannes Bergeccb8e82009-05-11 21:57:56 +03002057 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002058 return -EINVAL;
2059
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002060 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2061 params.plink_action =
2062 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2063
Johannes Berg463d0182009-07-14 00:33:35 +02002064 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002065 if (err)
Johannes Berg034d6552009-05-27 10:35:29 +02002066 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002067
2068 /* validate settings */
2069 err = 0;
2070
2071 switch (dev->ieee80211_ptr->iftype) {
2072 case NL80211_IFTYPE_AP:
2073 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002074 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002075 /* disallow mesh-specific things */
2076 if (params.plink_action)
2077 err = -EINVAL;
2078 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002079 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002080 case NL80211_IFTYPE_STATION:
2081 /* disallow everything but AUTHORIZED flag */
2082 if (params.plink_action)
2083 err = -EINVAL;
2084 if (params.vlan)
2085 err = -EINVAL;
2086 if (params.supported_rates)
2087 err = -EINVAL;
2088 if (params.ht_capa)
2089 err = -EINVAL;
2090 if (params.listen_interval >= 0)
2091 err = -EINVAL;
2092 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2093 err = -EINVAL;
2094 break;
2095 case NL80211_IFTYPE_MESH_POINT:
2096 /* disallow things mesh doesn't support */
2097 if (params.vlan)
2098 err = -EINVAL;
2099 if (params.ht_capa)
2100 err = -EINVAL;
2101 if (params.listen_interval >= 0)
2102 err = -EINVAL;
2103 if (params.supported_rates)
2104 err = -EINVAL;
2105 if (params.sta_flags_mask)
2106 err = -EINVAL;
2107 break;
2108 default:
2109 err = -EINVAL;
Johannes Berg034d6552009-05-27 10:35:29 +02002110 }
2111
Johannes Berg5727ef12007-12-19 02:03:34 +01002112 if (err)
2113 goto out;
2114
Johannes Berg79c97e92009-07-07 03:56:12 +02002115 if (!rdev->ops->change_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002116 err = -EOPNOTSUPP;
2117 goto out;
2118 }
2119
Johannes Berg79c97e92009-07-07 03:56:12 +02002120 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002121
2122 out:
2123 if (params.vlan)
2124 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002125
Johannes Berg5727ef12007-12-19 02:03:34 +01002126 return err;
2127}
2128
2129static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2130{
Johannes Berg4c476992010-10-04 21:36:35 +02002131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002132 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002133 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002134 struct station_parameters params;
2135 u8 *mac_addr = NULL;
2136
2137 memset(&params, 0, sizeof(params));
2138
2139 if (!info->attrs[NL80211_ATTR_MAC])
2140 return -EINVAL;
2141
Johannes Berg5727ef12007-12-19 02:03:34 +01002142 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2143 return -EINVAL;
2144
2145 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2146 return -EINVAL;
2147
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002148 if (!info->attrs[NL80211_ATTR_STA_AID])
2149 return -EINVAL;
2150
Johannes Berg5727ef12007-12-19 02:03:34 +01002151 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2152 params.supported_rates =
2153 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2154 params.supported_rates_len =
2155 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2156 params.listen_interval =
2157 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002158
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002159 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2160 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2161 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002162
Jouni Malinen36aedc92008-08-25 11:58:58 +03002163 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2164 params.ht_capa =
2165 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002166
Johannes Bergeccb8e82009-05-11 21:57:56 +03002167 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002168 return -EINVAL;
2169
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002170 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002171 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg4c476992010-10-04 21:36:35 +02002172 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2173 return -EINVAL;
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002174
Johannes Berg463d0182009-07-14 00:33:35 +02002175 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002176 if (err)
Johannes Berge80cf852009-05-11 14:43:13 +02002177 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002178
2179 /* validate settings */
2180 err = 0;
2181
Johannes Berg79c97e92009-07-07 03:56:12 +02002182 if (!rdev->ops->add_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002183 err = -EOPNOTSUPP;
2184 goto out;
2185 }
2186
Johannes Berg79c97e92009-07-07 03:56:12 +02002187 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002188
2189 out:
2190 if (params.vlan)
2191 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002192 return err;
2193}
2194
2195static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2196{
Johannes Berg4c476992010-10-04 21:36:35 +02002197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2198 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002199 u8 *mac_addr = NULL;
2200
2201 if (info->attrs[NL80211_ATTR_MAC])
2202 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2203
Johannes Berge80cf852009-05-11 14:43:13 +02002204 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002205 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002206 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002207 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2208 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002209
Johannes Berg4c476992010-10-04 21:36:35 +02002210 if (!rdev->ops->del_station)
2211 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002212
Johannes Berg4c476992010-10-04 21:36:35 +02002213 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002214}
2215
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002216static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2217 int flags, struct net_device *dev,
2218 u8 *dst, u8 *next_hop,
2219 struct mpath_info *pinfo)
2220{
2221 void *hdr;
2222 struct nlattr *pinfoattr;
2223
2224 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2225 if (!hdr)
2226 return -1;
2227
2228 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2229 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2230 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2231
Johannes Bergf5ea9122009-08-07 16:17:38 +02002232 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2233
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002234 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2235 if (!pinfoattr)
2236 goto nla_put_failure;
2237 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2238 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2239 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002240 if (pinfo->filled & MPATH_INFO_SN)
2241 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2242 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002243 if (pinfo->filled & MPATH_INFO_METRIC)
2244 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2245 pinfo->metric);
2246 if (pinfo->filled & MPATH_INFO_EXPTIME)
2247 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2248 pinfo->exptime);
2249 if (pinfo->filled & MPATH_INFO_FLAGS)
2250 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2251 pinfo->flags);
2252 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2253 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2254 pinfo->discovery_timeout);
2255 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2256 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2257 pinfo->discovery_retries);
2258
2259 nla_nest_end(msg, pinfoattr);
2260
2261 return genlmsg_end(msg, hdr);
2262
2263 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002264 genlmsg_cancel(msg, hdr);
2265 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002266}
2267
2268static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002269 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002270{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002271 struct mpath_info pinfo;
2272 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002273 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002274 u8 dst[ETH_ALEN];
2275 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002276 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002277 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002278
Johannes Berg67748892010-10-04 21:14:06 +02002279 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2280 if (err)
2281 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002282
2283 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002284 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002285 goto out_err;
2286 }
2287
Jouni Malineneec60b02009-03-20 21:21:19 +02002288 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2289 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002290 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002291 }
2292
Johannes Bergbba95fe2008-07-29 13:22:51 +02002293 while (1) {
2294 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2295 dst, next_hop, &pinfo);
2296 if (err == -ENOENT)
2297 break;
2298 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002299 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002300
2301 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2302 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2303 netdev, dst, next_hop,
2304 &pinfo) < 0)
2305 goto out;
2306
2307 path_idx++;
2308 }
2309
2310
2311 out:
2312 cb->args[1] = path_idx;
2313 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002314 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002315 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002316 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002317}
2318
2319static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2320{
Johannes Berg4c476992010-10-04 21:36:35 +02002321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002322 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002323 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002324 struct mpath_info pinfo;
2325 struct sk_buff *msg;
2326 u8 *dst = NULL;
2327 u8 next_hop[ETH_ALEN];
2328
2329 memset(&pinfo, 0, sizeof(pinfo));
2330
2331 if (!info->attrs[NL80211_ATTR_MAC])
2332 return -EINVAL;
2333
2334 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2335
Johannes Berg4c476992010-10-04 21:36:35 +02002336 if (!rdev->ops->get_mpath)
2337 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002338
Johannes Berg4c476992010-10-04 21:36:35 +02002339 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2340 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002341
Johannes Berg79c97e92009-07-07 03:56:12 +02002342 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002343 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002344 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002345
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002346 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002347 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002348 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002349
2350 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002351 dev, dst, next_hop, &pinfo) < 0) {
2352 nlmsg_free(msg);
2353 return -ENOBUFS;
2354 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002355
Johannes Berg4c476992010-10-04 21:36:35 +02002356 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002357}
2358
2359static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2360{
Johannes Berg4c476992010-10-04 21:36:35 +02002361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2362 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002363 u8 *dst = NULL;
2364 u8 *next_hop = NULL;
2365
2366 if (!info->attrs[NL80211_ATTR_MAC])
2367 return -EINVAL;
2368
2369 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2370 return -EINVAL;
2371
2372 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2373 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2374
Johannes Berg4c476992010-10-04 21:36:35 +02002375 if (!rdev->ops->change_mpath)
2376 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002377
Johannes Berg4c476992010-10-04 21:36:35 +02002378 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2379 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002380
Johannes Berg4c476992010-10-04 21:36:35 +02002381 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002382}
Johannes Berg4c476992010-10-04 21:36:35 +02002383
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002384static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2385{
Johannes Berg4c476992010-10-04 21:36:35 +02002386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2387 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002388 u8 *dst = NULL;
2389 u8 *next_hop = NULL;
2390
2391 if (!info->attrs[NL80211_ATTR_MAC])
2392 return -EINVAL;
2393
2394 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2395 return -EINVAL;
2396
2397 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2398 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2399
Johannes Berg4c476992010-10-04 21:36:35 +02002400 if (!rdev->ops->add_mpath)
2401 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002402
Johannes Berg4c476992010-10-04 21:36:35 +02002403 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2404 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002405
Johannes Berg4c476992010-10-04 21:36:35 +02002406 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002407}
2408
2409static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2410{
Johannes Berg4c476992010-10-04 21:36:35 +02002411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2412 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002413 u8 *dst = NULL;
2414
2415 if (info->attrs[NL80211_ATTR_MAC])
2416 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2417
Johannes Berg4c476992010-10-04 21:36:35 +02002418 if (!rdev->ops->del_mpath)
2419 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002420
Johannes Berg4c476992010-10-04 21:36:35 +02002421 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002422}
2423
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002424static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2425{
Johannes Berg4c476992010-10-04 21:36:35 +02002426 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2427 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002428 struct bss_parameters params;
2429
2430 memset(&params, 0, sizeof(params));
2431 /* default to not changing parameters */
2432 params.use_cts_prot = -1;
2433 params.use_short_preamble = -1;
2434 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002435 params.ap_isolate = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002436
2437 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2438 params.use_cts_prot =
2439 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2440 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2441 params.use_short_preamble =
2442 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2443 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2444 params.use_short_slot_time =
2445 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002446 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2447 params.basic_rates =
2448 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2449 params.basic_rates_len =
2450 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2451 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002452 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2453 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002454
Johannes Berg4c476992010-10-04 21:36:35 +02002455 if (!rdev->ops->change_bss)
2456 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002457
Johannes Berg074ac8d2010-09-16 14:58:22 +02002458 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002459 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2460 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002461
Johannes Berg4c476992010-10-04 21:36:35 +02002462 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002463}
2464
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002465static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002466 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2467 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2468 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2469 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2470 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2471 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2472};
2473
2474static int parse_reg_rule(struct nlattr *tb[],
2475 struct ieee80211_reg_rule *reg_rule)
2476{
2477 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
2478 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
2479
2480 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2481 return -EINVAL;
2482 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2483 return -EINVAL;
2484 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2485 return -EINVAL;
2486 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2487 return -EINVAL;
2488 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2489 return -EINVAL;
2490
2491 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2492
2493 freq_range->start_freq_khz =
2494 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2495 freq_range->end_freq_khz =
2496 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2497 freq_range->max_bandwidth_khz =
2498 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2499
2500 power_rule->max_eirp =
2501 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2502
2503 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2504 power_rule->max_antenna_gain =
2505 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2506
2507 return 0;
2508}
2509
2510static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2511{
2512 int r;
2513 char *data = NULL;
2514
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002515 /*
2516 * You should only get this when cfg80211 hasn't yet initialized
2517 * completely when built-in to the kernel right between the time
2518 * window between nl80211_init() and regulatory_init(), if that is
2519 * even possible.
2520 */
2521 mutex_lock(&cfg80211_mutex);
2522 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002523 mutex_unlock(&cfg80211_mutex);
2524 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002525 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002526 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002527
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002528 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2529 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002530
2531 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2532
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002533 r = regulatory_hint_user(data);
2534
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002535 return r;
2536}
2537
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002538static int nl80211_get_mesh_params(struct sk_buff *skb,
2539 struct genl_info *info)
2540{
Johannes Berg4c476992010-10-04 21:36:35 +02002541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002542 struct mesh_config cur_params;
2543 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002544 struct net_device *dev = info->user_ptr[1];
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002545 void *hdr;
2546 struct nlattr *pinfoattr;
2547 struct sk_buff *msg;
2548
Johannes Berg4c476992010-10-04 21:36:35 +02002549 if (!rdev->ops->get_mesh_params)
2550 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02002551
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002552 /* Get the mesh params */
Johannes Berg79c97e92009-07-07 03:56:12 +02002553 err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002554 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002555 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002556
2557 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002558 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002559 if (!msg)
2560 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002561 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2562 NL80211_CMD_GET_MESH_PARAMS);
2563 if (!hdr)
2564 goto nla_put_failure;
2565 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS);
2566 if (!pinfoattr)
2567 goto nla_put_failure;
2568 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2569 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2570 cur_params.dot11MeshRetryTimeout);
2571 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2572 cur_params.dot11MeshConfirmTimeout);
2573 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2574 cur_params.dot11MeshHoldingTimeout);
2575 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2576 cur_params.dot11MeshMaxPeerLinks);
2577 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2578 cur_params.dot11MeshMaxRetries);
2579 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2580 cur_params.dot11MeshTTL);
2581 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2582 cur_params.auto_open_plinks);
2583 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2584 cur_params.dot11MeshHWMPmaxPREQretries);
2585 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2586 cur_params.path_refresh_time);
2587 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2588 cur_params.min_discovery_timeout);
2589 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2590 cur_params.dot11MeshHWMPactivePathTimeout);
2591 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2592 cur_params.dot11MeshHWMPpreqMinInterval);
2593 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2594 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00002595 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
2596 cur_params.dot11MeshHWMPRootMode);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002597 nla_nest_end(msg, pinfoattr);
2598 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002599 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002600
Johannes Berg3b858752009-03-12 09:55:09 +01002601 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002602 genlmsg_cancel(msg, hdr);
Yuri Ershovd080e272010-06-29 15:08:07 +04002603 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02002604 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002605}
2606
2607#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2608do {\
2609 if (table[attr_num]) {\
2610 cfg.param = nla_fn(table[attr_num]); \
2611 mask |= (1 << (attr_num - 1)); \
2612 } \
2613} while (0);\
2614
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002615static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002616 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2617 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2618 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2619 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2620 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2621 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2622 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2623
2624 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2625 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2626 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2627 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2628 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2629 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2630};
2631
2632static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2633{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002634 u32 mask;
Johannes Berg4c476992010-10-04 21:36:35 +02002635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2636 struct net_device *dev = info->user_ptr[1];
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002637 struct mesh_config cfg;
2638 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2639 struct nlattr *parent_attr;
2640
2641 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2642 if (!parent_attr)
2643 return -EINVAL;
2644 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2645 parent_attr, nl80211_meshconf_params_policy))
2646 return -EINVAL;
2647
Johannes Berg4c476992010-10-04 21:36:35 +02002648 if (!rdev->ops->set_mesh_params)
2649 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02002650
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002651 /* This makes sure that there aren't more than 32 mesh config
2652 * parameters (otherwise our bitfield scheme would not work.) */
2653 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2654
2655 /* Fill in the params struct */
2656 mask = 0;
2657 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2658 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2659 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2660 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2661 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2662 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2663 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2664 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2665 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2666 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2667 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2668 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2669 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2670 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2671 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2672 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2673 nla_get_u8);
2674 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2675 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2676 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2677 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2678 nla_get_u16);
2679 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2680 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2681 nla_get_u32);
2682 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2683 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2684 nla_get_u16);
2685 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2686 dot11MeshHWMPnetDiameterTraversalTime,
2687 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2688 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00002689 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2690 dot11MeshHWMPRootMode, mask,
2691 NL80211_MESHCONF_HWMP_ROOTMODE,
2692 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002693
2694 /* Apply changes */
Johannes Berg4c476992010-10-04 21:36:35 +02002695 return rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002696}
2697
2698#undef FILL_IN_MESH_PARAM_IF_SET
2699
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002700static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2701{
2702 struct sk_buff *msg;
2703 void *hdr = NULL;
2704 struct nlattr *nl_reg_rules;
2705 unsigned int i;
2706 int err = -EINVAL;
2707
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002708 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002709
2710 if (!cfg80211_regdomain)
2711 goto out;
2712
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002713 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002714 if (!msg) {
2715 err = -ENOBUFS;
2716 goto out;
2717 }
2718
2719 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2720 NL80211_CMD_GET_REG);
2721 if (!hdr)
2722 goto nla_put_failure;
2723
2724 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2725 cfg80211_regdomain->alpha2);
2726
2727 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2728 if (!nl_reg_rules)
2729 goto nla_put_failure;
2730
2731 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2732 struct nlattr *nl_reg_rule;
2733 const struct ieee80211_reg_rule *reg_rule;
2734 const struct ieee80211_freq_range *freq_range;
2735 const struct ieee80211_power_rule *power_rule;
2736
2737 reg_rule = &cfg80211_regdomain->reg_rules[i];
2738 freq_range = &reg_rule->freq_range;
2739 power_rule = &reg_rule->power_rule;
2740
2741 nl_reg_rule = nla_nest_start(msg, i);
2742 if (!nl_reg_rule)
2743 goto nla_put_failure;
2744
2745 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2746 reg_rule->flags);
2747 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2748 freq_range->start_freq_khz);
2749 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2750 freq_range->end_freq_khz);
2751 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2752 freq_range->max_bandwidth_khz);
2753 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2754 power_rule->max_antenna_gain);
2755 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2756 power_rule->max_eirp);
2757
2758 nla_nest_end(msg, nl_reg_rule);
2759 }
2760
2761 nla_nest_end(msg, nl_reg_rules);
2762
2763 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00002764 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002765 goto out;
2766
2767nla_put_failure:
2768 genlmsg_cancel(msg, hdr);
Yuri Ershovd080e272010-06-29 15:08:07 +04002769 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002770 err = -EMSGSIZE;
2771out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002772 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002773 return err;
2774}
2775
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002776static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2777{
2778 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
2779 struct nlattr *nl_reg_rule;
2780 char *alpha2 = NULL;
2781 int rem_reg_rules = 0, r = 0;
2782 u32 num_rules = 0, rule_idx = 0, size_of_regd;
2783 struct ieee80211_regdomain *rd = NULL;
2784
2785 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2786 return -EINVAL;
2787
2788 if (!info->attrs[NL80211_ATTR_REG_RULES])
2789 return -EINVAL;
2790
2791 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2792
2793 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2794 rem_reg_rules) {
2795 num_rules++;
2796 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04002797 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002798 }
2799
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04002800 mutex_lock(&cfg80211_mutex);
2801
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04002802 if (!reg_is_valid_request(alpha2)) {
2803 r = -EINVAL;
2804 goto bad_reg;
2805 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002806
2807 size_of_regd = sizeof(struct ieee80211_regdomain) +
2808 (num_rules * sizeof(struct ieee80211_reg_rule));
2809
2810 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04002811 if (!rd) {
2812 r = -ENOMEM;
2813 goto bad_reg;
2814 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002815
2816 rd->n_reg_rules = num_rules;
2817 rd->alpha2[0] = alpha2[0];
2818 rd->alpha2[1] = alpha2[1];
2819
2820 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2821 rem_reg_rules) {
2822 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
2823 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
2824 reg_rule_policy);
2825 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
2826 if (r)
2827 goto bad_reg;
2828
2829 rule_idx++;
2830
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04002831 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
2832 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002833 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04002834 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002835 }
2836
2837 BUG_ON(rule_idx != num_rules);
2838
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002839 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04002840
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002841 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04002842
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002843 return r;
2844
Johannes Bergd2372b32008-10-24 20:32:20 +02002845 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04002846 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002847 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04002848 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002849}
2850
Johannes Berg83f5e2c2009-06-17 17:41:49 +02002851static int validate_scan_freqs(struct nlattr *freqs)
2852{
2853 struct nlattr *attr1, *attr2;
2854 int n_channels = 0, tmp1, tmp2;
2855
2856 nla_for_each_nested(attr1, freqs, tmp1) {
2857 n_channels++;
2858 /*
2859 * Some hardware has a limited channel list for
2860 * scanning, and it is pretty much nonsensical
2861 * to scan for a channel twice, so disallow that
2862 * and don't require drivers to check that the
2863 * channel list they get isn't longer than what
2864 * they can scan, as long as they can scan all
2865 * the channels they registered at once.
2866 */
2867 nla_for_each_nested(attr2, freqs, tmp2)
2868 if (attr1 != attr2 &&
2869 nla_get_u32(attr1) == nla_get_u32(attr2))
2870 return 0;
2871 }
2872
2873 return n_channels;
2874}
2875
Johannes Berg2a519312009-02-10 21:25:55 +01002876static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2877{
Johannes Berg4c476992010-10-04 21:36:35 +02002878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2879 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01002880 struct cfg80211_scan_request *request;
2881 struct cfg80211_ssid *ssid;
2882 struct ieee80211_channel *channel;
2883 struct nlattr *attr;
2884 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02002885 int err, tmp, n_ssids = 0, n_channels, i;
Johannes Berg2a519312009-02-10 21:25:55 +01002886 enum ieee80211_band band;
Jouni Malinen70692ad2009-02-16 19:39:13 +02002887 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01002888
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002889 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2890 return -EINVAL;
2891
Johannes Berg79c97e92009-07-07 03:56:12 +02002892 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01002893
Johannes Berg4c476992010-10-04 21:36:35 +02002894 if (!rdev->ops->scan)
2895 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01002896
Johannes Berg4c476992010-10-04 21:36:35 +02002897 if (rdev->scan_req)
2898 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01002899
2900 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02002901 n_channels = validate_scan_freqs(
2902 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02002903 if (!n_channels)
2904 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01002905 } else {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02002906 n_channels = 0;
2907
Johannes Berg2a519312009-02-10 21:25:55 +01002908 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2909 if (wiphy->bands[band])
2910 n_channels += wiphy->bands[band]->n_channels;
2911 }
2912
2913 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2914 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2915 n_ssids++;
2916
Johannes Berg4c476992010-10-04 21:36:35 +02002917 if (n_ssids > wiphy->max_scan_ssids)
2918 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01002919
Jouni Malinen70692ad2009-02-16 19:39:13 +02002920 if (info->attrs[NL80211_ATTR_IE])
2921 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2922 else
2923 ie_len = 0;
2924
Johannes Berg4c476992010-10-04 21:36:35 +02002925 if (ie_len > wiphy->max_scan_ie_len)
2926 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02002927
Johannes Berg2a519312009-02-10 21:25:55 +01002928 request = kzalloc(sizeof(*request)
2929 + sizeof(*ssid) * n_ssids
Jouni Malinen70692ad2009-02-16 19:39:13 +02002930 + sizeof(channel) * n_channels
2931 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002932 if (!request)
2933 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01002934
Johannes Berg2a519312009-02-10 21:25:55 +01002935 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02002936 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01002937 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02002938 if (ie_len) {
2939 if (request->ssids)
2940 request->ie = (void *)(request->ssids + n_ssids);
2941 else
2942 request->ie = (void *)(request->channels + n_channels);
2943 }
Johannes Berg2a519312009-02-10 21:25:55 +01002944
Johannes Berg584991d2009-11-02 13:32:03 +01002945 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01002946 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2947 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01002948 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01002949 struct ieee80211_channel *chan;
2950
2951 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2952
2953 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01002954 err = -EINVAL;
2955 goto out_free;
2956 }
Johannes Berg584991d2009-11-02 13:32:03 +01002957
2958 /* ignore disabled channels */
2959 if (chan->flags & IEEE80211_CHAN_DISABLED)
2960 continue;
2961
2962 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01002963 i++;
2964 }
2965 } else {
2966 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01002967 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2968 int j;
2969 if (!wiphy->bands[band])
2970 continue;
2971 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01002972 struct ieee80211_channel *chan;
2973
2974 chan = &wiphy->bands[band]->channels[j];
2975
2976 if (chan->flags & IEEE80211_CHAN_DISABLED)
2977 continue;
2978
2979 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01002980 i++;
2981 }
2982 }
2983 }
2984
Johannes Berg584991d2009-11-02 13:32:03 +01002985 if (!i) {
2986 err = -EINVAL;
2987 goto out_free;
2988 }
2989
2990 request->n_channels = i;
2991
Johannes Berg2a519312009-02-10 21:25:55 +01002992 i = 0;
2993 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2994 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2995 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2996 err = -EINVAL;
2997 goto out_free;
2998 }
2999 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
3000 request->ssids[i].ssid_len = nla_len(attr);
3001 i++;
3002 }
3003 }
3004
Jouni Malinen70692ad2009-02-16 19:39:13 +02003005 if (info->attrs[NL80211_ATTR_IE]) {
3006 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003007 memcpy((void *)request->ie,
3008 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003009 request->ie_len);
3010 }
3011
Johannes Berg463d0182009-07-14 00:33:35 +02003012 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003013 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003014
Johannes Berg79c97e92009-07-07 03:56:12 +02003015 rdev->scan_req = request;
3016 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003017
Johannes Berg463d0182009-07-14 00:33:35 +02003018 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003019 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003020 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003021 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003022 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003023 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003024 kfree(request);
3025 }
Johannes Berg3b858752009-03-12 09:55:09 +01003026
Johannes Berg2a519312009-02-10 21:25:55 +01003027 return err;
3028}
3029
3030static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
3031 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02003032 struct wireless_dev *wdev,
3033 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01003034{
Johannes Berg48ab9052009-07-10 18:42:31 +02003035 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01003036 void *hdr;
3037 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02003038 int i;
3039
3040 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003041
3042 hdr = nl80211hdr_put(msg, pid, seq, flags,
3043 NL80211_CMD_NEW_SCAN_RESULTS);
3044 if (!hdr)
3045 return -1;
3046
Johannes Bergf5ea9122009-08-07 16:17:38 +02003047 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02003048 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01003049
3050 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
3051 if (!bss)
3052 goto nla_put_failure;
3053 if (!is_zero_ether_addr(res->bssid))
3054 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
3055 if (res->information_elements && res->len_information_elements)
3056 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
3057 res->len_information_elements,
3058 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02003059 if (res->beacon_ies && res->len_beacon_ies &&
3060 res->beacon_ies != res->information_elements)
3061 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
3062 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01003063 if (res->tsf)
3064 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
3065 if (res->beacon_interval)
3066 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
3067 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
3068 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02003069 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
3070 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01003071
Johannes Berg77965c92009-02-18 18:45:06 +01003072 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01003073 case CFG80211_SIGNAL_TYPE_MBM:
3074 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
3075 break;
3076 case CFG80211_SIGNAL_TYPE_UNSPEC:
3077 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
3078 break;
3079 default:
3080 break;
3081 }
3082
Johannes Berg48ab9052009-07-10 18:42:31 +02003083 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02003084 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02003085 case NL80211_IFTYPE_STATION:
3086 if (intbss == wdev->current_bss)
3087 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3088 NL80211_BSS_STATUS_ASSOCIATED);
3089 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
3090 if (intbss != wdev->auth_bsses[i])
3091 continue;
3092 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3093 NL80211_BSS_STATUS_AUTHENTICATED);
3094 break;
3095 }
3096 break;
3097 case NL80211_IFTYPE_ADHOC:
3098 if (intbss == wdev->current_bss)
3099 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3100 NL80211_BSS_STATUS_IBSS_JOINED);
3101 break;
3102 default:
3103 break;
3104 }
3105
Johannes Berg2a519312009-02-10 21:25:55 +01003106 nla_nest_end(msg, bss);
3107
3108 return genlmsg_end(msg, hdr);
3109
3110 nla_put_failure:
3111 genlmsg_cancel(msg, hdr);
3112 return -EMSGSIZE;
3113}
3114
3115static int nl80211_dump_scan(struct sk_buff *skb,
3116 struct netlink_callback *cb)
3117{
Johannes Berg48ab9052009-07-10 18:42:31 +02003118 struct cfg80211_registered_device *rdev;
3119 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01003120 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02003121 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01003122 int start = cb->args[1], idx = 0;
3123 int err;
3124
Johannes Berg67748892010-10-04 21:14:06 +02003125 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
3126 if (err)
3127 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01003128
Johannes Berg48ab9052009-07-10 18:42:31 +02003129 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01003130
Johannes Berg48ab9052009-07-10 18:42:31 +02003131 wdev_lock(wdev);
3132 spin_lock_bh(&rdev->bss_lock);
3133 cfg80211_bss_expire(rdev);
3134
3135 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01003136 if (++idx <= start)
3137 continue;
3138 if (nl80211_send_bss(skb,
3139 NETLINK_CB(cb->skb).pid,
3140 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02003141 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01003142 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02003143 break;
Johannes Berg2a519312009-02-10 21:25:55 +01003144 }
3145 }
3146
Johannes Berg48ab9052009-07-10 18:42:31 +02003147 spin_unlock_bh(&rdev->bss_lock);
3148 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003149
3150 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02003151 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003152
Johannes Berg67748892010-10-04 21:14:06 +02003153 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01003154}
3155
Holger Schurig61fa7132009-11-11 12:25:40 +01003156static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
3157 int flags, struct net_device *dev,
3158 struct survey_info *survey)
3159{
3160 void *hdr;
3161 struct nlattr *infoattr;
3162
3163 /* Survey without a channel doesn't make sense */
3164 if (!survey->channel)
3165 return -EINVAL;
3166
3167 hdr = nl80211hdr_put(msg, pid, seq, flags,
3168 NL80211_CMD_NEW_SURVEY_RESULTS);
3169 if (!hdr)
3170 return -ENOMEM;
3171
3172 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3173
3174 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
3175 if (!infoattr)
3176 goto nla_put_failure;
3177
3178 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
3179 survey->channel->center_freq);
3180 if (survey->filled & SURVEY_INFO_NOISE_DBM)
3181 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
3182 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02003183 if (survey->filled & SURVEY_INFO_IN_USE)
3184 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02003185 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
3186 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
3187 survey->channel_time);
3188 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
3189 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
3190 survey->channel_time_busy);
3191 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
3192 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
3193 survey->channel_time_ext_busy);
3194 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
3195 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
3196 survey->channel_time_rx);
3197 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
3198 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
3199 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01003200
3201 nla_nest_end(msg, infoattr);
3202
3203 return genlmsg_end(msg, hdr);
3204
3205 nla_put_failure:
3206 genlmsg_cancel(msg, hdr);
3207 return -EMSGSIZE;
3208}
3209
3210static int nl80211_dump_survey(struct sk_buff *skb,
3211 struct netlink_callback *cb)
3212{
3213 struct survey_info survey;
3214 struct cfg80211_registered_device *dev;
3215 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01003216 int survey_idx = cb->args[1];
3217 int res;
3218
Johannes Berg67748892010-10-04 21:14:06 +02003219 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3220 if (res)
3221 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01003222
3223 if (!dev->ops->dump_survey) {
3224 res = -EOPNOTSUPP;
3225 goto out_err;
3226 }
3227
3228 while (1) {
3229 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
3230 &survey);
3231 if (res == -ENOENT)
3232 break;
3233 if (res)
3234 goto out_err;
3235
3236 if (nl80211_send_survey(skb,
3237 NETLINK_CB(cb->skb).pid,
3238 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3239 netdev,
3240 &survey) < 0)
3241 goto out;
3242 survey_idx++;
3243 }
3244
3245 out:
3246 cb->args[1] = survey_idx;
3247 res = skb->len;
3248 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003249 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01003250 return res;
3251}
3252
Jouni Malinen255e7372009-03-20 21:21:17 +02003253static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
3254{
Samuel Ortizb23aa672009-07-01 21:26:54 +02003255 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02003256}
3257
Samuel Ortizb23aa672009-07-01 21:26:54 +02003258static bool nl80211_valid_wpa_versions(u32 wpa_versions)
3259{
3260 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
3261 NL80211_WPA_VERSION_2));
3262}
3263
3264static bool nl80211_valid_akm_suite(u32 akm)
3265{
3266 return akm == WLAN_AKM_SUITE_8021X ||
3267 akm == WLAN_AKM_SUITE_PSK;
3268}
3269
3270static bool nl80211_valid_cipher_suite(u32 cipher)
3271{
3272 return cipher == WLAN_CIPHER_SUITE_WEP40 ||
3273 cipher == WLAN_CIPHER_SUITE_WEP104 ||
3274 cipher == WLAN_CIPHER_SUITE_TKIP ||
3275 cipher == WLAN_CIPHER_SUITE_CCMP ||
3276 cipher == WLAN_CIPHER_SUITE_AES_CMAC;
3277}
3278
3279
Jouni Malinen636a5d32009-03-19 13:39:22 +02003280static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3281{
Johannes Berg4c476992010-10-04 21:36:35 +02003282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3283 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003284 struct ieee80211_channel *chan;
3285 const u8 *bssid, *ssid, *ie = NULL;
3286 int err, ssid_len, ie_len = 0;
3287 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02003288 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003289 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003290
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003291 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3292 return -EINVAL;
3293
3294 if (!info->attrs[NL80211_ATTR_MAC])
3295 return -EINVAL;
3296
Jouni Malinen17780922009-03-27 20:52:47 +02003297 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
3298 return -EINVAL;
3299
Johannes Berg19957bb2009-07-02 17:20:43 +02003300 if (!info->attrs[NL80211_ATTR_SSID])
3301 return -EINVAL;
3302
3303 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
3304 return -EINVAL;
3305
Johannes Bergfffd0932009-07-08 14:22:54 +02003306 err = nl80211_parse_key(info, &key);
3307 if (err)
3308 return err;
3309
3310 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02003311 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
3312 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003313 if (!key.p.key || !key.p.key_len)
3314 return -EINVAL;
3315 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
3316 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
3317 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
3318 key.p.key_len != WLAN_KEY_LEN_WEP104))
3319 return -EINVAL;
3320 if (key.idx > 4)
3321 return -EINVAL;
3322 } else {
3323 key.p.key_len = 0;
3324 key.p.key = NULL;
3325 }
3326
Johannes Bergafea0b72010-08-10 09:46:42 +02003327 if (key.idx >= 0) {
3328 int i;
3329 bool ok = false;
3330 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
3331 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
3332 ok = true;
3333 break;
3334 }
3335 }
Johannes Berg4c476992010-10-04 21:36:35 +02003336 if (!ok)
3337 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02003338 }
3339
Johannes Berg4c476992010-10-04 21:36:35 +02003340 if (!rdev->ops->auth)
3341 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003342
Johannes Berg074ac8d2010-09-16 14:58:22 +02003343 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003344 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3345 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003346
Johannes Berg19957bb2009-07-02 17:20:43 +02003347 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02003348 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02003349 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02003350 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
3351 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003352
Johannes Berg19957bb2009-07-02 17:20:43 +02003353 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3354 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3355
3356 if (info->attrs[NL80211_ATTR_IE]) {
3357 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3358 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3359 }
3360
3361 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02003362 if (!nl80211_valid_auth_type(auth_type))
3363 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02003364
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003365 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3366
Johannes Berg4c476992010-10-04 21:36:35 +02003367 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
3368 ssid, ssid_len, ie, ie_len,
3369 key.p.key, key.p.key_len, key.idx,
3370 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003371}
3372
Johannes Bergc0692b82010-08-27 14:26:53 +03003373static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
3374 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02003375 struct cfg80211_crypto_settings *settings,
3376 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02003377{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02003378 memset(settings, 0, sizeof(*settings));
3379
Samuel Ortizb23aa672009-07-01 21:26:54 +02003380 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
3381
Johannes Bergc0692b82010-08-27 14:26:53 +03003382 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
3383 u16 proto;
3384 proto = nla_get_u16(
3385 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
3386 settings->control_port_ethertype = cpu_to_be16(proto);
3387 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
3388 proto != ETH_P_PAE)
3389 return -EINVAL;
3390 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
3391 settings->control_port_no_encrypt = true;
3392 } else
3393 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
3394
Samuel Ortizb23aa672009-07-01 21:26:54 +02003395 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
3396 void *data;
3397 int len, i;
3398
3399 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
3400 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
3401 settings->n_ciphers_pairwise = len / sizeof(u32);
3402
3403 if (len % sizeof(u32))
3404 return -EINVAL;
3405
Johannes Berg3dc27d22009-07-02 21:36:37 +02003406 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02003407 return -EINVAL;
3408
3409 memcpy(settings->ciphers_pairwise, data, len);
3410
3411 for (i = 0; i < settings->n_ciphers_pairwise; i++)
3412 if (!nl80211_valid_cipher_suite(
3413 settings->ciphers_pairwise[i]))
3414 return -EINVAL;
3415 }
3416
3417 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
3418 settings->cipher_group =
3419 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
3420 if (!nl80211_valid_cipher_suite(settings->cipher_group))
3421 return -EINVAL;
3422 }
3423
3424 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
3425 settings->wpa_versions =
3426 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
3427 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
3428 return -EINVAL;
3429 }
3430
3431 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
3432 void *data;
3433 int len, i;
3434
3435 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
3436 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
3437 settings->n_akm_suites = len / sizeof(u32);
3438
3439 if (len % sizeof(u32))
3440 return -EINVAL;
3441
3442 memcpy(settings->akm_suites, data, len);
3443
3444 for (i = 0; i < settings->n_ciphers_pairwise; i++)
3445 if (!nl80211_valid_akm_suite(settings->akm_suites[i]))
3446 return -EINVAL;
3447 }
3448
3449 return 0;
3450}
3451
Jouni Malinen636a5d32009-03-19 13:39:22 +02003452static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3453{
Johannes Berg4c476992010-10-04 21:36:35 +02003454 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3455 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003456 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02003457 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02003458 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02003459 int err, ssid_len, ie_len = 0;
3460 bool use_mfp = false;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003461
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003462 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3463 return -EINVAL;
3464
3465 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02003466 !info->attrs[NL80211_ATTR_SSID] ||
3467 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003468 return -EINVAL;
3469
Johannes Berg4c476992010-10-04 21:36:35 +02003470 if (!rdev->ops->assoc)
3471 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003472
Johannes Berg074ac8d2010-09-16 14:58:22 +02003473 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003474 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3475 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003476
Johannes Berg19957bb2009-07-02 17:20:43 +02003477 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003478
Johannes Berg19957bb2009-07-02 17:20:43 +02003479 chan = ieee80211_get_channel(&rdev->wiphy,
3480 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02003481 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
3482 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003483
Johannes Berg19957bb2009-07-02 17:20:43 +02003484 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3485 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003486
3487 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02003488 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3489 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003490 }
3491
Jouni Malinendc6382ce2009-05-06 22:09:37 +03003492 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02003493 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03003494 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02003495 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02003496 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02003497 else if (mfp != NL80211_MFP_NO)
3498 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03003499 }
3500
Johannes Berg3e5d7642009-07-07 14:37:26 +02003501 if (info->attrs[NL80211_ATTR_PREV_BSSID])
3502 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
3503
Johannes Bergc0692b82010-08-27 14:26:53 +03003504 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02003505 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02003506 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
3507 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Berg19957bb2009-07-02 17:20:43 +02003508 &crypto);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003509
Jouni Malinen636a5d32009-03-19 13:39:22 +02003510 return err;
3511}
3512
3513static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3514{
Johannes Berg4c476992010-10-04 21:36:35 +02003515 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3516 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003517 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02003518 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02003519 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003520 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003521
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003522 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3523 return -EINVAL;
3524
3525 if (!info->attrs[NL80211_ATTR_MAC])
3526 return -EINVAL;
3527
3528 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3529 return -EINVAL;
3530
Johannes Berg4c476992010-10-04 21:36:35 +02003531 if (!rdev->ops->deauth)
3532 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003533
Johannes Berg074ac8d2010-09-16 14:58:22 +02003534 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003535 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3536 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003537
Johannes Berg19957bb2009-07-02 17:20:43 +02003538 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003539
Johannes Berg19957bb2009-07-02 17:20:43 +02003540 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3541 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003542 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02003543 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02003544 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02003545
3546 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02003547 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3548 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003549 }
3550
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003551 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3552
Johannes Berg4c476992010-10-04 21:36:35 +02003553 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
3554 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003555}
3556
3557static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3558{
Johannes Berg4c476992010-10-04 21:36:35 +02003559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3560 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003561 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02003562 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02003563 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003564 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003565
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003566 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3567 return -EINVAL;
3568
3569 if (!info->attrs[NL80211_ATTR_MAC])
3570 return -EINVAL;
3571
3572 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3573 return -EINVAL;
3574
Johannes Berg4c476992010-10-04 21:36:35 +02003575 if (!rdev->ops->disassoc)
3576 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003577
Johannes Berg074ac8d2010-09-16 14:58:22 +02003578 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003579 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3580 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003581
Johannes Berg19957bb2009-07-02 17:20:43 +02003582 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003583
Johannes Berg19957bb2009-07-02 17:20:43 +02003584 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3585 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003586 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02003587 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02003588 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02003589
3590 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02003591 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3592 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003593 }
3594
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003595 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
3596
Johannes Berg4c476992010-10-04 21:36:35 +02003597 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
3598 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02003599}
3600
Johannes Berg04a773a2009-04-19 21:24:32 +02003601static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3602{
Johannes Berg4c476992010-10-04 21:36:35 +02003603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3604 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02003605 struct cfg80211_ibss_params ibss;
3606 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02003607 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02003608 int err;
3609
Johannes Berg8e30bc52009-04-22 17:45:38 +02003610 memset(&ibss, 0, sizeof(ibss));
3611
Johannes Berg04a773a2009-04-19 21:24:32 +02003612 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3613 return -EINVAL;
3614
3615 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
3616 !info->attrs[NL80211_ATTR_SSID] ||
3617 !nla_len(info->attrs[NL80211_ATTR_SSID]))
3618 return -EINVAL;
3619
Johannes Berg8e30bc52009-04-22 17:45:38 +02003620 ibss.beacon_interval = 100;
3621
3622 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
3623 ibss.beacon_interval =
3624 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3625 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
3626 return -EINVAL;
3627 }
3628
Johannes Berg4c476992010-10-04 21:36:35 +02003629 if (!rdev->ops->join_ibss)
3630 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02003631
Johannes Berg4c476992010-10-04 21:36:35 +02003632 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
3633 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02003634
Johannes Berg79c97e92009-07-07 03:56:12 +02003635 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02003636
3637 if (info->attrs[NL80211_ATTR_MAC])
3638 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3639 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3640 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3641
3642 if (info->attrs[NL80211_ATTR_IE]) {
3643 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3644 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3645 }
3646
3647 ibss.channel = ieee80211_get_channel(wiphy,
3648 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3649 if (!ibss.channel ||
3650 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02003651 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
3652 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02003653
3654 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02003655 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02003656
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003657 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3658 u8 *rates =
3659 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3660 int n_rates =
3661 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3662 struct ieee80211_supported_band *sband =
3663 wiphy->bands[ibss.channel->band];
3664 int i, j;
3665
Johannes Berg4c476992010-10-04 21:36:35 +02003666 if (n_rates == 0)
3667 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003668
3669 for (i = 0; i < n_rates; i++) {
3670 int rate = (rates[i] & 0x7f) * 5;
3671 bool found = false;
3672
3673 for (j = 0; j < sband->n_bitrates; j++) {
3674 if (sband->bitrates[j].bitrate == rate) {
3675 found = true;
3676 ibss.basic_rates |= BIT(j);
3677 break;
3678 }
3679 }
Johannes Berg4c476992010-10-04 21:36:35 +02003680 if (!found)
3681 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003682 }
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03003683 }
3684
Johannes Berg4c476992010-10-04 21:36:35 +02003685 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
3686 connkeys = nl80211_parse_connkeys(rdev,
3687 info->attrs[NL80211_ATTR_KEYS]);
3688 if (IS_ERR(connkeys))
3689 return PTR_ERR(connkeys);
3690 }
Johannes Berg04a773a2009-04-19 21:24:32 +02003691
Johannes Berg4c476992010-10-04 21:36:35 +02003692 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02003693 if (err)
3694 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02003695 return err;
3696}
3697
3698static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
3699{
Johannes Berg4c476992010-10-04 21:36:35 +02003700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3701 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02003702
Johannes Berg4c476992010-10-04 21:36:35 +02003703 if (!rdev->ops->leave_ibss)
3704 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02003705
Johannes Berg4c476992010-10-04 21:36:35 +02003706 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
3707 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02003708
Johannes Berg4c476992010-10-04 21:36:35 +02003709 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02003710}
3711
Johannes Bergaff89a92009-07-01 21:26:51 +02003712#ifdef CONFIG_NL80211_TESTMODE
3713static struct genl_multicast_group nl80211_testmode_mcgrp = {
3714 .name = "testmode",
3715};
3716
3717static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
3718{
Johannes Berg4c476992010-10-04 21:36:35 +02003719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02003720 int err;
3721
3722 if (!info->attrs[NL80211_ATTR_TESTDATA])
3723 return -EINVAL;
3724
Johannes Bergaff89a92009-07-01 21:26:51 +02003725 err = -EOPNOTSUPP;
3726 if (rdev->ops->testmode_cmd) {
3727 rdev->testmode_info = info;
3728 err = rdev->ops->testmode_cmd(&rdev->wiphy,
3729 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
3730 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
3731 rdev->testmode_info = NULL;
3732 }
3733
Johannes Bergaff89a92009-07-01 21:26:51 +02003734 return err;
3735}
3736
3737static struct sk_buff *
3738__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
3739 int approxlen, u32 pid, u32 seq, gfp_t gfp)
3740{
3741 struct sk_buff *skb;
3742 void *hdr;
3743 struct nlattr *data;
3744
3745 skb = nlmsg_new(approxlen + 100, gfp);
3746 if (!skb)
3747 return NULL;
3748
3749 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
3750 if (!hdr) {
3751 kfree_skb(skb);
3752 return NULL;
3753 }
3754
3755 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3756 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
3757
3758 ((void **)skb->cb)[0] = rdev;
3759 ((void **)skb->cb)[1] = hdr;
3760 ((void **)skb->cb)[2] = data;
3761
3762 return skb;
3763
3764 nla_put_failure:
3765 kfree_skb(skb);
3766 return NULL;
3767}
3768
3769struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
3770 int approxlen)
3771{
3772 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
3773
3774 if (WARN_ON(!rdev->testmode_info))
3775 return NULL;
3776
3777 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
3778 rdev->testmode_info->snd_pid,
3779 rdev->testmode_info->snd_seq,
3780 GFP_KERNEL);
3781}
3782EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
3783
3784int cfg80211_testmode_reply(struct sk_buff *skb)
3785{
3786 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
3787 void *hdr = ((void **)skb->cb)[1];
3788 struct nlattr *data = ((void **)skb->cb)[2];
3789
3790 if (WARN_ON(!rdev->testmode_info)) {
3791 kfree_skb(skb);
3792 return -EINVAL;
3793 }
3794
3795 nla_nest_end(skb, data);
3796 genlmsg_end(skb, hdr);
3797 return genlmsg_reply(skb, rdev->testmode_info);
3798}
3799EXPORT_SYMBOL(cfg80211_testmode_reply);
3800
3801struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
3802 int approxlen, gfp_t gfp)
3803{
3804 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
3805
3806 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
3807}
3808EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
3809
3810void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
3811{
3812 void *hdr = ((void **)skb->cb)[1];
3813 struct nlattr *data = ((void **)skb->cb)[2];
3814
3815 nla_nest_end(skb, data);
3816 genlmsg_end(skb, hdr);
3817 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
3818}
3819EXPORT_SYMBOL(cfg80211_testmode_event);
3820#endif
3821
Samuel Ortizb23aa672009-07-01 21:26:54 +02003822static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
3823{
Johannes Berg4c476992010-10-04 21:36:35 +02003824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3825 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02003826 struct cfg80211_connect_params connect;
3827 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02003828 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02003829 int err;
3830
3831 memset(&connect, 0, sizeof(connect));
3832
3833 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3834 return -EINVAL;
3835
3836 if (!info->attrs[NL80211_ATTR_SSID] ||
3837 !nla_len(info->attrs[NL80211_ATTR_SSID]))
3838 return -EINVAL;
3839
3840 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3841 connect.auth_type =
3842 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
3843 if (!nl80211_valid_auth_type(connect.auth_type))
3844 return -EINVAL;
3845 } else
3846 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3847
3848 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
3849
Johannes Bergc0692b82010-08-27 14:26:53 +03003850 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02003851 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02003852 if (err)
3853 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02003854
Johannes Berg074ac8d2010-09-16 14:58:22 +02003855 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003856 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3857 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02003858
Johannes Berg79c97e92009-07-07 03:56:12 +02003859 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02003860
Samuel Ortizb23aa672009-07-01 21:26:54 +02003861 if (info->attrs[NL80211_ATTR_MAC])
3862 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3863 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3864 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3865
3866 if (info->attrs[NL80211_ATTR_IE]) {
3867 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3868 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3869 }
3870
3871 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3872 connect.channel =
3873 ieee80211_get_channel(wiphy,
3874 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3875 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02003876 connect.channel->flags & IEEE80211_CHAN_DISABLED)
3877 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02003878 }
3879
Johannes Bergfffd0932009-07-08 14:22:54 +02003880 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
3881 connkeys = nl80211_parse_connkeys(rdev,
3882 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02003883 if (IS_ERR(connkeys))
3884 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02003885 }
3886
3887 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02003888 if (err)
3889 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02003890 return err;
3891}
3892
3893static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
3894{
Johannes Berg4c476992010-10-04 21:36:35 +02003895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3896 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02003897 u16 reason;
3898
3899 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3900 reason = WLAN_REASON_DEAUTH_LEAVING;
3901 else
3902 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3903
3904 if (reason == 0)
3905 return -EINVAL;
3906
Johannes Berg074ac8d2010-09-16 14:58:22 +02003907 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003908 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3909 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02003910
Johannes Berg4c476992010-10-04 21:36:35 +02003911 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02003912}
3913
Johannes Berg463d0182009-07-14 00:33:35 +02003914static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
3915{
Johannes Berg4c476992010-10-04 21:36:35 +02003916 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02003917 struct net *net;
3918 int err;
3919 u32 pid;
3920
3921 if (!info->attrs[NL80211_ATTR_PID])
3922 return -EINVAL;
3923
3924 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
3925
Johannes Berg463d0182009-07-14 00:33:35 +02003926 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02003927 if (IS_ERR(net))
3928 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02003929
3930 err = 0;
3931
3932 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02003933 if (!net_eq(wiphy_net(&rdev->wiphy), net))
3934 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02003935
Johannes Berg463d0182009-07-14 00:33:35 +02003936 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02003937 return err;
3938}
3939
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003940static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
3941{
Johannes Berg4c476992010-10-04 21:36:35 +02003942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003943 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
3944 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003945 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003946 struct cfg80211_pmksa pmksa;
3947
3948 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
3949
3950 if (!info->attrs[NL80211_ATTR_MAC])
3951 return -EINVAL;
3952
3953 if (!info->attrs[NL80211_ATTR_PMKID])
3954 return -EINVAL;
3955
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003956 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
3957 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3958
Johannes Berg074ac8d2010-09-16 14:58:22 +02003959 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003960 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3961 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003962
3963 switch (info->genlhdr->cmd) {
3964 case NL80211_CMD_SET_PMKSA:
3965 rdev_ops = rdev->ops->set_pmksa;
3966 break;
3967 case NL80211_CMD_DEL_PMKSA:
3968 rdev_ops = rdev->ops->del_pmksa;
3969 break;
3970 default:
3971 WARN_ON(1);
3972 break;
3973 }
3974
Johannes Berg4c476992010-10-04 21:36:35 +02003975 if (!rdev_ops)
3976 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003977
Johannes Berg4c476992010-10-04 21:36:35 +02003978 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003979}
3980
3981static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
3982{
Johannes Berg4c476992010-10-04 21:36:35 +02003983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3984 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003985
Johannes Berg074ac8d2010-09-16 14:58:22 +02003986 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003987 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3988 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003989
Johannes Berg4c476992010-10-04 21:36:35 +02003990 if (!rdev->ops->flush_pmksa)
3991 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003992
Johannes Berg4c476992010-10-04 21:36:35 +02003993 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01003994}
3995
Jouni Malinen9588bbd2009-12-23 13:15:41 +01003996static int nl80211_remain_on_channel(struct sk_buff *skb,
3997 struct genl_info *info)
3998{
Johannes Berg4c476992010-10-04 21:36:35 +02003999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4000 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004001 struct ieee80211_channel *chan;
4002 struct sk_buff *msg;
4003 void *hdr;
4004 u64 cookie;
4005 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
4006 u32 freq, duration;
4007 int err;
4008
4009 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4010 !info->attrs[NL80211_ATTR_DURATION])
4011 return -EINVAL;
4012
4013 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
4014
4015 /*
4016 * We should be on that channel for at least one jiffie,
4017 * and more than 5 seconds seems excessive.
4018 */
4019 if (!duration || !msecs_to_jiffies(duration) || duration > 5000)
4020 return -EINVAL;
4021
Johannes Berg4c476992010-10-04 21:36:35 +02004022 if (!rdev->ops->remain_on_channel)
4023 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004024
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004025 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4026 channel_type = nla_get_u32(
4027 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4028 if (channel_type != NL80211_CHAN_NO_HT &&
4029 channel_type != NL80211_CHAN_HT20 &&
4030 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02004031 channel_type != NL80211_CHAN_HT40MINUS)
4032 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004033 }
4034
4035 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4036 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02004037 if (chan == NULL)
4038 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004039
4040 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004041 if (!msg)
4042 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004043
4044 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4045 NL80211_CMD_REMAIN_ON_CHANNEL);
4046
4047 if (IS_ERR(hdr)) {
4048 err = PTR_ERR(hdr);
4049 goto free_msg;
4050 }
4051
4052 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
4053 channel_type, duration, &cookie);
4054
4055 if (err)
4056 goto free_msg;
4057
4058 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4059
4060 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004061
4062 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004063
4064 nla_put_failure:
4065 err = -ENOBUFS;
4066 free_msg:
4067 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004068 return err;
4069}
4070
4071static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
4072 struct genl_info *info)
4073{
Johannes Berg4c476992010-10-04 21:36:35 +02004074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4075 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004076 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004077
4078 if (!info->attrs[NL80211_ATTR_COOKIE])
4079 return -EINVAL;
4080
Johannes Berg4c476992010-10-04 21:36:35 +02004081 if (!rdev->ops->cancel_remain_on_channel)
4082 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004083
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004084 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4085
Johannes Berg4c476992010-10-04 21:36:35 +02004086 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004087}
4088
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004089static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4090 u8 *rates, u8 rates_len)
4091{
4092 u8 i;
4093 u32 mask = 0;
4094
4095 for (i = 0; i < rates_len; i++) {
4096 int rate = (rates[i] & 0x7f) * 5;
4097 int ridx;
4098 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4099 struct ieee80211_rate *srate =
4100 &sband->bitrates[ridx];
4101 if (rate == srate->bitrate) {
4102 mask |= 1 << ridx;
4103 break;
4104 }
4105 }
4106 if (ridx == sband->n_bitrates)
4107 return 0; /* rate not found */
4108 }
4109
4110 return mask;
4111}
4112
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004113static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004114 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4115 .len = NL80211_MAX_SUPP_RATES },
4116};
4117
4118static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4119 struct genl_info *info)
4120{
4121 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02004122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004123 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02004124 int rem, i;
4125 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004126 struct nlattr *tx_rates;
4127 struct ieee80211_supported_band *sband;
4128
4129 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
4130 return -EINVAL;
4131
Johannes Berg4c476992010-10-04 21:36:35 +02004132 if (!rdev->ops->set_bitrate_mask)
4133 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004134
4135 memset(&mask, 0, sizeof(mask));
4136 /* Default to all rates enabled */
4137 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
4138 sband = rdev->wiphy.bands[i];
4139 mask.control[i].legacy =
4140 sband ? (1 << sband->n_bitrates) - 1 : 0;
4141 }
4142
4143 /*
4144 * The nested attribute uses enum nl80211_band as the index. This maps
4145 * directly to the enum ieee80211_band values used in cfg80211.
4146 */
4147 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
4148 {
4149 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02004150 if (band < 0 || band >= IEEE80211_NUM_BANDS)
4151 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004152 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02004153 if (sband == NULL)
4154 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004155 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
4156 nla_len(tx_rates), nl80211_txattr_policy);
4157 if (tb[NL80211_TXRATE_LEGACY]) {
4158 mask.control[band].legacy = rateset_to_mask(
4159 sband,
4160 nla_data(tb[NL80211_TXRATE_LEGACY]),
4161 nla_len(tb[NL80211_TXRATE_LEGACY]));
Johannes Berg4c476992010-10-04 21:36:35 +02004162 if (mask.control[band].legacy == 0)
4163 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004164 }
4165 }
4166
Johannes Berg4c476992010-10-04 21:36:35 +02004167 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004168}
4169
Johannes Berg2e161f72010-08-12 15:38:38 +02004170static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004171{
Johannes Berg4c476992010-10-04 21:36:35 +02004172 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4173 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02004174 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02004175
4176 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
4177 return -EINVAL;
4178
Johannes Berg2e161f72010-08-12 15:38:38 +02004179 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
4180 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02004181
Johannes Berg9d38d852010-06-09 17:20:33 +02004182 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004183 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02004184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4185 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4186 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg4c476992010-10-04 21:36:35 +02004187 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4188 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004189
4190 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02004191 if (!rdev->ops->mgmt_tx)
4192 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004193
Johannes Berg4c476992010-10-04 21:36:35 +02004194 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02004195 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02004196 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
4197 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02004198}
4199
Johannes Berg2e161f72010-08-12 15:38:38 +02004200static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004201{
Johannes Berg4c476992010-10-04 21:36:35 +02004202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4203 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02004204 struct ieee80211_channel *chan;
4205 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02004206 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02004207 u32 freq;
4208 int err;
4209 void *hdr;
4210 u64 cookie;
4211 struct sk_buff *msg;
4212
4213 if (!info->attrs[NL80211_ATTR_FRAME] ||
4214 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
4215 return -EINVAL;
4216
Johannes Berg4c476992010-10-04 21:36:35 +02004217 if (!rdev->ops->mgmt_tx)
4218 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004219
Johannes Berg9d38d852010-06-09 17:20:33 +02004220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004221 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02004222 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4223 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4224 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg4c476992010-10-04 21:36:35 +02004225 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4226 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004227
Jouni Malinen026331c2010-02-15 12:53:10 +02004228 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4229 channel_type = nla_get_u32(
4230 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4231 if (channel_type != NL80211_CHAN_NO_HT &&
4232 channel_type != NL80211_CHAN_HT20 &&
4233 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02004234 channel_type != NL80211_CHAN_HT40MINUS)
4235 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02004236 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02004237 }
4238
4239 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4240 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02004241 if (chan == NULL)
4242 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02004243
4244 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004245 if (!msg)
4246 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02004247
4248 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg2e161f72010-08-12 15:38:38 +02004249 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02004250
4251 if (IS_ERR(hdr)) {
4252 err = PTR_ERR(hdr);
4253 goto free_msg;
4254 }
Johannes Berg2e161f72010-08-12 15:38:38 +02004255 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, channel_type,
4256 channel_type_valid,
4257 nla_data(info->attrs[NL80211_ATTR_FRAME]),
4258 nla_len(info->attrs[NL80211_ATTR_FRAME]),
4259 &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02004260 if (err)
4261 goto free_msg;
4262
4263 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4264
4265 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004266 return genlmsg_reply(msg, info);
Jouni Malinen026331c2010-02-15 12:53:10 +02004267
4268 nla_put_failure:
4269 err = -ENOBUFS;
4270 free_msg:
4271 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02004272 return err;
4273}
4274
Kalle Valoffb9eb32010-02-17 17:58:10 +02004275static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
4276{
Johannes Berg4c476992010-10-04 21:36:35 +02004277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02004278 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02004279 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02004280 u8 ps_state;
4281 bool state;
4282 int err;
4283
Johannes Berg4c476992010-10-04 21:36:35 +02004284 if (!info->attrs[NL80211_ATTR_PS_STATE])
4285 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004286
4287 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
4288
Johannes Berg4c476992010-10-04 21:36:35 +02004289 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
4290 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004291
4292 wdev = dev->ieee80211_ptr;
4293
Johannes Berg4c476992010-10-04 21:36:35 +02004294 if (!rdev->ops->set_power_mgmt)
4295 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004296
4297 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
4298
4299 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02004300 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004301
Johannes Berg4c476992010-10-04 21:36:35 +02004302 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
4303 wdev->ps_timeout);
4304 if (!err)
4305 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004306 return err;
4307}
4308
4309static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
4310{
Johannes Berg4c476992010-10-04 21:36:35 +02004311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02004312 enum nl80211_ps_state ps_state;
4313 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02004314 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02004315 struct sk_buff *msg;
4316 void *hdr;
4317 int err;
4318
Kalle Valoffb9eb32010-02-17 17:58:10 +02004319 wdev = dev->ieee80211_ptr;
4320
Johannes Berg4c476992010-10-04 21:36:35 +02004321 if (!rdev->ops->set_power_mgmt)
4322 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004323
4324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004325 if (!msg)
4326 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004327
4328 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4329 NL80211_CMD_GET_POWER_SAVE);
4330 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02004331 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02004332 goto free_msg;
4333 }
4334
4335 if (wdev->ps)
4336 ps_state = NL80211_PS_ENABLED;
4337 else
4338 ps_state = NL80211_PS_DISABLED;
4339
4340 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
4341
4342 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004343 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02004344
Johannes Berg4c476992010-10-04 21:36:35 +02004345 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02004346 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02004347 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02004348 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02004349 return err;
4350}
4351
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004352static struct nla_policy
4353nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
4354 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
4355 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
4356 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
4357};
4358
4359static int nl80211_set_cqm_rssi(struct genl_info *info,
4360 s32 threshold, u32 hysteresis)
4361{
Johannes Berg4c476992010-10-04 21:36:35 +02004362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004363 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02004364 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004365
4366 if (threshold > 0)
4367 return -EINVAL;
4368
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004369 wdev = dev->ieee80211_ptr;
4370
Johannes Berg4c476992010-10-04 21:36:35 +02004371 if (!rdev->ops->set_cqm_rssi_config)
4372 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004373
Johannes Berg074ac8d2010-09-16 14:58:22 +02004374 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004375 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
4376 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004377
Johannes Berg4c476992010-10-04 21:36:35 +02004378 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
4379 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004380}
4381
4382static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
4383{
4384 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
4385 struct nlattr *cqm;
4386 int err;
4387
4388 cqm = info->attrs[NL80211_ATTR_CQM];
4389 if (!cqm) {
4390 err = -EINVAL;
4391 goto out;
4392 }
4393
4394 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
4395 nl80211_attr_cqm_policy);
4396 if (err)
4397 goto out;
4398
4399 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
4400 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
4401 s32 threshold;
4402 u32 hysteresis;
4403 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
4404 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
4405 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
4406 } else
4407 err = -EINVAL;
4408
4409out:
4410 return err;
4411}
4412
Johannes Berg4c476992010-10-04 21:36:35 +02004413#define NL80211_FLAG_NEED_WIPHY 0x01
4414#define NL80211_FLAG_NEED_NETDEV 0x02
4415#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02004416#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
4417#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
4418 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02004419
4420static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
4421 struct genl_info *info)
4422{
4423 struct cfg80211_registered_device *rdev;
4424 struct net_device *dev;
4425 int err;
4426 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
4427
4428 if (rtnl)
4429 rtnl_lock();
4430
4431 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
4432 rdev = cfg80211_get_dev_from_info(info);
4433 if (IS_ERR(rdev)) {
4434 if (rtnl)
4435 rtnl_unlock();
4436 return PTR_ERR(rdev);
4437 }
4438 info->user_ptr[0] = rdev;
4439 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
4440 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4441 if (err) {
4442 if (rtnl)
4443 rtnl_unlock();
4444 return err;
4445 }
Johannes Berg41265712010-10-04 21:14:05 +02004446 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
4447 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02004448 cfg80211_unlock_rdev(rdev);
4449 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02004450 if (rtnl)
4451 rtnl_unlock();
4452 return -ENETDOWN;
4453 }
Johannes Berg4c476992010-10-04 21:36:35 +02004454 info->user_ptr[0] = rdev;
4455 info->user_ptr[1] = dev;
4456 }
4457
4458 return 0;
4459}
4460
4461static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
4462 struct genl_info *info)
4463{
4464 if (info->user_ptr[0])
4465 cfg80211_unlock_rdev(info->user_ptr[0]);
4466 if (info->user_ptr[1])
4467 dev_put(info->user_ptr[1]);
4468 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
4469 rtnl_unlock();
4470}
4471
Johannes Berg55682962007-09-20 13:09:35 -04004472static struct genl_ops nl80211_ops[] = {
4473 {
4474 .cmd = NL80211_CMD_GET_WIPHY,
4475 .doit = nl80211_get_wiphy,
4476 .dumpit = nl80211_dump_wiphy,
4477 .policy = nl80211_policy,
4478 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02004479 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04004480 },
4481 {
4482 .cmd = NL80211_CMD_SET_WIPHY,
4483 .doit = nl80211_set_wiphy,
4484 .policy = nl80211_policy,
4485 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004486 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04004487 },
4488 {
4489 .cmd = NL80211_CMD_GET_INTERFACE,
4490 .doit = nl80211_get_interface,
4491 .dumpit = nl80211_dump_interface,
4492 .policy = nl80211_policy,
4493 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02004494 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04004495 },
4496 {
4497 .cmd = NL80211_CMD_SET_INTERFACE,
4498 .doit = nl80211_set_interface,
4499 .policy = nl80211_policy,
4500 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004501 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4502 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04004503 },
4504 {
4505 .cmd = NL80211_CMD_NEW_INTERFACE,
4506 .doit = nl80211_new_interface,
4507 .policy = nl80211_policy,
4508 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004509 .internal_flags = NL80211_FLAG_NEED_WIPHY |
4510 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04004511 },
4512 {
4513 .cmd = NL80211_CMD_DEL_INTERFACE,
4514 .doit = nl80211_del_interface,
4515 .policy = nl80211_policy,
4516 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004517 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4518 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04004519 },
Johannes Berg41ade002007-12-19 02:03:29 +01004520 {
4521 .cmd = NL80211_CMD_GET_KEY,
4522 .doit = nl80211_get_key,
4523 .policy = nl80211_policy,
4524 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004525 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4526 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01004527 },
4528 {
4529 .cmd = NL80211_CMD_SET_KEY,
4530 .doit = nl80211_set_key,
4531 .policy = nl80211_policy,
4532 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004533 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004534 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01004535 },
4536 {
4537 .cmd = NL80211_CMD_NEW_KEY,
4538 .doit = nl80211_new_key,
4539 .policy = nl80211_policy,
4540 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004542 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01004543 },
4544 {
4545 .cmd = NL80211_CMD_DEL_KEY,
4546 .doit = nl80211_del_key,
4547 .policy = nl80211_policy,
4548 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004549 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004550 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01004551 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01004552 {
4553 .cmd = NL80211_CMD_SET_BEACON,
4554 .policy = nl80211_policy,
4555 .flags = GENL_ADMIN_PERM,
4556 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02004557 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4558 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01004559 },
4560 {
4561 .cmd = NL80211_CMD_NEW_BEACON,
4562 .policy = nl80211_policy,
4563 .flags = GENL_ADMIN_PERM,
4564 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02004565 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4566 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01004567 },
4568 {
4569 .cmd = NL80211_CMD_DEL_BEACON,
4570 .policy = nl80211_policy,
4571 .flags = GENL_ADMIN_PERM,
4572 .doit = nl80211_del_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02004573 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4574 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01004575 },
Johannes Berg5727ef12007-12-19 02:03:34 +01004576 {
4577 .cmd = NL80211_CMD_GET_STATION,
4578 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004579 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01004580 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02004581 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4582 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01004583 },
4584 {
4585 .cmd = NL80211_CMD_SET_STATION,
4586 .doit = nl80211_set_station,
4587 .policy = nl80211_policy,
4588 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004589 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4590 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01004591 },
4592 {
4593 .cmd = NL80211_CMD_NEW_STATION,
4594 .doit = nl80211_new_station,
4595 .policy = nl80211_policy,
4596 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004598 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01004599 },
4600 {
4601 .cmd = NL80211_CMD_DEL_STATION,
4602 .doit = nl80211_del_station,
4603 .policy = nl80211_policy,
4604 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004605 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4606 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01004607 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004608 {
4609 .cmd = NL80211_CMD_GET_MPATH,
4610 .doit = nl80211_get_mpath,
4611 .dumpit = nl80211_dump_mpath,
4612 .policy = nl80211_policy,
4613 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004615 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004616 },
4617 {
4618 .cmd = NL80211_CMD_SET_MPATH,
4619 .doit = nl80211_set_mpath,
4620 .policy = nl80211_policy,
4621 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004623 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004624 },
4625 {
4626 .cmd = NL80211_CMD_NEW_MPATH,
4627 .doit = nl80211_new_mpath,
4628 .policy = nl80211_policy,
4629 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004631 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004632 },
4633 {
4634 .cmd = NL80211_CMD_DEL_MPATH,
4635 .doit = nl80211_del_mpath,
4636 .policy = nl80211_policy,
4637 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004638 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4639 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004640 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004641 {
4642 .cmd = NL80211_CMD_SET_BSS,
4643 .doit = nl80211_set_bss,
4644 .policy = nl80211_policy,
4645 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004646 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4647 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004648 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004649 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004650 .cmd = NL80211_CMD_GET_REG,
4651 .doit = nl80211_get_reg,
4652 .policy = nl80211_policy,
4653 /* can be retrieved by unprivileged users */
4654 },
4655 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004656 .cmd = NL80211_CMD_SET_REG,
4657 .doit = nl80211_set_reg,
4658 .policy = nl80211_policy,
4659 .flags = GENL_ADMIN_PERM,
4660 },
4661 {
4662 .cmd = NL80211_CMD_REQ_SET_REG,
4663 .doit = nl80211_req_set_reg,
4664 .policy = nl80211_policy,
4665 .flags = GENL_ADMIN_PERM,
4666 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004667 {
4668 .cmd = NL80211_CMD_GET_MESH_PARAMS,
4669 .doit = nl80211_get_mesh_params,
4670 .policy = nl80211_policy,
4671 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02004672 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4673 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004674 },
4675 {
4676 .cmd = NL80211_CMD_SET_MESH_PARAMS,
4677 .doit = nl80211_set_mesh_params,
4678 .policy = nl80211_policy,
4679 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004680 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4681 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004682 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02004683 {
Johannes Berg2a519312009-02-10 21:25:55 +01004684 .cmd = NL80211_CMD_TRIGGER_SCAN,
4685 .doit = nl80211_trigger_scan,
4686 .policy = nl80211_policy,
4687 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004688 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004689 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01004690 },
4691 {
4692 .cmd = NL80211_CMD_GET_SCAN,
4693 .policy = nl80211_policy,
4694 .dumpit = nl80211_dump_scan,
4695 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02004696 {
4697 .cmd = NL80211_CMD_AUTHENTICATE,
4698 .doit = nl80211_authenticate,
4699 .policy = nl80211_policy,
4700 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004701 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004702 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02004703 },
4704 {
4705 .cmd = NL80211_CMD_ASSOCIATE,
4706 .doit = nl80211_associate,
4707 .policy = nl80211_policy,
4708 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004709 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004710 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02004711 },
4712 {
4713 .cmd = NL80211_CMD_DEAUTHENTICATE,
4714 .doit = nl80211_deauthenticate,
4715 .policy = nl80211_policy,
4716 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004717 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004718 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02004719 },
4720 {
4721 .cmd = NL80211_CMD_DISASSOCIATE,
4722 .doit = nl80211_disassociate,
4723 .policy = nl80211_policy,
4724 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004725 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004726 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02004727 },
Johannes Berg04a773a2009-04-19 21:24:32 +02004728 {
4729 .cmd = NL80211_CMD_JOIN_IBSS,
4730 .doit = nl80211_join_ibss,
4731 .policy = nl80211_policy,
4732 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004733 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004734 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02004735 },
4736 {
4737 .cmd = NL80211_CMD_LEAVE_IBSS,
4738 .doit = nl80211_leave_ibss,
4739 .policy = nl80211_policy,
4740 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004741 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004742 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02004743 },
Johannes Bergaff89a92009-07-01 21:26:51 +02004744#ifdef CONFIG_NL80211_TESTMODE
4745 {
4746 .cmd = NL80211_CMD_TESTMODE,
4747 .doit = nl80211_testmode_do,
4748 .policy = nl80211_policy,
4749 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004750 .internal_flags = NL80211_FLAG_NEED_WIPHY |
4751 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02004752 },
4753#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02004754 {
4755 .cmd = NL80211_CMD_CONNECT,
4756 .doit = nl80211_connect,
4757 .policy = nl80211_policy,
4758 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004759 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004760 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004761 },
4762 {
4763 .cmd = NL80211_CMD_DISCONNECT,
4764 .doit = nl80211_disconnect,
4765 .policy = nl80211_policy,
4766 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004768 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004769 },
Johannes Berg463d0182009-07-14 00:33:35 +02004770 {
4771 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
4772 .doit = nl80211_wiphy_netns,
4773 .policy = nl80211_policy,
4774 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004775 .internal_flags = NL80211_FLAG_NEED_WIPHY |
4776 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02004777 },
Holger Schurig61fa7132009-11-11 12:25:40 +01004778 {
4779 .cmd = NL80211_CMD_GET_SURVEY,
4780 .policy = nl80211_policy,
4781 .dumpit = nl80211_dump_survey,
4782 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004783 {
4784 .cmd = NL80211_CMD_SET_PMKSA,
4785 .doit = nl80211_setdel_pmksa,
4786 .policy = nl80211_policy,
4787 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004788 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4789 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004790 },
4791 {
4792 .cmd = NL80211_CMD_DEL_PMKSA,
4793 .doit = nl80211_setdel_pmksa,
4794 .policy = nl80211_policy,
4795 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004796 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4797 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004798 },
4799 {
4800 .cmd = NL80211_CMD_FLUSH_PMKSA,
4801 .doit = nl80211_flush_pmksa,
4802 .policy = nl80211_policy,
4803 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004804 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4805 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004806 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004807 {
4808 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
4809 .doit = nl80211_remain_on_channel,
4810 .policy = nl80211_policy,
4811 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004813 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004814 },
4815 {
4816 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
4817 .doit = nl80211_cancel_remain_on_channel,
4818 .policy = nl80211_policy,
4819 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004821 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004822 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004823 {
4824 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
4825 .doit = nl80211_set_tx_bitrate_mask,
4826 .policy = nl80211_policy,
4827 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004828 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4829 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004830 },
Jouni Malinen026331c2010-02-15 12:53:10 +02004831 {
Johannes Berg2e161f72010-08-12 15:38:38 +02004832 .cmd = NL80211_CMD_REGISTER_FRAME,
4833 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02004834 .policy = nl80211_policy,
4835 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004836 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4837 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02004838 },
4839 {
Johannes Berg2e161f72010-08-12 15:38:38 +02004840 .cmd = NL80211_CMD_FRAME,
4841 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02004842 .policy = nl80211_policy,
4843 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02004844 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02004845 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02004846 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02004847 {
4848 .cmd = NL80211_CMD_SET_POWER_SAVE,
4849 .doit = nl80211_set_power_save,
4850 .policy = nl80211_policy,
4851 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004852 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4853 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02004854 },
4855 {
4856 .cmd = NL80211_CMD_GET_POWER_SAVE,
4857 .doit = nl80211_get_power_save,
4858 .policy = nl80211_policy,
4859 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02004860 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4861 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02004862 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004863 {
4864 .cmd = NL80211_CMD_SET_CQM,
4865 .doit = nl80211_set_cqm,
4866 .policy = nl80211_policy,
4867 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004868 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4869 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02004870 },
Johannes Bergf444de02010-05-05 15:25:02 +02004871 {
4872 .cmd = NL80211_CMD_SET_CHANNEL,
4873 .doit = nl80211_set_channel,
4874 .policy = nl80211_policy,
4875 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02004876 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4877 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02004878 },
Bill Jordane8347eb2010-10-01 13:54:28 -04004879 {
4880 .cmd = NL80211_CMD_SET_WDS_PEER,
4881 .doit = nl80211_set_wds_peer,
4882 .policy = nl80211_policy,
4883 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02004884 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4885 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04004886 },
Johannes Berg55682962007-09-20 13:09:35 -04004887};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004888
Jouni Malinen6039f6d2009-03-19 13:39:21 +02004889static struct genl_multicast_group nl80211_mlme_mcgrp = {
4890 .name = "mlme",
4891};
Johannes Berg55682962007-09-20 13:09:35 -04004892
4893/* multicast groups */
4894static struct genl_multicast_group nl80211_config_mcgrp = {
4895 .name = "config",
4896};
Johannes Berg2a519312009-02-10 21:25:55 +01004897static struct genl_multicast_group nl80211_scan_mcgrp = {
4898 .name = "scan",
4899};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04004900static struct genl_multicast_group nl80211_regulatory_mcgrp = {
4901 .name = "regulatory",
4902};
Johannes Berg55682962007-09-20 13:09:35 -04004903
4904/* notification functions */
4905
4906void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
4907{
4908 struct sk_buff *msg;
4909
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004910 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04004911 if (!msg)
4912 return;
4913
4914 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
4915 nlmsg_free(msg);
4916 return;
4917 }
4918
Johannes Berg463d0182009-07-14 00:33:35 +02004919 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
4920 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04004921}
4922
Johannes Berg362a4152009-05-24 16:43:15 +02004923static int nl80211_add_scan_req(struct sk_buff *msg,
4924 struct cfg80211_registered_device *rdev)
4925{
4926 struct cfg80211_scan_request *req = rdev->scan_req;
4927 struct nlattr *nest;
4928 int i;
4929
Johannes Berg667503d2009-07-07 03:56:11 +02004930 ASSERT_RDEV_LOCK(rdev);
4931
Johannes Berg362a4152009-05-24 16:43:15 +02004932 if (WARN_ON(!req))
4933 return 0;
4934
4935 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
4936 if (!nest)
4937 goto nla_put_failure;
4938 for (i = 0; i < req->n_ssids; i++)
4939 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
4940 nla_nest_end(msg, nest);
4941
4942 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
4943 if (!nest)
4944 goto nla_put_failure;
4945 for (i = 0; i < req->n_channels; i++)
4946 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
4947 nla_nest_end(msg, nest);
4948
4949 if (req->ie)
4950 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
4951
4952 return 0;
4953 nla_put_failure:
4954 return -ENOBUFS;
4955}
4956
Johannes Berga538e2d2009-06-16 19:56:42 +02004957static int nl80211_send_scan_msg(struct sk_buff *msg,
4958 struct cfg80211_registered_device *rdev,
4959 struct net_device *netdev,
4960 u32 pid, u32 seq, int flags,
4961 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01004962{
4963 void *hdr;
4964
4965 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
4966 if (!hdr)
4967 return -1;
4968
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05004969 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01004970 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
4971
Johannes Berg362a4152009-05-24 16:43:15 +02004972 /* ignore errors and send incomplete event anyway */
4973 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004974
4975 return genlmsg_end(msg, hdr);
4976
4977 nla_put_failure:
4978 genlmsg_cancel(msg, hdr);
4979 return -EMSGSIZE;
4980}
4981
Johannes Berga538e2d2009-06-16 19:56:42 +02004982void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
4983 struct net_device *netdev)
4984{
4985 struct sk_buff *msg;
4986
4987 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
4988 if (!msg)
4989 return;
4990
4991 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
4992 NL80211_CMD_TRIGGER_SCAN) < 0) {
4993 nlmsg_free(msg);
4994 return;
4995 }
4996
Johannes Berg463d0182009-07-14 00:33:35 +02004997 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
4998 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02004999}
5000
Johannes Berg2a519312009-02-10 21:25:55 +01005001void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
5002 struct net_device *netdev)
5003{
5004 struct sk_buff *msg;
5005
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005006 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01005007 if (!msg)
5008 return;
5009
Johannes Berga538e2d2009-06-16 19:56:42 +02005010 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
5011 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005012 nlmsg_free(msg);
5013 return;
5014 }
5015
Johannes Berg463d0182009-07-14 00:33:35 +02005016 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5017 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01005018}
5019
5020void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
5021 struct net_device *netdev)
5022{
5023 struct sk_buff *msg;
5024
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01005026 if (!msg)
5027 return;
5028
Johannes Berga538e2d2009-06-16 19:56:42 +02005029 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
5030 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005031 nlmsg_free(msg);
5032 return;
5033 }
5034
Johannes Berg463d0182009-07-14 00:33:35 +02005035 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5036 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01005037}
5038
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04005039/*
5040 * This can happen on global regulatory changes or device specific settings
5041 * based on custom world regulatory domains.
5042 */
5043void nl80211_send_reg_change_event(struct regulatory_request *request)
5044{
5045 struct sk_buff *msg;
5046 void *hdr;
5047
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005048 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04005049 if (!msg)
5050 return;
5051
5052 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
5053 if (!hdr) {
5054 nlmsg_free(msg);
5055 return;
5056 }
5057
5058 /* Userspace can always count this one always being set */
5059 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
5060
5061 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
5062 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
5063 NL80211_REGDOM_TYPE_WORLD);
5064 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
5065 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
5066 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
5067 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
5068 request->intersect)
5069 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
5070 NL80211_REGDOM_TYPE_INTERSECTION);
5071 else {
5072 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
5073 NL80211_REGDOM_TYPE_COUNTRY);
5074 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
5075 }
5076
5077 if (wiphy_idx_valid(request->wiphy_idx))
5078 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
5079
5080 if (genlmsg_end(msg, hdr) < 0) {
5081 nlmsg_free(msg);
5082 return;
5083 }
5084
Johannes Bergbc43b282009-07-25 10:54:13 +02005085 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02005086 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02005087 GFP_ATOMIC);
5088 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04005089
5090 return;
5091
5092nla_put_failure:
5093 genlmsg_cancel(msg, hdr);
5094 nlmsg_free(msg);
5095}
5096
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005097static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
5098 struct net_device *netdev,
5099 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02005100 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005101{
5102 struct sk_buff *msg;
5103 void *hdr;
5104
Johannes Berge6d6e342009-07-01 21:26:47 +02005105 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005106 if (!msg)
5107 return;
5108
5109 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
5110 if (!hdr) {
5111 nlmsg_free(msg);
5112 return;
5113 }
5114
5115 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5116 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5117 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
5118
5119 if (genlmsg_end(msg, hdr) < 0) {
5120 nlmsg_free(msg);
5121 return;
5122 }
5123
Johannes Berg463d0182009-07-14 00:33:35 +02005124 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5125 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005126 return;
5127
5128 nla_put_failure:
5129 genlmsg_cancel(msg, hdr);
5130 nlmsg_free(msg);
5131}
5132
5133void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02005134 struct net_device *netdev, const u8 *buf,
5135 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005136{
5137 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02005138 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005139}
5140
5141void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
5142 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02005143 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005144{
Johannes Berge6d6e342009-07-01 21:26:47 +02005145 nl80211_send_mlme_event(rdev, netdev, buf, len,
5146 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005147}
5148
Jouni Malinen53b46b82009-03-27 20:53:56 +02005149void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02005150 struct net_device *netdev, const u8 *buf,
5151 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005152{
5153 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02005154 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005155}
5156
Jouni Malinen53b46b82009-03-27 20:53:56 +02005157void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
5158 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02005159 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005160{
5161 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02005162 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005163}
5164
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04005165static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
5166 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02005167 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03005168{
5169 struct sk_buff *msg;
5170 void *hdr;
5171
Johannes Berge6d6e342009-07-01 21:26:47 +02005172 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03005173 if (!msg)
5174 return;
5175
5176 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
5177 if (!hdr) {
5178 nlmsg_free(msg);
5179 return;
5180 }
5181
5182 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5183 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5184 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
5185 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
5186
5187 if (genlmsg_end(msg, hdr) < 0) {
5188 nlmsg_free(msg);
5189 return;
5190 }
5191
Johannes Berg463d0182009-07-14 00:33:35 +02005192 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5193 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03005194 return;
5195
5196 nla_put_failure:
5197 genlmsg_cancel(msg, hdr);
5198 nlmsg_free(msg);
5199}
5200
5201void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02005202 struct net_device *netdev, const u8 *addr,
5203 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03005204{
5205 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02005206 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03005207}
5208
5209void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02005210 struct net_device *netdev, const u8 *addr,
5211 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03005212{
Johannes Berge6d6e342009-07-01 21:26:47 +02005213 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
5214 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03005215}
5216
Samuel Ortizb23aa672009-07-01 21:26:54 +02005217void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
5218 struct net_device *netdev, const u8 *bssid,
5219 const u8 *req_ie, size_t req_ie_len,
5220 const u8 *resp_ie, size_t resp_ie_len,
5221 u16 status, gfp_t gfp)
5222{
5223 struct sk_buff *msg;
5224 void *hdr;
5225
5226 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
5227 if (!msg)
5228 return;
5229
5230 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
5231 if (!hdr) {
5232 nlmsg_free(msg);
5233 return;
5234 }
5235
5236 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5237 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5238 if (bssid)
5239 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
5240 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
5241 if (req_ie)
5242 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
5243 if (resp_ie)
5244 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
5245
5246 if (genlmsg_end(msg, hdr) < 0) {
5247 nlmsg_free(msg);
5248 return;
5249 }
5250
Johannes Berg463d0182009-07-14 00:33:35 +02005251 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5252 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005253 return;
5254
5255 nla_put_failure:
5256 genlmsg_cancel(msg, hdr);
5257 nlmsg_free(msg);
5258
5259}
5260
5261void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
5262 struct net_device *netdev, const u8 *bssid,
5263 const u8 *req_ie, size_t req_ie_len,
5264 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
5265{
5266 struct sk_buff *msg;
5267 void *hdr;
5268
5269 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
5270 if (!msg)
5271 return;
5272
5273 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
5274 if (!hdr) {
5275 nlmsg_free(msg);
5276 return;
5277 }
5278
5279 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5280 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5281 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
5282 if (req_ie)
5283 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
5284 if (resp_ie)
5285 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
5286
5287 if (genlmsg_end(msg, hdr) < 0) {
5288 nlmsg_free(msg);
5289 return;
5290 }
5291
Johannes Berg463d0182009-07-14 00:33:35 +02005292 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5293 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005294 return;
5295
5296 nla_put_failure:
5297 genlmsg_cancel(msg, hdr);
5298 nlmsg_free(msg);
5299
5300}
5301
5302void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
5303 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02005304 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005305{
5306 struct sk_buff *msg;
5307 void *hdr;
5308
Johannes Berg667503d2009-07-07 03:56:11 +02005309 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005310 if (!msg)
5311 return;
5312
5313 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
5314 if (!hdr) {
5315 nlmsg_free(msg);
5316 return;
5317 }
5318
5319 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5320 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5321 if (from_ap && reason)
5322 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
5323 if (from_ap)
5324 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
5325 if (ie)
5326 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
5327
5328 if (genlmsg_end(msg, hdr) < 0) {
5329 nlmsg_free(msg);
5330 return;
5331 }
5332
Johannes Berg463d0182009-07-14 00:33:35 +02005333 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5334 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005335 return;
5336
5337 nla_put_failure:
5338 genlmsg_cancel(msg, hdr);
5339 nlmsg_free(msg);
5340
5341}
5342
Johannes Berg04a773a2009-04-19 21:24:32 +02005343void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
5344 struct net_device *netdev, const u8 *bssid,
5345 gfp_t gfp)
5346{
5347 struct sk_buff *msg;
5348 void *hdr;
5349
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005350 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02005351 if (!msg)
5352 return;
5353
5354 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
5355 if (!hdr) {
5356 nlmsg_free(msg);
5357 return;
5358 }
5359
5360 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5361 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5362 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
5363
5364 if (genlmsg_end(msg, hdr) < 0) {
5365 nlmsg_free(msg);
5366 return;
5367 }
5368
Johannes Berg463d0182009-07-14 00:33:35 +02005369 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5370 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02005371 return;
5372
5373 nla_put_failure:
5374 genlmsg_cancel(msg, hdr);
5375 nlmsg_free(msg);
5376}
5377
Jouni Malinena3b8b052009-03-27 21:59:49 +02005378void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
5379 struct net_device *netdev, const u8 *addr,
5380 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02005381 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02005382{
5383 struct sk_buff *msg;
5384 void *hdr;
5385
Johannes Berge6d6e342009-07-01 21:26:47 +02005386 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02005387 if (!msg)
5388 return;
5389
5390 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
5391 if (!hdr) {
5392 nlmsg_free(msg);
5393 return;
5394 }
5395
5396 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5397 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5398 if (addr)
5399 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
5400 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
5401 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
5402 if (tsc)
5403 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
5404
5405 if (genlmsg_end(msg, hdr) < 0) {
5406 nlmsg_free(msg);
5407 return;
5408 }
5409
Johannes Berg463d0182009-07-14 00:33:35 +02005410 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5411 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02005412 return;
5413
5414 nla_put_failure:
5415 genlmsg_cancel(msg, hdr);
5416 nlmsg_free(msg);
5417}
5418
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04005419void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
5420 struct ieee80211_channel *channel_before,
5421 struct ieee80211_channel *channel_after)
5422{
5423 struct sk_buff *msg;
5424 void *hdr;
5425 struct nlattr *nl_freq;
5426
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04005428 if (!msg)
5429 return;
5430
5431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
5432 if (!hdr) {
5433 nlmsg_free(msg);
5434 return;
5435 }
5436
5437 /*
5438 * Since we are applying the beacon hint to a wiphy we know its
5439 * wiphy_idx is valid
5440 */
5441 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
5442
5443 /* Before */
5444 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
5445 if (!nl_freq)
5446 goto nla_put_failure;
5447 if (nl80211_msg_put_channel(msg, channel_before))
5448 goto nla_put_failure;
5449 nla_nest_end(msg, nl_freq);
5450
5451 /* After */
5452 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
5453 if (!nl_freq)
5454 goto nla_put_failure;
5455 if (nl80211_msg_put_channel(msg, channel_after))
5456 goto nla_put_failure;
5457 nla_nest_end(msg, nl_freq);
5458
5459 if (genlmsg_end(msg, hdr) < 0) {
5460 nlmsg_free(msg);
5461 return;
5462 }
5463
Johannes Berg463d0182009-07-14 00:33:35 +02005464 rcu_read_lock();
5465 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
5466 GFP_ATOMIC);
5467 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04005468
5469 return;
5470
5471nla_put_failure:
5472 genlmsg_cancel(msg, hdr);
5473 nlmsg_free(msg);
5474}
5475
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005476static void nl80211_send_remain_on_chan_event(
5477 int cmd, struct cfg80211_registered_device *rdev,
5478 struct net_device *netdev, u64 cookie,
5479 struct ieee80211_channel *chan,
5480 enum nl80211_channel_type channel_type,
5481 unsigned int duration, gfp_t gfp)
5482{
5483 struct sk_buff *msg;
5484 void *hdr;
5485
5486 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5487 if (!msg)
5488 return;
5489
5490 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
5491 if (!hdr) {
5492 nlmsg_free(msg);
5493 return;
5494 }
5495
5496 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5497 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5498 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
5499 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
5500 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5501
5502 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
5503 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
5504
5505 if (genlmsg_end(msg, hdr) < 0) {
5506 nlmsg_free(msg);
5507 return;
5508 }
5509
5510 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5511 nl80211_mlme_mcgrp.id, gfp);
5512 return;
5513
5514 nla_put_failure:
5515 genlmsg_cancel(msg, hdr);
5516 nlmsg_free(msg);
5517}
5518
5519void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
5520 struct net_device *netdev, u64 cookie,
5521 struct ieee80211_channel *chan,
5522 enum nl80211_channel_type channel_type,
5523 unsigned int duration, gfp_t gfp)
5524{
5525 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
5526 rdev, netdev, cookie, chan,
5527 channel_type, duration, gfp);
5528}
5529
5530void nl80211_send_remain_on_channel_cancel(
5531 struct cfg80211_registered_device *rdev, struct net_device *netdev,
5532 u64 cookie, struct ieee80211_channel *chan,
5533 enum nl80211_channel_type channel_type, gfp_t gfp)
5534{
5535 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5536 rdev, netdev, cookie, chan,
5537 channel_type, 0, gfp);
5538}
5539
Johannes Berg98b62182009-12-23 13:15:44 +01005540void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
5541 struct net_device *dev, const u8 *mac_addr,
5542 struct station_info *sinfo, gfp_t gfp)
5543{
5544 struct sk_buff *msg;
5545
5546 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
5547 if (!msg)
5548 return;
5549
5550 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
5551 nlmsg_free(msg);
5552 return;
5553 }
5554
5555 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5556 nl80211_mlme_mcgrp.id, gfp);
5557}
5558
Johannes Berg2e161f72010-08-12 15:38:38 +02005559int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
5560 struct net_device *netdev, u32 nlpid,
5561 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02005562{
5563 struct sk_buff *msg;
5564 void *hdr;
5565 int err;
5566
5567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5568 if (!msg)
5569 return -ENOMEM;
5570
Johannes Berg2e161f72010-08-12 15:38:38 +02005571 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005572 if (!hdr) {
5573 nlmsg_free(msg);
5574 return -ENOMEM;
5575 }
5576
5577 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5578 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5579 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
5580 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
5581
5582 err = genlmsg_end(msg, hdr);
5583 if (err < 0) {
5584 nlmsg_free(msg);
5585 return err;
5586 }
5587
5588 err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
5589 if (err < 0)
5590 return err;
5591 return 0;
5592
5593 nla_put_failure:
5594 genlmsg_cancel(msg, hdr);
5595 nlmsg_free(msg);
5596 return -ENOBUFS;
5597}
5598
Johannes Berg2e161f72010-08-12 15:38:38 +02005599void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
5600 struct net_device *netdev, u64 cookie,
5601 const u8 *buf, size_t len, bool ack,
5602 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02005603{
5604 struct sk_buff *msg;
5605 void *hdr;
5606
5607 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5608 if (!msg)
5609 return;
5610
Johannes Berg2e161f72010-08-12 15:38:38 +02005611 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02005612 if (!hdr) {
5613 nlmsg_free(msg);
5614 return;
5615 }
5616
5617 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5618 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5619 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
5620 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5621 if (ack)
5622 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
5623
5624 if (genlmsg_end(msg, hdr) < 0) {
5625 nlmsg_free(msg);
5626 return;
5627 }
5628
5629 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
5630 return;
5631
5632 nla_put_failure:
5633 genlmsg_cancel(msg, hdr);
5634 nlmsg_free(msg);
5635}
5636
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005637void
5638nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
5639 struct net_device *netdev,
5640 enum nl80211_cqm_rssi_threshold_event rssi_event,
5641 gfp_t gfp)
5642{
5643 struct sk_buff *msg;
5644 struct nlattr *pinfoattr;
5645 void *hdr;
5646
5647 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
5648 if (!msg)
5649 return;
5650
5651 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
5652 if (!hdr) {
5653 nlmsg_free(msg);
5654 return;
5655 }
5656
5657 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5658 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5659
5660 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
5661 if (!pinfoattr)
5662 goto nla_put_failure;
5663
5664 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
5665 rssi_event);
5666
5667 nla_nest_end(msg, pinfoattr);
5668
5669 if (genlmsg_end(msg, hdr) < 0) {
5670 nlmsg_free(msg);
5671 return;
5672 }
5673
5674 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5675 nl80211_mlme_mcgrp.id, gfp);
5676 return;
5677
5678 nla_put_failure:
5679 genlmsg_cancel(msg, hdr);
5680 nlmsg_free(msg);
5681}
5682
Jouni Malinen026331c2010-02-15 12:53:10 +02005683static int nl80211_netlink_notify(struct notifier_block * nb,
5684 unsigned long state,
5685 void *_notify)
5686{
5687 struct netlink_notify *notify = _notify;
5688 struct cfg80211_registered_device *rdev;
5689 struct wireless_dev *wdev;
5690
5691 if (state != NETLINK_URELEASE)
5692 return NOTIFY_DONE;
5693
5694 rcu_read_lock();
5695
5696 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
5697 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02005698 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Jouni Malinen026331c2010-02-15 12:53:10 +02005699
5700 rcu_read_unlock();
5701
5702 return NOTIFY_DONE;
5703}
5704
5705static struct notifier_block nl80211_netlink_notifier = {
5706 .notifier_call = nl80211_netlink_notify,
5707};
5708
Johannes Berg55682962007-09-20 13:09:35 -04005709/* initialisation/exit functions */
5710
5711int nl80211_init(void)
5712{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00005713 int err;
Johannes Berg55682962007-09-20 13:09:35 -04005714
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00005715 err = genl_register_family_with_ops(&nl80211_fam,
5716 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04005717 if (err)
5718 return err;
5719
Johannes Berg55682962007-09-20 13:09:35 -04005720 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
5721 if (err)
5722 goto err_out;
5723
Johannes Berg2a519312009-02-10 21:25:55 +01005724 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
5725 if (err)
5726 goto err_out;
5727
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04005728 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
5729 if (err)
5730 goto err_out;
5731
Jouni Malinen6039f6d2009-03-19 13:39:21 +02005732 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
5733 if (err)
5734 goto err_out;
5735
Johannes Bergaff89a92009-07-01 21:26:51 +02005736#ifdef CONFIG_NL80211_TESTMODE
5737 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
5738 if (err)
5739 goto err_out;
5740#endif
5741
Jouni Malinen026331c2010-02-15 12:53:10 +02005742 err = netlink_register_notifier(&nl80211_netlink_notifier);
5743 if (err)
5744 goto err_out;
5745
Johannes Berg55682962007-09-20 13:09:35 -04005746 return 0;
5747 err_out:
5748 genl_unregister_family(&nl80211_fam);
5749 return err;
5750}
5751
5752void nl80211_exit(void)
5753{
Jouni Malinen026331c2010-02-15 12:53:10 +02005754 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04005755 genl_unregister_family(&nl80211_fam);
5756}