vht.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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_RXLDPC |
  146. IEEE80211_VHT_CAP_VHT_TXOP_PS |
  147. IEEE80211_VHT_CAP_HTC_VHT |
  148. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  149. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB |
  150. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB |
  151. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  152. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  153. vht_cap->cap |= min_t(u32, cap_info & IEEE80211_VHT_CAP_MAX_MPDU_MASK,
  154. own_cap.cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK);
  155. /* and some based on our own capabilities */
  156. switch (own_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  157. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  158. vht_cap->cap |= cap_info &
  159. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  160. break;
  161. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  162. vht_cap->cap |= cap_info &
  163. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  164. break;
  165. default:
  166. /* nothing */
  167. break;
  168. }
  169. /* symmetric capabilities */
  170. vht_cap->cap |= cap_info & own_cap.cap &
  171. (IEEE80211_VHT_CAP_SHORT_GI_80 |
  172. IEEE80211_VHT_CAP_SHORT_GI_160);
  173. /* remaining ones */
  174. if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
  175. vht_cap->cap |= cap_info &
  176. (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  177. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
  178. if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
  179. vht_cap->cap |= cap_info &
  180. (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  181. IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
  182. if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
  183. vht_cap->cap |= cap_info &
  184. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  185. if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
  186. vht_cap->cap |= cap_info &
  187. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
  188. if (own_cap.cap & IEEE80211_VHT_CAP_TXSTBC)
  189. vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_RXSTBC_MASK;
  190. if (own_cap.cap & IEEE80211_VHT_CAP_RXSTBC_MASK)
  191. vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_TXSTBC;
  192. /* Copy peer MCS info, the driver might need them. */
  193. memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
  194. sizeof(struct ieee80211_vht_mcs_info));
  195. /* but also restrict MCSes */
  196. for (i = 0; i < 8; i++) {
  197. u16 own_rx, own_tx, peer_rx, peer_tx;
  198. own_rx = le16_to_cpu(own_cap.vht_mcs.rx_mcs_map);
  199. own_rx = (own_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  200. own_tx = le16_to_cpu(own_cap.vht_mcs.tx_mcs_map);
  201. own_tx = (own_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  202. peer_rx = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  203. peer_rx = (peer_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  204. peer_tx = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  205. peer_tx = (peer_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  206. if (peer_tx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  207. if (own_rx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  208. peer_tx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  209. else if (own_rx < peer_tx)
  210. peer_tx = own_rx;
  211. }
  212. if (peer_rx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  213. if (own_tx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
  214. peer_rx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  215. else if (own_tx < peer_rx)
  216. peer_rx = own_tx;
  217. }
  218. vht_cap->vht_mcs.rx_mcs_map &=
  219. ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
  220. vht_cap->vht_mcs.rx_mcs_map |= cpu_to_le16(peer_rx << i * 2);
  221. vht_cap->vht_mcs.tx_mcs_map &=
  222. ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
  223. vht_cap->vht_mcs.tx_mcs_map |= cpu_to_le16(peer_tx << i * 2);
  224. }
  225. /*
  226. * This is a workaround for VHT-enabled STAs which break the spec
  227. * and have the VHT-MCS Rx map filled in with value 3 for all eight
  228. * spacial streams, an example is AR9462.
  229. *
  230. * As per spec, in section 22.1.1 Introduction to the VHT PHY
  231. * A VHT STA shall support at least single spactial stream VHT-MCSs
  232. * 0 to 7 (transmit and receive) in all supported channel widths.
  233. */
  234. if (vht_cap->vht_mcs.rx_mcs_map == cpu_to_le16(0xFFFF)) {
  235. vht_cap->vht_supported = false;
  236. sdata_info(sdata, "Ignoring VHT IE from %pM due to invalid rx_mcs_map\n",
  237. sta->addr);
  238. return;
  239. }
  240. /* finally set up the bandwidth */
  241. switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  242. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  243. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  244. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  245. break;
  246. default:
  247. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  248. }
  249. sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta);
  250. /* If HT IE reported 3839 bytes only, stay with that size. */
  251. if (sta->sta.max_amsdu_len == IEEE80211_MAX_MPDU_LEN_HT_3839)
  252. return;
  253. switch (vht_cap->cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK) {
  254. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
  255. sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454;
  256. break;
  257. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
  258. sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991;
  259. break;
  260. case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
  261. default:
  262. sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895;
  263. break;
  264. }
  265. }
  266. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cap_rx_bw(struct sta_info *sta)
  267. {
  268. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  269. u32 cap_width;
  270. if (!vht_cap->vht_supported)
  271. return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  272. IEEE80211_STA_RX_BW_40 :
  273. IEEE80211_STA_RX_BW_20;
  274. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  275. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
  276. cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  277. return IEEE80211_STA_RX_BW_160;
  278. return IEEE80211_STA_RX_BW_80;
  279. }
  280. enum nl80211_chan_width ieee80211_sta_cap_chan_bw(struct sta_info *sta)
  281. {
  282. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  283. u32 cap_width;
  284. if (!vht_cap->vht_supported) {
  285. if (!sta->sta.ht_cap.ht_supported)
  286. return NL80211_CHAN_WIDTH_20_NOHT;
  287. return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  288. NL80211_CHAN_WIDTH_40 : NL80211_CHAN_WIDTH_20;
  289. }
  290. cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  291. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  292. return NL80211_CHAN_WIDTH_160;
  293. else if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  294. return NL80211_CHAN_WIDTH_80P80;
  295. return NL80211_CHAN_WIDTH_80;
  296. }
  297. enum nl80211_chan_width
  298. ieee80211_sta_rx_bw_to_chan_width(struct sta_info *sta)
  299. {
  300. enum ieee80211_sta_rx_bandwidth cur_bw = sta->sta.bandwidth;
  301. struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
  302. u32 cap_width;
  303. switch (cur_bw) {
  304. case IEEE80211_STA_RX_BW_20:
  305. if (!sta->sta.ht_cap.ht_supported)
  306. return NL80211_CHAN_WIDTH_20_NOHT;
  307. else
  308. return NL80211_CHAN_WIDTH_20;
  309. case IEEE80211_STA_RX_BW_40:
  310. return NL80211_CHAN_WIDTH_40;
  311. case IEEE80211_STA_RX_BW_80:
  312. return NL80211_CHAN_WIDTH_80;
  313. case IEEE80211_STA_RX_BW_160:
  314. cap_width =
  315. vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  316. if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
  317. return NL80211_CHAN_WIDTH_160;
  318. return NL80211_CHAN_WIDTH_80P80;
  319. default:
  320. return NL80211_CHAN_WIDTH_20;
  321. }
  322. }
  323. enum ieee80211_sta_rx_bandwidth
  324. ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width)
  325. {
  326. switch (width) {
  327. case NL80211_CHAN_WIDTH_20_NOHT:
  328. case NL80211_CHAN_WIDTH_20:
  329. return IEEE80211_STA_RX_BW_20;
  330. case NL80211_CHAN_WIDTH_40:
  331. return IEEE80211_STA_RX_BW_40;
  332. case NL80211_CHAN_WIDTH_80:
  333. return IEEE80211_STA_RX_BW_80;
  334. case NL80211_CHAN_WIDTH_160:
  335. case NL80211_CHAN_WIDTH_80P80:
  336. return IEEE80211_STA_RX_BW_160;
  337. default:
  338. WARN_ON_ONCE(1);
  339. return IEEE80211_STA_RX_BW_20;
  340. }
  341. }
  342. enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta)
  343. {
  344. struct ieee80211_sub_if_data *sdata = sta->sdata;
  345. enum ieee80211_sta_rx_bandwidth bw;
  346. enum nl80211_chan_width bss_width = sdata->vif.bss_conf.chandef.width;
  347. bw = ieee80211_sta_cap_rx_bw(sta);
  348. bw = min(bw, sta->cur_max_bandwidth);
  349. /* Don't consider AP's bandwidth for TDLS peers, section 11.23.1 of
  350. * IEEE80211-2016 specification makes higher bandwidth operation
  351. * possible on the TDLS link if the peers have wider bandwidth
  352. * capability.
  353. *
  354. * However, in this case, and only if the TDLS peer is authorized,
  355. * limit to the tdls_chandef so that the configuration here isn't
  356. * wider than what's actually requested on the channel context.
  357. */
  358. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  359. test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW) &&
  360. test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
  361. sta->tdls_chandef.chan)
  362. bw = min(bw, ieee80211_chan_width_to_rx_bw(sta->tdls_chandef.width));
  363. else
  364. bw = min(bw, ieee80211_chan_width_to_rx_bw(bss_width));
  365. return bw;
  366. }
  367. void ieee80211_sta_set_rx_nss(struct sta_info *sta)
  368. {
  369. u8 ht_rx_nss = 0, vht_rx_nss = 0;
  370. /* if we received a notification already don't overwrite it */
  371. if (sta->sta.rx_nss)
  372. return;
  373. if (sta->sta.ht_cap.ht_supported) {
  374. if (sta->sta.ht_cap.mcs.rx_mask[0])
  375. ht_rx_nss++;
  376. if (sta->sta.ht_cap.mcs.rx_mask[1])
  377. ht_rx_nss++;
  378. if (sta->sta.ht_cap.mcs.rx_mask[2])
  379. ht_rx_nss++;
  380. if (sta->sta.ht_cap.mcs.rx_mask[3])
  381. ht_rx_nss++;
  382. /* FIXME: consider rx_highest? */
  383. }
  384. if (sta->sta.vht_cap.vht_supported) {
  385. int i;
  386. u16 rx_mcs_map;
  387. rx_mcs_map = le16_to_cpu(sta->sta.vht_cap.vht_mcs.rx_mcs_map);
  388. for (i = 7; i >= 0; i--) {
  389. u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
  390. if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  391. vht_rx_nss = i + 1;
  392. break;
  393. }
  394. }
  395. /* FIXME: consider rx_highest? */
  396. }
  397. ht_rx_nss = max(ht_rx_nss, vht_rx_nss);
  398. sta->sta.rx_nss = max_t(u8, 1, ht_rx_nss);
  399. }
  400. u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  401. struct sta_info *sta, u8 opmode,
  402. enum nl80211_band band)
  403. {
  404. enum ieee80211_sta_rx_bandwidth new_bw;
  405. struct sta_opmode_info sta_opmode = {};
  406. u32 changed = 0;
  407. u8 nss;
  408. /* ignore - no support for BF yet */
  409. if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)
  410. return 0;
  411. nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  412. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  413. nss += 1;
  414. if (sta->sta.rx_nss != nss) {
  415. sta->sta.rx_nss = nss;
  416. sta_opmode.rx_nss = nss;
  417. changed |= IEEE80211_RC_NSS_CHANGED;
  418. sta_opmode.changed |= STA_OPMODE_N_SS_CHANGED;
  419. }
  420. switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) {
  421. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ:
  422. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20;
  423. break;
  424. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ:
  425. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40;
  426. break;
  427. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ:
  428. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
  429. break;
  430. case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ:
  431. sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
  432. break;
  433. }
  434. new_bw = ieee80211_sta_cur_vht_bw(sta);
  435. if (new_bw != sta->sta.bandwidth) {
  436. sta->sta.bandwidth = new_bw;
  437. sta_opmode.bw = ieee80211_sta_rx_bw_to_chan_width(sta);
  438. changed |= IEEE80211_RC_BW_CHANGED;
  439. sta_opmode.changed |= STA_OPMODE_MAX_BW_CHANGED;
  440. }
  441. if (sta_opmode.changed)
  442. cfg80211_sta_opmode_change_notify(sdata->dev, sta->addr,
  443. &sta_opmode, GFP_KERNEL);
  444. return changed;
  445. }
  446. void ieee80211_process_mu_groups(struct ieee80211_sub_if_data *sdata,
  447. struct ieee80211_mgmt *mgmt)
  448. {
  449. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  450. if (!sdata->vif.mu_mimo_owner)
  451. return;
  452. if (!memcmp(mgmt->u.action.u.vht_group_notif.position,
  453. bss_conf->mu_group.position, WLAN_USER_POSITION_LEN) &&
  454. !memcmp(mgmt->u.action.u.vht_group_notif.membership,
  455. bss_conf->mu_group.membership, WLAN_MEMBERSHIP_LEN))
  456. return;
  457. memcpy(bss_conf->mu_group.membership,
  458. mgmt->u.action.u.vht_group_notif.membership,
  459. WLAN_MEMBERSHIP_LEN);
  460. memcpy(bss_conf->mu_group.position,
  461. mgmt->u.action.u.vht_group_notif.position,
  462. WLAN_USER_POSITION_LEN);
  463. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
  464. }
  465. void ieee80211_update_mu_groups(struct ieee80211_vif *vif,
  466. const u8 *membership, const u8 *position)
  467. {
  468. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  469. if (WARN_ON_ONCE(!vif->mu_mimo_owner))
  470. return;
  471. memcpy(bss_conf->mu_group.membership, membership, WLAN_MEMBERSHIP_LEN);
  472. memcpy(bss_conf->mu_group.position, position, WLAN_USER_POSITION_LEN);
  473. }
  474. EXPORT_SYMBOL_GPL(ieee80211_update_mu_groups);
  475. void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
  476. struct sta_info *sta, u8 opmode,
  477. enum nl80211_band band)
  478. {
  479. struct ieee80211_local *local = sdata->local;
  480. struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
  481. u32 changed = __ieee80211_vht_handle_opmode(sdata, sta, opmode, band);
  482. if (changed > 0) {
  483. ieee80211_recalc_min_chandef(sdata);
  484. rate_control_rate_update(local, sband, sta, changed);
  485. }
  486. }
  487. void ieee80211_get_vht_mask_from_cap(__le16 vht_cap,
  488. u16 vht_mask[NL80211_VHT_NSS_MAX])
  489. {
  490. int i;
  491. u16 mask, cap = le16_to_cpu(vht_cap);
  492. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  493. mask = (cap >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
  494. switch (mask) {
  495. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  496. vht_mask[i] = 0x00FF;
  497. break;
  498. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  499. vht_mask[i] = 0x01FF;
  500. break;
  501. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  502. vht_mask[i] = 0x03FF;
  503. break;
  504. case IEEE80211_VHT_MCS_NOT_SUPPORTED:
  505. default:
  506. vht_mask[i] = 0;
  507. break;
  508. }
  509. }
  510. }