From 145968429b0f2ae2dfc68d907ee09349ed785020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Kr=C3=B3lik?= <66667989+Damian-Nordic@users.noreply.github.com> Date: Mon, 30 Jan 2023 18:23:43 +0100 Subject: [PATCH] [chip-tool] Add flag to enable server interactions (#24695) Add "--advertise-operational" flag to the chip-tool's "interactive" 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 +++++ .../chip-tool/commands/interactive/InteractiveCommands.cpp | 5 +++++ .../chip-tool/commands/interactive/InteractiveCommands.h | 7 ++++++- 4 files changed, 17 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..854b0877df0cd5 100644 --- a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp +++ b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp @@ -276,3 +276,8 @@ bool InteractiveCommand::ParseCommand(char * command, int * status) return true; } + +bool InteractiveCommand::NeedsOperationalAdvertising() +{ + return mAdvertiseOperational.ValueOr(true); +} diff --git a/examples/chip-tool/commands/interactive/InteractiveCommands.h b/examples/chip-tool/commands/interactive/InteractiveCommands.h index 49e6432ccb7f01..0b4ead9f9cbbf5 100644 --- a/examples/chip-tool/commands/interactive/InteractiveCommands.h +++ b/examples/chip-tool/commands/interactive/InteractiveCommands.h @@ -31,15 +31,20 @@ class InteractiveCommand : public CHIPCommand public: InteractiveCommand(const char * name, Commands * commandsHandler, CredentialIssuerCommands * credsIssuerConfig) : CHIPCommand(name, credsIssuerConfig), mHandler(commandsHandler) - {} + { + AddArgument("advertise-operational", 0, 1, &mAdvertiseOperational, + "Advertise operational node over DNS-SD and accept incoming CASE sessions."); + } /////////// CHIPCommand Interface ///////// chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); } + bool NeedsOperationalAdvertising() override; bool ParseCommand(char * command, int * status); private: Commands * mHandler = nullptr; + chip::Optional mAdvertiseOperational; }; class InteractiveStartCommand : public InteractiveCommand