From f5678d1d32fccb4234868d54a91d731a1ac766f1 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 27 Jan 2023 11:37:26 +0100 Subject: [PATCH] [chip-tool] Add flag to enable server interactions Add "--advertise-operational" flag to the chip-tool's "interactive start" command that enables server features, including advertising operational services. This feature is needed to test persistent subscriptions using chip-tool, which requires that chip-tool be discoverable after the publisher node reboots. --- examples/chip-tool/commands/common/CHIPCommand.cpp | 1 + examples/chip-tool/commands/common/CHIPCommand.h | 5 +++++ .../commands/interactive/InteractiveCommands.cpp | 5 +++++ .../chip-tool/commands/interactive/InteractiveCommands.h | 8 +++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 53dc8184e8d395..7b7e24a1e771c8 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -102,6 +102,7 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack() factoryInitParams.fabricIndependentStorage = &mDefaultStorage; factoryInitParams.operationalKeystore = &mOperationalKeystore; factoryInitParams.opCertStore = &mOpCertStore; + factoryInitParams.enableServerInteractions = NeedsOperationalAdvertising(); // Init group data provider that will be used for all group keys and IPKs for the // chip-tool-configured fabrics. This is OK to do once since the fabric tables diff --git a/examples/chip-tool/commands/common/CHIPCommand.h b/examples/chip-tool/commands/common/CHIPCommand.h index 1b5b3690ea3ee6..e062b0d85023cc 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.h +++ b/examples/chip-tool/commands/common/CHIPCommand.h @@ -123,6 +123,11 @@ class CHIPCommand : public Command // use member values that Shutdown will normally reset. virtual bool DeferInteractiveCleanup() { return false; } + // If true, the controller will be created with server capabilities enabled, + // such as advertising operational nodes over DNS-SD and accepting incoming + // CASE sessions. + virtual bool NeedsOperationalAdvertising() { return false; } + // Execute any deferred cleanups. Used when exiting interactive mode. static void ExecuteDeferredCleanups(intptr_t ignored); diff --git a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp index f3c76c28881fb1..7c8767a2c50a42 100644 --- a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp +++ b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp @@ -262,6 +262,11 @@ CHIP_ERROR InteractiveStartCommand::RunCommand() return CHIP_NO_ERROR; } +bool InteractiveStartCommand::NeedsOperationalAdvertising() +{ + return mAdvertiseOperational.ValueOr(true); +} + bool InteractiveCommand::ParseCommand(char * command, int * status) { if (strcmp(command, kInteractiveModeStopCommand) == 0) diff --git a/examples/chip-tool/commands/interactive/InteractiveCommands.h b/examples/chip-tool/commands/interactive/InteractiveCommands.h index 49e6432ccb7f01..429042166a1b0b 100644 --- a/examples/chip-tool/commands/interactive/InteractiveCommands.h +++ b/examples/chip-tool/commands/interactive/InteractiveCommands.h @@ -47,10 +47,16 @@ class InteractiveStartCommand : public InteractiveCommand public: InteractiveStartCommand(Commands * commandsHandler, CredentialIssuerCommands * credsIssuerConfig) : InteractiveCommand("start", commandsHandler, credsIssuerConfig) - {} + { + AddArgument("advertise-operational", 0, 1, &mAdvertiseOperational); + } /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; + bool NeedsOperationalAdvertising() override; + +private: + chip::Optional mAdvertiseOperational; }; class InteractiveServerCommand : public InteractiveCommand, public WebSocketServerDelegate, public RemoteDataModelLoggerDelegate