wme.c 3.7 KB

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