2 * mac80211 configuration hooks for cfg80211
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, int ifindex)
62 struct net_device *dev;
63 struct ieee80211_sub_if_data *sdata;
65 /* we're under RTNL */
66 dev = __dev_get_by_index(&init_net, ifindex);
70 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
72 ieee80211_if_remove(sdata);
77 static int ieee80211_change_iface(struct wiphy *wiphy,
78 struct net_device *dev,
79 enum nl80211_iftype type, u32 *flags,
80 struct vif_params *params)
82 struct ieee80211_sub_if_data *sdata;
85 if (!nl80211_type_check(type))
88 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
90 ret = ieee80211_if_change_type(sdata, type);
94 if (netif_running(sdata->dev))
97 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
98 ieee80211_sdata_set_mesh_id(sdata,
102 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
105 sdata->u.mntr_flags = *flags;
109 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
110 u8 key_idx, const u8 *mac_addr,
111 struct key_params *params)
113 struct ieee80211_sub_if_data *sdata;
114 struct sta_info *sta = NULL;
115 enum ieee80211_key_alg alg;
116 struct ieee80211_key *key;
119 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
121 switch (params->cipher) {
122 case WLAN_CIPHER_SUITE_WEP40:
123 case WLAN_CIPHER_SUITE_WEP104:
126 case WLAN_CIPHER_SUITE_TKIP:
129 case WLAN_CIPHER_SUITE_CCMP:
132 case WLAN_CIPHER_SUITE_AES_CMAC:
139 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key,
140 params->seq_len, params->seq);
147 sta = sta_info_get(sdata->local, mac_addr);
149 ieee80211_key_free(key);
155 ieee80211_key_link(key, sdata, sta);
164 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
165 u8 key_idx, const u8 *mac_addr)
167 struct ieee80211_sub_if_data *sdata;
168 struct sta_info *sta;
171 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
178 sta = sta_info_get(sdata->local, mac_addr);
183 ieee80211_key_free(sta->key);
191 if (!sdata->keys[key_idx]) {
196 ieee80211_key_free(sdata->keys[key_idx]);
197 WARN_ON(sdata->keys[key_idx]);
206 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
207 u8 key_idx, const u8 *mac_addr, void *cookie,
208 void (*callback)(void *cookie,
209 struct key_params *params))
211 struct ieee80211_sub_if_data *sdata;
212 struct sta_info *sta = NULL;
214 struct key_params params;
215 struct ieee80211_key *key;
220 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
225 sta = sta_info_get(sdata->local, mac_addr);
231 key = sdata->keys[key_idx];
236 memset(¶ms, 0, sizeof(params));
238 switch (key->conf.alg) {
240 params.cipher = WLAN_CIPHER_SUITE_TKIP;
242 iv32 = key->u.tkip.tx.iv32;
243 iv16 = key->u.tkip.tx.iv16;
245 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
246 drv_get_tkip_seq(sdata->local,
247 key->conf.hw_key_idx,
250 seq[0] = iv16 & 0xff;
251 seq[1] = (iv16 >> 8) & 0xff;
252 seq[2] = iv32 & 0xff;
253 seq[3] = (iv32 >> 8) & 0xff;
254 seq[4] = (iv32 >> 16) & 0xff;
255 seq[5] = (iv32 >> 24) & 0xff;
260 params.cipher = WLAN_CIPHER_SUITE_CCMP;
261 seq[0] = key->u.ccmp.tx_pn[5];
262 seq[1] = key->u.ccmp.tx_pn[4];
263 seq[2] = key->u.ccmp.tx_pn[3];
264 seq[3] = key->u.ccmp.tx_pn[2];
265 seq[4] = key->u.ccmp.tx_pn[1];
266 seq[5] = key->u.ccmp.tx_pn[0];
271 if (key->conf.keylen == 5)
272 params.cipher = WLAN_CIPHER_SUITE_WEP40;
274 params.cipher = WLAN_CIPHER_SUITE_WEP104;
277 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
278 seq[0] = key->u.aes_cmac.tx_pn[5];
279 seq[1] = key->u.aes_cmac.tx_pn[4];
280 seq[2] = key->u.aes_cmac.tx_pn[3];
281 seq[3] = key->u.aes_cmac.tx_pn[2];
282 seq[4] = key->u.aes_cmac.tx_pn[1];
283 seq[5] = key->u.aes_cmac.tx_pn[0];
289 params.key = key->conf.key;
290 params.key_len = key->conf.keylen;
292 callback(cookie, ¶ms);
300 static int ieee80211_config_default_key(struct wiphy *wiphy,
301 struct net_device *dev,
304 struct ieee80211_sub_if_data *sdata;
308 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
309 ieee80211_set_default_key(sdata, key_idx);
316 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
317 struct net_device *dev,
320 struct ieee80211_sub_if_data *sdata;
324 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
325 ieee80211_set_default_mgmt_key(sdata, key_idx);
332 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
334 struct ieee80211_sub_if_data *sdata = sta->sdata;
336 sinfo->filled = STATION_INFO_INACTIVE_TIME |
337 STATION_INFO_RX_BYTES |
338 STATION_INFO_TX_BYTES |
339 STATION_INFO_RX_PACKETS |
340 STATION_INFO_TX_PACKETS |
341 STATION_INFO_TX_BITRATE;
343 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
344 sinfo->rx_bytes = sta->rx_bytes;
345 sinfo->tx_bytes = sta->tx_bytes;
346 sinfo->rx_packets = sta->rx_packets;
347 sinfo->tx_packets = sta->tx_packets;
349 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
350 sinfo->filled |= STATION_INFO_SIGNAL;
351 sinfo->signal = (s8)sta->last_signal;
354 sinfo->txrate.flags = 0;
355 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
356 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
357 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
358 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
359 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
360 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
362 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
363 struct ieee80211_supported_band *sband;
364 sband = sta->local->hw.wiphy->bands[
365 sta->local->hw.conf.channel->band];
366 sinfo->txrate.legacy =
367 sband->bitrates[sta->last_tx_rate.idx].bitrate;
369 sinfo->txrate.mcs = sta->last_tx_rate.idx;
371 if (ieee80211_vif_is_mesh(&sdata->vif)) {
372 #ifdef CONFIG_MAC80211_MESH
373 sinfo->filled |= STATION_INFO_LLID |
375 STATION_INFO_PLINK_STATE;
377 sinfo->llid = le16_to_cpu(sta->llid);
378 sinfo->plid = le16_to_cpu(sta->plid);
379 sinfo->plink_state = sta->plink_state;
385 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
386 int idx, u8 *mac, struct station_info *sinfo)
388 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
389 struct sta_info *sta;
394 sta = sta_info_get_by_idx(local, idx, dev);
397 memcpy(mac, sta->sta.addr, ETH_ALEN);
398 sta_set_sinfo(sta, sinfo);
406 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
407 u8 *mac, struct station_info *sinfo)
409 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
410 struct sta_info *sta;
415 /* XXX: verify sta->dev == dev */
417 sta = sta_info_get(local, mac);
420 sta_set_sinfo(sta, sinfo);
429 * This handles both adding a beacon and setting new beacon info
431 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
432 struct beacon_parameters *params)
434 struct beacon_data *new, *old;
435 int new_head_len, new_tail_len;
439 old = sdata->u.ap.beacon;
441 /* head must not be zero-length */
442 if (params->head && !params->head_len)
446 * This is a kludge. beacon interval should really be part
447 * of the beacon information.
449 if (params->interval &&
450 (sdata->vif.bss_conf.beacon_int != params->interval)) {
451 sdata->vif.bss_conf.beacon_int = params->interval;
452 ieee80211_bss_info_change_notify(sdata,
453 BSS_CHANGED_BEACON_INT);
456 /* Need to have a beacon head if we don't have one yet */
457 if (!params->head && !old)
460 /* sorry, no way to start beaconing without dtim period */
461 if (!params->dtim_period && !old)
464 /* new or old head? */
466 new_head_len = params->head_len;
468 new_head_len = old->head_len;
470 /* new or old tail? */
471 if (params->tail || !old)
472 /* params->tail_len will be zero for !params->tail */
473 new_tail_len = params->tail_len;
475 new_tail_len = old->tail_len;
477 size = sizeof(*new) + new_head_len + new_tail_len;
479 new = kzalloc(size, GFP_KERNEL);
483 /* start filling the new info now */
485 /* new or old dtim period? */
486 if (params->dtim_period)
487 new->dtim_period = params->dtim_period;
489 new->dtim_period = old->dtim_period;
492 * pointers go into the block we allocated,
493 * memory is | beacon_data | head | tail |
495 new->head = ((u8 *) new) + sizeof(*new);
496 new->tail = new->head + new_head_len;
497 new->head_len = new_head_len;
498 new->tail_len = new_tail_len;
502 memcpy(new->head, params->head, new_head_len);
504 memcpy(new->head, old->head, new_head_len);
506 /* copy in optional tail */
508 memcpy(new->tail, params->tail, new_tail_len);
511 memcpy(new->tail, old->tail, new_tail_len);
513 rcu_assign_pointer(sdata->u.ap.beacon, new);
519 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
524 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
525 struct beacon_parameters *params)
527 struct ieee80211_sub_if_data *sdata;
528 struct beacon_data *old;
530 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
532 old = sdata->u.ap.beacon;
537 return ieee80211_config_beacon(sdata, params);
540 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
541 struct beacon_parameters *params)
543 struct ieee80211_sub_if_data *sdata;
544 struct beacon_data *old;
546 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
548 old = sdata->u.ap.beacon;
553 return ieee80211_config_beacon(sdata, params);
556 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
558 struct ieee80211_sub_if_data *sdata;
559 struct beacon_data *old;
561 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
563 old = sdata->u.ap.beacon;
568 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
572 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
576 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
577 struct iapp_layer2_update {
578 u8 da[ETH_ALEN]; /* broadcast */
579 u8 sa[ETH_ALEN]; /* STA addr */
585 } __attribute__ ((packed));
587 static void ieee80211_send_layer2_update(struct sta_info *sta)
589 struct iapp_layer2_update *msg;
592 /* Send Level 2 Update Frame to update forwarding tables in layer 2
595 skb = dev_alloc_skb(sizeof(*msg));
598 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
600 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
601 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
603 memset(msg->da, 0xff, ETH_ALEN);
604 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
607 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
608 msg->control = 0xaf; /* XID response lsb.1111F101.
609 * F=0 (no poll command; unsolicited frame) */
610 msg->xid_info[0] = 0x81; /* XID format identifier */
611 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
612 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
614 skb->dev = sta->sdata->dev;
615 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
616 memset(skb->cb, 0, sizeof(skb->cb));
620 static void sta_apply_parameters(struct ieee80211_local *local,
621 struct sta_info *sta,
622 struct station_parameters *params)
626 struct ieee80211_supported_band *sband;
627 struct ieee80211_sub_if_data *sdata = sta->sdata;
630 sband = local->hw.wiphy->bands[local->oper_channel->band];
632 spin_lock_bh(&sta->lock);
633 mask = params->sta_flags_mask;
634 set = params->sta_flags_set;
636 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
637 sta->flags &= ~WLAN_STA_AUTHORIZED;
638 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
639 sta->flags |= WLAN_STA_AUTHORIZED;
642 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
643 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
644 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
645 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
648 if (mask & BIT(NL80211_STA_FLAG_WME)) {
649 sta->flags &= ~WLAN_STA_WME;
650 if (set & BIT(NL80211_STA_FLAG_WME))
651 sta->flags |= WLAN_STA_WME;
654 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
655 sta->flags &= ~WLAN_STA_MFP;
656 if (set & BIT(NL80211_STA_FLAG_MFP))
657 sta->flags |= WLAN_STA_MFP;
659 spin_unlock_bh(&sta->lock);
662 * cfg80211 validates this (1-2007) and allows setting the AID
663 * only when creating a new station entry
666 sta->sta.aid = params->aid;
669 * FIXME: updating the following information is racy when this
670 * function is called from ieee80211_change_station().
671 * However, all this information should be static so
672 * maybe we should just reject attemps to change it.
675 if (params->listen_interval >= 0)
676 sta->listen_interval = params->listen_interval;
678 if (params->supported_rates) {
681 for (i = 0; i < params->supported_rates_len; i++) {
682 int rate = (params->supported_rates[i] & 0x7f) * 5;
683 for (j = 0; j < sband->n_bitrates; j++) {
684 if (sband->bitrates[j].bitrate == rate)
688 sta->sta.supp_rates[local->oper_channel->band] = rates;
692 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
696 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
697 switch (params->plink_action) {
698 case PLINK_ACTION_OPEN:
699 mesh_plink_open(sta);
701 case PLINK_ACTION_BLOCK:
702 mesh_plink_block(sta);
708 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
709 u8 *mac, struct station_parameters *params)
711 struct ieee80211_local *local = wiphy_priv(wiphy);
712 struct sta_info *sta;
713 struct ieee80211_sub_if_data *sdata;
718 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
720 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
721 sdata->vif.type != NL80211_IFTYPE_AP)
724 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
726 if (compare_ether_addr(mac, dev->dev_addr) == 0)
729 if (is_multicast_ether_addr(mac))
732 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
736 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
738 sta_apply_parameters(local, sta, params);
740 rate_control_rate_init(sta);
742 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
743 sdata->vif.type == NL80211_IFTYPE_AP;
747 err = sta_info_insert(sta);
749 /* STA has been freed */
750 if (err == -EEXIST && layer2_update) {
751 /* Need to update layer 2 devices on reassociation */
752 sta = sta_info_get(local, mac);
754 ieee80211_send_layer2_update(sta);
761 ieee80211_send_layer2_update(sta);
768 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
771 struct ieee80211_local *local = wiphy_priv(wiphy);
772 struct ieee80211_sub_if_data *sdata;
773 struct sta_info *sta;
775 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
780 /* XXX: get sta belonging to dev */
781 sta = sta_info_get(local, mac);
787 sta_info_unlink(&sta);
790 sta_info_destroy(sta);
792 sta_info_flush(local, sdata);
797 static int ieee80211_change_station(struct wiphy *wiphy,
798 struct net_device *dev,
800 struct station_parameters *params)
802 struct ieee80211_local *local = wiphy_priv(wiphy);
803 struct sta_info *sta;
804 struct ieee80211_sub_if_data *vlansdata;
808 /* XXX: get sta belonging to dev */
809 sta = sta_info_get(local, mac);
815 if (params->vlan && params->vlan != sta->sdata->dev) {
816 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
818 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
819 vlansdata->vif.type != NL80211_IFTYPE_AP) {
824 sta->sdata = vlansdata;
825 ieee80211_send_layer2_update(sta);
828 sta_apply_parameters(local, sta, params);
835 #ifdef CONFIG_MAC80211_MESH
836 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
837 u8 *dst, u8 *next_hop)
839 struct ieee80211_local *local = wiphy_priv(wiphy);
840 struct ieee80211_sub_if_data *sdata;
841 struct mesh_path *mpath;
842 struct sta_info *sta;
845 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
848 sta = sta_info_get(local, next_hop);
854 err = mesh_path_add(dst, sdata);
860 mpath = mesh_path_lookup(dst, sdata);
865 mesh_path_fix_nexthop(mpath, sta);
871 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
874 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
877 return mesh_path_del(dst, sdata);
879 mesh_path_flush(sdata);
883 static int ieee80211_change_mpath(struct wiphy *wiphy,
884 struct net_device *dev,
885 u8 *dst, u8 *next_hop)
887 struct ieee80211_local *local = wiphy_priv(wiphy);
888 struct ieee80211_sub_if_data *sdata;
889 struct mesh_path *mpath;
890 struct sta_info *sta;
892 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
896 sta = sta_info_get(local, next_hop);
902 mpath = mesh_path_lookup(dst, sdata);
908 mesh_path_fix_nexthop(mpath, sta);
914 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
915 struct mpath_info *pinfo)
918 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
920 memset(next_hop, 0, ETH_ALEN);
922 pinfo->filled = MPATH_INFO_FRAME_QLEN |
926 MPATH_INFO_DISCOVERY_TIMEOUT |
927 MPATH_INFO_DISCOVERY_RETRIES |
930 pinfo->frame_qlen = mpath->frame_queue.qlen;
931 pinfo->dsn = mpath->dsn;
932 pinfo->metric = mpath->metric;
933 if (time_before(jiffies, mpath->exp_time))
934 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
935 pinfo->discovery_timeout =
936 jiffies_to_msecs(mpath->discovery_timeout);
937 pinfo->discovery_retries = mpath->discovery_retries;
939 if (mpath->flags & MESH_PATH_ACTIVE)
940 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
941 if (mpath->flags & MESH_PATH_RESOLVING)
942 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
943 if (mpath->flags & MESH_PATH_DSN_VALID)
944 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
945 if (mpath->flags & MESH_PATH_FIXED)
946 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
947 if (mpath->flags & MESH_PATH_RESOLVING)
948 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
950 pinfo->flags = mpath->flags;
953 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
954 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
957 struct ieee80211_sub_if_data *sdata;
958 struct mesh_path *mpath;
960 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
963 mpath = mesh_path_lookup(dst, sdata);
968 memcpy(dst, mpath->dst, ETH_ALEN);
969 mpath_set_pinfo(mpath, next_hop, pinfo);
974 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
975 int idx, u8 *dst, u8 *next_hop,
976 struct mpath_info *pinfo)
978 struct ieee80211_sub_if_data *sdata;
979 struct mesh_path *mpath;
981 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
984 mpath = mesh_path_lookup_by_idx(idx, sdata);
989 memcpy(dst, mpath->dst, ETH_ALEN);
990 mpath_set_pinfo(mpath, next_hop, pinfo);
995 static int ieee80211_get_mesh_params(struct wiphy *wiphy,
996 struct net_device *dev,
997 struct mesh_config *conf)
999 struct ieee80211_sub_if_data *sdata;
1000 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1002 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1006 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1008 return (mask >> (parm-1)) & 0x1;
1011 static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1012 struct net_device *dev,
1013 const struct mesh_config *nconf, u32 mask)
1015 struct mesh_config *conf;
1016 struct ieee80211_sub_if_data *sdata;
1017 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1019 /* Set the config options which we are interested in setting */
1020 conf = &(sdata->u.mesh.mshcfg);
1021 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1022 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1023 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1024 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1025 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1026 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1027 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1028 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1029 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1030 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1031 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1032 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1033 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1034 conf->auto_open_plinks = nconf->auto_open_plinks;
1035 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1036 conf->dot11MeshHWMPmaxPREQretries =
1037 nconf->dot11MeshHWMPmaxPREQretries;
1038 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1039 conf->path_refresh_time = nconf->path_refresh_time;
1040 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1041 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1042 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1043 conf->dot11MeshHWMPactivePathTimeout =
1044 nconf->dot11MeshHWMPactivePathTimeout;
1045 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1046 conf->dot11MeshHWMPpreqMinInterval =
1047 nconf->dot11MeshHWMPpreqMinInterval;
1048 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1050 conf->dot11MeshHWMPnetDiameterTraversalTime =
1051 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1057 static int ieee80211_change_bss(struct wiphy *wiphy,
1058 struct net_device *dev,
1059 struct bss_parameters *params)
1061 struct ieee80211_sub_if_data *sdata;
1064 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1066 if (params->use_cts_prot >= 0) {
1067 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1068 changed |= BSS_CHANGED_ERP_CTS_PROT;
1070 if (params->use_short_preamble >= 0) {
1071 sdata->vif.bss_conf.use_short_preamble =
1072 params->use_short_preamble;
1073 changed |= BSS_CHANGED_ERP_PREAMBLE;
1075 if (params->use_short_slot_time >= 0) {
1076 sdata->vif.bss_conf.use_short_slot =
1077 params->use_short_slot_time;
1078 changed |= BSS_CHANGED_ERP_SLOT;
1081 if (params->basic_rates) {
1084 struct ieee80211_local *local = wiphy_priv(wiphy);
1085 struct ieee80211_supported_band *sband =
1086 wiphy->bands[local->oper_channel->band];
1088 for (i = 0; i < params->basic_rates_len; i++) {
1089 int rate = (params->basic_rates[i] & 0x7f) * 5;
1090 for (j = 0; j < sband->n_bitrates; j++) {
1091 if (sband->bitrates[j].bitrate == rate)
1095 sdata->vif.bss_conf.basic_rates = rates;
1096 changed |= BSS_CHANGED_BASIC_RATES;
1099 ieee80211_bss_info_change_notify(sdata, changed);
1104 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1105 struct ieee80211_txq_params *params)
1107 struct ieee80211_local *local = wiphy_priv(wiphy);
1108 struct ieee80211_tx_queue_params p;
1110 if (!local->ops->conf_tx)
1113 memset(&p, 0, sizeof(p));
1114 p.aifs = params->aifs;
1115 p.cw_max = params->cwmax;
1116 p.cw_min = params->cwmin;
1117 p.txop = params->txop;
1118 if (drv_conf_tx(local, params->queue, &p)) {
1119 printk(KERN_DEBUG "%s: failed to set TX queue "
1120 "parameters for queue %d\n",
1121 wiphy_name(local->hw.wiphy), params->queue);
1128 static int ieee80211_set_channel(struct wiphy *wiphy,
1129 struct ieee80211_channel *chan,
1130 enum nl80211_channel_type channel_type)
1132 struct ieee80211_local *local = wiphy_priv(wiphy);
1134 local->oper_channel = chan;
1135 local->oper_channel_type = channel_type;
1137 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1141 static int ieee80211_suspend(struct wiphy *wiphy)
1143 return __ieee80211_suspend(wiphy_priv(wiphy));
1146 static int ieee80211_resume(struct wiphy *wiphy)
1148 return __ieee80211_resume(wiphy_priv(wiphy));
1151 #define ieee80211_suspend NULL
1152 #define ieee80211_resume NULL
1155 static int ieee80211_scan(struct wiphy *wiphy,
1156 struct net_device *dev,
1157 struct cfg80211_scan_request *req)
1159 struct ieee80211_sub_if_data *sdata;
1161 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1163 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1164 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1165 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1166 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
1169 return ieee80211_request_scan(sdata, req);
1172 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1173 struct cfg80211_auth_request *req)
1175 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1178 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1179 struct cfg80211_assoc_request *req)
1181 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1184 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1185 struct cfg80211_deauth_request *req,
1188 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1192 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1193 struct cfg80211_disassoc_request *req,
1196 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1200 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1201 struct cfg80211_ibss_params *params)
1203 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1205 return ieee80211_ibss_join(sdata, params);
1208 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1210 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1212 return ieee80211_ibss_leave(sdata);
1215 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1217 struct ieee80211_local *local = wiphy_priv(wiphy);
1220 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1221 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1227 if (changed & WIPHY_PARAM_RETRY_SHORT)
1228 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1229 if (changed & WIPHY_PARAM_RETRY_LONG)
1230 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1232 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1233 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1238 static int ieee80211_set_tx_power(struct wiphy *wiphy,
1239 enum tx_power_setting type, int dbm)
1241 struct ieee80211_local *local = wiphy_priv(wiphy);
1242 struct ieee80211_channel *chan = local->hw.conf.channel;
1246 case TX_POWER_AUTOMATIC:
1247 local->user_power_level = -1;
1249 case TX_POWER_LIMITED:
1252 local->user_power_level = dbm;
1254 case TX_POWER_FIXED:
1257 /* TODO: move to cfg80211 when it knows the channel */
1258 if (dbm > chan->max_power)
1260 local->user_power_level = dbm;
1264 ieee80211_hw_config(local, changes);
1269 static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1271 struct ieee80211_local *local = wiphy_priv(wiphy);
1273 *dbm = local->hw.conf.power_level;
1278 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1281 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1283 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1288 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1290 struct ieee80211_local *local = wiphy_priv(wiphy);
1292 drv_rfkill_poll(local);
1295 #ifdef CONFIG_NL80211_TESTMODE
1296 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1298 struct ieee80211_local *local = wiphy_priv(wiphy);
1300 if (!local->ops->testmode_cmd)
1303 return local->ops->testmode_cmd(&local->hw, data, len);
1307 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1308 bool enabled, int timeout)
1310 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1311 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1312 struct ieee80211_conf *conf = &local->hw.conf;
1314 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1317 if (enabled == sdata->u.mgd.powersave &&
1318 timeout == conf->dynamic_ps_timeout)
1321 sdata->u.mgd.powersave = enabled;
1322 conf->dynamic_ps_timeout = timeout;
1324 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1325 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1327 ieee80211_recalc_ps(local, -1);
1332 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1333 struct net_device *dev,
1335 const struct cfg80211_bitrate_mask *mask)
1337 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1338 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1339 int i, err = -EINVAL;
1341 struct ieee80211_supported_band *sband;
1343 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1345 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
1346 * target_rate = X, rate->fixed = 1 means only rate X
1347 * target_rate = X, rate->fixed = 0 means all rates <= X */
1348 sdata->max_ratectrl_rateidx = -1;
1349 sdata->force_unicast_rateidx = -1;
1352 target_rate = mask->fixed / 100;
1353 else if (mask->maxrate)
1354 target_rate = mask->maxrate / 100;
1358 for (i=0; i< sband->n_bitrates; i++) {
1359 struct ieee80211_rate *brate = &sband->bitrates[i];
1360 int this_rate = brate->bitrate;
1362 if (target_rate == this_rate) {
1363 sdata->max_ratectrl_rateidx = i;
1365 sdata->force_unicast_rateidx = i;
1374 struct cfg80211_ops mac80211_config_ops = {
1375 .add_virtual_intf = ieee80211_add_iface,
1376 .del_virtual_intf = ieee80211_del_iface,
1377 .change_virtual_intf = ieee80211_change_iface,
1378 .add_key = ieee80211_add_key,
1379 .del_key = ieee80211_del_key,
1380 .get_key = ieee80211_get_key,
1381 .set_default_key = ieee80211_config_default_key,
1382 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
1383 .add_beacon = ieee80211_add_beacon,
1384 .set_beacon = ieee80211_set_beacon,
1385 .del_beacon = ieee80211_del_beacon,
1386 .add_station = ieee80211_add_station,
1387 .del_station = ieee80211_del_station,
1388 .change_station = ieee80211_change_station,
1389 .get_station = ieee80211_get_station,
1390 .dump_station = ieee80211_dump_station,
1391 #ifdef CONFIG_MAC80211_MESH
1392 .add_mpath = ieee80211_add_mpath,
1393 .del_mpath = ieee80211_del_mpath,
1394 .change_mpath = ieee80211_change_mpath,
1395 .get_mpath = ieee80211_get_mpath,
1396 .dump_mpath = ieee80211_dump_mpath,
1397 .set_mesh_params = ieee80211_set_mesh_params,
1398 .get_mesh_params = ieee80211_get_mesh_params,
1400 .change_bss = ieee80211_change_bss,
1401 .set_txq_params = ieee80211_set_txq_params,
1402 .set_channel = ieee80211_set_channel,
1403 .suspend = ieee80211_suspend,
1404 .resume = ieee80211_resume,
1405 .scan = ieee80211_scan,
1406 .auth = ieee80211_auth,
1407 .assoc = ieee80211_assoc,
1408 .deauth = ieee80211_deauth,
1409 .disassoc = ieee80211_disassoc,
1410 .join_ibss = ieee80211_join_ibss,
1411 .leave_ibss = ieee80211_leave_ibss,
1412 .set_wiphy_params = ieee80211_set_wiphy_params,
1413 .set_tx_power = ieee80211_set_tx_power,
1414 .get_tx_power = ieee80211_get_tx_power,
1415 .set_wds_peer = ieee80211_set_wds_peer,
1416 .rfkill_poll = ieee80211_rfkill_poll,
1417 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
1418 .set_power_mgmt = ieee80211_set_power_mgmt,
1419 .set_bitrate_mask = ieee80211_set_bitrate_mask,