mirror of
https://github.com/espressif/openthread.git
synced 2026-08-25 19:59:51 +00:00
[ci] test with time sync and header ie (#3514)
This commit adds the missing test with ie present by enabling TIME_SYNC feature, so that IE code are covered.
This commit is contained in:
@@ -177,7 +177,9 @@ def create_default_mle_tlvs_factories():
|
||||
mle.TlvType.PENDING_TIMESTAMP: mle.PendingTimestampFactory(),
|
||||
mle.TlvType.ACTIVE_OPERATIONAL_DATASET: mle.ActiveOperationalDatasetFactory(),
|
||||
mle.TlvType.PENDING_OPERATIONAL_DATASET: mle.PendingOperationalDatasetFactory(),
|
||||
mle.TlvType.THREAD_DISCOVERY: mle.ThreadDiscoveryFactory()
|
||||
mle.TlvType.THREAD_DISCOVERY: mle.ThreadDiscoveryFactory(),
|
||||
mle.TlvType.TIME_REQUEST: mle.TimeRequestFactory(),
|
||||
mle.TlvType.TIME_PARAMETER: mle.TimeParameterFactory(),
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +207,7 @@ def create_deafult_network_tlvs_factories():
|
||||
network_layer.TlvType.ND_OPTION: network_layer.NdOptionFactory(),
|
||||
network_layer.TlvType.ND_DATA: network_layer.NdDataFactory(),
|
||||
network_layer.TlvType.THREAD_NETWORK_DATA: network_layer.ThreadNetworkDataFactory(create_default_network_data_tlvs_factory()),
|
||||
network_layer.TlvType.XTAL_ACCURACY: network_layer.XtalAccuracyFactory(),
|
||||
|
||||
# Routing information are distributed in a Thread network by MLE Routing TLV
|
||||
# which is in fact MLE Route64 TLV. Thread specificaton v1.1. - Chapter 5.20
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"""
|
||||
|
||||
import io
|
||||
import binascii
|
||||
import struct
|
||||
|
||||
import config
|
||||
@@ -115,6 +116,13 @@ class MacFrame:
|
||||
|
||||
"""Class representing 802.15.4 MAC frame."""
|
||||
|
||||
IEEE802154_HEADER_IE_TYPE_MASK = 0x8000
|
||||
IEEE802154_HEADER_IE_ID_MASK = 0x7f80
|
||||
IEEE802154_HEADER_IE_LENGTH_MASK = 0x007f
|
||||
|
||||
IEEE802154_HEADER_IE_HT1 = 0x7e
|
||||
IEEE802154_HEADER_IE_HT2 = 0x7f
|
||||
|
||||
def parse(self, data):
|
||||
mhr_start = data.tell()
|
||||
|
||||
@@ -128,6 +136,7 @@ class MacFrame:
|
||||
dest_addr_mode = (fc & 0x0c00) >> 10
|
||||
frame_version = (fc & 0x3000) >> 12
|
||||
source_addr_mode = (fc & 0xc000) >> 14
|
||||
ie_present = bool(fc & 0x0200)
|
||||
|
||||
if frame_type == MacHeader.FrameType.ACK:
|
||||
fcs = self._parse_fcs(data, data.tell())
|
||||
@@ -140,7 +149,21 @@ class MacFrame:
|
||||
|
||||
dest_address = self._parse_address(data, dest_addr_mode)
|
||||
|
||||
if not panid_compression:
|
||||
src_pan_present = not panid_compression
|
||||
while src_pan_present:
|
||||
if frame_version < 2:
|
||||
break
|
||||
if frame_version == 3:
|
||||
assert(false)
|
||||
if dest_addr_mode == 0:
|
||||
break
|
||||
if dest_addr_mode == 2:
|
||||
break
|
||||
if dest_addr_mode == 3 and source_addr_mode == 2:
|
||||
break
|
||||
src_pan_present = False
|
||||
|
||||
if src_pan_present:
|
||||
src_pan_id = struct.unpack("<H", data.read(2))[0]
|
||||
else:
|
||||
src_pan_id = dest_pan_id
|
||||
@@ -155,6 +178,19 @@ class MacFrame:
|
||||
else:
|
||||
aux_sec_header = None
|
||||
|
||||
# skip header ie
|
||||
header_ie_start = data.tell()
|
||||
while ie_present:
|
||||
header_ie = struct.unpack("<H", data.read(2))[0]
|
||||
header_ie_id = ((header_ie & MacFrame.IEEE802154_HEADER_IE_ID_MASK) >> 7)
|
||||
header_ie_length = (header_ie & MacFrame.IEEE802154_HEADER_IE_LENGTH_MASK)
|
||||
if header_ie_length:
|
||||
data.read(header_ie_length)
|
||||
|
||||
if header_ie_id in [MacFrame.IEEE802154_HEADER_IE_HT1, MacFrame.IEEE802154_HEADER_IE_HT2]:
|
||||
break
|
||||
header_ie_end = data.tell()
|
||||
|
||||
# Check end of MAC frame
|
||||
if frame_type == MacHeader.FrameType.COMMAND:
|
||||
command_type = ord(data.read(1))
|
||||
@@ -196,6 +232,9 @@ class MacFrame:
|
||||
|
||||
non_payload_fields = bytearray([])
|
||||
|
||||
if ie_present:
|
||||
data.seek(header_ie_start)
|
||||
non_payload_fields += data.read(header_ie_end - header_ie_start)
|
||||
if command_type is not None:
|
||||
non_payload_fields.append(command_type)
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ class CommandType(IntEnum):
|
||||
ANNOUNCE = 15
|
||||
DISCOVERY_REQUEST = 16
|
||||
DISCOVERY_RESPONSE = 17
|
||||
TIME_SYNC = 99
|
||||
|
||||
|
||||
class TlvType(IntEnum):
|
||||
@@ -86,6 +87,8 @@ class TlvType(IntEnum):
|
||||
ACTIVE_OPERATIONAL_DATASET = 24
|
||||
PENDING_OPERATIONAL_DATASET = 25
|
||||
THREAD_DISCOVERY = 26
|
||||
TIME_REQUEST = 252
|
||||
TIME_PARAMETER = 253
|
||||
|
||||
|
||||
class SourceAddress(object):
|
||||
@@ -1018,6 +1021,28 @@ class ThreadDiscoveryFactory:
|
||||
def parse(self, data, message_info):
|
||||
return ThreadDiscovery()
|
||||
|
||||
class TimeRequest:
|
||||
# TODO: Not implemented yet
|
||||
|
||||
def __init__(self):
|
||||
print("TimeRequest is not implemented yet.")
|
||||
|
||||
class TimeRequestFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
return TimeRequest()
|
||||
|
||||
class TimeParameter:
|
||||
# TODO: Not implemented yet
|
||||
|
||||
def __init__(self):
|
||||
print("TimeParameter is not implemented yet.")
|
||||
|
||||
|
||||
class TimeParameterFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
return TimeParameter()
|
||||
|
||||
class MleCommand(object):
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ class TlvType(IntEnum):
|
||||
ND_DATA = 9
|
||||
THREAD_NETWORK_DATA = 10
|
||||
MLE_ROUTING = 11
|
||||
XTAL_ACCURACY = 254
|
||||
|
||||
|
||||
class StatusValues(IntEnum):
|
||||
@@ -274,6 +275,18 @@ class NdDataFactory(object):
|
||||
def parse(self, data, message_info):
|
||||
raise NotImplementedError("TODO: Not implemented yet")
|
||||
|
||||
class XtalAccuracy:
|
||||
# TODO: Not implemented yet
|
||||
|
||||
def __init__(self):
|
||||
print("XtalAccuracy is not implemented yet.")
|
||||
|
||||
|
||||
class XtalAccuracyFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
return XtalAccuracy()
|
||||
|
||||
|
||||
class ThreadNetworkData(object):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user