2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
6 * This file is GPLv2 as found in COPYING.
9 #include <linux/ieee80211.h>
10 #include <linux/nl80211.h>
11 #include <linux/rtnetlink.h>
12 #include <net/net_namespace.h>
13 #include <linux/rcupdate.h>
14 #include <net/cfg80211.h>
15 #include "ieee80211_i.h"
16 #include "driver-ops.h"
21 static bool nl80211_type_check(enum nl80211_iftype type)
24 case NL80211_IFTYPE_ADHOC:
25 case NL80211_IFTYPE_STATION:
26 case NL80211_IFTYPE_MONITOR:
27 #ifdef CONFIG_MAC80211_MESH
28 case NL80211_IFTYPE_MESH_POINT:
30 case NL80211_IFTYPE_AP:
31 case NL80211_IFTYPE_AP_VLAN:
32 case NL80211_IFTYPE_WDS:
39 static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
40 enum nl80211_iftype type, u32 *flags,
41 struct vif_params *params)
43 struct ieee80211_local *local = wiphy_priv(wiphy);
44 struct net_device *dev;
45 struct ieee80211_sub_if_data *sdata;
48 if (!nl80211_type_check(type))
51 err = ieee80211_if_add(local, name, &dev, type, params);
52 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
55 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
56 sdata->u.mntr_flags = *flags;
60 static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
62 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
67 static int ieee80211_change_iface(struct wiphy *wiphy,
68 struct net_device *dev,
69 enum nl80211_iftype type, u32 *flags,
70 struct vif_params *params)
72 struct ieee80211_sub_if_data *sdata;
75 if (!nl80211_type_check(type))
78 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
80 ret = ieee80211_if_change_type(sdata, type);
84 if (netif_running(sdata->dev))
87 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
88 ieee80211_sdata_set_mesh_id(sdata,
92 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
95 sdata->u.mntr_flags = *flags;
99 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
100 u8 key_idx, const u8 *mac_addr,
101 struct key_params *params)
103 struct ieee80211_sub_if_data *sdata;
104 struct sta_info *sta = NULL;
105 enum ieee80211_key_alg alg;
106 struct ieee80211_key *key;
109 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
111 switch (params->cipher) {
112 case WLAN_CIPHER_SUITE_WEP40:
113 case WLAN_CIPHER_SUITE_WEP104:
116 case WLAN_CIPHER_SUITE_TKIP:
119 case WLAN_CIPHER_SUITE_CCMP:
122 case WLAN_CIPHER_SUITE_AES_CMAC:
129 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key,
130 params->seq_len, params->seq);
137 sta = sta_info_get(sdata->local, mac_addr);
139 ieee80211_key_free(key);
145 ieee80211_key_link(key, sdata, sta);
154 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
155 u8 key_idx, const u8 *mac_addr)
157 struct ieee80211_sub_if_data *sdata;
158 struct sta_info *sta;
161 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
168 sta = sta_info_get(sdata->local, mac_addr);
173 ieee80211_key_free(sta->key);
181 if (!sdata->keys[key_idx]) {
186 ieee80211_key_free(sdata->keys[key_idx]);
187 WARN_ON(sdata->keys[key_idx]);
196 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
197 u8 key_idx, const u8 *mac_addr, void *cookie,
198 void (*callback)(void *cookie,
199 struct key_params *params))
201 struct ieee80211_sub_if_data *sdata;
202 struct sta_info *sta = NULL;
204 struct key_params params;
205 struct ieee80211_key *key;
210 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
215 sta = sta_info_get(sdata->local, mac_addr);
221 key = sdata->keys[key_idx];
226 memset(¶ms, 0, sizeof(params));
228 switch (key->conf.alg) {
230 params.cipher = WLAN_CIPHER_SUITE_TKIP;
232 iv32 = key->u.tkip.tx.iv32;
233 iv16 = key->u.tkip.tx.iv16;
235 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
236 drv_get_tkip_seq(sdata->local,
237 key->conf.hw_key_idx,
240 seq[0] = iv16 & 0xff;
241 seq[1] = (iv16 >> 8) & 0xff;
242 seq[2] = iv32 & 0xff;
243 seq[3] = (iv32 >> 8) & 0xff;
244 seq[4] = (iv32 >> 16) & 0xff;
245 seq[5] = (iv32 >> 24) & 0xff;
250 params.cipher = WLAN_CIPHER_SUITE_CCMP;
251 seq[0] = key->u.ccmp.tx_pn[5];
252 seq[1] = key->u.ccmp.tx_pn[4];
253 seq[2] = key->u.ccmp.tx_pn[3];
254 seq[3] = key->u.ccmp.tx_pn[2];
255 seq[4] = key->u.ccmp.tx_pn[1];
256 seq[5] = key->u.ccmp.tx_pn[0];
261 if (key->conf.keylen == 5)
262 params.cipher = WLAN_CIPHER_SUITE_WEP40;
264 params.cipher = WLAN_CIPHER_SUITE_WEP104;
267 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
268 seq[0] = key->u.aes_cmac.tx_pn[5];
269 seq[1] = key->u.aes_cmac.tx_pn[4];
270 seq[2] = key->u.aes_cmac.tx_pn[3];
271 seq[3] = key->u.aes_cmac.tx_pn[2];
272 seq[4] = key->u.aes_cmac.tx_pn[1];
273 seq[5] = key->u.aes_cmac.tx_pn[0];
279 params.key = key->conf.key;
280 params.key_len = key->conf.keylen;
282 callback(cookie, ¶ms);
290 static int ieee80211_config_default_key(struct wiphy *wiphy,
291 struct net_device *dev,
294 struct ieee80211_sub_if_data *sdata;
298 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
299 ieee80211_set_default_key(sdata, key_idx);
306 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
307 struct net_device *dev,
310 struct ieee80211_sub_if_data *sdata;
314 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
315 ieee80211_set_default_mgmt_key(sdata, key_idx);
322 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
324 struct ieee80211_sub_if_data *sdata = sta->sdata;
326 sinfo->filled = STATION_INFO_INACTIVE_TIME |
327 STATION_INFO_RX_BYTES |
328 STATION_INFO_TX_BYTES |
329 STATION_INFO_RX_PACKETS |
330 STATION_INFO_TX_PACKETS |
331 STATION_INFO_TX_BITRATE;
333 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
334 sinfo->rx_bytes = sta->rx_bytes;
335 sinfo->tx_bytes = sta->tx_bytes;
336 sinfo->rx_packets = sta->rx_packets;
337 sinfo->tx_packets = sta->tx_packets;
339 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
340 sinfo->filled |= STATION_INFO_SIGNAL;
341 sinfo->signal = (s8)sta->last_signal;
344 sinfo->txrate.flags = 0;
345 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
346 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
347 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
348 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
349 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
350 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
352 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
353 struct ieee80211_supported_band *sband;
354 sband = sta->local->hw.wiphy->bands[
355 sta->local->hw.conf.channel->band];
356 sinfo->txrate.legacy =
357 sband->bitrates[sta->last_tx_rate.idx].bitrate;
359 sinfo->txrate.mcs = sta->last_tx_rate.idx;
361 if (ieee80211_vif_is_mesh(&sdata->vif)) {
362 #ifdef CONFIG_MAC80211_MESH
363 sinfo->filled |= STATION_INFO_LLID |
365 STATION_INFO_PLINK_STATE;
367 sinfo->llid = le16_to_cpu(sta->llid);
368 sinfo->plid = le16_to_cpu(sta->plid);
369 sinfo->plink_state = sta->plink_state;
375 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
376 int idx, u8 *mac, struct station_info *sinfo)
378 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
379 struct sta_info *sta;
384 sta = sta_info_get_by_idx(local, idx, dev);
387 memcpy(mac, sta->sta.addr, ETH_ALEN);
388 sta_set_sinfo(sta, sinfo);
396 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
397 u8 *mac, struct station_info *sinfo)
399 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
400 struct sta_info *sta;
405 /* XXX: verify sta->dev == dev */
407 sta = sta_info_get(local, mac);
410 sta_set_sinfo(sta, sinfo);
419 * This handles both adding a beacon and setting new beacon info
421 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
422 struct beacon_parameters *params)
424 struct beacon_data *new, *old;
425 int new_head_len, new_tail_len;
429 old = sdata->u.ap.beacon;
431 /* head must not be zero-length */
432 if (params->head && !params->head_len)
436 * This is a kludge. beacon interval should really be part
437 * of the beacon information.
439 if (params->interval &&
440 (sdata->vif.bss_conf.beacon_int != params->interval)) {
441 sdata->vif.bss_conf.beacon_int = params->interval;
442 ieee80211_bss_info_change_notify(sdata,
443 BSS_CHANGED_BEACON_INT);
446 /* Need to have a beacon head if we don't have one yet */
447 if (!params->head && !old)
450 /* sorry, no way to start beaconing without dtim period */
451 if (!params->dtim_period && !old)
454 /* new or old head? */
456 new_head_len = params->head_len;
458 new_head_len = old->head_len;
460 /* new or old tail? */
461 if (params->tail || !old)
462 /* params->tail_len will be zero for !params->tail */
463 new_tail_len = params->tail_len;
465 new_tail_len = old->tail_len;
467 size = sizeof(*new) + new_head_len + new_tail_len;
469 new = kzalloc(size, GFP_KERNEL);
473 /* start filling the new info now */
475 /* new or old dtim period? */
476 if (params->dtim_period)
477 new->dtim_period = params->dtim_period;
479 new->dtim_period = old->dtim_period;
482 * pointers go into the block we allocated,
483 * memory is | beacon_data | head | tail |
485 new->head = ((u8 *) new) + sizeof(*new);
486 new->tail = new->head + new_head_len;
487 new->head_len = new_head_len;
488 new->tail_len = new_tail_len;
492 memcpy(new->head, params->head, new_head_len);
494 memcpy(new->head, old->head, new_head_len);
496 /* copy in optional tail */
498 memcpy(new->tail, params->tail, new_tail_len);
501 memcpy(new->tail, old->tail, new_tail_len);
503 rcu_assign_pointer(sdata->u.ap.beacon, new);
509 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
514 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
515 struct beacon_parameters *params)
517 struct ieee80211_sub_if_data *sdata;
518 struct beacon_data *old;
520 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
522 old = sdata->u.ap.beacon;
527 return ieee80211_config_beacon(sdata, params);
530 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
531 struct beacon_parameters *params)
533 struct ieee80211_sub_if_data *sdata;
534 struct beacon_data *old;
536 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
538 old = sdata->u.ap.beacon;
543 return ieee80211_config_beacon(sdata, params);
546 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
548 struct ieee80211_sub_if_data *sdata;
549 struct beacon_data *old;
551 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
553 old = sdata->u.ap.beacon;
558 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
562 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
566 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
567 struct iapp_layer2_update {
568 u8 da[ETH_ALEN]; /* broadcast */
569 u8 sa[ETH_ALEN]; /* STA addr */
575 } __attribute__ ((packed));
577 static void ieee80211_send_layer2_update(struct sta_info *sta)
579 struct iapp_layer2_update *msg;
582 /* Send Level 2 Update Frame to update forwarding tables in layer 2
585 skb = dev_alloc_skb(sizeof(*msg));
588 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
590 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
591 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
593 memset(msg->da, 0xff, ETH_ALEN);
594 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
597 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
598 msg->control = 0xaf; /* XID response lsb.1111F101.
599 * F=0 (no poll command; unsolicited frame) */
600 msg->xid_info[0] = 0x81; /* XID format identifier */
601 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
602 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
604 skb->dev = sta->sdata->dev;
605 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
606 memset(skb->cb, 0, sizeof(skb->cb));
610 static void sta_apply_parameters(struct ieee80211_local *local,
611 struct sta_info *sta,
612 struct station_parameters *params)
616 struct ieee80211_supported_band *sband;
617 struct ieee80211_sub_if_data *sdata = sta->sdata;
620 sband = local->hw.wiphy->bands[local->oper_channel->band];
622 spin_lock_bh(&sta->lock);
623 mask = params->sta_flags_mask;
624 set = params->sta_flags_set;
626 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
627 sta->flags &= ~WLAN_STA_AUTHORIZED;
628 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
629 sta->flags |= WLAN_STA_AUTHORIZED;
632 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
633 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
634 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
635 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
638 if (mask & BIT(NL80211_STA_FLAG_WME)) {
639 sta->flags &= ~WLAN_STA_WME;
640 if (set & BIT(NL80211_STA_FLAG_WME))
641 sta->flags |= WLAN_STA_WME;
644 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
645 sta->flags &= ~WLAN_STA_MFP;
646 if (set & BIT(NL80211_STA_FLAG_MFP))
647 sta->flags |= WLAN_STA_MFP;
649 spin_unlock_bh(&sta->lock);
652 * cfg80211 validates this (1-2007) and allows setting the AID
653 * only when creating a new station entry
656 sta->sta.aid = params->aid;
659 * FIXME: updating the following information is racy when this
660 * function is called from ieee80211_change_station().
661 * However, all this information should be static so
662 * maybe we should just reject attemps to change it.
665 if (params->listen_interval >= 0)
666 sta->listen_interval = params->listen_interval;
668 if (params->supported_rates) {
671 for (i = 0; i < params->supported_rates_len; i++) {
672 int rate = (params->supported_rates[i] & 0x7f) * 5;
673 for (j = 0; j < sband->n_bitrates; j++) {
674 if (sband->bitrates[j].bitrate == rate)
678 sta->sta.supp_rates[local->oper_channel->band] = rates;
682 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
686 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
687 switch (params->plink_action) {
688 case PLINK_ACTION_OPEN:
689 mesh_plink_open(sta);
691 case PLINK_ACTION_BLOCK:
692 mesh_plink_block(sta);
698 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
699 u8 *mac, struct station_parameters *params)
701 struct ieee80211_local *local = wiphy_priv(wiphy);
702 struct sta_info *sta;
703 struct ieee80211_sub_if_data *sdata;
708 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
710 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
711 sdata->vif.type != NL80211_IFTYPE_AP)
714 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
716 if (compare_ether_addr(mac, dev->dev_addr) == 0)
719 if (is_multicast_ether_addr(mac))
722 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
726 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
728 sta_apply_parameters(local, sta, params);
730 rate_control_rate_init(sta);
732 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
733 sdata->vif.type == NL80211_IFTYPE_AP;
737 err = sta_info_insert(sta);
739 /* STA has been freed */
740 if (err == -EEXIST && layer2_update) {
741 /* Need to update layer 2 devices on reassociation */
742 sta = sta_info_get(local, mac);
744 ieee80211_send_layer2_update(sta);
751 ieee80211_send_layer2_update(sta);
758 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
761 struct ieee80211_local *local = wiphy_priv(wiphy);
762 struct ieee80211_sub_if_data *sdata;
763 struct sta_info *sta;
765 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
770 /* XXX: get sta belonging to dev */
771 sta = sta_info_get(local, mac);
777 sta_info_unlink(&sta);
780 sta_info_destroy(sta);
782 sta_info_flush(local, sdata);
787 static int ieee80211_change_station(struct wiphy *wiphy,
788 struct net_device *dev,
790 struct station_parameters *params)
792 struct ieee80211_local *local = wiphy_priv(wiphy);
793 struct sta_info *sta;
794 struct ieee80211_sub_if_data *vlansdata;
798 /* XXX: get sta belonging to dev */
799 sta = sta_info_get(local, mac);
805 if (params->vlan && params->vlan != sta->sdata->dev) {
806 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
808 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
809 vlansdata->vif.type != NL80211_IFTYPE_AP) {
814 sta->sdata = vlansdata;
815 ieee80211_send_layer2_update(sta);
818 sta_apply_parameters(local, sta, params);
825 #ifdef CONFIG_MAC80211_MESH
826 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
827 u8 *dst, u8 *next_hop)
829 struct ieee80211_local *local = wiphy_priv(wiphy);
830 struct ieee80211_sub_if_data *sdata;
831 struct mesh_path *mpath;
832 struct sta_info *sta;
835 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
838 sta = sta_info_get(local, next_hop);
844 err = mesh_path_add(dst, sdata);
850 mpath = mesh_path_lookup(dst, sdata);
855 mesh_path_fix_nexthop(mpath, sta);
861 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
864 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
867 return mesh_path_del(dst, sdata);
869 mesh_path_flush(sdata);
873 static int ieee80211_change_mpath(struct wiphy *wiphy,
874 struct net_device *dev,
875 u8 *dst, u8 *next_hop)
877 struct ieee80211_local *local = wiphy_priv(wiphy);
878 struct ieee80211_sub_if_data *sdata;
879 struct mesh_path *mpath;
880 struct sta_info *sta;
882 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
886 sta = sta_info_get(local, next_hop);
892 mpath = mesh_path_lookup(dst, sdata);
898 mesh_path_fix_nexthop(mpath, sta);
904 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
905 struct mpath_info *pinfo)
908 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
910 memset(next_hop, 0, ETH_ALEN);
912 pinfo->filled = MPATH_INFO_FRAME_QLEN |
916 MPATH_INFO_DISCOVERY_TIMEOUT |
917 MPATH_INFO_DISCOVERY_RETRIES |
920 pinfo->frame_qlen = mpath->frame_queue.qlen;
921 pinfo->dsn = mpath->dsn;
922 pinfo->metric = mpath->metric;
923 if (time_before(jiffies, mpath->exp_time))
924 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
925 pinfo->discovery_timeout =
926 jiffies_to_msecs(mpath->discovery_timeout);
927 pinfo->discovery_retries = mpath->discovery_retries;
929 if (mpath->flags & MESH_PATH_ACTIVE)
930 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
931 if (mpath->flags & MESH_PATH_RESOLVING)
932 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
933 if (mpath->flags & MESH_PATH_DSN_VALID)
934 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
935 if (mpath->flags & MESH_PATH_FIXED)
936 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
937 if (mpath->flags & MESH_PATH_RESOLVING)
938 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
940 pinfo->flags = mpath->flags;
943 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
944 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
947 struct ieee80211_sub_if_data *sdata;
948 struct mesh_path *mpath;
950 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
953 mpath = mesh_path_lookup(dst, sdata);
958 memcpy(dst, mpath->dst, ETH_ALEN);
959 mpath_set_pinfo(mpath, next_hop, pinfo);
964 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
965 int idx, u8 *dst, u8 *next_hop,
966 struct mpath_info *pinfo)
968 struct ieee80211_sub_if_data *sdata;
969 struct mesh_path *mpath;
971 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
974 mpath = mesh_path_lookup_by_idx(idx, sdata);
979 memcpy(dst, mpath->dst, ETH_ALEN);
980 mpath_set_pinfo(mpath, next_hop, pinfo);
985 static int ieee80211_get_mesh_params(struct wiphy *wiphy,
986 struct net_device *dev,
987 struct mesh_config *conf)
989 struct ieee80211_sub_if_data *sdata;
990 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
992 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
996 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
998 return (mask >> (parm-1)) & 0x1;
1001 static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1002 struct net_device *dev,
1003 const struct mesh_config *nconf, u32 mask)
1005 struct mesh_config *conf;
1006 struct ieee80211_sub_if_data *sdata;
1007 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1009 /* Set the config options which we are interested in setting */
1010 conf = &(sdata->u.mesh.mshcfg);
1011 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1012 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1013 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1014 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1015 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1016 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1017 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1018 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1019 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1020 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1021 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1022 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1023 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1024 conf->auto_open_plinks = nconf->auto_open_plinks;
1025 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1026 conf->dot11MeshHWMPmaxPREQretries =
1027 nconf->dot11MeshHWMPmaxPREQretries;
1028 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1029 conf->path_refresh_time = nconf->path_refresh_time;
1030 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1031 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1032 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1033 conf->dot11MeshHWMPactivePathTimeout =
1034 nconf->dot11MeshHWMPactivePathTimeout;
1035 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1036 conf->dot11MeshHWMPpreqMinInterval =
1037 nconf->dot11MeshHWMPpreqMinInterval;
1038 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1040 conf->dot11MeshHWMPnetDiameterTraversalTime =
1041 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1047 static int ieee80211_change_bss(struct wiphy *wiphy,
1048 struct net_device *dev,
1049 struct bss_parameters *params)
1051 struct ieee80211_sub_if_data *sdata;
1054 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1056 if (params->use_cts_prot >= 0) {
1057 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1058 changed |= BSS_CHANGED_ERP_CTS_PROT;
1060 if (params->use_short_preamble >= 0) {
1061 sdata->vif.bss_conf.use_short_preamble =
1062 params->use_short_preamble;
1063 changed |= BSS_CHANGED_ERP_PREAMBLE;
1065 if (params->use_short_slot_time >= 0) {
1066 sdata->vif.bss_conf.use_short_slot =
1067 params->use_short_slot_time;
1068 changed |= BSS_CHANGED_ERP_SLOT;
1071 if (params->basic_rates) {
1074 struct ieee80211_local *local = wiphy_priv(wiphy);
1075 struct ieee80211_supported_band *sband =
1076 wiphy->bands[local->oper_channel->band];
1078 for (i = 0; i < params->basic_rates_len; i++) {
1079 int rate = (params->basic_rates[i] & 0x7f) * 5;
1080 for (j = 0; j < sband->n_bitrates; j++) {
1081 if (sband->bitrates[j].bitrate == rate)
1085 sdata->vif.bss_conf.basic_rates = rates;
1086 changed |= BSS_CHANGED_BASIC_RATES;
1089 ieee80211_bss_info_change_notify(sdata, changed);
1094 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1095 struct ieee80211_txq_params *params)
1097 struct ieee80211_local *local = wiphy_priv(wiphy);
1098 struct ieee80211_tx_queue_params p;
1100 if (!local->ops->conf_tx)
1103 memset(&p, 0, sizeof(p));
1104 p.aifs = params->aifs;
1105 p.cw_max = params->cwmax;
1106 p.cw_min = params->cwmin;
1107 p.txop = params->txop;
1108 if (drv_conf_tx(local, params->queue, &p)) {
1109 printk(KERN_DEBUG "%s: failed to set TX queue "
1110 "parameters for queue %d\n",
1111 wiphy_name(local->hw.wiphy), params->queue);
1118 static int ieee80211_set_channel(struct wiphy *wiphy,
1119 struct ieee80211_channel *chan,
1120 enum nl80211_channel_type channel_type)
1122 struct ieee80211_local *local = wiphy_priv(wiphy);
1124 local->oper_channel = chan;
1125 local->oper_channel_type = channel_type;
1127 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1131 static int ieee80211_suspend(struct wiphy *wiphy)
1133 return __ieee80211_suspend(wiphy_priv(wiphy));
1136 static int ieee80211_resume(struct wiphy *wiphy)
1138 return __ieee80211_resume(wiphy_priv(wiphy));
1141 #define ieee80211_suspend NULL
1142 #define ieee80211_resume NULL
1145 static int ieee80211_scan(struct wiphy *wiphy,
1146 struct net_device *dev,
1147 struct cfg80211_scan_request *req)
1149 struct ieee80211_sub_if_data *sdata;
1151 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1153 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1154 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1155 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1156 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
1159 return ieee80211_request_scan(sdata, req);
1162 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1163 struct cfg80211_auth_request *req)
1165 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1168 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1169 struct cfg80211_assoc_request *req)
1171 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1174 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1175 struct cfg80211_deauth_request *req,
1178 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1182 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1183 struct cfg80211_disassoc_request *req,
1186 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1190 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1191 struct cfg80211_ibss_params *params)
1193 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1195 return ieee80211_ibss_join(sdata, params);
1198 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1200 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1202 return ieee80211_ibss_leave(sdata);
1205 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1207 struct ieee80211_local *local = wiphy_priv(wiphy);
1210 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1211 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1217 if (changed & WIPHY_PARAM_RETRY_SHORT)
1218 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1219 if (changed & WIPHY_PARAM_RETRY_LONG)
1220 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1222 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1223 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1228 static int ieee80211_set_tx_power(struct wiphy *wiphy,
1229 enum tx_power_setting type, int dbm)
1231 struct ieee80211_local *local = wiphy_priv(wiphy);
1232 struct ieee80211_channel *chan = local->hw.conf.channel;
1236 case TX_POWER_AUTOMATIC:
1237 local->user_power_level = -1;
1239 case TX_POWER_LIMITED:
1242 local->user_power_level = dbm;
1244 case TX_POWER_FIXED:
1247 /* TODO: move to cfg80211 when it knows the channel */
1248 if (dbm > chan->max_power)
1250 local->user_power_level = dbm;
1254 ieee80211_hw_config(local, changes);
1259 static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1261 struct ieee80211_local *local = wiphy_priv(wiphy);
1263 *dbm = local->hw.conf.power_level;
1268 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1271 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1273 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1278 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1280 struct ieee80211_local *local = wiphy_priv(wiphy);
1282 drv_rfkill_poll(local);
1285 #ifdef CONFIG_NL80211_TESTMODE
1286 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1288 struct ieee80211_local *local = wiphy_priv(wiphy);
1290 if (!local->ops->testmode_cmd)
1293 return local->ops->testmode_cmd(&local->hw, data, len);
1297 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1298 bool enabled, int timeout)
1300 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1301 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1302 struct ieee80211_conf *conf = &local->hw.conf;
1304 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1307 if (enabled == sdata->u.mgd.powersave &&
1308 timeout == conf->dynamic_ps_timeout)
1311 sdata->u.mgd.powersave = enabled;
1312 conf->dynamic_ps_timeout = timeout;
1314 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1315 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1317 ieee80211_recalc_ps(local, -1);
1322 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1323 struct net_device *dev,
1325 const struct cfg80211_bitrate_mask *mask)
1327 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1328 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1329 int i, err = -EINVAL;
1331 struct ieee80211_supported_band *sband;
1333 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1335 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
1336 * target_rate = X, rate->fixed = 1 means only rate X
1337 * target_rate = X, rate->fixed = 0 means all rates <= X */
1338 sdata->max_ratectrl_rateidx = -1;
1339 sdata->force_unicast_rateidx = -1;
1342 target_rate = mask->fixed / 100;
1343 else if (mask->maxrate)
1344 target_rate = mask->maxrate / 100;
1348 for (i=0; i< sband->n_bitrates; i++) {
1349 struct ieee80211_rate *brate = &sband->bitrates[i];
1350 int this_rate = brate->bitrate;
1352 if (target_rate == this_rate) {
1353 sdata->max_ratectrl_rateidx = i;
1355 sdata->force_unicast_rateidx = i;
1364 struct cfg80211_ops mac80211_config_ops = {
1365 .add_virtual_intf = ieee80211_add_iface,
1366 .del_virtual_intf = ieee80211_del_iface,
1367 .change_virtual_intf = ieee80211_change_iface,
1368 .add_key = ieee80211_add_key,
1369 .del_key = ieee80211_del_key,
1370 .get_key = ieee80211_get_key,
1371 .set_default_key = ieee80211_config_default_key,
1372 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
1373 .add_beacon = ieee80211_add_beacon,
1374 .set_beacon = ieee80211_set_beacon,
1375 .del_beacon = ieee80211_del_beacon,
1376 .add_station = ieee80211_add_station,
1377 .del_station = ieee80211_del_station,
1378 .change_station = ieee80211_change_station,
1379 .get_station = ieee80211_get_station,
1380 .dump_station = ieee80211_dump_station,
1381 #ifdef CONFIG_MAC80211_MESH
1382 .add_mpath = ieee80211_add_mpath,
1383 .del_mpath = ieee80211_del_mpath,
1384 .change_mpath = ieee80211_change_mpath,
1385 .get_mpath = ieee80211_get_mpath,
1386 .dump_mpath = ieee80211_dump_mpath,
1387 .set_mesh_params = ieee80211_set_mesh_params,
1388 .get_mesh_params = ieee80211_get_mesh_params,
1390 .change_bss = ieee80211_change_bss,
1391 .set_txq_params = ieee80211_set_txq_params,
1392 .set_channel = ieee80211_set_channel,
1393 .suspend = ieee80211_suspend,
1394 .resume = ieee80211_resume,
1395 .scan = ieee80211_scan,
1396 .auth = ieee80211_auth,
1397 .assoc = ieee80211_assoc,
1398 .deauth = ieee80211_deauth,
1399 .disassoc = ieee80211_disassoc,
1400 .join_ibss = ieee80211_join_ibss,
1401 .leave_ibss = ieee80211_leave_ibss,
1402 .set_wiphy_params = ieee80211_set_wiphy_params,
1403 .set_tx_power = ieee80211_set_tx_power,
1404 .get_tx_power = ieee80211_get_tx_power,
1405 .set_wds_peer = ieee80211_set_wds_peer,
1406 .rfkill_poll = ieee80211_rfkill_poll,
1407 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
1408 .set_power_mgmt = ieee80211_set_power_mgmt,
1409 .set_bitrate_mask = ieee80211_set_bitrate_mask,