diff --git a/tools/tcat_ble_client/bbtc.py b/tools/tcat_ble_client/bbtc.py index 2824e5aca..a9be1f539 100755 --- a/tools/tcat_ble_client/bbtc.py +++ b/tools/tcat_ble_client/bbtc.py @@ -96,7 +96,7 @@ async def main(): quit_with_reason('TLS handshake failure') ds = ThreadDataset() - cli = CLI(ds, ble_sstream) + cli = CLI(ds, args, ble_sstream) loop = asyncio.get_running_loop() print('Enter \'help\' to see available commands' ' or \'exit\' to exit the application.') while True: diff --git a/tools/tcat_ble_client/cli/base_commands.py b/tools/tcat_ble_client/cli/base_commands.py index 411bc821e..b086ee0d3 100644 --- a/tools/tcat_ble_client/cli/base_commands.py +++ b/tools/tcat_ble_client/cli/base_commands.py @@ -251,10 +251,11 @@ class ScanCommand(Command): print(f'Connecting to {device}') ble_stream = await BleStream.create(device.address, BBTC_SERVICE_UUID, BBTC_TX_CHAR_UUID, BBTC_RX_CHAR_UUID) ble_sstream = BleStreamSecure(ble_stream) + cert_path = context['cmd_args'].cert_path if context['cmd_args'] else 'auth' ble_sstream.load_cert( - certfile=path.join('auth', 'commissioner_cert.pem'), - keyfile=path.join('auth', 'commissioner_key.pem'), - cafile=path.join('auth', 'ca_cert.pem'), + certfile=path.join(cert_path, 'commissioner_cert.pem'), + keyfile=path.join(cert_path, 'commissioner_key.pem'), + cafile=path.join(cert_path, 'ca_cert.pem'), ) print('Setting up secure channel...') diff --git a/tools/tcat_ble_client/cli/cli.py b/tools/tcat_ble_client/cli/cli.py index 01e33bac3..9835c950a 100644 --- a/tools/tcat_ble_client/cli/cli.py +++ b/tools/tcat_ble_client/cli/cli.py @@ -25,9 +25,9 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ - import readline import shlex +from argparse import ArgumentParser from ble.ble_stream_secure import BleStreamSecure from cli.base_commands import (HelpCommand, HelloCommand, CommissionCommand, DecommissionCommand, GetDeviceIdCommand, GetExtPanIDCommand, GetNetworkNameCommand, GetProvisioningUrlCommand, PingCommand, @@ -39,7 +39,10 @@ from typing import Optional class CLI: - def __init__(self, dataset: ThreadDataset, ble_sstream: Optional[BleStreamSecure] = None): + def __init__(self, + dataset: ThreadDataset, + cmd_args: Optional[ArgumentParser] = None, + ble_sstream: Optional[BleStreamSecure] = None): self._commands = { 'help': HelpCommand(), 'hello': HelloCommand(), @@ -54,7 +57,12 @@ class CLI: 'thread': ThreadStateCommand(), 'scan': ScanCommand(), } - self._context = {'ble_sstream': ble_sstream, 'dataset': dataset, 'commands': self._commands} + self._context = { + 'ble_sstream': ble_sstream, + 'dataset': dataset, + 'commands': self._commands, + 'cmd_args': cmd_args + } readline.set_completer(self.completer) readline.parse_and_bind('tab: complete')