mflash: initial support
[linux-2.6/verdex.git] / net / wireless / nl80211.c
blob353e1a4ece836423dd503e55becc7cbffd4a2812
1 /*
2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
5 */
7 #include <linux/if.h>
8 #include <linux/module.h>
9 #include <linux/err.h>
10 #include <linux/list.h>
11 #include <linux/if_ether.h>
12 #include <linux/ieee80211.h>
13 #include <linux/nl80211.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/netlink.h>
16 #include <linux/etherdevice.h>
17 #include <net/genetlink.h>
18 #include <net/cfg80211.h>
19 #include "core.h"
20 #include "nl80211.h"
21 #include "reg.h"
23 /* the netlink family */
24 static struct genl_family nl80211_fam = {
25 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
26 .name = "nl80211", /* have users key off the name instead */
27 .hdrsize = 0, /* no private header */
28 .version = 1, /* no particular meaning now */
29 .maxattr = NL80211_ATTR_MAX,
32 /* internal helper: get drv and dev */
33 static int get_drv_dev_by_info_ifindex(struct nlattr **attrs,
34 struct cfg80211_registered_device **drv,
35 struct net_device **dev)
37 int ifindex;
39 if (!attrs[NL80211_ATTR_IFINDEX])
40 return -EINVAL;
42 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
43 *dev = dev_get_by_index(&init_net, ifindex);
44 if (!*dev)
45 return -ENODEV;
47 *drv = cfg80211_get_dev_from_ifindex(ifindex);
48 if (IS_ERR(*drv)) {
49 dev_put(*dev);
50 return PTR_ERR(*drv);
53 return 0;
56 /* policy for the attributes */
57 static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
58 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
59 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
60 .len = BUS_ID_SIZE-1 },
61 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
62 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
63 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
65 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
66 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
67 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
69 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
71 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
72 .len = WLAN_MAX_KEY_LEN },
73 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
74 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
75 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
77 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
78 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
79 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
80 .len = IEEE80211_MAX_DATA_LEN },
81 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
82 .len = IEEE80211_MAX_DATA_LEN },
83 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
84 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
85 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
86 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
87 .len = NL80211_MAX_SUPP_RATES },
88 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
89 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
90 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
91 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
92 .len = IEEE80211_MAX_MESH_ID_LEN },
93 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
95 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
96 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
98 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
99 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
100 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
101 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
102 .len = NL80211_MAX_SUPP_RATES },
104 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED },
106 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
107 .len = NL80211_HT_CAPABILITY_LEN },
109 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
110 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
111 .len = IEEE80211_MAX_DATA_LEN },
112 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
113 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
115 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
116 .len = IEEE80211_MAX_SSID_LEN },
117 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
118 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
121 /* message building helper */
122 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
123 int flags, u8 cmd)
125 /* since there is no private header just add the generic one */
126 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
129 /* netlink command implementations */
131 static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
132 struct cfg80211_registered_device *dev)
134 void *hdr;
135 struct nlattr *nl_bands, *nl_band;
136 struct nlattr *nl_freqs, *nl_freq;
137 struct nlattr *nl_rates, *nl_rate;
138 struct nlattr *nl_modes;
139 struct nlattr *nl_cmds;
140 enum ieee80211_band band;
141 struct ieee80211_channel *chan;
142 struct ieee80211_rate *rate;
143 int i;
144 u16 ifmodes = dev->wiphy.interface_modes;
146 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
147 if (!hdr)
148 return -1;
150 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
151 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
152 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
153 dev->wiphy.max_scan_ssids);
155 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
156 if (!nl_modes)
157 goto nla_put_failure;
159 i = 0;
160 while (ifmodes) {
161 if (ifmodes & 1)
162 NLA_PUT_FLAG(msg, i);
163 ifmodes >>= 1;
164 i++;
167 nla_nest_end(msg, nl_modes);
169 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
170 if (!nl_bands)
171 goto nla_put_failure;
173 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
174 if (!dev->wiphy.bands[band])
175 continue;
177 nl_band = nla_nest_start(msg, band);
178 if (!nl_band)
179 goto nla_put_failure;
181 /* add HT info */
182 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
183 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
184 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
185 &dev->wiphy.bands[band]->ht_cap.mcs);
186 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
187 dev->wiphy.bands[band]->ht_cap.cap);
188 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
189 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
190 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
191 dev->wiphy.bands[band]->ht_cap.ampdu_density);
194 /* add frequencies */
195 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
196 if (!nl_freqs)
197 goto nla_put_failure;
199 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
200 nl_freq = nla_nest_start(msg, i);
201 if (!nl_freq)
202 goto nla_put_failure;
204 chan = &dev->wiphy.bands[band]->channels[i];
205 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
206 chan->center_freq);
208 if (chan->flags & IEEE80211_CHAN_DISABLED)
209 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
210 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
211 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
212 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
213 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
214 if (chan->flags & IEEE80211_CHAN_RADAR)
215 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
217 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
218 DBM_TO_MBM(chan->max_power));
220 nla_nest_end(msg, nl_freq);
223 nla_nest_end(msg, nl_freqs);
225 /* add bitrates */
226 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
227 if (!nl_rates)
228 goto nla_put_failure;
230 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
231 nl_rate = nla_nest_start(msg, i);
232 if (!nl_rate)
233 goto nla_put_failure;
235 rate = &dev->wiphy.bands[band]->bitrates[i];
236 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
237 rate->bitrate);
238 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
239 NLA_PUT_FLAG(msg,
240 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
242 nla_nest_end(msg, nl_rate);
245 nla_nest_end(msg, nl_rates);
247 nla_nest_end(msg, nl_band);
249 nla_nest_end(msg, nl_bands);
251 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
252 if (!nl_cmds)
253 goto nla_put_failure;
255 i = 0;
256 #define CMD(op, n) \
257 do { \
258 if (dev->ops->op) { \
259 i++; \
260 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
262 } while (0)
264 CMD(add_virtual_intf, NEW_INTERFACE);
265 CMD(change_virtual_intf, SET_INTERFACE);
266 CMD(add_key, NEW_KEY);
267 CMD(add_beacon, NEW_BEACON);
268 CMD(add_station, NEW_STATION);
269 CMD(add_mpath, NEW_MPATH);
270 CMD(set_mesh_params, SET_MESH_PARAMS);
271 CMD(change_bss, SET_BSS);
272 CMD(auth, AUTHENTICATE);
273 CMD(assoc, ASSOCIATE);
274 CMD(deauth, DEAUTHENTICATE);
275 CMD(disassoc, DISASSOCIATE);
277 #undef CMD
278 nla_nest_end(msg, nl_cmds);
280 return genlmsg_end(msg, hdr);
282 nla_put_failure:
283 genlmsg_cancel(msg, hdr);
284 return -EMSGSIZE;
287 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
289 int idx = 0;
290 int start = cb->args[0];
291 struct cfg80211_registered_device *dev;
293 mutex_lock(&cfg80211_mutex);
294 list_for_each_entry(dev, &cfg80211_drv_list, list) {
295 if (++idx <= start)
296 continue;
297 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
298 cb->nlh->nlmsg_seq, NLM_F_MULTI,
299 dev) < 0) {
300 idx--;
301 break;
304 mutex_unlock(&cfg80211_mutex);
306 cb->args[0] = idx;
308 return skb->len;
311 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
313 struct sk_buff *msg;
314 struct cfg80211_registered_device *dev;
316 dev = cfg80211_get_dev_from_info(info);
317 if (IS_ERR(dev))
318 return PTR_ERR(dev);
320 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
321 if (!msg)
322 goto out_err;
324 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
325 goto out_free;
327 cfg80211_put_dev(dev);
329 return genlmsg_unicast(msg, info->snd_pid);
331 out_free:
332 nlmsg_free(msg);
333 out_err:
334 cfg80211_put_dev(dev);
335 return -ENOBUFS;
338 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
339 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
340 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
341 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
342 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
343 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
346 static int parse_txq_params(struct nlattr *tb[],
347 struct ieee80211_txq_params *txq_params)
349 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
350 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
351 !tb[NL80211_TXQ_ATTR_AIFS])
352 return -EINVAL;
354 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
355 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
356 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
357 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
358 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
360 return 0;
363 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
365 struct cfg80211_registered_device *rdev;
366 int result = 0, rem_txq_params = 0;
367 struct nlattr *nl_txq_params;
369 rtnl_lock();
371 mutex_lock(&cfg80211_mutex);
373 rdev = __cfg80211_drv_from_info(info);
374 if (IS_ERR(rdev)) {
375 result = PTR_ERR(rdev);
376 goto unlock;
379 mutex_lock(&rdev->mtx);
381 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
382 result = cfg80211_dev_rename(
383 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
385 mutex_unlock(&cfg80211_mutex);
387 if (result)
388 goto bad_res;
390 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
391 struct ieee80211_txq_params txq_params;
392 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
394 if (!rdev->ops->set_txq_params) {
395 result = -EOPNOTSUPP;
396 goto bad_res;
399 nla_for_each_nested(nl_txq_params,
400 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
401 rem_txq_params) {
402 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
403 nla_data(nl_txq_params),
404 nla_len(nl_txq_params),
405 txq_params_policy);
406 result = parse_txq_params(tb, &txq_params);
407 if (result)
408 goto bad_res;
410 result = rdev->ops->set_txq_params(&rdev->wiphy,
411 &txq_params);
412 if (result)
413 goto bad_res;
417 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
418 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
419 struct ieee80211_channel *chan;
420 struct ieee80211_sta_ht_cap *ht_cap;
421 u32 freq, sec_freq;
423 if (!rdev->ops->set_channel) {
424 result = -EOPNOTSUPP;
425 goto bad_res;
428 result = -EINVAL;
430 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
431 channel_type = nla_get_u32(info->attrs[
432 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
433 if (channel_type != NL80211_CHAN_NO_HT &&
434 channel_type != NL80211_CHAN_HT20 &&
435 channel_type != NL80211_CHAN_HT40PLUS &&
436 channel_type != NL80211_CHAN_HT40MINUS)
437 goto bad_res;
440 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
441 chan = ieee80211_get_channel(&rdev->wiphy, freq);
443 /* Primary channel not allowed */
444 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
445 goto bad_res;
447 if (channel_type == NL80211_CHAN_HT40MINUS)
448 sec_freq = freq - 20;
449 else if (channel_type == NL80211_CHAN_HT40PLUS)
450 sec_freq = freq + 20;
451 else
452 sec_freq = 0;
454 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
456 /* no HT capabilities */
457 if (channel_type != NL80211_CHAN_NO_HT &&
458 !ht_cap->ht_supported)
459 goto bad_res;
461 if (sec_freq) {
462 struct ieee80211_channel *schan;
464 /* no 40 MHz capabilities */
465 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
466 (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
467 goto bad_res;
469 schan = ieee80211_get_channel(&rdev->wiphy, sec_freq);
471 /* Secondary channel not allowed */
472 if (!schan || schan->flags & IEEE80211_CHAN_DISABLED)
473 goto bad_res;
476 result = rdev->ops->set_channel(&rdev->wiphy, chan,
477 channel_type);
478 if (result)
479 goto bad_res;
483 bad_res:
484 mutex_unlock(&rdev->mtx);
485 unlock:
486 rtnl_unlock();
487 return result;
491 static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
492 struct net_device *dev)
494 void *hdr;
496 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
497 if (!hdr)
498 return -1;
500 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
501 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
502 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
503 return genlmsg_end(msg, hdr);
505 nla_put_failure:
506 genlmsg_cancel(msg, hdr);
507 return -EMSGSIZE;
510 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
512 int wp_idx = 0;
513 int if_idx = 0;
514 int wp_start = cb->args[0];
515 int if_start = cb->args[1];
516 struct cfg80211_registered_device *dev;
517 struct wireless_dev *wdev;
519 mutex_lock(&cfg80211_mutex);
520 list_for_each_entry(dev, &cfg80211_drv_list, list) {
521 if (wp_idx < wp_start) {
522 wp_idx++;
523 continue;
525 if_idx = 0;
527 mutex_lock(&dev->devlist_mtx);
528 list_for_each_entry(wdev, &dev->netdev_list, list) {
529 if (if_idx < if_start) {
530 if_idx++;
531 continue;
533 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
534 cb->nlh->nlmsg_seq, NLM_F_MULTI,
535 wdev->netdev) < 0) {
536 mutex_unlock(&dev->devlist_mtx);
537 goto out;
539 if_idx++;
541 mutex_unlock(&dev->devlist_mtx);
543 wp_idx++;
545 out:
546 mutex_unlock(&cfg80211_mutex);
548 cb->args[0] = wp_idx;
549 cb->args[1] = if_idx;
551 return skb->len;
554 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
556 struct sk_buff *msg;
557 struct cfg80211_registered_device *dev;
558 struct net_device *netdev;
559 int err;
561 err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev);
562 if (err)
563 return err;
565 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
566 if (!msg)
567 goto out_err;
569 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0)
570 goto out_free;
572 dev_put(netdev);
573 cfg80211_put_dev(dev);
575 return genlmsg_unicast(msg, info->snd_pid);
577 out_free:
578 nlmsg_free(msg);
579 out_err:
580 dev_put(netdev);
581 cfg80211_put_dev(dev);
582 return -ENOBUFS;
585 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
586 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
587 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
588 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
589 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
590 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
593 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
595 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
596 int flag;
598 *mntrflags = 0;
600 if (!nla)
601 return -EINVAL;
603 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
604 nla, mntr_flags_policy))
605 return -EINVAL;
607 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
608 if (flags[flag])
609 *mntrflags |= (1<<flag);
611 return 0;
614 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
616 struct cfg80211_registered_device *drv;
617 struct vif_params params;
618 int err, ifindex;
619 enum nl80211_iftype type;
620 struct net_device *dev;
621 u32 _flags, *flags = NULL;
622 bool change = false;
624 memset(&params, 0, sizeof(params));
626 rtnl_lock();
628 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
629 if (err)
630 goto unlock_rtnl;
632 ifindex = dev->ifindex;
633 type = dev->ieee80211_ptr->iftype;
634 dev_put(dev);
636 if (info->attrs[NL80211_ATTR_IFTYPE]) {
637 enum nl80211_iftype ntype;
639 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
640 if (type != ntype)
641 change = true;
642 type = ntype;
643 if (type > NL80211_IFTYPE_MAX) {
644 err = -EINVAL;
645 goto unlock;
649 if (!drv->ops->change_virtual_intf ||
650 !(drv->wiphy.interface_modes & (1 << type))) {
651 err = -EOPNOTSUPP;
652 goto unlock;
655 if (info->attrs[NL80211_ATTR_MESH_ID]) {
656 if (type != NL80211_IFTYPE_MESH_POINT) {
657 err = -EINVAL;
658 goto unlock;
660 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
661 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
662 change = true;
665 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
666 if (type != NL80211_IFTYPE_MONITOR) {
667 err = -EINVAL;
668 goto unlock;
670 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
671 &_flags);
672 if (err)
673 goto unlock;
675 flags = &_flags;
676 change = true;
679 if (change)
680 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex,
681 type, flags, &params);
682 else
683 err = 0;
685 dev = __dev_get_by_index(&init_net, ifindex);
686 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type));
688 unlock:
689 cfg80211_put_dev(drv);
690 unlock_rtnl:
691 rtnl_unlock();
692 return err;
695 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
697 struct cfg80211_registered_device *drv;
698 struct vif_params params;
699 int err;
700 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
701 u32 flags;
703 memset(&params, 0, sizeof(params));
705 if (!info->attrs[NL80211_ATTR_IFNAME])
706 return -EINVAL;
708 if (info->attrs[NL80211_ATTR_IFTYPE]) {
709 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
710 if (type > NL80211_IFTYPE_MAX)
711 return -EINVAL;
714 rtnl_lock();
716 drv = cfg80211_get_dev_from_info(info);
717 if (IS_ERR(drv)) {
718 err = PTR_ERR(drv);
719 goto unlock_rtnl;
722 if (!drv->ops->add_virtual_intf ||
723 !(drv->wiphy.interface_modes & (1 << type))) {
724 err = -EOPNOTSUPP;
725 goto unlock;
728 if (type == NL80211_IFTYPE_MESH_POINT &&
729 info->attrs[NL80211_ATTR_MESH_ID]) {
730 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
731 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
734 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
735 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
736 &flags);
737 err = drv->ops->add_virtual_intf(&drv->wiphy,
738 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
739 type, err ? NULL : &flags, &params);
741 unlock:
742 cfg80211_put_dev(drv);
743 unlock_rtnl:
744 rtnl_unlock();
745 return err;
748 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
750 struct cfg80211_registered_device *drv;
751 int ifindex, err;
752 struct net_device *dev;
754 rtnl_lock();
756 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
757 if (err)
758 goto unlock_rtnl;
759 ifindex = dev->ifindex;
760 dev_put(dev);
762 if (!drv->ops->del_virtual_intf) {
763 err = -EOPNOTSUPP;
764 goto out;
767 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
769 out:
770 cfg80211_put_dev(drv);
771 unlock_rtnl:
772 rtnl_unlock();
773 return err;
776 struct get_key_cookie {
777 struct sk_buff *msg;
778 int error;
781 static void get_key_callback(void *c, struct key_params *params)
783 struct get_key_cookie *cookie = c;
785 if (params->key)
786 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
787 params->key_len, params->key);
789 if (params->seq)
790 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
791 params->seq_len, params->seq);
793 if (params->cipher)
794 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
795 params->cipher);
797 return;
798 nla_put_failure:
799 cookie->error = 1;
802 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
804 struct cfg80211_registered_device *drv;
805 int err;
806 struct net_device *dev;
807 u8 key_idx = 0;
808 u8 *mac_addr = NULL;
809 struct get_key_cookie cookie = {
810 .error = 0,
812 void *hdr;
813 struct sk_buff *msg;
815 if (info->attrs[NL80211_ATTR_KEY_IDX])
816 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
818 if (key_idx > 5)
819 return -EINVAL;
821 if (info->attrs[NL80211_ATTR_MAC])
822 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
824 rtnl_lock();
826 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
827 if (err)
828 goto unlock_rtnl;
830 if (!drv->ops->get_key) {
831 err = -EOPNOTSUPP;
832 goto out;
835 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
836 if (!msg) {
837 err = -ENOMEM;
838 goto out;
841 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
842 NL80211_CMD_NEW_KEY);
844 if (IS_ERR(hdr)) {
845 err = PTR_ERR(hdr);
846 goto out;
849 cookie.msg = msg;
851 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
852 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
853 if (mac_addr)
854 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
856 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr,
857 &cookie, get_key_callback);
859 if (err)
860 goto out;
862 if (cookie.error)
863 goto nla_put_failure;
865 genlmsg_end(msg, hdr);
866 err = genlmsg_unicast(msg, info->snd_pid);
867 goto out;
869 nla_put_failure:
870 err = -ENOBUFS;
871 nlmsg_free(msg);
872 out:
873 cfg80211_put_dev(drv);
874 dev_put(dev);
875 unlock_rtnl:
876 rtnl_unlock();
878 return err;
881 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
883 struct cfg80211_registered_device *drv;
884 int err;
885 struct net_device *dev;
886 u8 key_idx;
887 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
888 u8 key_index);
890 if (!info->attrs[NL80211_ATTR_KEY_IDX])
891 return -EINVAL;
893 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
895 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) {
896 if (key_idx < 4 || key_idx > 5)
897 return -EINVAL;
898 } else if (key_idx > 3)
899 return -EINVAL;
901 /* currently only support setting default key */
902 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] &&
903 !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT])
904 return -EINVAL;
906 rtnl_lock();
908 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
909 if (err)
910 goto unlock_rtnl;
912 if (info->attrs[NL80211_ATTR_KEY_DEFAULT])
913 func = drv->ops->set_default_key;
914 else
915 func = drv->ops->set_default_mgmt_key;
917 if (!func) {
918 err = -EOPNOTSUPP;
919 goto out;
922 err = func(&drv->wiphy, dev, key_idx);
924 out:
925 cfg80211_put_dev(drv);
926 dev_put(dev);
928 unlock_rtnl:
929 rtnl_unlock();
931 return err;
934 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
936 struct cfg80211_registered_device *drv;
937 int err;
938 struct net_device *dev;
939 struct key_params params;
940 u8 key_idx = 0;
941 u8 *mac_addr = NULL;
943 memset(&params, 0, sizeof(params));
945 if (!info->attrs[NL80211_ATTR_KEY_CIPHER])
946 return -EINVAL;
948 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
949 params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
950 params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
953 if (info->attrs[NL80211_ATTR_KEY_IDX])
954 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
956 params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
958 if (info->attrs[NL80211_ATTR_MAC])
959 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
961 if (key_idx > 5)
962 return -EINVAL;
965 * Disallow pairwise keys with non-zero index unless it's WEP
966 * (because current deployments use pairwise WEP keys with
967 * non-zero indizes but 802.11i clearly specifies to use zero)
969 if (mac_addr && key_idx &&
970 params.cipher != WLAN_CIPHER_SUITE_WEP40 &&
971 params.cipher != WLAN_CIPHER_SUITE_WEP104)
972 return -EINVAL;
974 /* TODO: add definitions for the lengths to linux/ieee80211.h */
975 switch (params.cipher) {
976 case WLAN_CIPHER_SUITE_WEP40:
977 if (params.key_len != 5)
978 return -EINVAL;
979 break;
980 case WLAN_CIPHER_SUITE_TKIP:
981 if (params.key_len != 32)
982 return -EINVAL;
983 break;
984 case WLAN_CIPHER_SUITE_CCMP:
985 if (params.key_len != 16)
986 return -EINVAL;
987 break;
988 case WLAN_CIPHER_SUITE_WEP104:
989 if (params.key_len != 13)
990 return -EINVAL;
991 break;
992 case WLAN_CIPHER_SUITE_AES_CMAC:
993 if (params.key_len != 16)
994 return -EINVAL;
995 break;
996 default:
997 return -EINVAL;
1000 rtnl_lock();
1002 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1003 if (err)
1004 goto unlock_rtnl;
1006 if (!drv->ops->add_key) {
1007 err = -EOPNOTSUPP;
1008 goto out;
1011 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, &params);
1013 out:
1014 cfg80211_put_dev(drv);
1015 dev_put(dev);
1016 unlock_rtnl:
1017 rtnl_unlock();
1019 return err;
1022 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1024 struct cfg80211_registered_device *drv;
1025 int err;
1026 struct net_device *dev;
1027 u8 key_idx = 0;
1028 u8 *mac_addr = NULL;
1030 if (info->attrs[NL80211_ATTR_KEY_IDX])
1031 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1033 if (key_idx > 5)
1034 return -EINVAL;
1036 if (info->attrs[NL80211_ATTR_MAC])
1037 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1039 rtnl_lock();
1041 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1042 if (err)
1043 goto unlock_rtnl;
1045 if (!drv->ops->del_key) {
1046 err = -EOPNOTSUPP;
1047 goto out;
1050 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr);
1052 out:
1053 cfg80211_put_dev(drv);
1054 dev_put(dev);
1056 unlock_rtnl:
1057 rtnl_unlock();
1059 return err;
1062 static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1064 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1065 struct beacon_parameters *info);
1066 struct cfg80211_registered_device *drv;
1067 int err;
1068 struct net_device *dev;
1069 struct beacon_parameters params;
1070 int haveinfo = 0;
1072 rtnl_lock();
1074 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1075 if (err)
1076 goto unlock_rtnl;
1078 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1079 err = -EOPNOTSUPP;
1080 goto out;
1083 switch (info->genlhdr->cmd) {
1084 case NL80211_CMD_NEW_BEACON:
1085 /* these are required for NEW_BEACON */
1086 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1087 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
1088 !info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1089 err = -EINVAL;
1090 goto out;
1093 call = drv->ops->add_beacon;
1094 break;
1095 case NL80211_CMD_SET_BEACON:
1096 call = drv->ops->set_beacon;
1097 break;
1098 default:
1099 WARN_ON(1);
1100 err = -EOPNOTSUPP;
1101 goto out;
1104 if (!call) {
1105 err = -EOPNOTSUPP;
1106 goto out;
1109 memset(&params, 0, sizeof(params));
1111 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1112 params.interval =
1113 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1114 haveinfo = 1;
1117 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
1118 params.dtim_period =
1119 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1120 haveinfo = 1;
1123 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1124 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1125 params.head_len =
1126 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1127 haveinfo = 1;
1130 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
1131 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1132 params.tail_len =
1133 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1134 haveinfo = 1;
1137 if (!haveinfo) {
1138 err = -EINVAL;
1139 goto out;
1142 err = call(&drv->wiphy, dev, &params);
1144 out:
1145 cfg80211_put_dev(drv);
1146 dev_put(dev);
1147 unlock_rtnl:
1148 rtnl_unlock();
1150 return err;
1153 static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1155 struct cfg80211_registered_device *drv;
1156 int err;
1157 struct net_device *dev;
1159 rtnl_lock();
1161 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1162 if (err)
1163 goto unlock_rtnl;
1165 if (!drv->ops->del_beacon) {
1166 err = -EOPNOTSUPP;
1167 goto out;
1170 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1171 err = -EOPNOTSUPP;
1172 goto out;
1174 err = drv->ops->del_beacon(&drv->wiphy, dev);
1176 out:
1177 cfg80211_put_dev(drv);
1178 dev_put(dev);
1179 unlock_rtnl:
1180 rtnl_unlock();
1182 return err;
1185 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1186 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
1187 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1188 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
1191 static int parse_station_flags(struct nlattr *nla, u32 *staflags)
1193 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
1194 int flag;
1196 *staflags = 0;
1198 if (!nla)
1199 return 0;
1201 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
1202 nla, sta_flags_policy))
1203 return -EINVAL;
1205 *staflags = STATION_FLAG_CHANGED;
1207 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
1208 if (flags[flag])
1209 *staflags |= (1<<flag);
1211 return 0;
1214 static u16 nl80211_calculate_bitrate(struct rate_info *rate)
1216 int modulation, streams, bitrate;
1218 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
1219 return rate->legacy;
1221 /* the formula below does only work for MCS values smaller than 32 */
1222 if (rate->mcs >= 32)
1223 return 0;
1225 modulation = rate->mcs & 7;
1226 streams = (rate->mcs >> 3) + 1;
1228 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1229 13500000 : 6500000;
1231 if (modulation < 4)
1232 bitrate *= (modulation + 1);
1233 else if (modulation == 4)
1234 bitrate *= (modulation + 2);
1235 else
1236 bitrate *= (modulation + 3);
1238 bitrate *= streams;
1240 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1241 bitrate = (bitrate / 9) * 10;
1243 /* do NOT round down here */
1244 return (bitrate + 50000) / 100000;
1247 static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1248 int flags, struct net_device *dev,
1249 u8 *mac_addr, struct station_info *sinfo)
1251 void *hdr;
1252 struct nlattr *sinfoattr, *txrate;
1253 u16 bitrate;
1255 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1256 if (!hdr)
1257 return -1;
1259 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1260 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1262 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1263 if (!sinfoattr)
1264 goto nla_put_failure;
1265 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1266 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1267 sinfo->inactive_time);
1268 if (sinfo->filled & STATION_INFO_RX_BYTES)
1269 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
1270 sinfo->rx_bytes);
1271 if (sinfo->filled & STATION_INFO_TX_BYTES)
1272 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
1273 sinfo->tx_bytes);
1274 if (sinfo->filled & STATION_INFO_LLID)
1275 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
1276 sinfo->llid);
1277 if (sinfo->filled & STATION_INFO_PLID)
1278 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
1279 sinfo->plid);
1280 if (sinfo->filled & STATION_INFO_PLINK_STATE)
1281 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
1282 sinfo->plink_state);
1283 if (sinfo->filled & STATION_INFO_SIGNAL)
1284 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1285 sinfo->signal);
1286 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1287 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1288 if (!txrate)
1289 goto nla_put_failure;
1291 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1292 bitrate = nl80211_calculate_bitrate(&sinfo->txrate);
1293 if (bitrate > 0)
1294 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1296 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1297 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1298 sinfo->txrate.mcs);
1299 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1300 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1301 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1302 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
1304 nla_nest_end(msg, txrate);
1306 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1307 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
1308 sinfo->rx_packets);
1309 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1310 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1311 sinfo->tx_packets);
1312 nla_nest_end(msg, sinfoattr);
1314 return genlmsg_end(msg, hdr);
1316 nla_put_failure:
1317 genlmsg_cancel(msg, hdr);
1318 return -EMSGSIZE;
1321 static int nl80211_dump_station(struct sk_buff *skb,
1322 struct netlink_callback *cb)
1324 struct station_info sinfo;
1325 struct cfg80211_registered_device *dev;
1326 struct net_device *netdev;
1327 u8 mac_addr[ETH_ALEN];
1328 int ifidx = cb->args[0];
1329 int sta_idx = cb->args[1];
1330 int err;
1332 if (!ifidx) {
1333 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1334 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1335 nl80211_policy);
1336 if (err)
1337 return err;
1339 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1340 return -EINVAL;
1342 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1343 if (!ifidx)
1344 return -EINVAL;
1347 rtnl_lock();
1349 netdev = __dev_get_by_index(&init_net, ifidx);
1350 if (!netdev) {
1351 err = -ENODEV;
1352 goto out_rtnl;
1355 dev = cfg80211_get_dev_from_ifindex(ifidx);
1356 if (IS_ERR(dev)) {
1357 err = PTR_ERR(dev);
1358 goto out_rtnl;
1361 if (!dev->ops->dump_station) {
1362 err = -EOPNOTSUPP;
1363 goto out_err;
1366 while (1) {
1367 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
1368 mac_addr, &sinfo);
1369 if (err == -ENOENT)
1370 break;
1371 if (err)
1372 goto out_err;
1374 if (nl80211_send_station(skb,
1375 NETLINK_CB(cb->skb).pid,
1376 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1377 netdev, mac_addr,
1378 &sinfo) < 0)
1379 goto out;
1381 sta_idx++;
1385 out:
1386 cb->args[1] = sta_idx;
1387 err = skb->len;
1388 out_err:
1389 cfg80211_put_dev(dev);
1390 out_rtnl:
1391 rtnl_unlock();
1393 return err;
1396 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1398 struct cfg80211_registered_device *drv;
1399 int err;
1400 struct net_device *dev;
1401 struct station_info sinfo;
1402 struct sk_buff *msg;
1403 u8 *mac_addr = NULL;
1405 memset(&sinfo, 0, sizeof(sinfo));
1407 if (!info->attrs[NL80211_ATTR_MAC])
1408 return -EINVAL;
1410 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1412 rtnl_lock();
1414 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1415 if (err)
1416 goto out_rtnl;
1418 if (!drv->ops->get_station) {
1419 err = -EOPNOTSUPP;
1420 goto out;
1423 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo);
1424 if (err)
1425 goto out;
1427 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1428 if (!msg)
1429 goto out;
1431 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
1432 dev, mac_addr, &sinfo) < 0)
1433 goto out_free;
1435 err = genlmsg_unicast(msg, info->snd_pid);
1436 goto out;
1438 out_free:
1439 nlmsg_free(msg);
1440 out:
1441 cfg80211_put_dev(drv);
1442 dev_put(dev);
1443 out_rtnl:
1444 rtnl_unlock();
1446 return err;
1450 * Get vlan interface making sure it is on the right wiphy.
1452 static int get_vlan(struct nlattr *vlanattr,
1453 struct cfg80211_registered_device *rdev,
1454 struct net_device **vlan)
1456 *vlan = NULL;
1458 if (vlanattr) {
1459 *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr));
1460 if (!*vlan)
1461 return -ENODEV;
1462 if (!(*vlan)->ieee80211_ptr)
1463 return -EINVAL;
1464 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
1465 return -EINVAL;
1467 return 0;
1470 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1472 struct cfg80211_registered_device *drv;
1473 int err;
1474 struct net_device *dev;
1475 struct station_parameters params;
1476 u8 *mac_addr = NULL;
1478 memset(&params, 0, sizeof(params));
1480 params.listen_interval = -1;
1482 if (info->attrs[NL80211_ATTR_STA_AID])
1483 return -EINVAL;
1485 if (!info->attrs[NL80211_ATTR_MAC])
1486 return -EINVAL;
1488 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1490 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
1491 params.supported_rates =
1492 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1493 params.supported_rates_len =
1494 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1497 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1498 params.listen_interval =
1499 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1501 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1502 params.ht_capa =
1503 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1505 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1506 &params.station_flags))
1507 return -EINVAL;
1509 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
1510 params.plink_action =
1511 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
1513 rtnl_lock();
1515 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1516 if (err)
1517 goto out_rtnl;
1519 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan);
1520 if (err)
1521 goto out;
1523 if (!drv->ops->change_station) {
1524 err = -EOPNOTSUPP;
1525 goto out;
1528 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, &params);
1530 out:
1531 if (params.vlan)
1532 dev_put(params.vlan);
1533 cfg80211_put_dev(drv);
1534 dev_put(dev);
1535 out_rtnl:
1536 rtnl_unlock();
1538 return err;
1541 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1543 struct cfg80211_registered_device *drv;
1544 int err;
1545 struct net_device *dev;
1546 struct station_parameters params;
1547 u8 *mac_addr = NULL;
1549 memset(&params, 0, sizeof(params));
1551 if (!info->attrs[NL80211_ATTR_MAC])
1552 return -EINVAL;
1554 if (!info->attrs[NL80211_ATTR_STA_AID])
1555 return -EINVAL;
1557 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1558 return -EINVAL;
1560 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
1561 return -EINVAL;
1563 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1564 params.supported_rates =
1565 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1566 params.supported_rates_len =
1567 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1568 params.listen_interval =
1569 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1570 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
1571 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1572 params.ht_capa =
1573 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1575 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1576 &params.station_flags))
1577 return -EINVAL;
1579 rtnl_lock();
1581 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1582 if (err)
1583 goto out_rtnl;
1585 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan);
1586 if (err)
1587 goto out;
1589 if (!drv->ops->add_station) {
1590 err = -EOPNOTSUPP;
1591 goto out;
1594 if (!netif_running(dev)) {
1595 err = -ENETDOWN;
1596 goto out;
1599 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, &params);
1601 out:
1602 if (params.vlan)
1603 dev_put(params.vlan);
1604 cfg80211_put_dev(drv);
1605 dev_put(dev);
1606 out_rtnl:
1607 rtnl_unlock();
1609 return err;
1612 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1614 struct cfg80211_registered_device *drv;
1615 int err;
1616 struct net_device *dev;
1617 u8 *mac_addr = NULL;
1619 if (info->attrs[NL80211_ATTR_MAC])
1620 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1622 rtnl_lock();
1624 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1625 if (err)
1626 goto out_rtnl;
1628 if (!drv->ops->del_station) {
1629 err = -EOPNOTSUPP;
1630 goto out;
1633 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr);
1635 out:
1636 cfg80211_put_dev(drv);
1637 dev_put(dev);
1638 out_rtnl:
1639 rtnl_unlock();
1641 return err;
1644 static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
1645 int flags, struct net_device *dev,
1646 u8 *dst, u8 *next_hop,
1647 struct mpath_info *pinfo)
1649 void *hdr;
1650 struct nlattr *pinfoattr;
1652 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1653 if (!hdr)
1654 return -1;
1656 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1657 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
1658 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
1660 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
1661 if (!pinfoattr)
1662 goto nla_put_failure;
1663 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
1664 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
1665 pinfo->frame_qlen);
1666 if (pinfo->filled & MPATH_INFO_DSN)
1667 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN,
1668 pinfo->dsn);
1669 if (pinfo->filled & MPATH_INFO_METRIC)
1670 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
1671 pinfo->metric);
1672 if (pinfo->filled & MPATH_INFO_EXPTIME)
1673 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
1674 pinfo->exptime);
1675 if (pinfo->filled & MPATH_INFO_FLAGS)
1676 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
1677 pinfo->flags);
1678 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
1679 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
1680 pinfo->discovery_timeout);
1681 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
1682 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
1683 pinfo->discovery_retries);
1685 nla_nest_end(msg, pinfoattr);
1687 return genlmsg_end(msg, hdr);
1689 nla_put_failure:
1690 genlmsg_cancel(msg, hdr);
1691 return -EMSGSIZE;
1694 static int nl80211_dump_mpath(struct sk_buff *skb,
1695 struct netlink_callback *cb)
1697 struct mpath_info pinfo;
1698 struct cfg80211_registered_device *dev;
1699 struct net_device *netdev;
1700 u8 dst[ETH_ALEN];
1701 u8 next_hop[ETH_ALEN];
1702 int ifidx = cb->args[0];
1703 int path_idx = cb->args[1];
1704 int err;
1706 if (!ifidx) {
1707 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1708 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1709 nl80211_policy);
1710 if (err)
1711 return err;
1713 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1714 return -EINVAL;
1716 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1717 if (!ifidx)
1718 return -EINVAL;
1721 rtnl_lock();
1723 netdev = __dev_get_by_index(&init_net, ifidx);
1724 if (!netdev) {
1725 err = -ENODEV;
1726 goto out_rtnl;
1729 dev = cfg80211_get_dev_from_ifindex(ifidx);
1730 if (IS_ERR(dev)) {
1731 err = PTR_ERR(dev);
1732 goto out_rtnl;
1735 if (!dev->ops->dump_mpath) {
1736 err = -EOPNOTSUPP;
1737 goto out_err;
1740 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1741 err = -EOPNOTSUPP;
1742 goto out;
1745 while (1) {
1746 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
1747 dst, next_hop, &pinfo);
1748 if (err == -ENOENT)
1749 break;
1750 if (err)
1751 goto out_err;
1753 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
1754 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1755 netdev, dst, next_hop,
1756 &pinfo) < 0)
1757 goto out;
1759 path_idx++;
1763 out:
1764 cb->args[1] = path_idx;
1765 err = skb->len;
1766 out_err:
1767 cfg80211_put_dev(dev);
1768 out_rtnl:
1769 rtnl_unlock();
1771 return err;
1774 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
1776 struct cfg80211_registered_device *drv;
1777 int err;
1778 struct net_device *dev;
1779 struct mpath_info pinfo;
1780 struct sk_buff *msg;
1781 u8 *dst = NULL;
1782 u8 next_hop[ETH_ALEN];
1784 memset(&pinfo, 0, sizeof(pinfo));
1786 if (!info->attrs[NL80211_ATTR_MAC])
1787 return -EINVAL;
1789 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1791 rtnl_lock();
1793 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1794 if (err)
1795 goto out_rtnl;
1797 if (!drv->ops->get_mpath) {
1798 err = -EOPNOTSUPP;
1799 goto out;
1802 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1803 err = -EOPNOTSUPP;
1804 goto out;
1807 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo);
1808 if (err)
1809 goto out;
1811 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1812 if (!msg)
1813 goto out;
1815 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
1816 dev, dst, next_hop, &pinfo) < 0)
1817 goto out_free;
1819 err = genlmsg_unicast(msg, info->snd_pid);
1820 goto out;
1822 out_free:
1823 nlmsg_free(msg);
1824 out:
1825 cfg80211_put_dev(drv);
1826 dev_put(dev);
1827 out_rtnl:
1828 rtnl_unlock();
1830 return err;
1833 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
1835 struct cfg80211_registered_device *drv;
1836 int err;
1837 struct net_device *dev;
1838 u8 *dst = NULL;
1839 u8 *next_hop = NULL;
1841 if (!info->attrs[NL80211_ATTR_MAC])
1842 return -EINVAL;
1844 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
1845 return -EINVAL;
1847 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1848 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1850 rtnl_lock();
1852 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1853 if (err)
1854 goto out_rtnl;
1856 if (!drv->ops->change_mpath) {
1857 err = -EOPNOTSUPP;
1858 goto out;
1861 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1862 err = -EOPNOTSUPP;
1863 goto out;
1866 if (!netif_running(dev)) {
1867 err = -ENETDOWN;
1868 goto out;
1871 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop);
1873 out:
1874 cfg80211_put_dev(drv);
1875 dev_put(dev);
1876 out_rtnl:
1877 rtnl_unlock();
1879 return err;
1881 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
1883 struct cfg80211_registered_device *drv;
1884 int err;
1885 struct net_device *dev;
1886 u8 *dst = NULL;
1887 u8 *next_hop = NULL;
1889 if (!info->attrs[NL80211_ATTR_MAC])
1890 return -EINVAL;
1892 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
1893 return -EINVAL;
1895 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1896 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1898 rtnl_lock();
1900 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1901 if (err)
1902 goto out_rtnl;
1904 if (!drv->ops->add_mpath) {
1905 err = -EOPNOTSUPP;
1906 goto out;
1909 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1910 err = -EOPNOTSUPP;
1911 goto out;
1914 if (!netif_running(dev)) {
1915 err = -ENETDOWN;
1916 goto out;
1919 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop);
1921 out:
1922 cfg80211_put_dev(drv);
1923 dev_put(dev);
1924 out_rtnl:
1925 rtnl_unlock();
1927 return err;
1930 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
1932 struct cfg80211_registered_device *drv;
1933 int err;
1934 struct net_device *dev;
1935 u8 *dst = NULL;
1937 if (info->attrs[NL80211_ATTR_MAC])
1938 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1940 rtnl_lock();
1942 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1943 if (err)
1944 goto out_rtnl;
1946 if (!drv->ops->del_mpath) {
1947 err = -EOPNOTSUPP;
1948 goto out;
1951 err = drv->ops->del_mpath(&drv->wiphy, dev, dst);
1953 out:
1954 cfg80211_put_dev(drv);
1955 dev_put(dev);
1956 out_rtnl:
1957 rtnl_unlock();
1959 return err;
1962 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
1964 struct cfg80211_registered_device *drv;
1965 int err;
1966 struct net_device *dev;
1967 struct bss_parameters params;
1969 memset(&params, 0, sizeof(params));
1970 /* default to not changing parameters */
1971 params.use_cts_prot = -1;
1972 params.use_short_preamble = -1;
1973 params.use_short_slot_time = -1;
1975 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
1976 params.use_cts_prot =
1977 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
1978 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
1979 params.use_short_preamble =
1980 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
1981 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
1982 params.use_short_slot_time =
1983 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
1984 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
1985 params.basic_rates =
1986 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1987 params.basic_rates_len =
1988 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1991 rtnl_lock();
1993 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1994 if (err)
1995 goto out_rtnl;
1997 if (!drv->ops->change_bss) {
1998 err = -EOPNOTSUPP;
1999 goto out;
2002 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
2003 err = -EOPNOTSUPP;
2004 goto out;
2007 err = drv->ops->change_bss(&drv->wiphy, dev, &params);
2009 out:
2010 cfg80211_put_dev(drv);
2011 dev_put(dev);
2012 out_rtnl:
2013 rtnl_unlock();
2015 return err;
2018 static const struct nla_policy
2019 reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
2020 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2021 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2022 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2023 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2024 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2025 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2028 static int parse_reg_rule(struct nlattr *tb[],
2029 struct ieee80211_reg_rule *reg_rule)
2031 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
2032 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
2034 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2035 return -EINVAL;
2036 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2037 return -EINVAL;
2038 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2039 return -EINVAL;
2040 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2041 return -EINVAL;
2042 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2043 return -EINVAL;
2045 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2047 freq_range->start_freq_khz =
2048 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2049 freq_range->end_freq_khz =
2050 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2051 freq_range->max_bandwidth_khz =
2052 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2054 power_rule->max_eirp =
2055 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2057 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2058 power_rule->max_antenna_gain =
2059 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2061 return 0;
2064 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2066 int r;
2067 char *data = NULL;
2070 * You should only get this when cfg80211 hasn't yet initialized
2071 * completely when built-in to the kernel right between the time
2072 * window between nl80211_init() and regulatory_init(), if that is
2073 * even possible.
2075 mutex_lock(&cfg80211_mutex);
2076 if (unlikely(!cfg80211_regdomain)) {
2077 mutex_unlock(&cfg80211_mutex);
2078 return -EINPROGRESS;
2080 mutex_unlock(&cfg80211_mutex);
2082 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2083 return -EINVAL;
2085 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2087 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2088 /* We ignore world regdom requests with the old regdom setup */
2089 if (is_world_regdom(data))
2090 return -EINVAL;
2091 #endif
2093 r = regulatory_hint_user(data);
2095 return r;
2098 static int nl80211_get_mesh_params(struct sk_buff *skb,
2099 struct genl_info *info)
2101 struct cfg80211_registered_device *drv;
2102 struct mesh_config cur_params;
2103 int err;
2104 struct net_device *dev;
2105 void *hdr;
2106 struct nlattr *pinfoattr;
2107 struct sk_buff *msg;
2109 rtnl_lock();
2111 /* Look up our device */
2112 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2113 if (err)
2114 goto out_rtnl;
2116 if (!drv->ops->get_mesh_params) {
2117 err = -EOPNOTSUPP;
2118 goto out;
2121 /* Get the mesh params */
2122 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params);
2123 if (err)
2124 goto out;
2126 /* Draw up a netlink message to send back */
2127 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2128 if (!msg) {
2129 err = -ENOBUFS;
2130 goto out;
2132 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2133 NL80211_CMD_GET_MESH_PARAMS);
2134 if (!hdr)
2135 goto nla_put_failure;
2136 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS);
2137 if (!pinfoattr)
2138 goto nla_put_failure;
2139 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2140 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2141 cur_params.dot11MeshRetryTimeout);
2142 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2143 cur_params.dot11MeshConfirmTimeout);
2144 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2145 cur_params.dot11MeshHoldingTimeout);
2146 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2147 cur_params.dot11MeshMaxPeerLinks);
2148 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2149 cur_params.dot11MeshMaxRetries);
2150 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2151 cur_params.dot11MeshTTL);
2152 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2153 cur_params.auto_open_plinks);
2154 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2155 cur_params.dot11MeshHWMPmaxPREQretries);
2156 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2157 cur_params.path_refresh_time);
2158 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2159 cur_params.min_discovery_timeout);
2160 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2161 cur_params.dot11MeshHWMPactivePathTimeout);
2162 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2163 cur_params.dot11MeshHWMPpreqMinInterval);
2164 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2165 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
2166 nla_nest_end(msg, pinfoattr);
2167 genlmsg_end(msg, hdr);
2168 err = genlmsg_unicast(msg, info->snd_pid);
2169 goto out;
2171 nla_put_failure:
2172 genlmsg_cancel(msg, hdr);
2173 err = -EMSGSIZE;
2174 out:
2175 /* Cleanup */
2176 cfg80211_put_dev(drv);
2177 dev_put(dev);
2178 out_rtnl:
2179 rtnl_unlock();
2181 return err;
2184 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2185 do {\
2186 if (table[attr_num]) {\
2187 cfg.param = nla_fn(table[attr_num]); \
2188 mask |= (1 << (attr_num - 1)); \
2190 } while (0);\
2192 static struct nla_policy
2193 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = {
2194 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2195 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2196 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2197 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2198 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2199 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2200 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2202 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2203 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2204 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2205 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2206 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2207 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2210 static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2212 int err;
2213 u32 mask;
2214 struct cfg80211_registered_device *drv;
2215 struct net_device *dev;
2216 struct mesh_config cfg;
2217 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2218 struct nlattr *parent_attr;
2220 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2221 if (!parent_attr)
2222 return -EINVAL;
2223 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2224 parent_attr, nl80211_meshconf_params_policy))
2225 return -EINVAL;
2227 rtnl_lock();
2229 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2230 if (err)
2231 goto out_rtnl;
2233 if (!drv->ops->set_mesh_params) {
2234 err = -EOPNOTSUPP;
2235 goto out;
2238 /* This makes sure that there aren't more than 32 mesh config
2239 * parameters (otherwise our bitfield scheme would not work.) */
2240 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2242 /* Fill in the params struct */
2243 mask = 0;
2244 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2245 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2247 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2248 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2249 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2250 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2251 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2252 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2253 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2254 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2255 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2256 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2257 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2258 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2259 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2260 nla_get_u8);
2261 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2262 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2263 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2264 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2265 nla_get_u16);
2266 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2267 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2268 nla_get_u32);
2269 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2270 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2271 nla_get_u16);
2272 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2273 dot11MeshHWMPnetDiameterTraversalTime,
2274 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2275 nla_get_u16);
2277 /* Apply changes */
2278 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask);
2280 out:
2281 /* cleanup */
2282 cfg80211_put_dev(drv);
2283 dev_put(dev);
2284 out_rtnl:
2285 rtnl_unlock();
2287 return err;
2290 #undef FILL_IN_MESH_PARAM_IF_SET
2292 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2294 struct sk_buff *msg;
2295 void *hdr = NULL;
2296 struct nlattr *nl_reg_rules;
2297 unsigned int i;
2298 int err = -EINVAL;
2300 mutex_lock(&cfg80211_mutex);
2302 if (!cfg80211_regdomain)
2303 goto out;
2305 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2306 if (!msg) {
2307 err = -ENOBUFS;
2308 goto out;
2311 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2312 NL80211_CMD_GET_REG);
2313 if (!hdr)
2314 goto nla_put_failure;
2316 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2317 cfg80211_regdomain->alpha2);
2319 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2320 if (!nl_reg_rules)
2321 goto nla_put_failure;
2323 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2324 struct nlattr *nl_reg_rule;
2325 const struct ieee80211_reg_rule *reg_rule;
2326 const struct ieee80211_freq_range *freq_range;
2327 const struct ieee80211_power_rule *power_rule;
2329 reg_rule = &cfg80211_regdomain->reg_rules[i];
2330 freq_range = &reg_rule->freq_range;
2331 power_rule = &reg_rule->power_rule;
2333 nl_reg_rule = nla_nest_start(msg, i);
2334 if (!nl_reg_rule)
2335 goto nla_put_failure;
2337 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2338 reg_rule->flags);
2339 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2340 freq_range->start_freq_khz);
2341 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2342 freq_range->end_freq_khz);
2343 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2344 freq_range->max_bandwidth_khz);
2345 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2346 power_rule->max_antenna_gain);
2347 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2348 power_rule->max_eirp);
2350 nla_nest_end(msg, nl_reg_rule);
2353 nla_nest_end(msg, nl_reg_rules);
2355 genlmsg_end(msg, hdr);
2356 err = genlmsg_unicast(msg, info->snd_pid);
2357 goto out;
2359 nla_put_failure:
2360 genlmsg_cancel(msg, hdr);
2361 err = -EMSGSIZE;
2362 out:
2363 mutex_unlock(&cfg80211_mutex);
2364 return err;
2367 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2369 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
2370 struct nlattr *nl_reg_rule;
2371 char *alpha2 = NULL;
2372 int rem_reg_rules = 0, r = 0;
2373 u32 num_rules = 0, rule_idx = 0, size_of_regd;
2374 struct ieee80211_regdomain *rd = NULL;
2376 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2377 return -EINVAL;
2379 if (!info->attrs[NL80211_ATTR_REG_RULES])
2380 return -EINVAL;
2382 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2384 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2385 rem_reg_rules) {
2386 num_rules++;
2387 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
2388 goto bad_reg;
2391 if (!reg_is_valid_request(alpha2))
2392 return -EINVAL;
2394 size_of_regd = sizeof(struct ieee80211_regdomain) +
2395 (num_rules * sizeof(struct ieee80211_reg_rule));
2397 rd = kzalloc(size_of_regd, GFP_KERNEL);
2398 if (!rd)
2399 return -ENOMEM;
2401 rd->n_reg_rules = num_rules;
2402 rd->alpha2[0] = alpha2[0];
2403 rd->alpha2[1] = alpha2[1];
2405 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2406 rem_reg_rules) {
2407 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
2408 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
2409 reg_rule_policy);
2410 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
2411 if (r)
2412 goto bad_reg;
2414 rule_idx++;
2416 if (rule_idx > NL80211_MAX_SUPP_REG_RULES)
2417 goto bad_reg;
2420 BUG_ON(rule_idx != num_rules);
2422 mutex_lock(&cfg80211_mutex);
2423 r = set_regdom(rd);
2424 mutex_unlock(&cfg80211_mutex);
2425 return r;
2427 bad_reg:
2428 kfree(rd);
2429 return -EINVAL;
2432 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2434 struct cfg80211_registered_device *drv;
2435 struct net_device *dev;
2436 struct cfg80211_scan_request *request;
2437 struct cfg80211_ssid *ssid;
2438 struct ieee80211_channel *channel;
2439 struct nlattr *attr;
2440 struct wiphy *wiphy;
2441 int err, tmp, n_ssids = 0, n_channels = 0, i;
2442 enum ieee80211_band band;
2443 size_t ie_len;
2445 rtnl_lock();
2447 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2448 if (err)
2449 goto out_rtnl;
2451 wiphy = &drv->wiphy;
2453 if (!drv->ops->scan) {
2454 err = -EOPNOTSUPP;
2455 goto out;
2458 if (!netif_running(dev)) {
2459 err = -ENETDOWN;
2460 goto out;
2463 if (drv->scan_req) {
2464 err = -EBUSY;
2465 goto out;
2468 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2469 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp)
2470 n_channels++;
2471 if (!n_channels) {
2472 err = -EINVAL;
2473 goto out;
2475 } else {
2476 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2477 if (wiphy->bands[band])
2478 n_channels += wiphy->bands[band]->n_channels;
2481 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2482 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2483 n_ssids++;
2485 if (n_ssids > wiphy->max_scan_ssids) {
2486 err = -EINVAL;
2487 goto out;
2490 if (info->attrs[NL80211_ATTR_IE])
2491 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2492 else
2493 ie_len = 0;
2495 request = kzalloc(sizeof(*request)
2496 + sizeof(*ssid) * n_ssids
2497 + sizeof(channel) * n_channels
2498 + ie_len, GFP_KERNEL);
2499 if (!request) {
2500 err = -ENOMEM;
2501 goto out;
2504 request->channels = (void *)((char *)request + sizeof(*request));
2505 request->n_channels = n_channels;
2506 if (n_ssids)
2507 request->ssids = (void *)(request->channels + n_channels);
2508 request->n_ssids = n_ssids;
2509 if (ie_len) {
2510 if (request->ssids)
2511 request->ie = (void *)(request->ssids + n_ssids);
2512 else
2513 request->ie = (void *)(request->channels + n_channels);
2516 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2517 /* user specified, bail out if channel not found */
2518 request->n_channels = n_channels;
2519 i = 0;
2520 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
2521 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2522 if (!request->channels[i]) {
2523 err = -EINVAL;
2524 goto out_free;
2526 i++;
2528 } else {
2529 /* all channels */
2530 i = 0;
2531 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2532 int j;
2533 if (!wiphy->bands[band])
2534 continue;
2535 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2536 request->channels[i] = &wiphy->bands[band]->channels[j];
2537 i++;
2542 i = 0;
2543 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2544 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2545 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2546 err = -EINVAL;
2547 goto out_free;
2549 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
2550 request->ssids[i].ssid_len = nla_len(attr);
2551 i++;
2555 if (info->attrs[NL80211_ATTR_IE]) {
2556 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2557 memcpy(request->ie, nla_data(info->attrs[NL80211_ATTR_IE]),
2558 request->ie_len);
2561 request->ifidx = dev->ifindex;
2562 request->wiphy = &drv->wiphy;
2564 drv->scan_req = request;
2565 err = drv->ops->scan(&drv->wiphy, dev, request);
2567 out_free:
2568 if (err) {
2569 drv->scan_req = NULL;
2570 kfree(request);
2572 out:
2573 cfg80211_put_dev(drv);
2574 dev_put(dev);
2575 out_rtnl:
2576 rtnl_unlock();
2578 return err;
2581 static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
2582 struct cfg80211_registered_device *rdev,
2583 struct net_device *dev,
2584 struct cfg80211_bss *res)
2586 void *hdr;
2587 struct nlattr *bss;
2589 hdr = nl80211hdr_put(msg, pid, seq, flags,
2590 NL80211_CMD_NEW_SCAN_RESULTS);
2591 if (!hdr)
2592 return -1;
2594 NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION,
2595 rdev->bss_generation);
2596 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2598 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
2599 if (!bss)
2600 goto nla_put_failure;
2601 if (!is_zero_ether_addr(res->bssid))
2602 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
2603 if (res->information_elements && res->len_information_elements)
2604 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
2605 res->len_information_elements,
2606 res->information_elements);
2607 if (res->tsf)
2608 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
2609 if (res->beacon_interval)
2610 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
2611 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
2612 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
2614 switch (rdev->wiphy.signal_type) {
2615 case CFG80211_SIGNAL_TYPE_MBM:
2616 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
2617 break;
2618 case CFG80211_SIGNAL_TYPE_UNSPEC:
2619 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
2620 break;
2621 default:
2622 break;
2625 nla_nest_end(msg, bss);
2627 return genlmsg_end(msg, hdr);
2629 nla_put_failure:
2630 genlmsg_cancel(msg, hdr);
2631 return -EMSGSIZE;
2634 static int nl80211_dump_scan(struct sk_buff *skb,
2635 struct netlink_callback *cb)
2637 struct cfg80211_registered_device *dev;
2638 struct net_device *netdev;
2639 struct cfg80211_internal_bss *scan;
2640 int ifidx = cb->args[0];
2641 int start = cb->args[1], idx = 0;
2642 int err;
2644 if (!ifidx) {
2645 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
2646 nl80211_fam.attrbuf, nl80211_fam.maxattr,
2647 nl80211_policy);
2648 if (err)
2649 return err;
2651 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2652 return -EINVAL;
2654 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2655 if (!ifidx)
2656 return -EINVAL;
2657 cb->args[0] = ifidx;
2660 netdev = dev_get_by_index(&init_net, ifidx);
2661 if (!netdev)
2662 return -ENODEV;
2664 dev = cfg80211_get_dev_from_ifindex(ifidx);
2665 if (IS_ERR(dev)) {
2666 err = PTR_ERR(dev);
2667 goto out_put_netdev;
2670 spin_lock_bh(&dev->bss_lock);
2671 cfg80211_bss_expire(dev);
2673 list_for_each_entry(scan, &dev->bss_list, list) {
2674 if (++idx <= start)
2675 continue;
2676 if (nl80211_send_bss(skb,
2677 NETLINK_CB(cb->skb).pid,
2678 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2679 dev, netdev, &scan->pub) < 0) {
2680 idx--;
2681 goto out;
2685 out:
2686 spin_unlock_bh(&dev->bss_lock);
2688 cb->args[1] = idx;
2689 err = skb->len;
2690 cfg80211_put_dev(dev);
2691 out_put_netdev:
2692 dev_put(netdev);
2694 return err;
2697 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
2699 return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM ||
2700 auth_type == NL80211_AUTHTYPE_SHARED_KEY ||
2701 auth_type == NL80211_AUTHTYPE_FT ||
2702 auth_type == NL80211_AUTHTYPE_NETWORK_EAP;
2705 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2707 struct cfg80211_registered_device *drv;
2708 struct net_device *dev;
2709 struct cfg80211_auth_request req;
2710 struct wiphy *wiphy;
2711 int err;
2713 rtnl_lock();
2715 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2716 if (err)
2717 goto unlock_rtnl;
2719 if (!drv->ops->auth) {
2720 err = -EOPNOTSUPP;
2721 goto out;
2724 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2725 err = -EOPNOTSUPP;
2726 goto out;
2729 if (!netif_running(dev)) {
2730 err = -ENETDOWN;
2731 goto out;
2734 if (!info->attrs[NL80211_ATTR_MAC]) {
2735 err = -EINVAL;
2736 goto out;
2739 wiphy = &drv->wiphy;
2740 memset(&req, 0, sizeof(req));
2742 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2744 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2745 req.chan = ieee80211_get_channel(
2746 wiphy,
2747 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2748 if (!req.chan) {
2749 err = -EINVAL;
2750 goto out;
2754 if (info->attrs[NL80211_ATTR_SSID]) {
2755 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2756 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2759 if (info->attrs[NL80211_ATTR_IE]) {
2760 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2761 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2764 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2765 req.auth_type =
2766 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
2767 if (!nl80211_valid_auth_type(req.auth_type)) {
2768 err = -EINVAL;
2769 goto out;
2773 err = drv->ops->auth(&drv->wiphy, dev, &req);
2775 out:
2776 cfg80211_put_dev(drv);
2777 dev_put(dev);
2778 unlock_rtnl:
2779 rtnl_unlock();
2780 return err;
2783 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2785 struct cfg80211_registered_device *drv;
2786 struct net_device *dev;
2787 struct cfg80211_assoc_request req;
2788 struct wiphy *wiphy;
2789 int err;
2791 rtnl_lock();
2793 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2794 if (err)
2795 goto unlock_rtnl;
2797 if (!drv->ops->assoc) {
2798 err = -EOPNOTSUPP;
2799 goto out;
2802 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2803 err = -EOPNOTSUPP;
2804 goto out;
2807 if (!netif_running(dev)) {
2808 err = -ENETDOWN;
2809 goto out;
2812 if (!info->attrs[NL80211_ATTR_MAC] ||
2813 !info->attrs[NL80211_ATTR_SSID]) {
2814 err = -EINVAL;
2815 goto out;
2818 wiphy = &drv->wiphy;
2819 memset(&req, 0, sizeof(req));
2821 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2823 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2824 req.chan = ieee80211_get_channel(
2825 wiphy,
2826 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2827 if (!req.chan) {
2828 err = -EINVAL;
2829 goto out;
2833 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2834 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2836 if (info->attrs[NL80211_ATTR_IE]) {
2837 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2838 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2841 err = drv->ops->assoc(&drv->wiphy, dev, &req);
2843 out:
2844 cfg80211_put_dev(drv);
2845 dev_put(dev);
2846 unlock_rtnl:
2847 rtnl_unlock();
2848 return err;
2851 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
2853 struct cfg80211_registered_device *drv;
2854 struct net_device *dev;
2855 struct cfg80211_deauth_request req;
2856 struct wiphy *wiphy;
2857 int err;
2859 rtnl_lock();
2861 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2862 if (err)
2863 goto unlock_rtnl;
2865 if (!drv->ops->deauth) {
2866 err = -EOPNOTSUPP;
2867 goto out;
2870 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2871 err = -EOPNOTSUPP;
2872 goto out;
2875 if (!netif_running(dev)) {
2876 err = -ENETDOWN;
2877 goto out;
2880 if (!info->attrs[NL80211_ATTR_MAC]) {
2881 err = -EINVAL;
2882 goto out;
2885 wiphy = &drv->wiphy;
2886 memset(&req, 0, sizeof(req));
2888 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2890 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
2891 req.reason_code =
2892 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2893 if (req.reason_code == 0) {
2894 /* Reason Code 0 is reserved */
2895 err = -EINVAL;
2896 goto out;
2900 if (info->attrs[NL80211_ATTR_IE]) {
2901 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2902 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2905 err = drv->ops->deauth(&drv->wiphy, dev, &req);
2907 out:
2908 cfg80211_put_dev(drv);
2909 dev_put(dev);
2910 unlock_rtnl:
2911 rtnl_unlock();
2912 return err;
2915 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
2917 struct cfg80211_registered_device *drv;
2918 struct net_device *dev;
2919 struct cfg80211_disassoc_request req;
2920 struct wiphy *wiphy;
2921 int err;
2923 rtnl_lock();
2925 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2926 if (err)
2927 goto unlock_rtnl;
2929 if (!drv->ops->disassoc) {
2930 err = -EOPNOTSUPP;
2931 goto out;
2934 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2935 err = -EOPNOTSUPP;
2936 goto out;
2939 if (!netif_running(dev)) {
2940 err = -ENETDOWN;
2941 goto out;
2944 if (!info->attrs[NL80211_ATTR_MAC]) {
2945 err = -EINVAL;
2946 goto out;
2949 wiphy = &drv->wiphy;
2950 memset(&req, 0, sizeof(req));
2952 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2954 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
2955 req.reason_code =
2956 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2957 if (req.reason_code == 0) {
2958 /* Reason Code 0 is reserved */
2959 err = -EINVAL;
2960 goto out;
2964 if (info->attrs[NL80211_ATTR_IE]) {
2965 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2966 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2969 err = drv->ops->disassoc(&drv->wiphy, dev, &req);
2971 out:
2972 cfg80211_put_dev(drv);
2973 dev_put(dev);
2974 unlock_rtnl:
2975 rtnl_unlock();
2976 return err;
2979 static struct genl_ops nl80211_ops[] = {
2981 .cmd = NL80211_CMD_GET_WIPHY,
2982 .doit = nl80211_get_wiphy,
2983 .dumpit = nl80211_dump_wiphy,
2984 .policy = nl80211_policy,
2985 /* can be retrieved by unprivileged users */
2988 .cmd = NL80211_CMD_SET_WIPHY,
2989 .doit = nl80211_set_wiphy,
2990 .policy = nl80211_policy,
2991 .flags = GENL_ADMIN_PERM,
2994 .cmd = NL80211_CMD_GET_INTERFACE,
2995 .doit = nl80211_get_interface,
2996 .dumpit = nl80211_dump_interface,
2997 .policy = nl80211_policy,
2998 /* can be retrieved by unprivileged users */
3001 .cmd = NL80211_CMD_SET_INTERFACE,
3002 .doit = nl80211_set_interface,
3003 .policy = nl80211_policy,
3004 .flags = GENL_ADMIN_PERM,
3007 .cmd = NL80211_CMD_NEW_INTERFACE,
3008 .doit = nl80211_new_interface,
3009 .policy = nl80211_policy,
3010 .flags = GENL_ADMIN_PERM,
3013 .cmd = NL80211_CMD_DEL_INTERFACE,
3014 .doit = nl80211_del_interface,
3015 .policy = nl80211_policy,
3016 .flags = GENL_ADMIN_PERM,
3019 .cmd = NL80211_CMD_GET_KEY,
3020 .doit = nl80211_get_key,
3021 .policy = nl80211_policy,
3022 .flags = GENL_ADMIN_PERM,
3025 .cmd = NL80211_CMD_SET_KEY,
3026 .doit = nl80211_set_key,
3027 .policy = nl80211_policy,
3028 .flags = GENL_ADMIN_PERM,
3031 .cmd = NL80211_CMD_NEW_KEY,
3032 .doit = nl80211_new_key,
3033 .policy = nl80211_policy,
3034 .flags = GENL_ADMIN_PERM,
3037 .cmd = NL80211_CMD_DEL_KEY,
3038 .doit = nl80211_del_key,
3039 .policy = nl80211_policy,
3040 .flags = GENL_ADMIN_PERM,
3043 .cmd = NL80211_CMD_SET_BEACON,
3044 .policy = nl80211_policy,
3045 .flags = GENL_ADMIN_PERM,
3046 .doit = nl80211_addset_beacon,
3049 .cmd = NL80211_CMD_NEW_BEACON,
3050 .policy = nl80211_policy,
3051 .flags = GENL_ADMIN_PERM,
3052 .doit = nl80211_addset_beacon,
3055 .cmd = NL80211_CMD_DEL_BEACON,
3056 .policy = nl80211_policy,
3057 .flags = GENL_ADMIN_PERM,
3058 .doit = nl80211_del_beacon,
3061 .cmd = NL80211_CMD_GET_STATION,
3062 .doit = nl80211_get_station,
3063 .dumpit = nl80211_dump_station,
3064 .policy = nl80211_policy,
3067 .cmd = NL80211_CMD_SET_STATION,
3068 .doit = nl80211_set_station,
3069 .policy = nl80211_policy,
3070 .flags = GENL_ADMIN_PERM,
3073 .cmd = NL80211_CMD_NEW_STATION,
3074 .doit = nl80211_new_station,
3075 .policy = nl80211_policy,
3076 .flags = GENL_ADMIN_PERM,
3079 .cmd = NL80211_CMD_DEL_STATION,
3080 .doit = nl80211_del_station,
3081 .policy = nl80211_policy,
3082 .flags = GENL_ADMIN_PERM,
3085 .cmd = NL80211_CMD_GET_MPATH,
3086 .doit = nl80211_get_mpath,
3087 .dumpit = nl80211_dump_mpath,
3088 .policy = nl80211_policy,
3089 .flags = GENL_ADMIN_PERM,
3092 .cmd = NL80211_CMD_SET_MPATH,
3093 .doit = nl80211_set_mpath,
3094 .policy = nl80211_policy,
3095 .flags = GENL_ADMIN_PERM,
3098 .cmd = NL80211_CMD_NEW_MPATH,
3099 .doit = nl80211_new_mpath,
3100 .policy = nl80211_policy,
3101 .flags = GENL_ADMIN_PERM,
3104 .cmd = NL80211_CMD_DEL_MPATH,
3105 .doit = nl80211_del_mpath,
3106 .policy = nl80211_policy,
3107 .flags = GENL_ADMIN_PERM,
3110 .cmd = NL80211_CMD_SET_BSS,
3111 .doit = nl80211_set_bss,
3112 .policy = nl80211_policy,
3113 .flags = GENL_ADMIN_PERM,
3116 .cmd = NL80211_CMD_GET_REG,
3117 .doit = nl80211_get_reg,
3118 .policy = nl80211_policy,
3119 /* can be retrieved by unprivileged users */
3122 .cmd = NL80211_CMD_SET_REG,
3123 .doit = nl80211_set_reg,
3124 .policy = nl80211_policy,
3125 .flags = GENL_ADMIN_PERM,
3128 .cmd = NL80211_CMD_REQ_SET_REG,
3129 .doit = nl80211_req_set_reg,
3130 .policy = nl80211_policy,
3131 .flags = GENL_ADMIN_PERM,
3134 .cmd = NL80211_CMD_GET_MESH_PARAMS,
3135 .doit = nl80211_get_mesh_params,
3136 .policy = nl80211_policy,
3137 /* can be retrieved by unprivileged users */
3140 .cmd = NL80211_CMD_SET_MESH_PARAMS,
3141 .doit = nl80211_set_mesh_params,
3142 .policy = nl80211_policy,
3143 .flags = GENL_ADMIN_PERM,
3146 .cmd = NL80211_CMD_TRIGGER_SCAN,
3147 .doit = nl80211_trigger_scan,
3148 .policy = nl80211_policy,
3149 .flags = GENL_ADMIN_PERM,
3152 .cmd = NL80211_CMD_GET_SCAN,
3153 .policy = nl80211_policy,
3154 .dumpit = nl80211_dump_scan,
3157 .cmd = NL80211_CMD_AUTHENTICATE,
3158 .doit = nl80211_authenticate,
3159 .policy = nl80211_policy,
3160 .flags = GENL_ADMIN_PERM,
3163 .cmd = NL80211_CMD_ASSOCIATE,
3164 .doit = nl80211_associate,
3165 .policy = nl80211_policy,
3166 .flags = GENL_ADMIN_PERM,
3169 .cmd = NL80211_CMD_DEAUTHENTICATE,
3170 .doit = nl80211_deauthenticate,
3171 .policy = nl80211_policy,
3172 .flags = GENL_ADMIN_PERM,
3175 .cmd = NL80211_CMD_DISASSOCIATE,
3176 .doit = nl80211_disassociate,
3177 .policy = nl80211_policy,
3178 .flags = GENL_ADMIN_PERM,
3181 static struct genl_multicast_group nl80211_mlme_mcgrp = {
3182 .name = "mlme",
3185 /* multicast groups */
3186 static struct genl_multicast_group nl80211_config_mcgrp = {
3187 .name = "config",
3189 static struct genl_multicast_group nl80211_scan_mcgrp = {
3190 .name = "scan",
3192 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
3193 .name = "regulatory",
3196 /* notification functions */
3198 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
3200 struct sk_buff *msg;
3202 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3203 if (!msg)
3204 return;
3206 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
3207 nlmsg_free(msg);
3208 return;
3211 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
3214 static int nl80211_send_scan_donemsg(struct sk_buff *msg,
3215 struct cfg80211_registered_device *rdev,
3216 struct net_device *netdev,
3217 u32 pid, u32 seq, int flags,
3218 u32 cmd)
3220 void *hdr;
3222 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
3223 if (!hdr)
3224 return -1;
3226 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3227 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3229 /* XXX: we should probably bounce back the request? */
3231 return genlmsg_end(msg, hdr);
3233 nla_put_failure:
3234 genlmsg_cancel(msg, hdr);
3235 return -EMSGSIZE;
3238 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3239 struct net_device *netdev)
3241 struct sk_buff *msg;
3243 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3244 if (!msg)
3245 return;
3247 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3248 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
3249 nlmsg_free(msg);
3250 return;
3253 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3256 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
3257 struct net_device *netdev)
3259 struct sk_buff *msg;
3261 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3262 if (!msg)
3263 return;
3265 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3266 NL80211_CMD_SCAN_ABORTED) < 0) {
3267 nlmsg_free(msg);
3268 return;
3271 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3275 * This can happen on global regulatory changes or device specific settings
3276 * based on custom world regulatory domains.
3278 void nl80211_send_reg_change_event(struct regulatory_request *request)
3280 struct sk_buff *msg;
3281 void *hdr;
3283 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3284 if (!msg)
3285 return;
3287 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
3288 if (!hdr) {
3289 nlmsg_free(msg);
3290 return;
3293 /* Userspace can always count this one always being set */
3294 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
3296 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
3297 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3298 NL80211_REGDOM_TYPE_WORLD);
3299 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
3300 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3301 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
3302 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
3303 request->intersect)
3304 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3305 NL80211_REGDOM_TYPE_INTERSECTION);
3306 else {
3307 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3308 NL80211_REGDOM_TYPE_COUNTRY);
3309 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
3312 if (wiphy_idx_valid(request->wiphy_idx))
3313 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
3315 if (genlmsg_end(msg, hdr) < 0) {
3316 nlmsg_free(msg);
3317 return;
3320 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL);
3322 return;
3324 nla_put_failure:
3325 genlmsg_cancel(msg, hdr);
3326 nlmsg_free(msg);
3329 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3330 struct net_device *netdev,
3331 const u8 *buf, size_t len,
3332 enum nl80211_commands cmd)
3334 struct sk_buff *msg;
3335 void *hdr;
3337 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3338 if (!msg)
3339 return;
3341 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3342 if (!hdr) {
3343 nlmsg_free(msg);
3344 return;
3347 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3348 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3349 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
3351 if (genlmsg_end(msg, hdr) < 0) {
3352 nlmsg_free(msg);
3353 return;
3356 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3357 return;
3359 nla_put_failure:
3360 genlmsg_cancel(msg, hdr);
3361 nlmsg_free(msg);
3364 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3365 struct net_device *netdev, const u8 *buf, size_t len)
3367 nl80211_send_mlme_event(rdev, netdev, buf, len,
3368 NL80211_CMD_AUTHENTICATE);
3371 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3372 struct net_device *netdev, const u8 *buf,
3373 size_t len)
3375 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3378 void nl80211_send_rx_deauth(struct cfg80211_registered_device *rdev,
3379 struct net_device *netdev, const u8 *buf,
3380 size_t len)
3382 nl80211_send_mlme_event(rdev, netdev, buf, len,
3383 NL80211_CMD_DEAUTHENTICATE);
3386 void nl80211_send_rx_disassoc(struct cfg80211_registered_device *rdev,
3387 struct net_device *netdev, const u8 *buf,
3388 size_t len)
3390 nl80211_send_mlme_event(rdev, netdev, buf, len,
3391 NL80211_CMD_DISASSOCIATE);
3394 /* initialisation/exit functions */
3396 int nl80211_init(void)
3398 int err, i;
3400 err = genl_register_family(&nl80211_fam);
3401 if (err)
3402 return err;
3404 for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) {
3405 err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]);
3406 if (err)
3407 goto err_out;
3410 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
3411 if (err)
3412 goto err_out;
3414 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
3415 if (err)
3416 goto err_out;
3418 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
3419 if (err)
3420 goto err_out;
3422 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
3423 if (err)
3424 goto err_out;
3426 return 0;
3427 err_out:
3428 genl_unregister_family(&nl80211_fam);
3429 return err;
3432 void nl80211_exit(void)
3434 genl_unregister_family(&nl80211_fam);