wme.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2004, Instant802 Networks, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 2 as
00006  * published by the Free Software Foundation.
00007  */
00008 
00009 #include <linux/netdevice.h>
00010 #include <linux/skbuff.h>
00011 #include <linux/module.h>
00012 #include <linux/if_arp.h>
00013 #include <linux/types.h>
00014 #include <net/ip.h>
00015 #include <net/pkt_sched.h>
00016 
00017 #include <net/mac80211.h>
00018 #include "ieee80211_i.h"
00019 #include "wme.h"
00020 
00021 /* Default mapping in classifier to work with default
00022  * queue setup.
00023  */
00024 const int ieee802_1d_to_ac[8] = {
00025         IEEE80211_AC_BE,
00026         IEEE80211_AC_BK,
00027         IEEE80211_AC_BK,
00028         IEEE80211_AC_BE,
00029         IEEE80211_AC_VI,
00030         IEEE80211_AC_VI,
00031         IEEE80211_AC_VO,
00032         IEEE80211_AC_VO
00033 };
00034 
00035 static int wme_downgrade_ac(struct sk_buff *skb)
00036 {
00037         switch (skb->priority) {
00038         case 6:
00039         case 7:
00040                 skb->priority = 5; /* VO -> VI */
00041                 return 0;
00042         case 4:
00043         case 5:
00044                 skb->priority = 3; /* VI -> BE */
00045                 return 0;
00046         case 0:
00047         case 3:
00048                 skb->priority = 2; /* BE -> BK */
00049                 return 0;
00050         default:
00051                 return -1;
00052         }
00053 }
00054 
00055 static u16 ieee80211_downgrade_queue(struct ieee80211_local *local,
00056                                      struct sk_buff *skb)
00057 {
00058         /* in case we are a client verify acm is not set for this ac */
00059         while (unlikely(local->wmm_acm & BIT(skb->priority))) {
00060                 if (wme_downgrade_ac(skb)) {
00061                         /*
00062                          * This should not really happen. The AP has marked all
00063                          * lower ACs to require admission control which is not
00064                          * a reasonable configuration. Allow the frame to be
00065                          * transmitted using AC_BK as a workaround.
00066                          */
00067                         break;
00068                 }
00069         }
00070 
00071         /* look up which queue to use for frames with this 1d tag */
00072         return ieee802_1d_to_ac[skb->priority];
00073 }
00074 
00075 /* Indicate which queue to use for this fully formed 802.11 frame */
00076 u16 ieee80211_select_queue_80211(struct ieee80211_local *local,
00077                                  struct sk_buff *skb,
00078                                  struct ieee80211_hdr *hdr)
00079 {
00080         u8 *p;
00081 
00082         if (local->hw.queues < IEEE80211_NUM_ACS)
00083                 return 0;
00084 
00085         if (!ieee80211_is_data(hdr->frame_control)) {
00086                 skb->priority = 7;
00087                 return ieee802_1d_to_ac[skb->priority];
00088         }
00089         if (!ieee80211_is_data_qos(hdr->frame_control)) {
00090                 skb->priority = 0;
00091                 return ieee802_1d_to_ac[skb->priority];
00092         }
00093 
00094         p = ieee80211_get_qos_ctl(hdr);
00095         skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
00096 
00097         return ieee80211_downgrade_queue(local, skb);
00098 }
00099 
00100 /* Indicate which queue to use. */
00101 u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
00102                            struct sk_buff *skb)
00103 {
00104         struct ieee80211_local *local = sdata->local;
00105         struct sta_info *sta = NULL;
00106         const u8 *ra = NULL;
00107         bool qos = false;
00108 
00109         if (local->hw.queues < IEEE80211_NUM_ACS || skb->len < 6) {
00110                 skb->priority = 0; /* required for correct WPA/11i MIC */
00111                 return 0;
00112         }
00113 
00114         rcu_read_lock();
00115         switch (sdata->vif.type) {
00116         case NL80211_IFTYPE_AP_VLAN:
00117                 sta = rcu_dereference(sdata->u.vlan.sta);
00118                 if (sta) {
00119                         qos = test_sta_flag(sta, WLAN_STA_WME);
00120                         break;
00121                 }
00122         case NL80211_IFTYPE_AP:
00123                 ra = skb->data;
00124                 break;
00125         case NL80211_IFTYPE_WDS:
00126                 ra = sdata->u.wds.remote_addr;
00127                 break;
00128 #ifdef CONFIG_MAC80211_MESH
00129         case NL80211_IFTYPE_MESH_POINT:
00130                 qos = true;
00131                 break;
00132 #endif
00133         case NL80211_IFTYPE_STATION:
00134                 ra = sdata->u.mgd.bssid;
00135                 break;
00136         case NL80211_IFTYPE_ADHOC:
00137                 ra = skb->data;
00138                 break;
00139         default:
00140                 break;
00141         }
00142 
00143         if (!sta && ra && !is_multicast_ether_addr(ra)) {
00144                 sta = sta_info_get(sdata, ra);
00145                 if (sta)
00146                         qos = test_sta_flag(sta, WLAN_STA_WME);
00147         }
00148         rcu_read_unlock();
00149 
00150         if (!qos) {
00151                 skb->priority = 0; /* required for correct WPA/11i MIC */
00152                 return IEEE80211_AC_BE;
00153         }
00154 
00155         /* use the data classifier to determine what 802.1d tag the
00156          * data frame has */
00157         skb->priority = cfg80211_classify8021d(skb);
00158 
00159         return ieee80211_downgrade_queue(local, skb);
00160 }
00161 
00162 void ieee80211_set_qos_hdr(struct ieee80211_sub_if_data *sdata,
00163                            struct sk_buff *skb)
00164 {
00165         struct ieee80211_hdr *hdr = (void *)skb->data;
00166         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
00167 
00168         /* Fill in the QoS header if there is one. */
00169         if (ieee80211_is_data_qos(hdr->frame_control)) {
00170                 u8 *p = ieee80211_get_qos_ctl(hdr);
00171                 u8 ack_policy, tid;
00172 
00173                 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
00174 
00175                 /* preserve EOSP bit */
00176                 ack_policy = *p & IEEE80211_QOS_CTL_EOSP;
00177 
00178                 if (is_multicast_ether_addr(hdr->addr1) ||
00179                     sdata->noack_map & BIT(tid)) {
00180                         ack_policy |= IEEE80211_QOS_CTL_ACK_POLICY_NOACK;
00181                         info->flags |= IEEE80211_TX_CTL_NO_ACK;
00182                 }
00183 
00184                 /* qos header is 2 bytes */
00185                 *p++ = ack_policy | tid;
00186                 *p = ieee80211_vif_is_mesh(&sdata->vif) ?
00187                         (IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT >> 8) : 0;
00188         }
00189 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:11