wme.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. static u16 classify80211(struct ieee80211_local *local, struct sk_buff *skb)
  43. {
  44. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  45. if (!ieee80211_is_data(hdr->frame_control)) {
  46. /* management frames go on AC_VO queue, but are sent
  47. * without QoS control fields */
  48. return 0;
  49. }
  50. if (0 /* injected */) {
  51. /* use AC from radiotap */
  52. }
  53. if (!ieee80211_is_data_qos(hdr->frame_control)) {
  54. skb->priority = 0; /* required for correct WPA/11i MIC */
  55. return ieee802_1d_to_ac[skb->priority];
  56. }
  57. /* use the data classifier to determine what 802.1d tag the
  58. * data frame has */
  59. skb->priority = cfg80211_classify8021d(skb);
  60. /* in case we are a client verify acm is not set for this ac */
  61. while (unlikely(local->wmm_acm & BIT(skb->priority))) {
  62. if (wme_downgrade_ac(skb)) {
  63. /*
  64. * This should not really happen. The AP has marked all
  65. * lower ACs to require admission control which is not
  66. * a reasonable configuration. Allow the frame to be
  67. * transmitted using AC_BK as a workaround.
  68. */
  69. break;
  70. }
  71. }
  72. /* look up which queue to use for frames with this 1d tag */
  73. return ieee802_1d_to_ac[skb->priority];
  74. }
  75. u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
  76. {
  77. struct ieee80211_master_priv *mpriv = netdev_priv(dev);
  78. struct ieee80211_local *local = mpriv->local;
  79. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  80. u16 queue;
  81. u8 tid;
  82. queue = classify80211(local, skb);
  83. if (unlikely(queue >= local->hw.queues))
  84. queue = local->hw.queues - 1;
  85. /*
  86. * Now we know the 1d priority, fill in the QoS header if
  87. * there is one (and we haven't done this before).
  88. */
  89. if (ieee80211_is_data_qos(hdr->frame_control)) {
  90. u8 *p = ieee80211_get_qos_ctl(hdr);
  91. u8 ack_policy = 0;
  92. tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  93. if (unlikely(local->wifi_wme_noack_test))
  94. ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
  95. QOS_CONTROL_ACK_POLICY_SHIFT;
  96. /* qos header is 2 bytes, second reserved */
  97. *p++ = ack_policy | tid;
  98. *p = 0;
  99. }
  100. return queue;
  101. }