mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[tcat] implement get diagnostic tlvs in command class commissioning (#11163)
Adds implementation of Tcat TLV 0x26 Get Diagnostic TLVs. It also adds support for long BleSecure messages >1280 bytes in BleSecure::Flush(void).
This commit is contained in:
@@ -33,6 +33,7 @@ from ble.ble_stream import BleStream
|
||||
from ble.ble_stream_secure import BleStreamSecure
|
||||
from ble import ble_scanner
|
||||
from tlv.tlv import TLV
|
||||
from tlv.diagnostic_tlv import DiagnosticTLVType
|
||||
from tlv.tcat_tlv import TcatTLVType
|
||||
from cli.command import Command, CommandResultNone, CommandResultTLV
|
||||
from dataset.dataset import ThreadDataset
|
||||
@@ -386,6 +387,31 @@ class ScanCommand(Command):
|
||||
return CommandResultNone()
|
||||
|
||||
|
||||
class DiagnosticTlvsCommand(BleCommand):
|
||||
|
||||
def get_log_string(self) -> str:
|
||||
return 'Retrieving diagnostic information.'
|
||||
|
||||
def get_help_string(self) -> str:
|
||||
return 'Get diagnostic TLVs from the TCAT device.'
|
||||
|
||||
def prepare_data(self, args, context):
|
||||
num_args = DiagnosticTLVType.names_to_numbers(args)
|
||||
try:
|
||||
if not num_args:
|
||||
raise ValueError()
|
||||
vals = [int(x) for x in num_args]
|
||||
tlvs = bytes(vals)
|
||||
except ValueError:
|
||||
print('Please provide a list of diagnostic TLV types as names or numbers')
|
||||
print('TLV Types:')
|
||||
for key, value in DiagnosticTLVType.get_dict().items():
|
||||
print(f'{key} = {value},')
|
||||
raise DataNotPrepared()
|
||||
|
||||
return TLV(TcatTLVType.GET_DIAGNOSTIC_TLVS.value, tlvs).to_bytes()
|
||||
|
||||
|
||||
class ThreadStartCommand(BleCommand):
|
||||
|
||||
def get_log_string(self) -> str:
|
||||
|
||||
@@ -32,7 +32,8 @@ from ble.ble_stream_secure import BleStreamSecure
|
||||
from cli.base_commands import (DisconnectCommand, HelpCommand, HelloCommand, CommissionCommand, DecommissionCommand,
|
||||
ExtractDatasetCommand, GetCommissionerCertificate, GetDeviceIdCommand, GetPskdHash,
|
||||
GetExtPanIDCommand, GetNetworkNameCommand, GetProvisioningUrlCommand, PingCommand,
|
||||
GetRandomNumberChallenge, ThreadStateCommand, ScanCommand, PresentHash)
|
||||
GetRandomNumberChallenge, ThreadStateCommand, ScanCommand, PresentHash,
|
||||
DiagnosticTlvsCommand)
|
||||
from .tlv_commands import TlvCommand
|
||||
from cli.dataset_commands import (DatasetCommand)
|
||||
from dataset.dataset import ThreadDataset
|
||||
@@ -65,6 +66,7 @@ class CLI:
|
||||
'peer_pskd_hash': GetPskdHash(),
|
||||
'tlv': TlvCommand(),
|
||||
'get_comm_cert': GetCommissionerCertificate(),
|
||||
'diagnostic_tlvs': DiagnosticTlvsCommand()
|
||||
}
|
||||
self._context = {
|
||||
'ble_sstream': ble_sstream,
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"""
|
||||
Copyright (c) 2025, The OpenThread Authors.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
|
||||
|
||||
class DiagnosticTLVType:
|
||||
|
||||
def __init__(self):
|
||||
self._tlv_dict = {
|
||||
'extaddr': '0',
|
||||
'macaddr': '1',
|
||||
'mode': '2',
|
||||
'timeout': '3',
|
||||
'connectivity': '4',
|
||||
'route64': '5',
|
||||
'leaderdata': '6',
|
||||
'networkdata': '7',
|
||||
'ipaddr': '8',
|
||||
'maccounters': '9',
|
||||
'batterylevel': '14',
|
||||
'supplyvoltage': '15',
|
||||
'childtable': '16',
|
||||
'channelpages': '17',
|
||||
'maxchildtimeout': '19',
|
||||
'eui64': '23',
|
||||
'version': '24',
|
||||
'vendorname': '25',
|
||||
'vendormodel': '26',
|
||||
'vendorswversion': '27',
|
||||
'threadstackversion': '28',
|
||||
'child': '29',
|
||||
'childipv6list': '30',
|
||||
'routerneighbor': '31',
|
||||
'mlecounters': '34',
|
||||
'vendorappurl': '35',
|
||||
'channeldenylist': '36'
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def names_to_numbers(args):
|
||||
res = DiagnosticTLVType()
|
||||
return [x if x not in res._tlv_dict else res._tlv_dict[x] for x in args]
|
||||
|
||||
@staticmethod
|
||||
def get_dict():
|
||||
res = DiagnosticTLVType()
|
||||
return res._tlv_dict
|
||||
@@ -45,6 +45,7 @@ class TcatTLVType(Enum):
|
||||
ACTIVE_DATASET = 0x20
|
||||
GET_COMMISSIONER_CERTIFICATE = 0x25
|
||||
GET_ACTIVE_DATASET = 0x40
|
||||
GET_DIAGNOSTIC_TLVS = 0x26
|
||||
DECOMMISSION = 0x60
|
||||
APPLICATION = 0x82
|
||||
THREAD_START = 0x27
|
||||
|
||||
Reference in New Issue
Block a user