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_TX_BITRATE
;
346 sinfo
->inactive_time
= jiffies_to_msecs(jiffies
- sta
->last_rx
);
347 sinfo
->rx_bytes
= sta
->rx_bytes
;
348 sinfo
->tx_bytes
= sta
->tx_bytes
;
350 if (sta
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
) {
351 sinfo
->filled
|= STATION_INFO_SIGNAL
;
352 sinfo
->signal
= (s8
)sta
->last_signal
;
355 sinfo
->txrate
.flags
= 0;
356 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_MCS
)
357 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_MCS
;
358 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
359 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_40_MHZ_WIDTH
;
360 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_SHORT_GI
)
361 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_SHORT_GI
;
363 if (!(sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_MCS
)) {
364 struct ieee80211_supported_band
*sband
;
365 sband
= sta
->local
->hw
.wiphy
->bands
[
366 sta
->local
->hw
.conf
.channel
->band
];
367 sinfo
->txrate
.legacy
=
368 sband
->bitrates
[sta
->last_tx_rate
.idx
].bitrate
;
370 sinfo
->txrate
.mcs
= sta
->last_tx_rate
.idx
;
372 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
373 #ifdef CONFIG_MAC80211_MESH
374 sinfo
->filled
|= STATION_INFO_LLID
|
376 STATION_INFO_PLINK_STATE
;
378 sinfo
->llid
= le16_to_cpu(sta
->llid
);
379 sinfo
->plid
= le16_to_cpu(sta
->plid
);
380 sinfo
->plink_state
= sta
->plink_state
;
386 static int ieee80211_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
387 int idx
, u8
*mac
, struct station_info
*sinfo
)
389 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
390 struct sta_info
*sta
;
395 sta
= sta_info_get_by_idx(local
, idx
, dev
);
398 memcpy(mac
, sta
->sta
.addr
, ETH_ALEN
);
399 sta_set_sinfo(sta
, sinfo
);
407 static int ieee80211_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
408 u8
*mac
, struct station_info
*sinfo
)
410 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
411 struct sta_info
*sta
;
416 /* XXX: verify sta->dev == dev */
418 sta
= sta_info_get(local
, mac
);
421 sta_set_sinfo(sta
, sinfo
);
430 * This handles both adding a beacon and setting new beacon info
432 static int ieee80211_config_beacon(struct ieee80211_sub_if_data
*sdata
,
433 struct beacon_parameters
*params
)
435 struct beacon_data
*new, *old
;
436 int new_head_len
, new_tail_len
;
440 old
= sdata
->u
.ap
.beacon
;
442 /* head must not be zero-length */
443 if (params
->head
&& !params
->head_len
)
447 * This is a kludge. beacon interval should really be part
448 * of the beacon information.
450 if (params
->interval
) {
451 sdata
->local
->hw
.conf
.beacon_int
= params
->interval
;
452 err
= ieee80211_hw_config(sdata
->local
,
453 IEEE80211_CONF_CHANGE_BEACON_INTERVAL
);
457 * We updated some parameter so if below bails out
463 /* Need to have a beacon head if we don't have one yet */
464 if (!params
->head
&& !old
)
467 /* sorry, no way to start beaconing without dtim period */
468 if (!params
->dtim_period
&& !old
)
471 /* new or old head? */
473 new_head_len
= params
->head_len
;
475 new_head_len
= old
->head_len
;
477 /* new or old tail? */
478 if (params
->tail
|| !old
)
479 /* params->tail_len will be zero for !params->tail */
480 new_tail_len
= params
->tail_len
;
482 new_tail_len
= old
->tail_len
;
484 size
= sizeof(*new) + new_head_len
+ new_tail_len
;
486 new = kzalloc(size
, GFP_KERNEL
);
490 /* start filling the new info now */
492 /* new or old dtim period? */
493 if (params
->dtim_period
)
494 new->dtim_period
= params
->dtim_period
;
496 new->dtim_period
= old
->dtim_period
;
499 * pointers go into the block we allocated,
500 * memory is | beacon_data | head | tail |
502 new->head
= ((u8
*) new) + sizeof(*new);
503 new->tail
= new->head
+ new_head_len
;
504 new->head_len
= new_head_len
;
505 new->tail_len
= new_tail_len
;
509 memcpy(new->head
, params
->head
, new_head_len
);
511 memcpy(new->head
, old
->head
, new_head_len
);
513 /* copy in optional tail */
515 memcpy(new->tail
, params
->tail
, new_tail_len
);
518 memcpy(new->tail
, old
->tail
, new_tail_len
);
520 rcu_assign_pointer(sdata
->u
.ap
.beacon
, new);
526 return ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON
|
527 IEEE80211_IFCC_BEACON_ENABLED
);
530 static int ieee80211_add_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 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
541 old
= sdata
->u
.ap
.beacon
;
546 return ieee80211_config_beacon(sdata
, params
);
549 static int ieee80211_set_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
550 struct beacon_parameters
*params
)
552 struct ieee80211_sub_if_data
*sdata
;
553 struct beacon_data
*old
;
555 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
557 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
560 old
= sdata
->u
.ap
.beacon
;
565 return ieee80211_config_beacon(sdata
, params
);
568 static int ieee80211_del_beacon(struct wiphy
*wiphy
, struct net_device
*dev
)
570 struct ieee80211_sub_if_data
*sdata
;
571 struct beacon_data
*old
;
573 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
575 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
578 old
= sdata
->u
.ap
.beacon
;
583 rcu_assign_pointer(sdata
->u
.ap
.beacon
, NULL
);
587 return ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON_ENABLED
);
590 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
591 struct iapp_layer2_update
{
592 u8 da
[ETH_ALEN
]; /* broadcast */
593 u8 sa
[ETH_ALEN
]; /* STA addr */
599 } __attribute__ ((packed
));
601 static void ieee80211_send_layer2_update(struct sta_info
*sta
)
603 struct iapp_layer2_update
*msg
;
606 /* Send Level 2 Update Frame to update forwarding tables in layer 2
609 skb
= dev_alloc_skb(sizeof(*msg
));
612 msg
= (struct iapp_layer2_update
*)skb_put(skb
, sizeof(*msg
));
614 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
615 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
617 memset(msg
->da
, 0xff, ETH_ALEN
);
618 memcpy(msg
->sa
, sta
->sta
.addr
, ETH_ALEN
);
621 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
622 msg
->control
= 0xaf; /* XID response lsb.1111F101.
623 * F=0 (no poll command; unsolicited frame) */
624 msg
->xid_info
[0] = 0x81; /* XID format identifier */
625 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
626 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
628 skb
->dev
= sta
->sdata
->dev
;
629 skb
->protocol
= eth_type_trans(skb
, sta
->sdata
->dev
);
630 memset(skb
->cb
, 0, sizeof(skb
->cb
));
634 static void sta_apply_parameters(struct ieee80211_local
*local
,
635 struct sta_info
*sta
,
636 struct station_parameters
*params
)
640 struct ieee80211_supported_band
*sband
;
641 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
643 sband
= local
->hw
.wiphy
->bands
[local
->oper_channel
->band
];
646 * FIXME: updating the flags is racy when this function is
647 * called from ieee80211_change_station(), this will
648 * be resolved in a future patch.
651 if (params
->station_flags
& STATION_FLAG_CHANGED
) {
652 spin_lock_bh(&sta
->lock
);
653 sta
->flags
&= ~WLAN_STA_AUTHORIZED
;
654 if (params
->station_flags
& STATION_FLAG_AUTHORIZED
)
655 sta
->flags
|= WLAN_STA_AUTHORIZED
;
657 sta
->flags
&= ~WLAN_STA_SHORT_PREAMBLE
;
658 if (params
->station_flags
& STATION_FLAG_SHORT_PREAMBLE
)
659 sta
->flags
|= WLAN_STA_SHORT_PREAMBLE
;
661 sta
->flags
&= ~WLAN_STA_WME
;
662 if (params
->station_flags
& STATION_FLAG_WME
)
663 sta
->flags
|= WLAN_STA_WME
;
665 sta
->flags
&= ~WLAN_STA_MFP
;
666 if (params
->station_flags
& STATION_FLAG_MFP
)
667 sta
->flags
|= WLAN_STA_MFP
;
668 spin_unlock_bh(&sta
->lock
);
672 * FIXME: updating the following information is racy when this
673 * function is called from ieee80211_change_station().
674 * However, all this information should be static so
675 * maybe we should just reject attemps to change it.
679 sta
->sta
.aid
= params
->aid
;
680 if (sta
->sta
.aid
> IEEE80211_MAX_AID
)
681 sta
->sta
.aid
= 0; /* XXX: should this be an error? */
684 if (params
->listen_interval
>= 0)
685 sta
->listen_interval
= params
->listen_interval
;
687 if (params
->supported_rates
) {
690 for (i
= 0; i
< params
->supported_rates_len
; i
++) {
691 int rate
= (params
->supported_rates
[i
] & 0x7f) * 5;
692 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
693 if (sband
->bitrates
[j
].bitrate
== rate
)
697 sta
->sta
.supp_rates
[local
->oper_channel
->band
] = rates
;
701 ieee80211_ht_cap_ie_to_sta_ht_cap(sband
,
705 if (ieee80211_vif_is_mesh(&sdata
->vif
) && params
->plink_action
) {
706 switch (params
->plink_action
) {
707 case PLINK_ACTION_OPEN
:
708 mesh_plink_open(sta
);
710 case PLINK_ACTION_BLOCK
:
711 mesh_plink_block(sta
);
717 static int ieee80211_add_station(struct wiphy
*wiphy
, struct net_device
*dev
,
718 u8
*mac
, struct station_parameters
*params
)
720 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
721 struct sta_info
*sta
;
722 struct ieee80211_sub_if_data
*sdata
;
726 /* Prevent a race with changing the rate control algorithm */
727 if (!netif_running(dev
))
731 sdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
733 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
734 sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
737 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
739 if (compare_ether_addr(mac
, dev
->dev_addr
) == 0)
742 if (is_multicast_ether_addr(mac
))
745 sta
= sta_info_alloc(sdata
, mac
, GFP_KERNEL
);
749 sta
->flags
= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
751 sta_apply_parameters(local
, sta
, params
);
753 rate_control_rate_init(sta
);
755 layer2_update
= sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
||
756 sdata
->vif
.type
== NL80211_IFTYPE_AP
;
760 err
= sta_info_insert(sta
);
762 /* STA has been freed */
763 if (err
== -EEXIST
&& layer2_update
) {
764 /* Need to update layer 2 devices on reassociation */
765 sta
= sta_info_get(local
, mac
);
767 ieee80211_send_layer2_update(sta
);
774 ieee80211_send_layer2_update(sta
);
781 static int ieee80211_del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
784 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
785 struct ieee80211_sub_if_data
*sdata
;
786 struct sta_info
*sta
;
788 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
793 /* XXX: get sta belonging to dev */
794 sta
= sta_info_get(local
, mac
);
800 sta_info_unlink(&sta
);
803 sta_info_destroy(sta
);
805 sta_info_flush(local
, sdata
);
810 static int ieee80211_change_station(struct wiphy
*wiphy
,
811 struct net_device
*dev
,
813 struct station_parameters
*params
)
815 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
816 struct sta_info
*sta
;
817 struct ieee80211_sub_if_data
*vlansdata
;
821 /* XXX: get sta belonging to dev */
822 sta
= sta_info_get(local
, mac
);
828 if (params
->vlan
&& params
->vlan
!= sta
->sdata
->dev
) {
829 vlansdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
831 if (vlansdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
832 vlansdata
->vif
.type
!= NL80211_IFTYPE_AP
) {
837 sta
->sdata
= vlansdata
;
838 ieee80211_send_layer2_update(sta
);
841 sta_apply_parameters(local
, sta
, params
);
848 #ifdef CONFIG_MAC80211_MESH
849 static int ieee80211_add_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
850 u8
*dst
, u8
*next_hop
)
852 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
853 struct ieee80211_sub_if_data
*sdata
;
854 struct mesh_path
*mpath
;
855 struct sta_info
*sta
;
858 if (!netif_running(dev
))
861 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
863 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
867 sta
= sta_info_get(local
, next_hop
);
873 err
= mesh_path_add(dst
, sdata
);
879 mpath
= mesh_path_lookup(dst
, sdata
);
884 mesh_path_fix_nexthop(mpath
, sta
);
890 static int ieee80211_del_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
893 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
896 return mesh_path_del(dst
, sdata
);
898 mesh_path_flush(sdata
);
902 static int ieee80211_change_mpath(struct wiphy
*wiphy
,
903 struct net_device
*dev
,
904 u8
*dst
, u8
*next_hop
)
906 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
907 struct ieee80211_sub_if_data
*sdata
;
908 struct mesh_path
*mpath
;
909 struct sta_info
*sta
;
911 if (!netif_running(dev
))
914 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
916 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
921 sta
= sta_info_get(local
, next_hop
);
927 mpath
= mesh_path_lookup(dst
, sdata
);
933 mesh_path_fix_nexthop(mpath
, sta
);
939 static void mpath_set_pinfo(struct mesh_path
*mpath
, u8
*next_hop
,
940 struct mpath_info
*pinfo
)
943 memcpy(next_hop
, mpath
->next_hop
->sta
.addr
, ETH_ALEN
);
945 memset(next_hop
, 0, ETH_ALEN
);
947 pinfo
->filled
= MPATH_INFO_FRAME_QLEN
|
951 MPATH_INFO_DISCOVERY_TIMEOUT
|
952 MPATH_INFO_DISCOVERY_RETRIES
|
955 pinfo
->frame_qlen
= mpath
->frame_queue
.qlen
;
956 pinfo
->dsn
= mpath
->dsn
;
957 pinfo
->metric
= mpath
->metric
;
958 if (time_before(jiffies
, mpath
->exp_time
))
959 pinfo
->exptime
= jiffies_to_msecs(mpath
->exp_time
- jiffies
);
960 pinfo
->discovery_timeout
=
961 jiffies_to_msecs(mpath
->discovery_timeout
);
962 pinfo
->discovery_retries
= mpath
->discovery_retries
;
964 if (mpath
->flags
& MESH_PATH_ACTIVE
)
965 pinfo
->flags
|= NL80211_MPATH_FLAG_ACTIVE
;
966 if (mpath
->flags
& MESH_PATH_RESOLVING
)
967 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVING
;
968 if (mpath
->flags
& MESH_PATH_DSN_VALID
)
969 pinfo
->flags
|= NL80211_MPATH_FLAG_DSN_VALID
;
970 if (mpath
->flags
& MESH_PATH_FIXED
)
971 pinfo
->flags
|= NL80211_MPATH_FLAG_FIXED
;
972 if (mpath
->flags
& MESH_PATH_RESOLVING
)
973 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVING
;
975 pinfo
->flags
= mpath
->flags
;
978 static int ieee80211_get_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
979 u8
*dst
, u8
*next_hop
, struct mpath_info
*pinfo
)
982 struct ieee80211_sub_if_data
*sdata
;
983 struct mesh_path
*mpath
;
985 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
987 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
991 mpath
= mesh_path_lookup(dst
, sdata
);
996 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
997 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1002 static int ieee80211_dump_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1003 int idx
, u8
*dst
, u8
*next_hop
,
1004 struct mpath_info
*pinfo
)
1006 struct ieee80211_sub_if_data
*sdata
;
1007 struct mesh_path
*mpath
;
1009 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1011 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
1015 mpath
= mesh_path_lookup_by_idx(idx
, sdata
);
1020 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1021 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1026 static int ieee80211_get_mesh_params(struct wiphy
*wiphy
,
1027 struct net_device
*dev
,
1028 struct mesh_config
*conf
)
1030 struct ieee80211_sub_if_data
*sdata
;
1031 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1033 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
1035 memcpy(conf
, &(sdata
->u
.mesh
.mshcfg
), sizeof(struct mesh_config
));
1039 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm
, u32 mask
)
1041 return (mask
>> (parm
-1)) & 0x1;
1044 static int ieee80211_set_mesh_params(struct wiphy
*wiphy
,
1045 struct net_device
*dev
,
1046 const struct mesh_config
*nconf
, u32 mask
)
1048 struct mesh_config
*conf
;
1049 struct ieee80211_sub_if_data
*sdata
;
1050 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1052 if (sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
1055 /* Set the config options which we are interested in setting */
1056 conf
= &(sdata
->u
.mesh
.mshcfg
);
1057 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT
, mask
))
1058 conf
->dot11MeshRetryTimeout
= nconf
->dot11MeshRetryTimeout
;
1059 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT
, mask
))
1060 conf
->dot11MeshConfirmTimeout
= nconf
->dot11MeshConfirmTimeout
;
1061 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT
, mask
))
1062 conf
->dot11MeshHoldingTimeout
= nconf
->dot11MeshHoldingTimeout
;
1063 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS
, mask
))
1064 conf
->dot11MeshMaxPeerLinks
= nconf
->dot11MeshMaxPeerLinks
;
1065 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES
, mask
))
1066 conf
->dot11MeshMaxRetries
= nconf
->dot11MeshMaxRetries
;
1067 if (_chg_mesh_attr(NL80211_MESHCONF_TTL
, mask
))
1068 conf
->dot11MeshTTL
= nconf
->dot11MeshTTL
;
1069 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS
, mask
))
1070 conf
->auto_open_plinks
= nconf
->auto_open_plinks
;
1071 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
, mask
))
1072 conf
->dot11MeshHWMPmaxPREQretries
=
1073 nconf
->dot11MeshHWMPmaxPREQretries
;
1074 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME
, mask
))
1075 conf
->path_refresh_time
= nconf
->path_refresh_time
;
1076 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
, mask
))
1077 conf
->min_discovery_timeout
= nconf
->min_discovery_timeout
;
1078 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
, mask
))
1079 conf
->dot11MeshHWMPactivePathTimeout
=
1080 nconf
->dot11MeshHWMPactivePathTimeout
;
1081 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
, mask
))
1082 conf
->dot11MeshHWMPpreqMinInterval
=
1083 nconf
->dot11MeshHWMPpreqMinInterval
;
1084 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
1086 conf
->dot11MeshHWMPnetDiameterTraversalTime
=
1087 nconf
->dot11MeshHWMPnetDiameterTraversalTime
;
1093 static int ieee80211_change_bss(struct wiphy
*wiphy
,
1094 struct net_device
*dev
,
1095 struct bss_parameters
*params
)
1097 struct ieee80211_sub_if_data
*sdata
;
1100 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1102 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
1105 if (params
->use_cts_prot
>= 0) {
1106 sdata
->vif
.bss_conf
.use_cts_prot
= params
->use_cts_prot
;
1107 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
1109 if (params
->use_short_preamble
>= 0) {
1110 sdata
->vif
.bss_conf
.use_short_preamble
=
1111 params
->use_short_preamble
;
1112 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
1114 if (params
->use_short_slot_time
>= 0) {
1115 sdata
->vif
.bss_conf
.use_short_slot
=
1116 params
->use_short_slot_time
;
1117 changed
|= BSS_CHANGED_ERP_SLOT
;
1120 if (params
->basic_rates
) {
1123 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1124 struct ieee80211_supported_band
*sband
=
1125 wiphy
->bands
[local
->oper_channel
->band
];
1127 for (i
= 0; i
< params
->basic_rates_len
; i
++) {
1128 int rate
= (params
->basic_rates
[i
] & 0x7f) * 5;
1129 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1130 if (sband
->bitrates
[j
].bitrate
== rate
)
1134 sdata
->vif
.bss_conf
.basic_rates
= rates
;
1135 changed
|= BSS_CHANGED_BASIC_RATES
;
1138 ieee80211_bss_info_change_notify(sdata
, changed
);
1143 static int ieee80211_set_txq_params(struct wiphy
*wiphy
,
1144 struct ieee80211_txq_params
*params
)
1146 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1147 struct ieee80211_tx_queue_params p
;
1149 if (!local
->ops
->conf_tx
)
1152 memset(&p
, 0, sizeof(p
));
1153 p
.aifs
= params
->aifs
;
1154 p
.cw_max
= params
->cwmax
;
1155 p
.cw_min
= params
->cwmin
;
1156 p
.txop
= params
->txop
;
1157 if (local
->ops
->conf_tx(local_to_hw(local
), params
->queue
, &p
)) {
1158 printk(KERN_DEBUG
"%s: failed to set TX queue "
1159 "parameters for queue %d\n", local
->mdev
->name
,
1167 static int ieee80211_set_channel(struct wiphy
*wiphy
,
1168 struct ieee80211_channel
*chan
,
1169 enum nl80211_channel_type channel_type
)
1171 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1173 local
->oper_channel
= chan
;
1174 local
->oper_channel_type
= channel_type
;
1176 return ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
1179 static int set_mgmt_extra_ie_sta(struct ieee80211_sub_if_data
*sdata
,
1180 u8 subtype
, u8
*ies
, size_t ies_len
)
1182 struct ieee80211_local
*local
= sdata
->local
;
1183 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1186 case IEEE80211_STYPE_PROBE_REQ
>> 4:
1187 if (local
->ops
->hw_scan
)
1189 kfree(ifmgd
->ie_probereq
);
1190 ifmgd
->ie_probereq
= ies
;
1191 ifmgd
->ie_probereq_len
= ies_len
;
1193 case IEEE80211_STYPE_PROBE_RESP
>> 4:
1194 kfree(ifmgd
->ie_proberesp
);
1195 ifmgd
->ie_proberesp
= ies
;
1196 ifmgd
->ie_proberesp_len
= ies_len
;
1198 case IEEE80211_STYPE_AUTH
>> 4:
1199 kfree(ifmgd
->ie_auth
);
1200 ifmgd
->ie_auth
= ies
;
1201 ifmgd
->ie_auth_len
= ies_len
;
1203 case IEEE80211_STYPE_ASSOC_REQ
>> 4:
1204 kfree(ifmgd
->ie_assocreq
);
1205 ifmgd
->ie_assocreq
= ies
;
1206 ifmgd
->ie_assocreq_len
= ies_len
;
1208 case IEEE80211_STYPE_REASSOC_REQ
>> 4:
1209 kfree(ifmgd
->ie_reassocreq
);
1210 ifmgd
->ie_reassocreq
= ies
;
1211 ifmgd
->ie_reassocreq_len
= ies_len
;
1213 case IEEE80211_STYPE_DEAUTH
>> 4:
1214 kfree(ifmgd
->ie_deauth
);
1215 ifmgd
->ie_deauth
= ies
;
1216 ifmgd
->ie_deauth_len
= ies_len
;
1218 case IEEE80211_STYPE_DISASSOC
>> 4:
1219 kfree(ifmgd
->ie_disassoc
);
1220 ifmgd
->ie_disassoc
= ies
;
1221 ifmgd
->ie_disassoc_len
= ies_len
;
1228 static int ieee80211_set_mgmt_extra_ie(struct wiphy
*wiphy
,
1229 struct net_device
*dev
,
1230 struct mgmt_extra_ie_params
*params
)
1232 struct ieee80211_sub_if_data
*sdata
;
1235 int ret
= -EOPNOTSUPP
;
1238 ies
= kmemdup(params
->ies
, params
->ies_len
, GFP_KERNEL
);
1241 ies_len
= params
->ies_len
;
1247 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1249 switch (sdata
->vif
.type
) {
1250 case NL80211_IFTYPE_STATION
:
1251 ret
= set_mgmt_extra_ie_sta(sdata
, params
->subtype
,
1265 static int ieee80211_suspend(struct wiphy
*wiphy
)
1267 return __ieee80211_suspend(wiphy_priv(wiphy
));
1270 static int ieee80211_resume(struct wiphy
*wiphy
)
1272 return __ieee80211_resume(wiphy_priv(wiphy
));
1275 #define ieee80211_suspend NULL
1276 #define ieee80211_resume NULL
1279 static int ieee80211_scan(struct wiphy
*wiphy
,
1280 struct net_device
*dev
,
1281 struct cfg80211_scan_request
*req
)
1283 struct ieee80211_sub_if_data
*sdata
;
1285 if (!netif_running(dev
))
1288 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1290 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
1291 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
1292 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
1295 return ieee80211_request_scan(sdata
, req
);
1298 struct cfg80211_ops mac80211_config_ops
= {
1299 .add_virtual_intf
= ieee80211_add_iface
,
1300 .del_virtual_intf
= ieee80211_del_iface
,
1301 .change_virtual_intf
= ieee80211_change_iface
,
1302 .add_key
= ieee80211_add_key
,
1303 .del_key
= ieee80211_del_key
,
1304 .get_key
= ieee80211_get_key
,
1305 .set_default_key
= ieee80211_config_default_key
,
1306 .set_default_mgmt_key
= ieee80211_config_default_mgmt_key
,
1307 .add_beacon
= ieee80211_add_beacon
,
1308 .set_beacon
= ieee80211_set_beacon
,
1309 .del_beacon
= ieee80211_del_beacon
,
1310 .add_station
= ieee80211_add_station
,
1311 .del_station
= ieee80211_del_station
,
1312 .change_station
= ieee80211_change_station
,
1313 .get_station
= ieee80211_get_station
,
1314 .dump_station
= ieee80211_dump_station
,
1315 #ifdef CONFIG_MAC80211_MESH
1316 .add_mpath
= ieee80211_add_mpath
,
1317 .del_mpath
= ieee80211_del_mpath
,
1318 .change_mpath
= ieee80211_change_mpath
,
1319 .get_mpath
= ieee80211_get_mpath
,
1320 .dump_mpath
= ieee80211_dump_mpath
,
1321 .set_mesh_params
= ieee80211_set_mesh_params
,
1322 .get_mesh_params
= ieee80211_get_mesh_params
,
1324 .change_bss
= ieee80211_change_bss
,
1325 .set_txq_params
= ieee80211_set_txq_params
,
1326 .set_channel
= ieee80211_set_channel
,
1327 .set_mgmt_extra_ie
= ieee80211_set_mgmt_extra_ie
,
1328 .suspend
= ieee80211_suspend
,
1329 .resume
= ieee80211_resume
,
1330 .scan
= ieee80211_scan
,