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
:
140 key
= ieee80211_key_alloc(alg
, key_idx
, params
->key_len
, params
->key
);
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
, 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
, 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 sdata
->local
->ops
->get_tkip_seq
)
247 sdata
->local
->ops
->get_tkip_seq(
248 local_to_hw(sdata
->local
),
249 key
->conf
.hw_key_idx
,
252 seq
[0] = iv16
& 0xff;
253 seq
[1] = (iv16
>> 8) & 0xff;
254 seq
[2] = iv32
& 0xff;
255 seq
[3] = (iv32
>> 8) & 0xff;
256 seq
[4] = (iv32
>> 16) & 0xff;
257 seq
[5] = (iv32
>> 24) & 0xff;
262 params
.cipher
= WLAN_CIPHER_SUITE_CCMP
;
263 seq
[0] = key
->u
.ccmp
.tx_pn
[5];
264 seq
[1] = key
->u
.ccmp
.tx_pn
[4];
265 seq
[2] = key
->u
.ccmp
.tx_pn
[3];
266 seq
[3] = key
->u
.ccmp
.tx_pn
[2];
267 seq
[4] = key
->u
.ccmp
.tx_pn
[1];
268 seq
[5] = key
->u
.ccmp
.tx_pn
[0];
273 if (key
->conf
.keylen
== 5)
274 params
.cipher
= WLAN_CIPHER_SUITE_WEP40
;
276 params
.cipher
= WLAN_CIPHER_SUITE_WEP104
;
280 params
.key
= key
->conf
.key
;
281 params
.key_len
= key
->conf
.keylen
;
283 callback(cookie
, ¶ms
);
291 static int ieee80211_config_default_key(struct wiphy
*wiphy
,
292 struct net_device
*dev
,
295 struct ieee80211_sub_if_data
*sdata
;
299 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
300 ieee80211_set_default_key(sdata
, key_idx
);
307 static void sta_set_sinfo(struct sta_info
*sta
, struct station_info
*sinfo
)
309 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
311 sinfo
->filled
= STATION_INFO_INACTIVE_TIME
|
312 STATION_INFO_RX_BYTES
|
313 STATION_INFO_TX_BYTES
|
314 STATION_INFO_TX_BITRATE
;
316 sinfo
->inactive_time
= jiffies_to_msecs(jiffies
- sta
->last_rx
);
317 sinfo
->rx_bytes
= sta
->rx_bytes
;
318 sinfo
->tx_bytes
= sta
->tx_bytes
;
320 if (sta
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
) {
321 sinfo
->filled
|= STATION_INFO_SIGNAL
;
322 sinfo
->signal
= (s8
)sta
->last_signal
;
325 sinfo
->txrate
.flags
= 0;
326 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_MCS
)
327 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_MCS
;
328 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
329 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_40_MHZ_WIDTH
;
330 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_SHORT_GI
)
331 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_SHORT_GI
;
333 if (!(sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_MCS
)) {
334 struct ieee80211_supported_band
*sband
;
335 sband
= sta
->local
->hw
.wiphy
->bands
[
336 sta
->local
->hw
.conf
.channel
->band
];
337 sinfo
->txrate
.legacy
=
338 sband
->bitrates
[sta
->last_tx_rate
.idx
].bitrate
;
340 sinfo
->txrate
.mcs
= sta
->last_tx_rate
.idx
;
342 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
343 #ifdef CONFIG_MAC80211_MESH
344 sinfo
->filled
|= STATION_INFO_LLID
|
346 STATION_INFO_PLINK_STATE
;
348 sinfo
->llid
= le16_to_cpu(sta
->llid
);
349 sinfo
->plid
= le16_to_cpu(sta
->plid
);
350 sinfo
->plink_state
= sta
->plink_state
;
356 static int ieee80211_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
357 int idx
, u8
*mac
, struct station_info
*sinfo
)
359 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
360 struct sta_info
*sta
;
365 sta
= sta_info_get_by_idx(local
, idx
, dev
);
368 memcpy(mac
, sta
->sta
.addr
, ETH_ALEN
);
369 sta_set_sinfo(sta
, sinfo
);
377 static int ieee80211_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
378 u8
*mac
, struct station_info
*sinfo
)
380 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
381 struct sta_info
*sta
;
386 /* XXX: verify sta->dev == dev */
388 sta
= sta_info_get(local
, mac
);
391 sta_set_sinfo(sta
, sinfo
);
400 * This handles both adding a beacon and setting new beacon info
402 static int ieee80211_config_beacon(struct ieee80211_sub_if_data
*sdata
,
403 struct beacon_parameters
*params
)
405 struct beacon_data
*new, *old
;
406 int new_head_len
, new_tail_len
;
410 old
= sdata
->u
.ap
.beacon
;
412 /* head must not be zero-length */
413 if (params
->head
&& !params
->head_len
)
417 * This is a kludge. beacon interval should really be part
418 * of the beacon information.
420 if (params
->interval
) {
421 sdata
->local
->hw
.conf
.beacon_int
= params
->interval
;
422 err
= ieee80211_hw_config(sdata
->local
,
423 IEEE80211_CONF_CHANGE_BEACON_INTERVAL
);
427 * We updated some parameter so if below bails out
433 /* Need to have a beacon head if we don't have one yet */
434 if (!params
->head
&& !old
)
437 /* sorry, no way to start beaconing without dtim period */
438 if (!params
->dtim_period
&& !old
)
441 /* new or old head? */
443 new_head_len
= params
->head_len
;
445 new_head_len
= old
->head_len
;
447 /* new or old tail? */
448 if (params
->tail
|| !old
)
449 /* params->tail_len will be zero for !params->tail */
450 new_tail_len
= params
->tail_len
;
452 new_tail_len
= old
->tail_len
;
454 size
= sizeof(*new) + new_head_len
+ new_tail_len
;
456 new = kzalloc(size
, GFP_KERNEL
);
460 /* start filling the new info now */
462 /* new or old dtim period? */
463 if (params
->dtim_period
)
464 new->dtim_period
= params
->dtim_period
;
466 new->dtim_period
= old
->dtim_period
;
469 * pointers go into the block we allocated,
470 * memory is | beacon_data | head | tail |
472 new->head
= ((u8
*) new) + sizeof(*new);
473 new->tail
= new->head
+ new_head_len
;
474 new->head_len
= new_head_len
;
475 new->tail_len
= new_tail_len
;
479 memcpy(new->head
, params
->head
, new_head_len
);
481 memcpy(new->head
, old
->head
, new_head_len
);
483 /* copy in optional tail */
485 memcpy(new->tail
, params
->tail
, new_tail_len
);
488 memcpy(new->tail
, old
->tail
, new_tail_len
);
490 rcu_assign_pointer(sdata
->u
.ap
.beacon
, new);
496 return ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON
);
499 static int ieee80211_add_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
500 struct beacon_parameters
*params
)
502 struct ieee80211_sub_if_data
*sdata
;
503 struct beacon_data
*old
;
505 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
507 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
510 old
= sdata
->u
.ap
.beacon
;
515 return ieee80211_config_beacon(sdata
, params
);
518 static int ieee80211_set_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
519 struct beacon_parameters
*params
)
521 struct ieee80211_sub_if_data
*sdata
;
522 struct beacon_data
*old
;
524 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
526 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
529 old
= sdata
->u
.ap
.beacon
;
534 return ieee80211_config_beacon(sdata
, params
);
537 static int ieee80211_del_beacon(struct wiphy
*wiphy
, struct net_device
*dev
)
539 struct ieee80211_sub_if_data
*sdata
;
540 struct beacon_data
*old
;
542 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
544 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
547 old
= sdata
->u
.ap
.beacon
;
552 rcu_assign_pointer(sdata
->u
.ap
.beacon
, NULL
);
556 return ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON
);
559 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
560 struct iapp_layer2_update
{
561 u8 da
[ETH_ALEN
]; /* broadcast */
562 u8 sa
[ETH_ALEN
]; /* STA addr */
568 } __attribute__ ((packed
));
570 static void ieee80211_send_layer2_update(struct sta_info
*sta
)
572 struct iapp_layer2_update
*msg
;
575 /* Send Level 2 Update Frame to update forwarding tables in layer 2
578 skb
= dev_alloc_skb(sizeof(*msg
));
581 msg
= (struct iapp_layer2_update
*)skb_put(skb
, sizeof(*msg
));
583 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
584 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
586 memset(msg
->da
, 0xff, ETH_ALEN
);
587 memcpy(msg
->sa
, sta
->sta
.addr
, ETH_ALEN
);
590 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
591 msg
->control
= 0xaf; /* XID response lsb.1111F101.
592 * F=0 (no poll command; unsolicited frame) */
593 msg
->xid_info
[0] = 0x81; /* XID format identifier */
594 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
595 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
597 skb
->dev
= sta
->sdata
->dev
;
598 skb
->protocol
= eth_type_trans(skb
, sta
->sdata
->dev
);
599 memset(skb
->cb
, 0, sizeof(skb
->cb
));
603 static void sta_apply_parameters(struct ieee80211_local
*local
,
604 struct sta_info
*sta
,
605 struct station_parameters
*params
)
609 struct ieee80211_supported_band
*sband
;
610 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
612 sband
= local
->hw
.wiphy
->bands
[local
->oper_channel
->band
];
615 * FIXME: updating the flags is racy when this function is
616 * called from ieee80211_change_station(), this will
617 * be resolved in a future patch.
620 if (params
->station_flags
& STATION_FLAG_CHANGED
) {
621 spin_lock_bh(&sta
->lock
);
622 sta
->flags
&= ~WLAN_STA_AUTHORIZED
;
623 if (params
->station_flags
& STATION_FLAG_AUTHORIZED
)
624 sta
->flags
|= WLAN_STA_AUTHORIZED
;
626 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
627 if (params
->station_flags
& STATION_FLAG_SHORT_PREAMBLE
)
628 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
630 sta
->flags
&= ~WLAN_STA_WME
;
631 if (params
->station_flags
& STATION_FLAG_WME
)
632 sta
->flags
|= WLAN_STA_WME
;
633 spin_unlock_bh(&sta
->lock
);
637 * FIXME: updating the following information is racy when this
638 * function is called from ieee80211_change_station().
639 * However, all this information should be static so
640 * maybe we should just reject attemps to change it.
644 sta
->sta
.aid
= params
->aid
;
645 if (sta
->sta
.aid
> IEEE80211_MAX_AID
)
646 sta
->sta
.aid
= 0; /* XXX: should this be an error? */
649 if (params
->listen_interval
>= 0)
650 sta
->listen_interval
= params
->listen_interval
;
652 if (params
->supported_rates
) {
655 for (i
= 0; i
< params
->supported_rates_len
; i
++) {
656 int rate
= (params
->supported_rates
[i
] & 0x7f) * 5;
657 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
658 if (sband
->bitrates
[j
].bitrate
== rate
)
662 sta
->sta
.supp_rates
[local
->oper_channel
->band
] = rates
;
666 ieee80211_ht_cap_ie_to_sta_ht_cap(sband
,
670 if (ieee80211_vif_is_mesh(&sdata
->vif
) && params
->plink_action
) {
671 switch (params
->plink_action
) {
672 case PLINK_ACTION_OPEN
:
673 mesh_plink_open(sta
);
675 case PLINK_ACTION_BLOCK
:
676 mesh_plink_block(sta
);
682 static int ieee80211_add_station(struct wiphy
*wiphy
, struct net_device
*dev
,
683 u8
*mac
, struct station_parameters
*params
)
685 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
686 struct sta_info
*sta
;
687 struct ieee80211_sub_if_data
*sdata
;
691 /* Prevent a race with changing the rate control algorithm */
692 if (!netif_running(dev
))
696 sdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
698 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
699 sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
702 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
704 if (compare_ether_addr(mac
, dev
->dev_addr
) == 0)
707 if (is_multicast_ether_addr(mac
))
710 sta
= sta_info_alloc(sdata
, mac
, GFP_KERNEL
);
714 sta
->flags
= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
716 sta_apply_parameters(local
, sta
, params
);
718 rate_control_rate_init(sta
);
720 layer2_update
= sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
||
721 sdata
->vif
.type
== NL80211_IFTYPE_AP
;
725 err
= sta_info_insert(sta
);
727 /* STA has been freed */
728 if (err
== -EEXIST
&& layer2_update
) {
729 /* Need to update layer 2 devices on reassociation */
730 sta
= sta_info_get(local
, mac
);
732 ieee80211_send_layer2_update(sta
);
739 ieee80211_send_layer2_update(sta
);
746 static int ieee80211_del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
749 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
750 struct ieee80211_sub_if_data
*sdata
;
751 struct sta_info
*sta
;
753 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
758 /* XXX: get sta belonging to dev */
759 sta
= sta_info_get(local
, mac
);
765 sta_info_unlink(&sta
);
768 sta_info_destroy(sta
);
770 sta_info_flush(local
, sdata
);
775 static int ieee80211_change_station(struct wiphy
*wiphy
,
776 struct net_device
*dev
,
778 struct station_parameters
*params
)
780 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
781 struct sta_info
*sta
;
782 struct ieee80211_sub_if_data
*vlansdata
;
786 /* XXX: get sta belonging to dev */
787 sta
= sta_info_get(local
, mac
);
793 if (params
->vlan
&& params
->vlan
!= sta
->sdata
->dev
) {
794 vlansdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
796 if (vlansdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
797 vlansdata
->vif
.type
!= NL80211_IFTYPE_AP
) {
802 sta
->sdata
= vlansdata
;
803 ieee80211_send_layer2_update(sta
);
806 sta_apply_parameters(local
, sta
, params
);
813 #ifdef CONFIG_MAC80211_MESH
814 static int ieee80211_add_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
815 u8
*dst
, u8
*next_hop
)
817 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
818 struct ieee80211_sub_if_data
*sdata
;
819 struct mesh_path
*mpath
;
820 struct sta_info
*sta
;
823 if (!netif_running(dev
))
826 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
828 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
832 sta
= sta_info_get(local
, next_hop
);
838 err
= mesh_path_add(dst
, sdata
);
844 mpath
= mesh_path_lookup(dst
, sdata
);
849 mesh_path_fix_nexthop(mpath
, sta
);
855 static int ieee80211_del_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
858 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
861 return mesh_path_del(dst
, sdata
);
863 mesh_path_flush(sdata
);
867 static int ieee80211_change_mpath(struct wiphy
*wiphy
,
868 struct net_device
*dev
,
869 u8
*dst
, u8
*next_hop
)
871 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
872 struct ieee80211_sub_if_data
*sdata
;
873 struct mesh_path
*mpath
;
874 struct sta_info
*sta
;
876 if (!netif_running(dev
))
879 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
881 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
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
);
952 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
956 mpath
= mesh_path_lookup(dst
, sdata
);
961 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
962 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
967 static int ieee80211_dump_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
968 int idx
, u8
*dst
, u8
*next_hop
,
969 struct mpath_info
*pinfo
)
971 struct ieee80211_sub_if_data
*sdata
;
972 struct mesh_path
*mpath
;
974 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
976 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
980 mpath
= mesh_path_lookup_by_idx(idx
, sdata
);
985 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
986 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
991 static int ieee80211_get_mesh_params(struct wiphy
*wiphy
,
992 struct net_device
*dev
,
993 struct mesh_config
*conf
)
995 struct ieee80211_sub_if_data
*sdata
;
996 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
998 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
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 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
1020 /* Set the config options which we are interested in setting */
1021 conf
= &(sdata
->u
.mesh
.mshcfg
);
1022 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT
, mask
))
1023 conf
->dot11MeshRetryTimeout
= nconf
->dot11MeshRetryTimeout
;
1024 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT
, mask
))
1025 conf
->dot11MeshConfirmTimeout
= nconf
->dot11MeshConfirmTimeout
;
1026 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT
, mask
))
1027 conf
->dot11MeshHoldingTimeout
= nconf
->dot11MeshHoldingTimeout
;
1028 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS
, mask
))
1029 conf
->dot11MeshMaxPeerLinks
= nconf
->dot11MeshMaxPeerLinks
;
1030 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES
, mask
))
1031 conf
->dot11MeshMaxRetries
= nconf
->dot11MeshMaxRetries
;
1032 if (_chg_mesh_attr(NL80211_MESHCONF_TTL
, mask
))
1033 conf
->dot11MeshTTL
= nconf
->dot11MeshTTL
;
1034 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS
, mask
))
1035 conf
->auto_open_plinks
= nconf
->auto_open_plinks
;
1036 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
, mask
))
1037 conf
->dot11MeshHWMPmaxPREQretries
=
1038 nconf
->dot11MeshHWMPmaxPREQretries
;
1039 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME
, mask
))
1040 conf
->path_refresh_time
= nconf
->path_refresh_time
;
1041 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
, mask
))
1042 conf
->min_discovery_timeout
= nconf
->min_discovery_timeout
;
1043 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
, mask
))
1044 conf
->dot11MeshHWMPactivePathTimeout
=
1045 nconf
->dot11MeshHWMPactivePathTimeout
;
1046 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
, mask
))
1047 conf
->dot11MeshHWMPpreqMinInterval
=
1048 nconf
->dot11MeshHWMPpreqMinInterval
;
1049 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
1051 conf
->dot11MeshHWMPnetDiameterTraversalTime
=
1052 nconf
->dot11MeshHWMPnetDiameterTraversalTime
;
1058 static int ieee80211_change_bss(struct wiphy
*wiphy
,
1059 struct net_device
*dev
,
1060 struct bss_parameters
*params
)
1062 struct ieee80211_sub_if_data
*sdata
;
1065 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1067 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
1070 if (params
->use_cts_prot
>= 0) {
1071 sdata
->vif
.bss_conf
.use_cts_prot
= params
->use_cts_prot
;
1072 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
1074 if (params
->use_short_preamble
>= 0) {
1075 sdata
->vif
.bss_conf
.use_short_preamble
=
1076 params
->use_short_preamble
;
1077 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
1079 if (params
->use_short_slot_time
>= 0) {
1080 sdata
->vif
.bss_conf
.use_short_slot
=
1081 params
->use_short_slot_time
;
1082 changed
|= BSS_CHANGED_ERP_SLOT
;
1085 if (params
->basic_rates
) {
1088 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1089 struct ieee80211_supported_band
*sband
=
1090 wiphy
->bands
[local
->oper_channel
->band
];
1092 for (i
= 0; i
< params
->basic_rates_len
; i
++) {
1093 int rate
= (params
->basic_rates
[i
] & 0x7f) * 5;
1094 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1095 if (sband
->bitrates
[j
].bitrate
== rate
)
1099 sdata
->vif
.bss_conf
.basic_rates
= rates
;
1100 changed
|= BSS_CHANGED_BASIC_RATES
;
1103 ieee80211_bss_info_change_notify(sdata
, changed
);
1108 static int ieee80211_set_txq_params(struct wiphy
*wiphy
,
1109 struct ieee80211_txq_params
*params
)
1111 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1112 struct ieee80211_tx_queue_params p
;
1114 if (!local
->ops
->conf_tx
)
1117 memset(&p
, 0, sizeof(p
));
1118 p
.aifs
= params
->aifs
;
1119 p
.cw_max
= params
->cwmax
;
1120 p
.cw_min
= params
->cwmin
;
1121 p
.txop
= params
->txop
;
1122 if (local
->ops
->conf_tx(local_to_hw(local
), params
->queue
, &p
)) {
1123 printk(KERN_DEBUG
"%s: failed to set TX queue "
1124 "parameters for queue %d\n", local
->mdev
->name
,
1132 static int ieee80211_set_channel(struct wiphy
*wiphy
,
1133 struct ieee80211_channel
*chan
,
1134 enum nl80211_channel_type channel_type
)
1136 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1138 local
->oper_channel
= chan
;
1139 local
->oper_channel_type
= channel_type
;
1141 return ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
1144 struct cfg80211_ops mac80211_config_ops
= {
1145 .add_virtual_intf
= ieee80211_add_iface
,
1146 .del_virtual_intf
= ieee80211_del_iface
,
1147 .change_virtual_intf
= ieee80211_change_iface
,
1148 .add_key
= ieee80211_add_key
,
1149 .del_key
= ieee80211_del_key
,
1150 .get_key
= ieee80211_get_key
,
1151 .set_default_key
= ieee80211_config_default_key
,
1152 .add_beacon
= ieee80211_add_beacon
,
1153 .set_beacon
= ieee80211_set_beacon
,
1154 .del_beacon
= ieee80211_del_beacon
,
1155 .add_station
= ieee80211_add_station
,
1156 .del_station
= ieee80211_del_station
,
1157 .change_station
= ieee80211_change_station
,
1158 .get_station
= ieee80211_get_station
,
1159 .dump_station
= ieee80211_dump_station
,
1160 #ifdef CONFIG_MAC80211_MESH
1161 .add_mpath
= ieee80211_add_mpath
,
1162 .del_mpath
= ieee80211_del_mpath
,
1163 .change_mpath
= ieee80211_change_mpath
,
1164 .get_mpath
= ieee80211_get_mpath
,
1165 .dump_mpath
= ieee80211_dump_mpath
,
1166 .set_mesh_params
= ieee80211_set_mesh_params
,
1167 .get_mesh_params
= ieee80211_get_mesh_params
,
1169 .change_bss
= ieee80211_change_bss
,
1170 .set_txq_params
= ieee80211_set_txq_params
,
1171 .set_channel
= ieee80211_set_channel
,