vht.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * VHT handling
  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/ieee80211.h>
  9. #include <linux/export.h>
  10. #include <net/mac80211.h>
  11. #include "ieee80211_i.h"
  12. #include "rate.h"
  13. void ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
  14. struct ieee80211_supported_band *sband,
  15. struct ieee80211_vht_cap *vht_cap_ie,
  16. struct sta_info *sta)
  17. {
  18. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  19. memset(vht_cap, 0, sizeof(*vht_cap));
  20. if (!sta->sta.ht_cap.ht_supported)
  21. return;
  22. if (!vht_cap_ie || !sband->vht_cap.vht_supported)
  23. return;
  24. /* A VHT STA must support 40 MHz */
  25. if (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  26. return;
  27. vht_cap->vht_supported = true;
  28. vht_cap->cap = le32_to_cpu(vht_cap_ie->vht_cap_info);
  29. /* Copy peer MCS info, the driver might need them. */
  30. memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
  31. sizeof(struct ieee80211_vht_mcs_info));
  32. switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  33. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  34. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  35. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  36. break;
  37. default:
  38. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  39. }
  40. sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta);
  41. }
  42. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta)
  43. {
  44. struct ieee80211_sub_if_data *sdata = sta->sdata;
  45. u32 cap = sta->sta.vht_cap.cap;
  46. enum ieee80211_sta_rx_bandwidth bw;
  47. if (!sta->sta.vht_cap.vht_supported) {
  48. bw = sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  49. IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
  50. goto check_max;
  51. }
  52. switch (sdata->vif.bss_conf.chandef.width) {
  53. default:
  54. WARN_ON_ONCE(1);
  55. /* fall through */
  56. case NL80211_CHAN_WIDTH_20_NOHT:
  57. case NL80211_CHAN_WIDTH_20:
  58. case NL80211_CHAN_WIDTH_40:
  59. bw = sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  60. IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
  61. break;
  62. case NL80211_CHAN_WIDTH_160:
  63. if ((cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) ==
  64. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ) {
  65. bw = IEEE80211_STA_RX_BW_160;
  66. break;
  67. }
  68. /* fall through */
  69. case NL80211_CHAN_WIDTH_80P80:
  70. if ((cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) ==
  71. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
  72. bw = IEEE80211_STA_RX_BW_160;
  73. break;
  74. }
  75. /* fall through */
  76. case NL80211_CHAN_WIDTH_80:
  77. bw = IEEE80211_STA_RX_BW_80;
  78. }
  79. check_max:
  80. if (bw > sta->cur_max_bandwidth)
  81. bw = sta->cur_max_bandwidth;
  82. return bw;
  83. }
  84. void ieee80211_sta_set_rx_nss(struct sta_info *sta)
  85. {
  86. u8 ht_rx_nss = 0, vht_rx_nss = 0;
  87. /* if we received a notification already don't overwrite it */
  88. if (sta->sta.rx_nss)
  89. return;
  90. if (sta->sta.ht_cap.ht_supported) {
  91. if (sta->sta.ht_cap.mcs.rx_mask[0])
  92. ht_rx_nss++;
  93. if (sta->sta.ht_cap.mcs.rx_mask[1])
  94. ht_rx_nss++;
  95. if (sta->sta.ht_cap.mcs.rx_mask[2])
  96. ht_rx_nss++;
  97. if (sta->sta.ht_cap.mcs.rx_mask[3])
  98. ht_rx_nss++;
  99. /* FIXME: consider rx_highest? */
  100. }
  101. if (sta->sta.vht_cap.vht_supported) {
  102. int i;
  103. u16 rx_mcs_map;
  104. rx_mcs_map = le16_to_cpu(sta->sta.vht_cap.vht_mcs.rx_mcs_map);
  105. for (i = 7; i >= 0; i--) {
  106. u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
  107. if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  108. vht_rx_nss = i + 1;
  109. break;
  110. }
  111. }
  112. /* FIXME: consider rx_highest? */
  113. }
  114. ht_rx_nss = max(ht_rx_nss, vht_rx_nss);
  115. sta->sta.rx_nss = max_t(u8, 1, ht_rx_nss);
  116. }
  117. void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  118. struct sta_info *sta, u8 opmode,
  119. enum ieee80211_band band)
  120. {
  121. struct ieee80211_local *local = sdata->local;
  122. struct ieee80211_supported_band *sband;
  123. enum ieee80211_sta_rx_bandwidth new_bw;
  124. u32 changed = 0;
  125. u8 nss;
  126. sband = local->hw.wiphy->bands[band];
  127. /* ignore - no support for BF yet */
  128. if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)
  129. return;
  130. nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  131. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  132. nss += 1;
  133. if (sta->sta.rx_nss != nss) {
  134. sta->sta.rx_nss = nss;
  135. changed |= IEEE80211_RC_NSS_CHANGED;
  136. }
  137. switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) {
  138. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ:
  139. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20;
  140. break;
  141. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ:
  142. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40;
  143. break;
  144. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ:
  145. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  146. break;
  147. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ:
  148. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  149. break;
  150. }
  151. new_bw = ieee80211_sta_cur_vht_bw(sta);
  152. if (new_bw != sta->sta.bandwidth) {
  153. sta->sta.bandwidth = new_bw;
  154. changed |= IEEE80211_RC_NSS_CHANGED;
  155. }
  156. if (changed)
  157. rate_control_rate_update(local, sband, sta, changed);
  158. }