From 2402209e5b9b8a8e5d8f6b718a26551823ed7816 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Sat, 22 Oct 2022 15:07:38 +0200 Subject: [PATCH] [SetUpCodePairer] Pass the MRP parameters to RendezvousParameters in order to get them used in the initial pairing session (#23302) --- src/controller/CHIPDeviceController.cpp | 4 +-- src/controller/SetUpCodePairer.cpp | 13 +++++++++ .../secure_channel/RendezvousParameters.h | 28 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 6b71c9fbbd9fcd..af628edc572cc3 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -686,6 +686,7 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re mDeviceInPASEEstablishment = device; device->Init(GetControllerDeviceInitParams(), remoteDeviceId, peerAddress); + device->UpdateDeviceData(params.GetPeerAddress(), params.GetMRPConfig()); #if CONFIG_NETWORK_LAYER_BLE if (params.GetPeerAddress().GetTransportType() == Transport::Type::kBle) @@ -706,8 +707,7 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re } } #endif - // TODO: In some cases like PASE over IP, SAI and SII values from commissionable node service should be used - session = mSystemState->SessionMgr()->CreateUnauthenticatedSession(params.GetPeerAddress(), device->GetRemoteMRPConfig()); + session = mSystemState->SessionMgr()->CreateUnauthenticatedSession(params.GetPeerAddress(), params.GetMRPConfig()); VerifyOrExit(session.HasValue(), err = CHIP_ERROR_NO_MEMORY); // Allocate the exchange immediately before calling PASESession::Pair. diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 2f13f629a3e680..64b2459ce5faeb 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -344,6 +344,19 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], nodeData.resolutionData.port, interfaceId); mDiscoveredParameters.emplace(); mDiscoveredParameters.back().SetPeerAddress(peerAddress); + + if (nodeData.resolutionData.mrpRetryIntervalIdle.HasValue()) + { + auto interval = nodeData.resolutionData.mrpRetryIntervalIdle.Value(); + mDiscoveredParameters.back().SetIdleInterval(interval); + } + + if (nodeData.resolutionData.mrpRetryIntervalActive.HasValue()) + { + auto interval = nodeData.resolutionData.mrpRetryIntervalActive.Value(); + mDiscoveredParameters.back().SetActiveInterval(interval); + } + ConnectToDiscoveredDevice(); } diff --git a/src/protocols/secure_channel/RendezvousParameters.h b/src/protocols/secure_channel/RendezvousParameters.h index a5b76ed40482ee..ddc1281dd9d0e8 100644 --- a/src/protocols/secure_channel/RendezvousParameters.h +++ b/src/protocols/secure_channel/RendezvousParameters.h @@ -24,6 +24,7 @@ #endif // CONFIG_NETWORK_LAYER_BLE #include +#include #include namespace chip { @@ -31,6 +32,9 @@ namespace chip { // The largest supported value for Rendezvous discriminators const uint16_t kMaxRendezvousDiscriminatorValue = 0xFFF; +// The largest supported value for sleepy idle interval and sleepy active interval +constexpr uint32_t kMaxSleepyInterval = 3600000; + class RendezvousParameters { public: @@ -93,6 +97,28 @@ class RendezvousParameters bool HasConnectionObject() const { return false; } #endif // CONFIG_NETWORK_LAYER_BLE + bool HasMRPConfig() const { return mMRPConfig.HasValue(); } + ReliableMessageProtocolConfig GetMRPConfig() const { return mMRPConfig.ValueOr(GetDefaultMRPConfig()); } + RendezvousParameters & SetIdleInterval(System::Clock::Milliseconds32 interval) + { + if (!mMRPConfig.HasValue()) + { + mMRPConfig.Emplace(GetDefaultMRPConfig()); + } + mMRPConfig.Value().mIdleRetransTimeout = interval; + return *this; + } + + RendezvousParameters & SetActiveInterval(System::Clock::Milliseconds32 interval) + { + if (!mMRPConfig.HasValue()) + { + mMRPConfig.Emplace(GetDefaultMRPConfig()); + } + mMRPConfig.Value().mActiveRetransTimeout = interval; + return *this; + } + private: Transport::PeerAddress mPeerAddress; ///< the peer node address uint32_t mSetupPINCode = 0; ///< the target peripheral setup PIN Code @@ -101,6 +127,8 @@ class RendezvousParameters Spake2pVerifier mPASEVerifier; bool mHasPASEVerifier = false; + Optional mMRPConfig; + #if CONFIG_NETWORK_LAYER_BLE Ble::BleLayer * mBleLayer = nullptr; BLE_CONNECTION_OBJECT mConnectionObject = BLE_CONNECTION_UNINITIALIZED;