wme.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /* Indicate which queue to use. */
  51. u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
  52. struct sk_buff *skb)
  53. {
  54. struct ieee80211_local *local = sdata->local;
  55. struct sta_info *sta = NULL;
  56. const u8 *ra = NULL;
  57. bool qos = false;
  58. if (local->hw.queues < 4 || skb->len < 6) {
  59. skb->priority = 0; /* required for correct WPA/11i MIC */
  60. return min_t(u16, local->hw.queues - 1, IEEE80211_AC_BE);
  61. }
  62. rcu_read_lock();
  63. switch (sdata->vif.type) {
  64. case NL80211_IFTYPE_AP_VLAN:
  65. sta = rcu_dereference(sdata->u.vlan.sta);
  66. if (sta) {
  67. qos = get_sta_flags(sta) & WLAN_STA_WME;
  68. break;
  69. }
  70. case NL80211_IFTYPE_AP:
  71. ra = skb->data;
  72. break;
  73. case NL80211_IFTYPE_WDS:
  74. ra = sdata->u.wds.remote_addr;
  75. break;
  76. #ifdef CONFIG_MAC80211_MESH
  77. case NL80211_IFTYPE_MESH_POINT:
  78. /*
  79. * XXX: This is clearly broken ... but already was before,
  80. * because ieee80211_fill_mesh_addresses() would clear A1
  81. * except for multicast addresses.
  82. */
  83. break;
  84. #endif
  85. case NL80211_IFTYPE_STATION:
  86. ra = sdata->u.mgd.bssid;
  87. break;
  88. case NL80211_IFTYPE_ADHOC:
  89. ra = skb->data;
  90. break;
  91. default:
  92. break;
  93. }
  94. if (!sta && ra && !is_multicast_ether_addr(ra)) {
  95. sta = sta_info_get(sdata, ra);
  96. if (sta)
  97. qos = get_sta_flags(sta) & WLAN_STA_WME;
  98. }
  99. rcu_read_unlock();
  100. if (!qos) {
  101. skb->priority = 0; /* required for correct WPA/11i MIC */
  102. return IEEE80211_AC_BE;
  103. }
  104. /* use the data classifier to determine what 802.1d tag the
  105. * data frame has */
  106. skb->priority = cfg80211_classify8021d(skb);
  107. return ieee80211_downgrade_queue(local, skb);
  108. }
  109. u16 ieee80211_downgrade_queue(struct ieee80211_local *local,
  110. struct sk_buff *skb)
  111. {
  112. /* in case we are a client verify acm is not set for this ac */
  113. while (unlikely(local->wmm_acm & BIT(skb->priority))) {
  114. if (wme_downgrade_ac(skb)) {
  115. /*
  116. * This should not really happen. The AP has marked all
  117. * lower ACs to require admission control which is not
  118. * a reasonable configuration. Allow the frame to be
  119. * transmitted using AC_BK as a workaround.
  120. */
  121. break;
  122. }
  123. }
  124. /* look up which queue to use for frames with this 1d tag */
  125. return ieee802_1d_to_ac[skb->priority];
  126. }
  127. void ieee80211_set_qos_hdr(struct ieee80211_local *local, struct sk_buff *skb)
  128. {
  129. struct ieee80211_hdr *hdr = (void *)skb->data;
  130. /* Fill in the QoS header if there is one. */
  131. if (ieee80211_is_data_qos(hdr->frame_control)) {
  132. u8 *p = ieee80211_get_qos_ctl(hdr);
  133. u8 ack_policy = 0, tid;
  134. tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  135. if (unlikely(local->wifi_wme_noack_test))
  136. ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
  137. QOS_CONTROL_ACK_POLICY_SHIFT;
  138. /* qos header is 2 bytes, second reserved */
  139. *p++ = ack_policy | tid;
  140. *p = 0;
  141. }
  142. }