2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.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>
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)
39 if (!attrs[NL80211_ATTR_IFINDEX])
42 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
43 *dev = dev_get_by_index(&init_net, ifindex);
47 *drv = cfg80211_get_dev_from_ifindex(ifindex);
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 },
64 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
65 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
66 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
67 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
69 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
70 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
71 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
73 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
75 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
76 .len = WLAN_MAX_KEY_LEN },
77 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
78 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
79 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
81 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
82 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
83 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
84 .len = IEEE80211_MAX_DATA_LEN },
85 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
86 .len = IEEE80211_MAX_DATA_LEN },
87 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
88 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
89 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
90 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
91 .len = NL80211_MAX_SUPP_RATES },
92 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
93 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
94 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
95 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
96 .len = IEEE80211_MAX_MESH_ID_LEN },
97 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
99 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
100 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
102 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
103 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
104 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
105 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
106 .len = NL80211_MAX_SUPP_RATES },
108 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED },
110 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
111 .len = NL80211_HT_CAPABILITY_LEN },
113 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
114 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
115 .len = IEEE80211_MAX_DATA_LEN },
116 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
117 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
119 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
120 .len = IEEE80211_MAX_SSID_LEN },
121 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
122 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
123 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
124 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
128 static bool is_valid_ie_attr(const struct nlattr *attr)
136 pos = nla_data(attr);
157 /* message building helper */
158 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
161 /* since there is no private header just add the generic one */
162 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
165 static int nl80211_msg_put_channel(struct sk_buff *msg,
166 struct ieee80211_channel *chan)
168 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
171 if (chan->flags & IEEE80211_CHAN_DISABLED)
172 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
173 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
174 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
175 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
176 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
177 if (chan->flags & IEEE80211_CHAN_RADAR)
178 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
180 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
181 DBM_TO_MBM(chan->max_power));
189 /* netlink command implementations */
191 static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
192 struct cfg80211_registered_device *dev)
195 struct nlattr *nl_bands, *nl_band;
196 struct nlattr *nl_freqs, *nl_freq;
197 struct nlattr *nl_rates, *nl_rate;
198 struct nlattr *nl_modes;
199 struct nlattr *nl_cmds;
200 enum ieee80211_band band;
201 struct ieee80211_channel *chan;
202 struct ieee80211_rate *rate;
204 u16 ifmodes = dev->wiphy.interface_modes;
206 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
210 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
211 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
213 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
214 dev->wiphy.retry_short);
215 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
216 dev->wiphy.retry_long);
217 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
218 dev->wiphy.frag_threshold);
219 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
220 dev->wiphy.rts_threshold);
222 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
223 dev->wiphy.max_scan_ssids);
224 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
225 dev->wiphy.max_scan_ie_len);
227 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
228 sizeof(u32) * dev->wiphy.n_cipher_suites,
229 dev->wiphy.cipher_suites);
231 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
233 goto nla_put_failure;
238 NLA_PUT_FLAG(msg, i);
243 nla_nest_end(msg, nl_modes);
245 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
247 goto nla_put_failure;
249 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
250 if (!dev->wiphy.bands[band])
253 nl_band = nla_nest_start(msg, band);
255 goto nla_put_failure;
258 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
259 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
260 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
261 &dev->wiphy.bands[band]->ht_cap.mcs);
262 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
263 dev->wiphy.bands[band]->ht_cap.cap);
264 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
265 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
266 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
267 dev->wiphy.bands[band]->ht_cap.ampdu_density);
270 /* add frequencies */
271 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
273 goto nla_put_failure;
275 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
276 nl_freq = nla_nest_start(msg, i);
278 goto nla_put_failure;
280 chan = &dev->wiphy.bands[band]->channels[i];
282 if (nl80211_msg_put_channel(msg, chan))
283 goto nla_put_failure;
285 nla_nest_end(msg, nl_freq);
288 nla_nest_end(msg, nl_freqs);
291 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
293 goto nla_put_failure;
295 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
296 nl_rate = nla_nest_start(msg, i);
298 goto nla_put_failure;
300 rate = &dev->wiphy.bands[band]->bitrates[i];
301 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
303 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
305 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
307 nla_nest_end(msg, nl_rate);
310 nla_nest_end(msg, nl_rates);
312 nla_nest_end(msg, nl_band);
314 nla_nest_end(msg, nl_bands);
316 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
318 goto nla_put_failure;
323 if (dev->ops->op) { \
325 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
329 CMD(add_virtual_intf, NEW_INTERFACE);
330 CMD(change_virtual_intf, SET_INTERFACE);
331 CMD(add_key, NEW_KEY);
332 CMD(add_beacon, NEW_BEACON);
333 CMD(add_station, NEW_STATION);
334 CMD(add_mpath, NEW_MPATH);
335 CMD(set_mesh_params, SET_MESH_PARAMS);
336 CMD(change_bss, SET_BSS);
337 CMD(auth, AUTHENTICATE);
338 CMD(assoc, ASSOCIATE);
339 CMD(deauth, DEAUTHENTICATE);
340 CMD(disassoc, DISASSOCIATE);
341 CMD(join_ibss, JOIN_IBSS);
344 nla_nest_end(msg, nl_cmds);
346 return genlmsg_end(msg, hdr);
349 genlmsg_cancel(msg, hdr);
353 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
356 int start = cb->args[0];
357 struct cfg80211_registered_device *dev;
359 mutex_lock(&cfg80211_mutex);
360 list_for_each_entry(dev, &cfg80211_drv_list, list) {
363 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
364 cb->nlh->nlmsg_seq, NLM_F_MULTI,
370 mutex_unlock(&cfg80211_mutex);
377 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
380 struct cfg80211_registered_device *dev;
382 dev = cfg80211_get_dev_from_info(info);
386 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
390 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
393 cfg80211_put_dev(dev);
395 return genlmsg_unicast(msg, info->snd_pid);
400 cfg80211_put_dev(dev);
404 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
405 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
406 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
407 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
408 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
409 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
412 static int parse_txq_params(struct nlattr *tb[],
413 struct ieee80211_txq_params *txq_params)
415 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
416 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
417 !tb[NL80211_TXQ_ATTR_AIFS])
420 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
421 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
422 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
423 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
424 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
429 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
431 struct cfg80211_registered_device *rdev;
432 int result = 0, rem_txq_params = 0;
433 struct nlattr *nl_txq_params;
435 u8 retry_short = 0, retry_long = 0;
436 u32 frag_threshold = 0, rts_threshold = 0;
440 mutex_lock(&cfg80211_mutex);
442 rdev = __cfg80211_drv_from_info(info);
444 result = PTR_ERR(rdev);
448 mutex_lock(&rdev->mtx);
450 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
451 result = cfg80211_dev_rename(
452 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
454 mutex_unlock(&cfg80211_mutex);
459 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
460 struct ieee80211_txq_params txq_params;
461 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
463 if (!rdev->ops->set_txq_params) {
464 result = -EOPNOTSUPP;
468 nla_for_each_nested(nl_txq_params,
469 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
471 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
472 nla_data(nl_txq_params),
473 nla_len(nl_txq_params),
475 result = parse_txq_params(tb, &txq_params);
479 result = rdev->ops->set_txq_params(&rdev->wiphy,
486 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
487 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
488 struct ieee80211_channel *chan;
489 struct ieee80211_sta_ht_cap *ht_cap;
492 if (!rdev->ops->set_channel) {
493 result = -EOPNOTSUPP;
499 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
500 channel_type = nla_get_u32(info->attrs[
501 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
502 if (channel_type != NL80211_CHAN_NO_HT &&
503 channel_type != NL80211_CHAN_HT20 &&
504 channel_type != NL80211_CHAN_HT40PLUS &&
505 channel_type != NL80211_CHAN_HT40MINUS)
509 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
510 chan = ieee80211_get_channel(&rdev->wiphy, freq);
512 /* Primary channel not allowed */
513 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
516 if (channel_type == NL80211_CHAN_HT40MINUS)
517 sec_freq = freq - 20;
518 else if (channel_type == NL80211_CHAN_HT40PLUS)
519 sec_freq = freq + 20;
523 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
525 /* no HT capabilities */
526 if (channel_type != NL80211_CHAN_NO_HT &&
527 !ht_cap->ht_supported)
531 struct ieee80211_channel *schan;
533 /* no 40 MHz capabilities */
534 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
535 (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
538 schan = ieee80211_get_channel(&rdev->wiphy, sec_freq);
540 /* Secondary channel not allowed */
541 if (!schan || schan->flags & IEEE80211_CHAN_DISABLED)
545 result = rdev->ops->set_channel(&rdev->wiphy, chan,
553 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
554 retry_short = nla_get_u8(
555 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
556 if (retry_short == 0) {
560 changed |= WIPHY_PARAM_RETRY_SHORT;
563 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
564 retry_long = nla_get_u8(
565 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
566 if (retry_long == 0) {
570 changed |= WIPHY_PARAM_RETRY_LONG;
573 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
574 frag_threshold = nla_get_u32(
575 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
576 if (frag_threshold < 256) {
580 if (frag_threshold != (u32) -1) {
582 * Fragments (apart from the last one) are required to
583 * have even length. Make the fragmentation code
584 * simpler by stripping LSB should someone try to use
585 * odd threshold value.
587 frag_threshold &= ~0x1;
589 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
592 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
593 rts_threshold = nla_get_u32(
594 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
595 changed |= WIPHY_PARAM_RTS_THRESHOLD;
599 u8 old_retry_short, old_retry_long;
600 u32 old_frag_threshold, old_rts_threshold;
602 if (!rdev->ops->set_wiphy_params) {
603 result = -EOPNOTSUPP;
607 old_retry_short = rdev->wiphy.retry_short;
608 old_retry_long = rdev->wiphy.retry_long;
609 old_frag_threshold = rdev->wiphy.frag_threshold;
610 old_rts_threshold = rdev->wiphy.rts_threshold;
612 if (changed & WIPHY_PARAM_RETRY_SHORT)
613 rdev->wiphy.retry_short = retry_short;
614 if (changed & WIPHY_PARAM_RETRY_LONG)
615 rdev->wiphy.retry_long = retry_long;
616 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
617 rdev->wiphy.frag_threshold = frag_threshold;
618 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
619 rdev->wiphy.rts_threshold = rts_threshold;
621 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
623 rdev->wiphy.retry_short = old_retry_short;
624 rdev->wiphy.retry_long = old_retry_long;
625 rdev->wiphy.frag_threshold = old_frag_threshold;
626 rdev->wiphy.rts_threshold = old_rts_threshold;
631 mutex_unlock(&rdev->mtx);
638 static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
639 struct cfg80211_registered_device *rdev,
640 struct net_device *dev)
644 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
648 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
649 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
650 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
651 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
652 return genlmsg_end(msg, hdr);
655 genlmsg_cancel(msg, hdr);
659 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
663 int wp_start = cb->args[0];
664 int if_start = cb->args[1];
665 struct cfg80211_registered_device *dev;
666 struct wireless_dev *wdev;
668 mutex_lock(&cfg80211_mutex);
669 list_for_each_entry(dev, &cfg80211_drv_list, list) {
670 if (wp_idx < wp_start) {
676 mutex_lock(&dev->devlist_mtx);
677 list_for_each_entry(wdev, &dev->netdev_list, list) {
678 if (if_idx < if_start) {
682 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
683 cb->nlh->nlmsg_seq, NLM_F_MULTI,
684 dev, wdev->netdev) < 0) {
685 mutex_unlock(&dev->devlist_mtx);
690 mutex_unlock(&dev->devlist_mtx);
695 mutex_unlock(&cfg80211_mutex);
697 cb->args[0] = wp_idx;
698 cb->args[1] = if_idx;
703 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
706 struct cfg80211_registered_device *dev;
707 struct net_device *netdev;
710 err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev);
714 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
718 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
723 cfg80211_put_dev(dev);
725 return genlmsg_unicast(msg, info->snd_pid);
731 cfg80211_put_dev(dev);
735 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
736 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
737 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
738 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
739 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
740 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
743 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
745 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
753 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
754 nla, mntr_flags_policy))
757 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
759 *mntrflags |= (1<<flag);
764 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
766 struct cfg80211_registered_device *drv;
767 struct vif_params params;
769 enum nl80211_iftype otype, ntype;
770 struct net_device *dev;
771 u32 _flags, *flags = NULL;
774 memset(¶ms, 0, sizeof(params));
778 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
782 ifindex = dev->ifindex;
783 otype = ntype = dev->ieee80211_ptr->iftype;
786 if (info->attrs[NL80211_ATTR_IFTYPE]) {
787 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
790 if (ntype > NL80211_IFTYPE_MAX) {
796 if (!drv->ops->change_virtual_intf ||
797 !(drv->wiphy.interface_modes & (1 << ntype))) {
802 if (info->attrs[NL80211_ATTR_MESH_ID]) {
803 if (ntype != NL80211_IFTYPE_MESH_POINT) {
807 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
808 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
812 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
813 if (ntype != NL80211_IFTYPE_MONITOR) {
817 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
827 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex,
828 ntype, flags, ¶ms);
832 dev = __dev_get_by_index(&init_net, ifindex);
833 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != ntype));
835 if (dev && !err && (ntype != otype)) {
836 if (otype == NL80211_IFTYPE_ADHOC)
837 cfg80211_clear_ibss(dev, false);
841 cfg80211_put_dev(drv);
847 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
849 struct cfg80211_registered_device *drv;
850 struct vif_params params;
852 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
855 memset(¶ms, 0, sizeof(params));
857 if (!info->attrs[NL80211_ATTR_IFNAME])
860 if (info->attrs[NL80211_ATTR_IFTYPE]) {
861 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
862 if (type > NL80211_IFTYPE_MAX)
868 drv = cfg80211_get_dev_from_info(info);
874 if (!drv->ops->add_virtual_intf ||
875 !(drv->wiphy.interface_modes & (1 << type))) {
880 if (type == NL80211_IFTYPE_MESH_POINT &&
881 info->attrs[NL80211_ATTR_MESH_ID]) {
882 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
883 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
886 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
887 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
889 err = drv->ops->add_virtual_intf(&drv->wiphy,
890 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
891 type, err ? NULL : &flags, ¶ms);
894 cfg80211_put_dev(drv);
900 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
902 struct cfg80211_registered_device *drv;
904 struct net_device *dev;
908 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
911 ifindex = dev->ifindex;
914 if (!drv->ops->del_virtual_intf) {
919 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
922 cfg80211_put_dev(drv);
928 struct get_key_cookie {
933 static void get_key_callback(void *c, struct key_params *params)
935 struct get_key_cookie *cookie = c;
938 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
939 params->key_len, params->key);
942 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
943 params->seq_len, params->seq);
946 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
954 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
956 struct cfg80211_registered_device *drv;
958 struct net_device *dev;
961 struct get_key_cookie cookie = {
967 if (info->attrs[NL80211_ATTR_KEY_IDX])
968 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
973 if (info->attrs[NL80211_ATTR_MAC])
974 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
978 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
982 if (!drv->ops->get_key) {
987 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
993 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
994 NL80211_CMD_NEW_KEY);
1003 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1004 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1006 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1008 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr,
1009 &cookie, get_key_callback);
1015 goto nla_put_failure;
1017 genlmsg_end(msg, hdr);
1018 err = genlmsg_unicast(msg, info->snd_pid);
1025 cfg80211_put_dev(drv);
1033 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1035 struct cfg80211_registered_device *drv;
1037 struct net_device *dev;
1039 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
1042 if (!info->attrs[NL80211_ATTR_KEY_IDX])
1045 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1047 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) {
1048 if (key_idx < 4 || key_idx > 5)
1050 } else if (key_idx > 3)
1053 /* currently only support setting default key */
1054 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] &&
1055 !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT])
1060 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1064 if (info->attrs[NL80211_ATTR_KEY_DEFAULT])
1065 func = drv->ops->set_default_key;
1067 func = drv->ops->set_default_mgmt_key;
1074 err = func(&drv->wiphy, dev, key_idx);
1077 cfg80211_put_dev(drv);
1086 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1088 struct cfg80211_registered_device *drv;
1090 struct net_device *dev;
1091 struct key_params params;
1093 u8 *mac_addr = NULL;
1095 memset(¶ms, 0, sizeof(params));
1097 if (!info->attrs[NL80211_ATTR_KEY_CIPHER])
1100 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1101 params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1102 params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1105 if (info->attrs[NL80211_ATTR_KEY_IDX])
1106 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1108 params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1110 if (info->attrs[NL80211_ATTR_MAC])
1111 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1117 * Disallow pairwise keys with non-zero index unless it's WEP
1118 * (because current deployments use pairwise WEP keys with
1119 * non-zero indizes but 802.11i clearly specifies to use zero)
1121 if (mac_addr && key_idx &&
1122 params.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1123 params.cipher != WLAN_CIPHER_SUITE_WEP104)
1126 /* TODO: add definitions for the lengths to linux/ieee80211.h */
1127 switch (params.cipher) {
1128 case WLAN_CIPHER_SUITE_WEP40:
1129 if (params.key_len != 5)
1132 case WLAN_CIPHER_SUITE_TKIP:
1133 if (params.key_len != 32)
1136 case WLAN_CIPHER_SUITE_CCMP:
1137 if (params.key_len != 16)
1140 case WLAN_CIPHER_SUITE_WEP104:
1141 if (params.key_len != 13)
1144 case WLAN_CIPHER_SUITE_AES_CMAC:
1145 if (params.key_len != 16)
1154 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1158 for (i = 0; i < drv->wiphy.n_cipher_suites; i++)
1159 if (params.cipher == drv->wiphy.cipher_suites[i])
1161 if (i == drv->wiphy.n_cipher_suites) {
1166 if (!drv->ops->add_key) {
1171 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms);
1174 cfg80211_put_dev(drv);
1182 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1184 struct cfg80211_registered_device *drv;
1186 struct net_device *dev;
1188 u8 *mac_addr = NULL;
1190 if (info->attrs[NL80211_ATTR_KEY_IDX])
1191 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1196 if (info->attrs[NL80211_ATTR_MAC])
1197 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1201 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1205 if (!drv->ops->del_key) {
1210 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr);
1213 cfg80211_put_dev(drv);
1222 static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1224 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1225 struct beacon_parameters *info);
1226 struct cfg80211_registered_device *drv;
1228 struct net_device *dev;
1229 struct beacon_parameters params;
1232 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1237 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1241 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1246 switch (info->genlhdr->cmd) {
1247 case NL80211_CMD_NEW_BEACON:
1248 /* these are required for NEW_BEACON */
1249 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1250 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
1251 !info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1256 call = drv->ops->add_beacon;
1258 case NL80211_CMD_SET_BEACON:
1259 call = drv->ops->set_beacon;
1272 memset(¶ms, 0, sizeof(params));
1274 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1276 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1280 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
1281 params.dtim_period =
1282 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1286 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1287 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1289 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1293 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
1294 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1296 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1305 err = call(&drv->wiphy, dev, ¶ms);
1308 cfg80211_put_dev(drv);
1316 static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1318 struct cfg80211_registered_device *drv;
1320 struct net_device *dev;
1324 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1328 if (!drv->ops->del_beacon) {
1333 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1337 err = drv->ops->del_beacon(&drv->wiphy, dev);
1340 cfg80211_put_dev(drv);
1348 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1349 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
1350 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1351 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
1354 static int parse_station_flags(struct nlattr *nla, u32 *staflags)
1356 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
1364 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
1365 nla, sta_flags_policy))
1368 *staflags = STATION_FLAG_CHANGED;
1370 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
1372 *staflags |= (1<<flag);
1377 static u16 nl80211_calculate_bitrate(struct rate_info *rate)
1379 int modulation, streams, bitrate;
1381 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
1382 return rate->legacy;
1384 /* the formula below does only work for MCS values smaller than 32 */
1385 if (rate->mcs >= 32)
1388 modulation = rate->mcs & 7;
1389 streams = (rate->mcs >> 3) + 1;
1391 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1395 bitrate *= (modulation + 1);
1396 else if (modulation == 4)
1397 bitrate *= (modulation + 2);
1399 bitrate *= (modulation + 3);
1403 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1404 bitrate = (bitrate / 9) * 10;
1406 /* do NOT round down here */
1407 return (bitrate + 50000) / 100000;
1410 static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1411 int flags, struct net_device *dev,
1412 u8 *mac_addr, struct station_info *sinfo)
1415 struct nlattr *sinfoattr, *txrate;
1418 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1422 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1423 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1425 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1427 goto nla_put_failure;
1428 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1429 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1430 sinfo->inactive_time);
1431 if (sinfo->filled & STATION_INFO_RX_BYTES)
1432 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
1434 if (sinfo->filled & STATION_INFO_TX_BYTES)
1435 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
1437 if (sinfo->filled & STATION_INFO_LLID)
1438 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
1440 if (sinfo->filled & STATION_INFO_PLID)
1441 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
1443 if (sinfo->filled & STATION_INFO_PLINK_STATE)
1444 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
1445 sinfo->plink_state);
1446 if (sinfo->filled & STATION_INFO_SIGNAL)
1447 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1449 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1450 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1452 goto nla_put_failure;
1454 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1455 bitrate = nl80211_calculate_bitrate(&sinfo->txrate);
1457 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1459 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1460 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1462 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1463 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1464 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1465 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
1467 nla_nest_end(msg, txrate);
1469 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1470 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
1472 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1473 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1475 nla_nest_end(msg, sinfoattr);
1477 return genlmsg_end(msg, hdr);
1480 genlmsg_cancel(msg, hdr);
1484 static int nl80211_dump_station(struct sk_buff *skb,
1485 struct netlink_callback *cb)
1487 struct station_info sinfo;
1488 struct cfg80211_registered_device *dev;
1489 struct net_device *netdev;
1490 u8 mac_addr[ETH_ALEN];
1491 int ifidx = cb->args[0];
1492 int sta_idx = cb->args[1];
1496 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1497 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1502 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1505 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1512 netdev = __dev_get_by_index(&init_net, ifidx);
1518 dev = cfg80211_get_dev_from_ifindex(ifidx);
1524 if (!dev->ops->dump_station) {
1530 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
1537 if (nl80211_send_station(skb,
1538 NETLINK_CB(cb->skb).pid,
1539 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1549 cb->args[1] = sta_idx;
1552 cfg80211_put_dev(dev);
1559 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1561 struct cfg80211_registered_device *drv;
1563 struct net_device *dev;
1564 struct station_info sinfo;
1565 struct sk_buff *msg;
1566 u8 *mac_addr = NULL;
1568 memset(&sinfo, 0, sizeof(sinfo));
1570 if (!info->attrs[NL80211_ATTR_MAC])
1573 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1577 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1581 if (!drv->ops->get_station) {
1586 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo);
1590 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1594 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
1595 dev, mac_addr, &sinfo) < 0)
1598 err = genlmsg_unicast(msg, info->snd_pid);
1604 cfg80211_put_dev(drv);
1613 * Get vlan interface making sure it is on the right wiphy.
1615 static int get_vlan(struct nlattr *vlanattr,
1616 struct cfg80211_registered_device *rdev,
1617 struct net_device **vlan)
1622 *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr));
1625 if (!(*vlan)->ieee80211_ptr)
1627 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
1633 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1635 struct cfg80211_registered_device *drv;
1637 struct net_device *dev;
1638 struct station_parameters params;
1639 u8 *mac_addr = NULL;
1641 memset(¶ms, 0, sizeof(params));
1643 params.listen_interval = -1;
1645 if (info->attrs[NL80211_ATTR_STA_AID])
1648 if (!info->attrs[NL80211_ATTR_MAC])
1651 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1653 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
1654 params.supported_rates =
1655 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1656 params.supported_rates_len =
1657 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1660 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1661 params.listen_interval =
1662 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1664 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1666 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1668 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1669 ¶ms.station_flags))
1672 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
1673 params.plink_action =
1674 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
1678 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1682 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1686 if (!drv->ops->change_station) {
1691 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms);
1695 dev_put(params.vlan);
1696 cfg80211_put_dev(drv);
1704 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1706 struct cfg80211_registered_device *drv;
1708 struct net_device *dev;
1709 struct station_parameters params;
1710 u8 *mac_addr = NULL;
1712 memset(¶ms, 0, sizeof(params));
1714 if (!info->attrs[NL80211_ATTR_MAC])
1717 if (!info->attrs[NL80211_ATTR_STA_AID])
1720 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1723 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
1726 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1727 params.supported_rates =
1728 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1729 params.supported_rates_len =
1730 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1731 params.listen_interval =
1732 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1733 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
1734 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1736 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1738 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1739 ¶ms.station_flags))
1744 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1748 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1752 if (!drv->ops->add_station) {
1757 if (!netif_running(dev)) {
1762 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms);
1766 dev_put(params.vlan);
1767 cfg80211_put_dev(drv);
1775 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1777 struct cfg80211_registered_device *drv;
1779 struct net_device *dev;
1780 u8 *mac_addr = NULL;
1782 if (info->attrs[NL80211_ATTR_MAC])
1783 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1787 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1791 if (!drv->ops->del_station) {
1796 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr);
1799 cfg80211_put_dev(drv);
1807 static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
1808 int flags, struct net_device *dev,
1809 u8 *dst, u8 *next_hop,
1810 struct mpath_info *pinfo)
1813 struct nlattr *pinfoattr;
1815 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1819 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1820 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
1821 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
1823 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
1825 goto nla_put_failure;
1826 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
1827 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
1829 if (pinfo->filled & MPATH_INFO_DSN)
1830 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN,
1832 if (pinfo->filled & MPATH_INFO_METRIC)
1833 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
1835 if (pinfo->filled & MPATH_INFO_EXPTIME)
1836 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
1838 if (pinfo->filled & MPATH_INFO_FLAGS)
1839 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
1841 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
1842 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
1843 pinfo->discovery_timeout);
1844 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
1845 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
1846 pinfo->discovery_retries);
1848 nla_nest_end(msg, pinfoattr);
1850 return genlmsg_end(msg, hdr);
1853 genlmsg_cancel(msg, hdr);
1857 static int nl80211_dump_mpath(struct sk_buff *skb,
1858 struct netlink_callback *cb)
1860 struct mpath_info pinfo;
1861 struct cfg80211_registered_device *dev;
1862 struct net_device *netdev;
1864 u8 next_hop[ETH_ALEN];
1865 int ifidx = cb->args[0];
1866 int path_idx = cb->args[1];
1870 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1871 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1876 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1879 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1886 netdev = __dev_get_by_index(&init_net, ifidx);
1892 dev = cfg80211_get_dev_from_ifindex(ifidx);
1898 if (!dev->ops->dump_mpath) {
1903 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1909 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
1910 dst, next_hop, &pinfo);
1916 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
1917 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1918 netdev, dst, next_hop,
1927 cb->args[1] = path_idx;
1930 cfg80211_put_dev(dev);
1937 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
1939 struct cfg80211_registered_device *drv;
1941 struct net_device *dev;
1942 struct mpath_info pinfo;
1943 struct sk_buff *msg;
1945 u8 next_hop[ETH_ALEN];
1947 memset(&pinfo, 0, sizeof(pinfo));
1949 if (!info->attrs[NL80211_ATTR_MAC])
1952 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1956 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1960 if (!drv->ops->get_mpath) {
1965 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1970 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo);
1974 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1978 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
1979 dev, dst, next_hop, &pinfo) < 0)
1982 err = genlmsg_unicast(msg, info->snd_pid);
1988 cfg80211_put_dev(drv);
1996 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
1998 struct cfg80211_registered_device *drv;
2000 struct net_device *dev;
2002 u8 *next_hop = NULL;
2004 if (!info->attrs[NL80211_ATTR_MAC])
2007 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2010 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2011 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2015 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2019 if (!drv->ops->change_mpath) {
2024 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2029 if (!netif_running(dev)) {
2034 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop);
2037 cfg80211_put_dev(drv);
2044 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2046 struct cfg80211_registered_device *drv;
2048 struct net_device *dev;
2050 u8 *next_hop = NULL;
2052 if (!info->attrs[NL80211_ATTR_MAC])
2055 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2058 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2059 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2063 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2067 if (!drv->ops->add_mpath) {
2072 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2077 if (!netif_running(dev)) {
2082 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop);
2085 cfg80211_put_dev(drv);
2093 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2095 struct cfg80211_registered_device *drv;
2097 struct net_device *dev;
2100 if (info->attrs[NL80211_ATTR_MAC])
2101 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2105 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2109 if (!drv->ops->del_mpath) {
2114 err = drv->ops->del_mpath(&drv->wiphy, dev, dst);
2117 cfg80211_put_dev(drv);
2125 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2127 struct cfg80211_registered_device *drv;
2129 struct net_device *dev;
2130 struct bss_parameters params;
2132 memset(¶ms, 0, sizeof(params));
2133 /* default to not changing parameters */
2134 params.use_cts_prot = -1;
2135 params.use_short_preamble = -1;
2136 params.use_short_slot_time = -1;
2138 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2139 params.use_cts_prot =
2140 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2141 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2142 params.use_short_preamble =
2143 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2144 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2145 params.use_short_slot_time =
2146 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
2147 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2148 params.basic_rates =
2149 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2150 params.basic_rates_len =
2151 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2156 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2160 if (!drv->ops->change_bss) {
2165 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
2170 err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms);
2173 cfg80211_put_dev(drv);
2181 static const struct nla_policy
2182 reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
2183 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2184 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2185 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2186 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2187 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2188 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2191 static int parse_reg_rule(struct nlattr *tb[],
2192 struct ieee80211_reg_rule *reg_rule)
2194 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
2195 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
2197 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2199 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2201 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2203 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2205 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2208 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2210 freq_range->start_freq_khz =
2211 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2212 freq_range->end_freq_khz =
2213 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2214 freq_range->max_bandwidth_khz =
2215 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2217 power_rule->max_eirp =
2218 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2220 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2221 power_rule->max_antenna_gain =
2222 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2227 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2233 * You should only get this when cfg80211 hasn't yet initialized
2234 * completely when built-in to the kernel right between the time
2235 * window between nl80211_init() and regulatory_init(), if that is
2238 mutex_lock(&cfg80211_mutex);
2239 if (unlikely(!cfg80211_regdomain)) {
2240 mutex_unlock(&cfg80211_mutex);
2241 return -EINPROGRESS;
2243 mutex_unlock(&cfg80211_mutex);
2245 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2248 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2250 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2251 /* We ignore world regdom requests with the old regdom setup */
2252 if (is_world_regdom(data))
2256 r = regulatory_hint_user(data);
2261 static int nl80211_get_mesh_params(struct sk_buff *skb,
2262 struct genl_info *info)
2264 struct cfg80211_registered_device *drv;
2265 struct mesh_config cur_params;
2267 struct net_device *dev;
2269 struct nlattr *pinfoattr;
2270 struct sk_buff *msg;
2274 /* Look up our device */
2275 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2279 if (!drv->ops->get_mesh_params) {
2284 /* Get the mesh params */
2285 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params);
2289 /* Draw up a netlink message to send back */
2290 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2295 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2296 NL80211_CMD_GET_MESH_PARAMS);
2298 goto nla_put_failure;
2299 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS);
2301 goto nla_put_failure;
2302 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2303 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2304 cur_params.dot11MeshRetryTimeout);
2305 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2306 cur_params.dot11MeshConfirmTimeout);
2307 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2308 cur_params.dot11MeshHoldingTimeout);
2309 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2310 cur_params.dot11MeshMaxPeerLinks);
2311 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2312 cur_params.dot11MeshMaxRetries);
2313 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2314 cur_params.dot11MeshTTL);
2315 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2316 cur_params.auto_open_plinks);
2317 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2318 cur_params.dot11MeshHWMPmaxPREQretries);
2319 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2320 cur_params.path_refresh_time);
2321 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2322 cur_params.min_discovery_timeout);
2323 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2324 cur_params.dot11MeshHWMPactivePathTimeout);
2325 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2326 cur_params.dot11MeshHWMPpreqMinInterval);
2327 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2328 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
2329 nla_nest_end(msg, pinfoattr);
2330 genlmsg_end(msg, hdr);
2331 err = genlmsg_unicast(msg, info->snd_pid);
2335 genlmsg_cancel(msg, hdr);
2339 cfg80211_put_dev(drv);
2347 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2349 if (table[attr_num]) {\
2350 cfg.param = nla_fn(table[attr_num]); \
2351 mask |= (1 << (attr_num - 1)); \
2355 static struct nla_policy
2356 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = {
2357 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2358 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2359 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2360 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2361 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2362 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2363 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2365 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2366 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2367 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2368 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2369 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2370 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2373 static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2377 struct cfg80211_registered_device *drv;
2378 struct net_device *dev;
2379 struct mesh_config cfg;
2380 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2381 struct nlattr *parent_attr;
2383 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2386 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2387 parent_attr, nl80211_meshconf_params_policy))
2392 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2396 if (!drv->ops->set_mesh_params) {
2401 /* This makes sure that there aren't more than 32 mesh config
2402 * parameters (otherwise our bitfield scheme would not work.) */
2403 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2405 /* Fill in the params struct */
2407 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2408 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2409 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2410 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2411 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2412 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2413 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2414 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2415 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2416 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2417 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2418 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2419 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2420 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2421 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2422 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2424 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2425 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2426 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2427 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2429 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2430 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2432 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2433 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2436 dot11MeshHWMPnetDiameterTraversalTime,
2437 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2441 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask);
2445 cfg80211_put_dev(drv);
2453 #undef FILL_IN_MESH_PARAM_IF_SET
2455 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2457 struct sk_buff *msg;
2459 struct nlattr *nl_reg_rules;
2463 mutex_lock(&cfg80211_mutex);
2465 if (!cfg80211_regdomain)
2468 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2474 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2475 NL80211_CMD_GET_REG);
2477 goto nla_put_failure;
2479 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2480 cfg80211_regdomain->alpha2);
2482 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2484 goto nla_put_failure;
2486 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2487 struct nlattr *nl_reg_rule;
2488 const struct ieee80211_reg_rule *reg_rule;
2489 const struct ieee80211_freq_range *freq_range;
2490 const struct ieee80211_power_rule *power_rule;
2492 reg_rule = &cfg80211_regdomain->reg_rules[i];
2493 freq_range = ®_rule->freq_range;
2494 power_rule = ®_rule->power_rule;
2496 nl_reg_rule = nla_nest_start(msg, i);
2498 goto nla_put_failure;
2500 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2502 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2503 freq_range->start_freq_khz);
2504 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2505 freq_range->end_freq_khz);
2506 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2507 freq_range->max_bandwidth_khz);
2508 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2509 power_rule->max_antenna_gain);
2510 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2511 power_rule->max_eirp);
2513 nla_nest_end(msg, nl_reg_rule);
2516 nla_nest_end(msg, nl_reg_rules);
2518 genlmsg_end(msg, hdr);
2519 err = genlmsg_unicast(msg, info->snd_pid);
2523 genlmsg_cancel(msg, hdr);
2526 mutex_unlock(&cfg80211_mutex);
2530 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2532 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
2533 struct nlattr *nl_reg_rule;
2534 char *alpha2 = NULL;
2535 int rem_reg_rules = 0, r = 0;
2536 u32 num_rules = 0, rule_idx = 0, size_of_regd;
2537 struct ieee80211_regdomain *rd = NULL;
2539 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2542 if (!info->attrs[NL80211_ATTR_REG_RULES])
2545 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2547 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2550 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
2554 if (!reg_is_valid_request(alpha2))
2557 size_of_regd = sizeof(struct ieee80211_regdomain) +
2558 (num_rules * sizeof(struct ieee80211_reg_rule));
2560 rd = kzalloc(size_of_regd, GFP_KERNEL);
2564 rd->n_reg_rules = num_rules;
2565 rd->alpha2[0] = alpha2[0];
2566 rd->alpha2[1] = alpha2[1];
2568 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2570 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
2571 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
2573 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
2579 if (rule_idx > NL80211_MAX_SUPP_REG_RULES)
2583 BUG_ON(rule_idx != num_rules);
2585 mutex_lock(&cfg80211_mutex);
2587 mutex_unlock(&cfg80211_mutex);
2595 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2597 struct cfg80211_registered_device *drv;
2598 struct net_device *dev;
2599 struct cfg80211_scan_request *request;
2600 struct cfg80211_ssid *ssid;
2601 struct ieee80211_channel *channel;
2602 struct nlattr *attr;
2603 struct wiphy *wiphy;
2604 int err, tmp, n_ssids = 0, n_channels = 0, i;
2605 enum ieee80211_band band;
2608 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2613 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2617 wiphy = &drv->wiphy;
2619 if (!drv->ops->scan) {
2624 if (!netif_running(dev)) {
2629 if (drv->scan_req) {
2634 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2635 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp)
2642 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2643 if (wiphy->bands[band])
2644 n_channels += wiphy->bands[band]->n_channels;
2647 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2648 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2651 if (n_ssids > wiphy->max_scan_ssids) {
2656 if (info->attrs[NL80211_ATTR_IE])
2657 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2661 if (ie_len > wiphy->max_scan_ie_len) {
2666 request = kzalloc(sizeof(*request)
2667 + sizeof(*ssid) * n_ssids
2668 + sizeof(channel) * n_channels
2669 + ie_len, GFP_KERNEL);
2675 request->channels = (void *)((char *)request + sizeof(*request));
2676 request->n_channels = n_channels;
2678 request->ssids = (void *)(request->channels + n_channels);
2679 request->n_ssids = n_ssids;
2682 request->ie = (void *)(request->ssids + n_ssids);
2684 request->ie = (void *)(request->channels + n_channels);
2687 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2688 /* user specified, bail out if channel not found */
2689 request->n_channels = n_channels;
2691 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
2692 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2693 if (!request->channels[i]) {
2702 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2704 if (!wiphy->bands[band])
2706 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2707 request->channels[i] = &wiphy->bands[band]->channels[j];
2714 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2715 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2716 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2720 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
2721 request->ssids[i].ssid_len = nla_len(attr);
2726 if (info->attrs[NL80211_ATTR_IE]) {
2727 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2728 memcpy((void *)request->ie,
2729 nla_data(info->attrs[NL80211_ATTR_IE]),
2733 request->ifidx = dev->ifindex;
2734 request->wiphy = &drv->wiphy;
2736 drv->scan_req = request;
2737 err = drv->ops->scan(&drv->wiphy, dev, request);
2741 drv->scan_req = NULL;
2745 cfg80211_put_dev(drv);
2753 static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
2754 struct cfg80211_registered_device *rdev,
2755 struct net_device *dev,
2756 struct cfg80211_bss *res)
2761 hdr = nl80211hdr_put(msg, pid, seq, flags,
2762 NL80211_CMD_NEW_SCAN_RESULTS);
2766 NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION,
2767 rdev->bss_generation);
2768 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2770 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
2772 goto nla_put_failure;
2773 if (!is_zero_ether_addr(res->bssid))
2774 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
2775 if (res->information_elements && res->len_information_elements)
2776 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
2777 res->len_information_elements,
2778 res->information_elements);
2780 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
2781 if (res->beacon_interval)
2782 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
2783 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
2784 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
2786 switch (rdev->wiphy.signal_type) {
2787 case CFG80211_SIGNAL_TYPE_MBM:
2788 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
2790 case CFG80211_SIGNAL_TYPE_UNSPEC:
2791 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
2797 nla_nest_end(msg, bss);
2799 return genlmsg_end(msg, hdr);
2802 genlmsg_cancel(msg, hdr);
2806 static int nl80211_dump_scan(struct sk_buff *skb,
2807 struct netlink_callback *cb)
2809 struct cfg80211_registered_device *dev;
2810 struct net_device *netdev;
2811 struct cfg80211_internal_bss *scan;
2812 int ifidx = cb->args[0];
2813 int start = cb->args[1], idx = 0;
2817 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
2818 nl80211_fam.attrbuf, nl80211_fam.maxattr,
2823 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2826 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2829 cb->args[0] = ifidx;
2832 netdev = dev_get_by_index(&init_net, ifidx);
2836 dev = cfg80211_get_dev_from_ifindex(ifidx);
2839 goto out_put_netdev;
2842 spin_lock_bh(&dev->bss_lock);
2843 cfg80211_bss_expire(dev);
2845 list_for_each_entry(scan, &dev->bss_list, list) {
2848 if (nl80211_send_bss(skb,
2849 NETLINK_CB(cb->skb).pid,
2850 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2851 dev, netdev, &scan->pub) < 0) {
2858 spin_unlock_bh(&dev->bss_lock);
2862 cfg80211_put_dev(dev);
2869 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
2871 return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM ||
2872 auth_type == NL80211_AUTHTYPE_SHARED_KEY ||
2873 auth_type == NL80211_AUTHTYPE_FT ||
2874 auth_type == NL80211_AUTHTYPE_NETWORK_EAP;
2877 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2879 struct cfg80211_registered_device *drv;
2880 struct net_device *dev;
2881 struct cfg80211_auth_request req;
2882 struct wiphy *wiphy;
2885 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2888 if (!info->attrs[NL80211_ATTR_MAC])
2891 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
2896 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2900 if (!drv->ops->auth) {
2905 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2910 if (!netif_running(dev)) {
2915 wiphy = &drv->wiphy;
2916 memset(&req, 0, sizeof(req));
2918 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2920 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2921 req.chan = ieee80211_get_channel(
2923 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2930 if (info->attrs[NL80211_ATTR_SSID]) {
2931 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2932 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2935 if (info->attrs[NL80211_ATTR_IE]) {
2936 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2937 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2940 req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
2941 if (!nl80211_valid_auth_type(req.auth_type)) {
2946 err = drv->ops->auth(&drv->wiphy, dev, &req);
2949 cfg80211_put_dev(drv);
2956 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2958 struct cfg80211_registered_device *drv;
2959 struct net_device *dev;
2960 struct cfg80211_assoc_request req;
2961 struct wiphy *wiphy;
2964 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2967 if (!info->attrs[NL80211_ATTR_MAC] ||
2968 !info->attrs[NL80211_ATTR_SSID])
2973 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2977 if (!drv->ops->assoc) {
2982 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2987 if (!netif_running(dev)) {
2992 wiphy = &drv->wiphy;
2993 memset(&req, 0, sizeof(req));
2995 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2997 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2998 req.chan = ieee80211_get_channel(
3000 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3007 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3008 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3010 if (info->attrs[NL80211_ATTR_IE]) {
3011 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3012 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3015 err = drv->ops->assoc(&drv->wiphy, dev, &req);
3018 cfg80211_put_dev(drv);
3025 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3027 struct cfg80211_registered_device *drv;
3028 struct net_device *dev;
3029 struct cfg80211_deauth_request req;
3030 struct wiphy *wiphy;
3033 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3036 if (!info->attrs[NL80211_ATTR_MAC])
3039 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3044 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3048 if (!drv->ops->deauth) {
3053 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3058 if (!netif_running(dev)) {
3063 wiphy = &drv->wiphy;
3064 memset(&req, 0, sizeof(req));
3066 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3068 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3069 if (req.reason_code == 0) {
3070 /* Reason Code 0 is reserved */
3075 if (info->attrs[NL80211_ATTR_IE]) {
3076 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3077 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3080 err = drv->ops->deauth(&drv->wiphy, dev, &req);
3083 cfg80211_put_dev(drv);
3090 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3092 struct cfg80211_registered_device *drv;
3093 struct net_device *dev;
3094 struct cfg80211_disassoc_request req;
3095 struct wiphy *wiphy;
3098 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3101 if (!info->attrs[NL80211_ATTR_MAC])
3104 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3109 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3113 if (!drv->ops->disassoc) {
3118 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3123 if (!netif_running(dev)) {
3128 wiphy = &drv->wiphy;
3129 memset(&req, 0, sizeof(req));
3131 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3133 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3134 if (req.reason_code == 0) {
3135 /* Reason Code 0 is reserved */
3140 if (info->attrs[NL80211_ATTR_IE]) {
3141 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3142 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3145 err = drv->ops->disassoc(&drv->wiphy, dev, &req);
3148 cfg80211_put_dev(drv);
3155 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3157 struct cfg80211_registered_device *drv;
3158 struct net_device *dev;
3159 struct cfg80211_ibss_params ibss;
3160 struct wiphy *wiphy;
3163 memset(&ibss, 0, sizeof(ibss));
3165 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3168 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
3169 !info->attrs[NL80211_ATTR_SSID] ||
3170 !nla_len(info->attrs[NL80211_ATTR_SSID]))
3173 ibss.beacon_interval = 100;
3175 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
3176 ibss.beacon_interval =
3177 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3178 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
3184 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3188 if (!drv->ops->join_ibss) {
3193 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) {
3198 if (!netif_running(dev)) {
3203 wiphy = &drv->wiphy;
3205 if (info->attrs[NL80211_ATTR_MAC])
3206 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3207 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3208 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3210 if (info->attrs[NL80211_ATTR_IE]) {
3211 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3212 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3215 ibss.channel = ieee80211_get_channel(wiphy,
3216 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3217 if (!ibss.channel ||
3218 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
3219 ibss.channel->flags & IEEE80211_CHAN_DISABLED) {
3224 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
3226 err = cfg80211_join_ibss(drv, dev, &ibss);
3229 cfg80211_put_dev(drv);
3236 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
3238 struct cfg80211_registered_device *drv;
3239 struct net_device *dev;
3244 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3248 if (!drv->ops->leave_ibss) {
3253 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) {
3258 if (!netif_running(dev)) {
3263 err = cfg80211_leave_ibss(drv, dev, false);
3266 cfg80211_put_dev(drv);
3273 static struct genl_ops nl80211_ops[] = {
3275 .cmd = NL80211_CMD_GET_WIPHY,
3276 .doit = nl80211_get_wiphy,
3277 .dumpit = nl80211_dump_wiphy,
3278 .policy = nl80211_policy,
3279 /* can be retrieved by unprivileged users */
3282 .cmd = NL80211_CMD_SET_WIPHY,
3283 .doit = nl80211_set_wiphy,
3284 .policy = nl80211_policy,
3285 .flags = GENL_ADMIN_PERM,
3288 .cmd = NL80211_CMD_GET_INTERFACE,
3289 .doit = nl80211_get_interface,
3290 .dumpit = nl80211_dump_interface,
3291 .policy = nl80211_policy,
3292 /* can be retrieved by unprivileged users */
3295 .cmd = NL80211_CMD_SET_INTERFACE,
3296 .doit = nl80211_set_interface,
3297 .policy = nl80211_policy,
3298 .flags = GENL_ADMIN_PERM,
3301 .cmd = NL80211_CMD_NEW_INTERFACE,
3302 .doit = nl80211_new_interface,
3303 .policy = nl80211_policy,
3304 .flags = GENL_ADMIN_PERM,
3307 .cmd = NL80211_CMD_DEL_INTERFACE,
3308 .doit = nl80211_del_interface,
3309 .policy = nl80211_policy,
3310 .flags = GENL_ADMIN_PERM,
3313 .cmd = NL80211_CMD_GET_KEY,
3314 .doit = nl80211_get_key,
3315 .policy = nl80211_policy,
3316 .flags = GENL_ADMIN_PERM,
3319 .cmd = NL80211_CMD_SET_KEY,
3320 .doit = nl80211_set_key,
3321 .policy = nl80211_policy,
3322 .flags = GENL_ADMIN_PERM,
3325 .cmd = NL80211_CMD_NEW_KEY,
3326 .doit = nl80211_new_key,
3327 .policy = nl80211_policy,
3328 .flags = GENL_ADMIN_PERM,
3331 .cmd = NL80211_CMD_DEL_KEY,
3332 .doit = nl80211_del_key,
3333 .policy = nl80211_policy,
3334 .flags = GENL_ADMIN_PERM,
3337 .cmd = NL80211_CMD_SET_BEACON,
3338 .policy = nl80211_policy,
3339 .flags = GENL_ADMIN_PERM,
3340 .doit = nl80211_addset_beacon,
3343 .cmd = NL80211_CMD_NEW_BEACON,
3344 .policy = nl80211_policy,
3345 .flags = GENL_ADMIN_PERM,
3346 .doit = nl80211_addset_beacon,
3349 .cmd = NL80211_CMD_DEL_BEACON,
3350 .policy = nl80211_policy,
3351 .flags = GENL_ADMIN_PERM,
3352 .doit = nl80211_del_beacon,
3355 .cmd = NL80211_CMD_GET_STATION,
3356 .doit = nl80211_get_station,
3357 .dumpit = nl80211_dump_station,
3358 .policy = nl80211_policy,
3361 .cmd = NL80211_CMD_SET_STATION,
3362 .doit = nl80211_set_station,
3363 .policy = nl80211_policy,
3364 .flags = GENL_ADMIN_PERM,
3367 .cmd = NL80211_CMD_NEW_STATION,
3368 .doit = nl80211_new_station,
3369 .policy = nl80211_policy,
3370 .flags = GENL_ADMIN_PERM,
3373 .cmd = NL80211_CMD_DEL_STATION,
3374 .doit = nl80211_del_station,
3375 .policy = nl80211_policy,
3376 .flags = GENL_ADMIN_PERM,
3379 .cmd = NL80211_CMD_GET_MPATH,
3380 .doit = nl80211_get_mpath,
3381 .dumpit = nl80211_dump_mpath,
3382 .policy = nl80211_policy,
3383 .flags = GENL_ADMIN_PERM,
3386 .cmd = NL80211_CMD_SET_MPATH,
3387 .doit = nl80211_set_mpath,
3388 .policy = nl80211_policy,
3389 .flags = GENL_ADMIN_PERM,
3392 .cmd = NL80211_CMD_NEW_MPATH,
3393 .doit = nl80211_new_mpath,
3394 .policy = nl80211_policy,
3395 .flags = GENL_ADMIN_PERM,
3398 .cmd = NL80211_CMD_DEL_MPATH,
3399 .doit = nl80211_del_mpath,
3400 .policy = nl80211_policy,
3401 .flags = GENL_ADMIN_PERM,
3404 .cmd = NL80211_CMD_SET_BSS,
3405 .doit = nl80211_set_bss,
3406 .policy = nl80211_policy,
3407 .flags = GENL_ADMIN_PERM,
3410 .cmd = NL80211_CMD_GET_REG,
3411 .doit = nl80211_get_reg,
3412 .policy = nl80211_policy,
3413 /* can be retrieved by unprivileged users */
3416 .cmd = NL80211_CMD_SET_REG,
3417 .doit = nl80211_set_reg,
3418 .policy = nl80211_policy,
3419 .flags = GENL_ADMIN_PERM,
3422 .cmd = NL80211_CMD_REQ_SET_REG,
3423 .doit = nl80211_req_set_reg,
3424 .policy = nl80211_policy,
3425 .flags = GENL_ADMIN_PERM,
3428 .cmd = NL80211_CMD_GET_MESH_PARAMS,
3429 .doit = nl80211_get_mesh_params,
3430 .policy = nl80211_policy,
3431 /* can be retrieved by unprivileged users */
3434 .cmd = NL80211_CMD_SET_MESH_PARAMS,
3435 .doit = nl80211_set_mesh_params,
3436 .policy = nl80211_policy,
3437 .flags = GENL_ADMIN_PERM,
3440 .cmd = NL80211_CMD_TRIGGER_SCAN,
3441 .doit = nl80211_trigger_scan,
3442 .policy = nl80211_policy,
3443 .flags = GENL_ADMIN_PERM,
3446 .cmd = NL80211_CMD_GET_SCAN,
3447 .policy = nl80211_policy,
3448 .dumpit = nl80211_dump_scan,
3451 .cmd = NL80211_CMD_AUTHENTICATE,
3452 .doit = nl80211_authenticate,
3453 .policy = nl80211_policy,
3454 .flags = GENL_ADMIN_PERM,
3457 .cmd = NL80211_CMD_ASSOCIATE,
3458 .doit = nl80211_associate,
3459 .policy = nl80211_policy,
3460 .flags = GENL_ADMIN_PERM,
3463 .cmd = NL80211_CMD_DEAUTHENTICATE,
3464 .doit = nl80211_deauthenticate,
3465 .policy = nl80211_policy,
3466 .flags = GENL_ADMIN_PERM,
3469 .cmd = NL80211_CMD_DISASSOCIATE,
3470 .doit = nl80211_disassociate,
3471 .policy = nl80211_policy,
3472 .flags = GENL_ADMIN_PERM,
3475 .cmd = NL80211_CMD_JOIN_IBSS,
3476 .doit = nl80211_join_ibss,
3477 .policy = nl80211_policy,
3478 .flags = GENL_ADMIN_PERM,
3481 .cmd = NL80211_CMD_LEAVE_IBSS,
3482 .doit = nl80211_leave_ibss,
3483 .policy = nl80211_policy,
3484 .flags = GENL_ADMIN_PERM,
3487 static struct genl_multicast_group nl80211_mlme_mcgrp = {
3491 /* multicast groups */
3492 static struct genl_multicast_group nl80211_config_mcgrp = {
3495 static struct genl_multicast_group nl80211_scan_mcgrp = {
3498 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
3499 .name = "regulatory",
3502 /* notification functions */
3504 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
3506 struct sk_buff *msg;
3508 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3512 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
3517 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
3520 static int nl80211_send_scan_donemsg(struct sk_buff *msg,
3521 struct cfg80211_registered_device *rdev,
3522 struct net_device *netdev,
3523 u32 pid, u32 seq, int flags,
3528 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
3532 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3533 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3535 /* XXX: we should probably bounce back the request? */
3537 return genlmsg_end(msg, hdr);
3540 genlmsg_cancel(msg, hdr);
3544 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3545 struct net_device *netdev)
3547 struct sk_buff *msg;
3549 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3553 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3554 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
3559 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3562 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
3563 struct net_device *netdev)
3565 struct sk_buff *msg;
3567 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3571 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3572 NL80211_CMD_SCAN_ABORTED) < 0) {
3577 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3581 * This can happen on global regulatory changes or device specific settings
3582 * based on custom world regulatory domains.
3584 void nl80211_send_reg_change_event(struct regulatory_request *request)
3586 struct sk_buff *msg;
3589 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3593 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
3599 /* Userspace can always count this one always being set */
3600 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
3602 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
3603 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3604 NL80211_REGDOM_TYPE_WORLD);
3605 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
3606 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3607 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
3608 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
3610 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3611 NL80211_REGDOM_TYPE_INTERSECTION);
3613 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3614 NL80211_REGDOM_TYPE_COUNTRY);
3615 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
3618 if (wiphy_idx_valid(request->wiphy_idx))
3619 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
3621 if (genlmsg_end(msg, hdr) < 0) {
3626 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL);
3631 genlmsg_cancel(msg, hdr);
3635 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3636 struct net_device *netdev,
3637 const u8 *buf, size_t len,
3638 enum nl80211_commands cmd)
3640 struct sk_buff *msg;
3643 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
3647 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3653 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3654 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3655 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
3657 if (genlmsg_end(msg, hdr) < 0) {
3662 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC);
3666 genlmsg_cancel(msg, hdr);
3670 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3671 struct net_device *netdev, const u8 *buf, size_t len)
3673 nl80211_send_mlme_event(rdev, netdev, buf, len,
3674 NL80211_CMD_AUTHENTICATE);
3677 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3678 struct net_device *netdev, const u8 *buf,
3681 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3684 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
3685 struct net_device *netdev, const u8 *buf, size_t len)
3687 nl80211_send_mlme_event(rdev, netdev, buf, len,
3688 NL80211_CMD_DEAUTHENTICATE);
3691 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
3692 struct net_device *netdev, const u8 *buf,
3695 nl80211_send_mlme_event(rdev, netdev, buf, len,
3696 NL80211_CMD_DISASSOCIATE);
3699 void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
3700 struct net_device *netdev, int cmd,
3703 struct sk_buff *msg;
3706 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
3710 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3716 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3717 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3718 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
3719 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
3721 if (genlmsg_end(msg, hdr) < 0) {
3726 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC);
3730 genlmsg_cancel(msg, hdr);
3734 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
3735 struct net_device *netdev, const u8 *addr)
3737 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
3741 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
3742 struct net_device *netdev, const u8 *addr)
3744 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, addr);
3747 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
3748 struct net_device *netdev, const u8 *bssid,
3751 struct sk_buff *msg;
3754 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
3758 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
3764 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3765 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3766 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
3768 if (genlmsg_end(msg, hdr) < 0) {
3773 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
3777 genlmsg_cancel(msg, hdr);
3781 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
3782 struct net_device *netdev, const u8 *addr,
3783 enum nl80211_key_type key_type, int key_id,
3786 struct sk_buff *msg;
3789 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3793 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
3799 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3800 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3802 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
3803 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
3804 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
3806 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
3808 if (genlmsg_end(msg, hdr) < 0) {
3813 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3817 genlmsg_cancel(msg, hdr);
3821 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
3822 struct ieee80211_channel *channel_before,
3823 struct ieee80211_channel *channel_after)
3825 struct sk_buff *msg;
3827 struct nlattr *nl_freq;
3829 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
3833 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
3840 * Since we are applying the beacon hint to a wiphy we know its
3841 * wiphy_idx is valid
3843 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
3846 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
3848 goto nla_put_failure;
3849 if (nl80211_msg_put_channel(msg, channel_before))
3850 goto nla_put_failure;
3851 nla_nest_end(msg, nl_freq);
3854 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
3856 goto nla_put_failure;
3857 if (nl80211_msg_put_channel(msg, channel_after))
3858 goto nla_put_failure;
3859 nla_nest_end(msg, nl_freq);
3861 if (genlmsg_end(msg, hdr) < 0) {
3866 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_ATOMIC);
3871 genlmsg_cancel(msg, hdr);
3875 /* initialisation/exit functions */
3877 int nl80211_init(void)
3881 err = genl_register_family(&nl80211_fam);
3885 for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) {
3886 err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]);
3891 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
3895 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
3899 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
3903 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
3909 genl_unregister_family(&nl80211_fam);
3913 void nl80211_exit(void)
3915 genl_unregister_family(&nl80211_fam);