Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 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 | |
David S. Miller | 51cb6db | 2008-07-15 03:34:57 -0700 | [diff] [blame] | 21 | /* Default mapping in classifier to work with default |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 22 | * queue setup. |
| 23 | */ |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 24 | const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 }; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 25 | |
David S. Miller | 51cb6db | 2008-07-15 03:34:57 -0700 | [diff] [blame] | 26 | static int wme_downgrade_ac(struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 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 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 47 | /* Indicate which queue to use. */ |
| 48 | u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata, |
| 49 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 50 | { |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 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; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 56 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 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]); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 63 | rcu_read_lock(); |
| 64 | switch (sdata->vif.type) { |
| 65 | case NL80211_IFTYPE_AP_VLAN: |
| 66 | rcu_read_lock(); |
| 67 | sta = rcu_dereference(sdata->u.vlan.sta); |
| 68 | if (sta) |
| 69 | sta_flags = get_sta_flags(sta); |
| 70 | rcu_read_unlock(); |
| 71 | if (sta) |
| 72 | break; |
| 73 | case NL80211_IFTYPE_AP: |
| 74 | ra = skb->data; |
| 75 | break; |
| 76 | case NL80211_IFTYPE_WDS: |
| 77 | ra = sdata->u.wds.remote_addr; |
| 78 | break; |
| 79 | #ifdef CONFIG_MAC80211_MESH |
| 80 | case NL80211_IFTYPE_MESH_POINT: |
| 81 | /* |
| 82 | * XXX: This is clearly broken ... but already was before, |
| 83 | * because ieee80211_fill_mesh_addresses() would clear A1 |
| 84 | * except for multicast addresses. |
| 85 | */ |
| 86 | break; |
| 87 | #endif |
| 88 | case NL80211_IFTYPE_STATION: |
| 89 | ra = sdata->u.mgd.bssid; |
| 90 | break; |
| 91 | case NL80211_IFTYPE_ADHOC: |
| 92 | ra = skb->data; |
| 93 | break; |
| 94 | default: |
| 95 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 98 | if (!sta && ra && !is_multicast_ether_addr(ra)) { |
| 99 | sta = sta_info_get(sdata, ra); |
| 100 | if (sta) |
| 101 | sta_flags = get_sta_flags(sta); |
| 102 | } |
| 103 | |
| 104 | if (sta_flags & WLAN_STA_WME) |
| 105 | qos = true; |
| 106 | |
| 107 | rcu_read_unlock(); |
| 108 | |
| 109 | if (!qos) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 110 | skb->priority = 0; /* required for correct WPA/11i MIC */ |
| 111 | return ieee802_1d_to_ac[skb->priority]; |
| 112 | } |
| 113 | |
| 114 | /* use the data classifier to determine what 802.1d tag the |
Johannes Berg | 3c3b00c | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 115 | * data frame has */ |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 116 | skb->priority = cfg80211_classify8021d(skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 117 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 118 | return ieee80211_downgrade_queue(local, skb); |
| 119 | } |
| 120 | |
| 121 | u16 ieee80211_downgrade_queue(struct ieee80211_local *local, |
| 122 | struct sk_buff *skb) |
| 123 | { |
Johannes Berg | 3c3b00c | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 124 | /* in case we are a client verify acm is not set for this ac */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 125 | while (unlikely(local->wmm_acm & BIT(skb->priority))) { |
| 126 | if (wme_downgrade_ac(skb)) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 127 | /* |
| 128 | * This should not really happen. The AP has marked all |
| 129 | * lower ACs to require admission control which is not |
| 130 | * a reasonable configuration. Allow the frame to be |
| 131 | * transmitted using AC_BK as a workaround. |
David S. Miller | 51cb6db | 2008-07-15 03:34:57 -0700 | [diff] [blame] | 132 | */ |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 133 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | /* look up which queue to use for frames with this 1d tag */ |
| 138 | return ieee802_1d_to_ac[skb->priority]; |
| 139 | } |
| 140 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 141 | void ieee80211_set_qos_hdr(struct ieee80211_local *local, struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 142 | { |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 143 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 144 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 145 | /* Fill in the QoS header if there is one. */ |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 146 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
Harvey Harrison | 002aaf4 | 2008-06-11 14:21:59 -0700 | [diff] [blame] | 147 | u8 *p = ieee80211_get_qos_ctl(hdr); |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 148 | u8 ack_policy = 0, tid; |
| 149 | |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 150 | tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 151 | |
Johannes Berg | d3707d9 | 2009-05-12 22:05:40 +0200 | [diff] [blame] | 152 | if (unlikely(local->wifi_wme_noack_test)) |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 153 | ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK << |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 154 | QOS_CONTROL_ACK_POLICY_SHIFT; |
| 155 | /* qos header is 2 bytes, second reserved */ |
Harvey Harrison | 002aaf4 | 2008-06-11 14:21:59 -0700 | [diff] [blame] | 156 | *p++ = ack_policy | tid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 157 | *p = 0; |
| 158 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 159 | } |