| .. | .. |
|---|
| 5 | 5 | * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net> |
|---|
| 6 | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
|---|
| 7 | 7 | * Copyright 2017 Intel Deutschland GmbH |
|---|
| 8 | + * Copyright (C) 2018-2020 Intel Corporation |
|---|
| 8 | 9 | */ |
|---|
| 9 | 10 | #include <linux/export.h> |
|---|
| 10 | 11 | #include <linux/bitops.h> |
|---|
| 11 | 12 | #include <linux/etherdevice.h> |
|---|
| 12 | 13 | #include <linux/slab.h> |
|---|
| 14 | +#include <linux/ieee80211.h> |
|---|
| 13 | 15 | #include <net/cfg80211.h> |
|---|
| 14 | 16 | #include <net/ip.h> |
|---|
| 15 | 17 | #include <net/dsfield.h> |
|---|
| 16 | 18 | #include <linux/if_vlan.h> |
|---|
| 17 | 19 | #include <linux/mpls.h> |
|---|
| 18 | 20 | #include <linux/gcd.h> |
|---|
| 21 | +#include <linux/bitfield.h> |
|---|
| 22 | +#include <linux/nospec.h> |
|---|
| 19 | 23 | #include "core.h" |
|---|
| 20 | 24 | #include "rdev-ops.h" |
|---|
| 21 | 25 | |
|---|
| .. | .. |
|---|
| 68 | 72 | } |
|---|
| 69 | 73 | EXPORT_SYMBOL(ieee80211_mandatory_rates); |
|---|
| 70 | 74 | |
|---|
| 71 | | -int ieee80211_channel_to_frequency(int chan, enum nl80211_band band) |
|---|
| 75 | +u32 ieee80211_channel_to_freq_khz(int chan, enum nl80211_band band) |
|---|
| 72 | 76 | { |
|---|
| 73 | 77 | /* see 802.11 17.3.8.3.2 and Annex J |
|---|
| 74 | 78 | * there are overlapping channel numbers in 5GHz and 2GHz bands */ |
|---|
| .. | .. |
|---|
| 77 | 81 | switch (band) { |
|---|
| 78 | 82 | case NL80211_BAND_2GHZ: |
|---|
| 79 | 83 | if (chan == 14) |
|---|
| 80 | | - return 2484; |
|---|
| 84 | + return MHZ_TO_KHZ(2484); |
|---|
| 81 | 85 | else if (chan < 14) |
|---|
| 82 | | - return 2407 + chan * 5; |
|---|
| 86 | + return MHZ_TO_KHZ(2407 + chan * 5); |
|---|
| 83 | 87 | break; |
|---|
| 84 | 88 | case NL80211_BAND_5GHZ: |
|---|
| 85 | 89 | if (chan >= 182 && chan <= 196) |
|---|
| 86 | | - return 4000 + chan * 5; |
|---|
| 90 | + return MHZ_TO_KHZ(4000 + chan * 5); |
|---|
| 87 | 91 | else |
|---|
| 88 | | - return 5000 + chan * 5; |
|---|
| 92 | + return MHZ_TO_KHZ(5000 + chan * 5); |
|---|
| 93 | + break; |
|---|
| 94 | + case NL80211_BAND_6GHZ: |
|---|
| 95 | + /* see 802.11ax D6.1 27.3.23.2 */ |
|---|
| 96 | + if (chan == 2) |
|---|
| 97 | + return MHZ_TO_KHZ(5935); |
|---|
| 98 | + if (chan <= 233) |
|---|
| 99 | + return MHZ_TO_KHZ(5950 + chan * 5); |
|---|
| 89 | 100 | break; |
|---|
| 90 | 101 | case NL80211_BAND_60GHZ: |
|---|
| 91 | | - if (chan < 5) |
|---|
| 92 | | - return 56160 + chan * 2160; |
|---|
| 102 | + if (chan < 7) |
|---|
| 103 | + return MHZ_TO_KHZ(56160 + chan * 2160); |
|---|
| 93 | 104 | break; |
|---|
| 105 | + case NL80211_BAND_S1GHZ: |
|---|
| 106 | + return 902000 + chan * 500; |
|---|
| 94 | 107 | default: |
|---|
| 95 | 108 | ; |
|---|
| 96 | 109 | } |
|---|
| 97 | 110 | return 0; /* not supported */ |
|---|
| 98 | 111 | } |
|---|
| 99 | | -EXPORT_SYMBOL(ieee80211_channel_to_frequency); |
|---|
| 112 | +EXPORT_SYMBOL(ieee80211_channel_to_freq_khz); |
|---|
| 100 | 113 | |
|---|
| 101 | | -int ieee80211_frequency_to_channel(int freq) |
|---|
| 114 | +enum nl80211_chan_width |
|---|
| 115 | +ieee80211_s1g_channel_width(const struct ieee80211_channel *chan) |
|---|
| 102 | 116 | { |
|---|
| 117 | + if (WARN_ON(!chan || chan->band != NL80211_BAND_S1GHZ)) |
|---|
| 118 | + return NL80211_CHAN_WIDTH_20_NOHT; |
|---|
| 119 | + |
|---|
| 120 | + /*S1G defines a single allowed channel width per channel. |
|---|
| 121 | + * Extract that width here. |
|---|
| 122 | + */ |
|---|
| 123 | + if (chan->flags & IEEE80211_CHAN_1MHZ) |
|---|
| 124 | + return NL80211_CHAN_WIDTH_1; |
|---|
| 125 | + else if (chan->flags & IEEE80211_CHAN_2MHZ) |
|---|
| 126 | + return NL80211_CHAN_WIDTH_2; |
|---|
| 127 | + else if (chan->flags & IEEE80211_CHAN_4MHZ) |
|---|
| 128 | + return NL80211_CHAN_WIDTH_4; |
|---|
| 129 | + else if (chan->flags & IEEE80211_CHAN_8MHZ) |
|---|
| 130 | + return NL80211_CHAN_WIDTH_8; |
|---|
| 131 | + else if (chan->flags & IEEE80211_CHAN_16MHZ) |
|---|
| 132 | + return NL80211_CHAN_WIDTH_16; |
|---|
| 133 | + |
|---|
| 134 | + pr_err("unknown channel width for channel at %dKHz?\n", |
|---|
| 135 | + ieee80211_channel_to_khz(chan)); |
|---|
| 136 | + |
|---|
| 137 | + return NL80211_CHAN_WIDTH_1; |
|---|
| 138 | +} |
|---|
| 139 | +EXPORT_SYMBOL(ieee80211_s1g_channel_width); |
|---|
| 140 | + |
|---|
| 141 | +int ieee80211_freq_khz_to_channel(u32 freq) |
|---|
| 142 | +{ |
|---|
| 143 | + /* TODO: just handle MHz for now */ |
|---|
| 144 | + freq = KHZ_TO_MHZ(freq); |
|---|
| 145 | + |
|---|
| 103 | 146 | /* see 802.11 17.3.8.3.2 and Annex J */ |
|---|
| 104 | 147 | if (freq == 2484) |
|---|
| 105 | 148 | return 14; |
|---|
| .. | .. |
|---|
| 107 | 150 | return (freq - 2407) / 5; |
|---|
| 108 | 151 | else if (freq >= 4910 && freq <= 4980) |
|---|
| 109 | 152 | return (freq - 4000) / 5; |
|---|
| 110 | | - else if (freq <= 45000) /* DMG band lower limit */ |
|---|
| 153 | + else if (freq < 5925) |
|---|
| 111 | 154 | return (freq - 5000) / 5; |
|---|
| 112 | | - else if (freq >= 58320 && freq <= 64800) |
|---|
| 155 | + else if (freq == 5935) |
|---|
| 156 | + return 2; |
|---|
| 157 | + else if (freq <= 45000) /* DMG band lower limit */ |
|---|
| 158 | + /* see 802.11ax D6.1 27.3.22.2 */ |
|---|
| 159 | + return (freq - 5950) / 5; |
|---|
| 160 | + else if (freq >= 58320 && freq <= 70200) |
|---|
| 113 | 161 | return (freq - 56160) / 2160; |
|---|
| 114 | 162 | else |
|---|
| 115 | 163 | return 0; |
|---|
| 116 | 164 | } |
|---|
| 117 | | -EXPORT_SYMBOL(ieee80211_frequency_to_channel); |
|---|
| 165 | +EXPORT_SYMBOL(ieee80211_freq_khz_to_channel); |
|---|
| 118 | 166 | |
|---|
| 119 | | -struct ieee80211_channel *ieee80211_get_channel(struct wiphy *wiphy, int freq) |
|---|
| 167 | +struct ieee80211_channel *ieee80211_get_channel_khz(struct wiphy *wiphy, |
|---|
| 168 | + u32 freq) |
|---|
| 120 | 169 | { |
|---|
| 121 | 170 | enum nl80211_band band; |
|---|
| 122 | 171 | struct ieee80211_supported_band *sband; |
|---|
| .. | .. |
|---|
| 129 | 178 | continue; |
|---|
| 130 | 179 | |
|---|
| 131 | 180 | for (i = 0; i < sband->n_channels; i++) { |
|---|
| 132 | | - if (sband->channels[i].center_freq == freq) |
|---|
| 133 | | - return &sband->channels[i]; |
|---|
| 181 | + struct ieee80211_channel *chan = &sband->channels[i]; |
|---|
| 182 | + |
|---|
| 183 | + if (ieee80211_channel_to_khz(chan) == freq) |
|---|
| 184 | + return chan; |
|---|
| 134 | 185 | } |
|---|
| 135 | 186 | } |
|---|
| 136 | 187 | |
|---|
| 137 | 188 | return NULL; |
|---|
| 138 | 189 | } |
|---|
| 139 | | -EXPORT_SYMBOL(ieee80211_get_channel); |
|---|
| 190 | +EXPORT_SYMBOL(ieee80211_get_channel_khz); |
|---|
| 140 | 191 | |
|---|
| 141 | 192 | static void set_mandatory_flags_band(struct ieee80211_supported_band *sband) |
|---|
| 142 | 193 | { |
|---|
| .. | .. |
|---|
| 144 | 195 | |
|---|
| 145 | 196 | switch (sband->band) { |
|---|
| 146 | 197 | case NL80211_BAND_5GHZ: |
|---|
| 198 | + case NL80211_BAND_6GHZ: |
|---|
| 147 | 199 | want = 3; |
|---|
| 148 | 200 | for (i = 0; i < sband->n_bitrates; i++) { |
|---|
| 149 | 201 | if (sband->bitrates[i].bitrate == 60 || |
|---|
| .. | .. |
|---|
| 175 | 227 | sband->bitrates[i].flags |= |
|---|
| 176 | 228 | IEEE80211_RATE_MANDATORY_G; |
|---|
| 177 | 229 | want--; |
|---|
| 178 | | - /* fall through */ |
|---|
| 230 | + fallthrough; |
|---|
| 179 | 231 | default: |
|---|
| 180 | 232 | sband->bitrates[i].flags |= |
|---|
| 181 | 233 | IEEE80211_RATE_ERP_G; |
|---|
| .. | .. |
|---|
| 188 | 240 | /* check for mandatory HT MCS 1..4 */ |
|---|
| 189 | 241 | WARN_ON(!sband->ht_cap.ht_supported); |
|---|
| 190 | 242 | WARN_ON((sband->ht_cap.mcs.rx_mask[0] & 0x1e) != 0x1e); |
|---|
| 243 | + break; |
|---|
| 244 | + case NL80211_BAND_S1GHZ: |
|---|
| 245 | + /* Figure 9-589bd: 3 means unsupported, so != 3 means at least |
|---|
| 246 | + * mandatory is ok. |
|---|
| 247 | + */ |
|---|
| 248 | + WARN_ON((sband->s1g_cap.nss_mcs[0] & 0x3) == 0x3); |
|---|
| 191 | 249 | break; |
|---|
| 192 | 250 | case NUM_NL80211_BANDS: |
|---|
| 193 | 251 | default: |
|---|
| .. | .. |
|---|
| 241 | 299 | if (pairwise) |
|---|
| 242 | 300 | max_key_idx = 3; |
|---|
| 243 | 301 | else if (wiphy_ext_feature_isset(&rdev->wiphy, |
|---|
| 244 | | - NL80211_EXT_FEATURE_BEACON_PROTECTION)) |
|---|
| 302 | + NL80211_EXT_FEATURE_BEACON_PROTECTION) || |
|---|
| 303 | + wiphy_ext_feature_isset(&rdev->wiphy, |
|---|
| 304 | + NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) |
|---|
| 245 | 305 | max_key_idx = 7; |
|---|
| 246 | 306 | else if (cfg80211_igtk_cipher_supported(rdev)) |
|---|
| 247 | 307 | max_key_idx = 5; |
|---|
| .. | .. |
|---|
| 269 | 329 | |
|---|
| 270 | 330 | switch (params->cipher) { |
|---|
| 271 | 331 | case WLAN_CIPHER_SUITE_TKIP: |
|---|
| 332 | + /* Extended Key ID can only be used with CCMP/GCMP ciphers */ |
|---|
| 333 | + if ((pairwise && key_idx) || |
|---|
| 334 | + params->mode != NL80211_KEY_RX_TX) |
|---|
| 335 | + return -EINVAL; |
|---|
| 336 | + break; |
|---|
| 272 | 337 | case WLAN_CIPHER_SUITE_CCMP: |
|---|
| 273 | 338 | case WLAN_CIPHER_SUITE_CCMP_256: |
|---|
| 274 | 339 | case WLAN_CIPHER_SUITE_GCMP: |
|---|
| 275 | 340 | case WLAN_CIPHER_SUITE_GCMP_256: |
|---|
| 276 | | - /* Disallow pairwise keys with non-zero index unless it's WEP |
|---|
| 277 | | - * or a vendor specific cipher (because current deployments use |
|---|
| 278 | | - * pairwise WEP keys with non-zero indices and for vendor |
|---|
| 279 | | - * specific ciphers this should be validated in the driver or |
|---|
| 280 | | - * hardware level - but 802.11i clearly specifies to use zero) |
|---|
| 341 | + /* IEEE802.11-2016 allows only 0 and - when supporting |
|---|
| 342 | + * Extended Key ID - 1 as index for pairwise keys. |
|---|
| 343 | + * @NL80211_KEY_NO_TX is only allowed for pairwise keys when |
|---|
| 344 | + * the driver supports Extended Key ID. |
|---|
| 345 | + * @NL80211_KEY_SET_TX can't be set when installing and |
|---|
| 346 | + * validating a key. |
|---|
| 281 | 347 | */ |
|---|
| 282 | | - if (pairwise && key_idx) |
|---|
| 348 | + if ((params->mode == NL80211_KEY_NO_TX && !pairwise) || |
|---|
| 349 | + params->mode == NL80211_KEY_SET_TX) |
|---|
| 283 | 350 | return -EINVAL; |
|---|
| 351 | + if (wiphy_ext_feature_isset(&rdev->wiphy, |
|---|
| 352 | + NL80211_EXT_FEATURE_EXT_KEY_ID)) { |
|---|
| 353 | + if (pairwise && (key_idx < 0 || key_idx > 1)) |
|---|
| 354 | + return -EINVAL; |
|---|
| 355 | + } else if (pairwise && key_idx) { |
|---|
| 356 | + return -EINVAL; |
|---|
| 357 | + } |
|---|
| 284 | 358 | break; |
|---|
| 285 | 359 | case WLAN_CIPHER_SUITE_AES_CMAC: |
|---|
| 286 | 360 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
|---|
| .. | .. |
|---|
| 386 | 460 | unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc) |
|---|
| 387 | 461 | { |
|---|
| 388 | 462 | unsigned int hdrlen = 24; |
|---|
| 463 | + |
|---|
| 464 | + if (ieee80211_is_ext(fc)) { |
|---|
| 465 | + hdrlen = 4; |
|---|
| 466 | + goto out; |
|---|
| 467 | + } |
|---|
| 389 | 468 | |
|---|
| 390 | 469 | if (ieee80211_is_data(fc)) { |
|---|
| 391 | 470 | if (ieee80211_has_a4(fc)) |
|---|
| .. | .. |
|---|
| 755 | 834 | { |
|---|
| 756 | 835 | unsigned int dscp; |
|---|
| 757 | 836 | unsigned char vlan_priority; |
|---|
| 837 | + unsigned int ret; |
|---|
| 758 | 838 | |
|---|
| 759 | 839 | /* skb->priority values from 256->263 are magic values to |
|---|
| 760 | 840 | * directly indicate a specific 802.1d priority. This is used |
|---|
| 761 | 841 | * to allow 802.1d priority to be passed directly in from VLAN |
|---|
| 762 | 842 | * tags, etc. |
|---|
| 763 | 843 | */ |
|---|
| 764 | | - if (skb->priority >= 256 && skb->priority <= 263) |
|---|
| 765 | | - return skb->priority - 256; |
|---|
| 844 | + if (skb->priority >= 256 && skb->priority <= 263) { |
|---|
| 845 | + ret = skb->priority - 256; |
|---|
| 846 | + goto out; |
|---|
| 847 | + } |
|---|
| 766 | 848 | |
|---|
| 767 | 849 | if (skb_vlan_tag_present(skb)) { |
|---|
| 768 | 850 | vlan_priority = (skb_vlan_tag_get(skb) & VLAN_PRIO_MASK) |
|---|
| 769 | 851 | >> VLAN_PRIO_SHIFT; |
|---|
| 770 | | - if (vlan_priority > 0) |
|---|
| 771 | | - return vlan_priority; |
|---|
| 852 | + if (vlan_priority > 0) { |
|---|
| 853 | + ret = vlan_priority; |
|---|
| 854 | + goto out; |
|---|
| 855 | + } |
|---|
| 772 | 856 | } |
|---|
| 773 | 857 | |
|---|
| 774 | 858 | switch (skb->protocol) { |
|---|
| .. | .. |
|---|
| 787 | 871 | if (!mpls) |
|---|
| 788 | 872 | return 0; |
|---|
| 789 | 873 | |
|---|
| 790 | | - return (ntohl(mpls->entry) & MPLS_LS_TC_MASK) |
|---|
| 874 | + ret = (ntohl(mpls->entry) & MPLS_LS_TC_MASK) |
|---|
| 791 | 875 | >> MPLS_LS_TC_SHIFT; |
|---|
| 876 | + goto out; |
|---|
| 792 | 877 | } |
|---|
| 793 | 878 | case htons(ETH_P_80221): |
|---|
| 794 | 879 | /* 802.21 is always network control traffic */ |
|---|
| .. | .. |
|---|
| 801 | 886 | unsigned int i, tmp_dscp = dscp >> 2; |
|---|
| 802 | 887 | |
|---|
| 803 | 888 | for (i = 0; i < qos_map->num_des; i++) { |
|---|
| 804 | | - if (tmp_dscp == qos_map->dscp_exception[i].dscp) |
|---|
| 805 | | - return qos_map->dscp_exception[i].up; |
|---|
| 889 | + if (tmp_dscp == qos_map->dscp_exception[i].dscp) { |
|---|
| 890 | + ret = qos_map->dscp_exception[i].up; |
|---|
| 891 | + goto out; |
|---|
| 892 | + } |
|---|
| 806 | 893 | } |
|---|
| 807 | 894 | |
|---|
| 808 | 895 | for (i = 0; i < 8; i++) { |
|---|
| 809 | 896 | if (tmp_dscp >= qos_map->up[i].low && |
|---|
| 810 | | - tmp_dscp <= qos_map->up[i].high) |
|---|
| 811 | | - return i; |
|---|
| 897 | + tmp_dscp <= qos_map->up[i].high) { |
|---|
| 898 | + ret = i; |
|---|
| 899 | + goto out; |
|---|
| 900 | + } |
|---|
| 812 | 901 | } |
|---|
| 813 | 902 | } |
|---|
| 814 | 903 | |
|---|
| 815 | | - return dscp >> 5; |
|---|
| 904 | + ret = dscp >> 5; |
|---|
| 905 | +out: |
|---|
| 906 | + return array_index_nospec(ret, IEEE80211_NUM_TIDS); |
|---|
| 816 | 907 | } |
|---|
| 817 | 908 | EXPORT_SYMBOL(cfg80211_classify8021d); |
|---|
| 818 | 909 | |
|---|
| 819 | | -const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie) |
|---|
| 910 | +const struct element *ieee80211_bss_get_elem(struct cfg80211_bss *bss, u8 id) |
|---|
| 820 | 911 | { |
|---|
| 821 | 912 | const struct cfg80211_bss_ies *ies; |
|---|
| 822 | 913 | |
|---|
| .. | .. |
|---|
| 824 | 915 | if (!ies) |
|---|
| 825 | 916 | return NULL; |
|---|
| 826 | 917 | |
|---|
| 827 | | - return cfg80211_find_ie(ie, ies->data, ies->len); |
|---|
| 918 | + return cfg80211_find_elem(id, ies->data, ies->len); |
|---|
| 828 | 919 | } |
|---|
| 829 | | -EXPORT_SYMBOL(ieee80211_bss_get_ie); |
|---|
| 920 | +EXPORT_SYMBOL(ieee80211_bss_get_elem); |
|---|
| 830 | 921 | |
|---|
| 831 | 922 | void cfg80211_upload_connect_keys(struct wireless_dev *wdev) |
|---|
| 832 | 923 | { |
|---|
| .. | .. |
|---|
| 852 | 943 | } |
|---|
| 853 | 944 | } |
|---|
| 854 | 945 | |
|---|
| 855 | | - kzfree(wdev->connect_keys); |
|---|
| 946 | + kfree_sensitive(wdev->connect_keys); |
|---|
| 856 | 947 | wdev->connect_keys = NULL; |
|---|
| 857 | 948 | } |
|---|
| 858 | 949 | |
|---|
| .. | .. |
|---|
| 937 | 1028 | !(rdev->wiphy.interface_modes & (1 << ntype))) |
|---|
| 938 | 1029 | return -EOPNOTSUPP; |
|---|
| 939 | 1030 | |
|---|
| 940 | | - /* if it's part of a bridge, reject changing type to station/ibss */ |
|---|
| 941 | | - if ((dev->priv_flags & IFF_BRIDGE_PORT) && |
|---|
| 942 | | - (ntype == NL80211_IFTYPE_ADHOC || |
|---|
| 943 | | - ntype == NL80211_IFTYPE_STATION || |
|---|
| 944 | | - ntype == NL80211_IFTYPE_P2P_CLIENT)) |
|---|
| 945 | | - return -EBUSY; |
|---|
| 946 | | - |
|---|
| 947 | 1031 | if (ntype != otype) { |
|---|
| 1032 | + /* if it's part of a bridge, reject changing type to station/ibss */ |
|---|
| 1033 | + if (netif_is_bridge_port(dev) && |
|---|
| 1034 | + (ntype == NL80211_IFTYPE_ADHOC || |
|---|
| 1035 | + ntype == NL80211_IFTYPE_STATION || |
|---|
| 1036 | + ntype == NL80211_IFTYPE_P2P_CLIENT)) |
|---|
| 1037 | + return -EBUSY; |
|---|
| 1038 | + |
|---|
| 948 | 1039 | dev->ieee80211_ptr->use_4addr = false; |
|---|
| 949 | 1040 | dev->ieee80211_ptr->mesh_id_up_len = 0; |
|---|
| 950 | 1041 | wdev_lock(dev->ieee80211_ptr); |
|---|
| .. | .. |
|---|
| 993 | 1084 | case NL80211_IFTYPE_STATION: |
|---|
| 994 | 1085 | if (dev->ieee80211_ptr->use_4addr) |
|---|
| 995 | 1086 | break; |
|---|
| 996 | | - /* fall through */ |
|---|
| 1087 | + fallthrough; |
|---|
| 997 | 1088 | case NL80211_IFTYPE_OCB: |
|---|
| 998 | 1089 | case NL80211_IFTYPE_P2P_CLIENT: |
|---|
| 999 | 1090 | case NL80211_IFTYPE_ADHOC: |
|---|
| .. | .. |
|---|
| 1227 | 1318 | |
|---|
| 1228 | 1319 | static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate) |
|---|
| 1229 | 1320 | { |
|---|
| 1230 | | -#define SCALE 2048 |
|---|
| 1231 | | - u16 mcs_divisors[12] = { |
|---|
| 1232 | | - 34133, /* 16.666666... */ |
|---|
| 1233 | | - 17067, /* 8.333333... */ |
|---|
| 1234 | | - 11378, /* 5.555555... */ |
|---|
| 1235 | | - 8533, /* 4.166666... */ |
|---|
| 1236 | | - 5689, /* 2.777777... */ |
|---|
| 1237 | | - 4267, /* 2.083333... */ |
|---|
| 1238 | | - 3923, /* 1.851851... */ |
|---|
| 1239 | | - 3413, /* 1.666666... */ |
|---|
| 1240 | | - 2844, /* 1.388888... */ |
|---|
| 1241 | | - 2560, /* 1.250000... */ |
|---|
| 1242 | | - 2276, /* 1.111111... */ |
|---|
| 1243 | | - 2048, /* 1.000000... */ |
|---|
| 1321 | +#define SCALE 6144 |
|---|
| 1322 | + u32 mcs_divisors[14] = { |
|---|
| 1323 | + 102399, /* 16.666666... */ |
|---|
| 1324 | + 51201, /* 8.333333... */ |
|---|
| 1325 | + 34134, /* 5.555555... */ |
|---|
| 1326 | + 25599, /* 4.166666... */ |
|---|
| 1327 | + 17067, /* 2.777777... */ |
|---|
| 1328 | + 12801, /* 2.083333... */ |
|---|
| 1329 | + 11769, /* 1.851851... */ |
|---|
| 1330 | + 10239, /* 1.666666... */ |
|---|
| 1331 | + 8532, /* 1.388888... */ |
|---|
| 1332 | + 7680, /* 1.250000... */ |
|---|
| 1333 | + 6828, /* 1.111111... */ |
|---|
| 1334 | + 6144, /* 1.000000... */ |
|---|
| 1335 | + 5690, /* 0.926106... */ |
|---|
| 1336 | + 5120, /* 0.833333... */ |
|---|
| 1244 | 1337 | }; |
|---|
| 1245 | 1338 | u32 rates_160M[3] = { 960777777, 907400000, 816666666 }; |
|---|
| 1246 | 1339 | u32 rates_969[3] = { 480388888, 453700000, 408333333 }; |
|---|
| .. | .. |
|---|
| 1252 | 1345 | u64 tmp; |
|---|
| 1253 | 1346 | u32 result; |
|---|
| 1254 | 1347 | |
|---|
| 1255 | | - if (WARN_ON_ONCE(rate->mcs > 11)) |
|---|
| 1348 | + if (WARN_ON_ONCE(rate->mcs > 13)) |
|---|
| 1256 | 1349 | return 0; |
|---|
| 1257 | 1350 | |
|---|
| 1258 | 1351 | if (WARN_ON_ONCE(rate->he_gi > NL80211_RATE_INFO_HE_GI_3_2)) |
|---|
| .. | .. |
|---|
| 1286 | 1379 | else if (rate->bw == RATE_INFO_BW_HE_RU && |
|---|
| 1287 | 1380 | rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26) |
|---|
| 1288 | 1381 | result = rates_26[rate->he_gi]; |
|---|
| 1289 | | - else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n", |
|---|
| 1290 | | - rate->bw, rate->he_ru_alloc)) |
|---|
| 1382 | + else { |
|---|
| 1383 | + WARN(1, "invalid HE MCS: bw:%d, ru:%d\n", |
|---|
| 1384 | + rate->bw, rate->he_ru_alloc); |
|---|
| 1291 | 1385 | return 0; |
|---|
| 1386 | + } |
|---|
| 1292 | 1387 | |
|---|
| 1293 | 1388 | /* now scale to the appropriate MCS */ |
|---|
| 1294 | 1389 | tmp = result; |
|---|
| .. | .. |
|---|
| 1523 | 1618 | case 128 ... 130: |
|---|
| 1524 | 1619 | *band = NL80211_BAND_5GHZ; |
|---|
| 1525 | 1620 | return true; |
|---|
| 1621 | + case 131 ... 135: |
|---|
| 1622 | + *band = NL80211_BAND_6GHZ; |
|---|
| 1623 | + return true; |
|---|
| 1526 | 1624 | case 81: |
|---|
| 1527 | 1625 | case 82: |
|---|
| 1528 | 1626 | case 83: |
|---|
| .. | .. |
|---|
| 1562 | 1660 | } |
|---|
| 1563 | 1661 | |
|---|
| 1564 | 1662 | if (freq == 2484) { |
|---|
| 1565 | | - if (chandef->width > NL80211_CHAN_WIDTH_40) |
|---|
| 1663 | + /* channel 14 is only for IEEE 802.11b */ |
|---|
| 1664 | + if (chandef->width != NL80211_CHAN_WIDTH_20_NOHT) |
|---|
| 1566 | 1665 | return false; |
|---|
| 1567 | 1666 | |
|---|
| 1568 | 1667 | *op_class = 82; /* channel 14 */ |
|---|
| .. | .. |
|---|
| 1654 | 1753 | } |
|---|
| 1655 | 1754 | |
|---|
| 1656 | 1755 | /* 56.16 GHz, channel 1..4 */ |
|---|
| 1657 | | - if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 4) { |
|---|
| 1756 | + if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 6) { |
|---|
| 1658 | 1757 | if (chandef->width >= NL80211_CHAN_WIDTH_40) |
|---|
| 1659 | 1758 | return false; |
|---|
| 1660 | 1759 | |
|---|
| .. | .. |
|---|
| 1980 | 2079 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
|---|
| 1981 | 2080 | EXPORT_SYMBOL(bridge_tunnel_header); |
|---|
| 1982 | 2081 | |
|---|
| 1983 | | -bool cfg80211_iftype_allowed(struct wiphy *wiphy, enum nl80211_iftype iftype, |
|---|
| 1984 | | - bool is_4addr, u8 check_swif) |
|---|
| 1985 | | - |
|---|
| 1986 | | -{ |
|---|
| 1987 | | - bool is_vlan = iftype == NL80211_IFTYPE_AP_VLAN; |
|---|
| 1988 | | - |
|---|
| 1989 | | - switch (check_swif) { |
|---|
| 1990 | | - case 0: |
|---|
| 1991 | | - if (is_vlan && is_4addr) |
|---|
| 1992 | | - return wiphy->flags & WIPHY_FLAG_4ADDR_AP; |
|---|
| 1993 | | - return wiphy->interface_modes & BIT(iftype); |
|---|
| 1994 | | - case 1: |
|---|
| 1995 | | - if (!(wiphy->software_iftypes & BIT(iftype)) && is_vlan) |
|---|
| 1996 | | - return wiphy->flags & WIPHY_FLAG_4ADDR_AP; |
|---|
| 1997 | | - return wiphy->software_iftypes & BIT(iftype); |
|---|
| 1998 | | - default: |
|---|
| 1999 | | - break; |
|---|
| 2000 | | - } |
|---|
| 2001 | | - |
|---|
| 2002 | | - return false; |
|---|
| 2003 | | -} |
|---|
| 2004 | | -EXPORT_SYMBOL(cfg80211_iftype_allowed); |
|---|
| 2005 | | - |
|---|
| 2006 | 2082 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
|---|
| 2007 | 2083 | struct iapp_layer2_update { |
|---|
| 2008 | 2084 | u8 da[ETH_ALEN]; /* broadcast */ |
|---|
| .. | .. |
|---|
| 2047 | 2123 | netif_rx_ni(skb); |
|---|
| 2048 | 2124 | } |
|---|
| 2049 | 2125 | EXPORT_SYMBOL(cfg80211_send_layer2_update); |
|---|
| 2126 | + |
|---|
| 2127 | +int ieee80211_get_vht_max_nss(struct ieee80211_vht_cap *cap, |
|---|
| 2128 | + enum ieee80211_vht_chanwidth bw, |
|---|
| 2129 | + int mcs, bool ext_nss_bw_capable, |
|---|
| 2130 | + unsigned int max_vht_nss) |
|---|
| 2131 | +{ |
|---|
| 2132 | + u16 map = le16_to_cpu(cap->supp_mcs.rx_mcs_map); |
|---|
| 2133 | + int ext_nss_bw; |
|---|
| 2134 | + int supp_width; |
|---|
| 2135 | + int i, mcs_encoding; |
|---|
| 2136 | + |
|---|
| 2137 | + if (map == 0xffff) |
|---|
| 2138 | + return 0; |
|---|
| 2139 | + |
|---|
| 2140 | + if (WARN_ON(mcs > 9 || max_vht_nss > 8)) |
|---|
| 2141 | + return 0; |
|---|
| 2142 | + if (mcs <= 7) |
|---|
| 2143 | + mcs_encoding = 0; |
|---|
| 2144 | + else if (mcs == 8) |
|---|
| 2145 | + mcs_encoding = 1; |
|---|
| 2146 | + else |
|---|
| 2147 | + mcs_encoding = 2; |
|---|
| 2148 | + |
|---|
| 2149 | + if (!max_vht_nss) { |
|---|
| 2150 | + /* find max_vht_nss for the given MCS */ |
|---|
| 2151 | + for (i = 7; i >= 0; i--) { |
|---|
| 2152 | + int supp = (map >> (2 * i)) & 3; |
|---|
| 2153 | + |
|---|
| 2154 | + if (supp == 3) |
|---|
| 2155 | + continue; |
|---|
| 2156 | + |
|---|
| 2157 | + if (supp >= mcs_encoding) { |
|---|
| 2158 | + max_vht_nss = i + 1; |
|---|
| 2159 | + break; |
|---|
| 2160 | + } |
|---|
| 2161 | + } |
|---|
| 2162 | + } |
|---|
| 2163 | + |
|---|
| 2164 | + if (!(cap->supp_mcs.tx_mcs_map & |
|---|
| 2165 | + cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE))) |
|---|
| 2166 | + return max_vht_nss; |
|---|
| 2167 | + |
|---|
| 2168 | + ext_nss_bw = le32_get_bits(cap->vht_cap_info, |
|---|
| 2169 | + IEEE80211_VHT_CAP_EXT_NSS_BW_MASK); |
|---|
| 2170 | + supp_width = le32_get_bits(cap->vht_cap_info, |
|---|
| 2171 | + IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK); |
|---|
| 2172 | + |
|---|
| 2173 | + /* if not capable, treat ext_nss_bw as 0 */ |
|---|
| 2174 | + if (!ext_nss_bw_capable) |
|---|
| 2175 | + ext_nss_bw = 0; |
|---|
| 2176 | + |
|---|
| 2177 | + /* This is invalid */ |
|---|
| 2178 | + if (supp_width == 3) |
|---|
| 2179 | + return 0; |
|---|
| 2180 | + |
|---|
| 2181 | + /* This is an invalid combination so pretend nothing is supported */ |
|---|
| 2182 | + if (supp_width == 2 && (ext_nss_bw == 1 || ext_nss_bw == 2)) |
|---|
| 2183 | + return 0; |
|---|
| 2184 | + |
|---|
| 2185 | + /* |
|---|
| 2186 | + * Cover all the special cases according to IEEE 802.11-2016 |
|---|
| 2187 | + * Table 9-250. All other cases are either factor of 1 or not |
|---|
| 2188 | + * valid/supported. |
|---|
| 2189 | + */ |
|---|
| 2190 | + switch (bw) { |
|---|
| 2191 | + case IEEE80211_VHT_CHANWIDTH_USE_HT: |
|---|
| 2192 | + case IEEE80211_VHT_CHANWIDTH_80MHZ: |
|---|
| 2193 | + if ((supp_width == 1 || supp_width == 2) && |
|---|
| 2194 | + ext_nss_bw == 3) |
|---|
| 2195 | + return 2 * max_vht_nss; |
|---|
| 2196 | + break; |
|---|
| 2197 | + case IEEE80211_VHT_CHANWIDTH_160MHZ: |
|---|
| 2198 | + if (supp_width == 0 && |
|---|
| 2199 | + (ext_nss_bw == 1 || ext_nss_bw == 2)) |
|---|
| 2200 | + return max_vht_nss / 2; |
|---|
| 2201 | + if (supp_width == 0 && |
|---|
| 2202 | + ext_nss_bw == 3) |
|---|
| 2203 | + return (3 * max_vht_nss) / 4; |
|---|
| 2204 | + if (supp_width == 1 && |
|---|
| 2205 | + ext_nss_bw == 3) |
|---|
| 2206 | + return 2 * max_vht_nss; |
|---|
| 2207 | + break; |
|---|
| 2208 | + case IEEE80211_VHT_CHANWIDTH_80P80MHZ: |
|---|
| 2209 | + if (supp_width == 0 && ext_nss_bw == 1) |
|---|
| 2210 | + return 0; /* not possible */ |
|---|
| 2211 | + if (supp_width == 0 && |
|---|
| 2212 | + ext_nss_bw == 2) |
|---|
| 2213 | + return max_vht_nss / 2; |
|---|
| 2214 | + if (supp_width == 0 && |
|---|
| 2215 | + ext_nss_bw == 3) |
|---|
| 2216 | + return (3 * max_vht_nss) / 4; |
|---|
| 2217 | + if (supp_width == 1 && |
|---|
| 2218 | + ext_nss_bw == 0) |
|---|
| 2219 | + return 0; /* not possible */ |
|---|
| 2220 | + if (supp_width == 1 && |
|---|
| 2221 | + ext_nss_bw == 1) |
|---|
| 2222 | + return max_vht_nss / 2; |
|---|
| 2223 | + if (supp_width == 1 && |
|---|
| 2224 | + ext_nss_bw == 2) |
|---|
| 2225 | + return (3 * max_vht_nss) / 4; |
|---|
| 2226 | + break; |
|---|
| 2227 | + } |
|---|
| 2228 | + |
|---|
| 2229 | + /* not covered or invalid combination received */ |
|---|
| 2230 | + return max_vht_nss; |
|---|
| 2231 | +} |
|---|
| 2232 | +EXPORT_SYMBOL(ieee80211_get_vht_max_nss); |
|---|
| 2233 | + |
|---|
| 2234 | +bool cfg80211_iftype_allowed(struct wiphy *wiphy, enum nl80211_iftype iftype, |
|---|
| 2235 | + bool is_4addr, u8 check_swif) |
|---|
| 2236 | + |
|---|
| 2237 | +{ |
|---|
| 2238 | + bool is_vlan = iftype == NL80211_IFTYPE_AP_VLAN; |
|---|
| 2239 | + |
|---|
| 2240 | + switch (check_swif) { |
|---|
| 2241 | + case 0: |
|---|
| 2242 | + if (is_vlan && is_4addr) |
|---|
| 2243 | + return wiphy->flags & WIPHY_FLAG_4ADDR_AP; |
|---|
| 2244 | + return wiphy->interface_modes & BIT(iftype); |
|---|
| 2245 | + case 1: |
|---|
| 2246 | + if (!(wiphy->software_iftypes & BIT(iftype)) && is_vlan) |
|---|
| 2247 | + return wiphy->flags & WIPHY_FLAG_4ADDR_AP; |
|---|
| 2248 | + return wiphy->software_iftypes & BIT(iftype); |
|---|
| 2249 | + default: |
|---|
| 2250 | + break; |
|---|
| 2251 | + } |
|---|
| 2252 | + |
|---|
| 2253 | + return false; |
|---|
| 2254 | +} |
|---|
| 2255 | +EXPORT_SYMBOL(cfg80211_iftype_allowed); |
|---|