From 752e38ec87cae63ffb8ef865da4c7a6a511a6f22 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 6 Feb 2024 19:04:14 +0100 Subject: [PATCH] Add vendor TLV tag (#103) * Add vendor TLV tag Users received "unkown type 74" when trying to import Thread dataset from an Apple iOS device. It seems that an additional tag with type 74 is present in those datasets. Accept this unkown tag type as well. * Fix falke8/black * Split long line properly * Update python_otbr_api/tlv_parser.py Co-authored-by: Stefan Agner * Update test_tlv_parser.py --------- Co-authored-by: Erik Montnemery --- python_otbr_api/tlv_parser.py | 2 ++ tests/test_tlv_parser.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/python_otbr_api/tlv_parser.py b/python_otbr_api/tlv_parser.py index eeaf7dd..bbc44ac 100644 --- a/python_otbr_api/tlv_parser.py +++ b/python_otbr_api/tlv_parser.py @@ -50,6 +50,8 @@ class MeshcopTLVType(IntEnum): PERIOD = 55 SCAN_DURATION = 56 ENERGY_LIST = 57 + # Seen in a dataset imported through iOS companion app + APPLE_TAG_UNKNOWN = 74 DISCOVERYREQUEST = 128 DISCOVERYRESPONSE = 129 JOINERADVERTISEMENT = 241 diff --git a/tests/test_tlv_parser.py b/tests/test_tlv_parser.py index 10d4733..21abc4e 100644 --- a/tests/test_tlv_parser.py +++ b/tests/test_tlv_parser.py @@ -101,6 +101,32 @@ def test_parse_tlv() -> None: } +def test_parse_tlv_apple() -> None: + """Test the TLV parser from a (truncated) dataset from an Apple BR.""" + dataset_tlv = ( + "0e08000065901a07000000030000194a0300000f35060004001fffc003104d79486f6d65313233" + "31323331323334" + ) + dataset = parse_tlv(dataset_tlv) + assert dataset == { + MeshcopTLVType.ACTIVETIMESTAMP: Timestamp( + MeshcopTLVType.ACTIVETIMESTAMP, bytes.fromhex("000065901a070000") + ), + MeshcopTLVType.CHANNEL: Channel( + MeshcopTLVType.CHANNEL, bytes.fromhex("000019") + ), + MeshcopTLVType.APPLE_TAG_UNKNOWN: MeshcopTLVItem( + MeshcopTLVType.APPLE_TAG_UNKNOWN, bytes.fromhex("00000f") + ), + MeshcopTLVType.CHANNELMASK: MeshcopTLVItem( + MeshcopTLVType.CHANNELMASK, bytes.fromhex("0004001fffc0") + ), + MeshcopTLVType.NETWORKNAME: NetworkName( + MeshcopTLVType.NETWORKNAME, "MyHome1231231234".encode() + ), + } + + @pytest.mark.parametrize( "tlv, error, msg", (