1#!/usr/bin/env python3 2# 3# Copyright 2017 - Google 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import itertools 18 19BAND_2G = '2g' 20BAND_5G = '5g' 21WEP = 0 22WPA1 = 1 23WPA2 = 2 24MIXED = 3 25ENT = 4 # get the correct constant 26MAX_WPA_PSK_LENGTH = 64 27MIN_WPA_PSK_LENGTH = 8 28WPA_STRICT_REKEY = 1 29WPA_DEFAULT_CIPHER = 'TKIP' 30WPA2_DEFAULT_CIPER = 'CCMP' 31WPA_GROUP_KEY_ROTATION_TIME = 600 32WPA_STRICT_REKEY_DEFAULT = True 33WPA_STRING = 'wpa' 34WPA2_STRING = 'wpa2' 35WPA_MIXED_STRING = 'wpa/wpa2' 36ENT_STRING = 'ent' 37ENT_KEY_MGMT = 'WPA-EAP' 38IEEE8021X = 1 39WLAN0_STRING = 'wlan0' 40WLAN1_STRING = 'wlan1' 41WLAN2_STRING = 'wlan2' 42WLAN3_STRING = 'wlan3' 43WLAN0_GALE = 'wlan-2400mhz' 44WLAN1_GALE = 'wlan-5000mhz' 45WEP_STRING = 'wep' 46WEP_DEFAULT_KEY = 0 47WEP_HEX_LENGTH = [10, 26, 32, 58] 48AP_DEFAULT_CHANNEL_2G = 6 49AP_DEFAULT_CHANNEL_5G = 36 50AP_DEFAULT_MAX_SSIDS_2G = 8 51AP_DEFAULT_MAX_SSIDS_5G = 8 52AP_SSID_LENGTH_2G = 8 53AP_PASSPHRASE_LENGTH_2G = 10 54AP_SSID_LENGTH_5G = 8 55AP_PASSPHRASE_LENGTH_5G = 10 56INTERFACE_2G_LIST = [WLAN0_STRING, WLAN0_GALE] 57INTERFACE_5G_LIST = [WLAN1_STRING, WLAN1_GALE] 58 59# A mapping of frequency to channel number. This includes some 60# frequencies used outside the US. 61CHANNEL_MAP = { 62 2412: 1, 63 2417: 2, 64 2422: 3, 65 2427: 4, 66 2432: 5, 67 2437: 6, 68 2442: 7, 69 2447: 8, 70 2452: 9, 71 2457: 10, 72 2462: 11, 73 # 12, 13 are only legitimate outside the US. 74 # 2467: 12, 75 # 2472: 13, 76 # 14 is for Japan, DSSS and CCK only. 77 # 2484: 14, 78 # 34 valid in Japan. 79 # 5170: 34, 80 # 36-116 valid in the US, except 38, 42, and 46, which have 81 # mixed international support. 82 5180: 36, 83 5190: 38, 84 5200: 40, 85 5210: 42, 86 5220: 44, 87 5230: 46, 88 5240: 48, 89 # DFS channels. 90 5260: 52, 91 5280: 56, 92 5300: 60, 93 5320: 64, 94 5500: 100, 95 5520: 104, 96 5540: 108, 97 5560: 112, 98 5580: 116, 99 # 120, 124, 128 valid in Europe/Japan. 100 5600: 120, 101 5620: 124, 102 5640: 128, 103 # 132+ valid in US. 104 5660: 132, 105 5680: 136, 106 5700: 140, 107 # 144 is supported by a subset of WiFi chips 108 # (e.g. bcm4354, but not ath9k). 109 5720: 144, 110 # End DFS channels. 111 5745: 149, 112 5755: 151, 113 5765: 153, 114 5775: 155, 115 5795: 159, 116 5785: 157, 117 5805: 161, 118 5825: 165 119} 120FREQUENCY_MAP = {v: k for k, v in CHANNEL_MAP.items()} 121 122MODE_11A = 'a' 123MODE_11B = 'b' 124MODE_11G = 'g' 125MODE_11N_MIXED = 'n-mixed' 126MODE_11N_PURE = 'n-only' 127MODE_11AC_MIXED = 'ac-mixed' 128MODE_11AC_PURE = 'ac-only' 129 130N_CAPABILITY_LDPC = object() 131N_CAPABILITY_HT20 = object() 132N_CAPABILITY_HT40_PLUS = object() 133N_CAPABILITY_HT40_MINUS = object() 134N_CAPABILITY_GREENFIELD = object() 135N_CAPABILITY_SGI20 = object() 136N_CAPABILITY_SGI40 = object() 137N_CAPABILITY_TX_STBC = object() 138N_CAPABILITY_RX_STBC1 = object() 139N_CAPABILITY_RX_STBC12 = object() 140N_CAPABILITY_RX_STBC123 = object() 141N_CAPABILITY_DSSS_CCK_40 = object() 142N_CAPABILITIES_MAPPING = { 143 N_CAPABILITY_LDPC: '[LDPC]', 144 N_CAPABILITY_HT20: '[HT20]', 145 N_CAPABILITY_HT40_PLUS: '[HT40+]', 146 N_CAPABILITY_HT40_MINUS: '[HT40-]', 147 N_CAPABILITY_GREENFIELD: '[GF]', 148 N_CAPABILITY_SGI20: '[SHORT-GI-20]', 149 N_CAPABILITY_SGI40: '[SHORT-GI-40]', 150 N_CAPABILITY_TX_STBC: '[TX-STBC]', 151 N_CAPABILITY_RX_STBC1: '[RX-STBC1]', 152 N_CAPABILITY_RX_STBC12: '[RX-STBC12]', 153 N_CAPABILITY_RX_STBC123: '[RX-STBC123]', 154 N_CAPABILITY_DSSS_CCK_40: '[DSSS_CCK-40]' 155} 156N_CAPABILITY_HT40_MINUS_CHANNELS = object() 157N_CAPABILITY_HT40_PLUS_CHANNELS = object() 158AC_CAPABILITY_VHT160 = object() 159AC_CAPABILITY_VHT160_80PLUS80 = object() 160AC_CAPABILITY_RXLDPC = object() 161AC_CAPABILITY_SHORT_GI_80 = object() 162AC_CAPABILITY_SHORT_GI_160 = object() 163AC_CAPABILITY_TX_STBC_2BY1 = object() 164AC_CAPABILITY_RX_STBC_1 = object() 165AC_CAPABILITY_RX_STBC_12 = object() 166AC_CAPABILITY_RX_STBC_123 = object() 167AC_CAPABILITY_RX_STBC_1234 = object() 168AC_CAPABILITY_SU_BEAMFORMER = object() 169AC_CAPABILITY_SU_BEAMFORMEE = object() 170AC_CAPABILITY_BF_ANTENNA_2 = object() 171AC_CAPABILITY_SOUNDING_DIMENSION_2 = object() 172AC_CAPABILITY_MU_BEAMFORMER = object() 173AC_CAPABILITY_MU_BEAMFORMEE = object() 174AC_CAPABILITY_VHT_TXOP_PS = object() 175AC_CAPABILITY_HTC_VHT = object() 176AC_CAPABILITY_MAX_A_MPDU_LEN_EXP0 = object() 177AC_CAPABILITY_MAX_A_MPDU_LEN_EXP1 = object() 178AC_CAPABILITY_MAX_A_MPDU_LEN_EXP2 = object() 179AC_CAPABILITY_MAX_A_MPDU_LEN_EXP3 = object() 180AC_CAPABILITY_MAX_A_MPDU_LEN_EXP4 = object() 181AC_CAPABILITY_MAX_A_MPDU_LEN_EXP5 = object() 182AC_CAPABILITY_MAX_A_MPDU_LEN_EXP6 = object() 183AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7 = object() 184AC_CAPABILITY_VHT_LINK_ADAPT2 = object() 185AC_CAPABILITY_VHT_LINK_ADAPT3 = object() 186AC_CAPABILITY_RX_ANTENNA_PATTERN = object() 187AC_CAPABILITY_TX_ANTENNA_PATTERN = object() 188AC_CAPABILITY_MAX_MPDU_7991 = object() 189AC_CAPABILITY_MAX_MPDU_11454 = object() 190AC_CAPABILITIES_MAPPING = { 191 AC_CAPABILITY_VHT160: '[VHT160]', 192 AC_CAPABILITY_VHT160_80PLUS80: '[VHT160-80PLUS80]', 193 AC_CAPABILITY_RXLDPC: '[RXLDPC]', 194 AC_CAPABILITY_SHORT_GI_80: '[SHORT-GI-80]', 195 AC_CAPABILITY_SHORT_GI_160: '[SHORT-GI-160]', 196 AC_CAPABILITY_TX_STBC_2BY1: '[TX-STBC-2BY1]', 197 AC_CAPABILITY_RX_STBC_1: '[RX-STBC-1]', 198 AC_CAPABILITY_RX_STBC_12: '[RX-STBC-12]', 199 AC_CAPABILITY_RX_STBC_123: '[RX-STBC-123]', 200 AC_CAPABILITY_RX_STBC_1234: '[RX-STBC-1234]', 201 AC_CAPABILITY_SU_BEAMFORMER: '[SU-BEAMFORMER]', 202 AC_CAPABILITY_SU_BEAMFORMEE: '[SU-BEAMFORMEE]', 203 AC_CAPABILITY_BF_ANTENNA_2: '[BF-ANTENNA-2]', 204 AC_CAPABILITY_SOUNDING_DIMENSION_2: '[SOUNDING-DIMENSION-2]', 205 AC_CAPABILITY_MU_BEAMFORMER: '[MU-BEAMFORMER]', 206 AC_CAPABILITY_MU_BEAMFORMEE: '[MU-BEAMFORMEE]', 207 AC_CAPABILITY_VHT_TXOP_PS: '[VHT-TXOP-PS]', 208 AC_CAPABILITY_HTC_VHT: '[HTC-VHT]', 209 AC_CAPABILITY_MAX_A_MPDU_LEN_EXP0: '[MAX-A-MPDU-LEN-EXP0]', 210 AC_CAPABILITY_MAX_A_MPDU_LEN_EXP1: '[MAX-A-MPDU-LEN-EXP1]', 211 AC_CAPABILITY_MAX_A_MPDU_LEN_EXP2: '[MAX-A-MPDU-LEN-EXP2]', 212 AC_CAPABILITY_MAX_A_MPDU_LEN_EXP3: '[MAX-A-MPDU-LEN-EXP3]', 213 AC_CAPABILITY_MAX_A_MPDU_LEN_EXP4: '[MAX-A-MPDU-LEN-EXP4]', 214 AC_CAPABILITY_MAX_A_MPDU_LEN_EXP5: '[MAX-A-MPDU-LEN-EXP5]', 215 AC_CAPABILITY_MAX_A_MPDU_LEN_EXP6: '[MAX-A-MPDU-LEN-EXP6]', 216 AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7: '[MAX-A-MPDU-LEN-EXP7]', 217 AC_CAPABILITY_VHT_LINK_ADAPT2: '[VHT-LINK-ADAPT2]', 218 AC_CAPABILITY_VHT_LINK_ADAPT3: '[VHT-LINK-ADAPT3]', 219 AC_CAPABILITY_RX_ANTENNA_PATTERN: '[RX-ANTENNA-PATTERN]', 220 AC_CAPABILITY_TX_ANTENNA_PATTERN: '[TX-ANTENNA-PATTERN]', 221 AC_CAPABILITY_MAX_MPDU_11454: '[MAX-MPDU-11454]', 222 AC_CAPABILITY_MAX_MPDU_7991: '[MAX-MPDU-7991]' 223} 224VHT_CHANNEL_WIDTH_40 = 0 225VHT_CHANNEL_WIDTH_80 = 1 226VHT_CHANNEL_WIDTH_160 = 2 227VHT_CHANNEL_WIDTH_80_80 = 3 228 229VHT_CHANNEL = { 230 40: VHT_CHANNEL_WIDTH_40, 231 80: VHT_CHANNEL_WIDTH_80, 232 160: VHT_CHANNEL_WIDTH_160 233} 234 235# This is a loose merging of the rules for US and EU regulatory 236# domains as taken from IEEE Std 802.11-2012 Appendix E. For instance, 237# we tolerate HT40 in channels 149-161 (not allowed in EU), but also 238# tolerate HT40+ on channel 7 (not allowed in the US). We take the loose 239# definition so that we don't prohibit testing in either domain. 240HT40_ALLOW_MAP = { 241 N_CAPABILITY_HT40_MINUS_CHANNELS: 242 tuple( 243 itertools.chain( 244 range(6, 14), range(40, 65, 8), range(104, 137, 8), [153, 161])), 245 N_CAPABILITY_HT40_PLUS_CHANNELS: 246 tuple( 247 itertools.chain( 248 range(1, 8), range(36, 61, 8), range(100, 133, 8), [149, 157])) 249} 250 251PMF_SUPPORT_DISABLED = 0 252PMF_SUPPORT_ENABLED = 1 253PMF_SUPPORT_REQUIRED = 2 254PMF_SUPPORT_VALUES = (PMF_SUPPORT_DISABLED, PMF_SUPPORT_ENABLED, 255 PMF_SUPPORT_REQUIRED) 256 257DRIVER_NAME = 'nl80211' 258 259CENTER_CHANNEL_MAP = { 260 VHT_CHANNEL_WIDTH_40: { 261 'delta': 2, 262 'channels': ((36, 40), (44, 48), (52, 56), (60, 64), (100, 104), 263 (108, 112), (116, 120), (124, 128), (132, 136), 264 (140, 144), (149, 153), (147, 161)) 265 }, 266 VHT_CHANNEL_WIDTH_80: { 267 'delta': 6, 268 'channels': ((36, 48), (52, 64), (100, 112), (116, 128), (132, 144), 269 (149, 161)) 270 }, 271 VHT_CHANNEL_WIDTH_160: { 272 'delta': 14, 273 'channels': ((36, 64), (100, 128)) 274 } 275} 276