Skip to content

Commit

Permalink
[SetUpCodePairer] Pass the MRP parameters to RendezvousParameters in …
Browse files Browse the repository at this point in the history
…order to get them used in the initial pairing session (#23302)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jan 4, 2023
1 parent 7ca75a6 commit 2402209
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/controller/SetUpCodePairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
28 changes: 28 additions & 0 deletions src/protocols/secure_channel/RendezvousParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
#endif // CONFIG_NETWORK_LAYER_BLE

#include <lib/support/logging/CHIPLogging.h>
#include <messaging/ReliableMessageProtocolConfig.h>
#include <protocols/secure_channel/PASESession.h>

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:
Expand Down Expand Up @@ -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
Expand All @@ -101,6 +127,8 @@ class RendezvousParameters
Spake2pVerifier mPASEVerifier;
bool mHasPASEVerifier = false;

Optional<ReliableMessageProtocolConfig> mMRPConfig;

#if CONFIG_NETWORK_LAYER_BLE
Ble::BleLayer * mBleLayer = nullptr;
BLE_CONNECTION_OBJECT mConnectionObject = BLE_CONNECTION_UNINITIALIZED;
Expand Down

0 comments on commit 2402209

Please sign in to comment.