wme.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #include <linux/netdevice.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/module.h>
  11. #include <linux/if_arp.h>
  12. #include <linux/types.h>
  13. #include <net/ip.h>
  14. #include <net/pkt_sched.h>
  15. #include <net/mac80211.h>
  16. #include "ieee80211_i.h"
  17. #include "wme.h"
  18. /* Default mapping in classifier to work with default
  19. * queue setup.
  20. */
  21. const int ieee802_1d_to_ac[8] = {
  22. IEEE80211_AC_BE,
  23. IEEE80211_AC_BK,
  24. IEEE80211_AC_BK,
  25. IEEE80211_AC_BE,
  26. IEEE80211_AC_VI,
  27. IEEE80211_AC_VI,
  28. IEEE80211_AC_VO,
  29. IEEE80211_AC_VO
  30. };
  31. static int wme_downgrade_ac(struct sk_buff *skb)
  32. {
  33. switch (skb->priority) {
  34. case 6:
  35. case 7:
  36. skb->priority = 5; /* VO -> VI */
  37. return 0;
  38. case 4:
  39. case 5:
  40. skb->priority = 3; /* VI -> BE */
  41. return 0;
  42. case 0:
  43. case 3:
  44. skb->priority = 2; /* BE -> BK */
  45. return 0;
  46. default:
  47. return -1;
  48. }
  49. }
  50. static u16 ieee80211_downgrade_queue(struct ieee80211_sub_if_data *sdata,
  51. struct sk_buff *skb)
  52. {
  53. /* in case we are a client verify acm is not set for this ac */
  54. while (unlikely(sdata->wmm_acm & BIT(skb->priority))) {
  55. if (wme_downgrade_ac(skb)) {
  56. /*
  57. * This should not really happen. The AP has marked all
  58. * lower ACs to require admission control which is not
  59. * a reasonable configuration. Allow the frame to be
  60. * transmitted using AC_BK as a workaround.
  61. */
  62. break;
  63. }
  64. }
  65. /* look up which queue to use for frames with this 1d tag */
  66. return ieee802_1d_to_ac[skb->priority];
  67. }
  68. /* Indicate which queue to use for this fully formed 802.11 frame */
  69. u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata,
  70. struct sk_buff *skb,
  71. struct ieee80211_hdr *hdr)
  72. {
  73. struct ieee80211_local *local = sdata->local;
  74. u8 *p;
  75. if (local->hw.queues < IEEE80211_NUM_ACS)
  76. return 0;
  77. if (!ieee80211_is_data(hdr->frame_control)) {
  78. skb->priority = 7;
  79. return ieee802_1d_to_ac[skb->priority];
  80. }
  81. if (!ieee80211_is_data_qos(hdr->frame_control)) {
  82. skb->priority = 0;
  83. return ieee802_1d_to_ac[skb->priority];
  84. }
  85. p = ieee80211_get_qos_ctl(hdr);
  86. skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
  87. return ieee80211_downgrade_queue(sdata, skb);
  88. }
  89. /* Indicate which queue to use. */
  90. u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
  91. struct sk_buff *skb)
  92. {
  93. struct ieee80211_local *local = sdata->local;
  94. struct sta_info *sta = NULL;
  95. const u8 *ra = NULL;
  96. bool qos = false;
  97. if (local->hw.queues < IEEE80211_NUM_ACS || skb->len < 6) {
  98. skb->priority = 0; /* required for correct WPA/11i MIC */
  99. return 0;
  100. }
  101. rcu_read_lock();
  102. switch (sdata->vif.type) {
  103. case NL80211_IFTYPE_AP_VLAN:
  104. sta = rcu_dereference(sdata->u.vlan.sta);
  105. if (sta) {
  106. qos = test_sta_flag(sta, WLAN_STA_WME);
  107. break;
  108. }
  109. case NL80211_IFTYPE_AP:
  110. ra = skb->data;
  111. break;
  112. case NL80211_IFTYPE_WDS:
  113. ra = sdata->u.wds.remote_addr;
  114. break;
  115. #ifdef CONFIG_MAC80211_MESH
  116. case NL80211_IFTYPE_MESH_POINT:
  117. qos = true;
  118. break;
  119. #endif
  120. case NL80211_IFTYPE_STATION:
  121. ra = sdata->u.mgd.bssid;
  122. break;
  123. case NL80211_IFTYPE_ADHOC:
  124. ra = skb->data;
  125. break;
  126. default:
  127. break;
  128. }
  129. if (!sta && ra && !is_multicast_ether_addr(ra)) {
  130. sta = sta_info_get(sdata, ra);
  131. if (sta)
  132. qos = test_sta_flag(sta, WLAN_STA_WME);
  133. }
  134. rcu_read_unlock();
  135. if (!qos) {
  136. skb->priority = 0; /* required for correct WPA/11i MIC */
  137. return IEEE80211_AC_BE;
  138. }
  139. /* use the data classifier to determine what 802.1d tag the
  140. * data frame has */
  141. skb->priority = cfg80211_classify8021d(skb);
  142. return ieee80211_downgrade_queue(sdata, skb);
  143. }
  144. void ieee80211_set_qos_hdr(struct ieee80211_sub_if_data *sdata,
  145. struct sk_buff *skb)
  146. {
  147. struct ieee80211_hdr *hdr = (void *)skb->data;
  148. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  149. /* Fill in the QoS header if there is one. */
  150. if (ieee80211_is_data_qos(hdr->frame_control)) {
  151. u8 *p = ieee80211_get_qos_ctl(hdr);
  152. u8 ack_policy, tid;
  153. tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  154. /* preserve EOSP bit */
  155. ack_policy = *p & IEEE80211_QOS_CTL_EOSP;
  156. if (is_multicast_ether_addr(hdr->addr1) ||
  157. sdata->noack_map & BIT(tid)) {
  158. ack_policy |= IEEE80211_QOS_CTL_ACK_POLICY_NOACK;
  159. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  160. }
  161. /* qos header is 2 bytes */
  162. *p++ = ack_policy | tid;
  163. *p = ieee80211_vif_is_mesh(&sdata->vif) ?
  164. (IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT >> 8) : 0;
  165. }
  166. }