vht.c 18 KB

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