net: clear heap allocations for privileged ethtool actions
[firefly-linux-kernel-4.4.55.git] / net / mac80211 / wme.c
1 /*
2  * Copyright 2004, Instant802 Networks, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #include <linux/netdevice.h>
10 #include <linux/skbuff.h>
11 #include <linux/module.h>
12 #include <linux/if_arp.h>
13 #include <linux/types.h>
14 #include <net/ip.h>
15 #include <net/pkt_sched.h>
16
17 #include <net/mac80211.h>
18 #include "ieee80211_i.h"
19 #include "wme.h"
20
21 /* Default mapping in classifier to work with default
22  * queue setup.
23  */
24 const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
25
26 static int wme_downgrade_ac(struct sk_buff *skb)
27 {
28         switch (skb->priority) {
29         case 6:
30         case 7:
31                 skb->priority = 5; /* VO -> VI */
32                 return 0;
33         case 4:
34         case 5:
35                 skb->priority = 3; /* VI -> BE */
36                 return 0;
37         case 0:
38         case 3:
39                 skb->priority = 2; /* BE -> BK */
40                 return 0;
41         default:
42                 return -1;
43         }
44 }
45
46
47 /* Indicate which queue to use. */
48 u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
49                            struct sk_buff *skb)
50 {
51         struct ieee80211_local *local = sdata->local;
52         struct sta_info *sta = NULL;
53         u32 sta_flags = 0;
54         const u8 *ra = NULL;
55         bool qos = false;
56
57         if (local->hw.queues < 4 || skb->len < 6) {
58                 skb->priority = 0; /* required for correct WPA/11i MIC */
59                 return min_t(u16, local->hw.queues - 1,
60                              ieee802_1d_to_ac[skb->priority]);
61         }
62
63         rcu_read_lock();
64         switch (sdata->vif.type) {
65         case NL80211_IFTYPE_AP_VLAN:
66         case NL80211_IFTYPE_AP:
67                 ra = skb->data;
68                 break;
69         case NL80211_IFTYPE_WDS:
70                 ra = sdata->u.wds.remote_addr;
71                 break;
72 #ifdef CONFIG_MAC80211_MESH
73         case NL80211_IFTYPE_MESH_POINT:
74                 /*
75                  * XXX: This is clearly broken ... but already was before,
76                  * because ieee80211_fill_mesh_addresses() would clear A1
77                  * except for multicast addresses.
78                  */
79                 break;
80 #endif
81         case NL80211_IFTYPE_STATION:
82                 ra = sdata->u.mgd.bssid;
83                 break;
84         case NL80211_IFTYPE_ADHOC:
85                 ra = skb->data;
86                 break;
87         default:
88                 break;
89         }
90
91         if (!sta && ra && !is_multicast_ether_addr(ra)) {
92                 sta = sta_info_get(local, ra);
93                 if (sta)
94                         sta_flags = get_sta_flags(sta);
95         }
96
97         if (sta_flags & WLAN_STA_WME)
98                 qos = true;
99
100         rcu_read_unlock();
101
102         if (!qos) {
103                 skb->priority = 0; /* required for correct WPA/11i MIC */
104                 return ieee802_1d_to_ac[skb->priority];
105         }
106
107         /* use the data classifier to determine what 802.1d tag the
108          * data frame has */
109         skb->priority = cfg80211_classify8021d(skb);
110
111         return ieee80211_downgrade_queue(local, skb);
112 }
113
114 u16 ieee80211_downgrade_queue(struct ieee80211_local *local,
115                               struct sk_buff *skb)
116 {
117         /* in case we are a client verify acm is not set for this ac */
118         while (unlikely(local->wmm_acm & BIT(skb->priority))) {
119                 if (wme_downgrade_ac(skb)) {
120                         /*
121                          * This should not really happen. The AP has marked all
122                          * lower ACs to require admission control which is not
123                          * a reasonable configuration. Allow the frame to be
124                          * transmitted using AC_BK as a workaround.
125                          */
126                         break;
127                 }
128         }
129
130         /* look up which queue to use for frames with this 1d tag */
131         return ieee802_1d_to_ac[skb->priority];
132 }
133
134 void ieee80211_set_qos_hdr(struct ieee80211_local *local, struct sk_buff *skb)
135 {
136         struct ieee80211_hdr *hdr = (void *)skb->data;
137
138         /* Fill in the QoS header if there is one. */
139         if (ieee80211_is_data_qos(hdr->frame_control)) {
140                 u8 *p = ieee80211_get_qos_ctl(hdr);
141                 u8 ack_policy = 0, tid;
142
143                 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
144
145                 if (unlikely(local->wifi_wme_noack_test))
146                         ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
147                                         QOS_CONTROL_ACK_POLICY_SHIFT;
148                 /* qos header is 2 bytes, second reserved */
149                 *p++ = ack_policy | tid;
150                 *p = 0;
151         }
152 }