2 * Copyright 2004, Instant802 Networks, Inc.
3 * Copyright 2013-2014 Intel Mobile Communications GmbH
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/netdevice.h>
11 #include <linux/skbuff.h>
12 #include <linux/module.h>
13 #include <linux/if_arp.h>
14 #include <linux/types.h>
16 #include <net/pkt_sched.h>
18 #include <net/mac80211.h>
19 #include "ieee80211_i.h"
22 /* Default mapping in classifier to work with default
25 const int ieee802_1d_to_ac
[8] = {
36 static int wme_downgrade_ac(struct sk_buff
*skb
)
38 switch (skb
->priority
) {
41 skb
->priority
= 5; /* VO -> VI */
45 skb
->priority
= 3; /* VI -> BE */
49 skb
->priority
= 2; /* BE -> BK */
56 static u16
ieee80211_downgrade_queue(struct ieee80211_sub_if_data
*sdata
,
57 struct sta_info
*sta
, struct sk_buff
*skb
)
59 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
61 /* in case we are a client verify acm is not set for this ac */
62 while (sdata
->wmm_acm
& BIT(skb
->priority
)) {
63 int ac
= ieee802_1d_to_ac
[skb
->priority
];
65 if (ifmgd
->tx_tspec
[ac
].admitted_time
&&
66 skb
->priority
== ifmgd
->tx_tspec
[ac
].up
)
69 if (wme_downgrade_ac(skb
)) {
71 * This should not really happen. The AP has marked all
72 * lower ACs to require admission control which is not
73 * a reasonable configuration. Allow the frame to be
74 * transmitted using AC_BK as a workaround.
80 /* look up which queue to use for frames with this 1d tag */
81 return ieee802_1d_to_ac
[skb
->priority
];
84 /* Indicate which queue to use for this fully formed 802.11 frame */
85 u16
ieee80211_select_queue_80211(struct ieee80211_sub_if_data
*sdata
,
87 struct ieee80211_hdr
*hdr
)
89 struct ieee80211_local
*local
= sdata
->local
;
92 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
95 if (!ieee80211_is_data(hdr
->frame_control
)) {
97 return ieee802_1d_to_ac
[skb
->priority
];
99 if (!ieee80211_is_data_qos(hdr
->frame_control
)) {
101 return ieee802_1d_to_ac
[skb
->priority
];
104 p
= ieee80211_get_qos_ctl(hdr
);
105 skb
->priority
= *p
& IEEE80211_QOS_CTL_TAG1D_MASK
;
107 return ieee80211_downgrade_queue(sdata
, NULL
, skb
);
110 /* Indicate which queue to use. */
111 u16
ieee80211_select_queue(struct ieee80211_sub_if_data
*sdata
,
114 struct ieee80211_local
*local
= sdata
->local
;
115 struct sta_info
*sta
= NULL
;
118 struct mac80211_qos_map
*qos_map
;
121 if (local
->hw
.queues
< IEEE80211_NUM_ACS
|| skb
->len
< 6) {
122 skb
->priority
= 0; /* required for correct WPA/11i MIC */
127 switch (sdata
->vif
.type
) {
128 case NL80211_IFTYPE_AP_VLAN
:
129 sta
= rcu_dereference(sdata
->u
.vlan
.sta
);
134 case NL80211_IFTYPE_AP
:
137 case NL80211_IFTYPE_WDS
:
138 ra
= sdata
->u
.wds
.remote_addr
;
140 #ifdef CONFIG_MAC80211_MESH
141 case NL80211_IFTYPE_MESH_POINT
:
145 case NL80211_IFTYPE_STATION
:
146 ra
= sdata
->u
.mgd
.bssid
;
148 case NL80211_IFTYPE_ADHOC
:
151 case NL80211_IFTYPE_OCB
:
152 /* all stations are required to support WME */
159 if (!sta
&& ra
&& !is_multicast_ether_addr(ra
)) {
160 sta
= sta_info_get(sdata
, ra
);
166 skb
->priority
= 0; /* required for correct WPA/11i MIC */
167 ret
= IEEE80211_AC_BE
;
171 if (skb
->protocol
== sdata
->control_port_protocol
) {
176 /* use the data classifier to determine what 802.1d tag the
178 qos_map
= rcu_dereference(sdata
->qos_map
);
179 skb
->priority
= cfg80211_classify8021d(skb
, qos_map
?
180 &qos_map
->qos_map
: NULL
);
183 ret
= ieee80211_downgrade_queue(sdata
, sta
, skb
);
190 * ieee80211_set_qos_hdr - Fill in the QoS header if there is one.
192 * @sdata: local subif
193 * @skb: packet to be updated
195 void ieee80211_set_qos_hdr(struct ieee80211_sub_if_data
*sdata
,
198 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
199 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
203 if (!ieee80211_is_data_qos(hdr
->frame_control
))
206 p
= ieee80211_get_qos_ctl(hdr
);
207 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
209 /* preserve EOSP bit */
210 ack_policy
= *p
& IEEE80211_QOS_CTL_EOSP
;
212 if (is_multicast_ether_addr(hdr
->addr1
) ||
213 sdata
->noack_map
& BIT(tid
)) {
214 ack_policy
|= IEEE80211_QOS_CTL_ACK_POLICY_NOACK
;
215 info
->flags
|= IEEE80211_TX_CTL_NO_ACK
;
218 /* qos header is 2 bytes */
219 *p
++ = ack_policy
| tid
;
220 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
221 /* preserve RSPI and Mesh PS Level bit */
222 *p
&= ((IEEE80211_QOS_CTL_RSPI
|
223 IEEE80211_QOS_CTL_MESH_PS_LEVEL
) >> 8);
225 /* Nulls don't have a mesh header (frame body) */
226 if (!ieee80211_is_qos_nullfunc(hdr
->frame_control
))
227 *p
|= (IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT
>> 8);