diff --git a/examples/chef/efr32/include/CHIPProjectConfig.h b/examples/chef/efr32/include/CHIPProjectConfig.h index 123870156bcd4d..5904b776cd601d 100644 --- a/examples/chef/efr32/include/CHIPProjectConfig.h +++ b/examples/chef/efr32/include/CHIPProjectConfig.h @@ -128,7 +128,7 @@ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) /** - * @def CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + * @def CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL * * @brief * Active retransmit interval, or time to wait before retransmission after @@ -138,6 +138,6 @@ * needs (e.g. sleeping period) using Service Discovery TXT record CRA key. * */ -#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (2000_ms32) +#define CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL (2000_ms32) #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/chip-tool/commands/discover/Commands.h b/examples/chip-tool/commands/discover/Commands.h index f033e8d4341967..f7a41183bedf56 100644 --- a/examples/chip-tool/commands/discover/Commands.h +++ b/examples/chip-tool/commands/discover/Commands.h @@ -48,8 +48,10 @@ class Resolve : public DiscoverCommand, public chip::AddressResolve::NodeListene result.address.ToString(addrBuffer); ChipLogProgress(chipTool, "NodeId Resolution: %" PRIu64 " at %s", peerId.GetNodeId(), addrBuffer); - ChipLogProgress(chipTool, " MRP retry interval (idle): %" PRIu32 "ms", result.mrpConfig.mIdleRetransTimeout.count()); - ChipLogProgress(chipTool, " MRP retry interval (active): %" PRIu32 "ms", result.mrpConfig.mActiveRetransTimeout.count()); + ChipLogProgress(chipTool, " MRP retry interval (idle): %" PRIu32 "ms", + result.mrpRemoteConfig.mIdleRetransTimeout.count()); + ChipLogProgress(chipTool, " MRP retry interval (active): %" PRIu32 "ms", + result.mrpRemoteConfig.mActiveRetransTimeout.count()); ChipLogProgress(chipTool, " Supports TCP: %s", result.supportsTcp ? "yes" : "no"); SetCommandExitStatus(CHIP_NO_ERROR); } diff --git a/examples/light-switch-app/efr32/include/CHIPProjectConfig.h b/examples/light-switch-app/efr32/include/CHIPProjectConfig.h index 123870156bcd4d..5904b776cd601d 100644 --- a/examples/light-switch-app/efr32/include/CHIPProjectConfig.h +++ b/examples/light-switch-app/efr32/include/CHIPProjectConfig.h @@ -128,7 +128,7 @@ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) /** - * @def CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + * @def CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL * * @brief * Active retransmit interval, or time to wait before retransmission after @@ -138,6 +138,6 @@ * needs (e.g. sleeping period) using Service Discovery TXT record CRA key. * */ -#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (2000_ms32) +#define CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL (2000_ms32) #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/lighting-app/efr32/include/CHIPProjectConfig.h b/examples/lighting-app/efr32/include/CHIPProjectConfig.h index 244faf0af4e0ba..60a8d1ea0f471d 100644 --- a/examples/lighting-app/efr32/include/CHIPProjectConfig.h +++ b/examples/lighting-app/efr32/include/CHIPProjectConfig.h @@ -128,7 +128,7 @@ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) /** - * @def CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + * @def CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL * * @brief * Active retransmit interval, or time to wait before retransmission after @@ -138,6 +138,6 @@ * needs (e.g. sleeping period) using Service Discovery TXT record CRA key. * */ -#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (2000_ms32) +#define CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL (2000_ms32) #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/lock-app/efr32/include/CHIPProjectConfig.h b/examples/lock-app/efr32/include/CHIPProjectConfig.h index 118cb5e3fd31f7..9980ca347d507b 100644 --- a/examples/lock-app/efr32/include/CHIPProjectConfig.h +++ b/examples/lock-app/efr32/include/CHIPProjectConfig.h @@ -129,7 +129,7 @@ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) /** - * @def CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + * @def CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL * * @brief * Active retransmit interval, or time to wait before retransmission after @@ -139,4 +139,4 @@ * needs (e.g. sleeping period) using Service Discovery TXT record CRA key. * */ -#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (2000_ms32) +#define CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL (2000_ms32) diff --git a/examples/window-app/efr32/include/CHIPProjectConfig.h b/examples/window-app/efr32/include/CHIPProjectConfig.h index 1df627cbef00d9..14ebab2b3009e8 100644 --- a/examples/window-app/efr32/include/CHIPProjectConfig.h +++ b/examples/window-app/efr32/include/CHIPProjectConfig.h @@ -165,7 +165,7 @@ #define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT (15 * 60 * 1000) /** - * @def CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + * @def CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL * * @brief * Active retransmit interval, or time to wait before retransmission after @@ -175,6 +175,6 @@ * needs (e.g. sleeping period) using Service Discovery TXT record CRA key. * */ -#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (2000_ms32) +#define CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL (2000_ms32) #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/src/app/DeviceProxy.h b/src/app/DeviceProxy.h index 3f4bdb89649cc7..2c0d26dd24b2cc 100644 --- a/src/app/DeviceProxy.h +++ b/src/app/DeviceProxy.h @@ -72,7 +72,7 @@ class DLL_EXPORT DeviceProxy protected: virtual bool IsSecureConnected() const = 0; - ReliableMessageProtocolConfig mRemoteMRPConfig = GetLocalMRPConfig(); + ReliableMessageProtocolConfig mRemoteMRPConfig = GetDefaultMRPConfig(); }; } // namespace chip diff --git a/src/app/OperationalDeviceProxy.cpp b/src/app/OperationalDeviceProxy.cpp index 0d84e4a3aab876..8193d8c78286fd 100644 --- a/src/app/OperationalDeviceProxy.cpp +++ b/src/app/OperationalDeviceProxy.cpp @@ -404,7 +404,7 @@ CHIP_ERROR OperationalDeviceProxy::LookupPeerAddress() void OperationalDeviceProxy::OnNodeAddressResolved(const PeerId & peerId, const ResolveResult & result) { - UpdateDeviceData(result.address, result.mrpConfig); + UpdateDeviceData(result.address, result.mrpRemoteConfig); } void OperationalDeviceProxy::OnNodeAddressResolutionFailed(const PeerId & peerId, CHIP_ERROR reason) diff --git a/src/app/server/CommissioningWindowManager.cpp b/src/app/server/CommissioningWindowManager.cpp index f92cc2913fa5a7..0996e4fa80fd41 100644 --- a/src/app/server/CommissioningWindowManager.cpp +++ b/src/app/server/CommissioningWindowManager.cpp @@ -219,9 +219,8 @@ CHIP_ERROR CommissioningWindowManager::AdvertiseAndListenForPASE() if (mUseECM) { ReturnErrorOnFailure(SetTemporaryDiscriminator(mECMDiscriminator)); - ReturnErrorOnFailure(mPairingSession.WaitForPairing( - mServer->GetSecureSessionManager(), mECMPASEVerifier, mECMIterations, ByteSpan(mECMSalt, mECMSaltLength), - Optional::Value(GetLocalMRPConfig()), this)); + ReturnErrorOnFailure(mPairingSession.WaitForPairing(mServer->GetSecureSessionManager(), mECMPASEVerifier, mECMIterations, + ByteSpan(mECMSalt, mECMSaltLength), GetLocalMRPConfig(), this)); } else { @@ -243,8 +242,7 @@ CHIP_ERROR CommissioningWindowManager::AdvertiseAndListenForPASE() ReturnErrorOnFailure(verifier.Deserialize(ByteSpan(serializedVerifier))); ReturnErrorOnFailure(mPairingSession.WaitForPairing(mServer->GetSecureSessionManager(), verifier, iterationCount, saltSpan, - Optional::Value(GetLocalMRPConfig()), - this)); + GetLocalMRPConfig(), this)); } ReturnErrorOnFailure(StartAdvertisement()); diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp index b05ef7a3fb07bc..85301c60eb17ea 100644 --- a/src/app/server/Dnssd.cpp +++ b/src/app/server/Dnssd.cpp @@ -258,7 +258,7 @@ CHIP_ERROR DnssdServer::AdvertiseOperational() .SetMac(mac) .SetPort(GetSecuredPort()) .SetInterfaceId(GetInterfaceId()) - .SetMRPConfig(GetLocalMRPConfig()) + .SetLocalMRPConfig(GetLocalMRPConfig()) .SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)) .EnableIpV4(true); @@ -351,7 +351,7 @@ CHIP_ERROR DnssdServer::Advertise(bool commissionableNode, chip::Dnssd::Commissi advertiseParameters.SetRotatingDeviceId(chip::Optional::Value(rotatingDeviceIdHexBuffer)); #endif - advertiseParameters.SetMRPConfig(GetLocalMRPConfig()).SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)); + advertiseParameters.SetLocalMRPConfig(GetLocalMRPConfig()).SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)); if (!HaveOperationalCredentials()) { diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index eb7dd50d444163..2b5a638a885222 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -270,7 +270,7 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) .fabricTable = &mFabrics, .clientPool = &mCASEClientPool, .groupDataProvider = mGroupsProvider, - .mrpLocalConfig = Optional(GetLocalMRPConfig()), + .mrpLocalConfig = GetLocalMRPConfig(), }, .devicePool = &mDevicePool, }; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index f7d26e5fb6da14..b0196d45214d04 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -634,8 +634,7 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re exchangeCtxt = mSystemState->ExchangeMgr()->NewContext(session.Value(), &device->GetPairing()); VerifyOrExit(exchangeCtxt != nullptr, err = CHIP_ERROR_INTERNAL); - err = device->GetPairing().Pair(*mSystemState->SessionMgr(), params.GetSetupPINCode(), - Optional::Value(GetLocalMRPConfig()), exchangeCtxt, this); + err = device->GetPairing().Pair(*mSystemState->SessionMgr(), params.GetSetupPINCode(), GetLocalMRPConfig(), exchangeCtxt, this); SuccessOrExit(err); exit: diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index f61e3f92170d1b..7c7931467885b3 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -241,7 +241,7 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) .fabricTable = stateParams.fabricTable, .clientPool = stateParams.caseClientPool, .groupDataProvider = stateParams.groupDataProvider, - .mrpLocalConfig = Optional::Value(GetLocalMRPConfig()), + .mrpLocalConfig = GetLocalMRPConfig(), }; CASESessionManagerConfig sessionManagerConfig = { diff --git a/src/lib/address_resolve/AddressResolve.h b/src/lib/address_resolve/AddressResolve.h index 789fcddce7f104..c85a5127f3045e 100644 --- a/src/lib/address_resolve/AddressResolve.h +++ b/src/lib/address_resolve/AddressResolve.h @@ -32,10 +32,10 @@ namespace AddressResolve { struct ResolveResult { Transport::PeerAddress address; - ReliableMessageProtocolConfig mrpConfig; + ReliableMessageProtocolConfig mrpRemoteConfig; bool supportsTcp = false; - ResolveResult() : address(Transport::Type::kUdp), mrpConfig(GetLocalMRPConfig()) {} + ResolveResult() : address(Transport::Type::kUdp), mrpRemoteConfig(GetDefaultMRPConfig()) {} }; /// Represents an object interested in callbacks for a resolve operation. diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 48e93256d1789c..42fa5a9d35d83b 100644 --- a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp +++ b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp @@ -259,8 +259,8 @@ void Resolver::OnOperationalNodeResolved(const Dnssd::ResolvedNodeData & nodeDat result.address.SetPort(nodeData.resolutionData.port); result.address.SetInterface(nodeData.resolutionData.interfaceId); - result.mrpConfig = nodeData.resolutionData.GetMRPConfig(); - result.supportsTcp = nodeData.resolutionData.supportsTcp; + result.mrpRemoteConfig = nodeData.resolutionData.GetRemoteMRPConfig(); + result.supportsTcp = nodeData.resolutionData.supportsTcp; for (size_t i = 0; i < nodeData.resolutionData.numIPs; i++) { diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index 9a87d1f2c63ec6..7f6d1b3e34a517 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -54,8 +54,8 @@ class PrintOutNodeListener : public chip::AddressResolve::NodeListener ChipLogProgress(Discovery, "Resolve completed: %s", addr_string); ChipLogProgress(Discovery, " Supports TCP: %s", result.supportsTcp ? "YES" : "NO"); - ChipLogProgress(Discovery, " MRP IDLE retransmit timeout: %u ms", result.mrpConfig.mIdleRetransTimeout.count()); - ChipLogProgress(Discovery, " MRP ACTIVE retransmit timeout: %u ms", result.mrpConfig.mActiveRetransTimeout.count()); + ChipLogProgress(Discovery, " MRP IDLE retransmit timeout: %u ms", result.mrpRemoteConfig.mIdleRetransTimeout.count()); + ChipLogProgress(Discovery, " MRP ACTIVE retransmit timeout: %u ms", result.mrpRemoteConfig.mActiveRetransTimeout.count()); NotifyDone(); } diff --git a/src/lib/dnssd/Advertiser.h b/src/lib/dnssd/Advertiser.h index d99d4864ec1302..710fc64bc4596f 100644 --- a/src/lib/dnssd/Advertiser.h +++ b/src/lib/dnssd/Advertiser.h @@ -88,12 +88,12 @@ class BaseAdvertisingParams const chip::ByteSpan GetMac() const { return chip::ByteSpan(mMacStorage, mMacLength); } // Common Flags - Derived & SetMRPConfig(const ReliableMessageProtocolConfig & config) + Derived & SetLocalMRPConfig(const Optional & config) { - mMRPConfig.SetValue(config); + mLocalMRPConfig = config; return *reinterpret_cast(this); } - const Optional & GetMRPConfig() const { return mMRPConfig; } + const Optional & GetLocalMRPConfig() const { return mLocalMRPConfig; } Derived & SetTcpSupported(Optional tcpSupported) { mTcpSupported = tcpSupported; @@ -107,7 +107,7 @@ class BaseAdvertisingParams bool mEnableIPv4 = true; uint8_t mMacStorage[kMaxMacSize] = {}; size_t mMacLength = 0; - Optional mMRPConfig; + Optional mLocalMRPConfig; Optional mTcpSupported; }; diff --git a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp index 4db3f0676c89c0..b419027ab48e1a 100644 --- a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp @@ -222,7 +222,7 @@ class AdvertiserMinMdns : public ServiceAdvertiser, CHIP_ERROR AddCommonTxtEntries(const BaseAdvertisingParams & params, CommonTxtEntryStorage & storage, char ** txtFields, size_t & numTxtFields) { - auto optionalMrp = params.GetMRPConfig(); + auto optionalMrp = params.GetLocalMRPConfig(); if (optionalMrp.HasValue()) { diff --git a/src/lib/dnssd/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index 45b7c1766e05f1..1be6d969787869 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -277,7 +277,7 @@ CHIP_ERROR CopyTxtRecord(TxtFieldKey key, char * buffer, size_t bufferLen, const return CopyTextRecordValue(buffer, bufferLen, params.GetTcpSupported()); case TxtFieldKey::kSleepyIdleInterval: case TxtFieldKey::kSleepyActiveInterval: - return CopyTextRecordValue(buffer, bufferLen, params.GetMRPConfig(), key == TxtFieldKey::kSleepyIdleInterval); + return CopyTextRecordValue(buffer, bufferLen, params.GetLocalMRPConfig(), key == TxtFieldKey::kSleepyIdleInterval); default: return CHIP_ERROR_INVALID_ARGUMENT; } diff --git a/src/lib/dnssd/Resolver.h b/src/lib/dnssd/Resolver.h index e97c11b84a6570..b9f6facffb7281 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -56,9 +56,9 @@ struct CommonResolutionData bool IsValid() const { return !IsHost("") && (numIPs > 0) && (ipAddress[0] != chip::Inet::IPAddress::Any); } - ReliableMessageProtocolConfig GetMRPConfig() const + ReliableMessageProtocolConfig GetRemoteMRPConfig() const { - const ReliableMessageProtocolConfig defaultConfig = GetLocalMRPConfig(); + const ReliableMessageProtocolConfig defaultConfig = GetDefaultMRPConfig(); return ReliableMessageProtocolConfig(GetMrpRetryIntervalIdle().ValueOr(defaultConfig.mIdleRetransTimeout), GetMrpRetryIntervalActive().ValueOr(defaultConfig.mActiveRetransTimeout)); } diff --git a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp index 0741cd6933b4fb..e8009fe33d211f 100644 --- a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp @@ -79,7 +79,7 @@ OperationalAdvertisingParameters operationalParams1 = .SetPort(CHIP_PORT) .EnableIpV4(true) .SetTcpSupported(chip::Optional(false)) - .SetMRPConfig(ReliableMessageProtocolConfig(32_ms32, 30_ms32)); // Match SII, SAI below + .SetLocalMRPConfig(Optional::Value(32_ms32, 30_ms32)); // Match SII, SAI below OperationalAdvertisingParameters operationalParams2 = OperationalAdvertisingParameters().SetPeerId(kPeerId2).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true); OperationalAdvertisingParameters operationalParams3 = @@ -180,7 +180,7 @@ CommissionAdvertisingParameters commissionableNodeParamsLargeEnhanced = .SetRotatingDeviceId(chip::Optional("id_that_spins")) .SetTcpSupported(chip::Optional(true)) // 3600005 is more than the max so should be adjusted down - .SetMRPConfig(ReliableMessageProtocolConfig(3600000_ms32, 3600005_ms32)); + .SetLocalMRPConfig(Optional::Value(3600000_ms32, 3600005_ms32)); QNamePart txtCommissionableNodeParamsLargeEnhancedParts[] = { "D=22", "VP=555+897", "CM=2", "DT=70000", "DN=testy-test", "RI=id_that_spins", "PI=Pair me", "PH=3", "SAI=3600000", "SII=3600000", "T=1" }; diff --git a/src/lib/dnssd/platform/tests/TestPlatform.cpp b/src/lib/dnssd/platform/tests/TestPlatform.cpp index d7125f05b8fc41..47e70296f92632 100644 --- a/src/lib/dnssd/platform/tests/TestPlatform.cpp +++ b/src/lib/dnssd/platform/tests/TestPlatform.cpp @@ -46,13 +46,14 @@ test::ExpectedCall operationalCall1 = test::ExpectedCall() .SetInstanceName("BEEFBEEFF00DF00D-1111222233334444") .SetHostName(host) .AddSubtype("_IBEEFBEEFF00DF00D"); -OperationalAdvertisingParameters operationalParams2 = OperationalAdvertisingParameters() - .SetPeerId(kPeerId2) - .SetMac(ByteSpan(kMac)) - .SetPort(CHIP_PORT) - .EnableIpV4(true) - .SetMRPConfig({ 32_ms32, 30_ms32 }) // SII and SAI to match below - .SetTcpSupported(Optional(true)); +OperationalAdvertisingParameters operationalParams2 = + OperationalAdvertisingParameters() + .SetPeerId(kPeerId2) + .SetMac(ByteSpan(kMac)) + .SetPort(CHIP_PORT) + .EnableIpV4(true) + .SetLocalMRPConfig(Optional::Value(32_ms32, 30_ms32)) // SII and SAI to match below + .SetTcpSupported(Optional(true)); test::ExpectedCall operationalCall2 = test::ExpectedCall() .SetProtocol(DnssdServiceProtocol::kDnssdProtocolTcp) .SetServiceName("_matter") @@ -95,7 +96,7 @@ CommissionAdvertisingParameters commissionableNodeParamsLargeBasic = .SetRotatingDeviceId(chip::Optional("id_that_spins")) .SetTcpSupported(chip::Optional(true)) // 3600005 is over the max, so this should be adjusted by the platform - .SetMRPConfig({ 3600000_ms32, 3600005_ms32 }); + .SetLocalMRPConfig(Optional::Value(3600000_ms32, 3600005_ms32)); test::ExpectedCall commissionableLargeBasic = test::ExpectedCall() .SetProtocol(DnssdServiceProtocol::kDnssdProtocolUdp) diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 8649bfa1889b6b..53bf730763879f 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -571,21 +571,21 @@ void TestIsDeviceSleepyIdle(nlTestSuite * inSuite, void * inContext) char key[4]; char val[32]; NodeData nodeData; - const ReliableMessageProtocolConfig defaultMRPConfig(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL, - CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); + const ReliableMessageProtocolConfig defaultMRPConfig(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, + CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL); // No key/val set, so the device can't be sleepy NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig)); // If the interval is the default value, the device is not sleepy strcpy(key, "SII"); - sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL.count())); + sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL.count())); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig)); // If the interval is greater than the default value, the device is sleepy sprintf(key, "SII"); - sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL.count() + 1)); + sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL.count() + 1)); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); NL_TEST_ASSERT(inSuite, nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig)); } @@ -597,21 +597,21 @@ void TestIsDeviceSleepyActive(nlTestSuite * inSuite, void * inContext) char key[4]; char val[32]; NodeData nodeData; - const ReliableMessageProtocolConfig defaultMRPConfig(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL, - CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); + const ReliableMessageProtocolConfig defaultMRPConfig(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, + CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL); // No key/val set, so the device can't be sleepy NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig)); // If the interval is the default value, the device is not sleepy sprintf(key, "SAI"); - sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL.count())); + sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL.count())); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig)); // If the interval is greater than the default value, the device is sleepy strcpy(key, "SAI"); - sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL.count() + 1)); + sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL.count() + 1)); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); NL_TEST_ASSERT(inSuite, nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig)); } diff --git a/src/messaging/BUILD.gn b/src/messaging/BUILD.gn index 5e596b615ac596..ecb009d02e9441 100644 --- a/src/messaging/BUILD.gn +++ b/src/messaging/BUILD.gn @@ -22,9 +22,8 @@ declare_args() { defines = [] if (chip_case_retry_delta != "") { - defines += [ - "CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL=${chip_case_retry_delta}", - ] + defines += + [ "CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL=${chip_case_retry_delta}" ] } source_set("messaging_mrp_config") { diff --git a/src/messaging/ReliableMessageProtocolConfig.cpp b/src/messaging/ReliableMessageProtocolConfig.cpp index 6132a240cbaed3..ef9110964adc10 100644 --- a/src/messaging/ReliableMessageProtocolConfig.cpp +++ b/src/messaging/ReliableMessageProtocolConfig.cpp @@ -31,24 +31,32 @@ namespace chip { using namespace System::Clock::Literals; -ReliableMessageProtocolConfig GetLocalMRPConfig() +ReliableMessageProtocolConfig GetDefaultMRPConfig() { - ReliableMessageProtocolConfig config(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL, - CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); + // Default MRP intervals are defined in spec <2.11.3. Parameters and Constants> + static constexpr const System::Clock::Milliseconds32 idleRetransTimeout = 4000_ms32; + static constexpr const System::Clock::Milliseconds32 activeRetransTimeout = 300_ms32; + return ReliableMessageProtocolConfig(idleRetransTimeout, activeRetransTimeout); +} + +Optional GetLocalMRPConfig() +{ + ReliableMessageProtocolConfig config(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL); #if CHIP_DEVICE_CONFIG_ENABLE_SED DeviceLayer::ConnectivityManager::SEDIntervalsConfig sedIntervalsConfig; if (DeviceLayer::ConnectivityMgr().GetSEDIntervalsConfig(sedIntervalsConfig) == CHIP_NO_ERROR) { - // Increase default MRP retry intervals by SED intervals. That is, intervals for + // Increase local MRP retry intervals by SED intervals. That is, intervals for // which the device can be at sleep and not be able to receive any messages). config.mIdleRetransTimeout += sedIntervalsConfig.IdleIntervalMS; config.mActiveRetransTimeout += sedIntervalsConfig.ActiveIntervalMS; } #endif - return config; + return (config == GetDefaultMRPConfig()) ? Optional::Missing() + : Optional::Value(config); } } // namespace chip diff --git a/src/messaging/ReliableMessageProtocolConfig.h b/src/messaging/ReliableMessageProtocolConfig.h index f7876fea1fcf72..f05f4b05d9cc97 100644 --- a/src/messaging/ReliableMessageProtocolConfig.h +++ b/src/messaging/ReliableMessageProtocolConfig.h @@ -25,13 +25,14 @@ */ #pragma once +#include #include #include namespace chip { /** - * @def CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + * @def CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL * * @brief * Active retransmit interval, or time to wait before retransmission after @@ -41,12 +42,12 @@ namespace chip { * needs (e.g. sleeping period) using Service Discovery TXT record CRA key. * */ -#ifndef CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL -#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (300_ms32) -#endif // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL +#ifndef CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL +#define CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL (300_ms32) +#endif // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL /** - * @def CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL + * @def CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL * * @brief * Initial base retransmission interval, or time to wait before retransmission after first @@ -55,9 +56,9 @@ namespace chip { * This is the default value, that might be adjusted by end device depending on its * needs (e.g. sleeping period) using Service Discovery TXT record CRI key. */ -#ifndef CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL -#define CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL (5000_ms32) -#endif // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL +#ifndef CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL +#define CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL (5000_ms32) +#endif // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL /** * @def CHIP_CONFIG_RMP_DEFAULT_ACK_TIMEOUT @@ -115,8 +116,24 @@ struct ReliableMessageProtocolConfig // Configurable timeout in msec for retransmission of all subsequent messages. System::Clock::Milliseconds32 mActiveRetransTimeout; + + bool operator==(const ReliableMessageProtocolConfig & that) const + { + return mIdleRetransTimeout == that.mIdleRetransTimeout && mActiveRetransTimeout == that.mActiveRetransTimeout; + } }; -ReliableMessageProtocolConfig GetLocalMRPConfig(); +/// @brief The default MRP config. The value is defined by spec, and shall be same for all implementations, +ReliableMessageProtocolConfig GetDefaultMRPConfig(); + +/** + * @brief The custom value of MRP config for the platform. + * @return Missing If the value is same as default value defined by spec + * Value The custom value for the platform + * + * @note This value is not used by our MRP manager. The value is advertised via mDNS or during PASE/CASE paring, and our peers + * use it when communicating with us. + */ +Optional GetLocalMRPConfig(); } // namespace chip diff --git a/src/messaging/tests/MessagingContext.cpp b/src/messaging/tests/MessagingContext.cpp index a93bae5566a3e0..09f2331330ec44 100644 --- a/src/messaging/tests/MessagingContext.cpp +++ b/src/messaging/tests/MessagingContext.cpp @@ -174,14 +174,16 @@ void MessagingContext::ExpireSessionBobToFriends() Messaging::ExchangeContext * MessagingContext::NewUnauthenticatedExchangeToAlice(Messaging::ExchangeDelegate * delegate) { - return mExchangeManager.NewContext(mSessionManager.CreateUnauthenticatedSession(mAliceAddress, GetLocalMRPConfig()).Value(), - delegate); + return mExchangeManager.NewContext( + mSessionManager.CreateUnauthenticatedSession(mAliceAddress, GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig())).Value(), + delegate); } Messaging::ExchangeContext * MessagingContext::NewUnauthenticatedExchangeToBob(Messaging::ExchangeDelegate * delegate) { - return mExchangeManager.NewContext(mSessionManager.CreateUnauthenticatedSession(mBobAddress, GetLocalMRPConfig()).Value(), - delegate); + return mExchangeManager.NewContext( + mSessionManager.CreateUnauthenticatedSession(mBobAddress, GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig())).Value(), + delegate); } Messaging::ExchangeContext * MessagingContext::NewExchangeToAlice(Messaging::ExchangeDelegate * delegate) diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index a0c204c919366e..1a54b98b48ec6a 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -296,9 +296,9 @@ void CheckResendApplicationMessage(nlTestSuite * inSuite, void * inContext) ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr(); NL_TEST_ASSERT(inSuite, rm != nullptr); - exchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ - System::Clock::Timestamp(300), // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - System::Clock::Timestamp(300), // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + exchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ + System::Clock::Timestamp(300), // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + System::Clock::Timestamp(300), // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); // Let's drop the initial message @@ -409,9 +409,9 @@ void CheckCloseExchangeAndResendApplicationMessage(nlTestSuite * inSuite, void * ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr(); NL_TEST_ASSERT(inSuite, rm != nullptr); - exchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + exchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); // Let's drop the initial message @@ -468,9 +468,9 @@ void CheckFailedMessageRetainOnSend(nlTestSuite * inSuite, void * inContext) ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr(); NL_TEST_ASSERT(inSuite, rm != nullptr); - exchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + exchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); mockSender.mMessageDispatch.mRetainMessageOnSend = false; @@ -558,9 +558,9 @@ void CheckResendApplicationMessageWithPeerExchange(nlTestSuite * inSuite, void * ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr(); NL_TEST_ASSERT(inSuite, rm != nullptr); - exchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + exchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); // Let's drop the initial message @@ -620,7 +620,7 @@ void CheckDuplicateMessageClosedExchange(nlTestSuite * inSuite, void * inContext ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr(); NL_TEST_ASSERT(inSuite, rm != nullptr); - exchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ + exchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ 64_ms32, // CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL 64_ms32, // CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -687,7 +687,7 @@ void CheckDuplicateOldMessageClosedExchange(nlTestSuite * inSuite, void * inCont ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr(); NL_TEST_ASSERT(inSuite, rm != nullptr); - exchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ + exchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ 64_ms32, // CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL 64_ms32, // CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -792,9 +792,9 @@ void CheckResendSessionEstablishmentMessageWithPeerExchange(nlTestSuite * inSuit ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr(); NL_TEST_ASSERT(inSuite, rm != nullptr); - exchange->GetSessionHandle()->AsUnauthenticatedSession()->SetMRPConfig({ - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + exchange->GetSessionHandle()->AsUnauthenticatedSession()->SetRemoteMRPConfig({ + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); // Let's drop the initial message @@ -856,7 +856,7 @@ void CheckDuplicateMessage(nlTestSuite * inSuite, void * inContext) ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr(); NL_TEST_ASSERT(inSuite, rm != nullptr); - exchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ + exchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ 64_ms32, // CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL 64_ms32, // CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -1358,9 +1358,9 @@ void CheckLostResponseWithPiggyback(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 0); // Make sure that we resend our message before the other side does. - exchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + exchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); // We send a message, the other side sends an application-level response @@ -1396,9 +1396,9 @@ void CheckLostResponseWithPiggyback(nlTestSuite * inSuite, void * inContext) // Make sure receiver resends after sender does, and there's enough of a gap // that we are very unlikely to actually trigger the resends on the receiver // when we trigger the resends on the sender. - mockReceiver.mExchange->GetSessionHandle()->AsSecureSession()->SetMRPConfig({ - 256_ms32, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - 256_ms32, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + mockReceiver.mExchange->GetSessionHandle()->AsSecureSession()->SetRemoteMRPConfig({ + 256_ms32, // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + 256_ms32, // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); // Now send a message from the other side, but drop it. @@ -1620,8 +1620,8 @@ void CheckGetBackoff(nlTestSuite * inSuite, void * inContext) int InitializeTestCase(void * inContext) { TestContext & ctx = *static_cast(inContext); - ctx.GetSessionAliceToBob()->AsSecureSession()->SetMRPConfig(GetLocalMRPConfig()); - ctx.GetSessionBobToAlice()->AsSecureSession()->SetMRPConfig(GetLocalMRPConfig()); + ctx.GetSessionAliceToBob()->AsSecureSession()->SetRemoteMRPConfig(GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig())); + ctx.GetSessionBobToAlice()->AsSecureSession()->SetRemoteMRPConfig(GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig())); return SUCCESS; } diff --git a/src/platform/Darwin/CHIPPlatformConfig.h b/src/platform/Darwin/CHIPPlatformConfig.h index ea4252f93b1110..4b11bfefca9f66 100644 --- a/src/platform/Darwin/CHIPPlatformConfig.h +++ b/src/platform/Darwin/CHIPPlatformConfig.h @@ -61,7 +61,7 @@ // TODO - Fine tune MRP default parameters for Darwin platform #define CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL (15000) -#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (2000_ms32) +#define CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL (2000_ms32) #ifndef CHIP_CONFIG_KVS_PATH #define CHIP_CONFIG_KVS_PATH "/tmp/chip_kvs" diff --git a/src/protocols/secure_channel/CASEServer.cpp b/src/protocols/secure_channel/CASEServer.cpp index d2e8879de4a882..b36d5c1f004eea 100644 --- a/src/protocols/secure_channel/CASEServer.cpp +++ b/src/protocols/secure_channel/CASEServer.cpp @@ -132,8 +132,7 @@ void CASEServer::PrepareForSessionEstablishment(const ScopedNodeId & previouslyE // VerifyOrDie(GetSession().PrepareForSessionEstablishment(*mSessionManager, mFabrics, mSessionResumptionStorage, mCertificateValidityPolicy, this, previouslyEstablishedPeer, - Optional::Value(GetLocalMRPConfig())) == - CHIP_NO_ERROR); + GetLocalMRPConfig()) == CHIP_NO_ERROR); // // PairingSession::mSecureSessionHolder is a weak-reference. If MarkForEviction is called on this session, the session is diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index e303fc2f3a1dbb..3c71b69c8c17c7 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -194,7 +194,7 @@ CASESession::PrepareForSessionEstablishment(SessionManager & sessionManager, Fab SessionResumptionStorage * sessionResumptionStorage, Credentials::CertificateValidityPolicy * policy, SessionEstablishmentDelegate * delegate, const ScopedNodeId & previouslyEstablishedPeer, - Optional mrpConfig) + Optional mrpLocalConfig) { // Below VerifyOrReturnError is not SuccessOrExit since we only want to goto `exit:` after // Init has been successfully called. @@ -207,7 +207,7 @@ CASESession::PrepareForSessionEstablishment(SessionManager & sessionManager, Fab mFabricsTable = fabricTable; mRole = CryptoContext::SessionRole::kResponder; mSessionResumptionStorage = sessionResumptionStorage; - mLocalMRPConfig = mrpConfig; + mLocalMRPConfig = mrpLocalConfig; ChipLogDetail(SecureChannel, "Allocated SecureSession (%p) - waiting for Sigma1 msg", mSecureSessionHolder.Get().Value()->AsSecureSession()); @@ -223,7 +223,7 @@ CASESession::PrepareForSessionEstablishment(SessionManager & sessionManager, Fab CHIP_ERROR CASESession::EstablishSession(SessionManager & sessionManager, FabricTable * fabricTable, ScopedNodeId peerScopedNodeId, ExchangeContext * exchangeCtxt, SessionResumptionStorage * sessionResumptionStorage, Credentials::CertificateValidityPolicy * policy, SessionEstablishmentDelegate * delegate, - Optional mrpConfig) + Optional mrpLocalConfig) { MATTER_TRACE_EVENT_SCOPE("EstablishSession", "CASESession"); CHIP_ERROR err = CHIP_NO_ERROR; @@ -255,7 +255,7 @@ CHIP_ERROR CASESession::EstablishSession(SessionManager & sessionManager, Fabric mFabricsTable = fabricTable; mFabricIndex = fabricInfo->GetFabricIndex(); mSessionResumptionStorage = sessionResumptionStorage; - mLocalMRPConfig = mrpConfig; + mLocalMRPConfig = mrpLocalConfig; mExchangeCtxt->SetResponseTimeout(kSigma_Response_Timeout + mExchangeCtxt->GetSessionHandle()->GetAckTimeout()); mPeerNodeId = peerScopedNodeId.GetNodeId(); diff --git a/src/protocols/secure_channel/CASESession.h b/src/protocols/secure_channel/CASESession.h index 5ee8c247b60fdd..2ea286b07110b7 100644 --- a/src/protocols/secure_channel/CASESession.h +++ b/src/protocols/secure_channel/CASESession.h @@ -80,15 +80,16 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler, * @param previouslyEstablishedPeer If a session had previously been established successfully to a peer, this should * be set to its scoped node-id. Else, this should be initialized to a * default-constructed ScopedNodeId(). - * @param mrpConfig MRP configuration to encode into Sigma2. If not provided, it won't be encoded. + * @param mrpLocalConfig MRP configuration to encode into Sigma2. If not provided, it won't be encoded. * * @return CHIP_ERROR The result of initialization */ - CHIP_ERROR PrepareForSessionEstablishment( - SessionManager & sessionManager, FabricTable * fabricTable, SessionResumptionStorage * sessionResumptionStorage, - Credentials::CertificateValidityPolicy * policy, SessionEstablishmentDelegate * delegate, - const ScopedNodeId & previouslyEstablishedPeer, - Optional mrpConfig = Optional::Missing()); + CHIP_ERROR PrepareForSessionEstablishment(SessionManager & sessionManager, FabricTable * fabricTable, + SessionResumptionStorage * sessionResumptionStorage, + Credentials::CertificateValidityPolicy * policy, + SessionEstablishmentDelegate * delegate, + const ScopedNodeId & previouslyEstablishedPeer, + Optional mrpLocalConfig); /** * @brief @@ -107,7 +108,7 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler, EstablishSession(SessionManager & sessionManager, FabricTable * fabricTable, ScopedNodeId peerScopedNodeId, Messaging::ExchangeContext * exchangeCtxt, SessionResumptionStorage * sessionResumptionStorage, Credentials::CertificateValidityPolicy * policy, SessionEstablishmentDelegate * delegate, - Optional mrpConfig = Optional::Missing()); + Optional mrpLocalConfig); /** * @brief Set the Group Data Provider which will be used to look up IPKs diff --git a/src/protocols/secure_channel/PASESession.cpp b/src/protocols/secure_channel/PASESession.cpp index d780c0821a55ff..ae213a2792ec0f 100644 --- a/src/protocols/secure_channel/PASESession.cpp +++ b/src/protocols/secure_channel/PASESession.cpp @@ -155,7 +155,7 @@ CHIP_ERROR PASESession::SetupSpake2p() } CHIP_ERROR PASESession::WaitForPairing(SessionManager & sessionManager, const Spake2pVerifier & verifier, uint32_t pbkdf2IterCount, - const ByteSpan & salt, Optional mrpConfig, + const ByteSpan & salt, Optional mrpLocalConfig, SessionEstablishmentDelegate * delegate) { // Return early on error here, as we have not initialized any state yet @@ -189,7 +189,7 @@ CHIP_ERROR PASESession::WaitForPairing(SessionManager & sessionManager, const Sp mIterationCount = pbkdf2IterCount; mNextExpectedMsg = MsgType::PBKDFParamRequest; mPairingComplete = false; - mLocalMRPConfig = mrpConfig; + mLocalMRPConfig = mrpLocalConfig; ChipLogDetail(SecureChannel, "Waiting for PBKDF param request"); @@ -202,7 +202,7 @@ CHIP_ERROR PASESession::WaitForPairing(SessionManager & sessionManager, const Sp } CHIP_ERROR PASESession::Pair(SessionManager & sessionManager, uint32_t peerSetUpPINCode, - Optional mrpConfig, Messaging::ExchangeContext * exchangeCtxt, + Optional mrpLocalConfig, Messaging::ExchangeContext * exchangeCtxt, SessionEstablishmentDelegate * delegate) { MATTER_TRACE_EVENT_SCOPE("Pair", "PASESession"); @@ -215,7 +215,7 @@ CHIP_ERROR PASESession::Pair(SessionManager & sessionManager, uint32_t peerSetUp mExchangeCtxt = exchangeCtxt; mExchangeCtxt->SetResponseTimeout(kSpake2p_Response_Timeout + mExchangeCtxt->GetSessionHandle()->GetAckTimeout()); - mLocalMRPConfig = mrpConfig; + mLocalMRPConfig = mrpLocalConfig; err = SendPBKDFParamRequest(); SuccessOrExit(err); diff --git a/src/protocols/secure_channel/PASESession.h b/src/protocols/secure_channel/PASESession.h index 69492209f508c6..8669427ff2ce94 100644 --- a/src/protocols/secure_channel/PASESession.h +++ b/src/protocols/secure_channel/PASESession.h @@ -101,7 +101,7 @@ class DLL_EXPORT PASESession : public Messaging::UnsolicitedMessageHandler, * @return CHIP_ERROR The result of initialization */ CHIP_ERROR WaitForPairing(SessionManager & sessionManager, const Spake2pVerifier & verifier, uint32_t pbkdf2IterCount, - const ByteSpan & salt, Optional mrpConfig, + const ByteSpan & salt, Optional mrpLocalConfig, SessionEstablishmentDelegate * delegate); /** @@ -118,8 +118,9 @@ class DLL_EXPORT PASESession : public Messaging::UnsolicitedMessageHandler, * * @return CHIP_ERROR The result of initialization */ - CHIP_ERROR Pair(SessionManager & sessionManager, uint32_t peerSetUpPINCode, Optional mrpConfig, - Messaging::ExchangeContext * exchangeCtxt, SessionEstablishmentDelegate * delegate); + CHIP_ERROR Pair(SessionManager & sessionManager, uint32_t peerSetUpPINCode, + Optional mrpLocalConfig, Messaging::ExchangeContext * exchangeCtxt, + SessionEstablishmentDelegate * delegate); /** * @brief diff --git a/src/protocols/secure_channel/PairingSession.cpp b/src/protocols/secure_channel/PairingSession.cpp index ef87bedf3051c9..8c1dee5968ed4a 100644 --- a/src/protocols/secure_channel/PairingSession.cpp +++ b/src/protocols/secure_channel/PairingSession.cpp @@ -84,13 +84,13 @@ void PairingSession::DiscardExchange() } } -CHIP_ERROR PairingSession::EncodeMRPParameters(TLV::Tag tag, const ReliableMessageProtocolConfig & mrpConfig, +CHIP_ERROR PairingSession::EncodeMRPParameters(TLV::Tag tag, const ReliableMessageProtocolConfig & mrpLocalConfig, TLV::TLVWriter & tlvWriter) { TLV::TLVType mrpParamsContainer; ReturnErrorOnFailure(tlvWriter.StartContainer(tag, TLV::kTLVType_Structure, mrpParamsContainer)); - ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(1), mrpConfig.mIdleRetransTimeout.count())); - ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(2), mrpConfig.mActiveRetransTimeout.count())); + ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(1), mrpLocalConfig.mIdleRetransTimeout.count())); + ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(2), mrpLocalConfig.mActiveRetransTimeout.count())); return tlvWriter.EndContainer(mrpParamsContainer); } diff --git a/src/protocols/secure_channel/PairingSession.h b/src/protocols/secure_channel/PairingSession.h index dccb8ec7d8ead7..e13d89dced4983 100644 --- a/src/protocols/secure_channel/PairingSession.h +++ b/src/protocols/secure_channel/PairingSession.h @@ -101,7 +101,7 @@ class DLL_EXPORT PairingSession : public SessionDelegate /** * Encode the provided MRP parameters using the provided TLV tag. */ - static CHIP_ERROR EncodeMRPParameters(TLV::Tag tag, const ReliableMessageProtocolConfig & mrpConfig, + static CHIP_ERROR EncodeMRPParameters(TLV::Tag tag, const ReliableMessageProtocolConfig & mrpLocalConfig, TLV::TLVWriter & tlvWriter); protected: @@ -204,7 +204,7 @@ class DLL_EXPORT PairingSession : public SessionDelegate // mLocalMRPConfig is our config which is sent to the other end and used by the peer session. // mRemoteMRPConfig is received from other end and set to our session. Optional mLocalMRPConfig; - ReliableMessageProtocolConfig mRemoteMRPConfig = GetLocalMRPConfig(); + ReliableMessageProtocolConfig mRemoteMRPConfig = GetDefaultMRPConfig(); private: Optional mPeerSessionId; diff --git a/src/protocols/secure_channel/tests/TestCASESession.cpp b/src/protocols/secure_channel/tests/TestCASESession.cpp index e862c46c12f305..bf076e80e3ae02 100644 --- a/src/protocols/secure_channel/tests/TestCASESession.cpp +++ b/src/protocols/secure_channel/tests/TestCASESession.cpp @@ -246,14 +246,17 @@ void CASE_SecurePairingWaitTest(nlTestSuite * inSuite, void * inContext) caseSession.SetGroupDataProvider(&gDeviceGroupDataProvider); NL_TEST_ASSERT(inSuite, - caseSession.PrepareForSessionEstablishment(sessionManager, nullptr, nullptr, nullptr, nullptr, - ScopedNodeId()) == CHIP_ERROR_INVALID_ARGUMENT); + caseSession.PrepareForSessionEstablishment( + sessionManager, nullptr, nullptr, nullptr, nullptr, ScopedNodeId(), + Optional::Missing()) == CHIP_ERROR_INVALID_ARGUMENT); NL_TEST_ASSERT(inSuite, - caseSession.PrepareForSessionEstablishment(sessionManager, nullptr, nullptr, nullptr, &delegate, - ScopedNodeId()) == CHIP_ERROR_INVALID_ARGUMENT); - NL_TEST_ASSERT(inSuite, - caseSession.PrepareForSessionEstablishment(sessionManager, &fabrics, nullptr, nullptr, &delegate, - ScopedNodeId()) == CHIP_NO_ERROR); + caseSession.PrepareForSessionEstablishment( + sessionManager, nullptr, nullptr, nullptr, &delegate, ScopedNodeId(), + Optional::Missing()) == CHIP_ERROR_INVALID_ARGUMENT); + NL_TEST_ASSERT( + inSuite, + caseSession.PrepareForSessionEstablishment(sessionManager, &fabrics, nullptr, nullptr, &delegate, ScopedNodeId(), + Optional::Missing()) == CHIP_NO_ERROR); } } @@ -271,19 +274,20 @@ void CASE_SecurePairingStartTest(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, pairing.EstablishSession(sessionManager, nullptr, ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, nullptr, - nullptr, nullptr, nullptr) != CHIP_NO_ERROR); + nullptr, nullptr, nullptr, + Optional::Missing()) != CHIP_NO_ERROR); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(inSuite, pairing.EstablishSession(sessionManager, &gCommissionerFabrics, - ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, nullptr, nullptr, nullptr, - nullptr) != CHIP_NO_ERROR); + ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, nullptr, nullptr, nullptr, nullptr, + Optional::Missing()) != CHIP_NO_ERROR); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(inSuite, pairing.EstablishSession(sessionManager, &gCommissionerFabrics, ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, context, nullptr, nullptr, - &delegate) == CHIP_NO_ERROR); + &delegate, Optional::Missing()) == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); auto & loopback = ctx.GetLoopback(); @@ -303,9 +307,9 @@ void CASE_SecurePairingStartTest(nlTestSuite * inSuite, void * inContext) ExchangeContext * context1 = ctx.NewUnauthenticatedExchangeToBob(&pairing1); NL_TEST_ASSERT(inSuite, - pairing1.EstablishSession(sessionManager, &gCommissionerFabrics, - ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, context1, nullptr, nullptr, - &delegate) == CHIP_ERROR_BAD_REQUEST); + pairing1.EstablishSession( + sessionManager, &gCommissionerFabrics, ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, context1, + nullptr, nullptr, &delegate, Optional::Missing()) == CHIP_ERROR_BAD_REQUEST); ctx.DrainAndServiceIO(); loopback.mMessageSendError = CHIP_NO_ERROR; @@ -407,7 +411,8 @@ void CASE_SecurePairingHandshakeServerTest(nlTestSuite * inSuite, void * inConte NL_TEST_ASSERT(inSuite, pairingCommissioner->EstablishSession(ctx.GetSecureSessionManager(), &gCommissionerFabrics, ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, contextCommissioner, - nullptr, nullptr, &delegateCommissioner) == CHIP_NO_ERROR); + nullptr, nullptr, &delegateCommissioner, + Optional::Missing()) == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(inSuite, loopback.mSentMessageCount == sTestCaseMessageCount); @@ -426,7 +431,8 @@ void CASE_SecurePairingHandshakeServerTest(nlTestSuite * inSuite, void * inConte NL_TEST_ASSERT(inSuite, pairingCommissioner1->EstablishSession(ctx.GetSecureSessionManager(), &gCommissionerFabrics, ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, contextCommissioner1, - nullptr, nullptr, &delegateCommissioner) == CHIP_NO_ERROR); + nullptr, nullptr, &delegateCommissioner, + Optional::Missing()) == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); chip::Platform::Delete(pairingCommissioner); @@ -831,7 +837,8 @@ static void CASE_SessionResumptionStorage(nlTestSuite * inSuite, void * inContex ExchangeContext * contextCommissioner = ctx.NewUnauthenticatedExchangeToBob(pairingCommissioner); auto establishmentReturnVal = pairingCommissioner->EstablishSession( ctx.GetSecureSessionManager(), &gCommissionerFabrics, ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, - contextCommissioner, &testVectors[i].initiatorStorage, nullptr, &delegateCommissioner); + contextCommissioner, &testVectors[i].initiatorStorage, nullptr, &delegateCommissioner, + Optional::Missing()); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(inSuite, establishmentReturnVal == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, loopback.mSentMessageCount == testVectors[i].expectedSentMessageCount); @@ -881,8 +888,9 @@ void CASESessionForTest::CASE_SimulateUpdateNOCInvalidatePendingEstablishment(nl pairingAccessory.SetGroupDataProvider(&gDeviceGroupDataProvider); NL_TEST_ASSERT(inSuite, - pairingAccessory.PrepareForSessionEstablishment(sessionManager, &gDeviceFabrics, nullptr, nullptr, - &delegateAccessory, ScopedNodeId()) == CHIP_NO_ERROR); + pairingAccessory.PrepareForSessionEstablishment( + sessionManager, &gDeviceFabrics, nullptr, nullptr, &delegateAccessory, ScopedNodeId(), + Optional::Missing()) == CHIP_NO_ERROR); gDeviceFabrics.SendUpdateFabricNotificationForTest(gDeviceFabricIndex); ctx.DrainAndServiceIO(); @@ -891,7 +899,8 @@ void CASESessionForTest::CASE_SimulateUpdateNOCInvalidatePendingEstablishment(nl NL_TEST_ASSERT(inSuite, pairingCommissioner.EstablishSession(sessionManager, &gCommissionerFabrics, ScopedNodeId{ Node01_01, gCommissionerFabricIndex }, contextCommissioner, - nullptr, nullptr, &delegateCommissioner) == CHIP_NO_ERROR); + nullptr, nullptr, &delegateCommissioner, + Optional::Missing()) == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); // At this point the CASESession is in the process of establishing. Confirm that there are no errors and there are session diff --git a/src/protocols/secure_channel/tests/TestPASESession.cpp b/src/protocols/secure_channel/tests/TestPASESession.cpp index 6b60ff3bd413ab..6a94988effc296 100644 --- a/src/protocols/secure_channel/tests/TestPASESession.cpp +++ b/src/protocols/secure_channel/tests/TestPASESession.cpp @@ -222,9 +222,9 @@ void SecurePairingHandshakeTestCommon(nlTestSuite * inSuite, void * inContext, S NL_TEST_ASSERT(inSuite, rm != nullptr); NL_TEST_ASSERT(inSuite, rc != nullptr); - contextCommissioner->GetSessionHandle()->AsUnauthenticatedSession()->SetMRPConfig({ - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + contextCommissioner->GetSessionHandle()->AsUnauthenticatedSession()->SetRemoteMRPConfig({ + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); } @@ -376,9 +376,9 @@ void SecurePairingFailedHandshake(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, rm != nullptr); NL_TEST_ASSERT(inSuite, rc != nullptr); - contextCommissioner->GetSessionHandle()->AsUnauthenticatedSession()->SetMRPConfig({ - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL - 64_ms32, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL + contextCommissioner->GetSessionHandle()->AsUnauthenticatedSession()->SetRemoteMRPConfig({ + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL + 64_ms32, // CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL }); NL_TEST_ASSERT(inSuite, diff --git a/src/protocols/secure_channel/tests/TestPairingSession.cpp b/src/protocols/secure_channel/tests/TestPairingSession.cpp index af35283b0f934c..833fb7afd6c92d 100644 --- a/src/protocols/secure_channel/tests/TestPairingSession.cpp +++ b/src/protocols/secure_channel/tests/TestPairingSession.cpp @@ -85,8 +85,7 @@ void PairingSessionEncodeDecodeMRPParams(nlTestSuite * inSuite, void * inContext NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, session.DecodeMRPParametersIfPresent(TLV::ContextTag(1), reader) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, session.GetRemoteMRPConfig().mIdleRetransTimeout == config.mIdleRetransTimeout); - NL_TEST_ASSERT(inSuite, session.GetRemoteMRPConfig().mActiveRetransTimeout == config.mActiveRetransTimeout); + NL_TEST_ASSERT(inSuite, session.GetRemoteMRPConfig() == config); } void PairingSessionTryDecodeMissingMRPParams(nlTestSuite * inSuite, void * inContext) @@ -113,8 +112,7 @@ void PairingSessionTryDecodeMissingMRPParams(nlTestSuite * inSuite, void * inCon NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, session.DecodeMRPParametersIfPresent(TLV::ContextTag(2), reader) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, session.GetRemoteMRPConfig().mIdleRetransTimeout == GetLocalMRPConfig().mIdleRetransTimeout); - NL_TEST_ASSERT(inSuite, session.GetRemoteMRPConfig().mActiveRetransTimeout == GetLocalMRPConfig().mActiveRetransTimeout); + NL_TEST_ASSERT(inSuite, session.GetRemoteMRPConfig() == GetDefaultMRPConfig()); } // Test Suite diff --git a/src/transport/GroupSession.h b/src/transport/GroupSession.h index bbb327b36f7fc8..674e4d4537acac 100644 --- a/src/transport/GroupSession.h +++ b/src/transport/GroupSession.h @@ -62,9 +62,9 @@ class IncomingGroupSession : public Session, public ReferenceCounted session = - mSecureSessions.CreateNewSecureSessionForTest(chip::Transport::SecureSession::Type::kPASE, localSessionId, localNodeId, - peerNodeId, CATValues{}, peerSessionId, fabric, GetLocalMRPConfig()); + NodeId localNodeId = kUndefinedNodeId; + Optional session = mSecureSessions.CreateNewSecureSessionForTest( + chip::Transport::SecureSession::Type::kPASE, localSessionId, localNodeId, peerNodeId, CATValues{}, peerSessionId, fabric, + GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig())); VerifyOrReturnError(session.HasValue(), CHIP_ERROR_NO_MEMORY); SecureSession * secureSession = session.Value()->AsSecureSession(); secureSession->SetPeerAddress(peerAddress); @@ -400,9 +400,9 @@ CHIP_ERROR SessionManager::InjectCaseSessionWithTestKey(SessionHolder & sessionH FabricIndex fabric, const Transport::PeerAddress & peerAddress, CryptoContext::SessionRole role, const CATValues & cats) { - Optional session = - mSecureSessions.CreateNewSecureSessionForTest(chip::Transport::SecureSession::Type::kCASE, localSessionId, localNodeId, - peerNodeId, cats, peerSessionId, fabric, GetLocalMRPConfig()); + Optional session = mSecureSessions.CreateNewSecureSessionForTest( + chip::Transport::SecureSession::Type::kCASE, localSessionId, localNodeId, peerNodeId, cats, peerSessionId, fabric, + GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig())); VerifyOrReturnError(session.HasValue(), CHIP_ERROR_NO_MEMORY); SecureSession * secureSession = session.Value()->AsSecureSession(); secureSession->SetPeerAddress(peerAddress); @@ -457,7 +457,7 @@ void SessionManager::UnauthenticatedMessageDispatch(const PacketHeader & packetH if (source.HasValue()) { // Assume peer is the initiator, we are the responder. - optionalSession = mUnauthenticatedSessions.FindOrAllocateResponder(source.Value(), GetLocalMRPConfig()); + optionalSession = mUnauthenticatedSessions.FindOrAllocateResponder(source.Value(), GetDefaultMRPConfig()); if (!optionalSession.HasValue()) { ChipLogError(Inet, "UnauthenticatedSession exhausted"); diff --git a/src/transport/UnauthenticatedSessionTable.h b/src/transport/UnauthenticatedSessionTable.h index c0a660e564c9f6..cdaa7a8a7307c0 100644 --- a/src/transport/UnauthenticatedSessionTable.h +++ b/src/transport/UnauthenticatedSessionTable.h @@ -47,7 +47,7 @@ class UnauthenticatedSession : public Session, mEphemeralInitiatorNodeId(ephemeralInitiatorNodeID), mSessionRole(sessionRole), mLastActivityTime(System::SystemClock().GetMonotonicTimestamp()), mLastPeerActivityTime(System::Clock::kZero), // Start at zero to default to IDLE state - mMRPConfig(config) + mRemoteMRPConfig(config) {} ~UnauthenticatedSession() override { VerifyOrDie(GetReferenceCount() == 0); } @@ -90,7 +90,7 @@ class UnauthenticatedSession : public Session, switch (mPeerAddress.GetTransportType()) { case Transport::Type::kUdp: - return GetMRPConfig().mIdleRetransTimeout * (CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS + 1); + return GetRemoteMRPConfig().mIdleRetransTimeout * (CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS + 1); case Transport::Type::kTcp: return System::Clock::Seconds16(30); default: @@ -118,12 +118,12 @@ class UnauthenticatedSession : public Session, System::Clock::Timestamp GetMRPBaseTimeout() override { - return IsPeerActive() ? GetMRPConfig().mActiveRetransTimeout : GetMRPConfig().mIdleRetransTimeout; + return IsPeerActive() ? GetRemoteMRPConfig().mActiveRetransTimeout : GetRemoteMRPConfig().mIdleRetransTimeout; } - void SetMRPConfig(const ReliableMessageProtocolConfig & config) { mMRPConfig = config; } + void SetRemoteMRPConfig(const ReliableMessageProtocolConfig & config) { mRemoteMRPConfig = config; } - const ReliableMessageProtocolConfig & GetMRPConfig() const override { return mMRPConfig; } + const ReliableMessageProtocolConfig & GetRemoteMRPConfig() const override { return mRemoteMRPConfig; } PeerMessageCounter & GetPeerMessageCounter() { return mPeerMessageCounter; } @@ -133,7 +133,7 @@ class UnauthenticatedSession : public Session, PeerAddress mPeerAddress; System::Clock::Timestamp mLastActivityTime; ///< Timestamp of last tx or rx System::Clock::Timestamp mLastPeerActivityTime; ///< Timestamp of last rx - ReliableMessageProtocolConfig mMRPConfig; + ReliableMessageProtocolConfig mRemoteMRPConfig; PeerMessageCounter mPeerMessageCounter; }; diff --git a/src/transport/tests/TestPeerConnections.cpp b/src/transport/tests/TestPeerConnections.cpp index 10459afc456d3f..2e03347aa0f60b 100644 --- a/src/transport/tests/TestPeerConnections.cpp +++ b/src/transport/tests/TestPeerConnections.cpp @@ -68,7 +68,7 @@ void TestBasicFunctionality(nlTestSuite * inSuite, void * inContext) // First node, peer session id 1, local session id 2 auto optionalSession = connections.CreateNewSecureSessionForTest(SecureSession::Type::kCASE, 2, kLocalNodeId, kCasePeer1NodeId, - kPeer1CATs, 1, kFabricIndex, GetLocalMRPConfig()); + kPeer1CATs, 1, kFabricIndex, GetDefaultMRPConfig()); NL_TEST_ASSERT(inSuite, optionalSession.HasValue()); NL_TEST_ASSERT(inSuite, optionalSession.Value()->AsSecureSession()->GetSecureSessionType() == SecureSession::Type::kCASE); NL_TEST_ASSERT(inSuite, optionalSession.Value()->AsSecureSession()->GetPeerNodeId() == kCasePeer1NodeId); @@ -80,7 +80,7 @@ void TestBasicFunctionality(nlTestSuite * inSuite, void * inContext) // Second node, peer session id 3, local session id 4 optionalSession = connections.CreateNewSecureSessionForTest(SecureSession::Type::kCASE, 4, kLocalNodeId, kCasePeer2NodeId, - kPeer2CATs, 3, kFabricIndex, GetLocalMRPConfig()); + kPeer2CATs, 3, kFabricIndex, GetDefaultMRPConfig()); NL_TEST_ASSERT(inSuite, optionalSession.HasValue()); NL_TEST_ASSERT(inSuite, optionalSession.Value()->AsSecureSession()->GetSecureSessionType() == SecureSession::Type::kCASE); NL_TEST_ASSERT(inSuite, optionalSession.Value()->AsSecureSession()->GetPeerNodeId() == kCasePeer2NodeId); @@ -96,9 +96,9 @@ void TestBasicFunctionality(nlTestSuite * inSuite, void * inContext) // for (int i = 2; i < CHIP_CONFIG_SECURE_SESSION_POOL_SIZE; ++i) { - sessions[i] = connections.CreateNewSecureSessionForTest(SecureSession::Type::kCASE, - static_cast(static_cast(i) + 6u), kLocalNodeId, - kCasePeer2NodeId, kPeer2CATs, 3, kFabricIndex, GetLocalMRPConfig()); + sessions[i] = connections.CreateNewSecureSessionForTest( + SecureSession::Type::kCASE, static_cast(static_cast(i) + 6u), kLocalNodeId, kCasePeer2NodeId, + kPeer2CATs, 3, kFabricIndex, GetDefaultMRPConfig()); NL_TEST_ASSERT(inSuite, sessions[i].HasValue()); } @@ -115,7 +115,7 @@ void TestFindByKeyId(nlTestSuite * inSuite, void * inContext) // First node, peer session id 1, local session id 2 auto optionalSession = connections.CreateNewSecureSessionForTest(SecureSession::Type::kCASE, 2, kLocalNodeId, kCasePeer1NodeId, - kPeer1CATs, 1, kFabricIndex, GetLocalMRPConfig()); + kPeer1CATs, 1, kFabricIndex, GetDefaultMRPConfig()); NL_TEST_ASSERT(inSuite, optionalSession.HasValue()); NL_TEST_ASSERT(inSuite, !connections.FindSecureSessionByLocalKey(1).HasValue()); @@ -123,7 +123,7 @@ void TestFindByKeyId(nlTestSuite * inSuite, void * inContext) // Second node, peer session id 3, local session id 4 optionalSession = connections.CreateNewSecureSessionForTest(SecureSession::Type::kCASE, 4, kLocalNodeId, kCasePeer2NodeId, - kPeer2CATs, 3, kFabricIndex, GetLocalMRPConfig()); + kPeer2CATs, 3, kFabricIndex, GetDefaultMRPConfig()); NL_TEST_ASSERT(inSuite, optionalSession.HasValue()); NL_TEST_ASSERT(inSuite, !connections.FindSecureSessionByLocalKey(3).HasValue());