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"
20 static bool nl80211_type_check(enum nl80211_iftype type)
23 case NL80211_IFTYPE_ADHOC:
24 case NL80211_IFTYPE_STATION:
25 case NL80211_IFTYPE_MONITOR:
26 #ifdef CONFIG_MAC80211_MESH
27 case NL80211_IFTYPE_MESH_POINT:
29 case NL80211_IFTYPE_AP:
30 case NL80211_IFTYPE_AP_VLAN:
31 case NL80211_IFTYPE_WDS:
38 static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
39 enum nl80211_iftype type, u32 *flags,
40 struct vif_params *params)
42 struct ieee80211_local *local = wiphy_priv(wiphy);
43 struct net_device *dev;
44 struct ieee80211_sub_if_data *sdata;
47 if (!nl80211_type_check(type))
50 err = ieee80211_if_add(local, name, &dev, type, params);
51 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
54 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
55 sdata->u.mntr_flags = *flags;
59 static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
61 struct net_device *dev;
62 struct ieee80211_sub_if_data *sdata;
64 /* we're under RTNL */
65 dev = __dev_get_by_index(&init_net, ifindex);
69 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
71 ieee80211_if_remove(sdata);
76 static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
77 enum nl80211_iftype type, u32 *flags,
78 struct vif_params *params)
80 struct net_device *dev;
81 struct ieee80211_sub_if_data *sdata;
84 /* we're under RTNL */
85 dev = __dev_get_by_index(&init_net, ifindex);
89 if (!nl80211_type_check(type))
92 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
94 ret = ieee80211_if_change_type(sdata, type);
98 if (netif_running(sdata->dev))
101 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
102 ieee80211_sdata_set_mesh_id(sdata,
106 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
109 sdata->u.mntr_flags = *flags;
113 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
114 u8 key_idx, u8 *mac_addr,
115 struct key_params *params)
117 struct ieee80211_sub_if_data *sdata;
118 struct sta_info *sta = NULL;
119 enum ieee80211_key_alg alg;
120 struct ieee80211_key *key;
123 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
125 switch (params->cipher) {
126 case WLAN_CIPHER_SUITE_WEP40:
127 case WLAN_CIPHER_SUITE_WEP104:
130 case WLAN_CIPHER_SUITE_TKIP:
133 case WLAN_CIPHER_SUITE_CCMP:
136 case WLAN_CIPHER_SUITE_AES_CMAC:
143 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
150 sta = sta_info_get(sdata->local, mac_addr);
152 ieee80211_key_free(key);
158 ieee80211_key_link(key, sdata, sta);
167 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
168 u8 key_idx, u8 *mac_addr)
170 struct ieee80211_sub_if_data *sdata;
171 struct sta_info *sta;
174 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
181 sta = sta_info_get(sdata->local, mac_addr);
186 ieee80211_key_free(sta->key);
194 if (!sdata->keys[key_idx]) {
199 ieee80211_key_free(sdata->keys[key_idx]);
200 WARN_ON(sdata->keys[key_idx]);
209 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
210 u8 key_idx, u8 *mac_addr, void *cookie,
211 void (*callback)(void *cookie,
212 struct key_params *params))
214 struct ieee80211_sub_if_data *sdata;
215 struct sta_info *sta = NULL;
217 struct key_params params;
218 struct ieee80211_key *key;
223 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
228 sta = sta_info_get(sdata->local, mac_addr);
234 key = sdata->keys[key_idx];
239 memset(¶ms, 0, sizeof(params));
241 switch (key->conf.alg) {
243 params.cipher = WLAN_CIPHER_SUITE_TKIP;
245 iv32 = key->u.tkip.tx.iv32;
246 iv16 = key->u.tkip.tx.iv16;
248 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
249 sdata->local->ops->get_tkip_seq)
250 sdata->local->ops->get_tkip_seq(
251 local_to_hw(sdata->local),
252 key->conf.hw_key_idx,
255 seq[0] = iv16 & 0xff;
256 seq[1] = (iv16 >> 8) & 0xff;
257 seq[2] = iv32 & 0xff;
258 seq[3] = (iv32 >> 8) & 0xff;
259 seq[4] = (iv32 >> 16) & 0xff;
260 seq[5] = (iv32 >> 24) & 0xff;
265 params.cipher = WLAN_CIPHER_SUITE_CCMP;
266 seq[0] = key->u.ccmp.tx_pn[5];
267 seq[1] = key->u.ccmp.tx_pn[4];
268 seq[2] = key->u.ccmp.tx_pn[3];
269 seq[3] = key->u.ccmp.tx_pn[2];
270 seq[4] = key->u.ccmp.tx_pn[1];
271 seq[5] = key->u.ccmp.tx_pn[0];
276 if (key->conf.keylen == 5)
277 params.cipher = WLAN_CIPHER_SUITE_WEP40;
279 params.cipher = WLAN_CIPHER_SUITE_WEP104;
282 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
283 seq[0] = key->u.aes_cmac.tx_pn[5];
284 seq[1] = key->u.aes_cmac.tx_pn[4];
285 seq[2] = key->u.aes_cmac.tx_pn[3];
286 seq[3] = key->u.aes_cmac.tx_pn[2];
287 seq[4] = key->u.aes_cmac.tx_pn[1];
288 seq[5] = key->u.aes_cmac.tx_pn[0];
294 params.key = key->conf.key;
295 params.key_len = key->conf.keylen;
297 callback(cookie, ¶ms);
305 static int ieee80211_config_default_key(struct wiphy *wiphy,
306 struct net_device *dev,
309 struct ieee80211_sub_if_data *sdata;
313 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
314 ieee80211_set_default_key(sdata, key_idx);
321 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
322 struct net_device *dev,
325 struct ieee80211_sub_if_data *sdata;
329 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
330 ieee80211_set_default_mgmt_key(sdata, key_idx);
337 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
339 struct ieee80211_sub_if_data *sdata = sta->sdata;
341 sinfo->filled = STATION_INFO_INACTIVE_TIME |
342 STATION_INFO_RX_BYTES |
343 STATION_INFO_TX_BYTES |
344 STATION_INFO_RX_PACKETS |
345 STATION_INFO_TX_PACKETS |
346 STATION_INFO_TX_BITRATE;
348 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
349 sinfo->rx_bytes = sta->rx_bytes;
350 sinfo->tx_bytes = sta->tx_bytes;
351 sinfo->rx_packets = sta->rx_packets;
352 sinfo->tx_packets = sta->tx_packets;
354 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
355 sinfo->filled |= STATION_INFO_SIGNAL;
356 sinfo->signal = (s8)sta->last_signal;
359 sinfo->txrate.flags = 0;
360 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
361 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
362 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
363 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
364 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
365 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
367 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
368 struct ieee80211_supported_band *sband;
369 sband = sta->local->hw.wiphy->bands[
370 sta->local->hw.conf.channel->band];
371 sinfo->txrate.legacy =
372 sband->bitrates[sta->last_tx_rate.idx].bitrate;
374 sinfo->txrate.mcs = sta->last_tx_rate.idx;
376 if (ieee80211_vif_is_mesh(&sdata->vif)) {
377 #ifdef CONFIG_MAC80211_MESH
378 sinfo->filled |= STATION_INFO_LLID |
380 STATION_INFO_PLINK_STATE;
382 sinfo->llid = le16_to_cpu(sta->llid);
383 sinfo->plid = le16_to_cpu(sta->plid);
384 sinfo->plink_state = sta->plink_state;
390 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
391 int idx, u8 *mac, struct station_info *sinfo)
393 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
394 struct sta_info *sta;
399 sta = sta_info_get_by_idx(local, idx, dev);
402 memcpy(mac, sta->sta.addr, ETH_ALEN);
403 sta_set_sinfo(sta, sinfo);
411 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
412 u8 *mac, struct station_info *sinfo)
414 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
415 struct sta_info *sta;
420 /* XXX: verify sta->dev == dev */
422 sta = sta_info_get(local, mac);
425 sta_set_sinfo(sta, sinfo);
434 * This handles both adding a beacon and setting new beacon info
436 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
437 struct beacon_parameters *params)
439 struct beacon_data *new, *old;
440 int new_head_len, new_tail_len;
444 old = sdata->u.ap.beacon;
446 /* head must not be zero-length */
447 if (params->head && !params->head_len)
451 * This is a kludge. beacon interval should really be part
452 * of the beacon information.
454 if (params->interval &&
455 (sdata->vif.bss_conf.beacon_int != params->interval)) {
456 sdata->vif.bss_conf.beacon_int = params->interval;
457 ieee80211_bss_info_change_notify(sdata,
458 BSS_CHANGED_BEACON_INT);
461 /* Need to have a beacon head if we don't have one yet */
462 if (!params->head && !old)
465 /* sorry, no way to start beaconing without dtim period */
466 if (!params->dtim_period && !old)
469 /* new or old head? */
471 new_head_len = params->head_len;
473 new_head_len = old->head_len;
475 /* new or old tail? */
476 if (params->tail || !old)
477 /* params->tail_len will be zero for !params->tail */
478 new_tail_len = params->tail_len;
480 new_tail_len = old->tail_len;
482 size = sizeof(*new) + new_head_len + new_tail_len;
484 new = kzalloc(size, GFP_KERNEL);
488 /* start filling the new info now */
490 /* new or old dtim period? */
491 if (params->dtim_period)
492 new->dtim_period = params->dtim_period;
494 new->dtim_period = old->dtim_period;
497 * pointers go into the block we allocated,
498 * memory is | beacon_data | head | tail |
500 new->head = ((u8 *) new) + sizeof(*new);
501 new->tail = new->head + new_head_len;
502 new->head_len = new_head_len;
503 new->tail_len = new_tail_len;
507 memcpy(new->head, params->head, new_head_len);
509 memcpy(new->head, old->head, new_head_len);
511 /* copy in optional tail */
513 memcpy(new->tail, params->tail, new_tail_len);
516 memcpy(new->tail, old->tail, new_tail_len);
518 rcu_assign_pointer(sdata->u.ap.beacon, new);
524 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON |
525 IEEE80211_IFCC_BEACON_ENABLED);
528 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
529 struct beacon_parameters *params)
531 struct ieee80211_sub_if_data *sdata;
532 struct beacon_data *old;
534 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
536 old = sdata->u.ap.beacon;
541 return ieee80211_config_beacon(sdata, params);
544 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
545 struct beacon_parameters *params)
547 struct ieee80211_sub_if_data *sdata;
548 struct beacon_data *old;
550 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
552 old = sdata->u.ap.beacon;
557 return ieee80211_config_beacon(sdata, params);
560 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
562 struct ieee80211_sub_if_data *sdata;
563 struct beacon_data *old;
565 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
567 old = sdata->u.ap.beacon;
572 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
576 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON_ENABLED);
579 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
580 struct iapp_layer2_update {
581 u8 da[ETH_ALEN]; /* broadcast */
582 u8 sa[ETH_ALEN]; /* STA addr */
588 } __attribute__ ((packed));
590 static void ieee80211_send_layer2_update(struct sta_info *sta)
592 struct iapp_layer2_update *msg;
595 /* Send Level 2 Update Frame to update forwarding tables in layer 2
598 skb = dev_alloc_skb(sizeof(*msg));
601 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
603 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
604 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
606 memset(msg->da, 0xff, ETH_ALEN);
607 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
610 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
611 msg->control = 0xaf; /* XID response lsb.1111F101.
612 * F=0 (no poll command; unsolicited frame) */
613 msg->xid_info[0] = 0x81; /* XID format identifier */
614 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
615 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
617 skb->dev = sta->sdata->dev;
618 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
619 memset(skb->cb, 0, sizeof(skb->cb));
623 static void sta_apply_parameters(struct ieee80211_local *local,
624 struct sta_info *sta,
625 struct station_parameters *params)
629 struct ieee80211_supported_band *sband;
630 struct ieee80211_sub_if_data *sdata = sta->sdata;
632 sband = local->hw.wiphy->bands[local->oper_channel->band];
635 * FIXME: updating the flags is racy when this function is
636 * called from ieee80211_change_station(), this will
637 * be resolved in a future patch.
640 if (params->station_flags & STATION_FLAG_CHANGED) {
641 spin_lock_bh(&sta->lock);
642 sta->flags &= ~WLAN_STA_AUTHORIZED;
643 if (params->station_flags & STATION_FLAG_AUTHORIZED)
644 sta->flags |= WLAN_STA_AUTHORIZED;
646 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
647 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
648 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
650 sta->flags &= ~WLAN_STA_WME;
651 if (params->station_flags & STATION_FLAG_WME)
652 sta->flags |= WLAN_STA_WME;
654 sta->flags &= ~WLAN_STA_MFP;
655 if (params->station_flags & STATION_FLAG_MFP)
656 sta->flags |= WLAN_STA_MFP;
657 spin_unlock_bh(&sta->lock);
661 * FIXME: updating the following information is racy when this
662 * function is called from ieee80211_change_station().
663 * However, all this information should be static so
664 * maybe we should just reject attemps to change it.
668 sta->sta.aid = params->aid;
669 if (sta->sta.aid > IEEE80211_MAX_AID)
670 sta->sta.aid = 0; /* XXX: should this be an error? */
673 if (params->listen_interval >= 0)
674 sta->listen_interval = params->listen_interval;
676 if (params->supported_rates) {
679 for (i = 0; i < params->supported_rates_len; i++) {
680 int rate = (params->supported_rates[i] & 0x7f) * 5;
681 for (j = 0; j < sband->n_bitrates; j++) {
682 if (sband->bitrates[j].bitrate == rate)
686 sta->sta.supp_rates[local->oper_channel->band] = rates;
690 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
694 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
695 switch (params->plink_action) {
696 case PLINK_ACTION_OPEN:
697 mesh_plink_open(sta);
699 case PLINK_ACTION_BLOCK:
700 mesh_plink_block(sta);
706 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
707 u8 *mac, struct station_parameters *params)
709 struct ieee80211_local *local = wiphy_priv(wiphy);
710 struct sta_info *sta;
711 struct ieee80211_sub_if_data *sdata;
716 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
718 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
719 sdata->vif.type != NL80211_IFTYPE_AP)
722 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
724 if (compare_ether_addr(mac, dev->dev_addr) == 0)
727 if (is_multicast_ether_addr(mac))
730 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
734 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
736 sta_apply_parameters(local, sta, params);
738 rate_control_rate_init(sta);
740 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
741 sdata->vif.type == NL80211_IFTYPE_AP;
745 err = sta_info_insert(sta);
747 /* STA has been freed */
748 if (err == -EEXIST && layer2_update) {
749 /* Need to update layer 2 devices on reassociation */
750 sta = sta_info_get(local, mac);
752 ieee80211_send_layer2_update(sta);
759 ieee80211_send_layer2_update(sta);
766 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
769 struct ieee80211_local *local = wiphy_priv(wiphy);
770 struct ieee80211_sub_if_data *sdata;
771 struct sta_info *sta;
773 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
778 /* XXX: get sta belonging to dev */
779 sta = sta_info_get(local, mac);
785 sta_info_unlink(&sta);
788 sta_info_destroy(sta);
790 sta_info_flush(local, sdata);
795 static int ieee80211_change_station(struct wiphy *wiphy,
796 struct net_device *dev,
798 struct station_parameters *params)
800 struct ieee80211_local *local = wiphy_priv(wiphy);
801 struct sta_info *sta;
802 struct ieee80211_sub_if_data *vlansdata;
806 /* XXX: get sta belonging to dev */
807 sta = sta_info_get(local, mac);
813 if (params->vlan && params->vlan != sta->sdata->dev) {
814 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
816 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
817 vlansdata->vif.type != NL80211_IFTYPE_AP) {
822 sta->sdata = vlansdata;
823 ieee80211_send_layer2_update(sta);
826 sta_apply_parameters(local, sta, params);
833 #ifdef CONFIG_MAC80211_MESH
834 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
835 u8 *dst, u8 *next_hop)
837 struct ieee80211_local *local = wiphy_priv(wiphy);
838 struct ieee80211_sub_if_data *sdata;
839 struct mesh_path *mpath;
840 struct sta_info *sta;
843 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
846 sta = sta_info_get(local, next_hop);
852 err = mesh_path_add(dst, sdata);
858 mpath = mesh_path_lookup(dst, sdata);
863 mesh_path_fix_nexthop(mpath, sta);
869 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
872 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
875 return mesh_path_del(dst, sdata);
877 mesh_path_flush(sdata);
881 static int ieee80211_change_mpath(struct wiphy *wiphy,
882 struct net_device *dev,
883 u8 *dst, u8 *next_hop)
885 struct ieee80211_local *local = wiphy_priv(wiphy);
886 struct ieee80211_sub_if_data *sdata;
887 struct mesh_path *mpath;
888 struct sta_info *sta;
890 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
894 sta = sta_info_get(local, next_hop);
900 mpath = mesh_path_lookup(dst, sdata);
906 mesh_path_fix_nexthop(mpath, sta);
912 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
913 struct mpath_info *pinfo)
916 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
918 memset(next_hop, 0, ETH_ALEN);
920 pinfo->filled = MPATH_INFO_FRAME_QLEN |
924 MPATH_INFO_DISCOVERY_TIMEOUT |
925 MPATH_INFO_DISCOVERY_RETRIES |
928 pinfo->frame_qlen = mpath->frame_queue.qlen;
929 pinfo->dsn = mpath->dsn;
930 pinfo->metric = mpath->metric;
931 if (time_before(jiffies, mpath->exp_time))
932 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
933 pinfo->discovery_timeout =
934 jiffies_to_msecs(mpath->discovery_timeout);
935 pinfo->discovery_retries = mpath->discovery_retries;
937 if (mpath->flags & MESH_PATH_ACTIVE)
938 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
939 if (mpath->flags & MESH_PATH_RESOLVING)
940 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
941 if (mpath->flags & MESH_PATH_DSN_VALID)
942 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
943 if (mpath->flags & MESH_PATH_FIXED)
944 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
945 if (mpath->flags & MESH_PATH_RESOLVING)
946 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
948 pinfo->flags = mpath->flags;
951 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
952 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
955 struct ieee80211_sub_if_data *sdata;
956 struct mesh_path *mpath;
958 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
961 mpath = mesh_path_lookup(dst, sdata);
966 memcpy(dst, mpath->dst, ETH_ALEN);
967 mpath_set_pinfo(mpath, next_hop, pinfo);
972 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
973 int idx, u8 *dst, u8 *next_hop,
974 struct mpath_info *pinfo)
976 struct ieee80211_sub_if_data *sdata;
977 struct mesh_path *mpath;
979 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
982 mpath = mesh_path_lookup_by_idx(idx, sdata);
987 memcpy(dst, mpath->dst, ETH_ALEN);
988 mpath_set_pinfo(mpath, next_hop, pinfo);
993 static int ieee80211_get_mesh_params(struct wiphy *wiphy,
994 struct net_device *dev,
995 struct mesh_config *conf)
997 struct ieee80211_sub_if_data *sdata;
998 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1000 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1004 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1006 return (mask >> (parm-1)) & 0x1;
1009 static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1010 struct net_device *dev,
1011 const struct mesh_config *nconf, u32 mask)
1013 struct mesh_config *conf;
1014 struct ieee80211_sub_if_data *sdata;
1015 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1017 /* Set the config options which we are interested in setting */
1018 conf = &(sdata->u.mesh.mshcfg);
1019 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1020 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1021 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1022 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1023 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1024 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1025 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1026 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1027 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1028 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1029 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1030 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1031 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1032 conf->auto_open_plinks = nconf->auto_open_plinks;
1033 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1034 conf->dot11MeshHWMPmaxPREQretries =
1035 nconf->dot11MeshHWMPmaxPREQretries;
1036 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1037 conf->path_refresh_time = nconf->path_refresh_time;
1038 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1039 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1040 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1041 conf->dot11MeshHWMPactivePathTimeout =
1042 nconf->dot11MeshHWMPactivePathTimeout;
1043 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1044 conf->dot11MeshHWMPpreqMinInterval =
1045 nconf->dot11MeshHWMPpreqMinInterval;
1046 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1048 conf->dot11MeshHWMPnetDiameterTraversalTime =
1049 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1055 static int ieee80211_change_bss(struct wiphy *wiphy,
1056 struct net_device *dev,
1057 struct bss_parameters *params)
1059 struct ieee80211_sub_if_data *sdata;
1062 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1064 if (params->use_cts_prot >= 0) {
1065 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1066 changed |= BSS_CHANGED_ERP_CTS_PROT;
1068 if (params->use_short_preamble >= 0) {
1069 sdata->vif.bss_conf.use_short_preamble =
1070 params->use_short_preamble;
1071 changed |= BSS_CHANGED_ERP_PREAMBLE;
1073 if (params->use_short_slot_time >= 0) {
1074 sdata->vif.bss_conf.use_short_slot =
1075 params->use_short_slot_time;
1076 changed |= BSS_CHANGED_ERP_SLOT;
1079 if (params->basic_rates) {
1082 struct ieee80211_local *local = wiphy_priv(wiphy);
1083 struct ieee80211_supported_band *sband =
1084 wiphy->bands[local->oper_channel->band];
1086 for (i = 0; i < params->basic_rates_len; i++) {
1087 int rate = (params->basic_rates[i] & 0x7f) * 5;
1088 for (j = 0; j < sband->n_bitrates; j++) {
1089 if (sband->bitrates[j].bitrate == rate)
1093 sdata->vif.bss_conf.basic_rates = rates;
1094 changed |= BSS_CHANGED_BASIC_RATES;
1097 ieee80211_bss_info_change_notify(sdata, changed);
1102 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1103 struct ieee80211_txq_params *params)
1105 struct ieee80211_local *local = wiphy_priv(wiphy);
1106 struct ieee80211_tx_queue_params p;
1108 if (!local->ops->conf_tx)
1111 memset(&p, 0, sizeof(p));
1112 p.aifs = params->aifs;
1113 p.cw_max = params->cwmax;
1114 p.cw_min = params->cwmin;
1115 p.txop = params->txop;
1116 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1117 printk(KERN_DEBUG "%s: failed to set TX queue "
1118 "parameters for queue %d\n", local->mdev->name,
1126 static int ieee80211_set_channel(struct wiphy *wiphy,
1127 struct ieee80211_channel *chan,
1128 enum nl80211_channel_type channel_type)
1130 struct ieee80211_local *local = wiphy_priv(wiphy);
1132 local->oper_channel = chan;
1133 local->oper_channel_type = channel_type;
1135 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1139 static int ieee80211_suspend(struct wiphy *wiphy)
1141 return __ieee80211_suspend(wiphy_priv(wiphy));
1144 static int ieee80211_resume(struct wiphy *wiphy)
1146 return __ieee80211_resume(wiphy_priv(wiphy));
1149 #define ieee80211_suspend NULL
1150 #define ieee80211_resume NULL
1153 static int ieee80211_scan(struct wiphy *wiphy,
1154 struct net_device *dev,
1155 struct cfg80211_scan_request *req)
1157 struct ieee80211_sub_if_data *sdata;
1159 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1161 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1162 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1163 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1164 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
1167 return ieee80211_request_scan(sdata, req);
1170 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1171 struct cfg80211_auth_request *req)
1173 struct ieee80211_sub_if_data *sdata;
1175 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1177 switch (req->auth_type) {
1178 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1179 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
1181 case NL80211_AUTHTYPE_SHARED_KEY:
1182 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY;
1184 case NL80211_AUTHTYPE_FT:
1185 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT;
1187 case NL80211_AUTHTYPE_NETWORK_EAP:
1188 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP;
1194 memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
1195 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1196 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1198 /* TODO: req->chan */
1199 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1202 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1203 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1204 sdata->u.mgd.ssid_len = req->ssid_len;
1205 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1208 kfree(sdata->u.mgd.sme_auth_ie);
1209 sdata->u.mgd.sme_auth_ie = NULL;
1210 sdata->u.mgd.sme_auth_ie_len = 0;
1212 sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL);
1213 if (sdata->u.mgd.sme_auth_ie == NULL)
1215 memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len);
1216 sdata->u.mgd.sme_auth_ie_len = req->ie_len;
1219 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1220 sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
1221 ieee80211_sta_req_auth(sdata);
1225 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1226 struct cfg80211_assoc_request *req)
1228 struct ieee80211_sub_if_data *sdata;
1231 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1233 if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
1234 !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
1235 return -ENOLINK; /* not authenticated */
1237 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1238 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1240 /* TODO: req->chan */
1241 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1244 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1245 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1246 sdata->u.mgd.ssid_len = req->ssid_len;
1247 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1249 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
1251 ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
1255 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1256 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
1257 ieee80211_sta_req_auth(sdata);
1261 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1262 struct cfg80211_deauth_request *req)
1264 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1266 /* TODO: req->ie, req->peer_addr */
1267 return ieee80211_sta_deauthenticate(sdata, req->reason_code);
1270 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1271 struct cfg80211_disassoc_request *req)
1273 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1275 /* TODO: req->ie, req->peer_addr */
1276 return ieee80211_sta_disassociate(sdata, req->reason_code);
1279 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1280 struct cfg80211_ibss_params *params)
1282 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1284 return ieee80211_ibss_join(sdata, params);
1287 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1289 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1291 return ieee80211_ibss_leave(sdata);
1294 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1296 struct ieee80211_local *local = wiphy_priv(wiphy);
1298 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1301 if (local->ops->set_rts_threshold) {
1302 err = local->ops->set_rts_threshold(
1303 local_to_hw(local), wiphy->rts_threshold);
1309 if (changed & WIPHY_PARAM_RETRY_SHORT)
1310 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1311 if (changed & WIPHY_PARAM_RETRY_LONG)
1312 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1314 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1315 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1320 struct cfg80211_ops mac80211_config_ops = {
1321 .add_virtual_intf = ieee80211_add_iface,
1322 .del_virtual_intf = ieee80211_del_iface,
1323 .change_virtual_intf = ieee80211_change_iface,
1324 .add_key = ieee80211_add_key,
1325 .del_key = ieee80211_del_key,
1326 .get_key = ieee80211_get_key,
1327 .set_default_key = ieee80211_config_default_key,
1328 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
1329 .add_beacon = ieee80211_add_beacon,
1330 .set_beacon = ieee80211_set_beacon,
1331 .del_beacon = ieee80211_del_beacon,
1332 .add_station = ieee80211_add_station,
1333 .del_station = ieee80211_del_station,
1334 .change_station = ieee80211_change_station,
1335 .get_station = ieee80211_get_station,
1336 .dump_station = ieee80211_dump_station,
1337 #ifdef CONFIG_MAC80211_MESH
1338 .add_mpath = ieee80211_add_mpath,
1339 .del_mpath = ieee80211_del_mpath,
1340 .change_mpath = ieee80211_change_mpath,
1341 .get_mpath = ieee80211_get_mpath,
1342 .dump_mpath = ieee80211_dump_mpath,
1343 .set_mesh_params = ieee80211_set_mesh_params,
1344 .get_mesh_params = ieee80211_get_mesh_params,
1346 .change_bss = ieee80211_change_bss,
1347 .set_txq_params = ieee80211_set_txq_params,
1348 .set_channel = ieee80211_set_channel,
1349 .suspend = ieee80211_suspend,
1350 .resume = ieee80211_resume,
1351 .scan = ieee80211_scan,
1352 .auth = ieee80211_auth,
1353 .assoc = ieee80211_assoc,
1354 .deauth = ieee80211_deauth,
1355 .disassoc = ieee80211_disassoc,
1356 .join_ibss = ieee80211_join_ibss,
1357 .leave_ibss = ieee80211_leave_ibss,
1358 .set_wiphy_params = ieee80211_set_wiphy_params,