321-mac80211-Parse-legacy-and-HT-rate-in-injected-frames.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. From: Sven Eckelmann <sven@narfation.org>
  2. Date: Tue, 26 Jan 2016 17:11:13 +0100
  3. Subject: [PATCH] mac80211: Parse legacy and HT rate in injected frames
  4. Drivers/devices without their own rate control algorithm can get the
  5. information what rates they should use from either the radiotap header of
  6. injected frames or from the rate control algorithm. But the parsing of the
  7. legacy rate information from the radiotap header was removed in commit
  8. e6a9854b05c1 ("mac80211/drivers: rewrite the rate control API").
  9. The removal of this feature heavily reduced the usefulness of frame
  10. injection when wanting to simulate specific transmission behavior. Having
  11. rate parsing together with MCS rates and retry support allows a fine
  12. grained selection of the tx behavior of injected frames for these kind of
  13. tests.
  14. Signed-off-by: Sven Eckelmann <sven@narfation.org>
  15. Cc: Simon Wunderlich <sw@simonwunderlich.de>
  16. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  17. ---
  18. --- a/include/net/mac80211.h
  19. +++ b/include/net/mac80211.h
  20. @@ -708,12 +708,14 @@ enum mac80211_tx_info_flags {
  21. * protocol frame (e.g. EAP)
  22. * @IEEE80211_TX_CTRL_PS_RESPONSE: This frame is a response to a poll
  23. * frame (PS-Poll or uAPSD).
  24. + * @IEEE80211_TX_CTRL_RATE_INJECT: This frame is injected with rate information
  25. *
  26. * These flags are used in tx_info->control.flags.
  27. */
  28. enum mac80211_tx_control_flags {
  29. IEEE80211_TX_CTRL_PORT_CTRL_PROTO = BIT(0),
  30. IEEE80211_TX_CTRL_PS_RESPONSE = BIT(1),
  31. + IEEE80211_TX_CTRL_RATE_INJECT = BIT(2),
  32. };
  33. /*
  34. --- a/net/mac80211/tx.c
  35. +++ b/net/mac80211/tx.c
  36. @@ -710,6 +710,10 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
  37. info->control.short_preamble = txrc.short_preamble;
  38. + /* don't ask rate control when rate already injected via radiotap */
  39. + if (info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)
  40. + return TX_CONTINUE;
  41. +
  42. if (tx->sta)
  43. assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
  44. @@ -1665,15 +1669,24 @@ void ieee80211_xmit(struct ieee80211_sub
  45. ieee80211_tx(sdata, sta, skb, false);
  46. }
  47. -static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb)
  48. +static bool ieee80211_parse_tx_radiotap(struct ieee80211_local *local,
  49. + struct sk_buff *skb)
  50. {
  51. struct ieee80211_radiotap_iterator iterator;
  52. struct ieee80211_radiotap_header *rthdr =
  53. (struct ieee80211_radiotap_header *) skb->data;
  54. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  55. + struct ieee80211_supported_band *sband =
  56. + local->hw.wiphy->bands[info->band];
  57. int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
  58. NULL);
  59. u16 txflags;
  60. + u16 rate = 0;
  61. + bool rate_found = false;
  62. + u8 rate_retries = 0;
  63. + u16 rate_flags = 0;
  64. + u8 mcs_known, mcs_flags;
  65. + int i;
  66. info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  67. IEEE80211_TX_CTL_DONTFRAG;
  68. @@ -1724,6 +1737,35 @@ static bool ieee80211_parse_tx_radiotap(
  69. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  70. break;
  71. + case IEEE80211_RADIOTAP_RATE:
  72. + rate = *iterator.this_arg;
  73. + rate_flags = 0;
  74. + rate_found = true;
  75. + break;
  76. +
  77. + case IEEE80211_RADIOTAP_DATA_RETRIES:
  78. + rate_retries = *iterator.this_arg;
  79. + break;
  80. +
  81. + case IEEE80211_RADIOTAP_MCS:
  82. + mcs_known = iterator.this_arg[0];
  83. + mcs_flags = iterator.this_arg[1];
  84. + if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS))
  85. + break;
  86. +
  87. + rate_found = true;
  88. + rate = iterator.this_arg[2];
  89. + rate_flags = IEEE80211_TX_RC_MCS;
  90. +
  91. + if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI &&
  92. + mcs_flags & IEEE80211_RADIOTAP_MCS_SGI)
  93. + rate_flags |= IEEE80211_TX_RC_SHORT_GI;
  94. +
  95. + if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW &&
  96. + mcs_flags & IEEE80211_RADIOTAP_MCS_BW_40)
  97. + rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  98. + break;
  99. +
  100. /*
  101. * Please update the file
  102. * Documentation/networking/mac80211-injection.txt
  103. @@ -1738,6 +1780,32 @@ static bool ieee80211_parse_tx_radiotap(
  104. if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
  105. return false;
  106. + if (rate_found) {
  107. + info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT;
  108. +
  109. + for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  110. + info->control.rates[i].idx = -1;
  111. + info->control.rates[i].flags = 0;
  112. + info->control.rates[i].count = 0;
  113. + }
  114. +
  115. + if (rate_flags & IEEE80211_TX_RC_MCS) {
  116. + info->control.rates[0].idx = rate;
  117. + } else {
  118. + for (i = 0; i < sband->n_bitrates; i++) {
  119. + if (rate * 5 != sband->bitrates[i].bitrate)
  120. + continue;
  121. +
  122. + info->control.rates[0].idx = i;
  123. + break;
  124. + }
  125. + }
  126. +
  127. + info->control.rates[0].flags = rate_flags;
  128. + info->control.rates[0].count = min_t(u8, rate_retries + 1,
  129. + local->hw.max_rate_tries);
  130. + }
  131. +
  132. /*
  133. * remove the radiotap header
  134. * iterator->_max_length was sanity-checked against
  135. @@ -1819,7 +1887,7 @@ netdev_tx_t ieee80211_monitor_start_xmit
  136. IEEE80211_TX_CTL_INJECTED;
  137. /* process and remove the injection radiotap header */
  138. - if (!ieee80211_parse_tx_radiotap(skb))
  139. + if (!ieee80211_parse_tx_radiotap(local, skb))
  140. goto fail;
  141. rcu_read_lock();