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 },
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 },
122 static bool is_valid_ie_attr(const struct nlattr *attr)
130 pos = nla_data(attr);
151 /* message building helper */
152 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
155 /* since there is no private header just add the generic one */
156 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
159 /* netlink command implementations */
161 static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
162 struct cfg80211_registered_device *dev)
165 struct nlattr *nl_bands, *nl_band;
166 struct nlattr *nl_freqs, *nl_freq;
167 struct nlattr *nl_rates, *nl_rate;
168 struct nlattr *nl_modes;
169 struct nlattr *nl_cmds;
170 enum ieee80211_band band;
171 struct ieee80211_channel *chan;
172 struct ieee80211_rate *rate;
174 u16 ifmodes = dev->wiphy.interface_modes;
176 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
180 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
181 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
182 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
183 dev->wiphy.max_scan_ssids);
184 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
185 dev->wiphy.max_scan_ie_len);
187 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
189 goto nla_put_failure;
194 NLA_PUT_FLAG(msg, i);
199 nla_nest_end(msg, nl_modes);
201 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
203 goto nla_put_failure;
205 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
206 if (!dev->wiphy.bands[band])
209 nl_band = nla_nest_start(msg, band);
211 goto nla_put_failure;
214 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
215 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
216 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
217 &dev->wiphy.bands[band]->ht_cap.mcs);
218 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
219 dev->wiphy.bands[band]->ht_cap.cap);
220 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
221 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
222 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
223 dev->wiphy.bands[band]->ht_cap.ampdu_density);
226 /* add frequencies */
227 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
229 goto nla_put_failure;
231 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
232 nl_freq = nla_nest_start(msg, i);
234 goto nla_put_failure;
236 chan = &dev->wiphy.bands[band]->channels[i];
237 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
240 if (chan->flags & IEEE80211_CHAN_DISABLED)
241 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
242 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
243 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
244 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
245 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
246 if (chan->flags & IEEE80211_CHAN_RADAR)
247 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
249 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
250 DBM_TO_MBM(chan->max_power));
252 nla_nest_end(msg, nl_freq);
255 nla_nest_end(msg, nl_freqs);
258 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
260 goto nla_put_failure;
262 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
263 nl_rate = nla_nest_start(msg, i);
265 goto nla_put_failure;
267 rate = &dev->wiphy.bands[band]->bitrates[i];
268 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
270 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
272 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
274 nla_nest_end(msg, nl_rate);
277 nla_nest_end(msg, nl_rates);
279 nla_nest_end(msg, nl_band);
281 nla_nest_end(msg, nl_bands);
283 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
285 goto nla_put_failure;
290 if (dev->ops->op) { \
292 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
296 CMD(add_virtual_intf, NEW_INTERFACE);
297 CMD(change_virtual_intf, SET_INTERFACE);
298 CMD(add_key, NEW_KEY);
299 CMD(add_beacon, NEW_BEACON);
300 CMD(add_station, NEW_STATION);
301 CMD(add_mpath, NEW_MPATH);
302 CMD(set_mesh_params, SET_MESH_PARAMS);
303 CMD(change_bss, SET_BSS);
304 CMD(auth, AUTHENTICATE);
305 CMD(assoc, ASSOCIATE);
306 CMD(deauth, DEAUTHENTICATE);
307 CMD(disassoc, DISASSOCIATE);
310 nla_nest_end(msg, nl_cmds);
312 return genlmsg_end(msg, hdr);
315 genlmsg_cancel(msg, hdr);
319 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
322 int start = cb->args[0];
323 struct cfg80211_registered_device *dev;
325 mutex_lock(&cfg80211_mutex);
326 list_for_each_entry(dev, &cfg80211_drv_list, list) {
329 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
330 cb->nlh->nlmsg_seq, NLM_F_MULTI,
336 mutex_unlock(&cfg80211_mutex);
343 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
346 struct cfg80211_registered_device *dev;
348 dev = cfg80211_get_dev_from_info(info);
352 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
356 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
359 cfg80211_put_dev(dev);
361 return genlmsg_unicast(msg, info->snd_pid);
366 cfg80211_put_dev(dev);
370 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
371 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
372 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
373 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
374 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
375 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
378 static int parse_txq_params(struct nlattr *tb[],
379 struct ieee80211_txq_params *txq_params)
381 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
382 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
383 !tb[NL80211_TXQ_ATTR_AIFS])
386 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
387 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
388 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
389 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
390 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
395 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
397 struct cfg80211_registered_device *rdev;
398 int result = 0, rem_txq_params = 0;
399 struct nlattr *nl_txq_params;
403 mutex_lock(&cfg80211_mutex);
405 rdev = __cfg80211_drv_from_info(info);
407 result = PTR_ERR(rdev);
411 mutex_lock(&rdev->mtx);
413 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
414 result = cfg80211_dev_rename(
415 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
417 mutex_unlock(&cfg80211_mutex);
422 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
423 struct ieee80211_txq_params txq_params;
424 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
426 if (!rdev->ops->set_txq_params) {
427 result = -EOPNOTSUPP;
431 nla_for_each_nested(nl_txq_params,
432 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
434 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
435 nla_data(nl_txq_params),
436 nla_len(nl_txq_params),
438 result = parse_txq_params(tb, &txq_params);
442 result = rdev->ops->set_txq_params(&rdev->wiphy,
449 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
450 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
451 struct ieee80211_channel *chan;
452 struct ieee80211_sta_ht_cap *ht_cap;
455 if (!rdev->ops->set_channel) {
456 result = -EOPNOTSUPP;
462 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
463 channel_type = nla_get_u32(info->attrs[
464 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
465 if (channel_type != NL80211_CHAN_NO_HT &&
466 channel_type != NL80211_CHAN_HT20 &&
467 channel_type != NL80211_CHAN_HT40PLUS &&
468 channel_type != NL80211_CHAN_HT40MINUS)
472 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
473 chan = ieee80211_get_channel(&rdev->wiphy, freq);
475 /* Primary channel not allowed */
476 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
479 if (channel_type == NL80211_CHAN_HT40MINUS)
480 sec_freq = freq - 20;
481 else if (channel_type == NL80211_CHAN_HT40PLUS)
482 sec_freq = freq + 20;
486 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
488 /* no HT capabilities */
489 if (channel_type != NL80211_CHAN_NO_HT &&
490 !ht_cap->ht_supported)
494 struct ieee80211_channel *schan;
496 /* no 40 MHz capabilities */
497 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
498 (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
501 schan = ieee80211_get_channel(&rdev->wiphy, sec_freq);
503 /* Secondary channel not allowed */
504 if (!schan || schan->flags & IEEE80211_CHAN_DISABLED)
508 result = rdev->ops->set_channel(&rdev->wiphy, chan,
516 mutex_unlock(&rdev->mtx);
523 static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
524 struct net_device *dev)
528 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
532 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
533 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
534 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
535 return genlmsg_end(msg, hdr);
538 genlmsg_cancel(msg, hdr);
542 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
546 int wp_start = cb->args[0];
547 int if_start = cb->args[1];
548 struct cfg80211_registered_device *dev;
549 struct wireless_dev *wdev;
551 mutex_lock(&cfg80211_mutex);
552 list_for_each_entry(dev, &cfg80211_drv_list, list) {
553 if (wp_idx < wp_start) {
559 mutex_lock(&dev->devlist_mtx);
560 list_for_each_entry(wdev, &dev->netdev_list, list) {
561 if (if_idx < if_start) {
565 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
566 cb->nlh->nlmsg_seq, NLM_F_MULTI,
568 mutex_unlock(&dev->devlist_mtx);
573 mutex_unlock(&dev->devlist_mtx);
578 mutex_unlock(&cfg80211_mutex);
580 cb->args[0] = wp_idx;
581 cb->args[1] = if_idx;
586 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
589 struct cfg80211_registered_device *dev;
590 struct net_device *netdev;
593 err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev);
597 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
601 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0)
605 cfg80211_put_dev(dev);
607 return genlmsg_unicast(msg, info->snd_pid);
613 cfg80211_put_dev(dev);
617 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
618 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
619 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
620 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
621 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
622 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
625 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
627 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
635 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
636 nla, mntr_flags_policy))
639 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
641 *mntrflags |= (1<<flag);
646 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
648 struct cfg80211_registered_device *drv;
649 struct vif_params params;
651 enum nl80211_iftype type;
652 struct net_device *dev;
653 u32 _flags, *flags = NULL;
656 memset(¶ms, 0, sizeof(params));
660 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
664 ifindex = dev->ifindex;
665 type = dev->ieee80211_ptr->iftype;
668 if (info->attrs[NL80211_ATTR_IFTYPE]) {
669 enum nl80211_iftype ntype;
671 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
675 if (type > NL80211_IFTYPE_MAX) {
681 if (!drv->ops->change_virtual_intf ||
682 !(drv->wiphy.interface_modes & (1 << type))) {
687 if (info->attrs[NL80211_ATTR_MESH_ID]) {
688 if (type != NL80211_IFTYPE_MESH_POINT) {
692 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
693 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
697 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
698 if (type != NL80211_IFTYPE_MONITOR) {
702 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
712 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex,
713 type, flags, ¶ms);
717 dev = __dev_get_by_index(&init_net, ifindex);
718 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type));
721 cfg80211_put_dev(drv);
727 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
729 struct cfg80211_registered_device *drv;
730 struct vif_params params;
732 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
735 memset(¶ms, 0, sizeof(params));
737 if (!info->attrs[NL80211_ATTR_IFNAME])
740 if (info->attrs[NL80211_ATTR_IFTYPE]) {
741 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
742 if (type > NL80211_IFTYPE_MAX)
748 drv = cfg80211_get_dev_from_info(info);
754 if (!drv->ops->add_virtual_intf ||
755 !(drv->wiphy.interface_modes & (1 << type))) {
760 if (type == NL80211_IFTYPE_MESH_POINT &&
761 info->attrs[NL80211_ATTR_MESH_ID]) {
762 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
763 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
766 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
767 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
769 err = drv->ops->add_virtual_intf(&drv->wiphy,
770 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
771 type, err ? NULL : &flags, ¶ms);
774 cfg80211_put_dev(drv);
780 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
782 struct cfg80211_registered_device *drv;
784 struct net_device *dev;
788 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
791 ifindex = dev->ifindex;
794 if (!drv->ops->del_virtual_intf) {
799 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
802 cfg80211_put_dev(drv);
808 struct get_key_cookie {
813 static void get_key_callback(void *c, struct key_params *params)
815 struct get_key_cookie *cookie = c;
818 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
819 params->key_len, params->key);
822 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
823 params->seq_len, params->seq);
826 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
834 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
836 struct cfg80211_registered_device *drv;
838 struct net_device *dev;
841 struct get_key_cookie cookie = {
847 if (info->attrs[NL80211_ATTR_KEY_IDX])
848 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
853 if (info->attrs[NL80211_ATTR_MAC])
854 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
858 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
862 if (!drv->ops->get_key) {
867 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
873 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
874 NL80211_CMD_NEW_KEY);
883 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
884 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
886 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
888 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr,
889 &cookie, get_key_callback);
895 goto nla_put_failure;
897 genlmsg_end(msg, hdr);
898 err = genlmsg_unicast(msg, info->snd_pid);
905 cfg80211_put_dev(drv);
913 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
915 struct cfg80211_registered_device *drv;
917 struct net_device *dev;
919 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
922 if (!info->attrs[NL80211_ATTR_KEY_IDX])
925 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
927 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) {
928 if (key_idx < 4 || key_idx > 5)
930 } else if (key_idx > 3)
933 /* currently only support setting default key */
934 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] &&
935 !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT])
940 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
944 if (info->attrs[NL80211_ATTR_KEY_DEFAULT])
945 func = drv->ops->set_default_key;
947 func = drv->ops->set_default_mgmt_key;
954 err = func(&drv->wiphy, dev, key_idx);
957 cfg80211_put_dev(drv);
966 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
968 struct cfg80211_registered_device *drv;
970 struct net_device *dev;
971 struct key_params params;
975 memset(¶ms, 0, sizeof(params));
977 if (!info->attrs[NL80211_ATTR_KEY_CIPHER])
980 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
981 params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
982 params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
985 if (info->attrs[NL80211_ATTR_KEY_IDX])
986 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
988 params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
990 if (info->attrs[NL80211_ATTR_MAC])
991 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
997 * Disallow pairwise keys with non-zero index unless it's WEP
998 * (because current deployments use pairwise WEP keys with
999 * non-zero indizes but 802.11i clearly specifies to use zero)
1001 if (mac_addr && key_idx &&
1002 params.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1003 params.cipher != WLAN_CIPHER_SUITE_WEP104)
1006 /* TODO: add definitions for the lengths to linux/ieee80211.h */
1007 switch (params.cipher) {
1008 case WLAN_CIPHER_SUITE_WEP40:
1009 if (params.key_len != 5)
1012 case WLAN_CIPHER_SUITE_TKIP:
1013 if (params.key_len != 32)
1016 case WLAN_CIPHER_SUITE_CCMP:
1017 if (params.key_len != 16)
1020 case WLAN_CIPHER_SUITE_WEP104:
1021 if (params.key_len != 13)
1024 case WLAN_CIPHER_SUITE_AES_CMAC:
1025 if (params.key_len != 16)
1034 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1038 if (!drv->ops->add_key) {
1043 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms);
1046 cfg80211_put_dev(drv);
1054 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1056 struct cfg80211_registered_device *drv;
1058 struct net_device *dev;
1060 u8 *mac_addr = NULL;
1062 if (info->attrs[NL80211_ATTR_KEY_IDX])
1063 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1068 if (info->attrs[NL80211_ATTR_MAC])
1069 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1073 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1077 if (!drv->ops->del_key) {
1082 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr);
1085 cfg80211_put_dev(drv);
1094 static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1096 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1097 struct beacon_parameters *info);
1098 struct cfg80211_registered_device *drv;
1100 struct net_device *dev;
1101 struct beacon_parameters params;
1104 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1109 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1113 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1118 switch (info->genlhdr->cmd) {
1119 case NL80211_CMD_NEW_BEACON:
1120 /* these are required for NEW_BEACON */
1121 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1122 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
1123 !info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1128 call = drv->ops->add_beacon;
1130 case NL80211_CMD_SET_BEACON:
1131 call = drv->ops->set_beacon;
1144 memset(¶ms, 0, sizeof(params));
1146 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1148 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1152 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
1153 params.dtim_period =
1154 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1158 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1159 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1161 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1165 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
1166 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1168 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1177 err = call(&drv->wiphy, dev, ¶ms);
1180 cfg80211_put_dev(drv);
1188 static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1190 struct cfg80211_registered_device *drv;
1192 struct net_device *dev;
1196 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1200 if (!drv->ops->del_beacon) {
1205 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1209 err = drv->ops->del_beacon(&drv->wiphy, dev);
1212 cfg80211_put_dev(drv);
1220 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1221 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
1222 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1223 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
1226 static int parse_station_flags(struct nlattr *nla, u32 *staflags)
1228 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
1236 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
1237 nla, sta_flags_policy))
1240 *staflags = STATION_FLAG_CHANGED;
1242 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
1244 *staflags |= (1<<flag);
1249 static u16 nl80211_calculate_bitrate(struct rate_info *rate)
1251 int modulation, streams, bitrate;
1253 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
1254 return rate->legacy;
1256 /* the formula below does only work for MCS values smaller than 32 */
1257 if (rate->mcs >= 32)
1260 modulation = rate->mcs & 7;
1261 streams = (rate->mcs >> 3) + 1;
1263 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1267 bitrate *= (modulation + 1);
1268 else if (modulation == 4)
1269 bitrate *= (modulation + 2);
1271 bitrate *= (modulation + 3);
1275 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1276 bitrate = (bitrate / 9) * 10;
1278 /* do NOT round down here */
1279 return (bitrate + 50000) / 100000;
1282 static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1283 int flags, struct net_device *dev,
1284 u8 *mac_addr, struct station_info *sinfo)
1287 struct nlattr *sinfoattr, *txrate;
1290 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1294 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1295 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1297 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1299 goto nla_put_failure;
1300 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1301 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1302 sinfo->inactive_time);
1303 if (sinfo->filled & STATION_INFO_RX_BYTES)
1304 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
1306 if (sinfo->filled & STATION_INFO_TX_BYTES)
1307 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
1309 if (sinfo->filled & STATION_INFO_LLID)
1310 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
1312 if (sinfo->filled & STATION_INFO_PLID)
1313 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
1315 if (sinfo->filled & STATION_INFO_PLINK_STATE)
1316 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
1317 sinfo->plink_state);
1318 if (sinfo->filled & STATION_INFO_SIGNAL)
1319 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1321 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1322 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1324 goto nla_put_failure;
1326 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1327 bitrate = nl80211_calculate_bitrate(&sinfo->txrate);
1329 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1331 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1332 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1334 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1335 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1336 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1337 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
1339 nla_nest_end(msg, txrate);
1341 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1342 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
1344 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1345 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1347 nla_nest_end(msg, sinfoattr);
1349 return genlmsg_end(msg, hdr);
1352 genlmsg_cancel(msg, hdr);
1356 static int nl80211_dump_station(struct sk_buff *skb,
1357 struct netlink_callback *cb)
1359 struct station_info sinfo;
1360 struct cfg80211_registered_device *dev;
1361 struct net_device *netdev;
1362 u8 mac_addr[ETH_ALEN];
1363 int ifidx = cb->args[0];
1364 int sta_idx = cb->args[1];
1368 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1369 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1374 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1377 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1384 netdev = __dev_get_by_index(&init_net, ifidx);
1390 dev = cfg80211_get_dev_from_ifindex(ifidx);
1396 if (!dev->ops->dump_station) {
1402 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
1409 if (nl80211_send_station(skb,
1410 NETLINK_CB(cb->skb).pid,
1411 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1421 cb->args[1] = sta_idx;
1424 cfg80211_put_dev(dev);
1431 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1433 struct cfg80211_registered_device *drv;
1435 struct net_device *dev;
1436 struct station_info sinfo;
1437 struct sk_buff *msg;
1438 u8 *mac_addr = NULL;
1440 memset(&sinfo, 0, sizeof(sinfo));
1442 if (!info->attrs[NL80211_ATTR_MAC])
1445 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1449 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1453 if (!drv->ops->get_station) {
1458 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo);
1462 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1466 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
1467 dev, mac_addr, &sinfo) < 0)
1470 err = genlmsg_unicast(msg, info->snd_pid);
1476 cfg80211_put_dev(drv);
1485 * Get vlan interface making sure it is on the right wiphy.
1487 static int get_vlan(struct nlattr *vlanattr,
1488 struct cfg80211_registered_device *rdev,
1489 struct net_device **vlan)
1494 *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr));
1497 if (!(*vlan)->ieee80211_ptr)
1499 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
1505 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1507 struct cfg80211_registered_device *drv;
1509 struct net_device *dev;
1510 struct station_parameters params;
1511 u8 *mac_addr = NULL;
1513 memset(¶ms, 0, sizeof(params));
1515 params.listen_interval = -1;
1517 if (info->attrs[NL80211_ATTR_STA_AID])
1520 if (!info->attrs[NL80211_ATTR_MAC])
1523 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1525 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
1526 params.supported_rates =
1527 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1528 params.supported_rates_len =
1529 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1532 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1533 params.listen_interval =
1534 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1536 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1538 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1540 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1541 ¶ms.station_flags))
1544 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
1545 params.plink_action =
1546 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
1550 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1554 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1558 if (!drv->ops->change_station) {
1563 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms);
1567 dev_put(params.vlan);
1568 cfg80211_put_dev(drv);
1576 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1578 struct cfg80211_registered_device *drv;
1580 struct net_device *dev;
1581 struct station_parameters params;
1582 u8 *mac_addr = NULL;
1584 memset(¶ms, 0, sizeof(params));
1586 if (!info->attrs[NL80211_ATTR_MAC])
1589 if (!info->attrs[NL80211_ATTR_STA_AID])
1592 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1595 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
1598 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1599 params.supported_rates =
1600 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1601 params.supported_rates_len =
1602 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1603 params.listen_interval =
1604 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1605 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
1606 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1608 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1610 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1611 ¶ms.station_flags))
1616 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1620 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1624 if (!drv->ops->add_station) {
1629 if (!netif_running(dev)) {
1634 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms);
1638 dev_put(params.vlan);
1639 cfg80211_put_dev(drv);
1647 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1649 struct cfg80211_registered_device *drv;
1651 struct net_device *dev;
1652 u8 *mac_addr = NULL;
1654 if (info->attrs[NL80211_ATTR_MAC])
1655 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1659 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1663 if (!drv->ops->del_station) {
1668 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr);
1671 cfg80211_put_dev(drv);
1679 static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
1680 int flags, struct net_device *dev,
1681 u8 *dst, u8 *next_hop,
1682 struct mpath_info *pinfo)
1685 struct nlattr *pinfoattr;
1687 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1691 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1692 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
1693 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
1695 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
1697 goto nla_put_failure;
1698 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
1699 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
1701 if (pinfo->filled & MPATH_INFO_DSN)
1702 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN,
1704 if (pinfo->filled & MPATH_INFO_METRIC)
1705 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
1707 if (pinfo->filled & MPATH_INFO_EXPTIME)
1708 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
1710 if (pinfo->filled & MPATH_INFO_FLAGS)
1711 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
1713 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
1714 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
1715 pinfo->discovery_timeout);
1716 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
1717 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
1718 pinfo->discovery_retries);
1720 nla_nest_end(msg, pinfoattr);
1722 return genlmsg_end(msg, hdr);
1725 genlmsg_cancel(msg, hdr);
1729 static int nl80211_dump_mpath(struct sk_buff *skb,
1730 struct netlink_callback *cb)
1732 struct mpath_info pinfo;
1733 struct cfg80211_registered_device *dev;
1734 struct net_device *netdev;
1736 u8 next_hop[ETH_ALEN];
1737 int ifidx = cb->args[0];
1738 int path_idx = cb->args[1];
1742 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1743 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1748 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1751 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1758 netdev = __dev_get_by_index(&init_net, ifidx);
1764 dev = cfg80211_get_dev_from_ifindex(ifidx);
1770 if (!dev->ops->dump_mpath) {
1775 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1781 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
1782 dst, next_hop, &pinfo);
1788 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
1789 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1790 netdev, dst, next_hop,
1799 cb->args[1] = path_idx;
1802 cfg80211_put_dev(dev);
1809 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
1811 struct cfg80211_registered_device *drv;
1813 struct net_device *dev;
1814 struct mpath_info pinfo;
1815 struct sk_buff *msg;
1817 u8 next_hop[ETH_ALEN];
1819 memset(&pinfo, 0, sizeof(pinfo));
1821 if (!info->attrs[NL80211_ATTR_MAC])
1824 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1828 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1832 if (!drv->ops->get_mpath) {
1837 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1842 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo);
1846 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1850 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
1851 dev, dst, next_hop, &pinfo) < 0)
1854 err = genlmsg_unicast(msg, info->snd_pid);
1860 cfg80211_put_dev(drv);
1868 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
1870 struct cfg80211_registered_device *drv;
1872 struct net_device *dev;
1874 u8 *next_hop = NULL;
1876 if (!info->attrs[NL80211_ATTR_MAC])
1879 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
1882 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1883 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1887 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1891 if (!drv->ops->change_mpath) {
1896 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1901 if (!netif_running(dev)) {
1906 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop);
1909 cfg80211_put_dev(drv);
1916 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
1918 struct cfg80211_registered_device *drv;
1920 struct net_device *dev;
1922 u8 *next_hop = NULL;
1924 if (!info->attrs[NL80211_ATTR_MAC])
1927 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
1930 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1931 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1935 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1939 if (!drv->ops->add_mpath) {
1944 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1949 if (!netif_running(dev)) {
1954 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop);
1957 cfg80211_put_dev(drv);
1965 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
1967 struct cfg80211_registered_device *drv;
1969 struct net_device *dev;
1972 if (info->attrs[NL80211_ATTR_MAC])
1973 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1977 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1981 if (!drv->ops->del_mpath) {
1986 err = drv->ops->del_mpath(&drv->wiphy, dev, dst);
1989 cfg80211_put_dev(drv);
1997 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
1999 struct cfg80211_registered_device *drv;
2001 struct net_device *dev;
2002 struct bss_parameters params;
2004 memset(¶ms, 0, sizeof(params));
2005 /* default to not changing parameters */
2006 params.use_cts_prot = -1;
2007 params.use_short_preamble = -1;
2008 params.use_short_slot_time = -1;
2010 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2011 params.use_cts_prot =
2012 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2013 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2014 params.use_short_preamble =
2015 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2016 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2017 params.use_short_slot_time =
2018 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
2019 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2020 params.basic_rates =
2021 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2022 params.basic_rates_len =
2023 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2028 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2032 if (!drv->ops->change_bss) {
2037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
2042 err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms);
2045 cfg80211_put_dev(drv);
2053 static const struct nla_policy
2054 reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
2055 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2056 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2057 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2058 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2059 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2060 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2063 static int parse_reg_rule(struct nlattr *tb[],
2064 struct ieee80211_reg_rule *reg_rule)
2066 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
2067 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
2069 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2071 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2073 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2075 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2077 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2080 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2082 freq_range->start_freq_khz =
2083 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2084 freq_range->end_freq_khz =
2085 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2086 freq_range->max_bandwidth_khz =
2087 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2089 power_rule->max_eirp =
2090 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2092 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2093 power_rule->max_antenna_gain =
2094 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2099 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2105 * You should only get this when cfg80211 hasn't yet initialized
2106 * completely when built-in to the kernel right between the time
2107 * window between nl80211_init() and regulatory_init(), if that is
2110 mutex_lock(&cfg80211_mutex);
2111 if (unlikely(!cfg80211_regdomain)) {
2112 mutex_unlock(&cfg80211_mutex);
2113 return -EINPROGRESS;
2115 mutex_unlock(&cfg80211_mutex);
2117 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2120 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2122 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2123 /* We ignore world regdom requests with the old regdom setup */
2124 if (is_world_regdom(data))
2128 r = regulatory_hint_user(data);
2133 static int nl80211_get_mesh_params(struct sk_buff *skb,
2134 struct genl_info *info)
2136 struct cfg80211_registered_device *drv;
2137 struct mesh_config cur_params;
2139 struct net_device *dev;
2141 struct nlattr *pinfoattr;
2142 struct sk_buff *msg;
2146 /* Look up our device */
2147 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2151 if (!drv->ops->get_mesh_params) {
2156 /* Get the mesh params */
2157 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params);
2161 /* Draw up a netlink message to send back */
2162 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2167 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2168 NL80211_CMD_GET_MESH_PARAMS);
2170 goto nla_put_failure;
2171 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS);
2173 goto nla_put_failure;
2174 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2175 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2176 cur_params.dot11MeshRetryTimeout);
2177 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2178 cur_params.dot11MeshConfirmTimeout);
2179 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2180 cur_params.dot11MeshHoldingTimeout);
2181 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2182 cur_params.dot11MeshMaxPeerLinks);
2183 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2184 cur_params.dot11MeshMaxRetries);
2185 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2186 cur_params.dot11MeshTTL);
2187 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2188 cur_params.auto_open_plinks);
2189 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2190 cur_params.dot11MeshHWMPmaxPREQretries);
2191 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2192 cur_params.path_refresh_time);
2193 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2194 cur_params.min_discovery_timeout);
2195 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2196 cur_params.dot11MeshHWMPactivePathTimeout);
2197 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2198 cur_params.dot11MeshHWMPpreqMinInterval);
2199 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2200 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
2201 nla_nest_end(msg, pinfoattr);
2202 genlmsg_end(msg, hdr);
2203 err = genlmsg_unicast(msg, info->snd_pid);
2207 genlmsg_cancel(msg, hdr);
2211 cfg80211_put_dev(drv);
2219 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2221 if (table[attr_num]) {\
2222 cfg.param = nla_fn(table[attr_num]); \
2223 mask |= (1 << (attr_num - 1)); \
2227 static struct nla_policy
2228 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = {
2229 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2230 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2231 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2232 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2233 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2234 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2235 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2237 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2238 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2239 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2240 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2241 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2242 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2245 static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2249 struct cfg80211_registered_device *drv;
2250 struct net_device *dev;
2251 struct mesh_config cfg;
2252 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2253 struct nlattr *parent_attr;
2255 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2258 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2259 parent_attr, nl80211_meshconf_params_policy))
2264 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2268 if (!drv->ops->set_mesh_params) {
2273 /* This makes sure that there aren't more than 32 mesh config
2274 * parameters (otherwise our bitfield scheme would not work.) */
2275 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2277 /* Fill in the params struct */
2279 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2280 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2281 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2282 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2283 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2284 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2285 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2286 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2287 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2288 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2289 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2290 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2291 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2292 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2293 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2294 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2296 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2297 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2298 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2299 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2301 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2302 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2304 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2305 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2307 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2308 dot11MeshHWMPnetDiameterTraversalTime,
2309 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2313 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask);
2317 cfg80211_put_dev(drv);
2325 #undef FILL_IN_MESH_PARAM_IF_SET
2327 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2329 struct sk_buff *msg;
2331 struct nlattr *nl_reg_rules;
2335 mutex_lock(&cfg80211_mutex);
2337 if (!cfg80211_regdomain)
2340 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2346 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2347 NL80211_CMD_GET_REG);
2349 goto nla_put_failure;
2351 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2352 cfg80211_regdomain->alpha2);
2354 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2356 goto nla_put_failure;
2358 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2359 struct nlattr *nl_reg_rule;
2360 const struct ieee80211_reg_rule *reg_rule;
2361 const struct ieee80211_freq_range *freq_range;
2362 const struct ieee80211_power_rule *power_rule;
2364 reg_rule = &cfg80211_regdomain->reg_rules[i];
2365 freq_range = ®_rule->freq_range;
2366 power_rule = ®_rule->power_rule;
2368 nl_reg_rule = nla_nest_start(msg, i);
2370 goto nla_put_failure;
2372 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2374 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2375 freq_range->start_freq_khz);
2376 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2377 freq_range->end_freq_khz);
2378 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2379 freq_range->max_bandwidth_khz);
2380 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2381 power_rule->max_antenna_gain);
2382 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2383 power_rule->max_eirp);
2385 nla_nest_end(msg, nl_reg_rule);
2388 nla_nest_end(msg, nl_reg_rules);
2390 genlmsg_end(msg, hdr);
2391 err = genlmsg_unicast(msg, info->snd_pid);
2395 genlmsg_cancel(msg, hdr);
2398 mutex_unlock(&cfg80211_mutex);
2402 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2404 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
2405 struct nlattr *nl_reg_rule;
2406 char *alpha2 = NULL;
2407 int rem_reg_rules = 0, r = 0;
2408 u32 num_rules = 0, rule_idx = 0, size_of_regd;
2409 struct ieee80211_regdomain *rd = NULL;
2411 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2414 if (!info->attrs[NL80211_ATTR_REG_RULES])
2417 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2419 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2422 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
2426 if (!reg_is_valid_request(alpha2))
2429 size_of_regd = sizeof(struct ieee80211_regdomain) +
2430 (num_rules * sizeof(struct ieee80211_reg_rule));
2432 rd = kzalloc(size_of_regd, GFP_KERNEL);
2436 rd->n_reg_rules = num_rules;
2437 rd->alpha2[0] = alpha2[0];
2438 rd->alpha2[1] = alpha2[1];
2440 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2442 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
2443 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
2445 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
2451 if (rule_idx > NL80211_MAX_SUPP_REG_RULES)
2455 BUG_ON(rule_idx != num_rules);
2457 mutex_lock(&cfg80211_mutex);
2459 mutex_unlock(&cfg80211_mutex);
2467 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2469 struct cfg80211_registered_device *drv;
2470 struct net_device *dev;
2471 struct cfg80211_scan_request *request;
2472 struct cfg80211_ssid *ssid;
2473 struct ieee80211_channel *channel;
2474 struct nlattr *attr;
2475 struct wiphy *wiphy;
2476 int err, tmp, n_ssids = 0, n_channels = 0, i;
2477 enum ieee80211_band band;
2480 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2485 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2489 wiphy = &drv->wiphy;
2491 if (!drv->ops->scan) {
2496 if (!netif_running(dev)) {
2501 if (drv->scan_req) {
2506 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2507 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp)
2514 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2515 if (wiphy->bands[band])
2516 n_channels += wiphy->bands[band]->n_channels;
2519 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2520 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2523 if (n_ssids > wiphy->max_scan_ssids) {
2528 if (info->attrs[NL80211_ATTR_IE])
2529 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2533 if (ie_len > wiphy->max_scan_ie_len) {
2538 request = kzalloc(sizeof(*request)
2539 + sizeof(*ssid) * n_ssids
2540 + sizeof(channel) * n_channels
2541 + ie_len, GFP_KERNEL);
2547 request->channels = (void *)((char *)request + sizeof(*request));
2548 request->n_channels = n_channels;
2550 request->ssids = (void *)(request->channels + n_channels);
2551 request->n_ssids = n_ssids;
2554 request->ie = (void *)(request->ssids + n_ssids);
2556 request->ie = (void *)(request->channels + n_channels);
2559 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2560 /* user specified, bail out if channel not found */
2561 request->n_channels = n_channels;
2563 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
2564 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2565 if (!request->channels[i]) {
2574 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2576 if (!wiphy->bands[band])
2578 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2579 request->channels[i] = &wiphy->bands[band]->channels[j];
2586 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2587 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2588 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2592 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
2593 request->ssids[i].ssid_len = nla_len(attr);
2598 if (info->attrs[NL80211_ATTR_IE]) {
2599 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2600 memcpy(request->ie, nla_data(info->attrs[NL80211_ATTR_IE]),
2604 request->ifidx = dev->ifindex;
2605 request->wiphy = &drv->wiphy;
2607 drv->scan_req = request;
2608 err = drv->ops->scan(&drv->wiphy, dev, request);
2612 drv->scan_req = NULL;
2616 cfg80211_put_dev(drv);
2624 static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
2625 struct cfg80211_registered_device *rdev,
2626 struct net_device *dev,
2627 struct cfg80211_bss *res)
2632 hdr = nl80211hdr_put(msg, pid, seq, flags,
2633 NL80211_CMD_NEW_SCAN_RESULTS);
2637 NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION,
2638 rdev->bss_generation);
2639 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2641 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
2643 goto nla_put_failure;
2644 if (!is_zero_ether_addr(res->bssid))
2645 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
2646 if (res->information_elements && res->len_information_elements)
2647 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
2648 res->len_information_elements,
2649 res->information_elements);
2651 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
2652 if (res->beacon_interval)
2653 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
2654 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
2655 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
2657 switch (rdev->wiphy.signal_type) {
2658 case CFG80211_SIGNAL_TYPE_MBM:
2659 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
2661 case CFG80211_SIGNAL_TYPE_UNSPEC:
2662 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
2668 nla_nest_end(msg, bss);
2670 return genlmsg_end(msg, hdr);
2673 genlmsg_cancel(msg, hdr);
2677 static int nl80211_dump_scan(struct sk_buff *skb,
2678 struct netlink_callback *cb)
2680 struct cfg80211_registered_device *dev;
2681 struct net_device *netdev;
2682 struct cfg80211_internal_bss *scan;
2683 int ifidx = cb->args[0];
2684 int start = cb->args[1], idx = 0;
2688 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
2689 nl80211_fam.attrbuf, nl80211_fam.maxattr,
2694 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2697 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2700 cb->args[0] = ifidx;
2703 netdev = dev_get_by_index(&init_net, ifidx);
2707 dev = cfg80211_get_dev_from_ifindex(ifidx);
2710 goto out_put_netdev;
2713 spin_lock_bh(&dev->bss_lock);
2714 cfg80211_bss_expire(dev);
2716 list_for_each_entry(scan, &dev->bss_list, list) {
2719 if (nl80211_send_bss(skb,
2720 NETLINK_CB(cb->skb).pid,
2721 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2722 dev, netdev, &scan->pub) < 0) {
2729 spin_unlock_bh(&dev->bss_lock);
2733 cfg80211_put_dev(dev);
2740 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
2742 return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM ||
2743 auth_type == NL80211_AUTHTYPE_SHARED_KEY ||
2744 auth_type == NL80211_AUTHTYPE_FT ||
2745 auth_type == NL80211_AUTHTYPE_NETWORK_EAP;
2748 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2750 struct cfg80211_registered_device *drv;
2751 struct net_device *dev;
2752 struct cfg80211_auth_request req;
2753 struct wiphy *wiphy;
2756 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2759 if (!info->attrs[NL80211_ATTR_MAC])
2762 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
2767 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2771 if (!drv->ops->auth) {
2776 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2781 if (!netif_running(dev)) {
2786 wiphy = &drv->wiphy;
2787 memset(&req, 0, sizeof(req));
2789 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2791 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2792 req.chan = ieee80211_get_channel(
2794 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2801 if (info->attrs[NL80211_ATTR_SSID]) {
2802 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2803 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2806 if (info->attrs[NL80211_ATTR_IE]) {
2807 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2808 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2811 req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
2812 if (!nl80211_valid_auth_type(req.auth_type)) {
2817 err = drv->ops->auth(&drv->wiphy, dev, &req);
2820 cfg80211_put_dev(drv);
2827 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2829 struct cfg80211_registered_device *drv;
2830 struct net_device *dev;
2831 struct cfg80211_assoc_request req;
2832 struct wiphy *wiphy;
2835 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2838 if (!info->attrs[NL80211_ATTR_MAC] ||
2839 !info->attrs[NL80211_ATTR_SSID])
2844 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2848 if (!drv->ops->assoc) {
2853 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2858 if (!netif_running(dev)) {
2863 wiphy = &drv->wiphy;
2864 memset(&req, 0, sizeof(req));
2866 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2868 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2869 req.chan = ieee80211_get_channel(
2871 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2878 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2879 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2881 if (info->attrs[NL80211_ATTR_IE]) {
2882 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2883 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2886 err = drv->ops->assoc(&drv->wiphy, dev, &req);
2889 cfg80211_put_dev(drv);
2896 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
2898 struct cfg80211_registered_device *drv;
2899 struct net_device *dev;
2900 struct cfg80211_deauth_request req;
2901 struct wiphy *wiphy;
2904 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2907 if (!info->attrs[NL80211_ATTR_MAC])
2910 if (!info->attrs[NL80211_ATTR_REASON_CODE])
2915 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2919 if (!drv->ops->deauth) {
2924 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2929 if (!netif_running(dev)) {
2934 wiphy = &drv->wiphy;
2935 memset(&req, 0, sizeof(req));
2937 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2939 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2940 if (req.reason_code == 0) {
2941 /* Reason Code 0 is reserved */
2946 if (info->attrs[NL80211_ATTR_IE]) {
2947 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2948 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2951 err = drv->ops->deauth(&drv->wiphy, dev, &req);
2954 cfg80211_put_dev(drv);
2961 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
2963 struct cfg80211_registered_device *drv;
2964 struct net_device *dev;
2965 struct cfg80211_disassoc_request req;
2966 struct wiphy *wiphy;
2969 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2972 if (!info->attrs[NL80211_ATTR_MAC])
2975 if (!info->attrs[NL80211_ATTR_REASON_CODE])
2980 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2984 if (!drv->ops->disassoc) {
2989 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2994 if (!netif_running(dev)) {
2999 wiphy = &drv->wiphy;
3000 memset(&req, 0, sizeof(req));
3002 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3004 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3005 if (req.reason_code == 0) {
3006 /* Reason Code 0 is reserved */
3011 if (info->attrs[NL80211_ATTR_IE]) {
3012 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3013 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3016 err = drv->ops->disassoc(&drv->wiphy, dev, &req);
3019 cfg80211_put_dev(drv);
3026 static struct genl_ops nl80211_ops[] = {
3028 .cmd = NL80211_CMD_GET_WIPHY,
3029 .doit = nl80211_get_wiphy,
3030 .dumpit = nl80211_dump_wiphy,
3031 .policy = nl80211_policy,
3032 /* can be retrieved by unprivileged users */
3035 .cmd = NL80211_CMD_SET_WIPHY,
3036 .doit = nl80211_set_wiphy,
3037 .policy = nl80211_policy,
3038 .flags = GENL_ADMIN_PERM,
3041 .cmd = NL80211_CMD_GET_INTERFACE,
3042 .doit = nl80211_get_interface,
3043 .dumpit = nl80211_dump_interface,
3044 .policy = nl80211_policy,
3045 /* can be retrieved by unprivileged users */
3048 .cmd = NL80211_CMD_SET_INTERFACE,
3049 .doit = nl80211_set_interface,
3050 .policy = nl80211_policy,
3051 .flags = GENL_ADMIN_PERM,
3054 .cmd = NL80211_CMD_NEW_INTERFACE,
3055 .doit = nl80211_new_interface,
3056 .policy = nl80211_policy,
3057 .flags = GENL_ADMIN_PERM,
3060 .cmd = NL80211_CMD_DEL_INTERFACE,
3061 .doit = nl80211_del_interface,
3062 .policy = nl80211_policy,
3063 .flags = GENL_ADMIN_PERM,
3066 .cmd = NL80211_CMD_GET_KEY,
3067 .doit = nl80211_get_key,
3068 .policy = nl80211_policy,
3069 .flags = GENL_ADMIN_PERM,
3072 .cmd = NL80211_CMD_SET_KEY,
3073 .doit = nl80211_set_key,
3074 .policy = nl80211_policy,
3075 .flags = GENL_ADMIN_PERM,
3078 .cmd = NL80211_CMD_NEW_KEY,
3079 .doit = nl80211_new_key,
3080 .policy = nl80211_policy,
3081 .flags = GENL_ADMIN_PERM,
3084 .cmd = NL80211_CMD_DEL_KEY,
3085 .doit = nl80211_del_key,
3086 .policy = nl80211_policy,
3087 .flags = GENL_ADMIN_PERM,
3090 .cmd = NL80211_CMD_SET_BEACON,
3091 .policy = nl80211_policy,
3092 .flags = GENL_ADMIN_PERM,
3093 .doit = nl80211_addset_beacon,
3096 .cmd = NL80211_CMD_NEW_BEACON,
3097 .policy = nl80211_policy,
3098 .flags = GENL_ADMIN_PERM,
3099 .doit = nl80211_addset_beacon,
3102 .cmd = NL80211_CMD_DEL_BEACON,
3103 .policy = nl80211_policy,
3104 .flags = GENL_ADMIN_PERM,
3105 .doit = nl80211_del_beacon,
3108 .cmd = NL80211_CMD_GET_STATION,
3109 .doit = nl80211_get_station,
3110 .dumpit = nl80211_dump_station,
3111 .policy = nl80211_policy,
3114 .cmd = NL80211_CMD_SET_STATION,
3115 .doit = nl80211_set_station,
3116 .policy = nl80211_policy,
3117 .flags = GENL_ADMIN_PERM,
3120 .cmd = NL80211_CMD_NEW_STATION,
3121 .doit = nl80211_new_station,
3122 .policy = nl80211_policy,
3123 .flags = GENL_ADMIN_PERM,
3126 .cmd = NL80211_CMD_DEL_STATION,
3127 .doit = nl80211_del_station,
3128 .policy = nl80211_policy,
3129 .flags = GENL_ADMIN_PERM,
3132 .cmd = NL80211_CMD_GET_MPATH,
3133 .doit = nl80211_get_mpath,
3134 .dumpit = nl80211_dump_mpath,
3135 .policy = nl80211_policy,
3136 .flags = GENL_ADMIN_PERM,
3139 .cmd = NL80211_CMD_SET_MPATH,
3140 .doit = nl80211_set_mpath,
3141 .policy = nl80211_policy,
3142 .flags = GENL_ADMIN_PERM,
3145 .cmd = NL80211_CMD_NEW_MPATH,
3146 .doit = nl80211_new_mpath,
3147 .policy = nl80211_policy,
3148 .flags = GENL_ADMIN_PERM,
3151 .cmd = NL80211_CMD_DEL_MPATH,
3152 .doit = nl80211_del_mpath,
3153 .policy = nl80211_policy,
3154 .flags = GENL_ADMIN_PERM,
3157 .cmd = NL80211_CMD_SET_BSS,
3158 .doit = nl80211_set_bss,
3159 .policy = nl80211_policy,
3160 .flags = GENL_ADMIN_PERM,
3163 .cmd = NL80211_CMD_GET_REG,
3164 .doit = nl80211_get_reg,
3165 .policy = nl80211_policy,
3166 /* can be retrieved by unprivileged users */
3169 .cmd = NL80211_CMD_SET_REG,
3170 .doit = nl80211_set_reg,
3171 .policy = nl80211_policy,
3172 .flags = GENL_ADMIN_PERM,
3175 .cmd = NL80211_CMD_REQ_SET_REG,
3176 .doit = nl80211_req_set_reg,
3177 .policy = nl80211_policy,
3178 .flags = GENL_ADMIN_PERM,
3181 .cmd = NL80211_CMD_GET_MESH_PARAMS,
3182 .doit = nl80211_get_mesh_params,
3183 .policy = nl80211_policy,
3184 /* can be retrieved by unprivileged users */
3187 .cmd = NL80211_CMD_SET_MESH_PARAMS,
3188 .doit = nl80211_set_mesh_params,
3189 .policy = nl80211_policy,
3190 .flags = GENL_ADMIN_PERM,
3193 .cmd = NL80211_CMD_TRIGGER_SCAN,
3194 .doit = nl80211_trigger_scan,
3195 .policy = nl80211_policy,
3196 .flags = GENL_ADMIN_PERM,
3199 .cmd = NL80211_CMD_GET_SCAN,
3200 .policy = nl80211_policy,
3201 .dumpit = nl80211_dump_scan,
3204 .cmd = NL80211_CMD_AUTHENTICATE,
3205 .doit = nl80211_authenticate,
3206 .policy = nl80211_policy,
3207 .flags = GENL_ADMIN_PERM,
3210 .cmd = NL80211_CMD_ASSOCIATE,
3211 .doit = nl80211_associate,
3212 .policy = nl80211_policy,
3213 .flags = GENL_ADMIN_PERM,
3216 .cmd = NL80211_CMD_DEAUTHENTICATE,
3217 .doit = nl80211_deauthenticate,
3218 .policy = nl80211_policy,
3219 .flags = GENL_ADMIN_PERM,
3222 .cmd = NL80211_CMD_DISASSOCIATE,
3223 .doit = nl80211_disassociate,
3224 .policy = nl80211_policy,
3225 .flags = GENL_ADMIN_PERM,
3228 static struct genl_multicast_group nl80211_mlme_mcgrp = {
3232 /* multicast groups */
3233 static struct genl_multicast_group nl80211_config_mcgrp = {
3236 static struct genl_multicast_group nl80211_scan_mcgrp = {
3239 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
3240 .name = "regulatory",
3243 /* notification functions */
3245 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
3247 struct sk_buff *msg;
3249 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3253 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
3258 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
3261 static int nl80211_send_scan_donemsg(struct sk_buff *msg,
3262 struct cfg80211_registered_device *rdev,
3263 struct net_device *netdev,
3264 u32 pid, u32 seq, int flags,
3269 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
3273 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3274 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3276 /* XXX: we should probably bounce back the request? */
3278 return genlmsg_end(msg, hdr);
3281 genlmsg_cancel(msg, hdr);
3285 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3286 struct net_device *netdev)
3288 struct sk_buff *msg;
3290 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3294 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3295 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
3300 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3303 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
3304 struct net_device *netdev)
3306 struct sk_buff *msg;
3308 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3312 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3313 NL80211_CMD_SCAN_ABORTED) < 0) {
3318 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3322 * This can happen on global regulatory changes or device specific settings
3323 * based on custom world regulatory domains.
3325 void nl80211_send_reg_change_event(struct regulatory_request *request)
3327 struct sk_buff *msg;
3330 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3334 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
3340 /* Userspace can always count this one always being set */
3341 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
3343 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
3344 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3345 NL80211_REGDOM_TYPE_WORLD);
3346 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
3347 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3348 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
3349 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
3351 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3352 NL80211_REGDOM_TYPE_INTERSECTION);
3354 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3355 NL80211_REGDOM_TYPE_COUNTRY);
3356 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
3359 if (wiphy_idx_valid(request->wiphy_idx))
3360 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
3362 if (genlmsg_end(msg, hdr) < 0) {
3367 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL);
3372 genlmsg_cancel(msg, hdr);
3376 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3377 struct net_device *netdev,
3378 const u8 *buf, size_t len,
3379 enum nl80211_commands cmd)
3381 struct sk_buff *msg;
3384 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
3388 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3394 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3395 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3396 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
3398 if (genlmsg_end(msg, hdr) < 0) {
3403 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC);
3407 genlmsg_cancel(msg, hdr);
3411 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3412 struct net_device *netdev, const u8 *buf, size_t len)
3414 nl80211_send_mlme_event(rdev, netdev, buf, len,
3415 NL80211_CMD_AUTHENTICATE);
3418 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3419 struct net_device *netdev, const u8 *buf,
3422 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3425 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
3426 struct net_device *netdev, const u8 *buf, size_t len)
3428 nl80211_send_mlme_event(rdev, netdev, buf, len,
3429 NL80211_CMD_DEAUTHENTICATE);
3432 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
3433 struct net_device *netdev, const u8 *buf,
3436 nl80211_send_mlme_event(rdev, netdev, buf, len,
3437 NL80211_CMD_DISASSOCIATE);
3440 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
3441 struct net_device *netdev, const u8 *addr,
3442 enum nl80211_key_type key_type, int key_id,
3445 struct sk_buff *msg;
3448 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3452 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
3458 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3459 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3461 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
3462 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
3463 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
3465 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
3467 if (genlmsg_end(msg, hdr) < 0) {
3472 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3476 genlmsg_cancel(msg, hdr);
3480 /* initialisation/exit functions */
3482 int nl80211_init(void)
3486 err = genl_register_family(&nl80211_fam);
3490 for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) {
3491 err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]);
3496 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
3500 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
3504 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
3508 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
3514 genl_unregister_family(&nl80211_fam);
3518 void nl80211_exit(void)
3520 genl_unregister_family(&nl80211_fam);