From a2b3d1db2bf21f707ac7ffdbd9b26a217084a376 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 27 Apr 2021 23:16:55 +0200 Subject: [PATCH] Add OnNetwork pairing command to chip-tool (#6309) --- examples/chip-tool/commands/pairing/Commands.h | 10 ++++++++-- examples/chip-tool/commands/pairing/PairingCommand.cpp | 4 ++++ examples/chip-tool/commands/pairing/PairingCommand.h | 2 ++ src/app/server/Server.cpp | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/pairing/Commands.h b/examples/chip-tool/commands/pairing/Commands.h index 5240cae3fd011c..70008a924a0a8c 100644 --- a/examples/chip-tool/commands/pairing/Commands.h +++ b/examples/chip-tool/commands/pairing/Commands.h @@ -32,6 +32,12 @@ class PairBypass : public PairingCommand PairBypass() : PairingCommand("bypass", PairingMode::Bypass, PairingNetworkType::None) {} }; +class PairOnNetwork : public PairingCommand +{ +public: + PairOnNetwork() : PairingCommand("onnetwork", PairingMode::OnNetwork, PairingNetworkType::None) {} +}; + class PairBleWiFi : public PairingCommand { public: @@ -61,8 +67,8 @@ void registerCommandsPairing(Commands & commands) const char * clusterName = "Pairing"; commands_list clusterCommands = { - make_unique(), make_unique(), make_unique(), - make_unique(), make_unique(), make_unique(), + make_unique(), make_unique(), make_unique(), make_unique(), + make_unique(), make_unique(), make_unique(), }; commands.Register(clusterName, clusterCommands); diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 6b212fcb50a607..81b19cd68b20a6 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -36,6 +36,9 @@ CHIP_ERROR PairingCommand::Run(PersistentStorage & storage, NodeId localId, Node .mDeviceAddressUpdateDelegate = this, }; + err = mCommissioner.SetUdpListenPort(storage.GetListenPort()); + VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err))); + err = mCommissioner.Init(localId, params, this); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err))); @@ -70,6 +73,7 @@ CHIP_ERROR PairingCommand::RunInternal(NodeId remoteId) case PairingMode::Ble: err = Pair(remoteId, PeerAddress::BLE()); break; + case PairingMode::OnNetwork: case PairingMode::SoftAP: err = Pair(remoteId, PeerAddress::UDP(mRemoteAddr.address, mRemotePort)); break; diff --git a/examples/chip-tool/commands/pairing/PairingCommand.h b/examples/chip-tool/commands/pairing/PairingCommand.h index d54832f3f92637..c03c299353f955 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.h +++ b/examples/chip-tool/commands/pairing/PairingCommand.h @@ -30,6 +30,7 @@ enum class PairingMode Ble, SoftAP, Ethernet, + OnNetwork, }; enum class PairingNetworkType @@ -75,6 +76,7 @@ class PairingCommand : public Command, AddArgument("setup-pin-code", 0, 134217727, &mSetupPINCode); AddArgument("discriminator", 0, 4096, &mDiscriminator); break; + case PairingMode::OnNetwork: case PairingMode::SoftAP: AddArgument("fabric-id", 0, UINT64_MAX, &mFabricId); AddArgument("setup-pin-code", 0, 134217727, &mSetupPINCode); diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 4346b7d26d0feb..dc4f342074e14d 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -492,6 +492,11 @@ void InitServer(AppDelegate * delegate) InitDataModelHandler(); gCallbacks.SetDelegate(delegate); +#if CHIP_DEVICE_LAYER_TARGET_DARWIN + err = PersistedStorage::KeyValueStoreMgrImpl().Init("chip.store"); + SuccessOrExit(err); +#endif + err = gRendezvousServer.Init(delegate, &gServerStorage); SuccessOrExit(err);