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 },
121 /* message building helper */
122 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
125 /* since there is no private header just add the generic one */
126 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
129 /* netlink command implementations */
131 static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
132 struct cfg80211_registered_device *dev)
135 struct nlattr *nl_bands, *nl_band;
136 struct nlattr *nl_freqs, *nl_freq;
137 struct nlattr *nl_rates, *nl_rate;
138 struct nlattr *nl_modes;
139 struct nlattr *nl_cmds;
140 enum ieee80211_band band;
141 struct ieee80211_channel *chan;
142 struct ieee80211_rate *rate;
144 u16 ifmodes = dev->wiphy.interface_modes;
146 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
150 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
151 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
152 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
153 dev->wiphy.max_scan_ssids);
155 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
157 goto nla_put_failure;
162 NLA_PUT_FLAG(msg, i);
167 nla_nest_end(msg, nl_modes);
169 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
171 goto nla_put_failure;
173 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
174 if (!dev->wiphy.bands[band])
177 nl_band = nla_nest_start(msg, band);
179 goto nla_put_failure;
182 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
183 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
184 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
185 &dev->wiphy.bands[band]->ht_cap.mcs);
186 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
187 dev->wiphy.bands[band]->ht_cap.cap);
188 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
189 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
190 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
191 dev->wiphy.bands[band]->ht_cap.ampdu_density);
194 /* add frequencies */
195 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
197 goto nla_put_failure;
199 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
200 nl_freq = nla_nest_start(msg, i);
202 goto nla_put_failure;
204 chan = &dev->wiphy.bands[band]->channels[i];
205 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
208 if (chan->flags & IEEE80211_CHAN_DISABLED)
209 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
210 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
211 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
212 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
213 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
214 if (chan->flags & IEEE80211_CHAN_RADAR)
215 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
217 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
218 DBM_TO_MBM(chan->max_power));
220 nla_nest_end(msg, nl_freq);
223 nla_nest_end(msg, nl_freqs);
226 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
228 goto nla_put_failure;
230 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
231 nl_rate = nla_nest_start(msg, i);
233 goto nla_put_failure;
235 rate = &dev->wiphy.bands[band]->bitrates[i];
236 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
238 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
240 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
242 nla_nest_end(msg, nl_rate);
245 nla_nest_end(msg, nl_rates);
247 nla_nest_end(msg, nl_band);
249 nla_nest_end(msg, nl_bands);
251 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
253 goto nla_put_failure;
258 if (dev->ops->op) { \
260 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
264 CMD(add_virtual_intf, NEW_INTERFACE);
265 CMD(change_virtual_intf, SET_INTERFACE);
266 CMD(add_key, NEW_KEY);
267 CMD(add_beacon, NEW_BEACON);
268 CMD(add_station, NEW_STATION);
269 CMD(add_mpath, NEW_MPATH);
270 CMD(set_mesh_params, SET_MESH_PARAMS);
271 CMD(change_bss, SET_BSS);
272 CMD(auth, AUTHENTICATE);
273 CMD(assoc, ASSOCIATE);
274 CMD(deauth, DEAUTHENTICATE);
275 CMD(disassoc, DISASSOCIATE);
278 nla_nest_end(msg, nl_cmds);
280 return genlmsg_end(msg, hdr);
283 genlmsg_cancel(msg, hdr);
287 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
290 int start = cb->args[0];
291 struct cfg80211_registered_device *dev;
293 mutex_lock(&cfg80211_mutex);
294 list_for_each_entry(dev, &cfg80211_drv_list, list) {
297 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
298 cb->nlh->nlmsg_seq, NLM_F_MULTI,
304 mutex_unlock(&cfg80211_mutex);
311 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
314 struct cfg80211_registered_device *dev;
316 dev = cfg80211_get_dev_from_info(info);
320 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
324 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
327 cfg80211_put_dev(dev);
329 return genlmsg_unicast(msg, info->snd_pid);
334 cfg80211_put_dev(dev);
338 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
339 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
340 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
341 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
342 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
343 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
346 static int parse_txq_params(struct nlattr *tb[],
347 struct ieee80211_txq_params *txq_params)
349 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
350 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
351 !tb[NL80211_TXQ_ATTR_AIFS])
354 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
355 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
356 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
357 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
358 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
363 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
365 struct cfg80211_registered_device *rdev;
366 int result = 0, rem_txq_params = 0;
367 struct nlattr *nl_txq_params;
369 rdev = cfg80211_get_dev_from_info(info);
371 return PTR_ERR(rdev);
373 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) {
374 result = cfg80211_dev_rename(
375 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
380 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
381 struct ieee80211_txq_params txq_params;
382 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
384 if (!rdev->ops->set_txq_params) {
385 result = -EOPNOTSUPP;
389 nla_for_each_nested(nl_txq_params,
390 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
392 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
393 nla_data(nl_txq_params),
394 nla_len(nl_txq_params),
396 result = parse_txq_params(tb, &txq_params);
400 result = rdev->ops->set_txq_params(&rdev->wiphy,
407 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
408 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
409 struct ieee80211_channel *chan;
410 struct ieee80211_sta_ht_cap *ht_cap;
413 if (!rdev->ops->set_channel) {
414 result = -EOPNOTSUPP;
420 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
421 channel_type = nla_get_u32(info->attrs[
422 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
423 if (channel_type != NL80211_CHAN_NO_HT &&
424 channel_type != NL80211_CHAN_HT20 &&
425 channel_type != NL80211_CHAN_HT40PLUS &&
426 channel_type != NL80211_CHAN_HT40MINUS)
430 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
431 chan = ieee80211_get_channel(&rdev->wiphy, freq);
433 /* Primary channel not allowed */
434 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
437 if (channel_type == NL80211_CHAN_HT40MINUS)
438 sec_freq = freq - 20;
439 else if (channel_type == NL80211_CHAN_HT40PLUS)
440 sec_freq = freq + 20;
444 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
446 /* no HT capabilities */
447 if (channel_type != NL80211_CHAN_NO_HT &&
448 !ht_cap->ht_supported)
452 struct ieee80211_channel *schan;
454 /* no 40 MHz capabilities */
455 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
456 (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
459 schan = ieee80211_get_channel(&rdev->wiphy, sec_freq);
461 /* Secondary channel not allowed */
462 if (!schan || schan->flags & IEEE80211_CHAN_DISABLED)
466 result = rdev->ops->set_channel(&rdev->wiphy, chan,
474 cfg80211_put_dev(rdev);
479 static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
480 struct net_device *dev)
484 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
488 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
489 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
490 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
491 return genlmsg_end(msg, hdr);
494 genlmsg_cancel(msg, hdr);
498 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
502 int wp_start = cb->args[0];
503 int if_start = cb->args[1];
504 struct cfg80211_registered_device *dev;
505 struct wireless_dev *wdev;
507 mutex_lock(&cfg80211_mutex);
508 list_for_each_entry(dev, &cfg80211_drv_list, list) {
509 if (wp_idx < wp_start) {
515 mutex_lock(&dev->devlist_mtx);
516 list_for_each_entry(wdev, &dev->netdev_list, list) {
517 if (if_idx < if_start) {
521 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
522 cb->nlh->nlmsg_seq, NLM_F_MULTI,
524 mutex_unlock(&dev->devlist_mtx);
529 mutex_unlock(&dev->devlist_mtx);
534 mutex_unlock(&cfg80211_mutex);
536 cb->args[0] = wp_idx;
537 cb->args[1] = if_idx;
542 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
545 struct cfg80211_registered_device *dev;
546 struct net_device *netdev;
549 err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev);
553 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
557 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0)
561 cfg80211_put_dev(dev);
563 return genlmsg_unicast(msg, info->snd_pid);
569 cfg80211_put_dev(dev);
573 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
574 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
575 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
576 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
577 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
578 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
581 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
583 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
591 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
592 nla, mntr_flags_policy))
595 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
597 *mntrflags |= (1<<flag);
602 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
604 struct cfg80211_registered_device *drv;
605 struct vif_params params;
607 enum nl80211_iftype type;
608 struct net_device *dev;
609 u32 _flags, *flags = NULL;
612 memset(¶ms, 0, sizeof(params));
616 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
620 ifindex = dev->ifindex;
621 type = dev->ieee80211_ptr->iftype;
624 if (info->attrs[NL80211_ATTR_IFTYPE]) {
625 enum nl80211_iftype ntype;
627 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
631 if (type > NL80211_IFTYPE_MAX) {
637 if (!drv->ops->change_virtual_intf ||
638 !(drv->wiphy.interface_modes & (1 << type))) {
643 if (info->attrs[NL80211_ATTR_MESH_ID]) {
644 if (type != NL80211_IFTYPE_MESH_POINT) {
648 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
649 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
653 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
654 if (type != NL80211_IFTYPE_MONITOR) {
658 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
668 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex,
669 type, flags, ¶ms);
673 dev = __dev_get_by_index(&init_net, ifindex);
674 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type));
677 cfg80211_put_dev(drv);
683 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
685 struct cfg80211_registered_device *drv;
686 struct vif_params params;
688 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
691 memset(¶ms, 0, sizeof(params));
693 if (!info->attrs[NL80211_ATTR_IFNAME])
696 if (info->attrs[NL80211_ATTR_IFTYPE]) {
697 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
698 if (type > NL80211_IFTYPE_MAX)
704 drv = cfg80211_get_dev_from_info(info);
710 if (!drv->ops->add_virtual_intf ||
711 !(drv->wiphy.interface_modes & (1 << type))) {
716 if (type == NL80211_IFTYPE_MESH_POINT &&
717 info->attrs[NL80211_ATTR_MESH_ID]) {
718 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
719 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
722 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
723 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
725 err = drv->ops->add_virtual_intf(&drv->wiphy,
726 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
727 type, err ? NULL : &flags, ¶ms);
730 cfg80211_put_dev(drv);
736 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
738 struct cfg80211_registered_device *drv;
740 struct net_device *dev;
744 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
747 ifindex = dev->ifindex;
750 if (!drv->ops->del_virtual_intf) {
755 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
758 cfg80211_put_dev(drv);
764 struct get_key_cookie {
769 static void get_key_callback(void *c, struct key_params *params)
771 struct get_key_cookie *cookie = c;
774 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
775 params->key_len, params->key);
778 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
779 params->seq_len, params->seq);
782 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
790 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
792 struct cfg80211_registered_device *drv;
794 struct net_device *dev;
797 struct get_key_cookie cookie = {
803 if (info->attrs[NL80211_ATTR_KEY_IDX])
804 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
809 if (info->attrs[NL80211_ATTR_MAC])
810 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
814 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
818 if (!drv->ops->get_key) {
823 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
829 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
830 NL80211_CMD_NEW_KEY);
839 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
840 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
842 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
844 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr,
845 &cookie, get_key_callback);
851 goto nla_put_failure;
853 genlmsg_end(msg, hdr);
854 err = genlmsg_unicast(msg, info->snd_pid);
861 cfg80211_put_dev(drv);
869 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
871 struct cfg80211_registered_device *drv;
873 struct net_device *dev;
875 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
878 if (!info->attrs[NL80211_ATTR_KEY_IDX])
881 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
883 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) {
884 if (key_idx < 4 || key_idx > 5)
886 } else if (key_idx > 3)
889 /* currently only support setting default key */
890 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] &&
891 !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT])
896 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
900 if (info->attrs[NL80211_ATTR_KEY_DEFAULT])
901 func = drv->ops->set_default_key;
903 func = drv->ops->set_default_mgmt_key;
910 err = func(&drv->wiphy, dev, key_idx);
913 cfg80211_put_dev(drv);
922 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
924 struct cfg80211_registered_device *drv;
926 struct net_device *dev;
927 struct key_params params;
931 memset(¶ms, 0, sizeof(params));
933 if (!info->attrs[NL80211_ATTR_KEY_CIPHER])
936 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
937 params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
938 params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
941 if (info->attrs[NL80211_ATTR_KEY_IDX])
942 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
944 params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
946 if (info->attrs[NL80211_ATTR_MAC])
947 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
953 * Disallow pairwise keys with non-zero index unless it's WEP
954 * (because current deployments use pairwise WEP keys with
955 * non-zero indizes but 802.11i clearly specifies to use zero)
957 if (mac_addr && key_idx &&
958 params.cipher != WLAN_CIPHER_SUITE_WEP40 &&
959 params.cipher != WLAN_CIPHER_SUITE_WEP104)
962 /* TODO: add definitions for the lengths to linux/ieee80211.h */
963 switch (params.cipher) {
964 case WLAN_CIPHER_SUITE_WEP40:
965 if (params.key_len != 5)
968 case WLAN_CIPHER_SUITE_TKIP:
969 if (params.key_len != 32)
972 case WLAN_CIPHER_SUITE_CCMP:
973 if (params.key_len != 16)
976 case WLAN_CIPHER_SUITE_WEP104:
977 if (params.key_len != 13)
980 case WLAN_CIPHER_SUITE_AES_CMAC:
981 if (params.key_len != 16)
990 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
994 if (!drv->ops->add_key) {
999 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms);
1002 cfg80211_put_dev(drv);
1010 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1012 struct cfg80211_registered_device *drv;
1014 struct net_device *dev;
1016 u8 *mac_addr = NULL;
1018 if (info->attrs[NL80211_ATTR_KEY_IDX])
1019 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1024 if (info->attrs[NL80211_ATTR_MAC])
1025 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1029 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1033 if (!drv->ops->del_key) {
1038 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr);
1041 cfg80211_put_dev(drv);
1050 static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1052 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1053 struct beacon_parameters *info);
1054 struct cfg80211_registered_device *drv;
1056 struct net_device *dev;
1057 struct beacon_parameters params;
1062 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1066 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1071 switch (info->genlhdr->cmd) {
1072 case NL80211_CMD_NEW_BEACON:
1073 /* these are required for NEW_BEACON */
1074 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1075 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
1076 !info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1081 call = drv->ops->add_beacon;
1083 case NL80211_CMD_SET_BEACON:
1084 call = drv->ops->set_beacon;
1097 memset(¶ms, 0, sizeof(params));
1099 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1101 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1105 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
1106 params.dtim_period =
1107 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1111 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1112 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1114 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1118 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
1119 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1121 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1130 err = call(&drv->wiphy, dev, ¶ms);
1133 cfg80211_put_dev(drv);
1141 static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1143 struct cfg80211_registered_device *drv;
1145 struct net_device *dev;
1149 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1153 if (!drv->ops->del_beacon) {
1158 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1162 err = drv->ops->del_beacon(&drv->wiphy, dev);
1165 cfg80211_put_dev(drv);
1173 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1174 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
1175 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1176 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
1179 static int parse_station_flags(struct nlattr *nla, u32 *staflags)
1181 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
1189 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
1190 nla, sta_flags_policy))
1193 *staflags = STATION_FLAG_CHANGED;
1195 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
1197 *staflags |= (1<<flag);
1202 static u16 nl80211_calculate_bitrate(struct rate_info *rate)
1204 int modulation, streams, bitrate;
1206 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
1207 return rate->legacy;
1209 /* the formula below does only work for MCS values smaller than 32 */
1210 if (rate->mcs >= 32)
1213 modulation = rate->mcs & 7;
1214 streams = (rate->mcs >> 3) + 1;
1216 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1220 bitrate *= (modulation + 1);
1221 else if (modulation == 4)
1222 bitrate *= (modulation + 2);
1224 bitrate *= (modulation + 3);
1228 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1229 bitrate = (bitrate / 9) * 10;
1231 /* do NOT round down here */
1232 return (bitrate + 50000) / 100000;
1235 static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1236 int flags, struct net_device *dev,
1237 u8 *mac_addr, struct station_info *sinfo)
1240 struct nlattr *sinfoattr, *txrate;
1243 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1247 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1248 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1250 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1252 goto nla_put_failure;
1253 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1254 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1255 sinfo->inactive_time);
1256 if (sinfo->filled & STATION_INFO_RX_BYTES)
1257 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
1259 if (sinfo->filled & STATION_INFO_TX_BYTES)
1260 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
1262 if (sinfo->filled & STATION_INFO_LLID)
1263 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
1265 if (sinfo->filled & STATION_INFO_PLID)
1266 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
1268 if (sinfo->filled & STATION_INFO_PLINK_STATE)
1269 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
1270 sinfo->plink_state);
1271 if (sinfo->filled & STATION_INFO_SIGNAL)
1272 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1274 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1275 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1277 goto nla_put_failure;
1279 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1280 bitrate = nl80211_calculate_bitrate(&sinfo->txrate);
1282 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1284 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1285 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1287 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1288 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1289 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1290 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
1292 nla_nest_end(msg, txrate);
1294 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1295 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
1297 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1298 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1300 nla_nest_end(msg, sinfoattr);
1302 return genlmsg_end(msg, hdr);
1305 genlmsg_cancel(msg, hdr);
1309 static int nl80211_dump_station(struct sk_buff *skb,
1310 struct netlink_callback *cb)
1312 struct station_info sinfo;
1313 struct cfg80211_registered_device *dev;
1314 struct net_device *netdev;
1315 u8 mac_addr[ETH_ALEN];
1316 int ifidx = cb->args[0];
1317 int sta_idx = cb->args[1];
1321 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1322 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1327 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1330 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1337 netdev = __dev_get_by_index(&init_net, ifidx);
1343 dev = cfg80211_get_dev_from_ifindex(ifidx);
1349 if (!dev->ops->dump_station) {
1355 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
1362 if (nl80211_send_station(skb,
1363 NETLINK_CB(cb->skb).pid,
1364 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1374 cb->args[1] = sta_idx;
1377 cfg80211_put_dev(dev);
1384 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1386 struct cfg80211_registered_device *drv;
1388 struct net_device *dev;
1389 struct station_info sinfo;
1390 struct sk_buff *msg;
1391 u8 *mac_addr = NULL;
1393 memset(&sinfo, 0, sizeof(sinfo));
1395 if (!info->attrs[NL80211_ATTR_MAC])
1398 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1402 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1406 if (!drv->ops->get_station) {
1411 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo);
1415 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1419 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
1420 dev, mac_addr, &sinfo) < 0)
1423 err = genlmsg_unicast(msg, info->snd_pid);
1429 cfg80211_put_dev(drv);
1438 * Get vlan interface making sure it is on the right wiphy.
1440 static int get_vlan(struct nlattr *vlanattr,
1441 struct cfg80211_registered_device *rdev,
1442 struct net_device **vlan)
1447 *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr));
1450 if (!(*vlan)->ieee80211_ptr)
1452 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
1458 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1460 struct cfg80211_registered_device *drv;
1462 struct net_device *dev;
1463 struct station_parameters params;
1464 u8 *mac_addr = NULL;
1466 memset(¶ms, 0, sizeof(params));
1468 params.listen_interval = -1;
1470 if (info->attrs[NL80211_ATTR_STA_AID])
1473 if (!info->attrs[NL80211_ATTR_MAC])
1476 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1478 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
1479 params.supported_rates =
1480 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1481 params.supported_rates_len =
1482 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1485 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1486 params.listen_interval =
1487 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1489 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1491 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1493 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1494 ¶ms.station_flags))
1497 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
1498 params.plink_action =
1499 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
1503 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1507 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1511 if (!drv->ops->change_station) {
1516 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms);
1520 dev_put(params.vlan);
1521 cfg80211_put_dev(drv);
1529 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1531 struct cfg80211_registered_device *drv;
1533 struct net_device *dev;
1534 struct station_parameters params;
1535 u8 *mac_addr = NULL;
1537 memset(¶ms, 0, sizeof(params));
1539 if (!info->attrs[NL80211_ATTR_MAC])
1542 if (!info->attrs[NL80211_ATTR_STA_AID])
1545 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1548 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
1551 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1552 params.supported_rates =
1553 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1554 params.supported_rates_len =
1555 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1556 params.listen_interval =
1557 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1558 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
1559 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1561 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1563 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1564 ¶ms.station_flags))
1569 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1573 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1577 if (!drv->ops->add_station) {
1582 if (!netif_running(dev)) {
1587 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms);
1591 dev_put(params.vlan);
1592 cfg80211_put_dev(drv);
1600 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1602 struct cfg80211_registered_device *drv;
1604 struct net_device *dev;
1605 u8 *mac_addr = NULL;
1607 if (info->attrs[NL80211_ATTR_MAC])
1608 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1612 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1616 if (!drv->ops->del_station) {
1621 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr);
1624 cfg80211_put_dev(drv);
1632 static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
1633 int flags, struct net_device *dev,
1634 u8 *dst, u8 *next_hop,
1635 struct mpath_info *pinfo)
1638 struct nlattr *pinfoattr;
1640 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1644 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1645 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
1646 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
1648 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
1650 goto nla_put_failure;
1651 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
1652 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
1654 if (pinfo->filled & MPATH_INFO_DSN)
1655 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN,
1657 if (pinfo->filled & MPATH_INFO_METRIC)
1658 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
1660 if (pinfo->filled & MPATH_INFO_EXPTIME)
1661 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
1663 if (pinfo->filled & MPATH_INFO_FLAGS)
1664 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
1666 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
1667 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
1668 pinfo->discovery_timeout);
1669 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
1670 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
1671 pinfo->discovery_retries);
1673 nla_nest_end(msg, pinfoattr);
1675 return genlmsg_end(msg, hdr);
1678 genlmsg_cancel(msg, hdr);
1682 static int nl80211_dump_mpath(struct sk_buff *skb,
1683 struct netlink_callback *cb)
1685 struct mpath_info pinfo;
1686 struct cfg80211_registered_device *dev;
1687 struct net_device *netdev;
1689 u8 next_hop[ETH_ALEN];
1690 int ifidx = cb->args[0];
1691 int path_idx = cb->args[1];
1695 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1696 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1701 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1704 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1711 netdev = __dev_get_by_index(&init_net, ifidx);
1717 dev = cfg80211_get_dev_from_ifindex(ifidx);
1723 if (!dev->ops->dump_mpath) {
1728 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1734 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
1735 dst, next_hop, &pinfo);
1741 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
1742 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1743 netdev, dst, next_hop,
1752 cb->args[1] = path_idx;
1755 cfg80211_put_dev(dev);
1762 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
1764 struct cfg80211_registered_device *drv;
1766 struct net_device *dev;
1767 struct mpath_info pinfo;
1768 struct sk_buff *msg;
1770 u8 next_hop[ETH_ALEN];
1772 memset(&pinfo, 0, sizeof(pinfo));
1774 if (!info->attrs[NL80211_ATTR_MAC])
1777 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1781 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1785 if (!drv->ops->get_mpath) {
1790 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1795 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo);
1799 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1803 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
1804 dev, dst, next_hop, &pinfo) < 0)
1807 err = genlmsg_unicast(msg, info->snd_pid);
1813 cfg80211_put_dev(drv);
1821 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
1823 struct cfg80211_registered_device *drv;
1825 struct net_device *dev;
1827 u8 *next_hop = NULL;
1829 if (!info->attrs[NL80211_ATTR_MAC])
1832 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
1835 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1836 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1840 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1844 if (!drv->ops->change_mpath) {
1849 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1854 if (!netif_running(dev)) {
1859 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop);
1862 cfg80211_put_dev(drv);
1869 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
1871 struct cfg80211_registered_device *drv;
1873 struct net_device *dev;
1875 u8 *next_hop = NULL;
1877 if (!info->attrs[NL80211_ATTR_MAC])
1880 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
1883 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1884 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1888 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1892 if (!drv->ops->add_mpath) {
1897 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1902 if (!netif_running(dev)) {
1907 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop);
1910 cfg80211_put_dev(drv);
1918 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
1920 struct cfg80211_registered_device *drv;
1922 struct net_device *dev;
1925 if (info->attrs[NL80211_ATTR_MAC])
1926 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1930 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1934 if (!drv->ops->del_mpath) {
1939 err = drv->ops->del_mpath(&drv->wiphy, dev, dst);
1942 cfg80211_put_dev(drv);
1950 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
1952 struct cfg80211_registered_device *drv;
1954 struct net_device *dev;
1955 struct bss_parameters params;
1957 memset(¶ms, 0, sizeof(params));
1958 /* default to not changing parameters */
1959 params.use_cts_prot = -1;
1960 params.use_short_preamble = -1;
1961 params.use_short_slot_time = -1;
1963 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
1964 params.use_cts_prot =
1965 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
1966 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
1967 params.use_short_preamble =
1968 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
1969 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
1970 params.use_short_slot_time =
1971 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
1972 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
1973 params.basic_rates =
1974 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1975 params.basic_rates_len =
1976 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1981 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1985 if (!drv->ops->change_bss) {
1990 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1995 err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms);
1998 cfg80211_put_dev(drv);
2006 static const struct nla_policy
2007 reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
2008 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2009 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2010 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2011 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2012 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2013 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2016 static int parse_reg_rule(struct nlattr *tb[],
2017 struct ieee80211_reg_rule *reg_rule)
2019 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
2020 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
2022 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2024 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2026 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2028 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2030 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2033 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2035 freq_range->start_freq_khz =
2036 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2037 freq_range->end_freq_khz =
2038 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2039 freq_range->max_bandwidth_khz =
2040 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2042 power_rule->max_eirp =
2043 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2045 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2046 power_rule->max_antenna_gain =
2047 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2052 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2058 * You should only get this when cfg80211 hasn't yet initialized
2059 * completely when built-in to the kernel right between the time
2060 * window between nl80211_init() and regulatory_init(), if that is
2063 mutex_lock(&cfg80211_mutex);
2064 if (unlikely(!cfg80211_regdomain)) {
2065 mutex_unlock(&cfg80211_mutex);
2066 return -EINPROGRESS;
2068 mutex_unlock(&cfg80211_mutex);
2070 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2073 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2075 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2076 /* We ignore world regdom requests with the old regdom setup */
2077 if (is_world_regdom(data))
2081 r = regulatory_hint_user(data);
2086 static int nl80211_get_mesh_params(struct sk_buff *skb,
2087 struct genl_info *info)
2089 struct cfg80211_registered_device *drv;
2090 struct mesh_config cur_params;
2092 struct net_device *dev;
2094 struct nlattr *pinfoattr;
2095 struct sk_buff *msg;
2099 /* Look up our device */
2100 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2104 if (!drv->ops->get_mesh_params) {
2109 /* Get the mesh params */
2110 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params);
2114 /* Draw up a netlink message to send back */
2115 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2120 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2121 NL80211_CMD_GET_MESH_PARAMS);
2123 goto nla_put_failure;
2124 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS);
2126 goto nla_put_failure;
2127 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2128 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2129 cur_params.dot11MeshRetryTimeout);
2130 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2131 cur_params.dot11MeshConfirmTimeout);
2132 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2133 cur_params.dot11MeshHoldingTimeout);
2134 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2135 cur_params.dot11MeshMaxPeerLinks);
2136 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2137 cur_params.dot11MeshMaxRetries);
2138 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2139 cur_params.dot11MeshTTL);
2140 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2141 cur_params.auto_open_plinks);
2142 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2143 cur_params.dot11MeshHWMPmaxPREQretries);
2144 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2145 cur_params.path_refresh_time);
2146 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2147 cur_params.min_discovery_timeout);
2148 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2149 cur_params.dot11MeshHWMPactivePathTimeout);
2150 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2151 cur_params.dot11MeshHWMPpreqMinInterval);
2152 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2153 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
2154 nla_nest_end(msg, pinfoattr);
2155 genlmsg_end(msg, hdr);
2156 err = genlmsg_unicast(msg, info->snd_pid);
2160 genlmsg_cancel(msg, hdr);
2164 cfg80211_put_dev(drv);
2172 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2174 if (table[attr_num]) {\
2175 cfg.param = nla_fn(table[attr_num]); \
2176 mask |= (1 << (attr_num - 1)); \
2180 static struct nla_policy
2181 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = {
2182 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2183 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2184 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2185 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2186 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2187 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2188 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2190 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2191 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2192 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2193 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2194 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2195 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2198 static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2202 struct cfg80211_registered_device *drv;
2203 struct net_device *dev;
2204 struct mesh_config cfg;
2205 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2206 struct nlattr *parent_attr;
2208 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2211 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2212 parent_attr, nl80211_meshconf_params_policy))
2217 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2221 if (!drv->ops->set_mesh_params) {
2226 /* This makes sure that there aren't more than 32 mesh config
2227 * parameters (otherwise our bitfield scheme would not work.) */
2228 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2230 /* Fill in the params struct */
2232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2233 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2234 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2235 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2236 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2237 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2239 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2240 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2241 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2242 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2243 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2244 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2245 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2247 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2249 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2250 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2251 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2252 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2254 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2255 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2257 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2258 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2260 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2261 dot11MeshHWMPnetDiameterTraversalTime,
2262 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2266 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask);
2270 cfg80211_put_dev(drv);
2278 #undef FILL_IN_MESH_PARAM_IF_SET
2280 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2282 struct sk_buff *msg;
2284 struct nlattr *nl_reg_rules;
2288 mutex_lock(&cfg80211_mutex);
2290 if (!cfg80211_regdomain)
2293 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2299 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2300 NL80211_CMD_GET_REG);
2302 goto nla_put_failure;
2304 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2305 cfg80211_regdomain->alpha2);
2307 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2309 goto nla_put_failure;
2311 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2312 struct nlattr *nl_reg_rule;
2313 const struct ieee80211_reg_rule *reg_rule;
2314 const struct ieee80211_freq_range *freq_range;
2315 const struct ieee80211_power_rule *power_rule;
2317 reg_rule = &cfg80211_regdomain->reg_rules[i];
2318 freq_range = ®_rule->freq_range;
2319 power_rule = ®_rule->power_rule;
2321 nl_reg_rule = nla_nest_start(msg, i);
2323 goto nla_put_failure;
2325 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2327 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2328 freq_range->start_freq_khz);
2329 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2330 freq_range->end_freq_khz);
2331 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2332 freq_range->max_bandwidth_khz);
2333 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2334 power_rule->max_antenna_gain);
2335 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2336 power_rule->max_eirp);
2338 nla_nest_end(msg, nl_reg_rule);
2341 nla_nest_end(msg, nl_reg_rules);
2343 genlmsg_end(msg, hdr);
2344 err = genlmsg_unicast(msg, info->snd_pid);
2348 genlmsg_cancel(msg, hdr);
2351 mutex_unlock(&cfg80211_mutex);
2355 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2357 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
2358 struct nlattr *nl_reg_rule;
2359 char *alpha2 = NULL;
2360 int rem_reg_rules = 0, r = 0;
2361 u32 num_rules = 0, rule_idx = 0, size_of_regd;
2362 struct ieee80211_regdomain *rd = NULL;
2364 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2367 if (!info->attrs[NL80211_ATTR_REG_RULES])
2370 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2372 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2375 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
2379 if (!reg_is_valid_request(alpha2))
2382 size_of_regd = sizeof(struct ieee80211_regdomain) +
2383 (num_rules * sizeof(struct ieee80211_reg_rule));
2385 rd = kzalloc(size_of_regd, GFP_KERNEL);
2389 rd->n_reg_rules = num_rules;
2390 rd->alpha2[0] = alpha2[0];
2391 rd->alpha2[1] = alpha2[1];
2393 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2395 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
2396 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
2398 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
2404 if (rule_idx > NL80211_MAX_SUPP_REG_RULES)
2408 BUG_ON(rule_idx != num_rules);
2410 mutex_lock(&cfg80211_mutex);
2412 mutex_unlock(&cfg80211_mutex);
2420 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2422 struct cfg80211_registered_device *drv;
2423 struct net_device *dev;
2424 struct cfg80211_scan_request *request;
2425 struct cfg80211_ssid *ssid;
2426 struct ieee80211_channel *channel;
2427 struct nlattr *attr;
2428 struct wiphy *wiphy;
2429 int err, tmp, n_ssids = 0, n_channels = 0, i;
2430 enum ieee80211_band band;
2435 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2439 wiphy = &drv->wiphy;
2441 if (!drv->ops->scan) {
2446 if (!netif_running(dev)) {
2451 if (drv->scan_req) {
2456 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2457 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp)
2464 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2465 if (wiphy->bands[band])
2466 n_channels += wiphy->bands[band]->n_channels;
2469 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2470 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2473 if (n_ssids > wiphy->max_scan_ssids) {
2478 if (info->attrs[NL80211_ATTR_IE])
2479 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2483 request = kzalloc(sizeof(*request)
2484 + sizeof(*ssid) * n_ssids
2485 + sizeof(channel) * n_channels
2486 + ie_len, GFP_KERNEL);
2492 request->channels = (void *)((char *)request + sizeof(*request));
2493 request->n_channels = n_channels;
2495 request->ssids = (void *)(request->channels + n_channels);
2496 request->n_ssids = n_ssids;
2499 request->ie = (void *)(request->ssids + n_ssids);
2501 request->ie = (void *)(request->channels + n_channels);
2504 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2505 /* user specified, bail out if channel not found */
2506 request->n_channels = n_channels;
2508 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
2509 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2510 if (!request->channels[i]) {
2519 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2521 if (!wiphy->bands[band])
2523 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2524 request->channels[i] = &wiphy->bands[band]->channels[j];
2531 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2532 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2533 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2537 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
2538 request->ssids[i].ssid_len = nla_len(attr);
2543 if (info->attrs[NL80211_ATTR_IE]) {
2544 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2545 memcpy(request->ie, nla_data(info->attrs[NL80211_ATTR_IE]),
2549 request->ifidx = dev->ifindex;
2550 request->wiphy = &drv->wiphy;
2552 drv->scan_req = request;
2553 err = drv->ops->scan(&drv->wiphy, dev, request);
2557 drv->scan_req = NULL;
2561 cfg80211_put_dev(drv);
2569 static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
2570 struct cfg80211_registered_device *rdev,
2571 struct net_device *dev,
2572 struct cfg80211_bss *res)
2577 hdr = nl80211hdr_put(msg, pid, seq, flags,
2578 NL80211_CMD_NEW_SCAN_RESULTS);
2582 NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION,
2583 rdev->bss_generation);
2584 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2586 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
2588 goto nla_put_failure;
2589 if (!is_zero_ether_addr(res->bssid))
2590 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
2591 if (res->information_elements && res->len_information_elements)
2592 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
2593 res->len_information_elements,
2594 res->information_elements);
2596 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
2597 if (res->beacon_interval)
2598 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
2599 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
2600 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
2602 switch (rdev->wiphy.signal_type) {
2603 case CFG80211_SIGNAL_TYPE_MBM:
2604 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
2606 case CFG80211_SIGNAL_TYPE_UNSPEC:
2607 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
2613 nla_nest_end(msg, bss);
2615 return genlmsg_end(msg, hdr);
2618 genlmsg_cancel(msg, hdr);
2622 static int nl80211_dump_scan(struct sk_buff *skb,
2623 struct netlink_callback *cb)
2625 struct cfg80211_registered_device *dev;
2626 struct net_device *netdev;
2627 struct cfg80211_internal_bss *scan;
2628 int ifidx = cb->args[0];
2629 int start = cb->args[1], idx = 0;
2633 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
2634 nl80211_fam.attrbuf, nl80211_fam.maxattr,
2639 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2642 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2645 cb->args[0] = ifidx;
2648 netdev = dev_get_by_index(&init_net, ifidx);
2652 dev = cfg80211_get_dev_from_ifindex(ifidx);
2655 goto out_put_netdev;
2658 spin_lock_bh(&dev->bss_lock);
2659 cfg80211_bss_expire(dev);
2661 list_for_each_entry(scan, &dev->bss_list, list) {
2664 if (nl80211_send_bss(skb,
2665 NETLINK_CB(cb->skb).pid,
2666 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2667 dev, netdev, &scan->pub) < 0) {
2674 spin_unlock_bh(&dev->bss_lock);
2678 cfg80211_put_dev(dev);
2685 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
2687 return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM ||
2688 auth_type == NL80211_AUTHTYPE_SHARED_KEY ||
2689 auth_type == NL80211_AUTHTYPE_FT ||
2690 auth_type == NL80211_AUTHTYPE_NETWORK_EAP;
2693 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2695 struct cfg80211_registered_device *drv;
2696 struct net_device *dev;
2697 struct cfg80211_auth_request req;
2698 struct wiphy *wiphy;
2703 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2707 if (!drv->ops->auth) {
2712 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2717 if (!netif_running(dev)) {
2722 if (!info->attrs[NL80211_ATTR_MAC]) {
2727 wiphy = &drv->wiphy;
2728 memset(&req, 0, sizeof(req));
2730 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2732 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2733 req.chan = ieee80211_get_channel(
2735 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2742 if (info->attrs[NL80211_ATTR_SSID]) {
2743 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2744 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2747 if (info->attrs[NL80211_ATTR_IE]) {
2748 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2749 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2752 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2754 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
2755 if (!nl80211_valid_auth_type(req.auth_type)) {
2761 err = drv->ops->auth(&drv->wiphy, dev, &req);
2764 cfg80211_put_dev(drv);
2771 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2773 struct cfg80211_registered_device *drv;
2774 struct net_device *dev;
2775 struct cfg80211_assoc_request req;
2776 struct wiphy *wiphy;
2781 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2785 if (!drv->ops->assoc) {
2790 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2795 if (!netif_running(dev)) {
2800 if (!info->attrs[NL80211_ATTR_MAC] ||
2801 !info->attrs[NL80211_ATTR_SSID]) {
2806 wiphy = &drv->wiphy;
2807 memset(&req, 0, sizeof(req));
2809 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2811 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2812 req.chan = ieee80211_get_channel(
2814 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2821 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2822 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2824 if (info->attrs[NL80211_ATTR_IE]) {
2825 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2826 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2829 err = drv->ops->assoc(&drv->wiphy, dev, &req);
2832 cfg80211_put_dev(drv);
2839 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
2841 struct cfg80211_registered_device *drv;
2842 struct net_device *dev;
2843 struct cfg80211_deauth_request req;
2844 struct wiphy *wiphy;
2849 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2853 if (!drv->ops->deauth) {
2858 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2863 if (!netif_running(dev)) {
2868 if (!info->attrs[NL80211_ATTR_MAC]) {
2873 wiphy = &drv->wiphy;
2874 memset(&req, 0, sizeof(req));
2876 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2878 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
2880 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2881 if (req.reason_code == 0) {
2882 /* Reason Code 0 is reserved */
2888 if (info->attrs[NL80211_ATTR_IE]) {
2889 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2890 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2893 err = drv->ops->deauth(&drv->wiphy, dev, &req);
2896 cfg80211_put_dev(drv);
2903 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
2905 struct cfg80211_registered_device *drv;
2906 struct net_device *dev;
2907 struct cfg80211_disassoc_request req;
2908 struct wiphy *wiphy;
2913 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2917 if (!drv->ops->disassoc) {
2922 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2927 if (!netif_running(dev)) {
2932 if (!info->attrs[NL80211_ATTR_MAC]) {
2937 wiphy = &drv->wiphy;
2938 memset(&req, 0, sizeof(req));
2940 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2942 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
2944 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2945 if (req.reason_code == 0) {
2946 /* Reason Code 0 is reserved */
2952 if (info->attrs[NL80211_ATTR_IE]) {
2953 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2954 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2957 err = drv->ops->disassoc(&drv->wiphy, dev, &req);
2960 cfg80211_put_dev(drv);
2967 static struct genl_ops nl80211_ops[] = {
2969 .cmd = NL80211_CMD_GET_WIPHY,
2970 .doit = nl80211_get_wiphy,
2971 .dumpit = nl80211_dump_wiphy,
2972 .policy = nl80211_policy,
2973 /* can be retrieved by unprivileged users */
2976 .cmd = NL80211_CMD_SET_WIPHY,
2977 .doit = nl80211_set_wiphy,
2978 .policy = nl80211_policy,
2979 .flags = GENL_ADMIN_PERM,
2982 .cmd = NL80211_CMD_GET_INTERFACE,
2983 .doit = nl80211_get_interface,
2984 .dumpit = nl80211_dump_interface,
2985 .policy = nl80211_policy,
2986 /* can be retrieved by unprivileged users */
2989 .cmd = NL80211_CMD_SET_INTERFACE,
2990 .doit = nl80211_set_interface,
2991 .policy = nl80211_policy,
2992 .flags = GENL_ADMIN_PERM,
2995 .cmd = NL80211_CMD_NEW_INTERFACE,
2996 .doit = nl80211_new_interface,
2997 .policy = nl80211_policy,
2998 .flags = GENL_ADMIN_PERM,
3001 .cmd = NL80211_CMD_DEL_INTERFACE,
3002 .doit = nl80211_del_interface,
3003 .policy = nl80211_policy,
3004 .flags = GENL_ADMIN_PERM,
3007 .cmd = NL80211_CMD_GET_KEY,
3008 .doit = nl80211_get_key,
3009 .policy = nl80211_policy,
3010 .flags = GENL_ADMIN_PERM,
3013 .cmd = NL80211_CMD_SET_KEY,
3014 .doit = nl80211_set_key,
3015 .policy = nl80211_policy,
3016 .flags = GENL_ADMIN_PERM,
3019 .cmd = NL80211_CMD_NEW_KEY,
3020 .doit = nl80211_new_key,
3021 .policy = nl80211_policy,
3022 .flags = GENL_ADMIN_PERM,
3025 .cmd = NL80211_CMD_DEL_KEY,
3026 .doit = nl80211_del_key,
3027 .policy = nl80211_policy,
3028 .flags = GENL_ADMIN_PERM,
3031 .cmd = NL80211_CMD_SET_BEACON,
3032 .policy = nl80211_policy,
3033 .flags = GENL_ADMIN_PERM,
3034 .doit = nl80211_addset_beacon,
3037 .cmd = NL80211_CMD_NEW_BEACON,
3038 .policy = nl80211_policy,
3039 .flags = GENL_ADMIN_PERM,
3040 .doit = nl80211_addset_beacon,
3043 .cmd = NL80211_CMD_DEL_BEACON,
3044 .policy = nl80211_policy,
3045 .flags = GENL_ADMIN_PERM,
3046 .doit = nl80211_del_beacon,
3049 .cmd = NL80211_CMD_GET_STATION,
3050 .doit = nl80211_get_station,
3051 .dumpit = nl80211_dump_station,
3052 .policy = nl80211_policy,
3055 .cmd = NL80211_CMD_SET_STATION,
3056 .doit = nl80211_set_station,
3057 .policy = nl80211_policy,
3058 .flags = GENL_ADMIN_PERM,
3061 .cmd = NL80211_CMD_NEW_STATION,
3062 .doit = nl80211_new_station,
3063 .policy = nl80211_policy,
3064 .flags = GENL_ADMIN_PERM,
3067 .cmd = NL80211_CMD_DEL_STATION,
3068 .doit = nl80211_del_station,
3069 .policy = nl80211_policy,
3070 .flags = GENL_ADMIN_PERM,
3073 .cmd = NL80211_CMD_GET_MPATH,
3074 .doit = nl80211_get_mpath,
3075 .dumpit = nl80211_dump_mpath,
3076 .policy = nl80211_policy,
3077 .flags = GENL_ADMIN_PERM,
3080 .cmd = NL80211_CMD_SET_MPATH,
3081 .doit = nl80211_set_mpath,
3082 .policy = nl80211_policy,
3083 .flags = GENL_ADMIN_PERM,
3086 .cmd = NL80211_CMD_NEW_MPATH,
3087 .doit = nl80211_new_mpath,
3088 .policy = nl80211_policy,
3089 .flags = GENL_ADMIN_PERM,
3092 .cmd = NL80211_CMD_DEL_MPATH,
3093 .doit = nl80211_del_mpath,
3094 .policy = nl80211_policy,
3095 .flags = GENL_ADMIN_PERM,
3098 .cmd = NL80211_CMD_SET_BSS,
3099 .doit = nl80211_set_bss,
3100 .policy = nl80211_policy,
3101 .flags = GENL_ADMIN_PERM,
3104 .cmd = NL80211_CMD_GET_REG,
3105 .doit = nl80211_get_reg,
3106 .policy = nl80211_policy,
3107 /* can be retrieved by unprivileged users */
3110 .cmd = NL80211_CMD_SET_REG,
3111 .doit = nl80211_set_reg,
3112 .policy = nl80211_policy,
3113 .flags = GENL_ADMIN_PERM,
3116 .cmd = NL80211_CMD_REQ_SET_REG,
3117 .doit = nl80211_req_set_reg,
3118 .policy = nl80211_policy,
3119 .flags = GENL_ADMIN_PERM,
3122 .cmd = NL80211_CMD_GET_MESH_PARAMS,
3123 .doit = nl80211_get_mesh_params,
3124 .policy = nl80211_policy,
3125 /* can be retrieved by unprivileged users */
3128 .cmd = NL80211_CMD_SET_MESH_PARAMS,
3129 .doit = nl80211_set_mesh_params,
3130 .policy = nl80211_policy,
3131 .flags = GENL_ADMIN_PERM,
3134 .cmd = NL80211_CMD_TRIGGER_SCAN,
3135 .doit = nl80211_trigger_scan,
3136 .policy = nl80211_policy,
3137 .flags = GENL_ADMIN_PERM,
3140 .cmd = NL80211_CMD_GET_SCAN,
3141 .policy = nl80211_policy,
3142 .dumpit = nl80211_dump_scan,
3145 .cmd = NL80211_CMD_AUTHENTICATE,
3146 .doit = nl80211_authenticate,
3147 .policy = nl80211_policy,
3148 .flags = GENL_ADMIN_PERM,
3151 .cmd = NL80211_CMD_ASSOCIATE,
3152 .doit = nl80211_associate,
3153 .policy = nl80211_policy,
3154 .flags = GENL_ADMIN_PERM,
3157 .cmd = NL80211_CMD_DEAUTHENTICATE,
3158 .doit = nl80211_deauthenticate,
3159 .policy = nl80211_policy,
3160 .flags = GENL_ADMIN_PERM,
3163 .cmd = NL80211_CMD_DISASSOCIATE,
3164 .doit = nl80211_disassociate,
3165 .policy = nl80211_policy,
3166 .flags = GENL_ADMIN_PERM,
3169 static struct genl_multicast_group nl80211_mlme_mcgrp = {
3173 /* multicast groups */
3174 static struct genl_multicast_group nl80211_config_mcgrp = {
3177 static struct genl_multicast_group nl80211_scan_mcgrp = {
3180 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
3181 .name = "regulatory",
3184 /* notification functions */
3186 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
3188 struct sk_buff *msg;
3190 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3194 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
3199 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
3202 static int nl80211_send_scan_donemsg(struct sk_buff *msg,
3203 struct cfg80211_registered_device *rdev,
3204 struct net_device *netdev,
3205 u32 pid, u32 seq, int flags,
3210 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
3214 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3215 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3217 /* XXX: we should probably bounce back the request? */
3219 return genlmsg_end(msg, hdr);
3222 genlmsg_cancel(msg, hdr);
3226 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3227 struct net_device *netdev)
3229 struct sk_buff *msg;
3231 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3235 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3236 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
3241 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3244 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
3245 struct net_device *netdev)
3247 struct sk_buff *msg;
3249 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3253 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3254 NL80211_CMD_SCAN_ABORTED) < 0) {
3259 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3263 * This can happen on global regulatory changes or device specific settings
3264 * based on custom world regulatory domains.
3266 void nl80211_send_reg_change_event(struct regulatory_request *request)
3268 struct sk_buff *msg;
3271 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3275 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
3281 /* Userspace can always count this one always being set */
3282 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
3284 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
3285 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3286 NL80211_REGDOM_TYPE_WORLD);
3287 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
3288 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3289 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
3290 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
3292 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3293 NL80211_REGDOM_TYPE_INTERSECTION);
3295 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3296 NL80211_REGDOM_TYPE_COUNTRY);
3297 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
3300 if (wiphy_idx_valid(request->wiphy_idx))
3301 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
3303 if (genlmsg_end(msg, hdr) < 0) {
3308 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL);
3313 genlmsg_cancel(msg, hdr);
3317 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3318 struct net_device *netdev,
3319 const u8 *buf, size_t len,
3320 enum nl80211_commands cmd)
3322 struct sk_buff *msg;
3325 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3329 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3335 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3336 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3337 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
3339 if (genlmsg_end(msg, hdr) < 0) {
3344 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3348 genlmsg_cancel(msg, hdr);
3352 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3353 struct net_device *netdev, const u8 *buf, size_t len)
3355 nl80211_send_mlme_event(rdev, netdev, buf, len,
3356 NL80211_CMD_AUTHENTICATE);
3359 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3360 struct net_device *netdev, const u8 *buf,
3363 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3366 void nl80211_send_rx_deauth(struct cfg80211_registered_device *rdev,
3367 struct net_device *netdev, const u8 *buf,
3370 nl80211_send_mlme_event(rdev, netdev, buf, len,
3371 NL80211_CMD_DEAUTHENTICATE);
3374 void nl80211_send_rx_disassoc(struct cfg80211_registered_device *rdev,
3375 struct net_device *netdev, const u8 *buf,
3378 nl80211_send_mlme_event(rdev, netdev, buf, len,
3379 NL80211_CMD_DISASSOCIATE);
3382 /* initialisation/exit functions */
3384 int nl80211_init(void)
3388 err = genl_register_family(&nl80211_fam);
3392 for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) {
3393 err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]);
3398 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
3402 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
3406 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
3410 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
3416 genl_unregister_family(&nl80211_fam);
3420 void nl80211_exit(void)
3422 genl_unregister_family(&nl80211_fam);