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/mutex.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <net/genetlink.h>
18 #include <net/cfg80211.h>
22 /* the netlink family */
23 static struct genl_family nl80211_fam = {
24 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
25 .name = "nl80211", /* have users key off the name instead */
26 .hdrsize = 0, /* no private header */
27 .version = 1, /* no particular meaning now */
28 .maxattr = NL80211_ATTR_MAX,
31 /* internal helper: get drv and dev */
32 static int get_drv_dev_by_info_ifindex(struct genl_info *info,
33 struct cfg80211_registered_device **drv,
34 struct net_device **dev)
38 if (!info->attrs[NL80211_ATTR_IFINDEX])
41 ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
42 *dev = dev_get_by_index(&init_net, ifindex);
46 *drv = cfg80211_get_dev_from_ifindex(ifindex);
55 /* policy for the attributes */
56 static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
57 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
58 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
59 .len = BUS_ID_SIZE-1 },
61 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
62 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
63 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
65 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
67 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
68 .len = WLAN_MAX_KEY_LEN },
69 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
70 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
71 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
73 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
74 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
75 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
76 .len = IEEE80211_MAX_DATA_LEN },
77 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
78 .len = IEEE80211_MAX_DATA_LEN },
79 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
80 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
81 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
82 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
83 .len = NL80211_MAX_SUPP_RATES },
84 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
87 /* message building helper */
88 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
91 /* since there is no private header just add the generic one */
92 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
95 /* netlink command implementations */
97 static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
98 struct cfg80211_registered_device *dev)
101 struct nlattr *nl_bands, *nl_band;
102 struct nlattr *nl_freqs, *nl_freq;
103 struct nlattr *nl_rates, *nl_rate;
104 enum ieee80211_band band;
105 struct ieee80211_channel *chan;
106 struct ieee80211_rate *rate;
109 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
113 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->idx);
114 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
116 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
118 goto nla_put_failure;
120 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
121 if (!dev->wiphy.bands[band])
124 nl_band = nla_nest_start(msg, band);
126 goto nla_put_failure;
128 /* add frequencies */
129 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
131 goto nla_put_failure;
133 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
134 nl_freq = nla_nest_start(msg, i);
136 goto nla_put_failure;
138 chan = &dev->wiphy.bands[band]->channels[i];
139 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
142 if (chan->flags & IEEE80211_CHAN_DISABLED)
143 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
144 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
145 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
146 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
147 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
148 if (chan->flags & IEEE80211_CHAN_RADAR)
149 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
151 nla_nest_end(msg, nl_freq);
154 nla_nest_end(msg, nl_freqs);
157 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
159 goto nla_put_failure;
161 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
162 nl_rate = nla_nest_start(msg, i);
164 goto nla_put_failure;
166 rate = &dev->wiphy.bands[band]->bitrates[i];
167 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
169 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
171 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
173 nla_nest_end(msg, nl_rate);
176 nla_nest_end(msg, nl_rates);
178 nla_nest_end(msg, nl_band);
180 nla_nest_end(msg, nl_bands);
182 return genlmsg_end(msg, hdr);
185 return genlmsg_cancel(msg, hdr);
188 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
191 int start = cb->args[0];
192 struct cfg80211_registered_device *dev;
194 mutex_lock(&cfg80211_drv_mutex);
195 list_for_each_entry(dev, &cfg80211_drv_list, list) {
198 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
199 cb->nlh->nlmsg_seq, NLM_F_MULTI,
203 mutex_unlock(&cfg80211_drv_mutex);
210 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
213 struct cfg80211_registered_device *dev;
215 dev = cfg80211_get_dev_from_info(info);
219 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
223 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
226 cfg80211_put_dev(dev);
228 return genlmsg_unicast(msg, info->snd_pid);
233 cfg80211_put_dev(dev);
237 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
239 struct cfg80211_registered_device *rdev;
242 if (!info->attrs[NL80211_ATTR_WIPHY_NAME])
245 rdev = cfg80211_get_dev_from_info(info);
247 return PTR_ERR(rdev);
249 result = cfg80211_dev_rename(rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
251 cfg80211_put_dev(rdev);
256 static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
257 struct net_device *dev)
261 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
265 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
266 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
267 /* TODO: interface type */
268 return genlmsg_end(msg, hdr);
271 return genlmsg_cancel(msg, hdr);
274 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
278 int wp_start = cb->args[0];
279 int if_start = cb->args[1];
280 struct cfg80211_registered_device *dev;
281 struct wireless_dev *wdev;
283 mutex_lock(&cfg80211_drv_mutex);
284 list_for_each_entry(dev, &cfg80211_drv_list, list) {
285 if (++wp_idx < wp_start)
289 mutex_lock(&dev->devlist_mtx);
290 list_for_each_entry(wdev, &dev->netdev_list, list) {
291 if (++if_idx < if_start)
293 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
294 cb->nlh->nlmsg_seq, NLM_F_MULTI,
298 mutex_unlock(&dev->devlist_mtx);
300 mutex_unlock(&cfg80211_drv_mutex);
302 cb->args[0] = wp_idx;
303 cb->args[1] = if_idx;
308 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
311 struct cfg80211_registered_device *dev;
312 struct net_device *netdev;
315 err = get_drv_dev_by_info_ifindex(info, &dev, &netdev);
319 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
323 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0)
327 cfg80211_put_dev(dev);
329 return genlmsg_unicast(msg, info->snd_pid);
335 cfg80211_put_dev(dev);
339 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
341 struct cfg80211_registered_device *drv;
343 enum nl80211_iftype type;
344 struct net_device *dev;
346 if (info->attrs[NL80211_ATTR_IFTYPE]) {
347 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
348 if (type > NL80211_IFTYPE_MAX)
353 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
356 ifindex = dev->ifindex;
359 if (!drv->ops->change_virtual_intf) {
365 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, type);
369 cfg80211_put_dev(drv);
373 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
375 struct cfg80211_registered_device *drv;
377 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
379 if (!info->attrs[NL80211_ATTR_IFNAME])
382 if (info->attrs[NL80211_ATTR_IFTYPE]) {
383 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
384 if (type > NL80211_IFTYPE_MAX)
388 drv = cfg80211_get_dev_from_info(info);
392 if (!drv->ops->add_virtual_intf) {
398 err = drv->ops->add_virtual_intf(&drv->wiphy,
399 nla_data(info->attrs[NL80211_ATTR_IFNAME]), type);
403 cfg80211_put_dev(drv);
407 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
409 struct cfg80211_registered_device *drv;
411 struct net_device *dev;
413 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
416 ifindex = dev->ifindex;
419 if (!drv->ops->del_virtual_intf) {
425 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
429 cfg80211_put_dev(drv);
433 struct get_key_cookie {
438 static void get_key_callback(void *c, struct key_params *params)
440 struct get_key_cookie *cookie = c;
443 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
444 params->key_len, params->key);
447 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
448 params->seq_len, params->seq);
451 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
459 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
461 struct cfg80211_registered_device *drv;
463 struct net_device *dev;
466 struct get_key_cookie cookie = {
472 if (info->attrs[NL80211_ATTR_KEY_IDX])
473 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
478 if (info->attrs[NL80211_ATTR_MAC])
479 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
481 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
485 if (!drv->ops->get_key) {
490 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
496 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
497 NL80211_CMD_NEW_KEY);
506 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
507 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
509 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
512 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr,
513 &cookie, get_key_callback);
520 goto nla_put_failure;
522 genlmsg_end(msg, hdr);
523 err = genlmsg_unicast(msg, info->snd_pid);
530 cfg80211_put_dev(drv);
535 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
537 struct cfg80211_registered_device *drv;
539 struct net_device *dev;
542 if (!info->attrs[NL80211_ATTR_KEY_IDX])
545 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
550 /* currently only support setting default key */
551 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT])
554 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
558 if (!drv->ops->set_default_key) {
564 err = drv->ops->set_default_key(&drv->wiphy, dev, key_idx);
568 cfg80211_put_dev(drv);
573 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
575 struct cfg80211_registered_device *drv;
577 struct net_device *dev;
578 struct key_params params;
582 memset(¶ms, 0, sizeof(params));
584 if (!info->attrs[NL80211_ATTR_KEY_CIPHER])
587 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
588 params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
589 params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
592 if (info->attrs[NL80211_ATTR_KEY_IDX])
593 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
595 params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
597 if (info->attrs[NL80211_ATTR_MAC])
598 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
604 * Disallow pairwise keys with non-zero index unless it's WEP
605 * (because current deployments use pairwise WEP keys with
606 * non-zero indizes but 802.11i clearly specifies to use zero)
608 if (mac_addr && key_idx &&
609 params.cipher != WLAN_CIPHER_SUITE_WEP40 &&
610 params.cipher != WLAN_CIPHER_SUITE_WEP104)
613 /* TODO: add definitions for the lengths to linux/ieee80211.h */
614 switch (params.cipher) {
615 case WLAN_CIPHER_SUITE_WEP40:
616 if (params.key_len != 5)
619 case WLAN_CIPHER_SUITE_TKIP:
620 if (params.key_len != 32)
623 case WLAN_CIPHER_SUITE_CCMP:
624 if (params.key_len != 16)
627 case WLAN_CIPHER_SUITE_WEP104:
628 if (params.key_len != 13)
635 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
639 if (!drv->ops->add_key) {
645 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms);
649 cfg80211_put_dev(drv);
654 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
656 struct cfg80211_registered_device *drv;
658 struct net_device *dev;
662 if (info->attrs[NL80211_ATTR_KEY_IDX])
663 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
668 if (info->attrs[NL80211_ATTR_MAC])
669 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
671 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
675 if (!drv->ops->del_key) {
681 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr);
685 cfg80211_put_dev(drv);
690 static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
692 int (*call)(struct wiphy *wiphy, struct net_device *dev,
693 struct beacon_parameters *info);
694 struct cfg80211_registered_device *drv;
696 struct net_device *dev;
697 struct beacon_parameters params;
700 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
704 switch (info->genlhdr->cmd) {
705 case NL80211_CMD_NEW_BEACON:
706 /* these are required for NEW_BEACON */
707 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
708 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
709 !info->attrs[NL80211_ATTR_BEACON_HEAD]) {
714 call = drv->ops->add_beacon;
716 case NL80211_CMD_SET_BEACON:
717 call = drv->ops->set_beacon;
730 memset(¶ms, 0, sizeof(params));
732 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
734 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
738 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
740 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
744 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
745 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
747 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
751 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
752 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
754 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
764 err = call(&drv->wiphy, dev, ¶ms);
768 cfg80211_put_dev(drv);
773 static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
775 struct cfg80211_registered_device *drv;
777 struct net_device *dev;
779 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
783 if (!drv->ops->del_beacon) {
789 err = drv->ops->del_beacon(&drv->wiphy, dev);
793 cfg80211_put_dev(drv);
798 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
799 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
800 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
801 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
804 static int parse_station_flags(struct nlattr *nla, u32 *staflags)
806 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
814 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
815 nla, sta_flags_policy))
818 *staflags = STATION_FLAG_CHANGED;
820 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
822 *staflags |= (1<<flag);
827 static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
828 int flags, struct net_device *dev,
829 u8 *mac_addr, struct station_stats *stats)
832 struct nlattr *statsattr;
834 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
838 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
839 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
841 statsattr = nla_nest_start(msg, NL80211_ATTR_STA_STATS);
843 goto nla_put_failure;
844 if (stats->filled & STATION_STAT_INACTIVE_TIME)
845 NLA_PUT_U32(msg, NL80211_STA_STAT_INACTIVE_TIME,
846 stats->inactive_time);
847 if (stats->filled & STATION_STAT_RX_BYTES)
848 NLA_PUT_U32(msg, NL80211_STA_STAT_RX_BYTES,
850 if (stats->filled & STATION_STAT_TX_BYTES)
851 NLA_PUT_U32(msg, NL80211_STA_STAT_TX_BYTES,
854 nla_nest_end(msg, statsattr);
856 return genlmsg_end(msg, hdr);
859 return genlmsg_cancel(msg, hdr);
863 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
865 struct cfg80211_registered_device *drv;
867 struct net_device *dev;
868 struct station_stats stats;
872 memset(&stats, 0, sizeof(stats));
874 if (!info->attrs[NL80211_ATTR_MAC])
877 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
879 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
883 if (!drv->ops->get_station) {
889 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &stats);
892 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
896 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
897 dev, mac_addr, &stats) < 0)
900 err = genlmsg_unicast(msg, info->snd_pid);
907 cfg80211_put_dev(drv);
913 * Get vlan interface making sure it is on the right wiphy.
915 static int get_vlan(struct nlattr *vlanattr,
916 struct cfg80211_registered_device *rdev,
917 struct net_device **vlan)
922 *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr));
925 if (!(*vlan)->ieee80211_ptr)
927 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
933 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
935 struct cfg80211_registered_device *drv;
937 struct net_device *dev;
938 struct station_parameters params;
941 memset(¶ms, 0, sizeof(params));
943 params.listen_interval = -1;
945 if (info->attrs[NL80211_ATTR_STA_AID])
948 if (!info->attrs[NL80211_ATTR_MAC])
951 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
953 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
954 params.supported_rates =
955 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
956 params.supported_rates_len =
957 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
960 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
961 params.listen_interval =
962 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
964 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
965 ¶ms.station_flags))
968 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
972 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
976 if (!drv->ops->change_station) {
982 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms);
987 dev_put(params.vlan);
988 cfg80211_put_dev(drv);
993 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
995 struct cfg80211_registered_device *drv;
997 struct net_device *dev;
998 struct station_parameters params;
1001 memset(¶ms, 0, sizeof(params));
1003 if (!info->attrs[NL80211_ATTR_MAC])
1006 if (!info->attrs[NL80211_ATTR_STA_AID])
1009 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1012 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
1015 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1016 params.supported_rates =
1017 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1018 params.supported_rates_len =
1019 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1020 params.listen_interval =
1021 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1022 params.listen_interval = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
1024 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1025 ¶ms.station_flags))
1028 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
1032 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan);
1036 if (!drv->ops->add_station) {
1042 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms);
1047 dev_put(params.vlan);
1048 cfg80211_put_dev(drv);
1053 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1055 struct cfg80211_registered_device *drv;
1057 struct net_device *dev;
1058 u8 *mac_addr = NULL;
1060 if (info->attrs[NL80211_ATTR_MAC])
1061 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1063 err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
1067 if (!drv->ops->del_station) {
1073 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr);
1077 cfg80211_put_dev(drv);
1082 static struct genl_ops nl80211_ops[] = {
1084 .cmd = NL80211_CMD_GET_WIPHY,
1085 .doit = nl80211_get_wiphy,
1086 .dumpit = nl80211_dump_wiphy,
1087 .policy = nl80211_policy,
1088 /* can be retrieved by unprivileged users */
1091 .cmd = NL80211_CMD_SET_WIPHY,
1092 .doit = nl80211_set_wiphy,
1093 .policy = nl80211_policy,
1094 .flags = GENL_ADMIN_PERM,
1097 .cmd = NL80211_CMD_GET_INTERFACE,
1098 .doit = nl80211_get_interface,
1099 .dumpit = nl80211_dump_interface,
1100 .policy = nl80211_policy,
1101 /* can be retrieved by unprivileged users */
1104 .cmd = NL80211_CMD_SET_INTERFACE,
1105 .doit = nl80211_set_interface,
1106 .policy = nl80211_policy,
1107 .flags = GENL_ADMIN_PERM,
1110 .cmd = NL80211_CMD_NEW_INTERFACE,
1111 .doit = nl80211_new_interface,
1112 .policy = nl80211_policy,
1113 .flags = GENL_ADMIN_PERM,
1116 .cmd = NL80211_CMD_DEL_INTERFACE,
1117 .doit = nl80211_del_interface,
1118 .policy = nl80211_policy,
1119 .flags = GENL_ADMIN_PERM,
1122 .cmd = NL80211_CMD_GET_KEY,
1123 .doit = nl80211_get_key,
1124 .policy = nl80211_policy,
1125 .flags = GENL_ADMIN_PERM,
1128 .cmd = NL80211_CMD_SET_KEY,
1129 .doit = nl80211_set_key,
1130 .policy = nl80211_policy,
1131 .flags = GENL_ADMIN_PERM,
1134 .cmd = NL80211_CMD_NEW_KEY,
1135 .doit = nl80211_new_key,
1136 .policy = nl80211_policy,
1137 .flags = GENL_ADMIN_PERM,
1140 .cmd = NL80211_CMD_DEL_KEY,
1141 .doit = nl80211_del_key,
1142 .policy = nl80211_policy,
1143 .flags = GENL_ADMIN_PERM,
1146 .cmd = NL80211_CMD_SET_BEACON,
1147 .policy = nl80211_policy,
1148 .flags = GENL_ADMIN_PERM,
1149 .doit = nl80211_addset_beacon,
1152 .cmd = NL80211_CMD_NEW_BEACON,
1153 .policy = nl80211_policy,
1154 .flags = GENL_ADMIN_PERM,
1155 .doit = nl80211_addset_beacon,
1158 .cmd = NL80211_CMD_DEL_BEACON,
1159 .policy = nl80211_policy,
1160 .flags = GENL_ADMIN_PERM,
1161 .doit = nl80211_del_beacon,
1164 .cmd = NL80211_CMD_GET_STATION,
1165 .doit = nl80211_get_station,
1166 /* TODO: implement dumpit */
1167 .policy = nl80211_policy,
1168 .flags = GENL_ADMIN_PERM,
1171 .cmd = NL80211_CMD_SET_STATION,
1172 .doit = nl80211_set_station,
1173 .policy = nl80211_policy,
1174 .flags = GENL_ADMIN_PERM,
1177 .cmd = NL80211_CMD_NEW_STATION,
1178 .doit = nl80211_new_station,
1179 .policy = nl80211_policy,
1180 .flags = GENL_ADMIN_PERM,
1183 .cmd = NL80211_CMD_DEL_STATION,
1184 .doit = nl80211_del_station,
1185 .policy = nl80211_policy,
1186 .flags = GENL_ADMIN_PERM,
1190 /* multicast groups */
1191 static struct genl_multicast_group nl80211_config_mcgrp = {
1195 /* notification functions */
1197 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
1199 struct sk_buff *msg;
1201 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1205 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
1210 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
1213 /* initialisation/exit functions */
1215 int nl80211_init(void)
1219 err = genl_register_family(&nl80211_fam);
1223 for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) {
1224 err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]);
1229 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
1235 genl_unregister_family(&nl80211_fam);
1239 void nl80211_exit(void)
1241 genl_unregister_family(&nl80211_fam);