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;
611 memset(¶ms, 0, sizeof(params));
615 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
619 ifindex = dev->ifindex;
620 type = dev->ieee80211_ptr->iftype;
624 if (info->attrs[NL80211_ATTR_IFTYPE]) {
625 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
626 if (type > NL80211_IFTYPE_MAX)
630 if (!drv->ops->change_virtual_intf ||
631 !(drv->wiphy.interface_modes & (1 << type))) {
636 if (info->attrs[NL80211_ATTR_MESH_ID]) {
637 if (type != NL80211_IFTYPE_MESH_POINT) {
641 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
642 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
645 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
646 if (type != NL80211_IFTYPE_MONITOR) {
650 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
656 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex,
657 type, flags, ¶ms);
659 dev = __dev_get_by_index(&init_net, ifindex);
660 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type));
663 cfg80211_put_dev(drv);
669 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
671 struct cfg80211_registered_device *drv;
672 struct vif_params params;
674 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
677 memset(¶ms, 0, sizeof(params));
679 if (!info->attrs[NL80211_ATTR_IFNAME])
682 if (info->attrs[NL80211_ATTR_IFTYPE]) {
683 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
684 if (type > NL80211_IFTYPE_MAX)
690 drv = cfg80211_get_dev_from_info(info);
696 if (!drv->ops->add_virtual_intf ||
697 !(drv->wiphy.interface_modes & (1 << type))) {
702 if (type == NL80211_IFTYPE_MESH_POINT &&
703 info->attrs[NL80211_ATTR_MESH_ID]) {
704 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
705 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
708 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
709 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
711 err = drv->ops->add_virtual_intf(&drv->wiphy,
712 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
713 type, err ? NULL : &flags, ¶ms);
716 cfg80211_put_dev(drv);
722 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
724 struct cfg80211_registered_device *drv;
726 struct net_device *dev;
730 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
733 ifindex = dev->ifindex;
736 if (!drv->ops->del_virtual_intf) {
741 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
744 cfg80211_put_dev(drv);
750 struct get_key_cookie {
755 static void get_key_callback(void *c, struct key_params *params)
757 struct get_key_cookie *cookie = c;
760 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
761 params->key_len, params->key);
764 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
765 params->seq_len, params->seq);
768 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
776 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
778 struct cfg80211_registered_device *drv;
780 struct net_device *dev;
783 struct get_key_cookie cookie = {
789 if (info->attrs[NL80211_ATTR_KEY_IDX])
790 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
795 if (info->attrs[NL80211_ATTR_MAC])
796 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
800 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
804 if (!drv->ops->get_key) {
809 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
815 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
816 NL80211_CMD_NEW_KEY);
825 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
826 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
828 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
830 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr,
831 &cookie, get_key_callback);
837 goto nla_put_failure;
839 genlmsg_end(msg, hdr);
840 err = genlmsg_unicast(msg, info->snd_pid);
847 cfg80211_put_dev(drv);
855 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
857 struct cfg80211_registered_device *drv;
859 struct net_device *dev;
861 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
864 if (!info->attrs[NL80211_ATTR_KEY_IDX])
867 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
869 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) {
870 if (key_idx < 4 || key_idx > 5)
872 } else if (key_idx > 3)
875 /* currently only support setting default key */
876 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] &&
877 !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT])
882 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
886 if (info->attrs[NL80211_ATTR_KEY_DEFAULT])
887 func = drv->ops->set_default_key;
889 func = drv->ops->set_default_mgmt_key;
896 err = func(&drv->wiphy, dev, key_idx);
899 cfg80211_put_dev(drv);
908 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
910 struct cfg80211_registered_device *drv;
912 struct net_device *dev;
913 struct key_params params;
917 memset(¶ms, 0, sizeof(params));
919 if (!info->attrs[NL80211_ATTR_KEY_CIPHER])
922 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
923 params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
924 params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
927 if (info->attrs[NL80211_ATTR_KEY_IDX])
928 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
930 params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
932 if (info->attrs[NL80211_ATTR_MAC])
933 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
939 * Disallow pairwise keys with non-zero index unless it's WEP
940 * (because current deployments use pairwise WEP keys with
941 * non-zero indizes but 802.11i clearly specifies to use zero)
943 if (mac_addr && key_idx &&
944 params.cipher != WLAN_CIPHER_SUITE_WEP40 &&
945 params.cipher != WLAN_CIPHER_SUITE_WEP104)
948 /* TODO: add definitions for the lengths to linux/ieee80211.h */
949 switch (params.cipher) {
950 case WLAN_CIPHER_SUITE_WEP40:
951 if (params.key_len != 5)
954 case WLAN_CIPHER_SUITE_TKIP:
955 if (params.key_len != 32)
958 case WLAN_CIPHER_SUITE_CCMP:
959 if (params.key_len != 16)
962 case WLAN_CIPHER_SUITE_WEP104:
963 if (params.key_len != 13)
966 case WLAN_CIPHER_SUITE_AES_CMAC:
967 if (params.key_len != 16)
976 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
980 if (!drv->ops->add_key) {
985 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms);
988 cfg80211_put_dev(drv);
996 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
998 struct cfg80211_registered_device *drv;
1000 struct net_device *dev;
1002 u8 *mac_addr = NULL;
1004 if (info->attrs[NL80211_ATTR_KEY_IDX])
1005 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1010 if (info->attrs[NL80211_ATTR_MAC])
1011 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1015 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1019 if (!drv->ops->del_key) {
1024 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr);
1027 cfg80211_put_dev(drv);
1036 static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1038 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1039 struct beacon_parameters *info);
1040 struct cfg80211_registered_device *drv;
1042 struct net_device *dev;
1043 struct beacon_parameters params;
1048 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1052 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1057 switch (info->genlhdr->cmd) {
1058 case NL80211_CMD_NEW_BEACON:
1059 /* these are required for NEW_BEACON */
1060 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1061 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
1062 !info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1067 call = drv->ops->add_beacon;
1069 case NL80211_CMD_SET_BEACON:
1070 call = drv->ops->set_beacon;
1083 memset(¶ms, 0, sizeof(params));
1085 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1087 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1091 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
1092 params.dtim_period =
1093 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1097 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1098 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1100 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1104 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
1105 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1107 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1116 err = call(&drv->wiphy, dev, ¶ms);
1119 cfg80211_put_dev(drv);
1127 static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1129 struct cfg80211_registered_device *drv;
1131 struct net_device *dev;
1135 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1139 if (!drv->ops->del_beacon) {
1144 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1148 err = drv->ops->del_beacon(&drv->wiphy, dev);
1151 cfg80211_put_dev(drv);
1159 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1160 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
1161 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1162 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
1165 static int parse_station_flags(struct nlattr *nla, u32 *staflags)
1167 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
1175 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
1176 nla, sta_flags_policy))
1179 *staflags = STATION_FLAG_CHANGED;
1181 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
1183 *staflags |= (1<<flag);
1188 static u16 nl80211_calculate_bitrate(struct rate_info *rate)
1190 int modulation, streams, bitrate;
1192 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
1193 return rate->legacy;
1195 /* the formula below does only work for MCS values smaller than 32 */
1196 if (rate->mcs >= 32)
1199 modulation = rate->mcs & 7;
1200 streams = (rate->mcs >> 3) + 1;
1202 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1206 bitrate *= (modulation + 1);
1207 else if (modulation == 4)
1208 bitrate *= (modulation + 2);
1210 bitrate *= (modulation + 3);
1214 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1215 bitrate = (bitrate / 9) * 10;
1217 /* do NOT round down here */
1218 return (bitrate + 50000) / 100000;
1221 static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1222 int flags, struct net_device *dev,
1223 u8 *mac_addr, struct station_info *sinfo)
1226 struct nlattr *sinfoattr, *txrate;
1229 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1233 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1234 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1236 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1238 goto nla_put_failure;
1239 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1240 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1241 sinfo->inactive_time);
1242 if (sinfo->filled & STATION_INFO_RX_BYTES)
1243 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
1245 if (sinfo->filled & STATION_INFO_TX_BYTES)
1246 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
1248 if (sinfo->filled & STATION_INFO_LLID)
1249 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
1251 if (sinfo->filled & STATION_INFO_PLID)
1252 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
1254 if (sinfo->filled & STATION_INFO_PLINK_STATE)
1255 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
1256 sinfo->plink_state);
1257 if (sinfo->filled & STATION_INFO_SIGNAL)
1258 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1260 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1261 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1263 goto nla_put_failure;
1265 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1266 bitrate = nl80211_calculate_bitrate(&sinfo->txrate);
1268 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1270 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1271 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1273 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1274 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1275 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1276 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
1278 nla_nest_end(msg, txrate);
1280 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1281 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
1283 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1284 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1286 nla_nest_end(msg, sinfoattr);
1288 return genlmsg_end(msg, hdr);
1291 genlmsg_cancel(msg, hdr);
1295 static int nl80211_dump_station(struct sk_buff *skb,
1296 struct netlink_callback *cb)
1298 struct station_info sinfo;
1299 struct cfg80211_registered_device *dev;
1300 struct net_device *netdev;
1301 u8 mac_addr[ETH_ALEN];
1302 int ifidx = cb->args[0];
1303 int sta_idx = cb->args[1];
1307 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1308 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1313 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1316 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1323 netdev = __dev_get_by_index(&init_net, ifidx);
1329 dev = cfg80211_get_dev_from_ifindex(ifidx);
1335 if (!dev->ops->dump_station) {
1341 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
1348 if (nl80211_send_station(skb,
1349 NETLINK_CB(cb->skb).pid,
1350 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1360 cb->args[1] = sta_idx;
1363 cfg80211_put_dev(dev);
1370 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1372 struct cfg80211_registered_device *drv;
1374 struct net_device *dev;
1375 struct station_info sinfo;
1376 struct sk_buff *msg;
1377 u8 *mac_addr = NULL;
1379 memset(&sinfo, 0, sizeof(sinfo));
1381 if (!info->attrs[NL80211_ATTR_MAC])
1384 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1388 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1392 if (!drv->ops->get_station) {
1397 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo);
1401 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1405 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
1406 dev, mac_addr, &sinfo) < 0)
1409 err = genlmsg_unicast(msg, info->snd_pid);
1415 cfg80211_put_dev(drv);
1424 * Get vlan interface making sure it is on the right wiphy.
1426 static int get_vlan(struct nlattr *vlanattr,
1427 struct cfg80211_registered_device *rdev,
1428 struct net_device **vlan)
1433 *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr));
1436 if (!(*vlan)->ieee80211_ptr)
1438 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
1444 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1446 struct cfg80211_registered_device *drv;
1448 struct net_device *dev;
1449 struct station_parameters params;
1450 u8 *mac_addr = NULL;
1452 memset(¶ms, 0, sizeof(params));
1454 params.listen_interval = -1;
1456 if (info->attrs[NL80211_ATTR_STA_AID])
1459 if (!info->attrs[NL80211_ATTR_MAC])
1462 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1464 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
1465 params.supported_rates =
1466 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1467 params.supported_rates_len =
1468 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1471 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1472 params.listen_interval =
1473 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1475 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1477 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1479 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1480 ¶ms.station_flags))
1483 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
1484 params.plink_action =
1485 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
1489 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1493 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1497 if (!drv->ops->change_station) {
1502 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms);
1506 dev_put(params.vlan);
1507 cfg80211_put_dev(drv);
1515 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1517 struct cfg80211_registered_device *drv;
1519 struct net_device *dev;
1520 struct station_parameters params;
1521 u8 *mac_addr = NULL;
1523 memset(¶ms, 0, sizeof(params));
1525 if (!info->attrs[NL80211_ATTR_MAC])
1528 if (!info->attrs[NL80211_ATTR_STA_AID])
1531 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1534 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
1537 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1538 params.supported_rates =
1539 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1540 params.supported_rates_len =
1541 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1542 params.listen_interval =
1543 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1544 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
1545 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1547 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1549 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1550 ¶ms.station_flags))
1555 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1559 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1563 if (!drv->ops->add_station) {
1568 if (!netif_running(dev)) {
1573 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms);
1577 dev_put(params.vlan);
1578 cfg80211_put_dev(drv);
1586 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1588 struct cfg80211_registered_device *drv;
1590 struct net_device *dev;
1591 u8 *mac_addr = NULL;
1593 if (info->attrs[NL80211_ATTR_MAC])
1594 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1598 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1602 if (!drv->ops->del_station) {
1607 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr);
1610 cfg80211_put_dev(drv);
1618 static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
1619 int flags, struct net_device *dev,
1620 u8 *dst, u8 *next_hop,
1621 struct mpath_info *pinfo)
1624 struct nlattr *pinfoattr;
1626 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1630 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1631 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
1632 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
1634 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
1636 goto nla_put_failure;
1637 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
1638 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
1640 if (pinfo->filled & MPATH_INFO_DSN)
1641 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN,
1643 if (pinfo->filled & MPATH_INFO_METRIC)
1644 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
1646 if (pinfo->filled & MPATH_INFO_EXPTIME)
1647 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
1649 if (pinfo->filled & MPATH_INFO_FLAGS)
1650 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
1652 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
1653 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
1654 pinfo->discovery_timeout);
1655 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
1656 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
1657 pinfo->discovery_retries);
1659 nla_nest_end(msg, pinfoattr);
1661 return genlmsg_end(msg, hdr);
1664 genlmsg_cancel(msg, hdr);
1668 static int nl80211_dump_mpath(struct sk_buff *skb,
1669 struct netlink_callback *cb)
1671 struct mpath_info pinfo;
1672 struct cfg80211_registered_device *dev;
1673 struct net_device *netdev;
1675 u8 next_hop[ETH_ALEN];
1676 int ifidx = cb->args[0];
1677 int path_idx = cb->args[1];
1681 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1682 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1687 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1690 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1697 netdev = __dev_get_by_index(&init_net, ifidx);
1703 dev = cfg80211_get_dev_from_ifindex(ifidx);
1709 if (!dev->ops->dump_mpath) {
1714 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1720 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
1721 dst, next_hop, &pinfo);
1727 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
1728 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1729 netdev, dst, next_hop,
1738 cb->args[1] = path_idx;
1741 cfg80211_put_dev(dev);
1748 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
1750 struct cfg80211_registered_device *drv;
1752 struct net_device *dev;
1753 struct mpath_info pinfo;
1754 struct sk_buff *msg;
1756 u8 next_hop[ETH_ALEN];
1758 memset(&pinfo, 0, sizeof(pinfo));
1760 if (!info->attrs[NL80211_ATTR_MAC])
1763 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1767 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1771 if (!drv->ops->get_mpath) {
1776 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1781 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo);
1785 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1789 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
1790 dev, dst, next_hop, &pinfo) < 0)
1793 err = genlmsg_unicast(msg, info->snd_pid);
1799 cfg80211_put_dev(drv);
1807 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
1809 struct cfg80211_registered_device *drv;
1811 struct net_device *dev;
1813 u8 *next_hop = NULL;
1815 if (!info->attrs[NL80211_ATTR_MAC])
1818 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
1821 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1822 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1826 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1830 if (!drv->ops->change_mpath) {
1835 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1840 if (!netif_running(dev)) {
1845 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop);
1848 cfg80211_put_dev(drv);
1855 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
1857 struct cfg80211_registered_device *drv;
1859 struct net_device *dev;
1861 u8 *next_hop = NULL;
1863 if (!info->attrs[NL80211_ATTR_MAC])
1866 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
1869 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1870 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
1874 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1878 if (!drv->ops->add_mpath) {
1883 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1888 if (!netif_running(dev)) {
1893 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop);
1896 cfg80211_put_dev(drv);
1904 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
1906 struct cfg80211_registered_device *drv;
1908 struct net_device *dev;
1911 if (info->attrs[NL80211_ATTR_MAC])
1912 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1916 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1920 if (!drv->ops->del_mpath) {
1925 err = drv->ops->del_mpath(&drv->wiphy, dev, dst);
1928 cfg80211_put_dev(drv);
1936 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
1938 struct cfg80211_registered_device *drv;
1940 struct net_device *dev;
1941 struct bss_parameters params;
1943 memset(¶ms, 0, sizeof(params));
1944 /* default to not changing parameters */
1945 params.use_cts_prot = -1;
1946 params.use_short_preamble = -1;
1947 params.use_short_slot_time = -1;
1949 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
1950 params.use_cts_prot =
1951 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
1952 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
1953 params.use_short_preamble =
1954 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
1955 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
1956 params.use_short_slot_time =
1957 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
1958 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
1959 params.basic_rates =
1960 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1961 params.basic_rates_len =
1962 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1967 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1971 if (!drv->ops->change_bss) {
1976 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1981 err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms);
1984 cfg80211_put_dev(drv);
1992 static const struct nla_policy
1993 reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
1994 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
1995 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
1996 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
1997 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
1998 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
1999 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2002 static int parse_reg_rule(struct nlattr *tb[],
2003 struct ieee80211_reg_rule *reg_rule)
2005 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
2006 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
2008 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2010 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2012 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2014 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2016 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2019 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2021 freq_range->start_freq_khz =
2022 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2023 freq_range->end_freq_khz =
2024 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2025 freq_range->max_bandwidth_khz =
2026 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2028 power_rule->max_eirp =
2029 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2031 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2032 power_rule->max_antenna_gain =
2033 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2038 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2044 * You should only get this when cfg80211 hasn't yet initialized
2045 * completely when built-in to the kernel right between the time
2046 * window between nl80211_init() and regulatory_init(), if that is
2049 mutex_lock(&cfg80211_mutex);
2050 if (unlikely(!cfg80211_regdomain)) {
2051 mutex_unlock(&cfg80211_mutex);
2052 return -EINPROGRESS;
2054 mutex_unlock(&cfg80211_mutex);
2056 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2059 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2061 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2062 /* We ignore world regdom requests with the old regdom setup */
2063 if (is_world_regdom(data))
2067 r = regulatory_hint_user(data);
2072 static int nl80211_get_mesh_params(struct sk_buff *skb,
2073 struct genl_info *info)
2075 struct cfg80211_registered_device *drv;
2076 struct mesh_config cur_params;
2078 struct net_device *dev;
2080 struct nlattr *pinfoattr;
2081 struct sk_buff *msg;
2085 /* Look up our device */
2086 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2090 if (!drv->ops->get_mesh_params) {
2095 /* Get the mesh params */
2096 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params);
2100 /* Draw up a netlink message to send back */
2101 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2106 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2107 NL80211_CMD_GET_MESH_PARAMS);
2109 goto nla_put_failure;
2110 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS);
2112 goto nla_put_failure;
2113 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2114 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2115 cur_params.dot11MeshRetryTimeout);
2116 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2117 cur_params.dot11MeshConfirmTimeout);
2118 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2119 cur_params.dot11MeshHoldingTimeout);
2120 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2121 cur_params.dot11MeshMaxPeerLinks);
2122 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2123 cur_params.dot11MeshMaxRetries);
2124 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2125 cur_params.dot11MeshTTL);
2126 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2127 cur_params.auto_open_plinks);
2128 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2129 cur_params.dot11MeshHWMPmaxPREQretries);
2130 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2131 cur_params.path_refresh_time);
2132 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2133 cur_params.min_discovery_timeout);
2134 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2135 cur_params.dot11MeshHWMPactivePathTimeout);
2136 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2137 cur_params.dot11MeshHWMPpreqMinInterval);
2138 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2139 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
2140 nla_nest_end(msg, pinfoattr);
2141 genlmsg_end(msg, hdr);
2142 err = genlmsg_unicast(msg, info->snd_pid);
2146 genlmsg_cancel(msg, hdr);
2150 cfg80211_put_dev(drv);
2158 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2160 if (table[attr_num]) {\
2161 cfg.param = nla_fn(table[attr_num]); \
2162 mask |= (1 << (attr_num - 1)); \
2166 static struct nla_policy
2167 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = {
2168 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2169 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2170 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2171 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2172 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2173 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2174 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2176 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2177 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2178 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2179 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2180 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2181 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2184 static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2188 struct cfg80211_registered_device *drv;
2189 struct net_device *dev;
2190 struct mesh_config cfg;
2191 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2192 struct nlattr *parent_attr;
2194 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2197 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2198 parent_attr, nl80211_meshconf_params_policy))
2203 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2207 if (!drv->ops->set_mesh_params) {
2212 /* This makes sure that there aren't more than 32 mesh config
2213 * parameters (otherwise our bitfield scheme would not work.) */
2214 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2216 /* Fill in the params struct */
2218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2219 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2220 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2221 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2222 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2223 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2224 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2225 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2227 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2228 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2229 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2230 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2231 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2233 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2235 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2236 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2237 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2238 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2240 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2241 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2243 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2244 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2247 dot11MeshHWMPnetDiameterTraversalTime,
2248 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2252 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask);
2256 cfg80211_put_dev(drv);
2264 #undef FILL_IN_MESH_PARAM_IF_SET
2266 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2268 struct sk_buff *msg;
2270 struct nlattr *nl_reg_rules;
2274 mutex_lock(&cfg80211_mutex);
2276 if (!cfg80211_regdomain)
2279 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2285 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2286 NL80211_CMD_GET_REG);
2288 goto nla_put_failure;
2290 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2291 cfg80211_regdomain->alpha2);
2293 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2295 goto nla_put_failure;
2297 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2298 struct nlattr *nl_reg_rule;
2299 const struct ieee80211_reg_rule *reg_rule;
2300 const struct ieee80211_freq_range *freq_range;
2301 const struct ieee80211_power_rule *power_rule;
2303 reg_rule = &cfg80211_regdomain->reg_rules[i];
2304 freq_range = ®_rule->freq_range;
2305 power_rule = ®_rule->power_rule;
2307 nl_reg_rule = nla_nest_start(msg, i);
2309 goto nla_put_failure;
2311 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2313 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2314 freq_range->start_freq_khz);
2315 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2316 freq_range->end_freq_khz);
2317 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2318 freq_range->max_bandwidth_khz);
2319 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2320 power_rule->max_antenna_gain);
2321 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2322 power_rule->max_eirp);
2324 nla_nest_end(msg, nl_reg_rule);
2327 nla_nest_end(msg, nl_reg_rules);
2329 genlmsg_end(msg, hdr);
2330 err = genlmsg_unicast(msg, info->snd_pid);
2334 genlmsg_cancel(msg, hdr);
2337 mutex_unlock(&cfg80211_mutex);
2341 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2343 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
2344 struct nlattr *nl_reg_rule;
2345 char *alpha2 = NULL;
2346 int rem_reg_rules = 0, r = 0;
2347 u32 num_rules = 0, rule_idx = 0, size_of_regd;
2348 struct ieee80211_regdomain *rd = NULL;
2350 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2353 if (!info->attrs[NL80211_ATTR_REG_RULES])
2356 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2358 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2361 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
2365 if (!reg_is_valid_request(alpha2))
2368 size_of_regd = sizeof(struct ieee80211_regdomain) +
2369 (num_rules * sizeof(struct ieee80211_reg_rule));
2371 rd = kzalloc(size_of_regd, GFP_KERNEL);
2375 rd->n_reg_rules = num_rules;
2376 rd->alpha2[0] = alpha2[0];
2377 rd->alpha2[1] = alpha2[1];
2379 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2381 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
2382 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
2384 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
2390 if (rule_idx > NL80211_MAX_SUPP_REG_RULES)
2394 BUG_ON(rule_idx != num_rules);
2396 mutex_lock(&cfg80211_mutex);
2398 mutex_unlock(&cfg80211_mutex);
2406 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2408 struct cfg80211_registered_device *drv;
2409 struct net_device *dev;
2410 struct cfg80211_scan_request *request;
2411 struct cfg80211_ssid *ssid;
2412 struct ieee80211_channel *channel;
2413 struct nlattr *attr;
2414 struct wiphy *wiphy;
2415 int err, tmp, n_ssids = 0, n_channels = 0, i;
2416 enum ieee80211_band band;
2421 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2425 wiphy = &drv->wiphy;
2427 if (!drv->ops->scan) {
2432 if (!netif_running(dev)) {
2437 if (drv->scan_req) {
2442 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2443 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp)
2450 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2451 if (wiphy->bands[band])
2452 n_channels += wiphy->bands[band]->n_channels;
2455 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2456 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2459 if (n_ssids > wiphy->max_scan_ssids) {
2464 if (info->attrs[NL80211_ATTR_IE])
2465 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2469 request = kzalloc(sizeof(*request)
2470 + sizeof(*ssid) * n_ssids
2471 + sizeof(channel) * n_channels
2472 + ie_len, GFP_KERNEL);
2478 request->channels = (void *)((char *)request + sizeof(*request));
2479 request->n_channels = n_channels;
2481 request->ssids = (void *)(request->channels + n_channels);
2482 request->n_ssids = n_ssids;
2485 request->ie = (void *)(request->ssids + n_ssids);
2487 request->ie = (void *)(request->channels + n_channels);
2490 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2491 /* user specified, bail out if channel not found */
2492 request->n_channels = n_channels;
2494 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
2495 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2496 if (!request->channels[i]) {
2505 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2507 if (!wiphy->bands[band])
2509 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2510 request->channels[i] = &wiphy->bands[band]->channels[j];
2517 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2518 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2519 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2523 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
2524 request->ssids[i].ssid_len = nla_len(attr);
2529 if (info->attrs[NL80211_ATTR_IE]) {
2530 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2531 memcpy(request->ie, nla_data(info->attrs[NL80211_ATTR_IE]),
2535 request->ifidx = dev->ifindex;
2536 request->wiphy = &drv->wiphy;
2538 drv->scan_req = request;
2539 err = drv->ops->scan(&drv->wiphy, dev, request);
2543 drv->scan_req = NULL;
2547 cfg80211_put_dev(drv);
2555 static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
2556 struct cfg80211_registered_device *rdev,
2557 struct net_device *dev,
2558 struct cfg80211_bss *res)
2563 hdr = nl80211hdr_put(msg, pid, seq, flags,
2564 NL80211_CMD_NEW_SCAN_RESULTS);
2568 NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION,
2569 rdev->bss_generation);
2570 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2572 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
2574 goto nla_put_failure;
2575 if (!is_zero_ether_addr(res->bssid))
2576 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
2577 if (res->information_elements && res->len_information_elements)
2578 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
2579 res->len_information_elements,
2580 res->information_elements);
2582 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
2583 if (res->beacon_interval)
2584 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
2585 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
2586 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
2588 switch (rdev->wiphy.signal_type) {
2589 case CFG80211_SIGNAL_TYPE_MBM:
2590 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
2592 case CFG80211_SIGNAL_TYPE_UNSPEC:
2593 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
2599 nla_nest_end(msg, bss);
2601 return genlmsg_end(msg, hdr);
2604 genlmsg_cancel(msg, hdr);
2608 static int nl80211_dump_scan(struct sk_buff *skb,
2609 struct netlink_callback *cb)
2611 struct cfg80211_registered_device *dev;
2612 struct net_device *netdev;
2613 struct cfg80211_internal_bss *scan;
2614 int ifidx = cb->args[0];
2615 int start = cb->args[1], idx = 0;
2619 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
2620 nl80211_fam.attrbuf, nl80211_fam.maxattr,
2625 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2628 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2631 cb->args[0] = ifidx;
2634 netdev = dev_get_by_index(&init_net, ifidx);
2638 dev = cfg80211_get_dev_from_ifindex(ifidx);
2641 goto out_put_netdev;
2644 spin_lock_bh(&dev->bss_lock);
2645 cfg80211_bss_expire(dev);
2647 list_for_each_entry(scan, &dev->bss_list, list) {
2650 if (nl80211_send_bss(skb,
2651 NETLINK_CB(cb->skb).pid,
2652 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2653 dev, netdev, &scan->pub) < 0) {
2660 spin_unlock_bh(&dev->bss_lock);
2664 cfg80211_put_dev(dev);
2671 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
2673 return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM ||
2674 auth_type == NL80211_AUTHTYPE_SHARED_KEY ||
2675 auth_type == NL80211_AUTHTYPE_FT ||
2676 auth_type == NL80211_AUTHTYPE_NETWORK_EAP;
2679 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2681 struct cfg80211_registered_device *drv;
2682 struct net_device *dev;
2683 struct cfg80211_auth_request req;
2684 struct wiphy *wiphy;
2689 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2693 if (!drv->ops->auth) {
2698 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2703 if (!netif_running(dev)) {
2708 if (!info->attrs[NL80211_ATTR_MAC]) {
2713 wiphy = &drv->wiphy;
2714 memset(&req, 0, sizeof(req));
2716 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2718 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2719 req.chan = ieee80211_get_channel(
2721 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2728 if (info->attrs[NL80211_ATTR_SSID]) {
2729 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2730 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2733 if (info->attrs[NL80211_ATTR_IE]) {
2734 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2735 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2738 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2740 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
2741 if (!nl80211_valid_auth_type(req.auth_type)) {
2747 err = drv->ops->auth(&drv->wiphy, dev, &req);
2750 cfg80211_put_dev(drv);
2757 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2759 struct cfg80211_registered_device *drv;
2760 struct net_device *dev;
2761 struct cfg80211_assoc_request req;
2762 struct wiphy *wiphy;
2767 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2771 if (!drv->ops->assoc) {
2776 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2781 if (!netif_running(dev)) {
2786 if (!info->attrs[NL80211_ATTR_MAC] ||
2787 !info->attrs[NL80211_ATTR_SSID]) {
2792 wiphy = &drv->wiphy;
2793 memset(&req, 0, sizeof(req));
2795 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2797 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2798 req.chan = ieee80211_get_channel(
2800 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2807 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2808 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2810 if (info->attrs[NL80211_ATTR_IE]) {
2811 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2812 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2815 err = drv->ops->assoc(&drv->wiphy, dev, &req);
2818 cfg80211_put_dev(drv);
2825 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
2827 struct cfg80211_registered_device *drv;
2828 struct net_device *dev;
2829 struct cfg80211_deauth_request req;
2830 struct wiphy *wiphy;
2835 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2839 if (!drv->ops->deauth) {
2844 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2849 if (!netif_running(dev)) {
2854 if (!info->attrs[NL80211_ATTR_MAC]) {
2859 wiphy = &drv->wiphy;
2860 memset(&req, 0, sizeof(req));
2862 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2864 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
2866 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2867 if (req.reason_code == 0) {
2868 /* Reason Code 0 is reserved */
2874 if (info->attrs[NL80211_ATTR_IE]) {
2875 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2876 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2879 err = drv->ops->deauth(&drv->wiphy, dev, &req);
2882 cfg80211_put_dev(drv);
2889 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
2891 struct cfg80211_registered_device *drv;
2892 struct net_device *dev;
2893 struct cfg80211_disassoc_request req;
2894 struct wiphy *wiphy;
2899 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2903 if (!drv->ops->disassoc) {
2908 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2913 if (!netif_running(dev)) {
2918 if (!info->attrs[NL80211_ATTR_MAC]) {
2923 wiphy = &drv->wiphy;
2924 memset(&req, 0, sizeof(req));
2926 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2928 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
2930 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2931 if (req.reason_code == 0) {
2932 /* Reason Code 0 is reserved */
2938 if (info->attrs[NL80211_ATTR_IE]) {
2939 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2940 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2943 err = drv->ops->disassoc(&drv->wiphy, dev, &req);
2946 cfg80211_put_dev(drv);
2953 static struct genl_ops nl80211_ops[] = {
2955 .cmd = NL80211_CMD_GET_WIPHY,
2956 .doit = nl80211_get_wiphy,
2957 .dumpit = nl80211_dump_wiphy,
2958 .policy = nl80211_policy,
2959 /* can be retrieved by unprivileged users */
2962 .cmd = NL80211_CMD_SET_WIPHY,
2963 .doit = nl80211_set_wiphy,
2964 .policy = nl80211_policy,
2965 .flags = GENL_ADMIN_PERM,
2968 .cmd = NL80211_CMD_GET_INTERFACE,
2969 .doit = nl80211_get_interface,
2970 .dumpit = nl80211_dump_interface,
2971 .policy = nl80211_policy,
2972 /* can be retrieved by unprivileged users */
2975 .cmd = NL80211_CMD_SET_INTERFACE,
2976 .doit = nl80211_set_interface,
2977 .policy = nl80211_policy,
2978 .flags = GENL_ADMIN_PERM,
2981 .cmd = NL80211_CMD_NEW_INTERFACE,
2982 .doit = nl80211_new_interface,
2983 .policy = nl80211_policy,
2984 .flags = GENL_ADMIN_PERM,
2987 .cmd = NL80211_CMD_DEL_INTERFACE,
2988 .doit = nl80211_del_interface,
2989 .policy = nl80211_policy,
2990 .flags = GENL_ADMIN_PERM,
2993 .cmd = NL80211_CMD_GET_KEY,
2994 .doit = nl80211_get_key,
2995 .policy = nl80211_policy,
2996 .flags = GENL_ADMIN_PERM,
2999 .cmd = NL80211_CMD_SET_KEY,
3000 .doit = nl80211_set_key,
3001 .policy = nl80211_policy,
3002 .flags = GENL_ADMIN_PERM,
3005 .cmd = NL80211_CMD_NEW_KEY,
3006 .doit = nl80211_new_key,
3007 .policy = nl80211_policy,
3008 .flags = GENL_ADMIN_PERM,
3011 .cmd = NL80211_CMD_DEL_KEY,
3012 .doit = nl80211_del_key,
3013 .policy = nl80211_policy,
3014 .flags = GENL_ADMIN_PERM,
3017 .cmd = NL80211_CMD_SET_BEACON,
3018 .policy = nl80211_policy,
3019 .flags = GENL_ADMIN_PERM,
3020 .doit = nl80211_addset_beacon,
3023 .cmd = NL80211_CMD_NEW_BEACON,
3024 .policy = nl80211_policy,
3025 .flags = GENL_ADMIN_PERM,
3026 .doit = nl80211_addset_beacon,
3029 .cmd = NL80211_CMD_DEL_BEACON,
3030 .policy = nl80211_policy,
3031 .flags = GENL_ADMIN_PERM,
3032 .doit = nl80211_del_beacon,
3035 .cmd = NL80211_CMD_GET_STATION,
3036 .doit = nl80211_get_station,
3037 .dumpit = nl80211_dump_station,
3038 .policy = nl80211_policy,
3041 .cmd = NL80211_CMD_SET_STATION,
3042 .doit = nl80211_set_station,
3043 .policy = nl80211_policy,
3044 .flags = GENL_ADMIN_PERM,
3047 .cmd = NL80211_CMD_NEW_STATION,
3048 .doit = nl80211_new_station,
3049 .policy = nl80211_policy,
3050 .flags = GENL_ADMIN_PERM,
3053 .cmd = NL80211_CMD_DEL_STATION,
3054 .doit = nl80211_del_station,
3055 .policy = nl80211_policy,
3056 .flags = GENL_ADMIN_PERM,
3059 .cmd = NL80211_CMD_GET_MPATH,
3060 .doit = nl80211_get_mpath,
3061 .dumpit = nl80211_dump_mpath,
3062 .policy = nl80211_policy,
3063 .flags = GENL_ADMIN_PERM,
3066 .cmd = NL80211_CMD_SET_MPATH,
3067 .doit = nl80211_set_mpath,
3068 .policy = nl80211_policy,
3069 .flags = GENL_ADMIN_PERM,
3072 .cmd = NL80211_CMD_NEW_MPATH,
3073 .doit = nl80211_new_mpath,
3074 .policy = nl80211_policy,
3075 .flags = GENL_ADMIN_PERM,
3078 .cmd = NL80211_CMD_DEL_MPATH,
3079 .doit = nl80211_del_mpath,
3080 .policy = nl80211_policy,
3081 .flags = GENL_ADMIN_PERM,
3084 .cmd = NL80211_CMD_SET_BSS,
3085 .doit = nl80211_set_bss,
3086 .policy = nl80211_policy,
3087 .flags = GENL_ADMIN_PERM,
3090 .cmd = NL80211_CMD_GET_REG,
3091 .doit = nl80211_get_reg,
3092 .policy = nl80211_policy,
3093 /* can be retrieved by unprivileged users */
3096 .cmd = NL80211_CMD_SET_REG,
3097 .doit = nl80211_set_reg,
3098 .policy = nl80211_policy,
3099 .flags = GENL_ADMIN_PERM,
3102 .cmd = NL80211_CMD_REQ_SET_REG,
3103 .doit = nl80211_req_set_reg,
3104 .policy = nl80211_policy,
3105 .flags = GENL_ADMIN_PERM,
3108 .cmd = NL80211_CMD_GET_MESH_PARAMS,
3109 .doit = nl80211_get_mesh_params,
3110 .policy = nl80211_policy,
3111 /* can be retrieved by unprivileged users */
3114 .cmd = NL80211_CMD_SET_MESH_PARAMS,
3115 .doit = nl80211_set_mesh_params,
3116 .policy = nl80211_policy,
3117 .flags = GENL_ADMIN_PERM,
3120 .cmd = NL80211_CMD_TRIGGER_SCAN,
3121 .doit = nl80211_trigger_scan,
3122 .policy = nl80211_policy,
3123 .flags = GENL_ADMIN_PERM,
3126 .cmd = NL80211_CMD_GET_SCAN,
3127 .policy = nl80211_policy,
3128 .dumpit = nl80211_dump_scan,
3131 .cmd = NL80211_CMD_AUTHENTICATE,
3132 .doit = nl80211_authenticate,
3133 .policy = nl80211_policy,
3134 .flags = GENL_ADMIN_PERM,
3137 .cmd = NL80211_CMD_ASSOCIATE,
3138 .doit = nl80211_associate,
3139 .policy = nl80211_policy,
3140 .flags = GENL_ADMIN_PERM,
3143 .cmd = NL80211_CMD_DEAUTHENTICATE,
3144 .doit = nl80211_deauthenticate,
3145 .policy = nl80211_policy,
3146 .flags = GENL_ADMIN_PERM,
3149 .cmd = NL80211_CMD_DISASSOCIATE,
3150 .doit = nl80211_disassociate,
3151 .policy = nl80211_policy,
3152 .flags = GENL_ADMIN_PERM,
3155 static struct genl_multicast_group nl80211_mlme_mcgrp = {
3159 /* multicast groups */
3160 static struct genl_multicast_group nl80211_config_mcgrp = {
3163 static struct genl_multicast_group nl80211_scan_mcgrp = {
3166 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
3167 .name = "regulatory",
3170 /* notification functions */
3172 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
3174 struct sk_buff *msg;
3176 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3180 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
3185 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
3188 static int nl80211_send_scan_donemsg(struct sk_buff *msg,
3189 struct cfg80211_registered_device *rdev,
3190 struct net_device *netdev,
3191 u32 pid, u32 seq, int flags,
3196 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
3200 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3201 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3203 /* XXX: we should probably bounce back the request? */
3205 return genlmsg_end(msg, hdr);
3208 genlmsg_cancel(msg, hdr);
3212 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3213 struct net_device *netdev)
3215 struct sk_buff *msg;
3217 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3221 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3222 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
3227 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3230 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
3231 struct net_device *netdev)
3233 struct sk_buff *msg;
3235 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3239 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3240 NL80211_CMD_SCAN_ABORTED) < 0) {
3245 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3249 * This can happen on global regulatory changes or device specific settings
3250 * based on custom world regulatory domains.
3252 void nl80211_send_reg_change_event(struct regulatory_request *request)
3254 struct sk_buff *msg;
3257 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3261 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
3267 /* Userspace can always count this one always being set */
3268 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
3270 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
3271 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3272 NL80211_REGDOM_TYPE_WORLD);
3273 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
3274 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3275 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
3276 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
3278 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3279 NL80211_REGDOM_TYPE_INTERSECTION);
3281 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3282 NL80211_REGDOM_TYPE_COUNTRY);
3283 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
3286 if (wiphy_idx_valid(request->wiphy_idx))
3287 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
3289 if (genlmsg_end(msg, hdr) < 0) {
3294 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL);
3299 genlmsg_cancel(msg, hdr);
3303 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3304 struct net_device *netdev,
3305 const u8 *buf, size_t len,
3306 enum nl80211_commands cmd)
3308 struct sk_buff *msg;
3311 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3315 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3321 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3322 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3323 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
3325 if (genlmsg_end(msg, hdr) < 0) {
3330 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3334 genlmsg_cancel(msg, hdr);
3338 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3339 struct net_device *netdev, const u8 *buf, size_t len)
3341 nl80211_send_mlme_event(rdev, netdev, buf, len,
3342 NL80211_CMD_AUTHENTICATE);
3345 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3346 struct net_device *netdev, const u8 *buf,
3349 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3352 void nl80211_send_rx_deauth(struct cfg80211_registered_device *rdev,
3353 struct net_device *netdev, const u8 *buf,
3356 nl80211_send_mlme_event(rdev, netdev, buf, len,
3357 NL80211_CMD_DEAUTHENTICATE);
3360 void nl80211_send_rx_disassoc(struct cfg80211_registered_device *rdev,
3361 struct net_device *netdev, const u8 *buf,
3364 nl80211_send_mlme_event(rdev, netdev, buf, len,
3365 NL80211_CMD_DISASSOCIATE);
3368 /* initialisation/exit functions */
3370 int nl80211_init(void)
3374 err = genl_register_family(&nl80211_fam);
3378 for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) {
3379 err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]);
3384 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
3388 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
3392 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
3396 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
3402 genl_unregister_family(&nl80211_fam);
3406 void nl80211_exit(void)
3408 genl_unregister_family(&nl80211_fam);