wme.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 const char llc_ip_hdr[8] = {0xAA, 0xAA, 0x3, 0, 0, 0, 0x08, 0};
  23. /* Given a data frame determine the 802.1p/1d tag to use. */
  24. static unsigned int classify_1d(struct sk_buff *skb)
  25. {
  26. unsigned int dscp;
  27. /* skb->priority values from 256->263 are magic values to
  28. * directly indicate a specific 802.1d priority. This is used
  29. * to allow 802.1d priority to be passed directly in from VLAN
  30. * tags, etc.
  31. */
  32. if (skb->priority >= 256 && skb->priority <= 263)
  33. return skb->priority - 256;
  34. switch (skb->protocol) {
  35. case htons(ETH_P_IP):
  36. dscp = ip_hdr(skb)->tos & 0xfc;
  37. break;
  38. default:
  39. return 0;
  40. }
  41. return dscp >> 5;
  42. }
  43. static int wme_downgrade_ac(struct sk_buff *skb)
  44. {
  45. switch (skb->priority) {
  46. case 6:
  47. case 7:
  48. skb->priority = 5; /* VO -> VI */
  49. return 0;
  50. case 4:
  51. case 5:
  52. skb->priority = 3; /* VI -> BE */
  53. return 0;
  54. case 0:
  55. case 3:
  56. skb->priority = 2; /* BE -> BK */
  57. return 0;
  58. default:
  59. return -1;
  60. }
  61. }
  62. /* Indicate which queue to use. */
  63. static u16 classify80211(struct ieee80211_local *local, struct sk_buff *skb)
  64. {
  65. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  66. if (!ieee80211_is_data(hdr->frame_control)) {
  67. /* management frames go on AC_VO queue, but are sent
  68. * without QoS control fields */
  69. return 0;
  70. }
  71. if (0 /* injected */) {
  72. /* use AC from radiotap */
  73. }
  74. if (!ieee80211_is_data_qos(hdr->frame_control)) {
  75. skb->priority = 0; /* required for correct WPA/11i MIC */
  76. return ieee802_1d_to_ac[skb->priority];
  77. }
  78. /* use the data classifier to determine what 802.1d tag the
  79. * data frame has */
  80. skb->priority = classify_1d(skb);
  81. /* in case we are a client verify acm is not set for this ac */
  82. while (unlikely(local->wmm_acm & BIT(skb->priority))) {
  83. if (wme_downgrade_ac(skb)) {
  84. /*
  85. * This should not really happen. The AP has marked all
  86. * lower ACs to require admission control which is not
  87. * a reasonable configuration. Allow the frame to be
  88. * transmitted using AC_BK as a workaround.
  89. */
  90. break;
  91. }
  92. }
  93. /* look up which queue to use for frames with this 1d tag */
  94. return ieee802_1d_to_ac[skb->priority];
  95. }
  96. u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
  97. {
  98. struct ieee80211_master_priv *mpriv = netdev_priv(dev);
  99. struct ieee80211_local *local = mpriv->local;
  100. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  101. u16 queue;
  102. u8 tid;
  103. queue = classify80211(local, skb);
  104. if (unlikely(queue >= local->hw.queues))
  105. queue = local->hw.queues - 1;
  106. /*
  107. * Now we know the 1d priority, fill in the QoS header if
  108. * there is one (and we haven't done this before).
  109. */
  110. if (!skb->requeue && ieee80211_is_data_qos(hdr->frame_control)) {
  111. u8 *p = ieee80211_get_qos_ctl(hdr);
  112. u8 ack_policy = 0;
  113. tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  114. if (local->wifi_wme_noack_test)
  115. ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
  116. QOS_CONTROL_ACK_POLICY_SHIFT;
  117. /* qos header is 2 bytes, second reserved */
  118. *p++ = ack_policy | tid;
  119. *p = 0;
  120. }
  121. return queue;
  122. }