Skip to content

Commit

Permalink
[tcat] Implementation of tcat disconnect command.
Browse files Browse the repository at this point in the history
Implementation of tcat disconnect command in python client.
  • Loading branch information
canisLupus1313 committed Oct 23, 2024
1 parent c519aa4 commit 1cf14ee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/core/radio/ble_secure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ void BleSecure::HandleTlsReceive(uint8_t *aBuf, uint16_t aLength)

if (error == kErrorAbort)
{
LogInfo("Disconnecting tcat client.");
// kErrorAbort indicates that a Disconnect command TLV has been received.
Disconnect();
// BleSecure is not stopped here, it must remain active in advertising state and
Expand Down
20 changes: 18 additions & 2 deletions tools/tcat_ble_client/cli/base_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def prepare_data(self, args, context):
pass

async def execute_default(self, args, context):
if 'ble_sstream' not in context or context['ble_sstream'] is None:
print("Device not connected.")
return CommandResultNone()
bless: BleStreamSecure = context['ble_sstream']

print(self.get_log_string())
Expand All @@ -85,6 +88,7 @@ async def execute_default(self, args, context):
return CommandResultTLV(tlv_response)
except DataNotPrepared as err:
print('Command failed', err)
return CommandResultNone()


class HelloCommand(BleCommand):
Expand Down Expand Up @@ -298,7 +302,7 @@ async def execute_default(self, args, context):
response = await bless.send_with_resp(data)
elapsed_time = 1e3 * (time() - elapsed_time)
if not response:
return
return CommandResultNone()

tlv_response = TLV.from_bytes(response)
if tlv_response.value != to_send:
Expand Down Expand Up @@ -352,7 +356,8 @@ def get_help_string(self) -> str:
return 'Perform scan for TCAT devices.'

async def execute_default(self, args, context):
if not (context['ble_sstream'] is None):
if 'ble_sstream' in context and context['ble_stream'] is not None:
context['ble_sstream'].close()
del context['ble_sstream']

tcat_devices = await ble_scanner.scan_tcat_devices()
Expand All @@ -379,3 +384,14 @@ async def execute_default(self, args, context):
else:
print('Secure channel not established.')
await ble_stream.disconnect()
return CommandResultNone()


class DisconnectCommand(Command):

def get_help_string(self) -> str:
return 'Disconnect from device'

async def execute_default(self, args, context):
await context['ble_sstream'].close()
return CommandResultNone()
3 changes: 2 additions & 1 deletion tools/tcat_ble_client/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import shlex
from argparse import ArgumentParser
from ble.ble_stream_secure import BleStreamSecure
from cli.base_commands import (HelpCommand, HelloCommand, CommissionCommand, DecommissionCommand, GetDeviceIdCommand,
from cli.base_commands import (DisconnectCommand, HelpCommand, HelloCommand, CommissionCommand, DecommissionCommand, GetDeviceIdCommand,
GetPskdHash, GetExtPanIDCommand, GetNetworkNameCommand, GetProvisioningUrlCommand,
PingCommand, GetRandomNumberChallenge, ThreadStateCommand, ScanCommand, PresentHash)
from cli.dataset_commands import (DatasetCommand)
Expand All @@ -48,6 +48,7 @@ def __init__(self,
'hello': HelloCommand(),
'commission': CommissionCommand(),
'decommission': DecommissionCommand(),
'disconnect': DisconnectCommand(),
'device_id': GetDeviceIdCommand(),
'ext_panid': GetExtPanIDCommand(),
'provisioning_url': GetProvisioningUrlCommand(),
Expand Down

0 comments on commit 1cf14ee

Please sign in to comment.