1#!/usr/bin/env python3 2# 3# Copyright (c) 2019, The OpenThread Authors. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 3. Neither the name of the copyright holder nor the 14# names of its contributors may be used to endorse or promote products 15# derived from this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30from pktverify.addrs import Ipv6Addr 31from pktverify.bytes import Bytes 32 33DOMAIN_PREFIX = Bytes('fd00:7d03:7d03:7d03') 34BACKBONE_IPV6_PREFIX = Bytes('91') 35 36LINK_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS = Ipv6Addr('ff32:40:fd00:db8::1') 37REALM_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS = Ipv6Addr('ff33:40:fd00:db8::1') 38REALM_LOCAL_ALL_NODES_ADDRESS = Ipv6Addr('ff03::1') 39REALM_LOCAL_ALL_ROUTERS_ADDRESS = Ipv6Addr('ff03::2') 40LINK_LOCAL_ALL_NODES_MULTICAST_ADDRESS = Ipv6Addr('ff02::1') 41LINK_LOCAL_ALL_ROUTERS_MULTICAST_ADDRESS = Ipv6Addr('ff02::2') 42LINK_LOCAL_ALL_BBRS_MULTICAST_ADDRESS = Ipv6Addr('ff32:40:fd00:7d03:7d03:7d03:0:3') 43 44# MA in Test Plan, make sure these are same as ../config.py 45MA1 = Ipv6Addr('ff04::1234:777a:1') 46MA1g = Ipv6Addr('ff0e::1234:777a:1') 47MA2 = Ipv6Addr('ff05::1234:777a:1') 48MA3 = Ipv6Addr('ff0e::1234:777a:3') 49MA4 = Ipv6Addr('ff05::1234:777a:4') 50MA5 = Ipv6Addr('ff03::1234:777a:5') 51MA6 = Ipv6Addr('ff02::1') 52MAe1 = Ipv6Addr('fd0e::1234:777a:1') 53MAe2 = Ipv6Addr('::') 54MAe3 = Ipv6Addr('cafe::e0ff') 55MAS = [[Ipv6Addr(f'ff0e::{j:x}:777a:{i:x}') for j in range(16)] for i in range(16)] 56ALL_MPL_FORWARDERS_MA = Ipv6Addr('ff03::fc') 57 58LINK_LOCAL_PREFIX = Bytes("fe80") 59DEFAULT_MESH_LOCAL_PREFIX = Bytes("fd00:0db8:0000:0000") 60LEADER_ALOC_IID = Bytes("0000:00ff:fe00:fc00") 61PBBR_ALOC_IID = Bytes("0000:00ff:fe00:fc38") 62LEADER_ALOC = Ipv6Addr(DEFAULT_MESH_LOCAL_PREFIX + LEADER_ALOC_IID) 63PBBR_ALOC = Ipv6Addr(DEFAULT_MESH_LOCAL_PREFIX + PBBR_ALOC_IID) 64 65# Minimum value of the MLR Timeout parameter in the BBR Dataset 66MLR_TIMEOUT_MIN = 300 67 68# Max response delay 69MLE_MAX_RESPONSE_DELAY = 1 70 71# WPAN CMDs 72WPAN_DATA_REQUEST = 4 73 74# WPAN Frame Types 75WPAN_BEACON = 0 76WPAN_DATA = 1 77WPAN_ACK = 2 78WPAN_CMD = 3 79 80# COAP methods 81COAP_CODE_POST = 2 82COAP_CODE_ACK = 68 83 84MLE_LINK_REQUEST = 0 85MLE_LINK_ACCEPT = 1 86MLE_LINK_ACCEPT_AND_REQUEST = 2 87MLE_ADVERTISEMENT = 4 88MLE_DATA_REQUEST = 7 89MLE_DATA_RESPONSE = 8 90MLE_PARENT_REQUEST = 9 91MLE_PARENT_RESPONSE = 10 92MLE_CHILD_ID_REQUEST = 11 93MLE_CHILD_ID_RESPONSE = 12 94MLE_CHILD_UPDATE_REQUEST = 13 95MLE_CHILD_UPDATE_RESPONSE = 14 96MLE_ANNOUNCE = 15 97MLE_DISCOVERY_REQUEST = 16 98MLE_DISCOVERY_RESPONSE = 17 99MLE_LINK_METRICS_MANAGEMENT_REQUEST = 18 100MLE_LINK_METRICS_MANAGEMENT_RESPONSE = 19 101MLE_LINK_PROBE = 20 102 103# COAP URIs 104ADDR_QRY_URI = '/a/aq' 105ADDR_NTF_URI = '/a/an' 106ADDR_ERR_URI = '/a/ae' 107ADDR_SOL_URI = '/a/as' 108ADDR_REL_URI = '/a/ar' 109SVR_DATA_URI = '/a/sd' 110ND_DATA_URI = '/a/nd' 111RLY_RX_URI = '/c/rx' 112RLY_TX_URI = '/c/tx' 113MGMT_PANID_QUERY = '/c/pq' 114MGMT_PANID_CONFLICT = '/c/pc' 115MGMT_ED_SCAN = '/c/es' 116MGMT_ED_REPORT = '/c/er' 117MGMT_ACTIVE_GET_URI = '/c/ag' 118MGMT_ACTIVE_SET_URI = '/c/as' 119MGMT_PENDING_SET_URI = '/c/ps' 120MGMT_PENDING_GET_URI = '/c/pg' 121MGMT_DATASET_CHANGED_URI = '/c/dc' 122MGMT_COMMISSIONER_GET_URI = '/c/cg' 123DIAG_GET_URI = '/d/dg' 124DIAG_RST_URI = '/d/dr' 125MGMT_COMMISSIONER_SET_URI = '/c/cs' 126LEAD_PET_URI = '/c/lp' 127LEAD_KA_URI = '/c/la' 128DIAG_GET_QRY_URI = '/d/dq' 129DIAG_GET_ANS_URI = '/d/da' 130 131# ADDR SOL Status 132ADDR_SOL_SUCCESS = 0 133ADDR_SOL_NA = 1 134 135# MLE TLVs 136SOURCE_ADDRESS_TLV = 0 137MODE_TLV = 1 138TIMEOUT_TLV = 2 139CHALLENGE_TLV = 3 140RESPONSE_TLV = 4 141LINK_LAYER_FRAME_COUNTER_TLV = 5 142LINK_QUALITY_TLV = 6 143PARAMETER_TLV = 7 144MLE_FRAME_COUNTER_TLV = 8 145ROUTE64_TLV = 9 146ADDRESS16_TLV = 10 147LEADER_DATA_TLV = 11 148NETWORK_DATA_TLV = 12 149TLV_REQUEST_TLV = 13 150SCAN_MASK_TLV = 14 151CONNECTIVITY_TLV = 15 152LINK_MARGIN_TLV = 16 153STATUS_TLV = 17 154VERSION_TLV = 18 155ADDRESS_REGISTRATION_TLV = 19 156CHANNEL_TLV = 20 157PAN_ID_TLV = 21 158ACTIVE_TIMESTAMP_TLV = 22 159PENDING_TIMESTAMP_TLV = 23 160ACTIVE_OPERATION_DATASET_TLV = 24 161PENDING_OPERATION_DATASET_TLV = 25 162THREAD_DISCOVERY_TLV = 26 163CSL_SYNCHRONIZED_TIMEOUT = 85 164CSL_CLOCK_ACCURACY = 86 165 166# Network Layer TLVs 167NL_TARGET_EID_TLV = 0 168NL_MAC_EXTENDED_ADDRESS_TLV = 1 169NL_RLOC16_TLV = 2 170NL_ML_EID_TLV = 3 171NL_STATUS_TLV = 4 172NL_TIME_SINCE_LAST_TRANSACTION_TLV = 6 173NL_ROUTER_MASK_TLV = 7 174NL_ND_OPTION_TLV = 8 175NL_ND_DATA_TLV = 9 176NL_THREAD_NETWORK_DATA_TLV = 10 177 178# Network Layer Status 179NL_SUCESS = 0 180NL_NO_ADDRESS_AVAILABLE = 1 181NL_TOO_FEW_ROUTERS = 2 182NL_HAVE_CHILD_ID_REQUEST = 3 183NL_PARENT_PARTITION_CHANGE = 4 184 185# MeshCop TLVs 186NM_CHANNEL_TLV = 0 187NM_PAN_ID_TLV = 1 188NM_EXTENDED_PAN_ID_TLV = 2 189NM_NETWORK_NAME_TLV = 3 190NM_PSKC_TLV = 4 191NM_NETWORK_KEY_TLV = 5 192NM_NETWORK_KEY_SEQUENCE_COUNTER_TLV = 6 193NM_NETWORK_MESH_LOCAL_PREFIX_TLV = 7 194NM_STEERING_DATA_TLV = 8 195NM_BORDER_AGENT_LOCATOR_TLV = 9 196NM_COMMISSIONER_ID_TLV = 10 197NM_COMMISSIONER_SESSION_ID_TLV = 11 198NM_SECURITY_POLICY_TLV = 12 199NM_ACTIVE_TIMESTAMP_TLV = 14 200NM_COMMISSIONER_UDP_PORT_TLV = 15 201NM_STATE_TLV = 16 202NM_JOINER_DTLS_ENCAPSULATION_TLV = 17 203NM_JOINER_UDP_PORT_TLV = 18 204NM_JOINER_IID_TLV = 19 205NM_JOINER_ROUTER_LOCATOR_TLV = 20 206NM_JOINER_ROUTER_KEK_TLV = 21 207NM_PENDING_TIMESTAMP_TLV = 51 208NM_DELAY_TIMER_TLV = 52 209NM_CHANNEL_MASK_TLV = 53 210NM_SCAN_DURATION = 56 211NM_ENERGY_LIST_TLV = 57 212NM_DISCOVERY_REQUEST_TLV = 128 213NM_DISCOVERY_RESPONSE_TLV = 129 214 215# Diagnostic TLVs 216DG_MAC_EXTENDED_ADDRESS_TLV = 0 217DG_MAC_ADDRESS_TLV = 1 218DG_MODE_TLV = 2 219DG_TIMEOUT_TLV = 3 220DG_CONNECTIVITY_TLV = 4 221DG_ROUTE64_TLV = 5 222DG_LEADER_DATA_TLV = 6 223DG_NETWORK_DATA_TLV = 7 224DG_IPV6_ADDRESS_LIST_TLV = 8 225DG_MAC_COUNTERS_TLV = 9 226DG_BATTERY_LEVEL_TLV = 14 227DG_SUPPLY_VOLTAGE_TLV = 15 228DG_CHILD_TABLE_TLV = 16 229DG_CHANNEL_PAGES_TLV = 17 230DG_TYPE_LIST_TLV = 18 231DG_MAX_CHILD_TIMEOUT_TLV = 19 232 233# MeshCop State 234MESHCOP_ACCEPT = 1 235MESHCOP_PENDING = 0 236MESHCOP_REJECT = -1 237 238# DTLS 239HANDSHAKE_HELLO_REQUEST = 0 240HANDSHAKE_CLIENT_HELLO = 1 241HANDSHAKE_SERVER_HELLO = 2 242HANDSHAKE_HELLO_VERIFY_REQUEST = 3 243HANDSHAKE_CERTIFICATE = 11 244HANDSHAKE_SERVER_KEY_EXCHANGE = 12 245HANDSHAKE_CERTIFICATE_REQUEST = 13 246HANDSHAKE_SERVER_HELLO_DONE = 14 247HANDSHAKE_CERTIFICATE_VERIFY = 15 248HANDSHAKE_CLIENT_KEY_EXCHANGE = 16 249HANDSHAKE_FINISHED = 20 250CONTENT_CHANGE_CIPHER_SPEC = 20 251CONTENT_ALERT = 21 252CONTENT_HANDSHAKE = 22 253CONTENT_APPLICATION_DATA = 23 254 255# Network Data TLVs 256NWD_HAS_ROUTER_TLV = 0 257NWD_PREFIX_TLV = 1 258NWD_BORDER_ROUTER_TLV = 2 259NWD_6LOWPAN_ID_TLV = 3 260NWD_COMMISSIONING_DATA_TLV = 4 261NWD_SERVICE_TLV = 5 262NWD_SERVER_TLV = 6 263 264# Link Metrics TLVs 265LM_FORWARD_PROBING_REGISTRATION_SUB_TLV = 3 266LM_ENHANCED_ACK_CONFIGURATION_SUB_TLV = 7 267 268# DUA related constants 269 270ADDRESS_QUERY_INITIAL_RETRY_DELAY = 15 271ADDRESS_QUERY_MAX_RETRY_DELAY = 8 272ADDRESS_QUERY_TIMEOUT = 3 273ADVERTISEMENT_I_MAX = 32 274ADVERTISEMENT_I_MIN = 1 275 276CONTEXT_ID_REUSE_DELAY = 48 277 278DATA_RESUBMIT_DELAY = 300 279 280DUA_DAD_PERIOD = 100 281DUA_DAD_QUERY_TIMEOUT = 1.0 282DUA_DAD_REPEATS = 2 283DUA_RECENT_TIME = 20 284FAILED_ROUTER_TRANSMISSIONS = 4 285ID_REUSE_DELAY = 100 286ID_SEQUENCE_PERIOD = 10 287INFINITE_COST_TIMEOUT = 90 288 289REAL_LAYER_NAMES = { 290 'mle', 291 'coap', 292 'dtls', 293 'wpan', 294 'eth', 295 'tcp', 296 'udp', 297 'ip', 298 'ipv6', 299 'icmpv6', 300 '6lowpan', 301 'arp', 302 'thread_bl', 303 'thread_address', 304 'thread_diagnostic', 305 'thread_nm', 306 'thread_bcn', 307 'ssdp', 308 'dns', 309 'igmp', 310 'mdns', 311} 312 313FAKE_LAYER_NAMES = {'thread_nwd', 'thread_meshcop', 'ipv6inner'} 314 315VALID_LAYER_NAMES = REAL_LAYER_NAMES | FAKE_LAYER_NAMES 316 317AUTO_SEEK_BACK_MAX_DURATION = 0.02 318 319# Wireshark configs 320WIRESHARK_OVERRIDE_PREFS = { 321 '6lowpan.context0': 322 'fd00:db8::/64', 323 '6lowpan.context1': 324 'fd00:7d03:7d03:7d03::/64', 325 'wpan.802154_fcs_ok': 326 'FALSE', 327 'wpan.802154_sec_suite': 328 'AES-128 Encryption, 32-bit Integrity Protection', 329 'thread.thr_seq_ctr': 330 '00000000', 331 'uat:ieee802154_keys': 332 '''"00112233445566778899aabbccddeeff","1","Thread hash" 333 "ffeeddccbbaa99887766554433221100","1","Thread hash"''', 334} 335 336WIRESHARK_DECODE_AS_ENTRIES = { 337 'udp.port==61631': 'coap', 338} 339 340TIMEOUT_JOIN_NETWORK = 10 341TIMEOUT_DUA_REGISTRATION = 10 342TIMEOUT_DUA_DAD = 15 343TIMEOUT_HOST_READY = 10 344TIMEOUT_CHILD_DETACH = 120 345TIMEOUT_REGISTER_MA = 5 346 347# 802.15.4 Frame Version 348MAC_FRAME_VERSION_2006 = 1 349MAC_FRAME_VERSION_2015 = 2 350 351# 802.15.4 Frame Type 352MAC_FRAME_TYPE_BEACON = 0x0 353MAC_FRAME_TYPE_DATA = 0x1 354MAC_FRAME_TYPE_ACK = 0x2 355MAC_FRAME_TYPE_MAC_CMD = 0x3 356 357# CSL 358CSL_DEFAULT_PERIOD = 3125 # 0.5s, 3125 in units of ten symbols 359CSL_DEFAULT_PERIOD_IN_SECOND = 0.5 360US_PER_TEN_SYMBOLS = 160 361CSL_IE_ID = 0x1a 362CSL_DEFAULT_TIMEOUT = 30 363CSL_DEFAULT_CHANNEL = 12 364 365# Thread Version TLV value 366THREAD_VERSION_1_2 = 3 367 368# ICMPv6 Types 369ICMPV6_TYPE_DESTINATION_UNREACHABLE = 1 370 371# Link Metrics 372LINK_METRICS_STATUS_SUCCESS = 0 373LINK_METRICS_STATUS_CANNOT_SUPPORT_NEW_SERIES = 1 374LINK_METRICS_STATUS_SERIES_ID_ALREADY_REGISTERED = 2 375LINK_METRICS_STATUS_SERIES_ID_NOT_RECOGNIZED = 3 376LINK_METRICS_STATUS_NO_MATCHING_FRAMES_RECEIVED = 4 377LINK_METRICS_STATUS_OTHER_ERROR = 254 378 379LINK_METRICS_TYPE_AVERAGE_ENUM_COUNT = 0 380LINK_METRICS_TYPE_AVERAGE_ENUM_EXPONENTIAL = 1 381 382LINK_METRICS_METRIC_TYPE_ENUM_PDU_COUNT = 0 383LINK_METRICS_METRIC_TYPE_ENUM_LQI = 1 384LINK_METRICS_METRIC_TYPE_ENUM_LINK_MARGIN = 2 385LINK_METRICS_METRIC_TYPE_ENUM_RSSI = 3 386 387LINK_METRICS_ENH_ACK_PROBING_CLEAR = 0 388LINK_METRICS_ENH_ACK_PROBING_REGISTER = 1 389 390# THREAD_COMPANY_ID 391THREAD_IEEE_802154_COMPANY_ID = 0xEAB89B 392 393if __name__ == '__main__': 394 from pktverify.addrs import Ipv6Addr 395 396 assert Ipv6Addr("fe80:0000:0000:0000:0200:0000:0000:0004").startswith(LINK_LOCAL_PREFIX) 397 assert Ipv6Addr("fd00:0db8:0000:0000:0000:00ff:fe00:8001").startswith(DEFAULT_MESH_LOCAL_PREFIX) 398