vht.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * VHT handling
  3. *
  4. * Portions of this file
  5. * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/ieee80211.h>
  12. #include <linux/export.h>
  13. #include <net/mac80211.h>
  14. #include "ieee80211_i.h"
  15. #include "rate.h"
  16. static void __check_vhtcap_disable(struct ieee80211_sub_if_data *sdata,
  17. struct ieee80211_sta_vht_cap *vht_cap,
  18. u32 flag)
  19. {
  20. __le32 le_flag = cpu_to_le32(flag);
  21. if (sdata->u.mgd.vht_capa_mask.vht_cap_info & le_flag &&
  22. !(sdata->u.mgd.vht_capa.vht_cap_info & le_flag))
  23. vht_cap->cap &= ~flag;
  24. }
  25. void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data *sdata,
  26. struct ieee80211_sta_vht_cap *vht_cap)
  27. {
  28. int i;
  29. u16 rxmcs_mask, rxmcs_cap, rxmcs_n, txmcs_mask, txmcs_cap, txmcs_n;
  30. if (!vht_cap->vht_supported)
  31. return;
  32. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  33. return;
  34. __check_vhtcap_disable(sdata, vht_cap,
  35. IEEE80211_VHT_CAP_RXLDPC);
  36. __check_vhtcap_disable(sdata, vht_cap,
  37. IEEE80211_VHT_CAP_SHORT_GI_80);
  38. __check_vhtcap_disable(sdata, vht_cap,
  39. IEEE80211_VHT_CAP_SHORT_GI_160);
  40. __check_vhtcap_disable(sdata, vht_cap,
  41. IEEE80211_VHT_CAP_TXSTBC);
  42. __check_vhtcap_disable(sdata, vht_cap,
  43. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
  44. __check_vhtcap_disable(sdata, vht_cap,
  45. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE);
  46. __check_vhtcap_disable(sdata, vht_cap,
  47. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN);
  48. __check_vhtcap_disable(sdata, vht_cap,
  49. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN);
  50. /* Allow user to decrease AMPDU length exponent */
  51. if (sdata->u.mgd.vht_capa_mask.vht_cap_info &
  52. cpu_to_le32(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK)) {
  53. u32 cap, n;
  54. n = le32_to_cpu(sdata->u.mgd.vht_capa.vht_cap_info) &
  55. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  56. n >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  57. cap = vht_cap->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  58. cap >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  59. if (n < cap) {
  60. vht_cap->cap &=
  61. ~IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  62. vht_cap->cap |=
  63. n << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  64. }
  65. }
  66. /* Allow the user to decrease MCSes */
  67. rxmcs_mask =
  68. le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.rx_mcs_map);
  69. rxmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.rx_mcs_map);
  70. rxmcs_n &= rxmcs_mask;
  71. rxmcs_cap = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  72. txmcs_mask =
  73. le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.tx_mcs_map);
  74. txmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.tx_mcs_map);
  75. txmcs_n &= txmcs_mask;
  76. txmcs_cap = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  77. for (i = 0; i < 8; i++) {
  78. u8 m, n, c;
  79. m = (rxmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  80. n = (rxmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  81. c = (rxmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  82. if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
  83. n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
  84. rxmcs_cap &= ~(3 << 2*i);
  85. rxmcs_cap |= (rxmcs_n & (3 << 2*i));
  86. }
  87. m = (txmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  88. n = (txmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  89. c = (txmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  90. if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
  91. n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
  92. txmcs_cap &= ~(3 << 2*i);
  93. txmcs_cap |= (txmcs_n & (3 << 2*i));
  94. }
  95. }
  96. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_cap);
  97. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_cap);
  98. }
  99. void
  100. ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
  101. struct ieee80211_supported_band *sband,
  102. const struct ieee80211_vht_cap *vht_cap_ie,
  103. struct sta_info *sta)
  104. {
  105. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  106. struct ieee80211_sta_vht_cap own_cap;
  107. u32 cap_info, i;
  108. bool have_80mhz;
  109. memset(vht_cap, 0, sizeof(*vht_cap));
  110. if (!sta->sta.ht_cap.ht_supported)
  111. return;
  112. if (!vht_cap_ie || !sband->vht_cap.vht_supported)
  113. return;
  114. /* Allow VHT if at least one channel on the sband supports 80 MHz */
  115. have_80mhz = false;
  116. for (i = 0; i < sband->n_channels; i++) {
  117. if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
  118. IEEE80211_CHAN_NO_80MHZ))
  119. continue;
  120. have_80mhz = true;
  121. break;
  122. }
  123. if (!have_80mhz)
  124. return;
  125. /*
  126. * A VHT STA must support 40 MHz, but if we verify that here
  127. * then we break a few things - some APs (e.g. Netgear R6300v2
  128. * and others based on the BCM4360 chipset) will unset this
  129. * capability bit when operating in 20 MHz.
  130. */
  131. vht_cap->vht_supported = true;
  132. own_cap = sband->vht_cap;
  133. /*
  134. * If user has specified capability overrides, take care
  135. * of that if the station we're setting up is the AP that
  136. * we advertised a restricted capability set to. Override
  137. * our own capabilities and then use those below.
  138. */
  139. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  140. !test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  141. ieee80211_apply_vhtcap_overrides(sdata, &own_cap);
  142. /* take some capabilities as-is */
  143. cap_info = le32_to_cpu(vht_cap_ie->vht_cap_info);
  144. vht_cap->cap = cap_info;
  145. vht_cap->cap &= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
  146. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
  147. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  148. IEEE80211_VHT_CAP_RXLDPC |
  149. IEEE80211_VHT_CAP_VHT_TXOP_PS |
  150. IEEE80211_VHT_CAP_HTC_VHT |
  151. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  152. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB |
  153. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB |
  154. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  155. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  156. /* and some based on our own capabilities */
  157. switch (own_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  158. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  159. vht_cap->cap |= cap_info &
  160. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  161. break;
  162. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  163. vht_cap->cap |= cap_info &
  164. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  165. break;
  166. default:
  167. /* nothing */
  168. break;
  169. }
  170. /* symmetric capabilities */
  171. vht_cap->cap |= cap_info & own_cap.cap &
  172. (IEEE80211_VHT_CAP_SHORT_GI_80 |
  173. IEEE80211_VHT_CAP_SHORT_GI_160);
  174. /* remaining ones */
  175. if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
  176. vht_cap->cap |= cap_info &
  177. (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  178. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
  179. if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
  180. vht_cap->cap |= cap_info &
  181. (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  182. IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
  183. if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
  184. vht_cap->cap |= cap_info &
  185. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  186. if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
  187. vht_cap->cap |= cap_info &
  188. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
  189. if (own_cap.cap & IEEE80211_VHT_CAP_TXSTBC)
  190. vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_RXSTBC_MASK;
  191. if (own_cap.cap & IEEE80211_VHT_CAP_RXSTBC_MASK)
  192. vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_TXSTBC;
  193. /* Copy peer MCS info, the driver might need them. */
  194. memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
  195. sizeof(struct ieee80211_vht_mcs_info));
  196. /* but also restrict MCSes */
  197. for (i = 0; i < 8; i++) {
  198. u16 own_rx, own_tx, peer_rx, peer_tx;
  199. own_rx = le16_to_cpu(own_cap.vht_mcs.rx_mcs_map);
  200. own_rx = (own_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  201. own_tx = le16_to_cpu(own_cap.vht_mcs.tx_mcs_map);
  202. own_tx = (own_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  203. peer_rx = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  204. peer_rx = (peer_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  205. peer_tx = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  206. peer_tx = (peer_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  207. if (peer_tx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  208. if (own_rx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  209. peer_tx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  210. else if (own_rx < peer_tx)
  211. peer_tx = own_rx;
  212. }
  213. if (peer_rx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  214. if (own_tx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  215. peer_rx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  216. else if (own_tx < peer_rx)
  217. peer_rx = own_tx;
  218. }
  219. vht_cap->vht_mcs.rx_mcs_map &=
  220. ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
  221. vht_cap->vht_mcs.rx_mcs_map |= cpu_to_le16(peer_rx << i * 2);
  222. vht_cap->vht_mcs.tx_mcs_map &=
  223. ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
  224. vht_cap->vht_mcs.tx_mcs_map |= cpu_to_le16(peer_tx << i * 2);
  225. }
  226. /*
  227. * This is a workaround for VHT-enabled STAs which break the spec
  228. * and have the VHT-MCS Rx map filled in with value 3 for all eight
  229. * spacial streams, an example is AR9462.
  230. *
  231. * As per spec, in section 22.1.1 Introduction to the VHT PHY
  232. * A VHT STA shall support at least single spactial stream VHT-MCSs
  233. * 0 to 7 (transmit and receive) in all supported channel widths.
  234. */
  235. if (vht_cap->vht_mcs.rx_mcs_map == cpu_to_le16(0xFFFF)) {
  236. vht_cap->vht_supported = false;
  237. sdata_info(sdata, "Ignoring VHT IE from %pM due to invalid rx_mcs_map\n",
  238. sta->addr);
  239. return;
  240. }
  241. /* finally set up the bandwidth */
  242. switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  243. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  244. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  245. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  246. break;
  247. default:
  248. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  249. }
  250. sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta);
  251. /* If HT IE reported 3839 bytes only, stay with that size. */
  252. if (sta->sta.max_amsdu_len == IEEE80211_MAX_MPDU_LEN_HT_3839)
  253. return;
  254. switch (vht_cap->cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK) {
  255. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
  256. sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454;
  257. break;
  258. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
  259. sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991;
  260. break;
  261. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
  262. default:
  263. sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895;
  264. break;
  265. }
  266. }
  267. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cap_rx_bw(struct sta_info *sta)
  268. {
  269. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  270. u32 cap_width;
  271. if (!vht_cap->vht_supported)
  272. return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  273. IEEE80211_STA_RX_BW_40 :
  274. IEEE80211_STA_RX_BW_20;
  275. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  276. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
  277. cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  278. return IEEE80211_STA_RX_BW_160;
  279. return IEEE80211_STA_RX_BW_80;
  280. }
  281. enum nl80211_chan_width ieee80211_sta_cap_chan_bw(struct sta_info *sta)
  282. {
  283. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  284. u32 cap_width;
  285. if (!vht_cap->vht_supported) {
  286. if (!sta->sta.ht_cap.ht_supported)
  287. return NL80211_CHAN_WIDTH_20_NOHT;
  288. return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  289. NL80211_CHAN_WIDTH_40 : NL80211_CHAN_WIDTH_20;
  290. }
  291. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  292. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  293. return NL80211_CHAN_WIDTH_160;
  294. else if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  295. return NL80211_CHAN_WIDTH_80P80;
  296. return NL80211_CHAN_WIDTH_80;
  297. }
  298. enum nl80211_chan_width
  299. ieee80211_sta_rx_bw_to_chan_width(struct sta_info *sta)
  300. {
  301. enum ieee80211_sta_rx_bandwidth cur_bw = sta->sta.bandwidth;
  302. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  303. u32 cap_width;
  304. switch (cur_bw) {
  305. case IEEE80211_STA_RX_BW_20:
  306. if (!sta->sta.ht_cap.ht_supported)
  307. return NL80211_CHAN_WIDTH_20_NOHT;
  308. else
  309. return NL80211_CHAN_WIDTH_20;
  310. case IEEE80211_STA_RX_BW_40:
  311. return NL80211_CHAN_WIDTH_40;
  312. case IEEE80211_STA_RX_BW_80:
  313. return NL80211_CHAN_WIDTH_80;
  314. case IEEE80211_STA_RX_BW_160:
  315. cap_width =
  316. vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  317. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  318. return NL80211_CHAN_WIDTH_160;
  319. return NL80211_CHAN_WIDTH_80P80;
  320. default:
  321. return NL80211_CHAN_WIDTH_20;
  322. }
  323. }
  324. enum ieee80211_sta_rx_bandwidth
  325. ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width)
  326. {
  327. switch (width) {
  328. case NL80211_CHAN_WIDTH_20_NOHT:
  329. case NL80211_CHAN_WIDTH_20:
  330. return IEEE80211_STA_RX_BW_20;
  331. case NL80211_CHAN_WIDTH_40:
  332. return IEEE80211_STA_RX_BW_40;
  333. case NL80211_CHAN_WIDTH_80:
  334. return IEEE80211_STA_RX_BW_80;
  335. case NL80211_CHAN_WIDTH_160:
  336. case NL80211_CHAN_WIDTH_80P80:
  337. return IEEE80211_STA_RX_BW_160;
  338. default:
  339. WARN_ON_ONCE(1);
  340. return IEEE80211_STA_RX_BW_20;
  341. }
  342. }
  343. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta)
  344. {
  345. struct ieee80211_sub_if_data *sdata = sta->sdata;
  346. enum ieee80211_sta_rx_bandwidth bw;
  347. enum nl80211_chan_width bss_width = sdata->vif.bss_conf.chandef.width;
  348. bw = ieee80211_sta_cap_rx_bw(sta);
  349. bw = min(bw, sta->cur_max_bandwidth);
  350. /* Don't consider AP's bandwidth for TDLS peers, section 11.23.1 of
  351. * IEEE80211-2016 specification makes higher bandwidth operation
  352. * possible on the TDLS link if the peers have wider bandwidth
  353. * capability.
  354. */
  355. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  356. test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW))
  357. return bw;
  358. bw = min(bw, ieee80211_chan_width_to_rx_bw(bss_width));
  359. return bw;
  360. }
  361. void ieee80211_sta_set_rx_nss(struct sta_info *sta)
  362. {
  363. u8 ht_rx_nss = 0, vht_rx_nss = 0;
  364. /* if we received a notification already don't overwrite it */
  365. if (sta->sta.rx_nss)
  366. return;
  367. if (sta->sta.ht_cap.ht_supported) {
  368. if (sta->sta.ht_cap.mcs.rx_mask[0])
  369. ht_rx_nss++;
  370. if (sta->sta.ht_cap.mcs.rx_mask[1])
  371. ht_rx_nss++;
  372. if (sta->sta.ht_cap.mcs.rx_mask[2])
  373. ht_rx_nss++;
  374. if (sta->sta.ht_cap.mcs.rx_mask[3])
  375. ht_rx_nss++;
  376. /* FIXME: consider rx_highest? */
  377. }
  378. if (sta->sta.vht_cap.vht_supported) {
  379. int i;
  380. u16 rx_mcs_map;
  381. rx_mcs_map = le16_to_cpu(sta->sta.vht_cap.vht_mcs.rx_mcs_map);
  382. for (i = 7; i >= 0; i--) {
  383. u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
  384. if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  385. vht_rx_nss = i + 1;
  386. break;
  387. }
  388. }
  389. /* FIXME: consider rx_highest? */
  390. }
  391. ht_rx_nss = max(ht_rx_nss, vht_rx_nss);
  392. sta->sta.rx_nss = max_t(u8, 1, ht_rx_nss);
  393. }
  394. u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  395. struct sta_info *sta, u8 opmode,
  396. enum nl80211_band band)
  397. {
  398. enum ieee80211_sta_rx_bandwidth new_bw;
  399. struct sta_opmode_info sta_opmode = {};
  400. u32 changed = 0;
  401. u8 nss;
  402. /* ignore - no support for BF yet */
  403. if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)
  404. return 0;
  405. nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  406. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  407. nss += 1;
  408. if (sta->sta.rx_nss != nss) {
  409. sta->sta.rx_nss = nss;
  410. sta_opmode.rx_nss = nss;
  411. changed |= IEEE80211_RC_NSS_CHANGED;
  412. sta_opmode.changed |= STA_OPMODE_N_SS_CHANGED;
  413. }
  414. switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) {
  415. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ:
  416. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20;
  417. break;
  418. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ:
  419. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40;
  420. break;
  421. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ:
  422. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  423. break;
  424. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ:
  425. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  426. break;
  427. }
  428. new_bw = ieee80211_sta_cur_vht_bw(sta);
  429. if (new_bw != sta->sta.bandwidth) {
  430. sta->sta.bandwidth = new_bw;
  431. sta_opmode.bw = ieee80211_sta_rx_bw_to_chan_width(sta);
  432. changed |= IEEE80211_RC_BW_CHANGED;
  433. sta_opmode.changed |= STA_OPMODE_MAX_BW_CHANGED;
  434. }
  435. if (sta_opmode.changed)
  436. cfg80211_sta_opmode_change_notify(sdata->dev, sta->addr,
  437. &sta_opmode, GFP_KERNEL);
  438. return changed;
  439. }
  440. void ieee80211_process_mu_groups(struct ieee80211_sub_if_data *sdata,
  441. struct ieee80211_mgmt *mgmt)
  442. {
  443. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  444. if (!sdata->vif.mu_mimo_owner)
  445. return;
  446. if (!memcmp(mgmt->u.action.u.vht_group_notif.position,
  447. bss_conf->mu_group.position, WLAN_USER_POSITION_LEN) &&
  448. !memcmp(mgmt->u.action.u.vht_group_notif.membership,
  449. bss_conf->mu_group.membership, WLAN_MEMBERSHIP_LEN))
  450. return;
  451. memcpy(bss_conf->mu_group.membership,
  452. mgmt->u.action.u.vht_group_notif.membership,
  453. WLAN_MEMBERSHIP_LEN);
  454. memcpy(bss_conf->mu_group.position,
  455. mgmt->u.action.u.vht_group_notif.position,
  456. WLAN_USER_POSITION_LEN);
  457. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
  458. }
  459. void ieee80211_update_mu_groups(struct ieee80211_vif *vif,
  460. const u8 *membership, const u8 *position)
  461. {
  462. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  463. if (WARN_ON_ONCE(!vif->mu_mimo_owner))
  464. return;
  465. memcpy(bss_conf->mu_group.membership, membership, WLAN_MEMBERSHIP_LEN);
  466. memcpy(bss_conf->mu_group.position, position, WLAN_USER_POSITION_LEN);
  467. }
  468. EXPORT_SYMBOL_GPL(ieee80211_update_mu_groups);
  469. void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  470. struct sta_info *sta, u8 opmode,
  471. enum nl80211_band band)
  472. {
  473. struct ieee80211_local *local = sdata->local;
  474. struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
  475. u32 changed = __ieee80211_vht_handle_opmode(sdata, sta, opmode, band);
  476. if (changed > 0) {
  477. ieee80211_recalc_min_chandef(sdata);
  478. rate_control_rate_update(local, sband, sta, changed);
  479. }
  480. }
  481. void ieee80211_get_vht_mask_from_cap(__le16 vht_cap,
  482. u16 vht_mask[NL80211_VHT_NSS_MAX])
  483. {
  484. int i;
  485. u16 mask, cap = le16_to_cpu(vht_cap);
  486. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  487. mask = (cap >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  488. switch (mask) {
  489. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  490. vht_mask[i] = 0x00FF;
  491. break;
  492. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  493. vht_mask[i] = 0x01FF;
  494. break;
  495. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  496. vht_mask[i] = 0x03FF;
  497. break;
  498. case IEEE80211_VHT_MCS_NOT_SUPPORTED:
  499. default:
  500. vht_mask[i] = 0;
  501. break;
  502. }
  503. }
  504. }