vht.c 4.9 KB

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