vht.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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 ieee80211_sta_rx_bandwidth
  299. ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width)
  300. {
  301. switch (width) {
  302. case NL80211_CHAN_WIDTH_20_NOHT:
  303. case NL80211_CHAN_WIDTH_20:
  304. return IEEE80211_STA_RX_BW_20;
  305. case NL80211_CHAN_WIDTH_40:
  306. return IEEE80211_STA_RX_BW_40;
  307. case NL80211_CHAN_WIDTH_80:
  308. return IEEE80211_STA_RX_BW_80;
  309. case NL80211_CHAN_WIDTH_160:
  310. case NL80211_CHAN_WIDTH_80P80:
  311. return IEEE80211_STA_RX_BW_160;
  312. default:
  313. WARN_ON_ONCE(1);
  314. return IEEE80211_STA_RX_BW_20;
  315. }
  316. }
  317. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta)
  318. {
  319. struct ieee80211_sub_if_data *sdata = sta->sdata;
  320. enum ieee80211_sta_rx_bandwidth bw;
  321. enum nl80211_chan_width bss_width = sdata->vif.bss_conf.chandef.width;
  322. bw = ieee80211_sta_cap_rx_bw(sta);
  323. bw = min(bw, sta->cur_max_bandwidth);
  324. bw = min(bw, ieee80211_chan_width_to_rx_bw(bss_width));
  325. return bw;
  326. }
  327. void ieee80211_sta_set_rx_nss(struct sta_info *sta)
  328. {
  329. u8 ht_rx_nss = 0, vht_rx_nss = 0;
  330. /* if we received a notification already don't overwrite it */
  331. if (sta->sta.rx_nss)
  332. return;
  333. if (sta->sta.ht_cap.ht_supported) {
  334. if (sta->sta.ht_cap.mcs.rx_mask[0])
  335. ht_rx_nss++;
  336. if (sta->sta.ht_cap.mcs.rx_mask[1])
  337. ht_rx_nss++;
  338. if (sta->sta.ht_cap.mcs.rx_mask[2])
  339. ht_rx_nss++;
  340. if (sta->sta.ht_cap.mcs.rx_mask[3])
  341. ht_rx_nss++;
  342. /* FIXME: consider rx_highest? */
  343. }
  344. if (sta->sta.vht_cap.vht_supported) {
  345. int i;
  346. u16 rx_mcs_map;
  347. rx_mcs_map = le16_to_cpu(sta->sta.vht_cap.vht_mcs.rx_mcs_map);
  348. for (i = 7; i >= 0; i--) {
  349. u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
  350. if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  351. vht_rx_nss = i + 1;
  352. break;
  353. }
  354. }
  355. /* FIXME: consider rx_highest? */
  356. }
  357. ht_rx_nss = max(ht_rx_nss, vht_rx_nss);
  358. sta->sta.rx_nss = max_t(u8, 1, ht_rx_nss);
  359. }
  360. u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  361. struct sta_info *sta, u8 opmode,
  362. enum nl80211_band band)
  363. {
  364. struct ieee80211_local *local = sdata->local;
  365. struct ieee80211_supported_band *sband;
  366. enum ieee80211_sta_rx_bandwidth new_bw;
  367. u32 changed = 0;
  368. u8 nss;
  369. sband = local->hw.wiphy->bands[band];
  370. /* ignore - no support for BF yet */
  371. if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)
  372. return 0;
  373. nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  374. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  375. nss += 1;
  376. if (sta->sta.rx_nss != nss) {
  377. sta->sta.rx_nss = nss;
  378. changed |= IEEE80211_RC_NSS_CHANGED;
  379. }
  380. switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) {
  381. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ:
  382. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20;
  383. break;
  384. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ:
  385. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40;
  386. break;
  387. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ:
  388. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  389. break;
  390. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ:
  391. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  392. break;
  393. }
  394. new_bw = ieee80211_sta_cur_vht_bw(sta);
  395. if (new_bw != sta->sta.bandwidth) {
  396. sta->sta.bandwidth = new_bw;
  397. changed |= IEEE80211_RC_BW_CHANGED;
  398. }
  399. return changed;
  400. }
  401. void ieee80211_process_mu_groups(struct ieee80211_sub_if_data *sdata,
  402. struct ieee80211_mgmt *mgmt)
  403. {
  404. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  405. if (!sdata->vif.mu_mimo_owner)
  406. return;
  407. if (!memcmp(mgmt->u.action.u.vht_group_notif.position,
  408. bss_conf->mu_group.position, WLAN_USER_POSITION_LEN) &&
  409. !memcmp(mgmt->u.action.u.vht_group_notif.membership,
  410. bss_conf->mu_group.membership, WLAN_MEMBERSHIP_LEN))
  411. return;
  412. memcpy(bss_conf->mu_group.membership,
  413. mgmt->u.action.u.vht_group_notif.membership,
  414. WLAN_MEMBERSHIP_LEN);
  415. memcpy(bss_conf->mu_group.position,
  416. mgmt->u.action.u.vht_group_notif.position,
  417. WLAN_USER_POSITION_LEN);
  418. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
  419. }
  420. void ieee80211_update_mu_groups(struct ieee80211_vif *vif,
  421. const u8 *membership, const u8 *position)
  422. {
  423. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  424. if (WARN_ON_ONCE(!vif->mu_mimo_owner))
  425. return;
  426. memcpy(bss_conf->mu_group.membership, membership, WLAN_MEMBERSHIP_LEN);
  427. memcpy(bss_conf->mu_group.position, position, WLAN_USER_POSITION_LEN);
  428. }
  429. EXPORT_SYMBOL_GPL(ieee80211_update_mu_groups);
  430. void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  431. struct sta_info *sta, u8 opmode,
  432. enum nl80211_band band)
  433. {
  434. struct ieee80211_local *local = sdata->local;
  435. struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
  436. u32 changed = __ieee80211_vht_handle_opmode(sdata, sta, opmode, band);
  437. if (changed > 0) {
  438. ieee80211_recalc_min_chandef(sdata);
  439. rate_control_rate_update(local, sband, sta, changed);
  440. }
  441. }
  442. void ieee80211_get_vht_mask_from_cap(__le16 vht_cap,
  443. u16 vht_mask[NL80211_VHT_NSS_MAX])
  444. {
  445. int i;
  446. u16 mask, cap = le16_to_cpu(vht_cap);
  447. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  448. mask = (cap >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  449. switch (mask) {
  450. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  451. vht_mask[i] = 0x00FF;
  452. break;
  453. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  454. vht_mask[i] = 0x01FF;
  455. break;
  456. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  457. vht_mask[i] = 0x03FF;
  458. break;
  459. case IEEE80211_VHT_MCS_NOT_SUPPORTED:
  460. default:
  461. vht_mask[i] = 0;
  462. break;
  463. }
  464. }
  465. }