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' 130BACKBONE_QUERY_URI = '/b/bq' 131BACKBONE_ANSWER_URI = '/b/ba' 132 133# ADDR SOL Status 134ADDR_SOL_SUCCESS = 0 135ADDR_SOL_NA = 1 136 137# MLE TLVs 138SOURCE_ADDRESS_TLV = 0 139MODE_TLV = 1 140TIMEOUT_TLV = 2 141CHALLENGE_TLV = 3 142RESPONSE_TLV = 4 143LINK_LAYER_FRAME_COUNTER_TLV = 5 144LINK_QUALITY_TLV = 6 145PARAMETER_TLV = 7 146MLE_FRAME_COUNTER_TLV = 8 147ROUTE64_TLV = 9 148ADDRESS16_TLV = 10 149LEADER_DATA_TLV = 11 150NETWORK_DATA_TLV = 12 151TLV_REQUEST_TLV = 13 152SCAN_MASK_TLV = 14 153CONNECTIVITY_TLV = 15 154LINK_MARGIN_TLV = 16 155STATUS_TLV = 17 156VERSION_TLV = 18 157ADDRESS_REGISTRATION_TLV = 19 158CHANNEL_TLV = 20 159PAN_ID_TLV = 21 160ACTIVE_TIMESTAMP_TLV = 22 161PENDING_TIMESTAMP_TLV = 23 162ACTIVE_OPERATION_DATASET_TLV = 24 163PENDING_OPERATION_DATASET_TLV = 25 164THREAD_DISCOVERY_TLV = 26 165CSL_SYNCHRONIZED_TIMEOUT = 85 166CSL_CLOCK_ACCURACY = 86 167 168# Network Layer TLVs 169NL_TARGET_EID_TLV = 0 170NL_MAC_EXTENDED_ADDRESS_TLV = 1 171NL_RLOC16_TLV = 2 172NL_ML_EID_TLV = 3 173NL_STATUS_TLV = 4 174NL_TIME_SINCE_LAST_TRANSACTION_TLV = 6 175NL_ROUTER_MASK_TLV = 7 176NL_ND_OPTION_TLV = 8 177NL_ND_DATA_TLV = 9 178NL_THREAD_NETWORK_DATA_TLV = 10 179 180# Network Layer Status 181NL_SUCESS = 0 182NL_NO_ADDRESS_AVAILABLE = 1 183NL_TOO_FEW_ROUTERS = 2 184NL_HAVE_CHILD_ID_REQUEST = 3 185NL_PARENT_PARTITION_CHANGE = 4 186 187# MeshCop TLVs 188NM_CHANNEL_TLV = 0 189NM_PAN_ID_TLV = 1 190NM_EXTENDED_PAN_ID_TLV = 2 191NM_NETWORK_NAME_TLV = 3 192NM_PSKC_TLV = 4 193NM_NETWORK_KEY_TLV = 5 194NM_NETWORK_KEY_SEQUENCE_COUNTER_TLV = 6 195NM_NETWORK_MESH_LOCAL_PREFIX_TLV = 7 196NM_STEERING_DATA_TLV = 8 197NM_BORDER_AGENT_LOCATOR_TLV = 9 198NM_COMMISSIONER_ID_TLV = 10 199NM_COMMISSIONER_SESSION_ID_TLV = 11 200NM_SECURITY_POLICY_TLV = 12 201NM_ACTIVE_TIMESTAMP_TLV = 14 202NM_COMMISSIONER_UDP_PORT_TLV = 15 203NM_STATE_TLV = 16 204NM_JOINER_DTLS_ENCAPSULATION_TLV = 17 205NM_JOINER_UDP_PORT_TLV = 18 206NM_JOINER_IID_TLV = 19 207NM_JOINER_ROUTER_LOCATOR_TLV = 20 208NM_JOINER_ROUTER_KEK_TLV = 21 209NM_PENDING_TIMESTAMP_TLV = 51 210NM_DELAY_TIMER_TLV = 52 211NM_CHANNEL_MASK_TLV = 53 212NM_SCAN_DURATION = 56 213NM_ENERGY_LIST_TLV = 57 214NM_DISCOVERY_REQUEST_TLV = 128 215NM_DISCOVERY_RESPONSE_TLV = 129 216 217# Diagnostic TLVs 218DG_MAC_EXTENDED_ADDRESS_TLV = 0 219DG_MAC_ADDRESS_TLV = 1 220DG_MODE_TLV = 2 221DG_TIMEOUT_TLV = 3 222DG_CONNECTIVITY_TLV = 4 223DG_ROUTE64_TLV = 5 224DG_LEADER_DATA_TLV = 6 225DG_NETWORK_DATA_TLV = 7 226DG_IPV6_ADDRESS_LIST_TLV = 8 227DG_MAC_COUNTERS_TLV = 9 228DG_BATTERY_LEVEL_TLV = 14 229DG_SUPPLY_VOLTAGE_TLV = 15 230DG_CHILD_TABLE_TLV = 16 231DG_CHANNEL_PAGES_TLV = 17 232DG_TYPE_LIST_TLV = 18 233DG_MAX_CHILD_TIMEOUT_TLV = 19 234 235# MeshCop State 236MESHCOP_ACCEPT = 1 237MESHCOP_PENDING = 0 238MESHCOP_REJECT = -1 239 240# DTLS 241HANDSHAKE_HELLO_REQUEST = 0 242HANDSHAKE_CLIENT_HELLO = 1 243HANDSHAKE_SERVER_HELLO = 2 244HANDSHAKE_HELLO_VERIFY_REQUEST = 3 245HANDSHAKE_CERTIFICATE = 11 246HANDSHAKE_SERVER_KEY_EXCHANGE = 12 247HANDSHAKE_CERTIFICATE_REQUEST = 13 248HANDSHAKE_SERVER_HELLO_DONE = 14 249HANDSHAKE_CERTIFICATE_VERIFY = 15 250HANDSHAKE_CLIENT_KEY_EXCHANGE = 16 251HANDSHAKE_FINISHED = 20 252CONTENT_CHANGE_CIPHER_SPEC = 20 253CONTENT_ALERT = 21 254CONTENT_HANDSHAKE = 22 255CONTENT_APPLICATION_DATA = 23 256 257# Network Data TLVs 258NWD_HAS_ROUTER_TLV = 0 259NWD_PREFIX_TLV = 1 260NWD_BORDER_ROUTER_TLV = 2 261NWD_6LOWPAN_ID_TLV = 3 262NWD_COMMISSIONING_DATA_TLV = 4 263NWD_SERVICE_TLV = 5 264NWD_SERVER_TLV = 6 265 266# Link Metrics TLVs 267LM_FORWARD_PROBING_REGISTRATION_SUB_TLV = 3 268LM_ENHANCED_ACK_CONFIGURATION_SUB_TLV = 7 269 270# DUA related constants 271 272ADDRESS_QUERY_INITIAL_RETRY_DELAY = 15 273ADDRESS_QUERY_MAX_RETRY_DELAY = 8 274ADDRESS_QUERY_TIMEOUT = 3 275ADVERTISEMENT_I_MAX = 32 276ADVERTISEMENT_I_MIN = 1 277 278CONTEXT_ID_REUSE_DELAY = 48 279 280DATA_RESUBMIT_DELAY = 300 281 282DUA_DAD_PERIOD = 100 283DUA_DAD_QUERY_TIMEOUT = 1.0 284DUA_DAD_REPEATS = 2 285DUA_RECENT_TIME = 20 286FAILED_ROUTER_TRANSMISSIONS = 4 287ID_REUSE_DELAY = 100 288ID_SEQUENCE_PERIOD = 10 289INFINITE_COST_TIMEOUT = 90 290 291REAL_LAYER_NAMES = { 292 'mle', 293 'coap', 294 'dtls', 295 'wpan', 296 'eth', 297 'tcp', 298 'udp', 299 'ip', 300 'ipv6', 301 'icmpv6', 302 '6lowpan', 303 'arp', 304 'thread_bl', 305 'thread_address', 306 'thread_diagnostic', 307 'thread_nm', 308 'thread_bcn', 309 'ssdp', 310 'dns', 311 'igmp', 312 'mdns', 313 'dns', 314} 315 316FAKE_LAYER_NAMES = {'thread_nwd', 'thread_meshcop', 'ipv6inner'} 317 318VALID_LAYER_NAMES = REAL_LAYER_NAMES | FAKE_LAYER_NAMES 319 320AUTO_SEEK_BACK_MAX_DURATION = 0.02 321 322# Wireshark configs 323WIRESHARK_OVERRIDE_PREFS = { 324 '6lowpan.context0': 325 'fd00:db8::/64', 326 '6lowpan.context1': 327 'fd00:7d03:7d03:7d03::/64', 328 'wpan.802154_fcs_ok': 329 'FALSE', 330 'wpan.802154_sec_suite': 331 'AES-128 Encryption, 32-bit Integrity Protection', 332 'thread.thr_seq_ctr': 333 '00000000', 334 'uat:ieee802154_keys': 335 '''"00112233445566778899aabbccddeeff","1","Thread hash" 336 "ffeeddccbbaa99887766554433221100","1","Thread hash"''', 337} 338 339WIRESHARK_DECODE_AS_ENTRIES = { 340 'udp.port==61631': 'coap', 341 # SRP server ports for dissecting SRP requests and responses 342 'udp.port==53535': 'dns', 343 'udp.port==53536': 'dns', 344 'udp.port==53537': 'dns', 345 'udp.port==53538': 'dns', 346 'udp.port==53539': 'dns', 347 'udp.port==53540': 'dns', 348 'udp.port==53541': 'dns', 349 'udp.port==53542': 'dns', 350 'udp.port==53543': 'dns', 351 'udp.port==53544': 'dns', 352 'udp.port==53545': 'dns', 353 'udp.port==53546': 'dns', 354 'udp.port==53547': 'dns', 355 'udp.port==53548': 'dns', 356 'udp.port==53549': 'dns', 357 'udp.port==53550': 'dns', 358 'udp.port==53551': 'dns', 359 'udp.port==53552': 'dns', 360 'udp.port==53553': 'dns', 361 'udp.port==53554': 'dns', 362} 363 364TIMEOUT_JOIN_NETWORK = 10 365TIMEOUT_DUA_REGISTRATION = 10 366TIMEOUT_DUA_DAD = 15 367TIMEOUT_HOST_READY = 10 368TIMEOUT_CHILD_DETACH = 120 369TIMEOUT_REGISTER_MA = 5 370 371# 802.15.4 Frame Version 372MAC_FRAME_VERSION_2006 = 1 373MAC_FRAME_VERSION_2015 = 2 374 375# 802.15.4 Frame Type 376MAC_FRAME_TYPE_BEACON = 0x0 377MAC_FRAME_TYPE_DATA = 0x1 378MAC_FRAME_TYPE_ACK = 0x2 379MAC_FRAME_TYPE_MAC_CMD = 0x3 380 381# CSL 382CSL_DEFAULT_PERIOD = 3125 # 0.5s, 3125 in units of ten symbols 383CSL_DEFAULT_PERIOD_IN_SECOND = 0.5 384US_PER_TEN_SYMBOLS = 160 385CSL_IE_ID = 0x1a 386CSL_DEFAULT_TIMEOUT = 30 387CSL_DEFAULT_CHANNEL = 12 388 389# Thread Version TLV value 390THREAD_VERSION_1_1 = 2 391THREAD_VERSION_1_2 = 3 392THREAD_VERSION_1_3 = 4 393 394# ICMPv6 Types 395ICMPV6_TYPE_DESTINATION_UNREACHABLE = 1 396ICMPV6_TYPE_PACKET_TO_BIG = 2 397ICMPV6_TYPE_TIME_EXCEEDED = 3 398ICMPV6_TYPE_PARAMETER_PROBLEM = 4 399ICMPV6_TYPE_ECHO_REQUEST = 128 400ICMPV6_TYPE_ECHO_REPLY = 129 401 402ICMPV6_RA_OPT_TYPE_RIO = 24 403 404THREAD_ALLOWED_ICMPV6_TYPES = [ 405 ICMPV6_TYPE_DESTINATION_UNREACHABLE, 406 ICMPV6_TYPE_PACKET_TO_BIG, 407 ICMPV6_TYPE_TIME_EXCEEDED, 408 ICMPV6_TYPE_PARAMETER_PROBLEM, 409 ICMPV6_TYPE_ECHO_REQUEST, 410 ICMPV6_TYPE_ECHO_REPLY, 411] 412 413# Link Metrics 414LINK_METRICS_STATUS_SUCCESS = 0 415LINK_METRICS_STATUS_CANNOT_SUPPORT_NEW_SERIES = 1 416LINK_METRICS_STATUS_SERIES_ID_ALREADY_REGISTERED = 2 417LINK_METRICS_STATUS_SERIES_ID_NOT_RECOGNIZED = 3 418LINK_METRICS_STATUS_NO_MATCHING_FRAMES_RECEIVED = 4 419LINK_METRICS_STATUS_OTHER_ERROR = 254 420 421LINK_METRICS_TYPE_AVERAGE_ENUM_COUNT = 0 422LINK_METRICS_TYPE_AVERAGE_ENUM_EXPONENTIAL = 1 423 424LINK_METRICS_METRIC_TYPE_ENUM_PDU_COUNT = 0 425LINK_METRICS_METRIC_TYPE_ENUM_LQI = 1 426LINK_METRICS_METRIC_TYPE_ENUM_LINK_MARGIN = 2 427LINK_METRICS_METRIC_TYPE_ENUM_RSSI = 3 428 429LINK_METRICS_ENH_ACK_PROBING_CLEAR = 0 430LINK_METRICS_ENH_ACK_PROBING_REGISTER = 1 431 432# THREAD_COMPANY_ID 433THREAD_IEEE_802154_COMPANY_ID = 0xEAB89B 434 435if __name__ == '__main__': 436 from pktverify.addrs import Ipv6Addr 437 438 assert Ipv6Addr("fe80:0000:0000:0000:0200:0000:0000:0004").startswith(LINK_LOCAL_PREFIX) 439 assert Ipv6Addr("fd00:0db8:0000:0000:0000:00ff:fe00:8001").startswith(DEFAULT_MESH_LOCAL_PREFIX) 440