vht.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. void ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
  13. struct ieee80211_supported_band *sband,
  14. struct ieee80211_vht_cap *vht_cap_ie,
  15. struct sta_info *sta)
  16. {
  17. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  18. memset(vht_cap, 0, sizeof(*vht_cap));
  19. if (!sta->sta.ht_cap.ht_supported)
  20. return;
  21. if (!vht_cap_ie || !sband->vht_cap.vht_supported)
  22. return;
  23. /* A VHT STA must support 40 MHz */
  24. if (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  25. return;
  26. vht_cap->vht_supported = true;
  27. vht_cap->cap = le32_to_cpu(vht_cap_ie->vht_cap_info);
  28. /* Copy peer MCS info, the driver might need them. */
  29. memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
  30. sizeof(struct ieee80211_vht_mcs_info));
  31. sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta);
  32. }
  33. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta)
  34. {
  35. struct ieee80211_sub_if_data *sdata = sta->sdata;
  36. u32 cap = sta->sta.vht_cap.cap;
  37. if (!sta->sta.vht_cap.vht_supported)
  38. return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  39. IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
  40. /* TODO: handle VHT opmode notification data */
  41. switch (sdata->vif.bss_conf.chandef.width) {
  42. default:
  43. WARN_ON_ONCE(1);
  44. /* fall through */
  45. case NL80211_CHAN_WIDTH_20_NOHT:
  46. case NL80211_CHAN_WIDTH_20:
  47. case NL80211_CHAN_WIDTH_40:
  48. return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  49. IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
  50. case NL80211_CHAN_WIDTH_160:
  51. if (cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  52. return IEEE80211_STA_RX_BW_160;
  53. /* fall through */
  54. case NL80211_CHAN_WIDTH_80P80:
  55. if (cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  56. return IEEE80211_STA_RX_BW_160;
  57. /* fall through */
  58. case NL80211_CHAN_WIDTH_80:
  59. return IEEE80211_STA_RX_BW_80;
  60. }
  61. }
  62. void ieee80211_sta_set_rx_nss(struct sta_info *sta)
  63. {
  64. u8 ht_rx_nss = 0, vht_rx_nss = 0;
  65. /* if we received a notification already don't overwrite it */
  66. if (sta->sta.rx_nss)
  67. return;
  68. if (sta->sta.ht_cap.ht_supported) {
  69. if (sta->sta.ht_cap.mcs.rx_mask[0])
  70. ht_rx_nss++;
  71. if (sta->sta.ht_cap.mcs.rx_mask[1])
  72. ht_rx_nss++;
  73. if (sta->sta.ht_cap.mcs.rx_mask[2])
  74. ht_rx_nss++;
  75. if (sta->sta.ht_cap.mcs.rx_mask[3])
  76. ht_rx_nss++;
  77. /* FIXME: consider rx_highest? */
  78. }
  79. if (sta->sta.vht_cap.vht_supported) {
  80. int i;
  81. u16 rx_mcs_map;
  82. rx_mcs_map = le16_to_cpu(sta->sta.vht_cap.vht_mcs.rx_mcs_map);
  83. for (i = 7; i >= 0; i--) {
  84. u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
  85. if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  86. vht_rx_nss = i + 1;
  87. break;
  88. }
  89. }
  90. /* FIXME: consider rx_highest? */
  91. }
  92. ht_rx_nss = max(ht_rx_nss, vht_rx_nss);
  93. sta->sta.rx_nss = max_t(u8, 1, ht_rx_nss);
  94. }