From 3bf82fdf4abdbe671d1b769ec1a4579c1a8ebe20 Mon Sep 17 00:00:00 2001 From: Suhas Shankar Date: Mon, 15 Apr 2024 20:05:59 +0530 Subject: [PATCH 1/9] Refactored DiscoveredNodeData definition and usage --- .../commands/common/DeviceScanner.cpp | 6 +- .../commands/common/RemoteDataModelLogger.cpp | 6 +- .../commands/common/RemoteDataModelLogger.h | 2 +- .../DiscoverCommissionablesCommand.cpp | 2 +- .../discover/DiscoverCommissionablesCommand.h | 2 +- .../discover/DiscoverCommissionersCommand.cpp | 2 +- .../commands/pairing/PairingCommand.cpp | 6 +- .../commands/pairing/PairingCommand.h | 2 +- .../linux/ControllerShellCommands.cpp | 6 +- .../app/src/main/jni/cpp/ConversionUtils.cpp | 34 +- .../app/src/main/jni/cpp/ConversionUtils.h | 2 +- .../app/src/main/jni/cpp/TvCastingApp-JNI.cpp | 2 +- .../CastingServerBridge.mm | 4 +- .../CommissionerDiscoveryDelegateImpl.h | 4 +- .../MatterTvCastingBridge/ConversionUtils.hpp | 4 +- .../MatterTvCastingBridge/ConversionUtils.mm | 70 +-- .../tv-casting-app/linux/CastingUtils.cpp | 8 +- examples/tv-casting-app/linux/CastingUtils.h | 2 +- .../core/CastingPlayerDiscovery.cpp | 27 +- .../core/CastingPlayerDiscovery.h | 2 +- .../tv-casting-common/include/CastingServer.h | 4 +- .../include/TargetVideoPlayerInfo.h | 2 +- .../tv-casting-common/src/CastingServer.cpp | 28 +- .../tv-casting-common/src/ConversionUtils.cpp | 21 +- .../src/TargetVideoPlayerInfo.cpp | 6 +- .../AbstractDnssdDiscoveryController.cpp | 22 +- .../AbstractDnssdDiscoveryController.h | 4 +- .../CHIPCommissionableNodeController.cpp | 2 +- .../CHIPCommissionableNodeController.h | 4 +- src/controller/CHIPDeviceController.cpp | 2 +- src/controller/CHIPDeviceController.h | 4 +- src/controller/DeviceDiscoveryDelegate.h | 2 +- src/controller/SetUpCodePairer.cpp | 22 +- .../java/CHIPDeviceController-JNI.cpp | 28 +- ...issionableNodeController-ScriptBinding.cpp | 44 +- .../python/ChipDeviceController-Discovery.cpp | 100 ++--- ...r-ScriptPairingDeviceDiscoveryDelegate.cpp | 12 +- ...ler-ScriptPairingDeviceDiscoveryDelegate.h | 2 +- .../TestCommissionableNodeController.cpp | 70 +-- .../CHIP/MTRCommissionableBrowser.mm | 4 +- src/lib/dnssd/ActiveResolveAttempts.h | 12 +- src/lib/dnssd/Discovery_ImplPlatform.cpp | 24 +- src/lib/dnssd/IncrementalResolve.cpp | 14 +- src/lib/dnssd/IncrementalResolve.h | 4 +- src/lib/dnssd/Resolver_ImplMinimalMdns.cpp | 2 - src/lib/dnssd/TxtFields.cpp | 2 +- src/lib/dnssd/TxtFields.h | 2 +- src/lib/dnssd/Types.h | 18 +- .../dnssd/tests/TestActiveResolveAttempts.cpp | 6 +- .../dnssd/tests/TestIncrementalResolve.cpp | 31 +- src/lib/dnssd/tests/TestTxtFields.cpp | 418 +++++++++++++++--- src/lib/shell/commands/Dns.cpp | 54 ++- .../UserDirectedCommissioningServer.cpp | 46 +- .../tests/TestUdcMessages.cpp | 42 +- 54 files changed, 807 insertions(+), 444 deletions(-) diff --git a/examples/chip-tool/commands/common/DeviceScanner.cpp b/examples/chip-tool/commands/common/DeviceScanner.cpp index 9d3dbca98f8db9..79b3669f14fea6 100644 --- a/examples/chip-tool/commands/common/DeviceScanner.cpp +++ b/examples/chip-tool/commands/common/DeviceScanner.cpp @@ -55,7 +55,7 @@ CHIP_ERROR DeviceScanner::Stop() void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) { - auto & commissionData = nodeData.nodeData; + auto & commissionData = nodeData.Get(); auto discriminator = commissionData.longDiscriminator; auto vendorId = static_cast(commissionData.vendorId); @@ -64,7 +64,7 @@ void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) ChipLogProgress(chipTool, "OnNodeDiscovered (MDNS): discriminator: %u, vendorId: %u, productId: %u", discriminator, vendorId, productId); - auto & resolutionData = nodeData.resolutionData; + auto & resolutionData = (CommonResolutionData &)commissionData; auto & instanceData = mDiscoveredResults[commissionData.instanceName]; auto & interfaceData = instanceData[resolutionData.interfaceId.GetPlatformInterface()]; @@ -76,7 +76,7 @@ void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) interfaceData.push_back(result); } - nodeData.LogDetail(); + commissionData.LogDetail(); } void DeviceScanner::OnBrowseAdd(chip::Dnssd::DnssdService service) diff --git a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp index 9e3026262db97d..92253f27d624c0 100644 --- a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp +++ b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp @@ -204,12 +204,12 @@ CHIP_ERROR LogIssueNOCChain(const char * noc, const char * icac, const char * rc return gDelegate->LogJSON(valueStr.c_str()); } -CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::DiscoveredNodeData & nodeData) +CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeData) { VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR); - auto & resolutionData = nodeData.resolutionData; - auto & commissionData = nodeData.nodeData; + auto & commissionData = nodeData; + auto & resolutionData = (chip::Dnssd::CommonResolutionData &)commissionData; if (!chip::CanCastTo(resolutionData.numIPs)) { diff --git a/examples/chip-tool/commands/common/RemoteDataModelLogger.h b/examples/chip-tool/commands/common/RemoteDataModelLogger.h index 7c93a50aa1f191..215433588e3ae6 100644 --- a/examples/chip-tool/commands/common/RemoteDataModelLogger.h +++ b/examples/chip-tool/commands/common/RemoteDataModelLogger.h @@ -43,6 +43,6 @@ CHIP_ERROR LogErrorAsJSON(const CHIP_ERROR & error); CHIP_ERROR LogGetCommissionerNodeId(chip::NodeId value); CHIP_ERROR LogGetCommissionerRootCertificate(const char * value); CHIP_ERROR LogIssueNOCChain(const char * noc, const char * icac, const char * rcac, const char * ipk); -CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::DiscoveredNodeData & nodeData); +CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeData); void SetDelegate(RemoteDataModelLoggerDelegate * delegate); }; // namespace RemoteDataModelLogger diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp index 9e65a87b16bac7..ad5e7feaf7f948 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp +++ b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp @@ -23,7 +23,7 @@ using namespace ::chip; -void DiscoverCommissionablesCommandBase::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) +void DiscoverCommissionablesCommandBase::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) { nodeData.LogDetail(); LogErrorOnFailure(RemoteDataModelLogger::LogDiscoveredNodeData(nodeData)); diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h index bac24634152823..d1fec307eac19e 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h +++ b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h @@ -31,7 +31,7 @@ class DiscoverCommissionablesCommandBase : public CHIPCommand, public chip::Cont } /////////// DeviceDiscoveryDelegate Interface ///////// - void OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) override; + void OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) override; /////////// CHIPCommand Interface ///////// chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); } diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp b/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp index 57c7574c4ea2e3..30de62b9329173 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp +++ b/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp @@ -32,7 +32,7 @@ void DiscoverCommissionersCommand::Shutdown() [[maybe_unused]] int commissionerCount = 0; for (int i = 0; i < CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES; i++) { - const Dnssd::DiscoveredNodeData * commissioner = mCommissionableNodeController.GetDiscoveredCommissioner(i); + const Dnssd::CommissionNodeData * commissioner = mCommissionableNodeController.GetDiscoveredCommissioner(i); if (commissioner != nullptr) { ChipLogProgress(chipTool, "Discovered Commissioner #%d", commissionerCount); diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 5ec206c25b7ea0..61afed536698f7 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -479,12 +479,12 @@ void PairingCommand::OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedA ChipLogValueX64(deviceId), promisedActiveDuration); } -void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) +void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) { // Ignore nodes with closed commissioning window - VerifyOrReturn(nodeData.nodeData.commissioningMode != 0); + VerifyOrReturn(nodeData.commissioningMode != 0); - auto & resolutionData = nodeData.resolutionData; + auto & resolutionData = (chip::Dnssd::CommonResolutionData &)nodeData; const uint16_t port = resolutionData.port; char buf[chip::Inet::IPAddress::kMaxStringLength]; diff --git a/examples/chip-tool/commands/pairing/PairingCommand.h b/examples/chip-tool/commands/pairing/PairingCommand.h index 0baf70128531b8..4df17f7dee40b5 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.h +++ b/examples/chip-tool/commands/pairing/PairingCommand.h @@ -201,7 +201,7 @@ class PairingCommand : public CHIPCommand, void OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedActiveDuration) override; /////////// DeviceDiscoveryDelegate Interface ///////// - void OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) override; + void OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) override; /////////// DeviceAttestationDelegate ///////// chip::Optional FailSafeExpiryTimeoutSecs() const override; diff --git a/examples/platform/linux/ControllerShellCommands.cpp b/examples/platform/linux/ControllerShellCommands.cpp index aefbb3fafa4353..701448e0bd832c 100644 --- a/examples/platform/linux/ControllerShellCommands.cpp +++ b/examples/platform/linux/ControllerShellCommands.cpp @@ -116,7 +116,7 @@ static CHIP_ERROR display(bool printHeader) for (int i = 0; i < 10; i++) { - const Dnssd::DiscoveredNodeData * next = GetDeviceCommissioner()->GetDiscoveredDevice(i); + const Dnssd::CommissionNodeData * next = GetDeviceCommissioner()->GetDiscoveredDevice(i); if (next == nullptr) { streamer_printf(sout, " Entry %d null\r\n", i); @@ -124,8 +124,8 @@ static CHIP_ERROR display(bool printHeader) else { streamer_printf(sout, " Entry %d instanceName=%s host=%s longDiscriminator=%d vendorId=%d productId=%d\r\n", i, - next->nodeData.instanceName, next->resolutionData.hostName, next->nodeData.longDiscriminator, - next->nodeData.vendorId, next->nodeData.productId); + next->instanceName, next->hostName, next->longDiscriminator, + next->vendorId, next->productId); } } diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp index fd66ba44649cea..002a94aa23897c 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp @@ -301,7 +301,7 @@ CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * ta } CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscoveredNodeData, - chip::Dnssd::DiscoveredNodeData & outCppDiscoveredNodeData) + chip::Dnssd::CommissionNodeData & outCppDiscoveredNodeData) { ChipLogProgress(AppServer, "convertJDiscoveredNodeDataToCppDiscoveredNodeData called"); VerifyOrReturnError(jDiscoveredNodeData != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -316,7 +316,7 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered jstring jHostName = static_cast(env->GetObjectField(jDiscoveredNodeData, getHostNameField)); if (jHostName != nullptr) { - chip::Platform::CopyString(outCppDiscoveredNodeData.resolutionData.hostName, chip::Dnssd::kHostNameMaxLength + 1, + chip::Platform::CopyString(outCppDiscoveredNodeData.hostName, chip::Dnssd::kHostNameMaxLength + 1, env->GetStringUTFChars(jHostName, 0)); } @@ -324,61 +324,61 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered jstring jInstanceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getInstanceNameField)); if (jInstanceName != nullptr) { - chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.instanceName, + chip::Platform::CopyString(outCppDiscoveredNodeData.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, env->GetStringUTFChars(jInstanceName, 0)); } jfieldID jLongDiscriminatorField = env->GetFieldID(jDiscoveredNodeDataClass, "longDiscriminator", "J"); - outCppDiscoveredNodeData.nodeData.vendorId = + outCppDiscoveredNodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jLongDiscriminatorField)); jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J"); - outCppDiscoveredNodeData.nodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jVendorIdField)); + outCppDiscoveredNodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jVendorIdField)); jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J"); - outCppDiscoveredNodeData.nodeData.productId = static_cast(env->GetLongField(jDiscoveredNodeData, jProductIdField)); + outCppDiscoveredNodeData.productId = static_cast(env->GetLongField(jDiscoveredNodeData, jProductIdField)); jfieldID jCommissioningModeField = env->GetFieldID(jDiscoveredNodeDataClass, "commissioningMode", "B"); - outCppDiscoveredNodeData.nodeData.commissioningMode = + outCppDiscoveredNodeData.commissioningMode = static_cast(env->GetByteField(jDiscoveredNodeData, jCommissioningModeField)); jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J"); - outCppDiscoveredNodeData.nodeData.deviceType = static_cast(env->GetLongField(jDiscoveredNodeData, jDeviceTypeField)); + outCppDiscoveredNodeData.deviceType = static_cast(env->GetLongField(jDiscoveredNodeData, jDeviceTypeField)); jfieldID getDeviceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceName", "Ljava/lang/String;"); jstring jDeviceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getDeviceNameField)); if (jDeviceName != nullptr) { - chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, + chip::Platform::CopyString(outCppDiscoveredNodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, env->GetStringUTFChars(jDeviceName, 0)); } // TODO: map rotating ID jfieldID jRotatingIdLenField = env->GetFieldID(jDiscoveredNodeDataClass, "rotatingIdLen", "I"); - outCppDiscoveredNodeData.nodeData.rotatingIdLen = + outCppDiscoveredNodeData.rotatingIdLen = static_cast(env->GetIntField(jDiscoveredNodeData, jRotatingIdLenField)); jfieldID jPairingHintField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingHint", "S"); - outCppDiscoveredNodeData.nodeData.pairingHint = + outCppDiscoveredNodeData.pairingHint = static_cast(env->GetShortField(jDiscoveredNodeData, jPairingHintField)); jfieldID getPairingInstructionField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingInstruction", "Ljava/lang/String;"); jstring jPairingInstruction = static_cast(env->GetObjectField(jDiscoveredNodeData, getPairingInstructionField)); if (jPairingInstruction != nullptr) { - chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.pairingInstruction, chip::Dnssd::kMaxPairingInstructionLen + 1, + chip::Platform::CopyString(outCppDiscoveredNodeData.pairingInstruction, chip::Dnssd::kMaxPairingInstructionLen + 1, env->GetStringUTFChars(jPairingInstruction, 0)); } jfieldID jPortField = env->GetFieldID(jDiscoveredNodeDataClass, "port", "I"); - outCppDiscoveredNodeData.resolutionData.port = static_cast(env->GetIntField(jDiscoveredNodeData, jPortField)); + outCppDiscoveredNodeData.port = static_cast(env->GetIntField(jDiscoveredNodeData, jPortField)); jfieldID jNumIpsField = env->GetFieldID(jDiscoveredNodeDataClass, "numIPs", "I"); - outCppDiscoveredNodeData.resolutionData.numIPs = static_cast(env->GetIntField(jDiscoveredNodeData, jNumIpsField)); + outCppDiscoveredNodeData.numIPs = static_cast(env->GetIntField(jDiscoveredNodeData, jNumIpsField)); jfieldID jIPAddressesField = env->GetFieldID(jDiscoveredNodeDataClass, "ipAddresses", "Ljava/util/List;"); jobject jIPAddresses = env->GetObjectField(jDiscoveredNodeData, jIPAddressesField); - if (jIPAddresses == nullptr && outCppDiscoveredNodeData.resolutionData.numIPs > 0) + if (jIPAddresses == nullptr && outCppDiscoveredNodeData.numIPs > 0) { return CHIP_ERROR_INVALID_ARGUMENT; } @@ -400,11 +400,11 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered chip::Inet::IPAddress addressInet; chip::JniUtfString addressJniString(env, jIPAddressStr); VerifyOrReturnError(chip::Inet::IPAddress::FromString(addressJniString.c_str(), addressInet), CHIP_ERROR_INVALID_ARGUMENT); - outCppDiscoveredNodeData.resolutionData.ipAddress[ipAddressCount] = addressInet; + outCppDiscoveredNodeData.ipAddress[ipAddressCount] = addressInet; if (ipAddressCount == 0) { - outCppDiscoveredNodeData.resolutionData.interfaceId = chip::Inet::InterfaceId::FromIPAddress(addressInet); + outCppDiscoveredNodeData.interfaceId = chip::Inet::InterfaceId::FromIPAddress(addressInet); } ipAddressCount++; } diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.h b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.h index a2c59596d9e9e5..28f5a1abd28c5a 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.h +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.h @@ -33,4 +33,4 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * targetVideoPlayerInfo, jobject & outVideoPlayer); CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscoveredNodeData, - chip::Dnssd::DiscoveredNodeData & cppDiscoveredNodeData); + chip::Dnssd::CommissionNodeData & cppDiscoveredNodeData); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp index 6dbdfba9c83449..f2e0d5b79fc53c 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp @@ -372,7 +372,7 @@ JNI_METHOD(jboolean, sendCommissioningRequest)(JNIEnv * env, jobject, jobject jD chip::DeviceLayer::StackLock lock; ChipLogProgress(AppServer, "JNI_METHOD sendCommissioningRequest called"); - chip::Dnssd::DiscoveredNodeData commissioner; + chip::Dnssd::CommissionNodeData commissioner; CHIP_ERROR err = convertJDiscoveredNodeDataToCppDiscoveredNodeData(jDiscoveredNodeData, commissioner); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(AppServer, diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm index 86a1976aed7d18..f199ba96b7a5a5 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm @@ -456,7 +456,7 @@ - (void)getDiscoveredCommissioner:(int)index block:^{ chip::Optional associatedConnectableVideoPlayer; DiscoveredNodeData * commissioner = nil; - const chip::Dnssd::DiscoveredNodeData * cppDiscoveredNodeData + const chip::Dnssd::CommissionNodeData * cppDiscoveredNodeData = CastingServer::GetInstance()->GetDiscoveredCommissioner( index, associatedConnectableVideoPlayer); if (cppDiscoveredNodeData != nullptr) { @@ -530,7 +530,7 @@ - (void)sendUserDirectedCommissioningRequest:(DiscoveredNodeData * _Nonnull)comm block:^{ bool udcRequestStatus; - chip::Dnssd::DiscoveredNodeData cppCommissioner; + chip::Dnssd::CommissionNodeData cppCommissioner; if ([ConversionUtils convertToCppDiscoveredNodeDataFrom:commissioner outDiscoveredNodeData:cppCommissioner] != CHIP_NO_ERROR) { diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionerDiscoveryDelegateImpl.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionerDiscoveryDelegateImpl.h index 07c1f5c68fc893..8f55e33e27402a 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionerDiscoveryDelegateImpl.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionerDiscoveryDelegateImpl.h @@ -61,10 +61,10 @@ class CommissionerDiscoveryDelegateImpl : public chip::Controller::DeviceDiscove } } - void OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) + void OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) { ChipLogProgress(AppServer, "CommissionerDiscoveryDelegateImpl().OnDiscoveredDevice() called"); - __block const chip::Dnssd::DiscoveredNodeData cppNodeData = nodeData; + __block const chip::Dnssd::CommissionNodeData cppNodeData = nodeData; dispatch_async(mClientQueue, ^{ DiscoveredNodeData * objCDiscoveredNodeData = [ConversionUtils convertToObjCDiscoveredNodeDataFrom:&cppNodeData]; mDiscoveredCommissioners.push_back(objCDiscoveredNodeData); // add to the list of discovered commissioners diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.hpp b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.hpp index d60b442c03c7a5..597b3728e3f6c5 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.hpp +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.hpp @@ -43,7 +43,7 @@ outTargetVideoPlayerInfo:(TargetVideoPlayerInfo &)outTargetVideoPlayerInfo; + (CHIP_ERROR)convertToCppDiscoveredNodeDataFrom:(DiscoveredNodeData * _Nonnull)objCDiscoveredNodeData - outDiscoveredNodeData:(chip::Dnssd::DiscoveredNodeData &)outDiscoveredNodeData; + outDiscoveredNodeData:(chip::Dnssd::CommissionNodeData &)outDiscoveredNodeData; /** * @brief C++ to Objective C converters @@ -51,7 +51,7 @@ + (ContentApp * _Nonnull)convertToObjCContentAppFrom:(TargetEndpointInfo * _Nonnull)cppTargetEndpointInfo; + (DiscoveredNodeData * _Nonnull)convertToObjCDiscoveredNodeDataFrom: - (const chip::Dnssd::DiscoveredNodeData * _Nonnull)cppDiscoveredNodedata; + (const chip::Dnssd::CommissionNodeData * _Nonnull)cppDiscoveredNodedata; + (VideoPlayer * _Nonnull)convertToObjCVideoPlayerFrom:(TargetVideoPlayerInfo * _Nonnull)cppTargetVideoPlayerInfo; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm index 902e386ae551e1..5cce096756bfa0 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm @@ -45,36 +45,36 @@ + (CHIP_ERROR)convertToCppTargetEndpointInfoFrom:(ContentApp * _Nonnull)objCCont } + (CHIP_ERROR)convertToCppDiscoveredNodeDataFrom:(DiscoveredNodeData * _Nonnull)objCDiscoveredNodeData - outDiscoveredNodeData:(chip::Dnssd::DiscoveredNodeData &)outDiscoveredNodeData + outDiscoveredNodeData:(chip::Dnssd::CommissionNodeData &)outDiscoveredNodeData { // setting CommissionNodeData - outDiscoveredNodeData.nodeData.deviceType = objCDiscoveredNodeData.deviceType; - outDiscoveredNodeData.nodeData.vendorId = objCDiscoveredNodeData.vendorId; - outDiscoveredNodeData.nodeData.productId = objCDiscoveredNodeData.productId; - outDiscoveredNodeData.nodeData.longDiscriminator = objCDiscoveredNodeData.longDiscriminator; - outDiscoveredNodeData.nodeData.commissioningMode = objCDiscoveredNodeData.commissioningMode; - outDiscoveredNodeData.nodeData.pairingHint = objCDiscoveredNodeData.pairingHint; - memset(outDiscoveredNodeData.nodeData.deviceName, '\0', sizeof(outDiscoveredNodeData.nodeData.deviceName)); + outDiscoveredNodeData.deviceType = objCDiscoveredNodeData.deviceType; + outDiscoveredNodeData.vendorId = objCDiscoveredNodeData.vendorId; + outDiscoveredNodeData.productId = objCDiscoveredNodeData.productId; + outDiscoveredNodeData.longDiscriminator = objCDiscoveredNodeData.longDiscriminator; + outDiscoveredNodeData.commissioningMode = objCDiscoveredNodeData.commissioningMode; + outDiscoveredNodeData.pairingHint = objCDiscoveredNodeData.pairingHint; + memset(outDiscoveredNodeData.deviceName, '\0', sizeof(outDiscoveredNodeData.deviceName)); if (objCDiscoveredNodeData.deviceName != nullptr) { - chip::Platform::CopyString(outDiscoveredNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, + chip::Platform::CopyString(outDiscoveredNodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, [objCDiscoveredNodeData.deviceName UTF8String]); } - outDiscoveredNodeData.nodeData.rotatingIdLen = objCDiscoveredNodeData.rotatingIdLen; + outDiscoveredNodeData.rotatingIdLen = objCDiscoveredNodeData.rotatingIdLen; memcpy( - outDiscoveredNodeData.nodeData.rotatingId, objCDiscoveredNodeData.rotatingId, objCDiscoveredNodeData.rotatingIdLen); + outDiscoveredNodeData.rotatingId, objCDiscoveredNodeData.rotatingId, objCDiscoveredNodeData.rotatingIdLen); // setting CommonResolutionData - outDiscoveredNodeData.resolutionData.port = objCDiscoveredNodeData.port; - memset(outDiscoveredNodeData.resolutionData.hostName, '\0', sizeof(outDiscoveredNodeData.resolutionData.hostName)); + outDiscoveredNodeData.port = objCDiscoveredNodeData.port; + memset(outDiscoveredNodeData.hostName, '\0', sizeof(outDiscoveredNodeData.hostName)); if (objCDiscoveredNodeData.hostName != nullptr) { - chip::Platform::CopyString(outDiscoveredNodeData.resolutionData.hostName, chip::Dnssd::kHostNameMaxLength + 1, + chip::Platform::CopyString(outDiscoveredNodeData.hostName, chip::Dnssd::kHostNameMaxLength + 1, [objCDiscoveredNodeData.hostName UTF8String]); } - outDiscoveredNodeData.resolutionData.interfaceId = chip::Inet::InterfaceId(objCDiscoveredNodeData.platformInterface); - outDiscoveredNodeData.resolutionData.numIPs = objCDiscoveredNodeData.numIPs; + outDiscoveredNodeData.interfaceId = chip::Inet::InterfaceId(objCDiscoveredNodeData.platformInterface); + outDiscoveredNodeData.numIPs = objCDiscoveredNodeData.numIPs; for (size_t i = 0; i < objCDiscoveredNodeData.numIPs; i++) { chip::Inet::IPAddress::FromString( - [objCDiscoveredNodeData.ipAddresses[i] UTF8String], outDiscoveredNodeData.resolutionData.ipAddress[i]); + [objCDiscoveredNodeData.ipAddresses[i] UTF8String], outDiscoveredNodeData.ipAddress[i]); } return CHIP_NO_ERROR; } @@ -116,36 +116,36 @@ + (ContentApp *)convertToObjCContentAppFrom:(TargetEndpointInfo * _Nonnull)cppTa return objCContentApp; } -+ (DiscoveredNodeData *)convertToObjCDiscoveredNodeDataFrom:(const chip::Dnssd::DiscoveredNodeData * _Nonnull)cppDiscoveredNodedata ++ (DiscoveredNodeData *)convertToObjCDiscoveredNodeDataFrom:(const chip::Dnssd::CommissionNodeData * _Nonnull)cppDiscoveredNodedata { DiscoveredNodeData * objCDiscoveredNodeData = [DiscoveredNodeData new]; // from CommissionNodeData - objCDiscoveredNodeData.deviceType = cppDiscoveredNodedata->nodeData.deviceType; - objCDiscoveredNodeData.vendorId = cppDiscoveredNodedata->nodeData.vendorId; - objCDiscoveredNodeData.productId = cppDiscoveredNodedata->nodeData.productId; - objCDiscoveredNodeData.longDiscriminator = cppDiscoveredNodedata->nodeData.longDiscriminator; - objCDiscoveredNodeData.commissioningMode = cppDiscoveredNodedata->nodeData.commissioningMode; - objCDiscoveredNodeData.pairingHint = cppDiscoveredNodedata->nodeData.pairingHint; - objCDiscoveredNodeData.deviceName = [NSString stringWithCString:cppDiscoveredNodedata->nodeData.deviceName + objCDiscoveredNodeData.deviceType = cppDiscoveredNodedata->deviceType; + objCDiscoveredNodeData.vendorId = cppDiscoveredNodedata->vendorId; + objCDiscoveredNodeData.productId = cppDiscoveredNodedata->productId; + objCDiscoveredNodeData.longDiscriminator = cppDiscoveredNodedata->longDiscriminator; + objCDiscoveredNodeData.commissioningMode = cppDiscoveredNodedata->commissioningMode; + objCDiscoveredNodeData.pairingHint = cppDiscoveredNodedata->pairingHint; + objCDiscoveredNodeData.deviceName = [NSString stringWithCString:cppDiscoveredNodedata->deviceName encoding:NSUTF8StringEncoding]; - objCDiscoveredNodeData.rotatingIdLen = cppDiscoveredNodedata->nodeData.rotatingIdLen; - objCDiscoveredNodeData.rotatingId = cppDiscoveredNodedata->nodeData.rotatingId; - objCDiscoveredNodeData.instanceName = [NSString stringWithCString:cppDiscoveredNodedata->nodeData.instanceName + objCDiscoveredNodeData.rotatingIdLen = cppDiscoveredNodedata->rotatingIdLen; + objCDiscoveredNodeData.rotatingId = cppDiscoveredNodedata->rotatingId; + objCDiscoveredNodeData.instanceName = [NSString stringWithCString:cppDiscoveredNodedata->instanceName encoding:NSUTF8StringEncoding]; // from CommonResolutionData - objCDiscoveredNodeData.port = cppDiscoveredNodedata->resolutionData.port; - objCDiscoveredNodeData.hostName = [NSString stringWithCString:cppDiscoveredNodedata->resolutionData.hostName + objCDiscoveredNodeData.port = cppDiscoveredNodedata->port; + objCDiscoveredNodeData.hostName = [NSString stringWithCString:cppDiscoveredNodedata->hostName encoding:NSUTF8StringEncoding]; - objCDiscoveredNodeData.platformInterface = cppDiscoveredNodedata->resolutionData.interfaceId.GetPlatformInterface(); - objCDiscoveredNodeData.numIPs = cppDiscoveredNodedata->resolutionData.numIPs; - if (cppDiscoveredNodedata->resolutionData.numIPs > 0) { + objCDiscoveredNodeData.platformInterface = cppDiscoveredNodedata->interfaceId.GetPlatformInterface(); + objCDiscoveredNodeData.numIPs = cppDiscoveredNodedata->numIPs; + if (cppDiscoveredNodedata->numIPs > 0) { objCDiscoveredNodeData.ipAddresses = [NSMutableArray new]; } - for (size_t i = 0; i < cppDiscoveredNodedata->resolutionData.numIPs; i++) { + for (size_t i = 0; i < cppDiscoveredNodedata->numIPs; i++) { char addrCString[chip::Inet::IPAddress::kMaxStringLength]; - cppDiscoveredNodedata->resolutionData.ipAddress[i].ToString(addrCString, chip::Inet::IPAddress::kMaxStringLength); + cppDiscoveredNodedata->ipAddress[i].ToString(addrCString, chip::Inet::IPAddress::kMaxStringLength); objCDiscoveredNodeData.ipAddresses[i] = [NSString stringWithCString:addrCString encoding:NSASCIIStringEncoding]; } return objCDiscoveredNodeData; diff --git a/examples/tv-casting-app/linux/CastingUtils.cpp b/examples/tv-casting-app/linux/CastingUtils.cpp index d4d71b5dd2c0ae..4a89d5bbbe851a 100644 --- a/examples/tv-casting-app/linux/CastingUtils.cpp +++ b/examples/tv-casting-app/linux/CastingUtils.cpp @@ -44,7 +44,7 @@ CHIP_ERROR DiscoverCommissioners() CHIP_ERROR RequestCommissioning(int index) { chip::Optional associatedConnectableVideoPlayer; - const Dnssd::DiscoveredNodeData * selectedCommissioner = + const Dnssd::CommissionNodeData * selectedCommissioner = CastingServer::GetInstance()->GetDiscoveredCommissioner(index, associatedConnectableVideoPlayer); if (selectedCommissioner == nullptr) { @@ -60,7 +60,7 @@ CHIP_ERROR RequestCommissioning(int index) * If non-null selectedCommissioner is provided, sends user directed commissioning * request to the selectedCommissioner and advertises self as commissionable node over DNS-SD */ -void PrepareForCommissioning(const Dnssd::DiscoveredNodeData * selectedCommissioner) +void PrepareForCommissioning(const Dnssd::CommissionNodeData * selectedCommissioner) { CastingServer::GetInstance()->Init(); @@ -96,7 +96,7 @@ void InitCommissioningFlow(intptr_t commandArg) for (int i = 0; i < CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES; i++) { chip::Optional associatedConnectableVideoPlayer; - const Dnssd::DiscoveredNodeData * commissioner = + const Dnssd::CommissionNodeData * commissioner = CastingServer::GetInstance()->GetDiscoveredCommissioner(i, associatedConnectableVideoPlayer); if (commissioner != nullptr) { @@ -286,7 +286,7 @@ void HandleCommissioningCompleteCallback(CHIP_ERROR err) #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT void HandleUDCSendExpiration(System::Layer * aSystemLayer, void * context) { - Dnssd::DiscoveredNodeData * selectedCommissioner = (Dnssd::DiscoveredNodeData *) context; + Dnssd::CommissionNodeData * selectedCommissioner = (Dnssd::CommissionNodeData *) context; // Send User Directed commissioning request ReturnOnFailure(CastingServer::GetInstance()->SendUserDirectedCommissioningRequest(selectedCommissioner)); diff --git a/examples/tv-casting-app/linux/CastingUtils.h b/examples/tv-casting-app/linux/CastingUtils.h index d87a8318948c76..1d780da8ebfeaf 100644 --- a/examples/tv-casting-app/linux/CastingUtils.h +++ b/examples/tv-casting-app/linux/CastingUtils.h @@ -34,7 +34,7 @@ CHIP_ERROR DiscoverCommissioners(); CHIP_ERROR RequestCommissioning(int index); -void PrepareForCommissioning(const chip::Dnssd::DiscoveredNodeData * selectedCommissioner = nullptr); +void PrepareForCommissioning(const chip::Dnssd::CommissionNodeData * selectedCommissioner = nullptr); void InitCommissioningFlow(intptr_t commandArg); diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp index 9dd365d8db559f..82cb1487b91eaa 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp @@ -73,32 +73,33 @@ CHIP_ERROR CastingPlayerDiscovery::StopDiscovery() return CHIP_NO_ERROR; } -void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) +void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & discNodeData) { ChipLogProgress(Discovery, "DeviceDiscoveryDelegateImpl::OnDiscoveredDevice() called"); VerifyOrReturn(mClientDelegate != nullptr, ChipLogError(Discovery, "DeviceDiscoveryDelegateImpl::OnDiscoveredDevice mClientDelegate is a nullptr")); + auto & nodeData = discNodeData; // convert nodeData to CastingPlayer CastingPlayerAttributes attributes; - snprintf(attributes.id, kIdMaxLength + 1, "%s%u", nodeData.resolutionData.hostName, nodeData.resolutionData.port); + snprintf(attributes.id, kIdMaxLength + 1, "%s%u", nodeData.hostName, nodeData.port); - chip::Platform::CopyString(attributes.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, nodeData.nodeData.deviceName); - chip::Platform::CopyString(attributes.hostName, chip::Dnssd::kHostNameMaxLength + 1, nodeData.resolutionData.hostName); + chip::Platform::CopyString(attributes.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, nodeData.deviceName); + chip::Platform::CopyString(attributes.hostName, chip::Dnssd::kHostNameMaxLength + 1, nodeData.hostName); chip::Platform::CopyString(attributes.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, - nodeData.nodeData.instanceName); + nodeData.instanceName); - attributes.numIPs = (unsigned int) nodeData.resolutionData.numIPs; + attributes.numIPs = (unsigned int) nodeData.numIPs; for (unsigned j = 0; j < attributes.numIPs; j++) { - attributes.ipAddresses[j] = nodeData.resolutionData.ipAddress[j]; + attributes.ipAddresses[j] = nodeData.ipAddress[j]; } - attributes.interfaceId = nodeData.resolutionData.interfaceId; - attributes.port = nodeData.resolutionData.port; - attributes.productId = nodeData.nodeData.productId; - attributes.vendorId = nodeData.nodeData.vendorId; - attributes.deviceType = nodeData.nodeData.deviceType; - attributes.supportsCommissionerGeneratedPasscode = nodeData.nodeData.supportsCommissionerGeneratedPasscode; + attributes.interfaceId = nodeData.interfaceId; + attributes.port = nodeData.port; + attributes.productId = nodeData.productId; + attributes.vendorId = nodeData.vendorId; + attributes.deviceType = nodeData.deviceType; + attributes.supportsCommissionerGeneratedPasscode = nodeData.supportsCommissionerGeneratedPasscode; memory::Strong player = std::make_shared(attributes); diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.h b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.h index 86886ac71be30f..24bbb00ce4907b 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.h +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.h @@ -68,7 +68,7 @@ class DeviceDiscoveryDelegateImpl : public chip::Controller::DeviceDiscoveryDele DeviceDiscoveryDelegateImpl() {} DeviceDiscoveryDelegateImpl(DiscoveryDelegate * delegate) { mClientDelegate = delegate; } - void OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) override; + void OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) override; }; /** diff --git a/examples/tv-casting-app/tv-casting-common/include/CastingServer.h b/examples/tv-casting-app/tv-casting-common/include/CastingServer.h index 49eb65d13786fb..da497a3d00c543 100644 --- a/examples/tv-casting-app/tv-casting-common/include/CastingServer.h +++ b/examples/tv-casting-app/tv-casting-common/include/CastingServer.h @@ -73,7 +73,7 @@ class CastingServer : public AppDelegate #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT CHIP_ERROR DiscoverCommissioners(chip::Controller::DeviceDiscoveryDelegate * deviceDiscoveryDelegate = nullptr); - const chip::Dnssd::DiscoveredNodeData * + const chip::Dnssd::CommissionNodeData * GetDiscoveredCommissioner(int index, chip::Optional & outAssociatedConnectableVideoPlayer); CHIP_ERROR OpenBasicCommissioningWindow(CommissioningCallbacks commissioningCallbacks, std::function onConnectionSuccess, @@ -82,7 +82,7 @@ class CastingServer : public AppDelegate #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT CHIP_ERROR SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress commissioner); - CHIP_ERROR SendUserDirectedCommissioningRequest(chip::Dnssd::DiscoveredNodeData * selectedCommissioner); + CHIP_ERROR SendUserDirectedCommissioningRequest(chip::Dnssd::CommissionNodeData * selectedCommissioner); #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT TargetVideoPlayerInfo * GetActiveTargetVideoPlayer() { return &mActiveTargetVideoPlayerInfo; } diff --git a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h index dd799bdf8c776d..9fa0a139bf3d6c 100644 --- a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h +++ b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h @@ -85,7 +85,7 @@ class TargetVideoPlayerInfo const char * GetHostName() const { return mHostName; } size_t GetNumIPs() const { return mNumIPs; } const chip::Inet::IPAddress * GetIpAddresses() const { return mIpAddress; } - bool IsSameAs(const chip::Dnssd::DiscoveredNodeData * discoveredNodeData); + bool IsSameAs(const chip::Dnssd::CommissionNodeData * discoveredNodeData); bool IsSameAs(const char * hostName, const char * deviceName, size_t numIPs, const chip::Inet::IPAddress * ipAddresses); uint16_t GetPort() const { return mPort; } diff --git a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp index ef56d3f1144644..7729dc0dcee874 100644 --- a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp @@ -253,37 +253,37 @@ chip::Inet::IPAddress * CastingServer::getIpAddressForUDCRequest(chip::Inet::IPA return &ipAddresses[ipIndexToUse]; } -CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(Dnssd::DiscoveredNodeData * selectedCommissioner) +CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(Dnssd::CommissionNodeData * selectedCommissioner) { mUdcInProgress = true; // Send User Directed commissioning request chip::Inet::IPAddress * ipAddressToUse = - getIpAddressForUDCRequest(selectedCommissioner->resolutionData.ipAddress, selectedCommissioner->resolutionData.numIPs); + getIpAddressForUDCRequest(selectedCommissioner->ipAddress, selectedCommissioner->numIPs); ReturnErrorOnFailure(SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP( - *ipAddressToUse, selectedCommissioner->resolutionData.port, selectedCommissioner->resolutionData.interfaceId))); - mTargetVideoPlayerVendorId = selectedCommissioner->nodeData.vendorId; - mTargetVideoPlayerProductId = selectedCommissioner->nodeData.productId; - mTargetVideoPlayerDeviceType = selectedCommissioner->nodeData.deviceType; - mTargetVideoPlayerNumIPs = selectedCommissioner->resolutionData.numIPs; + *ipAddressToUse, selectedCommissioner->port, selectedCommissioner->interfaceId))); + mTargetVideoPlayerVendorId = selectedCommissioner->vendorId; + mTargetVideoPlayerProductId = selectedCommissioner->productId; + mTargetVideoPlayerDeviceType = selectedCommissioner->deviceType; + mTargetVideoPlayerNumIPs = selectedCommissioner->numIPs; for (size_t i = 0; i < mTargetVideoPlayerNumIPs && i < chip::Dnssd::CommonResolutionData::kMaxIPAddresses; i++) { - mTargetVideoPlayerIpAddress[i] = selectedCommissioner->resolutionData.ipAddress[i]; + mTargetVideoPlayerIpAddress[i] = selectedCommissioner->ipAddress[i]; } chip::Platform::CopyString(mTargetVideoPlayerDeviceName, chip::Dnssd::kMaxDeviceNameLen + 1, - selectedCommissioner->nodeData.deviceName); + selectedCommissioner->deviceName); chip::Platform::CopyString(mTargetVideoPlayerHostName, chip::Dnssd::kHostNameMaxLength + 1, - selectedCommissioner->resolutionData.hostName); + selectedCommissioner->hostName); chip::Platform::CopyString(mTargetVideoPlayerInstanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, - selectedCommissioner->nodeData.instanceName); - mTargetVideoPlayerPort = selectedCommissioner->resolutionData.port; + selectedCommissioner->instanceName); + mTargetVideoPlayerPort = selectedCommissioner->port; return CHIP_NO_ERROR; } #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT -const Dnssd::DiscoveredNodeData * +const Dnssd::CommissionNodeData * CastingServer::GetDiscoveredCommissioner(int index, chip::Optional & outAssociatedConnectableVideoPlayer) { - const Dnssd::DiscoveredNodeData * discoveredNodeData = mCommissionableNodeController.GetDiscoveredCommissioner(index); + const Dnssd::CommissionNodeData * discoveredNodeData = mCommissionableNodeController.GetDiscoveredCommissioner(index); if (discoveredNodeData != nullptr) { for (size_t i = 0; i < kMaxCachedVideoPlayers && mCachedTargetVideoPlayerInfo[i].IsInitialized(); i++) diff --git a/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp b/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp index a57e2548009ada..0861f12cc95720 100644 --- a/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp @@ -18,27 +18,30 @@ #include "ConversionUtils.h" -CHIP_ERROR ConvertToDiscoveredNodeData(TargetVideoPlayerInfo * inPlayer, chip::Dnssd::DiscoveredNodeData & outNodeData) +CHIP_ERROR ConvertToDiscoveredNodeData(TargetVideoPlayerInfo * inPlayer, chip::Dnssd::DiscoveredNodeData & outDiscNodeData) { if (inPlayer == nullptr) return CHIP_ERROR_INVALID_ARGUMENT; + + outDiscNodeData.Set(); + auto & outNodeData = outDiscNodeData.Get(); - outNodeData.nodeData.vendorId = inPlayer->GetVendorId(); - outNodeData.nodeData.productId = static_cast(inPlayer->GetProductId()); - outNodeData.nodeData.deviceType = inPlayer->GetDeviceType(); - outNodeData.resolutionData.numIPs = inPlayer->GetNumIPs(); + outNodeData.vendorId = inPlayer->GetVendorId(); + outNodeData.productId = static_cast(inPlayer->GetProductId()); + outNodeData.deviceType = inPlayer->GetDeviceType(); + outNodeData.numIPs = inPlayer->GetNumIPs(); const chip::Inet::IPAddress * ipAddresses = inPlayer->GetIpAddresses(); if (ipAddresses != nullptr) { - for (size_t i = 0; i < outNodeData.resolutionData.numIPs && i < chip::Dnssd::CommonResolutionData::kMaxIPAddresses; i++) + for (size_t i = 0; i < outNodeData.numIPs && i < chip::Dnssd::CommonResolutionData::kMaxIPAddresses; i++) { - outNodeData.resolutionData.ipAddress[i] = ipAddresses[i]; + outNodeData.ipAddress[i] = ipAddresses[i]; } } - chip::Platform::CopyString(outNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, inPlayer->GetDeviceName()); - chip::Platform::CopyString(outNodeData.resolutionData.hostName, chip::Dnssd::kHostNameMaxLength + 1, inPlayer->GetHostName()); + chip::Platform::CopyString(outNodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, inPlayer->GetDeviceName()); + chip::Platform::CopyString(outNodeData.hostName, chip::Dnssd::kHostNameMaxLength + 1, inPlayer->GetHostName()); return CHIP_NO_ERROR; } diff --git a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp index c182856039975a..d22c9682c01769 100644 --- a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp @@ -224,7 +224,7 @@ bool TargetVideoPlayerInfo::IsSameAs(const char * hostName, const char * deviceN return true; } -bool TargetVideoPlayerInfo::IsSameAs(const chip::Dnssd::DiscoveredNodeData * discoveredNodeData) +bool TargetVideoPlayerInfo::IsSameAs(const chip::Dnssd::CommissionNodeData * discoveredNodeData) { // return false because 'this' VideoPlayer is not null if (discoveredNodeData == nullptr) @@ -232,6 +232,6 @@ bool TargetVideoPlayerInfo::IsSameAs(const chip::Dnssd::DiscoveredNodeData * dis return false; } - return IsSameAs(discoveredNodeData->resolutionData.hostName, discoveredNodeData->nodeData.deviceName, - discoveredNodeData->resolutionData.numIPs, discoveredNodeData->resolutionData.ipAddress); + return IsSameAs(discoveredNodeData->hostName, discoveredNodeData->deviceName, + discoveredNodeData->numIPs, discoveredNodeData->ipAddress); } diff --git a/src/controller/AbstractDnssdDiscoveryController.cpp b/src/controller/AbstractDnssdDiscoveryController.cpp index 4d916e068ddbe6..0f9b8d739fd84d 100644 --- a/src/controller/AbstractDnssdDiscoveryController.cpp +++ b/src/controller/AbstractDnssdDiscoveryController.cpp @@ -25,20 +25,24 @@ namespace chip { namespace Controller { -void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData) +void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & discNodeData) { + VerifyOrReturn(discNodeData.Is()); + auto discoveredNodes = GetDiscoveredNodes(); + auto & nodeData = discNodeData.Get(); for (auto & discoveredNode : discoveredNodes) { - if (!discoveredNode.resolutionData.IsValid()) + + if (!discoveredNode.IsValid()) { continue; } // TODO(#32576) Check if IP address are the same. Must account for `numIPs` in the list of `ipAddress`. // Additionally, must NOT assume that the ordering is consistent. - if (strcmp(discoveredNode.resolutionData.hostName, nodeData.resolutionData.hostName) == 0 && - discoveredNode.resolutionData.port == nodeData.resolutionData.port && - discoveredNode.resolutionData.numIPs == nodeData.resolutionData.numIPs) + if (strcmp(discoveredNode.hostName, nodeData.hostName) == 0 && + discoveredNode.port == nodeData.port && + discoveredNode.numIPs == nodeData.numIPs) { discoveredNode = nodeData; if (mDeviceDiscoveryDelegate != nullptr) @@ -51,7 +55,7 @@ void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::Disco // Node not yet in the list for (auto & discoveredNode : discoveredNodes) { - if (!discoveredNode.resolutionData.IsValid()) + if (!discoveredNode.IsValid()) { discoveredNode = nodeData; if (mDeviceDiscoveryDelegate != nullptr) @@ -61,7 +65,7 @@ void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::Disco return; } } - ChipLogError(Discovery, "Failed to add discovered node with hostname %s- Insufficient space", nodeData.resolutionData.hostName); + ChipLogError(Discovery, "Failed to add discovered node with hostname %s- Insufficient space", nodeData.hostName); } CHIP_ERROR AbstractDnssdDiscoveryController::SetUpNodeDiscovery() @@ -74,11 +78,11 @@ CHIP_ERROR AbstractDnssdDiscoveryController::SetUpNodeDiscovery() return CHIP_NO_ERROR; } -const Dnssd::DiscoveredNodeData * AbstractDnssdDiscoveryController::GetDiscoveredNode(int idx) +const Dnssd::CommissionNodeData * AbstractDnssdDiscoveryController::GetDiscoveredNode(int idx) { // TODO(cecille): Add assertion about main loop. auto discoveredNodes = GetDiscoveredNodes(); - if (0 <= idx && idx < CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES && discoveredNodes.data()[idx].resolutionData.IsValid()) + if (0 <= idx && idx < CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES && discoveredNodes.data()[idx].IsValid()) { return discoveredNodes.data() + idx; } diff --git a/src/controller/AbstractDnssdDiscoveryController.h b/src/controller/AbstractDnssdDiscoveryController.h index c8c9053f878ff3..8aeaece1bb521b 100644 --- a/src/controller/AbstractDnssdDiscoveryController.h +++ b/src/controller/AbstractDnssdDiscoveryController.h @@ -45,9 +45,9 @@ class DLL_EXPORT AbstractDnssdDiscoveryController : public Dnssd::DiscoverNodeDe CHIP_ERROR StopDiscovery() { return mDNSResolver.StopDiscovery(); }; protected: - using DiscoveredNodeList = FixedSpan; + using DiscoveredNodeList = FixedSpan; CHIP_ERROR SetUpNodeDiscovery(); - const Dnssd::DiscoveredNodeData * GetDiscoveredNode(int idx); + const Dnssd::CommissionNodeData * GetDiscoveredNode(int idx); virtual DiscoveredNodeList GetDiscoveredNodes() = 0; DeviceDiscoveryDelegate * mDeviceDiscoveryDelegate = nullptr; Dnssd::ResolverProxy mDNSResolver; diff --git a/src/controller/CHIPCommissionableNodeController.cpp b/src/controller/CHIPCommissionableNodeController.cpp index f116928b585d82..eaf212e90693c7 100644 --- a/src/controller/CHIPCommissionableNodeController.cpp +++ b/src/controller/CHIPCommissionableNodeController.cpp @@ -45,7 +45,7 @@ CommissionableNodeController::~CommissionableNodeController() mDNSResolver.SetDiscoveryDelegate(nullptr); } -const Dnssd::DiscoveredNodeData * CommissionableNodeController::GetDiscoveredCommissioner(int idx) +const Dnssd::CommissionNodeData * CommissionableNodeController::GetDiscoveredCommissioner(int idx) { return GetDiscoveredNode(idx); } diff --git a/src/controller/CHIPCommissionableNodeController.h b/src/controller/CHIPCommissionableNodeController.h index 5c9f57919a2897..9605653cbb87d6 100644 --- a/src/controller/CHIPCommissionableNodeController.h +++ b/src/controller/CHIPCommissionableNodeController.h @@ -49,13 +49,13 @@ class DLL_EXPORT CommissionableNodeController : public AbstractDnssdDiscoveryCon * Otherwise, returns nullptr * See Resolver.h IsValid() */ - const Dnssd::DiscoveredNodeData * GetDiscoveredCommissioner(int idx); + const Dnssd::CommissionNodeData * GetDiscoveredCommissioner(int idx); protected: DiscoveredNodeList GetDiscoveredNodes() override { return DiscoveredNodeList(mDiscoveredCommissioners); } private: - Dnssd::DiscoveredNodeData mDiscoveredCommissioners[CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES]; + Dnssd::CommissionNodeData mDiscoveredCommissioners[CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES]; }; } // namespace Controller diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 9103a0ba728156..bb1143265945c2 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1706,7 +1706,7 @@ CHIP_ERROR DeviceCommissioner::StopCommissionableDiscovery() return mDNSResolver.StopDiscovery(); } -const Dnssd::DiscoveredNodeData * DeviceCommissioner::GetDiscoveredDevice(int idx) +const Dnssd::CommissionNodeData * DeviceCommissioner::GetDiscoveredDevice(int idx) { return GetDiscoveredNode(idx); } diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index 5290a26fdfbc47..42b8a7e2481541 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -412,7 +412,7 @@ class DLL_EXPORT DeviceController : public AbstractDnssdDiscoveryController // TODO(cecille): Make this configuarable. static constexpr int kMaxCommissionableNodes = 10; - Dnssd::DiscoveredNodeData mCommissionableNodes[kMaxCommissionableNodes]; + Dnssd::CommissionNodeData mCommissionableNodes[kMaxCommissionableNodes]; DeviceControllerSystemState * mSystemState = nullptr; ControllerDeviceInitParams GetControllerDeviceInitParams(); @@ -730,7 +730,7 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, * Should be called on main loop thread. * @return const DiscoveredNodeData* info about the selected device. May be nullptr if no information has been returned yet. */ - const Dnssd::DiscoveredNodeData * GetDiscoveredDevice(int idx); + const Dnssd::CommissionNodeData * GetDiscoveredDevice(int idx); /** * @brief diff --git a/src/controller/DeviceDiscoveryDelegate.h b/src/controller/DeviceDiscoveryDelegate.h index a15acaa53cd0eb..8e82f6d32d404e 100644 --- a/src/controller/DeviceDiscoveryDelegate.h +++ b/src/controller/DeviceDiscoveryDelegate.h @@ -29,7 +29,7 @@ class DLL_EXPORT DeviceDiscoveryDelegate { public: virtual ~DeviceDiscoveryDelegate() {} - virtual void OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) = 0; + virtual void OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) = 0; }; } // namespace Controller diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 3a995a6e93579a..7ae5c9d7b2e89d 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -330,24 +330,30 @@ bool SetUpCodePairer::IdIsPresent(uint16_t vendorOrProductID) return vendorOrProductID != kNotAvailable; } -bool SetUpCodePairer::NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & nodeData) const +bool SetUpCodePairer::NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & discNodeData) const { - if (nodeData.nodeData.commissioningMode == 0) + if (!discNodeData.Is()) + { + return false; + } + + Dnssd::CommissionNodeData nodeData = discNodeData.Get(); + if (nodeData.commissioningMode == 0) { ChipLogProgress(Controller, "Discovered device does not have an open commissioning window."); return false; } // The advertisement may not include a vendor id. - if (IdIsPresent(mPayloadVendorID) && IdIsPresent(nodeData.nodeData.vendorId) && mPayloadVendorID != nodeData.nodeData.vendorId) + if (IdIsPresent(mPayloadVendorID) && IdIsPresent(nodeData.vendorId) && mPayloadVendorID != nodeData.vendorId) { ChipLogProgress(Controller, "Discovered device does not match our vendor id."); return false; } // The advertisement may not include a product id. - if (IdIsPresent(mPayloadProductID) && IdIsPresent(nodeData.nodeData.productId) && - mPayloadProductID != nodeData.nodeData.productId) + if (IdIsPresent(mPayloadProductID) && IdIsPresent(nodeData.productId) && + mPayloadProductID != nodeData.productId) { ChipLogProgress(Controller, "Discovered device does not match our product id."); return false; @@ -357,10 +363,10 @@ bool SetUpCodePairer::NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & switch (mCurrentFilter.type) { case Dnssd::DiscoveryFilterType::kShortDiscriminator: - discriminatorMatches = (((nodeData.nodeData.longDiscriminator >> 8) & 0x0F) == mCurrentFilter.code); + discriminatorMatches = (((nodeData.longDiscriminator >> 8) & 0x0F) == mCurrentFilter.code); break; case Dnssd::DiscoveryFilterType::kLongDiscriminator: - discriminatorMatches = (nodeData.nodeData.longDiscriminator == mCurrentFilter.code); + discriminatorMatches = (nodeData.longDiscriminator == mCurrentFilter.code); break; default: ChipLogError(Controller, "Unknown filter type; all matches will fail"); @@ -382,7 +388,7 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover ChipLogProgress(Controller, "Discovered device to be commissioned over DNS-SD"); - NotifyCommissionableDeviceDiscovered(nodeData.resolutionData); + NotifyCommissionableDeviceDiscovered((Dnssd::CommonResolutionData &)nodeData.Get()); } void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::CommonResolutionData & resolutionData) diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 83c0d029d8ddb7..352dee619172ad 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1839,7 +1839,7 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl chip::DeviceLayer::StackLock lock; AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); - const Dnssd::DiscoveredNodeData * data = wrapper->Controller()->GetDiscoveredDevice(idx); + const Dnssd::CommissionNodeData * data = wrapper->Controller()->GetDiscoveredDevice(idx); if (data == nullptr) { @@ -1866,21 +1866,21 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl jobject discoveredObj = env->NewObject(discoveredDeviceCls, constructor); - env->SetLongField(discoveredObj, discrminatorID, data->nodeData.longDiscriminator); + env->SetLongField(discoveredObj, discrminatorID, data->longDiscriminator); char ipAddress[100]; - data->resolutionData.ipAddress[0].ToString(ipAddress, 100); + data->ipAddress[0].ToString(ipAddress, 100); jstring jniipAdress = env->NewStringUTF(ipAddress); env->SetObjectField(discoveredObj, ipAddressID, jniipAdress); - env->SetIntField(discoveredObj, portID, static_cast(data->resolutionData.port)); - env->SetLongField(discoveredObj, deviceTypeID, static_cast(data->nodeData.deviceType)); - env->SetIntField(discoveredObj, vendorIdID, static_cast(data->nodeData.vendorId)); - env->SetIntField(discoveredObj, productIdID, static_cast(data->nodeData.productId)); + env->SetIntField(discoveredObj, portID, static_cast(data->port)); + env->SetLongField(discoveredObj, deviceTypeID, static_cast(data->deviceType)); + env->SetIntField(discoveredObj, vendorIdID, static_cast(data->vendorId)); + env->SetIntField(discoveredObj, productIdID, static_cast(data->productId)); jbyteArray jRotatingId; - CHIP_ERROR err = JniReferences::GetInstance().N2J_ByteArray(env, data->nodeData.rotatingId, - static_cast(data->nodeData.rotatingIdLen), jRotatingId); + CHIP_ERROR err = JniReferences::GetInstance().N2J_ByteArray(env, data->rotatingId, + static_cast(data->rotatingIdLen), jRotatingId); if (err != CHIP_NO_ERROR) { @@ -1888,12 +1888,12 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl return nullptr; } env->SetObjectField(discoveredObj, rotatingIdID, static_cast(jRotatingId)); - env->SetObjectField(discoveredObj, instanceNameID, env->NewStringUTF(data->nodeData.instanceName)); - env->SetObjectField(discoveredObj, deviceNameID, env->NewStringUTF(data->nodeData.deviceName)); - env->SetObjectField(discoveredObj, pairingInstructionID, env->NewStringUTF(data->nodeData.pairingInstruction)); + env->SetObjectField(discoveredObj, instanceNameID, env->NewStringUTF(data->instanceName)); + env->SetObjectField(discoveredObj, deviceNameID, env->NewStringUTF(data->deviceName)); + env->SetObjectField(discoveredObj, pairingInstructionID, env->NewStringUTF(data->pairingInstruction)); - env->CallVoidMethod(discoveredObj, setCommissioningModeID, static_cast(data->nodeData.commissioningMode)); - env->CallVoidMethod(discoveredObj, setPairingHintID, static_cast(data->nodeData.pairingHint)); + env->CallVoidMethod(discoveredObj, setCommissioningModeID, static_cast(data->commissioningMode)); + env->CallVoidMethod(discoveredObj, setPairingHintID, static_cast(data->pairingHint)); return discoveredObj; } diff --git a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp index 39d70e350ae4db..4f38ed699f19f0 100644 --- a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp +++ b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp @@ -76,58 +76,58 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( { for (int i = 0; i < CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES; ++i) { - const chip::Dnssd::DiscoveredNodeData * dnsSdInfo = commissionableNodeCtrl->GetDiscoveredCommissioner(i); + const chip::Dnssd::CommissionNodeData * dnsSdInfo = commissionableNodeCtrl->GetDiscoveredCommissioner(i); if (dnsSdInfo == nullptr) { continue; } char rotatingId[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->nodeData.rotatingId, dnsSdInfo->nodeData.rotatingIdLen, rotatingId, + Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissioner %d", i); - ChipLogProgress(Discovery, "\tInstance name:\t\t%s", dnsSdInfo->nodeData.instanceName); - ChipLogProgress(Discovery, "\tHost name:\t\t%s", dnsSdInfo->resolutionData.hostName); - ChipLogProgress(Discovery, "\tPort:\t\t\t%u", dnsSdInfo->resolutionData.port); - ChipLogProgress(Discovery, "\tLong discriminator:\t%u", dnsSdInfo->nodeData.longDiscriminator); - ChipLogProgress(Discovery, "\tVendor ID:\t\t%u", dnsSdInfo->nodeData.vendorId); - ChipLogProgress(Discovery, "\tProduct ID:\t\t%u", dnsSdInfo->nodeData.productId); - ChipLogProgress(Discovery, "\tCommissioning Mode\t%u", dnsSdInfo->nodeData.commissioningMode); - ChipLogProgress(Discovery, "\tDevice Type\t\t%u", dnsSdInfo->nodeData.deviceType); - ChipLogProgress(Discovery, "\tDevice Name\t\t%s", dnsSdInfo->nodeData.deviceName); + ChipLogProgress(Discovery, "\tInstance name:\t\t%s", dnsSdInfo->instanceName); + ChipLogProgress(Discovery, "\tHost name:\t\t%s", dnsSdInfo->hostName); + ChipLogProgress(Discovery, "\tPort:\t\t\t%u", dnsSdInfo->port); + ChipLogProgress(Discovery, "\tLong discriminator:\t%u", dnsSdInfo->longDiscriminator); + ChipLogProgress(Discovery, "\tVendor ID:\t\t%u", dnsSdInfo->vendorId); + ChipLogProgress(Discovery, "\tProduct ID:\t\t%u", dnsSdInfo->productId); + ChipLogProgress(Discovery, "\tCommissioning Mode\t%u", dnsSdInfo->commissioningMode); + ChipLogProgress(Discovery, "\tDevice Type\t\t%u", dnsSdInfo->deviceType); + ChipLogProgress(Discovery, "\tDevice Name\t\t%s", dnsSdInfo->deviceName); ChipLogProgress(Discovery, "\tRotating Id\t\t%s", rotatingId); - ChipLogProgress(Discovery, "\tPairing Instruction\t%s", dnsSdInfo->nodeData.pairingInstruction); - ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->nodeData.pairingHint); - if (dnsSdInfo->resolutionData.GetMrpRetryIntervalIdle().HasValue()) + ChipLogProgress(Discovery, "\tPairing Instruction\t%s", dnsSdInfo->pairingInstruction); + ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->pairingHint); + if (dnsSdInfo->GetMrpRetryIntervalIdle().HasValue()) { ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", - dnsSdInfo->resolutionData.GetMrpRetryIntervalIdle().Value().count()); + dnsSdInfo->GetMrpRetryIntervalIdle().Value().count()); } else { ChipLogProgress(Discovery, "\tMrp Interval idle\tNot present"); } - if (dnsSdInfo->resolutionData.GetMrpRetryIntervalActive().HasValue()) + if (dnsSdInfo->GetMrpRetryIntervalActive().HasValue()) { ChipLogProgress(Discovery, "\tMrp Interval active\t%u", - dnsSdInfo->resolutionData.GetMrpRetryIntervalActive().Value().count()); + dnsSdInfo->GetMrpRetryIntervalActive().Value().count()); } else { ChipLogProgress(Discovery, "\tMrp Interval active\tNot present"); } - ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->resolutionData.supportsTcp); + ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp); - if (dnsSdInfo->resolutionData.isICDOperatingAsLIT.HasValue()) + if (dnsSdInfo->isICDOperatingAsLIT.HasValue()) { ChipLogProgress(Discovery, "\tICD is operating as a\t%s", - dnsSdInfo->resolutionData.isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + dnsSdInfo->isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); } - for (unsigned j = 0; j < dnsSdInfo->resolutionData.numIPs; ++j) + for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j) { char buf[chip::Inet::IPAddress::kMaxStringLength]; - dnsSdInfo->resolutionData.ipAddress[j].ToString(buf); + dnsSdInfo->ipAddress[j].ToString(buf); ChipLogProgress(Discovery, "\tAddress %d:\t\t%s", j, buf); } } diff --git a/src/controller/python/ChipDeviceController-Discovery.cpp b/src/controller/python/ChipDeviceController-Discovery.cpp index a8896628680a8f..c97ee6d5d4429b 100644 --- a/src/controller/python/ChipDeviceController-Discovery.cpp +++ b/src/controller/python/ChipDeviceController-Discovery.cpp @@ -40,7 +40,7 @@ bool pychip_DeviceController_HasDiscoveredCommissionableNode(Controller::DeviceC { for (int i = 0; i < devCtrl->GetMaxCommissionableNodesSupported(); ++i) { - const Dnssd::DiscoveredNodeData * dnsSdInfo = devCtrl->GetDiscoveredDevice(i); + const Dnssd::CommissionNodeData * dnsSdInfo = devCtrl->GetDiscoveredDevice(i); if (dnsSdInfo == nullptr) { continue; @@ -101,7 +101,7 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De for (int i = 0; i < devCtrl->GetMaxCommissionableNodesSupported(); ++i) { - const Dnssd::DiscoveredNodeData * dnsSdInfo = devCtrl->GetDiscoveredDevice(i); + const Dnssd::CommissionNodeData * dnsSdInfo = devCtrl->GetDiscoveredDevice(i); if (dnsSdInfo == nullptr) { continue; @@ -110,49 +110,49 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De Json::Value jsonVal; char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->nodeData.rotatingId, dnsSdInfo->nodeData.rotatingIdLen, rotatingId, + Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissionable Node %d", i); - jsonVal["instanceName"] = dnsSdInfo->nodeData.instanceName; - jsonVal["hostName"] = dnsSdInfo->resolutionData.hostName; - jsonVal["port"] = dnsSdInfo->resolutionData.port; - jsonVal["longDiscriminator"] = dnsSdInfo->nodeData.longDiscriminator; - jsonVal["vendorId"] = dnsSdInfo->nodeData.vendorId; - jsonVal["productId"] = dnsSdInfo->nodeData.productId; - jsonVal["commissioningMode"] = dnsSdInfo->nodeData.commissioningMode; - jsonVal["deviceType"] = dnsSdInfo->nodeData.deviceType; - jsonVal["deviceName"] = dnsSdInfo->nodeData.deviceName; - jsonVal["pairingInstruction"] = dnsSdInfo->nodeData.pairingInstruction; - jsonVal["pairingHint"] = dnsSdInfo->nodeData.pairingHint; - if (dnsSdInfo->resolutionData.GetMrpRetryIntervalIdle().HasValue()) + jsonVal["instanceName"] = dnsSdInfo->instanceName; + jsonVal["hostName"] = dnsSdInfo->hostName; + jsonVal["port"] = dnsSdInfo->port; + jsonVal["longDiscriminator"] = dnsSdInfo->longDiscriminator; + jsonVal["vendorId"] = dnsSdInfo->vendorId; + jsonVal["productId"] = dnsSdInfo->productId; + jsonVal["commissioningMode"] = dnsSdInfo->commissioningMode; + jsonVal["deviceType"] = dnsSdInfo->deviceType; + jsonVal["deviceName"] = dnsSdInfo->deviceName; + jsonVal["pairingInstruction"] = dnsSdInfo->pairingInstruction; + jsonVal["pairingHint"] = dnsSdInfo->pairingHint; + if (dnsSdInfo->GetMrpRetryIntervalIdle().HasValue()) { - jsonVal["mrpRetryIntervalIdle"] = dnsSdInfo->resolutionData.GetMrpRetryIntervalIdle().Value().count(); + jsonVal["mrpRetryIntervalIdle"] = dnsSdInfo->GetMrpRetryIntervalIdle().Value().count(); } - if (dnsSdInfo->resolutionData.GetMrpRetryIntervalActive().HasValue()) + if (dnsSdInfo->GetMrpRetryIntervalActive().HasValue()) { - jsonVal["mrpRetryIntervalActive"] = dnsSdInfo->resolutionData.GetMrpRetryIntervalActive().Value().count(); + jsonVal["mrpRetryIntervalActive"] = dnsSdInfo->GetMrpRetryIntervalActive().Value().count(); } - if (dnsSdInfo->resolutionData.GetMrpRetryActiveThreshold().HasValue()) + if (dnsSdInfo->GetMrpRetryActiveThreshold().HasValue()) { - jsonVal["mrpRetryActiveThreshold"] = dnsSdInfo->resolutionData.GetMrpRetryActiveThreshold().Value().count(); + jsonVal["mrpRetryActiveThreshold"] = dnsSdInfo->GetMrpRetryActiveThreshold().Value().count(); } - jsonVal["supportsTcp"] = dnsSdInfo->resolutionData.supportsTcp; + jsonVal["supportsTcp"] = dnsSdInfo->supportsTcp; { Json::Value addresses; - for (unsigned j = 0; j < dnsSdInfo->resolutionData.numIPs; ++j) + for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j) { char buf[Inet::IPAddress::kMaxStringLength]; - dnsSdInfo->resolutionData.ipAddress[j].ToString(buf); + dnsSdInfo->ipAddress[j].ToString(buf); addresses[j] = buf; } jsonVal["addresses"] = addresses; } - if (dnsSdInfo->resolutionData.isICDOperatingAsLIT.HasValue()) + if (dnsSdInfo->isICDOperatingAsLIT.HasValue()) { - jsonVal["isICDOperatingAsLIT"] = dnsSdInfo->resolutionData.isICDOperatingAsLIT.Value(); + jsonVal["isICDOperatingAsLIT"] = dnsSdInfo->isICDOperatingAsLIT.Value(); } - if (dnsSdInfo->nodeData.rotatingIdLen > 0) + if (dnsSdInfo->rotatingIdLen > 0) { jsonVal["rotatingId"] = rotatingId; } @@ -168,56 +168,56 @@ void pychip_DeviceController_PrintDiscoveredDevices(Controller::DeviceCommission { for (int i = 0; i < devCtrl->GetMaxCommissionableNodesSupported(); ++i) { - const Dnssd::DiscoveredNodeData * dnsSdInfo = devCtrl->GetDiscoveredDevice(i); + const Dnssd::CommissionNodeData * dnsSdInfo = devCtrl->GetDiscoveredDevice(i); if (dnsSdInfo == nullptr) { continue; } char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->nodeData.rotatingId, dnsSdInfo->nodeData.rotatingIdLen, rotatingId, + Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissionable Node %d", i); - ChipLogProgress(Discovery, "\tInstance name:\t\t%s", dnsSdInfo->nodeData.instanceName); - ChipLogProgress(Discovery, "\tHost name:\t\t%s", dnsSdInfo->resolutionData.hostName); - ChipLogProgress(Discovery, "\tPort:\t\t\t%u", dnsSdInfo->resolutionData.port); - ChipLogProgress(Discovery, "\tLong discriminator:\t%u", dnsSdInfo->nodeData.longDiscriminator); - ChipLogProgress(Discovery, "\tVendor ID:\t\t%u", dnsSdInfo->nodeData.vendorId); - ChipLogProgress(Discovery, "\tProduct ID:\t\t%u", dnsSdInfo->nodeData.productId); - ChipLogProgress(Discovery, "\tCommissioning Mode\t%u", dnsSdInfo->nodeData.commissioningMode); - ChipLogProgress(Discovery, "\tDevice Type\t\t%u", dnsSdInfo->nodeData.deviceType); - ChipLogProgress(Discovery, "\tDevice Name\t\t%s", dnsSdInfo->nodeData.deviceName); + ChipLogProgress(Discovery, "\tInstance name:\t\t%s", dnsSdInfo->instanceName); + ChipLogProgress(Discovery, "\tHost name:\t\t%s", dnsSdInfo->hostName); + ChipLogProgress(Discovery, "\tPort:\t\t\t%u", dnsSdInfo->port); + ChipLogProgress(Discovery, "\tLong discriminator:\t%u", dnsSdInfo->longDiscriminator); + ChipLogProgress(Discovery, "\tVendor ID:\t\t%u", dnsSdInfo->vendorId); + ChipLogProgress(Discovery, "\tProduct ID:\t\t%u", dnsSdInfo->productId); + ChipLogProgress(Discovery, "\tCommissioning Mode\t%u", dnsSdInfo->commissioningMode); + ChipLogProgress(Discovery, "\tDevice Type\t\t%u", dnsSdInfo->deviceType); + ChipLogProgress(Discovery, "\tDevice Name\t\t%s", dnsSdInfo->deviceName); ChipLogProgress(Discovery, "\tRotating Id\t\t%s", rotatingId); - ChipLogProgress(Discovery, "\tPairing Instruction\t%s", dnsSdInfo->nodeData.pairingInstruction); - ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->nodeData.pairingHint); - if (dnsSdInfo->resolutionData.GetMrpRetryIntervalIdle().HasValue()) + ChipLogProgress(Discovery, "\tPairing Instruction\t%s", dnsSdInfo->pairingInstruction); + ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->pairingHint); + if (dnsSdInfo->GetMrpRetryIntervalIdle().HasValue()) { ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", - dnsSdInfo->resolutionData.GetMrpRetryIntervalIdle().Value().count()); + dnsSdInfo->GetMrpRetryIntervalIdle().Value().count()); } else { ChipLogProgress(Discovery, "\tMrp Interval idle\tNot present"); } - if (dnsSdInfo->resolutionData.GetMrpRetryIntervalActive().HasValue()) + if (dnsSdInfo->GetMrpRetryIntervalActive().HasValue()) { ChipLogProgress(Discovery, "\tMrp Interval active\t%u", - dnsSdInfo->resolutionData.GetMrpRetryIntervalActive().Value().count()); + dnsSdInfo->GetMrpRetryIntervalActive().Value().count()); } else { ChipLogProgress(Discovery, "\tMrp Interval active\tNot present"); } - ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->resolutionData.supportsTcp); - if (dnsSdInfo->resolutionData.isICDOperatingAsLIT.HasValue()) + ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp); + if (dnsSdInfo->isICDOperatingAsLIT.HasValue()) { ChipLogProgress(Discovery, "\tICD is operating as a\t%s", - dnsSdInfo->resolutionData.isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + dnsSdInfo->isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); } - for (unsigned j = 0; j < dnsSdInfo->resolutionData.numIPs; ++j) + for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j) { char buf[Inet::IPAddress::kMaxStringLength]; - dnsSdInfo->resolutionData.ipAddress[j].ToString(buf); + dnsSdInfo->ipAddress[j].ToString(buf); ChipLogProgress(Discovery, "\tAddress %d:\t\t%s", j, buf); } } @@ -226,13 +226,13 @@ void pychip_DeviceController_PrintDiscoveredDevices(Controller::DeviceCommission bool pychip_DeviceController_GetIPForDiscoveredDevice(Controller::DeviceCommissioner * devCtrl, int idx, char * addrStr, uint32_t len) { - const Dnssd::DiscoveredNodeData * dnsSdInfo = devCtrl->GetDiscoveredDevice(idx); + const Dnssd::CommissionNodeData * dnsSdInfo = devCtrl->GetDiscoveredDevice(idx); if (dnsSdInfo == nullptr) { return false; } // TODO(cecille): Select which one we actually want. - if (dnsSdInfo->resolutionData.ipAddress[0].ToString(addrStr, len) == addrStr) + if (dnsSdInfo->ipAddress[0].ToString(addrStr, len) == addrStr) { return true; } diff --git a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp index a83a56c1b813f9..534383fa8aca43 100644 --- a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp +++ b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp @@ -21,15 +21,15 @@ namespace chip { namespace Controller { -void ScriptPairingDeviceDiscoveryDelegate::OnDiscoveredDevice(const Dnssd::DiscoveredNodeData & nodeData) +void ScriptPairingDeviceDiscoveryDelegate::OnDiscoveredDevice(const Dnssd::CommissionNodeData & nodeData) { // Ignore nodes with closed comissioning window - VerifyOrReturn(nodeData.nodeData.commissioningMode != 0); + VerifyOrReturn(nodeData.commissioningMode != 0); VerifyOrReturn(mActiveDeviceCommissioner != nullptr); - const uint16_t port = nodeData.resolutionData.port; + const uint16_t port = nodeData.port; char buf[chip::Inet::IPAddress::kMaxStringLength]; - nodeData.resolutionData.ipAddress[0].ToString(buf); + nodeData.ipAddress[0].ToString(buf); ChipLogProgress(chipTool, "Discovered Device: %s:%u", buf, port); // Cancel discovery timer. @@ -39,8 +39,8 @@ void ScriptPairingDeviceDiscoveryDelegate::OnDiscoveredDevice(const Dnssd::Disco mActiveDeviceCommissioner->RegisterDeviceDiscoveryDelegate(nullptr); Inet::InterfaceId interfaceId = - nodeData.resolutionData.ipAddress[0].IsIPv6LinkLocal() ? nodeData.resolutionData.interfaceId : Inet::InterfaceId::Null(); - auto peerAddress = Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], port, interfaceId); + nodeData.ipAddress[0].IsIPv6LinkLocal() ? nodeData.interfaceId : Inet::InterfaceId::Null(); + auto peerAddress = Transport::PeerAddress::UDP(nodeData.ipAddress[0], port, interfaceId); RendezvousParameters keyExchangeParams = RendezvousParameters().SetSetupPINCode(mSetupPasscode).SetPeerAddress(peerAddress); diff --git a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h index 7745bb13de4c15..944e0a0a047851 100644 --- a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h +++ b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h @@ -44,7 +44,7 @@ class ScriptPairingDeviceDiscoveryDelegate : public DeviceDiscoveryDelegate return chip::DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(discoveryTimeoutMsec), OnDiscoveredTimeout, this); } - void OnDiscoveredDevice(const Dnssd::DiscoveredNodeData & nodeData); + void OnDiscoveredDevice(const Dnssd::CommissionNodeData & nodeData); private: static void OnDiscoveredTimeout(System::Layer * layer, void * context) diff --git a/src/controller/tests/TestCommissionableNodeController.cpp b/src/controller/tests/TestCommissionableNodeController.cpp index 760b62e97386b0..78f43e19ee6e82 100644 --- a/src/controller/tests/TestCommissionableNodeController.cpp +++ b/src/controller/tests/TestCommissionableNodeController.cpp @@ -66,33 +66,37 @@ void TestGetDiscoveredCommissioner_HappyCase(nlTestSuite * inSuite, void * inCon { MockResolver resolver; CommissionableNodeController controller(&resolver); - chip::Dnssd::DiscoveredNodeData inNodeData; - Platform::CopyString(inNodeData.resolutionData.hostName, "mockHostName"); - Inet::IPAddress::FromString("192.168.1.10", inNodeData.resolutionData.ipAddress[0]); - inNodeData.resolutionData.numIPs++; - inNodeData.resolutionData.port = 5540; + chip::Dnssd::DiscoveredNodeData discNodeData; + discNodeData.Set(); + chip::Dnssd::CommissionNodeData & inNodeData = discNodeData.Get(); + Platform::CopyString(inNodeData.hostName, "mockHostName"); + Inet::IPAddress::FromString("192.168.1.10", inNodeData.ipAddress[0]); + inNodeData.numIPs++; + inNodeData.port = 5540; - controller.OnNodeDiscovered(inNodeData); + controller.OnNodeDiscovered(discNodeData); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0) != nullptr); NL_TEST_ASSERT( - inSuite, strcmp(inNodeData.resolutionData.hostName, controller.GetDiscoveredCommissioner(0)->resolutionData.hostName) == 0); + inSuite, strcmp(inNodeData.hostName, controller.GetDiscoveredCommissioner(0)->hostName) == 0); NL_TEST_ASSERT(inSuite, - inNodeData.resolutionData.ipAddress[0] == controller.GetDiscoveredCommissioner(0)->resolutionData.ipAddress[0]); - NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->resolutionData.port == 5540); - NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->resolutionData.numIPs == 1); + inNodeData.ipAddress[0] == controller.GetDiscoveredCommissioner(0)->ipAddress[0]); + NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->port == 5540); + NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->numIPs == 1); } void TestGetDiscoveredCommissioner_InvalidNodeDiscovered_ReturnsNullptr(nlTestSuite * inSuite, void * inContext) { MockResolver resolver; CommissionableNodeController controller(&resolver); - chip::Dnssd::DiscoveredNodeData inNodeData; - Inet::IPAddress::FromString("192.168.1.10", inNodeData.resolutionData.ipAddress[0]); - inNodeData.resolutionData.numIPs++; - inNodeData.resolutionData.port = 5540; + chip::Dnssd::DiscoveredNodeData discNodeData; + discNodeData.Set(); + chip::Dnssd::CommissionNodeData & inNodeData = discNodeData.Get(); + Inet::IPAddress::FromString("192.168.1.10", inNodeData.ipAddress[0]); + inNodeData.numIPs++; + inNodeData.port = 5540; - controller.OnNodeDiscovered(inNodeData); + controller.OnNodeDiscovered(discNodeData); for (int i = 0; i < CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES; i++) { @@ -104,27 +108,31 @@ void TestGetDiscoveredCommissioner_HappyCase_OneValidOneInvalidNode(nlTestSuite { MockResolver resolver; CommissionableNodeController controller(&resolver); - chip::Dnssd::DiscoveredNodeData invalidNodeData, validNodeData; - Inet::IPAddress::FromString("192.168.1.10", invalidNodeData.resolutionData.ipAddress[0]); - invalidNodeData.resolutionData.numIPs++; - invalidNodeData.resolutionData.port = 5540; - - Platform::CopyString(validNodeData.resolutionData.hostName, "mockHostName2"); - Inet::IPAddress::FromString("192.168.1.11", validNodeData.resolutionData.ipAddress[0]); - validNodeData.resolutionData.numIPs++; - validNodeData.resolutionData.port = 5540; - - controller.OnNodeDiscovered(validNodeData); - controller.OnNodeDiscovered(invalidNodeData); + chip::Dnssd::DiscoveredNodeData invalidDiscNodeData, validDiscNodeData; + invalidDiscNodeData.Set(); + validDiscNodeData.Set(); + chip::Dnssd::CommissionNodeData & invalidNodeData = invalidDiscNodeData.Get(); + chip::Dnssd::CommissionNodeData & validNodeData = validDiscNodeData.Get(); + Inet::IPAddress::FromString("192.168.1.10", invalidNodeData.ipAddress[0]); + invalidNodeData.numIPs++; + invalidNodeData.port = 5540; + + Platform::CopyString(validNodeData.hostName, "mockHostName2"); + Inet::IPAddress::FromString("192.168.1.11", validNodeData.ipAddress[0]); + validNodeData.numIPs++; + validNodeData.port = 5540; + + controller.OnNodeDiscovered(validDiscNodeData); + controller.OnNodeDiscovered(invalidDiscNodeData); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0) != nullptr); NL_TEST_ASSERT( inSuite, - strcmp(validNodeData.resolutionData.hostName, controller.GetDiscoveredCommissioner(0)->resolutionData.hostName) == 0); + strcmp(validNodeData.hostName, controller.GetDiscoveredCommissioner(0)->hostName) == 0); NL_TEST_ASSERT( - inSuite, validNodeData.resolutionData.ipAddress[0] == controller.GetDiscoveredCommissioner(0)->resolutionData.ipAddress[0]); - NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->resolutionData.port == 5540); - NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->resolutionData.numIPs == 1); + inSuite, validNodeData.ipAddress[0] == controller.GetDiscoveredCommissioner(0)->ipAddress[0]); + NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->port == 5540); + NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->numIPs == 1); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(1) == nullptr); } diff --git a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm index bf975b672decd5..760c6f39b65c29 100644 --- a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm +++ b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm @@ -161,7 +161,7 @@ void OnNodeDiscovered(const DiscoveredNodeData & nodeData) override { assertChipStackLockedByCurrentThread(); - auto & commissionData = nodeData.nodeData; + auto & commissionData = nodeData.Get(); auto key = [NSString stringWithUTF8String:commissionData.instanceName]; if ([mDiscoveredResults objectForKey:key] == nil) { // It should not happens. @@ -175,7 +175,7 @@ void OnNodeDiscovered(const DiscoveredNodeData & nodeData) override result.discriminator = @(commissionData.longDiscriminator); result.commissioningMode = commissionData.commissioningMode != 0; - auto & resolutionData = nodeData.resolutionData; + auto & resolutionData = commissionData; auto * interfaces = result.interfaces; interfaces[@(resolutionData.interfaceId.GetPlatformInterface())].resolutionData = chip::MakeOptional(resolutionData); diff --git a/src/lib/dnssd/ActiveResolveAttempts.h b/src/lib/dnssd/ActiveResolveAttempts.h index 1d87bbbba49cbc..39728552433c4f 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.h +++ b/src/lib/dnssd/ActiveResolveAttempts.h @@ -159,17 +159,17 @@ class ActiveResolveAttempts case chip::Dnssd::DiscoveryFilterType::kNone: return true; case chip::Dnssd::DiscoveryFilterType::kShortDiscriminator: - return browse.filter.code == static_cast((data.nodeData.longDiscriminator >> 8) & 0x0F); + return browse.filter.code == static_cast((data.Get().longDiscriminator >> 8) & 0x0F); case chip::Dnssd::DiscoveryFilterType::kLongDiscriminator: - return browse.filter.code == data.nodeData.longDiscriminator; + return browse.filter.code == data.Get().longDiscriminator; case chip::Dnssd::DiscoveryFilterType::kVendorId: - return browse.filter.code == data.nodeData.vendorId; + return browse.filter.code == data.Get().vendorId; case chip::Dnssd::DiscoveryFilterType::kDeviceType: - return browse.filter.code == data.nodeData.deviceType; + return browse.filter.code == data.Get().deviceType; case chip::Dnssd::DiscoveryFilterType::kCommissioningMode: - return browse.filter.code == data.nodeData.commissioningMode; + return browse.filter.code == data.Get().commissioningMode; case chip::Dnssd::DiscoveryFilterType::kInstanceName: - return strncmp(browse.filter.instanceName, data.nodeData.instanceName, + return strncmp(browse.filter.instanceName, data.Get().instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1) == 0; case chip::Dnssd::DiscoveryFilterType::kCommissioner: case chip::Dnssd::DiscoveryFilterType::kCompressedFabricId: diff --git a/src/lib/dnssd/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index c12019ca60b5fd..2b6b6cd470c618 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -51,7 +51,7 @@ static void HandleNodeResolve(void * context, DnssdService * result, const Span< DiscoveredNodeData nodeData; result->ToDiscoveredNodeData(addresses, nodeData); - nodeData.LogDetail(); + nodeData.Get().LogDetail(); discoveryContext->OnNodeDiscovered(nodeData); discoveryContext->Release(); } @@ -339,37 +339,37 @@ void DiscoveryImplPlatform::HandleNodeIdResolve(void * context, DnssdService * r void DnssdService::ToDiscoveredNodeData(const Span & addresses, DiscoveredNodeData & nodeData) { - auto & resolutionData = nodeData.resolutionData; - auto & commissionData = nodeData.nodeData; + nodeData.Set(); + auto & discoveredData = nodeData.Get(); - Platform::CopyString(resolutionData.hostName, mHostName); - Platform::CopyString(commissionData.instanceName, mName); + Platform::CopyString(discoveredData.hostName, mHostName); + Platform::CopyString(discoveredData.instanceName, mName); IPAddressSorter::Sort(addresses, mInterface); size_t addressesFound = 0; for (auto & ip : addresses) { - if (addressesFound == ArraySize(resolutionData.ipAddress)) + if (addressesFound == ArraySize(discoveredData.ipAddress)) { // Out of space. ChipLogProgress(Discovery, "Can't add more IPs to DiscoveredNodeData"); break; } - resolutionData.ipAddress[addressesFound] = ip; + discoveredData.ipAddress[addressesFound] = ip; ++addressesFound; } - resolutionData.interfaceId = mInterface; - resolutionData.numIPs = addressesFound; - resolutionData.port = mPort; + discoveredData.interfaceId = mInterface; + discoveredData.numIPs = addressesFound; + discoveredData.port = mPort; for (size_t i = 0; i < mTextEntrySize; ++i) { ByteSpan key(reinterpret_cast(mTextEntries[i].mKey), strlen(mTextEntries[i].mKey)); ByteSpan val(mTextEntries[i].mData, mTextEntries[i].mDataSize); - FillNodeDataFromTxt(key, val, resolutionData); - FillNodeDataFromTxt(key, val, commissionData); + FillNodeDataFromTxt(key, val, discoveredData); + FillNodeDataFromTxt(key, val, discoveredData); } } diff --git a/src/lib/dnssd/IncrementalResolve.cpp b/src/lib/dnssd/IncrementalResolve.cpp index 766d979e33a4ba..5f9a951b5dc569 100644 --- a/src/lib/dnssd/IncrementalResolve.cpp +++ b/src/lib/dnssd/IncrementalResolve.cpp @@ -189,7 +189,7 @@ CHIP_ERROR IncrementalResolver::InitializeParsing(mdns::Minimal::SerializedQName break; case ServiceNameType::kCommissioner: case ServiceNameType::kCommissionable: - mSpecificResolutionData.Set(); + mSpecificResolutionData.Set(); { // Commission addresses start with instance name @@ -199,10 +199,10 @@ CHIP_ERROR IncrementalResolver::InitializeParsing(mdns::Minimal::SerializedQName return CHIP_ERROR_INVALID_ARGUMENT; } - Platform::CopyString(mSpecificResolutionData.Get().instanceName, nameCopy.Value()); + Platform::CopyString(mSpecificResolutionData.Get().instanceName, nameCopy.Value()); } - LogFoundCommissionSrvRecord(mSpecificResolutionData.Get().instanceName, mTargetHostName.Get()); + LogFoundCommissionSrvRecord(mSpecificResolutionData.Get().instanceName, mTargetHostName.Get()); break; default: return CHIP_ERROR_INVALID_ARGUMENT; @@ -306,7 +306,7 @@ CHIP_ERROR IncrementalResolver::OnTxtRecord(const ResourceData & data, BytesRang if (IsActiveBrowseParse()) { - TxtParser delegate(mSpecificResolutionData.Get()); + TxtParser delegate(mSpecificResolutionData.Get()); if (!ParseTxtRecord(data.GetData(), &delegate)) { return CHIP_ERROR_INVALID_ARGUMENT; @@ -347,8 +347,10 @@ CHIP_ERROR IncrementalResolver::Take(DiscoveredNodeData & outputData) IPAddressSorter::Sort(mCommonResolutionData.ipAddress, mCommonResolutionData.numIPs, mCommonResolutionData.interfaceId); - outputData.resolutionData = mCommonResolutionData; - outputData.nodeData = mSpecificResolutionData.Get(); + outputData.Set(); + CommissionNodeData & nodeData = outputData.Get(); + nodeData = mSpecificResolutionData.Get(); + (CommonResolutionData &)nodeData = mCommonResolutionData; ResetToInactive(); diff --git a/src/lib/dnssd/IncrementalResolve.h b/src/lib/dnssd/IncrementalResolve.h index 17790b6f9f5fe0..4a8bc0c5792ee3 100644 --- a/src/lib/dnssd/IncrementalResolve.h +++ b/src/lib/dnssd/IncrementalResolve.h @@ -100,7 +100,7 @@ class IncrementalResolver /// method. bool IsActive() const { return mSpecificResolutionData.Valid(); } - bool IsActiveBrowseParse() const { return mSpecificResolutionData.Is(); } + bool IsActiveBrowseParse() const { return mSpecificResolutionData.Is(); } bool IsActiveOperationalParse() const { return mSpecificResolutionData.Is(); } ServiceNameType GetCurrentType() const { return mServiceNameType; } @@ -185,7 +185,7 @@ class IncrementalResolver /// Prerequisite: IP address belongs to the right nost name CHIP_ERROR OnIpAddress(Inet::InterfaceId interface, const Inet::IPAddress & addr); - using ParsedRecordSpecificData = Variant; + using ParsedRecordSpecificData = Variant; StoredServerName mRecordName; // Record name for what is parsed (SRV/PTR/TXT) StoredServerName mTargetHostName; // `Target` for the SRV record diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index 3abc11ac659cf8..403da6effcd36c 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -425,12 +425,10 @@ void MinMdnsResolver::AdvancePendingResolverStates() case IncrementalResolver::ServiceNameType::kCommissioner: discoveredNodeIsRelevant = mActiveResolves.HasBrowseFor(chip::Dnssd::DiscoveryType::kCommissionerNode); mActiveResolves.CompleteCommissioner(nodeData); - nodeData.nodeType = DiscoveryType::kCommissionerNode; break; case IncrementalResolver::ServiceNameType::kCommissionable: discoveredNodeIsRelevant = mActiveResolves.HasBrowseFor(chip::Dnssd::DiscoveryType::kCommissionableNode); mActiveResolves.CompleteCommissionable(nodeData); - nodeData.nodeType = DiscoveryType::kCommissionableNode; break; default: ChipLogError(Discovery, "Unexpected type for browse data parsing"); diff --git a/src/lib/dnssd/TxtFields.cpp b/src/lib/dnssd/TxtFields.cpp index c4ec70e342d41a..88a116871ca017 100644 --- a/src/lib/dnssd/TxtFields.cpp +++ b/src/lib/dnssd/TxtFields.cpp @@ -225,7 +225,7 @@ TxtFieldKey GetTxtFieldKey(const ByteSpan & key) } // namespace Internal -void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & val, DnssdNodeData & nodeData) +void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & val, CommissionNodeData & nodeData) { TxtFieldKey keyType = Internal::GetTxtFieldKey(key); switch (keyType) diff --git a/src/lib/dnssd/TxtFields.h b/src/lib/dnssd/TxtFields.h index 194750451289a4..5546493624119d 100644 --- a/src/lib/dnssd/TxtFields.h +++ b/src/lib/dnssd/TxtFields.h @@ -192,7 +192,7 @@ constexpr size_t ValSize(TxtFieldKey key) } void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & value, CommonResolutionData & nodeData); -void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & value, DnssdNodeData & nodeData); +void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & value, CommissionNodeData & nodeData); } // namespace Dnssd } // namespace chip diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h index 43e55bfbc65e0e..4ad3eb608a78d4 100644 --- a/src/lib/dnssd/Types.h +++ b/src/lib/dnssd/Types.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -205,7 +206,7 @@ inline constexpr size_t kMaxRotatingIdLen = 50; inline constexpr size_t kMaxPairingInstructionLen = 128; /// Data that is specific to commisionable/commissioning node discovery -struct DnssdNodeData +struct CommissionNodeData : public CommonResolutionData { size_t rotatingIdLen = 0; uint32_t deviceType = 0; @@ -220,19 +221,22 @@ struct DnssdNodeData char deviceName[kMaxDeviceNameLen + 1] = {}; char pairingInstruction[kMaxPairingInstructionLen + 1] = {}; - DnssdNodeData() {} + CommissionNodeData() {} void Reset() { + CommonResolutionData::Reset(); // Let constructor clear things as default - this->~DnssdNodeData(); - new (this) DnssdNodeData(); + this->~CommissionNodeData(); + new (this) CommissionNodeData(); } bool IsInstanceName(const char * instance) const { return strcmp(instance, instanceName) == 0; } void LogDetail() const { + CommonResolutionData::LogDetail(); + if (rotatingIdLen > 0) { char rotatingIdString[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; @@ -293,10 +297,13 @@ struct ResolvedNodeData } }; +using DiscoveredNodeData = Variant; + +#if 0 struct DiscoveredNodeData { CommonResolutionData resolutionData; - DnssdNodeData nodeData; + CommissionNodeData nodeData; DiscoveryType nodeType; void Reset() @@ -314,6 +321,7 @@ struct DiscoveredNodeData nodeData.LogDetail(); } }; +#endif /// Callbacks for discovering nodes advertising non-operational status: /// - Commissioners diff --git a/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp b/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp index 58c1cf86dab511..4c2665658f3493 100644 --- a/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp +++ b/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp @@ -124,7 +124,8 @@ TEST(TestActiveResolveAttempts, TestSingleBrowseAddRemove) // once complete, nothing to schedule Dnssd::DiscoveredNodeData data; - data.nodeData.longDiscriminator = 1234; + data.Set(); + data.Get().longDiscriminator = 1234; attempts.CompleteCommissionable(data); EXPECT_FALSE(attempts.GetTimeUntilNextExpectedResponse().HasValue()); EXPECT_FALSE(attempts.NextScheduled().HasValue()); @@ -372,7 +373,8 @@ TEST(TestActiveResolveAttempts, TestCombination) attempts.Complete(MakePeerId(2)); attempts.Complete(MakePeerId(1)); Dnssd::DiscoveredNodeData data; - data.nodeData.longDiscriminator = 1234; + data.Set(); + data.Get().longDiscriminator = 1234; attempts.CompleteCommissionable(data); EXPECT_FALSE(attempts.GetTimeUntilNextExpectedResponse().HasValue()); diff --git a/src/lib/dnssd/tests/TestIncrementalResolve.cpp b/src/lib/dnssd/tests/TestIncrementalResolve.cpp index 646e4abfe38303..5ed4191319e824 100644 --- a/src/lib/dnssd/tests/TestIncrementalResolve.cpp +++ b/src/lib/dnssd/tests/TestIncrementalResolve.cpp @@ -385,28 +385,31 @@ TEST(TestIncrementalResolve, TestParseCommissionable) EXPECT_FALSE(resolver.GetMissingRequiredInformation().HasAny()); // At this point taking value should work. Once taken, the resolver is reset. - DiscoveredNodeData nodeData; - EXPECT_EQ(resolver.Take(nodeData), CHIP_NO_ERROR); + DiscoveredNodeData discoveredNodeData; + EXPECT_TRUE(resolver.Take(discoveredNodeData) == CHIP_NO_ERROR); EXPECT_FALSE(resolver.IsActive()); + EXPECT_TRUE(discoveredNodeData.Is()); + CommissionNodeData nodeData = discoveredNodeData.Get(); + // validate data as it was passed in - EXPECT_EQ(nodeData.resolutionData.numIPs, 2u); - EXPECT_EQ(nodeData.resolutionData.port, 0x1234); - EXPECT_FALSE(nodeData.resolutionData.supportsTcp); - EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); - EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalActive().Value(), chip::System::Clock::Milliseconds32(321)); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); + EXPECT_EQ(nodeData.numIPs, 2u); + EXPECT_EQ(nodeData.port, 0x1234); + EXPECT_FALSE(nodeData.supportsTcp); + EXPECT_TRUE(nodeData.GetMrpRetryIntervalActive().HasValue()); + EXPECT_EQ(nodeData.GetMrpRetryIntervalActive().Value(), chip::System::Clock::Milliseconds32(321)); + EXPECT_FALSE(nodeData.GetMrpRetryIntervalIdle().HasValue()); Inet::IPAddress addr; EXPECT_TRUE(Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr)); - EXPECT_EQ(nodeData.resolutionData.ipAddress[0], addr); + EXPECT_EQ(nodeData.ipAddress[0], addr); EXPECT_TRUE(Inet::IPAddress::FromString("fe80::f0f1:f2f3:f4f5:1234", addr)); - EXPECT_EQ(nodeData.resolutionData.ipAddress[1], addr); + EXPECT_EQ(nodeData.ipAddress[1], addr); // parsed txt data for discovered nodes - EXPECT_EQ(nodeData.nodeData.longDiscriminator, 22345); - EXPECT_EQ(nodeData.nodeData.vendorId, 321); - EXPECT_EQ(nodeData.nodeData.productId, 654); - EXPECT_STREQ(nodeData.nodeData.deviceName, "mytest"); + EXPECT_EQ(nodeData.longDiscriminator, 22345); + EXPECT_EQ(nodeData.vendorId, 321); + EXPECT_EQ(nodeData.productId, 654); + EXPECT_STREQ(nodeData.deviceName, "mytest"); } } // namespace diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index d487c261346c05..336171b6759658 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -300,23 +300,23 @@ TEST(TestTxtFields, TestGetCommissionerPasscode) EXPECT_EQ(GetCommissionerPasscode(GetSpan(cm)), 0); } -bool NodeDataIsEmpty(const DiscoveredNodeData & node) +bool NodeDataIsEmpty(const CommissionNodeData & node) { - if (node.nodeData.longDiscriminator != 0 || node.nodeData.vendorId != 0 || node.nodeData.productId != 0 || - node.nodeData.commissioningMode != 0 || node.nodeData.deviceType != 0 || node.nodeData.rotatingIdLen != 0 || - node.nodeData.pairingHint != 0 || node.resolutionData.mrpRetryIntervalIdle.HasValue() || - node.resolutionData.mrpRetryIntervalActive.HasValue() || node.resolutionData.mrpRetryActiveThreshold.HasValue() || - node.resolutionData.isICDOperatingAsLIT.HasValue() || node.resolutionData.supportsTcp || - node.nodeData.supportsCommissionerGeneratedPasscode != 0) + if (node.longDiscriminator != 0 || node.vendorId != 0 || node.productId != 0 || + node.commissioningMode != 0 || node.deviceType != 0 || node.rotatingIdLen != 0 || + node.pairingHint != 0 || node.mrpRetryIntervalIdle.HasValue() || + node.mrpRetryIntervalActive.HasValue() || node.mrpRetryActiveThreshold.HasValue() || + node.isICDOperatingAsLIT.HasValue() || node.supportsTcp || + node.supportsCommissionerGeneratedPasscode != 0) { return false; } - if (strcmp(node.nodeData.deviceName, "") != 0 || strcmp(node.nodeData.pairingInstruction, "") != 0) + if (strcmp(node.deviceName, "") != 0 || strcmp(node.pairingInstruction, "") != 0) { return false; } - for (uint8_t id : node.nodeData.rotatingId) + for (uint8_t id : node.rotatingId) { if (id != 0) { @@ -331,83 +331,82 @@ TEST(TestTxtFields, TestFillDiscoveredNodeDataFromTxt) { char key[3]; char val[16]; - DiscoveredNodeData filled; + CommissionNodeData filled; // Long discriminator strcpy(key, "D"); strcpy(val, "840"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_EQ(filled.nodeData.longDiscriminator, 840); - filled.nodeData.longDiscriminator = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_EQ(filled.longDiscriminator, 840); + filled.longDiscriminator = 0; EXPECT_TRUE(NodeDataIsEmpty(filled)); // vendor and product strcpy(key, "VP"); strcpy(val, "123+456"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_EQ(filled.nodeData.vendorId, 123); - EXPECT_EQ(filled.nodeData.productId, 456); - filled.nodeData.vendorId = 0; - filled.nodeData.productId = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_EQ(filled.vendorId, 123); + EXPECT_EQ(filled.productId, 456); + filled.vendorId = 0; + filled.productId = 0; EXPECT_TRUE(NodeDataIsEmpty(filled)); // Commissioning mode strcpy(key, "CM"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_EQ(filled.nodeData.commissioningMode, 1); - filled.nodeData.commissioningMode = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_EQ(filled.commissioningMode, 1); + filled.commissioningMode = 0; EXPECT_TRUE(NodeDataIsEmpty(filled)); - // Supports Commissioner Generated Passcode strcpy(key, "CP"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_TRUE(filled.nodeData.supportsCommissionerGeneratedPasscode); - filled.nodeData.supportsCommissionerGeneratedPasscode = false; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_TRUE(filled.supportsCommissionerGeneratedPasscode); + filled.supportsCommissionerGeneratedPasscode = false; EXPECT_TRUE(NodeDataIsEmpty(filled)); // Device type strcpy(key, "DT"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_EQ(filled.nodeData.deviceType, 1u); - filled.nodeData.deviceType = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_EQ(filled.deviceType, 1u); + filled.deviceType = 0; EXPECT_TRUE(NodeDataIsEmpty(filled)); // Device name strcpy(key, "DN"); strcpy(val, "abc"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_STREQ(filled.nodeData.deviceName, "abc"); - memset(filled.nodeData.deviceName, 0, sizeof(filled.nodeData.deviceName)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_STREQ(filled.deviceName, "abc"); + memset(filled.deviceName, 0, sizeof(filled.deviceName)); EXPECT_TRUE(NodeDataIsEmpty(filled)); // Rotating device id strcpy(key, "RI"); strcpy(val, "1A2B"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_EQ(filled.nodeData.rotatingId[0], 0x1A); - EXPECT_EQ(filled.nodeData.rotatingId[1], 0x2B); - EXPECT_EQ(filled.nodeData.rotatingIdLen, 2u); - filled.nodeData.rotatingIdLen = 0; - memset(filled.nodeData.rotatingId, 0, sizeof(filled.nodeData.rotatingId)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_EQ(filled.rotatingId[0], 0x1A); + EXPECT_EQ(filled.rotatingId[1], 0x2B); + EXPECT_EQ(filled.rotatingIdLen, 2u); + filled.rotatingIdLen = 0; + memset(filled.rotatingId, 0, sizeof(filled.rotatingId)); EXPECT_TRUE(NodeDataIsEmpty(filled)); // Pairing instruction strcpy(key, "PI"); strcpy(val, "hint"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_STREQ(filled.nodeData.pairingInstruction, "hint"); - memset(filled.nodeData.pairingInstruction, 0, sizeof(filled.nodeData.pairingInstruction)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_STREQ(filled.pairingInstruction, "hint"); + memset(filled.pairingInstruction, 0, sizeof(filled.pairingInstruction)); EXPECT_TRUE(NodeDataIsEmpty(filled)); // Pairing hint strcpy(key, "PH"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - EXPECT_EQ(filled.nodeData.pairingHint, 1); - filled.nodeData.pairingHint = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + EXPECT_EQ(filled.pairingHint, 1); + filled.pairingHint = 0; EXPECT_TRUE(NodeDataIsEmpty(filled)); } @@ -421,7 +420,7 @@ bool NodeDataIsEmpty(const ResolvedNodeData & nodeData) void ResetRetryIntervalIdle(DiscoveredNodeData & nodeData) { - nodeData.resolutionData.mrpRetryIntervalIdle.ClearValue(); + nodeData.Get().mrpRetryIntervalIdle.ClearValue(); } void ResetRetryIntervalIdle(ResolvedNodeData & nodeData) @@ -431,7 +430,7 @@ void ResetRetryIntervalIdle(ResolvedNodeData & nodeData) void ResetRetryIntervalActive(DiscoveredNodeData & nodeData) { - nodeData.resolutionData.mrpRetryIntervalActive.ClearValue(); + nodeData.Get().mrpRetryIntervalActive.ClearValue(); } void ResetRetryIntervalActive(ResolvedNodeData & nodeData) @@ -441,7 +440,7 @@ void ResetRetryIntervalActive(ResolvedNodeData & nodeData) void ResetRetryActiveThreshold(DiscoveredNodeData & nodeData) { - nodeData.resolutionData.mrpRetryActiveThreshold.ClearValue(); + nodeData.Get().mrpRetryActiveThreshold.ClearValue(); } void ResetRetryActiveThreshold(ResolvedNodeData & nodeData) @@ -449,6 +448,319 @@ void ResetRetryActiveThreshold(ResolvedNodeData & nodeData) nodeData.resolutionData.mrpRetryActiveThreshold.ClearValue(); } +template +void DiscoveredTxtFieldSessionIdleInterval() +{ + char key[4]; + char val[16]; + DiscoveredNodeData nodeData; + nodeData.Set(); + + // Minimum + strcpy(key, "SII"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().Value() == 1_ms32); + + // Maximum + strcpy(key, "SII"); + strcpy(val, "3600000"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().Value() == 3600000_ms32); + + // Test no other fields were populated + ResetRetryIntervalIdle(nodeData); + EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + + // Invalid SII - negative value + strcpy(key, "SII"); + strcpy(val, "-1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - greater than maximum + strcpy(key, "SII"); + strcpy(val, "3600001"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - much greater than maximum + strcpy(key, "SII"); + strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - hexadecimal value + strcpy(key, "SII"); + strcpy(val, "0x20"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - leading zeros + strcpy(key, "SII"); + strcpy(val, "0700"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - text at the end + strcpy(key, "SII"); + strcpy(val, "123abc"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); +} + +// Test SAI (formerly CRA) +template +void DiscoveredTxtFieldSessionActiveInterval() +{ + char key[4]; + char val[16]; + DiscoveredNodeData nodeData; + nodeData.Set(); + + // Minimum + strcpy(key, "SAI"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().Value() == 1_ms32); + + // Maximum + strcpy(key, "SAI"); + strcpy(val, "3600000"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().Value() == 3600000_ms32); + + // Test no other fields were populated + ResetRetryIntervalActive(nodeData); + EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + + // Invalid SAI - negative value + strcpy(key, "SAI"); + strcpy(val, "-1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - greater than maximum + strcpy(key, "SAI"); + strcpy(val, "3600001"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - much greater than maximum + strcpy(key, "SAI"); + strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - hexadecimal value + strcpy(key, "SAI"); + strcpy(val, "0x20"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - leading zeros + strcpy(key, "SAI"); + strcpy(val, "0700"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - text at the end + strcpy(key, "SAI"); + strcpy(val, "123abc"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); +} + +// Test SAT (Session Active Threshold) +template +void DiscoveredTxtFieldSessionActiveThreshold() +{ + char key[4]; + char val[16]; + DiscoveredNodeData nodeData; + nodeData.Set(); + + // Minimum + strcpy(key, "SAT"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().Value() == 1_ms16); + + // Maximum + strcpy(key, "SAT"); + strcpy(val, "65535"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().Value() == 65535_ms16); + + // Test no other fields were populated + ResetRetryActiveThreshold(nodeData); + EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + + // Invalid SAI - negative value + strcpy(key, "SAT"); + strcpy(val, "-1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAI - greater than maximum + strcpy(key, "SAT"); + strcpy(val, "65536"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAT - much greater than maximum + strcpy(key, "SAT"); + strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAT - hexadecimal value + strcpy(key, "SAT"); + strcpy(val, "0x20"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAT - leading zeros + strcpy(key, "SAT"); + strcpy(val, "0700"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAT - text at the end + strcpy(key, "SAT"); + strcpy(val, "123abc"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); +} + +// Test T (TCP support) +template +void DiscoveredTxtFieldTcpSupport() +{ + char key[4]; + char val[8]; + DiscoveredNodeData nodeData; + nodeData.Set(); + + // True + strcpy(key, "T"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().supportsTcp); + + // Test no other fields were populated + nodeData.Get().supportsTcp = false; + EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + + // False + strcpy(key, "T"); + strcpy(val, "0"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().supportsTcp == false); + + // Invalid value, stil false + strcpy(key, "T"); + strcpy(val, "asdf"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().supportsTcp == false); +} + +// Test ICD (ICD operation Mode) +template +void DiscoveredTxtFieldICDoperatesAsLIT() +{ + char key[4]; + char val[16]; + DiscoveredNodeData nodeData; + nodeData.Set(); + + // ICD is operating as a LIT device + strcpy(key, "ICD"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue()); + EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.Value()); + + // Test no other fields were populated + nodeData.Get().isICDOperatingAsLIT.ClearValue(); + EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + + // ICD is operating as a SIT device + strcpy(key, "ICD"); + strcpy(val, "0"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue()); + EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.Value() == false); + + nodeData.Get().isICDOperatingAsLIT.ClearValue(); + EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + // Invalid value, No key set + strcpy(key, "ICD"); + strcpy(val, "asdf"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue() == false); +} + +// Test IsDeviceTreatedAsSleepy() with CRI +template +void DiscoveredTestIsDeviceSessionIdle() +{ + char key[4]; + char val[32]; + DiscoveredNodeData nodeData; + nodeData.Set(); + 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 + EXPECT_TRUE( !nodeData.Get().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_LOCAL_IDLE_RETRY_INTERVAL.count())); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().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_LOCAL_IDLE_RETRY_INTERVAL.count() + 1)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); +} + +// Test IsDeviceTreatedAsSleepy() with CRA +template +void DiscoveredTestIsDeviceSessionActive() +{ + char key[4]; + char val[32]; + DiscoveredNodeData nodeData; + nodeData.Set(); + 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 + EXPECT_TRUE( !nodeData.Get().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_LOCAL_ACTIVE_RETRY_INTERVAL.count())); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( !nodeData.Get().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_LOCAL_ACTIVE_RETRY_INTERVAL.count() + 1)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + EXPECT_TRUE( nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); +} + // Test SAI (formally CRI) template void TxtFieldSessionIdleInterval() @@ -514,7 +826,7 @@ void TxtFieldSessionIdleInterval() TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryIntervalIdle) { - TxtFieldSessionIdleInterval(); + DiscoveredTxtFieldSessionIdleInterval(); } TEST(TestTxtFields, TxtResolvedFieldMrpRetryIntervalIdle) @@ -587,7 +899,7 @@ void TxtFieldSessionActiveInterval() TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryIntervalActive) { - TxtFieldSessionActiveInterval(); + DiscoveredTxtFieldSessionActiveInterval(); } TEST(TestTxtFields, TxtResolvedFieldMrpRetryIntervalActive) @@ -660,7 +972,7 @@ void TxtFieldSessionActiveThreshold() TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryActiveThreshold) { - TxtFieldSessionActiveThreshold(); + DiscoveredTxtFieldSessionActiveThreshold(); } TEST(TestTxtFields, TxtResolvedFieldMrpRetryActiveThreshold) @@ -701,7 +1013,7 @@ void TxtFieldTcpSupport() TEST(TestTxtFields, TxtDiscoveredFieldTcpSupport) { - TxtFieldTcpSupport(); + DiscoveredTxtFieldTcpSupport(); } TEST(TestTxtFields, TxtResolvedFieldTcpSupport) @@ -746,7 +1058,7 @@ void TxtFieldICDoperatesAsLIT() TEST(TestTxtFields, TxtDiscoveredIsICDoperatingAsLIT) { - TxtFieldICDoperatesAsLIT(); + DiscoveredTxtFieldICDoperatesAsLIT(); } TEST(TestTxtFields, TxtResolvedFieldICDoperatingAsLIT) @@ -782,7 +1094,7 @@ void TestIsDeviceSessionIdle() TEST(TestTxtFields, TxtDiscoveredIsDeviceSessionIdle) { - TestIsDeviceSessionIdle(); + DiscoveredTestIsDeviceSessionIdle(); } TEST(TestTxtFields, TxtResolvedIsDeviceSessionIdle) @@ -818,7 +1130,7 @@ void TestIsDeviceSessionActive() TEST(TestTxtFields, TxtDiscoveredIsDeviceSessionActive) { - TestIsDeviceSessionActive(); + DiscoveredTestIsDeviceSessionActive(); } TEST(TestTxtFields, TxtResolvedIsDeviceSessionActive) diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index ff9edad52445a5..9fff1d7999f74e 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -83,61 +83,67 @@ class DnsShellResolverDelegate : public Dnssd::DiscoverNodeDelegate, public Addr AddressResolve::NodeLookupHandle & Handle() { return mSelfHandle; } - void OnNodeDiscovered(const Dnssd::DiscoveredNodeData & nodeData) override + void OnNodeDiscovered(const Dnssd::DiscoveredNodeData & discNodeData) override { - if (!nodeData.resolutionData.IsValid()) + if (!discNodeData.Is()) + { + streamer_printf(streamer_get(), "DNS browse failed - not commission type node \r\n"); + return; + } + + Dnssd::CommissionNodeData nodeData = discNodeData.Get(); + if (!nodeData.IsValid()) { streamer_printf(streamer_get(), "DNS browse failed - not found valid services \r\n"); return; } char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1]; - Encoding::BytesToUppercaseHexString(nodeData.nodeData.rotatingId, nodeData.nodeData.rotatingIdLen, rotatingId, + Encoding::BytesToUppercaseHexString(nodeData.rotatingId, nodeData.rotatingIdLen, rotatingId, sizeof(rotatingId)); streamer_printf(streamer_get(), "DNS browse succeeded: \r\n"); - streamer_printf(streamer_get(), " Node Type: %u\r\n", nodeData.nodeType); - streamer_printf(streamer_get(), " Hostname: %s\r\n", nodeData.resolutionData.hostName); - streamer_printf(streamer_get(), " Vendor ID: %u\r\n", nodeData.nodeData.vendorId); - streamer_printf(streamer_get(), " Product ID: %u\r\n", nodeData.nodeData.productId); - streamer_printf(streamer_get(), " Long discriminator: %u\r\n", nodeData.nodeData.longDiscriminator); - streamer_printf(streamer_get(), " Device type: %u\r\n", nodeData.nodeData.deviceType); - streamer_printf(streamer_get(), " Device name: %s\n", nodeData.nodeData.deviceName); - streamer_printf(streamer_get(), " Commissioning mode: %d\r\n", static_cast(nodeData.nodeData.commissioningMode)); - streamer_printf(streamer_get(), " Pairing hint: %u\r\n", nodeData.nodeData.pairingHint); - streamer_printf(streamer_get(), " Pairing instruction: %s\r\n", nodeData.nodeData.pairingInstruction); + streamer_printf(streamer_get(), " Hostname: %s\r\n", nodeData.hostName); + streamer_printf(streamer_get(), " Vendor ID: %u\r\n", nodeData.vendorId); + streamer_printf(streamer_get(), " Product ID: %u\r\n", nodeData.productId); + streamer_printf(streamer_get(), " Long discriminator: %u\r\n", nodeData.longDiscriminator); + streamer_printf(streamer_get(), " Device type: %u\r\n", nodeData.deviceType); + streamer_printf(streamer_get(), " Device name: %s\n", nodeData.deviceName); + streamer_printf(streamer_get(), " Commissioning mode: %d\r\n", static_cast(nodeData.commissioningMode)); + streamer_printf(streamer_get(), " Pairing hint: %u\r\n", nodeData.pairingHint); + streamer_printf(streamer_get(), " Pairing instruction: %s\r\n", nodeData.pairingInstruction); streamer_printf(streamer_get(), " Rotating ID %s\r\n", rotatingId); - auto retryInterval = nodeData.resolutionData.GetMrpRetryIntervalIdle(); + auto retryInterval = nodeData.GetMrpRetryIntervalIdle(); if (retryInterval.HasValue()) streamer_printf(streamer_get(), " MRP retry interval (idle): %" PRIu32 "ms\r\n", retryInterval.Value()); - retryInterval = nodeData.resolutionData.GetMrpRetryIntervalActive(); + retryInterval = nodeData.GetMrpRetryIntervalActive(); if (retryInterval.HasValue()) streamer_printf(streamer_get(), " MRP retry interval (active): %" PRIu32 "ms\r\n", retryInterval.Value()); - if (nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()) + if (nodeData.GetMrpRetryActiveThreshold().HasValue()) { streamer_printf(streamer_get(), " MRP retry active threshold time: %" PRIu32 "ms\r\n", - nodeData.resolutionData.GetMrpRetryActiveThreshold().Value()); + nodeData.GetMrpRetryActiveThreshold().Value()); } - streamer_printf(streamer_get(), " Supports TCP: %s\r\n", nodeData.resolutionData.supportsTcp ? "yes" : "no"); + streamer_printf(streamer_get(), " Supports TCP: %s\r\n", nodeData.supportsTcp ? "yes" : "no"); - if (nodeData.resolutionData.isICDOperatingAsLIT.HasValue()) + if (nodeData.isICDOperatingAsLIT.HasValue()) { streamer_printf(streamer_get(), " ICD is operating as a: %s\r\n", - nodeData.resolutionData.isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + nodeData.isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); } streamer_printf(streamer_get(), " IP addresses:\r\n"); - for (size_t i = 0; i < nodeData.resolutionData.numIPs; i++) + for (size_t i = 0; i < nodeData.numIPs; i++) { - streamer_printf(streamer_get(), " %s\r\n", nodeData.resolutionData.ipAddress[i].ToString(ipAddressBuf)); + streamer_printf(streamer_get(), " %s\r\n", nodeData.ipAddress[i].ToString(ipAddressBuf)); } - if (nodeData.resolutionData.port > 0) + if (nodeData.port > 0) { - streamer_printf(streamer_get(), " Port: %u\r\n", nodeData.resolutionData.port); + streamer_printf(streamer_get(), " Port: %u\r\n", nodeData.port); } } diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp index b96c45630166fa..24e7ff6f15821f 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp @@ -466,21 +466,27 @@ void UserDirectedCommissioningServer::SetUDCClientProcessingState(char * instanc mUdcClients.MarkUDCClientActive(client); } -void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::DiscoveredNodeData & nodeData) +void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::DiscoveredNodeData & discNodeData) { - if (nodeData.resolutionData.numIPs == 0) + if (!discNodeData.Is()) + { + return; + } + + Dnssd::CommissionNodeData nodeData = discNodeData.Get(); + if (nodeData.numIPs == 0) { ChipLogError(AppServer, "OnCommissionableNodeFound no IP addresses returned for instance name=%s", - nodeData.nodeData.instanceName); + nodeData.instanceName); return; } - if (nodeData.resolutionData.port == 0) + if (nodeData.port == 0) { - ChipLogError(AppServer, "OnCommissionableNodeFound no port returned for instance name=%s", nodeData.nodeData.instanceName); + ChipLogError(AppServer, "OnCommissionableNodeFound no port returned for instance name=%s", nodeData.instanceName); return; } - UDCClientState * client = mUdcClients.FindUDCClientState(nodeData.nodeData.instanceName); + UDCClientState * client = mUdcClients.FindUDCClientState(nodeData.instanceName); if (client != nullptr && client->GetUDCClientProcessingState() == UDCClientProcessingState::kDiscoveringNode) { ChipLogDetail(AppServer, "OnCommissionableNodeFound instance: name=%s old_state=%d new_state=%d", client->GetInstanceName(), @@ -490,13 +496,13 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis #if INET_CONFIG_ENABLE_IPV4 // prefer IPv4 if its an option bool foundV4 = false; - for (unsigned i = 0; i < nodeData.resolutionData.numIPs; ++i) + for (unsigned i = 0; i < nodeData.numIPs; ++i) { - if (nodeData.resolutionData.ipAddress[i].IsIPv4()) + if (nodeData.ipAddress[i].IsIPv4()) { foundV4 = true; client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[i], nodeData.resolutionData.port)); + chip::Transport::PeerAddress::UDP(nodeData.ipAddress[i], nodeData.port)); break; } } @@ -504,18 +510,18 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis if (!foundV4) { client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], nodeData.resolutionData.port)); + chip::Transport::PeerAddress::UDP(nodeData.ipAddress[0], nodeData.port)); } #else // INET_CONFIG_ENABLE_IPV4 // if we only support V6, then try to find a v6 address bool foundV6 = false; - for (unsigned i = 0; i < nodeData.resolutionData.numIPs; ++i) + for (unsigned i = 0; i < nodeData.numIPs; ++i) { - if (nodeData.resolutionData.ipAddress[i].IsIPv6()) + if (nodeData.ipAddress[i].IsIPv6()) { foundV6 = true; client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[i], nodeData.resolutionData.port)); + chip::Transport::PeerAddress::UDP(nodeData.ipAddress[i], nodeData.port)); break; } } @@ -523,17 +529,17 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis if (!foundV6) { ChipLogError(AppServer, "OnCommissionableNodeFound no v6 returned for instance name=%s", - nodeData.nodeData.instanceName); + nodeData.instanceName); client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], nodeData.resolutionData.port)); + chip::Transport::PeerAddress::UDP(nodeData.ipAddress[0], nodeData.port)); } #endif // INET_CONFIG_ENABLE_IPV4 - client->SetDeviceName(nodeData.nodeData.deviceName); - client->SetLongDiscriminator(nodeData.nodeData.longDiscriminator); - client->SetVendorId(nodeData.nodeData.vendorId); - client->SetProductId(nodeData.nodeData.productId); - client->SetRotatingId(nodeData.nodeData.rotatingId, nodeData.nodeData.rotatingIdLen); + client->SetDeviceName(nodeData.deviceName); + client->SetLongDiscriminator(nodeData.longDiscriminator); + client->SetVendorId(nodeData.vendorId); + client->SetProductId(nodeData.productId); + client->SetRotatingId(nodeData.rotatingId, nodeData.rotatingIdLen); // Call the registered mUserConfirmationProvider, if any. if (mUserConfirmationProvider != nullptr) diff --git a/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp b/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp index a62aa52b94a2e3..c1be77d05eeb64 100644 --- a/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp +++ b/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp @@ -86,23 +86,27 @@ void TestUDCServerUserConfirmationProvider(nlTestSuite * inSuite, void * inConte // setup for tests udcServer.SetUDCClientProcessingState((char *) instanceName1, UDCClientProcessingState::kUserDeclined); - Dnssd::DiscoveredNodeData nodeData1; - nodeData1.resolutionData.port = 5540; - nodeData1.resolutionData.ipAddress[0] = address; - nodeData1.resolutionData.numIPs = 1; - Platform::CopyString(nodeData1.nodeData.instanceName, instanceName1); - - Dnssd::DiscoveredNodeData nodeData2; - nodeData2.resolutionData.port = 5540; - nodeData2.resolutionData.ipAddress[0] = address; - nodeData2.resolutionData.numIPs = 1; - nodeData2.nodeData.longDiscriminator = disc2; - Platform::CopyString(nodeData2.nodeData.instanceName, instanceName2); - Platform::CopyString(nodeData2.nodeData.deviceName, deviceName2); + Dnssd::DiscoveredNodeData discNodeData1; + discNodeData1.Set(); + Dnssd::CommissionNodeData & nodeData1 = discNodeData1.Get(); + nodeData1.port = 5540; + nodeData1.ipAddress[0] = address; + nodeData1.numIPs = 1; + Platform::CopyString(nodeData1.instanceName, instanceName1); + + Dnssd::DiscoveredNodeData discNodeData2; + discNodeData2.Set(); + Dnssd::CommissionNodeData & nodeData2 = discNodeData2.Get(); + nodeData2.port = 5540; + nodeData2.ipAddress[0] = address; + nodeData2.numIPs = 1; + nodeData2.longDiscriminator = disc2; + Platform::CopyString(nodeData2.instanceName, instanceName2); + Platform::CopyString(nodeData2.deviceName, deviceName2); // test empty UserConfirmationProvider - udcServer.OnCommissionableNodeFound(nodeData2); - udcServer.OnCommissionableNodeFound(nodeData1); + udcServer.OnCommissionableNodeFound(discNodeData2); + udcServer.OnCommissionableNodeFound(discNodeData1); state = udcServer.GetUDCClients().FindUDCClientState(instanceName1); NL_TEST_EXIT_ON_FAILED_ASSERT(inSuite, nullptr != state); NL_TEST_ASSERT(inSuite, UDCClientProcessingState::kUserDeclined == state->GetUDCClientProcessingState()); @@ -115,8 +119,8 @@ void TestUDCServerUserConfirmationProvider(nlTestSuite * inSuite, void * inConte // test current state check udcServer.SetUDCClientProcessingState((char *) instanceName1, UDCClientProcessingState::kUserDeclined); udcServer.SetUDCClientProcessingState((char *) instanceName2, UDCClientProcessingState::kDiscoveringNode); - udcServer.OnCommissionableNodeFound(nodeData2); - udcServer.OnCommissionableNodeFound(nodeData1); + udcServer.OnCommissionableNodeFound(discNodeData2); + udcServer.OnCommissionableNodeFound(discNodeData1); state = udcServer.GetUDCClients().FindUDCClientState(instanceName1); NL_TEST_EXIT_ON_FAILED_ASSERT(inSuite, nullptr != state); NL_TEST_ASSERT(inSuite, UDCClientProcessingState::kUserDeclined == state->GetUDCClientProcessingState()); @@ -132,9 +136,9 @@ void TestUDCServerUserConfirmationProvider(nlTestSuite * inSuite, void * inConte udcServer.SetUserConfirmationProvider(&testCallback); udcServer.SetUDCClientProcessingState((char *) instanceName1, UDCClientProcessingState::kUserDeclined); udcServer.SetUDCClientProcessingState((char *) instanceName2, UDCClientProcessingState::kDiscoveringNode); - udcServer.OnCommissionableNodeFound(nodeData1); + udcServer.OnCommissionableNodeFound(discNodeData1); NL_TEST_ASSERT(inSuite, !testCallback.mOnUserDirectedCommissioningRequestCalled); - udcServer.OnCommissionableNodeFound(nodeData2); + udcServer.OnCommissionableNodeFound(discNodeData2); NL_TEST_ASSERT(inSuite, testCallback.mOnUserDirectedCommissioningRequestCalled); NL_TEST_ASSERT(inSuite, 0 == strcmp(testCallback.mState.GetInstanceName(), instanceName2)); } From 0540549e8aaebf3ff29b3e2f6553495c16a36a46 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 17 Apr 2024 11:08:31 +0000 Subject: [PATCH 2/9] Restyled by whitespace --- .../tv-casting-app/tv-casting-common/src/ConversionUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp b/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp index 0861f12cc95720..bd27f275cf20dd 100644 --- a/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp @@ -22,7 +22,7 @@ CHIP_ERROR ConvertToDiscoveredNodeData(TargetVideoPlayerInfo * inPlayer, chip::D { if (inPlayer == nullptr) return CHIP_ERROR_INVALID_ARGUMENT; - + outDiscNodeData.Set(); auto & outNodeData = outDiscNodeData.Get(); From b0b30ddf0355f9438546c3d2ed4d4982250fad9f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 17 Apr 2024 11:08:33 +0000 Subject: [PATCH 3/9] Restyled by clang-format --- .../commands/common/DeviceScanner.cpp | 2 +- .../commands/common/RemoteDataModelLogger.cpp | 2 +- .../commands/pairing/PairingCommand.cpp | 2 +- .../linux/ControllerShellCommands.cpp | 3 +- .../app/src/main/jni/cpp/ConversionUtils.cpp | 29 +++++++++---------- .../core/CastingPlayerDiscovery.cpp | 3 +- .../tv-casting-common/src/CastingServer.cpp | 10 +++---- .../tv-casting-common/src/ConversionUtils.cpp | 8 ++--- .../src/TargetVideoPlayerInfo.cpp | 4 +-- .../AbstractDnssdDiscoveryController.cpp | 5 ++-- src/controller/SetUpCodePairer.cpp | 5 ++-- .../java/CHIPDeviceController-JNI.cpp | 4 +-- ...issionableNodeController-ScriptBinding.cpp | 12 +++----- .../python/ChipDeviceController-Discovery.cpp | 15 ++++------ ...r-ScriptPairingDeviceDiscoveryDelegate.cpp | 5 ++-- .../TestCommissionableNodeController.cpp | 15 ++++------ src/lib/dnssd/ActiveResolveAttempts.h | 3 +- src/lib/dnssd/IncrementalResolve.cpp | 6 ++-- src/lib/shell/commands/Dns.cpp | 3 +- .../UserDirectedCommissioningServer.cpp | 18 ++++-------- .../tests/TestUdcMessages.cpp | 14 ++++----- 21 files changed, 69 insertions(+), 99 deletions(-) diff --git a/examples/chip-tool/commands/common/DeviceScanner.cpp b/examples/chip-tool/commands/common/DeviceScanner.cpp index 79b3669f14fea6..56e8f4566743b9 100644 --- a/examples/chip-tool/commands/common/DeviceScanner.cpp +++ b/examples/chip-tool/commands/common/DeviceScanner.cpp @@ -64,7 +64,7 @@ void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) ChipLogProgress(chipTool, "OnNodeDiscovered (MDNS): discriminator: %u, vendorId: %u, productId: %u", discriminator, vendorId, productId); - auto & resolutionData = (CommonResolutionData &)commissionData; + auto & resolutionData = (CommonResolutionData &) commissionData; auto & instanceData = mDiscoveredResults[commissionData.instanceName]; auto & interfaceData = instanceData[resolutionData.interfaceId.GetPlatformInterface()]; diff --git a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp index 92253f27d624c0..f036069fa48f33 100644 --- a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp +++ b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp @@ -209,7 +209,7 @@ CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeDat VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR); auto & commissionData = nodeData; - auto & resolutionData = (chip::Dnssd::CommonResolutionData &)commissionData; + auto & resolutionData = (chip::Dnssd::CommonResolutionData &) commissionData; if (!chip::CanCastTo(resolutionData.numIPs)) { diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 61afed536698f7..c0a1e677ddb8d3 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -484,7 +484,7 @@ void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & // Ignore nodes with closed commissioning window VerifyOrReturn(nodeData.commissioningMode != 0); - auto & resolutionData = (chip::Dnssd::CommonResolutionData &)nodeData; + auto & resolutionData = (chip::Dnssd::CommonResolutionData &) nodeData; const uint16_t port = resolutionData.port; char buf[chip::Inet::IPAddress::kMaxStringLength]; diff --git a/examples/platform/linux/ControllerShellCommands.cpp b/examples/platform/linux/ControllerShellCommands.cpp index 701448e0bd832c..b2bc8af2d8f92b 100644 --- a/examples/platform/linux/ControllerShellCommands.cpp +++ b/examples/platform/linux/ControllerShellCommands.cpp @@ -124,8 +124,7 @@ static CHIP_ERROR display(bool printHeader) else { streamer_printf(sout, " Entry %d instanceName=%s host=%s longDiscriminator=%d vendorId=%d productId=%d\r\n", i, - next->instanceName, next->hostName, next->longDiscriminator, - next->vendorId, next->productId); + next->instanceName, next->hostName, next->longDiscriminator, next->vendorId, next->productId); } } diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp index 002a94aa23897c..c8a38942e60234 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp @@ -324,25 +324,24 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered jstring jInstanceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getInstanceNameField)); if (jInstanceName != nullptr) { - chip::Platform::CopyString(outCppDiscoveredNodeData.instanceName, - chip::Dnssd::Commission::kInstanceNameMaxLength + 1, env->GetStringUTFChars(jInstanceName, 0)); + chip::Platform::CopyString(outCppDiscoveredNodeData.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, + env->GetStringUTFChars(jInstanceName, 0)); } - jfieldID jLongDiscriminatorField = env->GetFieldID(jDiscoveredNodeDataClass, "longDiscriminator", "J"); - outCppDiscoveredNodeData.vendorId = - static_cast(env->GetLongField(jDiscoveredNodeData, jLongDiscriminatorField)); + jfieldID jLongDiscriminatorField = env->GetFieldID(jDiscoveredNodeDataClass, "longDiscriminator", "J"); + outCppDiscoveredNodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jLongDiscriminatorField)); - jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J"); + jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J"); outCppDiscoveredNodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jVendorIdField)); - jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J"); + jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J"); outCppDiscoveredNodeData.productId = static_cast(env->GetLongField(jDiscoveredNodeData, jProductIdField)); jfieldID jCommissioningModeField = env->GetFieldID(jDiscoveredNodeDataClass, "commissioningMode", "B"); outCppDiscoveredNodeData.commissioningMode = static_cast(env->GetByteField(jDiscoveredNodeData, jCommissioningModeField)); - jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J"); + jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J"); outCppDiscoveredNodeData.deviceType = static_cast(env->GetLongField(jDiscoveredNodeData, jDeviceTypeField)); jfieldID getDeviceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceName", "Ljava/lang/String;"); @@ -354,13 +353,11 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered } // TODO: map rotating ID - jfieldID jRotatingIdLenField = env->GetFieldID(jDiscoveredNodeDataClass, "rotatingIdLen", "I"); - outCppDiscoveredNodeData.rotatingIdLen = - static_cast(env->GetIntField(jDiscoveredNodeData, jRotatingIdLenField)); + jfieldID jRotatingIdLenField = env->GetFieldID(jDiscoveredNodeDataClass, "rotatingIdLen", "I"); + outCppDiscoveredNodeData.rotatingIdLen = static_cast(env->GetIntField(jDiscoveredNodeData, jRotatingIdLenField)); - jfieldID jPairingHintField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingHint", "S"); - outCppDiscoveredNodeData.pairingHint = - static_cast(env->GetShortField(jDiscoveredNodeData, jPairingHintField)); + jfieldID jPairingHintField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingHint", "S"); + outCppDiscoveredNodeData.pairingHint = static_cast(env->GetShortField(jDiscoveredNodeData, jPairingHintField)); jfieldID getPairingInstructionField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingInstruction", "Ljava/lang/String;"); jstring jPairingInstruction = static_cast(env->GetObjectField(jDiscoveredNodeData, getPairingInstructionField)); @@ -370,10 +367,10 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered env->GetStringUTFChars(jPairingInstruction, 0)); } - jfieldID jPortField = env->GetFieldID(jDiscoveredNodeDataClass, "port", "I"); + jfieldID jPortField = env->GetFieldID(jDiscoveredNodeDataClass, "port", "I"); outCppDiscoveredNodeData.port = static_cast(env->GetIntField(jDiscoveredNodeData, jPortField)); - jfieldID jNumIpsField = env->GetFieldID(jDiscoveredNodeDataClass, "numIPs", "I"); + jfieldID jNumIpsField = env->GetFieldID(jDiscoveredNodeDataClass, "numIPs", "I"); outCppDiscoveredNodeData.numIPs = static_cast(env->GetIntField(jDiscoveredNodeData, jNumIpsField)); jfieldID jIPAddressesField = env->GetFieldID(jDiscoveredNodeDataClass, "ipAddresses", "Ljava/util/List;"); diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp index 82cb1487b91eaa..ee1256023a40b2 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp @@ -86,8 +86,7 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Commissi chip::Platform::CopyString(attributes.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, nodeData.deviceName); chip::Platform::CopyString(attributes.hostName, chip::Dnssd::kHostNameMaxLength + 1, nodeData.hostName); - chip::Platform::CopyString(attributes.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, - nodeData.instanceName); + chip::Platform::CopyString(attributes.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, nodeData.instanceName); attributes.numIPs = (unsigned int) nodeData.numIPs; for (unsigned j = 0; j < attributes.numIPs; j++) diff --git a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp index 7729dc0dcee874..f97db446d8783d 100644 --- a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp @@ -259,8 +259,8 @@ CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(Dnssd::Commission // Send User Directed commissioning request chip::Inet::IPAddress * ipAddressToUse = getIpAddressForUDCRequest(selectedCommissioner->ipAddress, selectedCommissioner->numIPs); - ReturnErrorOnFailure(SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP( - *ipAddressToUse, selectedCommissioner->port, selectedCommissioner->interfaceId))); + ReturnErrorOnFailure(SendUserDirectedCommissioningRequest( + chip::Transport::PeerAddress::UDP(*ipAddressToUse, selectedCommissioner->port, selectedCommissioner->interfaceId))); mTargetVideoPlayerVendorId = selectedCommissioner->vendorId; mTargetVideoPlayerProductId = selectedCommissioner->productId; mTargetVideoPlayerDeviceType = selectedCommissioner->deviceType; @@ -269,10 +269,8 @@ CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(Dnssd::Commission { mTargetVideoPlayerIpAddress[i] = selectedCommissioner->ipAddress[i]; } - chip::Platform::CopyString(mTargetVideoPlayerDeviceName, chip::Dnssd::kMaxDeviceNameLen + 1, - selectedCommissioner->deviceName); - chip::Platform::CopyString(mTargetVideoPlayerHostName, chip::Dnssd::kHostNameMaxLength + 1, - selectedCommissioner->hostName); + chip::Platform::CopyString(mTargetVideoPlayerDeviceName, chip::Dnssd::kMaxDeviceNameLen + 1, selectedCommissioner->deviceName); + chip::Platform::CopyString(mTargetVideoPlayerHostName, chip::Dnssd::kHostNameMaxLength + 1, selectedCommissioner->hostName); chip::Platform::CopyString(mTargetVideoPlayerInstanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, selectedCommissioner->instanceName); mTargetVideoPlayerPort = selectedCommissioner->port; diff --git a/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp b/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp index bd27f275cf20dd..3c098aa9b4fbf3 100644 --- a/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp @@ -26,10 +26,10 @@ CHIP_ERROR ConvertToDiscoveredNodeData(TargetVideoPlayerInfo * inPlayer, chip::D outDiscNodeData.Set(); auto & outNodeData = outDiscNodeData.Get(); - outNodeData.vendorId = inPlayer->GetVendorId(); - outNodeData.productId = static_cast(inPlayer->GetProductId()); - outNodeData.deviceType = inPlayer->GetDeviceType(); - outNodeData.numIPs = inPlayer->GetNumIPs(); + outNodeData.vendorId = inPlayer->GetVendorId(); + outNodeData.productId = static_cast(inPlayer->GetProductId()); + outNodeData.deviceType = inPlayer->GetDeviceType(); + outNodeData.numIPs = inPlayer->GetNumIPs(); const chip::Inet::IPAddress * ipAddresses = inPlayer->GetIpAddresses(); if (ipAddresses != nullptr) diff --git a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp index d22c9682c01769..a3ded0d7db8f26 100644 --- a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp @@ -232,6 +232,6 @@ bool TargetVideoPlayerInfo::IsSameAs(const chip::Dnssd::CommissionNodeData * dis return false; } - return IsSameAs(discoveredNodeData->hostName, discoveredNodeData->deviceName, - discoveredNodeData->numIPs, discoveredNodeData->ipAddress); + return IsSameAs(discoveredNodeData->hostName, discoveredNodeData->deviceName, discoveredNodeData->numIPs, + discoveredNodeData->ipAddress); } diff --git a/src/controller/AbstractDnssdDiscoveryController.cpp b/src/controller/AbstractDnssdDiscoveryController.cpp index 0f9b8d739fd84d..3d3ca4c8097955 100644 --- a/src/controller/AbstractDnssdDiscoveryController.cpp +++ b/src/controller/AbstractDnssdDiscoveryController.cpp @@ -30,7 +30,7 @@ void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::Disco VerifyOrReturn(discNodeData.Is()); auto discoveredNodes = GetDiscoveredNodes(); - auto & nodeData = discNodeData.Get(); + auto & nodeData = discNodeData.Get(); for (auto & discoveredNode : discoveredNodes) { @@ -40,8 +40,7 @@ void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::Disco } // TODO(#32576) Check if IP address are the same. Must account for `numIPs` in the list of `ipAddress`. // Additionally, must NOT assume that the ordering is consistent. - if (strcmp(discoveredNode.hostName, nodeData.hostName) == 0 && - discoveredNode.port == nodeData.port && + if (strcmp(discoveredNode.hostName, nodeData.hostName) == 0 && discoveredNode.port == nodeData.port && discoveredNode.numIPs == nodeData.numIPs) { discoveredNode = nodeData; diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 7ae5c9d7b2e89d..e341283f65dd72 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -352,8 +352,7 @@ bool SetUpCodePairer::NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & } // The advertisement may not include a product id. - if (IdIsPresent(mPayloadProductID) && IdIsPresent(nodeData.productId) && - mPayloadProductID != nodeData.productId) + if (IdIsPresent(mPayloadProductID) && IdIsPresent(nodeData.productId) && mPayloadProductID != nodeData.productId) { ChipLogProgress(Controller, "Discovered device does not match our product id."); return false; @@ -388,7 +387,7 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover ChipLogProgress(Controller, "Discovered device to be commissioned over DNS-SD"); - NotifyCommissionableDeviceDiscovered((Dnssd::CommonResolutionData &)nodeData.Get()); + NotifyCommissionableDeviceDiscovered((Dnssd::CommonResolutionData &) nodeData.Get()); } void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::CommonResolutionData & resolutionData) diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 352dee619172ad..dd034caf2007ba 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1879,8 +1879,8 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl env->SetIntField(discoveredObj, productIdID, static_cast(data->productId)); jbyteArray jRotatingId; - CHIP_ERROR err = JniReferences::GetInstance().N2J_ByteArray(env, data->rotatingId, - static_cast(data->rotatingIdLen), jRotatingId); + CHIP_ERROR err = + JniReferences::GetInstance().N2J_ByteArray(env, data->rotatingId, static_cast(data->rotatingIdLen), jRotatingId); if (err != CHIP_NO_ERROR) { diff --git a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp index 4f38ed699f19f0..6df32c6940667a 100644 --- a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp +++ b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp @@ -82,8 +82,7 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( continue; } char rotatingId[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, - sizeof(rotatingId)); + Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissioner %d", i); ChipLogProgress(Discovery, "\tInstance name:\t\t%s", dnsSdInfo->instanceName); @@ -100,8 +99,7 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->pairingHint); if (dnsSdInfo->GetMrpRetryIntervalIdle().HasValue()) { - ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", - dnsSdInfo->GetMrpRetryIntervalIdle().Value().count()); + ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", dnsSdInfo->GetMrpRetryIntervalIdle().Value().count()); } else { @@ -109,8 +107,7 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( } if (dnsSdInfo->GetMrpRetryIntervalActive().HasValue()) { - ChipLogProgress(Discovery, "\tMrp Interval active\t%u", - dnsSdInfo->GetMrpRetryIntervalActive().Value().count()); + ChipLogProgress(Discovery, "\tMrp Interval active\t%u", dnsSdInfo->GetMrpRetryIntervalActive().Value().count()); } else { @@ -120,8 +117,7 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( if (dnsSdInfo->isICDOperatingAsLIT.HasValue()) { - ChipLogProgress(Discovery, "\tICD is operating as a\t%s", - dnsSdInfo->isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + ChipLogProgress(Discovery, "\tICD is operating as a\t%s", dnsSdInfo->isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); } for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j) diff --git a/src/controller/python/ChipDeviceController-Discovery.cpp b/src/controller/python/ChipDeviceController-Discovery.cpp index c97ee6d5d4429b..b7589791b41eab 100644 --- a/src/controller/python/ChipDeviceController-Discovery.cpp +++ b/src/controller/python/ChipDeviceController-Discovery.cpp @@ -110,8 +110,7 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De Json::Value jsonVal; char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, - sizeof(rotatingId)); + Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissionable Node %d", i); jsonVal["instanceName"] = dnsSdInfo->instanceName; @@ -174,8 +173,7 @@ void pychip_DeviceController_PrintDiscoveredDevices(Controller::DeviceCommission continue; } char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, - sizeof(rotatingId)); + Encoding::BytesToUppercaseHexString(dnsSdInfo->rotatingId, dnsSdInfo->rotatingIdLen, rotatingId, sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissionable Node %d", i); ChipLogProgress(Discovery, "\tInstance name:\t\t%s", dnsSdInfo->instanceName); @@ -192,8 +190,7 @@ void pychip_DeviceController_PrintDiscoveredDevices(Controller::DeviceCommission ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->pairingHint); if (dnsSdInfo->GetMrpRetryIntervalIdle().HasValue()) { - ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", - dnsSdInfo->GetMrpRetryIntervalIdle().Value().count()); + ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", dnsSdInfo->GetMrpRetryIntervalIdle().Value().count()); } else { @@ -201,8 +198,7 @@ void pychip_DeviceController_PrintDiscoveredDevices(Controller::DeviceCommission } if (dnsSdInfo->GetMrpRetryIntervalActive().HasValue()) { - ChipLogProgress(Discovery, "\tMrp Interval active\t%u", - dnsSdInfo->GetMrpRetryIntervalActive().Value().count()); + ChipLogProgress(Discovery, "\tMrp Interval active\t%u", dnsSdInfo->GetMrpRetryIntervalActive().Value().count()); } else { @@ -211,8 +207,7 @@ void pychip_DeviceController_PrintDiscoveredDevices(Controller::DeviceCommission ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp); if (dnsSdInfo->isICDOperatingAsLIT.HasValue()) { - ChipLogProgress(Discovery, "\tICD is operating as a\t%s", - dnsSdInfo->isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + ChipLogProgress(Discovery, "\tICD is operating as a\t%s", dnsSdInfo->isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); } for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j) { diff --git a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp index 534383fa8aca43..56b4932e9a8988 100644 --- a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp +++ b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp @@ -38,9 +38,8 @@ void ScriptPairingDeviceDiscoveryDelegate::OnDiscoveredDevice(const Dnssd::Commi // Stop Mdns discovery. mActiveDeviceCommissioner->RegisterDeviceDiscoveryDelegate(nullptr); - Inet::InterfaceId interfaceId = - nodeData.ipAddress[0].IsIPv6LinkLocal() ? nodeData.interfaceId : Inet::InterfaceId::Null(); - auto peerAddress = Transport::PeerAddress::UDP(nodeData.ipAddress[0], port, interfaceId); + Inet::InterfaceId interfaceId = nodeData.ipAddress[0].IsIPv6LinkLocal() ? nodeData.interfaceId : Inet::InterfaceId::Null(); + auto peerAddress = Transport::PeerAddress::UDP(nodeData.ipAddress[0], port, interfaceId); RendezvousParameters keyExchangeParams = RendezvousParameters().SetSetupPINCode(mSetupPasscode).SetPeerAddress(peerAddress); diff --git a/src/controller/tests/TestCommissionableNodeController.cpp b/src/controller/tests/TestCommissionableNodeController.cpp index 78f43e19ee6e82..5e866b4b25ea72 100644 --- a/src/controller/tests/TestCommissionableNodeController.cpp +++ b/src/controller/tests/TestCommissionableNodeController.cpp @@ -77,10 +77,8 @@ void TestGetDiscoveredCommissioner_HappyCase(nlTestSuite * inSuite, void * inCon controller.OnNodeDiscovered(discNodeData); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0) != nullptr); - NL_TEST_ASSERT( - inSuite, strcmp(inNodeData.hostName, controller.GetDiscoveredCommissioner(0)->hostName) == 0); - NL_TEST_ASSERT(inSuite, - inNodeData.ipAddress[0] == controller.GetDiscoveredCommissioner(0)->ipAddress[0]); + NL_TEST_ASSERT(inSuite, strcmp(inNodeData.hostName, controller.GetDiscoveredCommissioner(0)->hostName) == 0); + NL_TEST_ASSERT(inSuite, inNodeData.ipAddress[0] == controller.GetDiscoveredCommissioner(0)->ipAddress[0]); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->port == 5540); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->numIPs == 1); } @@ -112,7 +110,7 @@ void TestGetDiscoveredCommissioner_HappyCase_OneValidOneInvalidNode(nlTestSuite invalidDiscNodeData.Set(); validDiscNodeData.Set(); chip::Dnssd::CommissionNodeData & invalidNodeData = invalidDiscNodeData.Get(); - chip::Dnssd::CommissionNodeData & validNodeData = validDiscNodeData.Get(); + chip::Dnssd::CommissionNodeData & validNodeData = validDiscNodeData.Get(); Inet::IPAddress::FromString("192.168.1.10", invalidNodeData.ipAddress[0]); invalidNodeData.numIPs++; invalidNodeData.port = 5540; @@ -126,11 +124,8 @@ void TestGetDiscoveredCommissioner_HappyCase_OneValidOneInvalidNode(nlTestSuite controller.OnNodeDiscovered(invalidDiscNodeData); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0) != nullptr); - NL_TEST_ASSERT( - inSuite, - strcmp(validNodeData.hostName, controller.GetDiscoveredCommissioner(0)->hostName) == 0); - NL_TEST_ASSERT( - inSuite, validNodeData.ipAddress[0] == controller.GetDiscoveredCommissioner(0)->ipAddress[0]); + NL_TEST_ASSERT(inSuite, strcmp(validNodeData.hostName, controller.GetDiscoveredCommissioner(0)->hostName) == 0); + NL_TEST_ASSERT(inSuite, validNodeData.ipAddress[0] == controller.GetDiscoveredCommissioner(0)->ipAddress[0]); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->port == 5540); NL_TEST_ASSERT(inSuite, controller.GetDiscoveredCommissioner(0)->numIPs == 1); diff --git a/src/lib/dnssd/ActiveResolveAttempts.h b/src/lib/dnssd/ActiveResolveAttempts.h index 39728552433c4f..aa5ed2bcd2b446 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.h +++ b/src/lib/dnssd/ActiveResolveAttempts.h @@ -159,7 +159,8 @@ class ActiveResolveAttempts case chip::Dnssd::DiscoveryFilterType::kNone: return true; case chip::Dnssd::DiscoveryFilterType::kShortDiscriminator: - return browse.filter.code == static_cast((data.Get().longDiscriminator >> 8) & 0x0F); + return browse.filter.code == + static_cast((data.Get().longDiscriminator >> 8) & 0x0F); case chip::Dnssd::DiscoveryFilterType::kLongDiscriminator: return browse.filter.code == data.Get().longDiscriminator; case chip::Dnssd::DiscoveryFilterType::kVendorId: diff --git a/src/lib/dnssd/IncrementalResolve.cpp b/src/lib/dnssd/IncrementalResolve.cpp index 5f9a951b5dc569..a246d16500be0a 100644 --- a/src/lib/dnssd/IncrementalResolve.cpp +++ b/src/lib/dnssd/IncrementalResolve.cpp @@ -348,9 +348,9 @@ CHIP_ERROR IncrementalResolver::Take(DiscoveredNodeData & outputData) IPAddressSorter::Sort(mCommonResolutionData.ipAddress, mCommonResolutionData.numIPs, mCommonResolutionData.interfaceId); outputData.Set(); - CommissionNodeData & nodeData = outputData.Get(); - nodeData = mSpecificResolutionData.Get(); - (CommonResolutionData &)nodeData = mCommonResolutionData; + CommissionNodeData & nodeData = outputData.Get(); + nodeData = mSpecificResolutionData.Get(); + (CommonResolutionData &) nodeData = mCommonResolutionData; ResetToInactive(); diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 9fff1d7999f74e..04d82313d7d3d4 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -99,8 +99,7 @@ class DnsShellResolverDelegate : public Dnssd::DiscoverNodeDelegate, public Addr } char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1]; - Encoding::BytesToUppercaseHexString(nodeData.rotatingId, nodeData.rotatingIdLen, rotatingId, - sizeof(rotatingId)); + Encoding::BytesToUppercaseHexString(nodeData.rotatingId, nodeData.rotatingIdLen, rotatingId, sizeof(rotatingId)); streamer_printf(streamer_get(), "DNS browse succeeded: \r\n"); streamer_printf(streamer_get(), " Hostname: %s\r\n", nodeData.hostName); diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp index 24e7ff6f15821f..46f40a701944d1 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp @@ -476,8 +476,7 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis Dnssd::CommissionNodeData nodeData = discNodeData.Get(); if (nodeData.numIPs == 0) { - ChipLogError(AppServer, "OnCommissionableNodeFound no IP addresses returned for instance name=%s", - nodeData.instanceName); + ChipLogError(AppServer, "OnCommissionableNodeFound no IP addresses returned for instance name=%s", nodeData.instanceName); return; } if (nodeData.port == 0) @@ -501,16 +500,14 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis if (nodeData.ipAddress[i].IsIPv4()) { foundV4 = true; - client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.ipAddress[i], nodeData.port)); + client->SetPeerAddress(chip::Transport::PeerAddress::UDP(nodeData.ipAddress[i], nodeData.port)); break; } } // use IPv6 as last resort if (!foundV4) { - client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.ipAddress[0], nodeData.port)); + client->SetPeerAddress(chip::Transport::PeerAddress::UDP(nodeData.ipAddress[0], nodeData.port)); } #else // INET_CONFIG_ENABLE_IPV4 // if we only support V6, then try to find a v6 address @@ -520,18 +517,15 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis if (nodeData.ipAddress[i].IsIPv6()) { foundV6 = true; - client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.ipAddress[i], nodeData.port)); + client->SetPeerAddress(chip::Transport::PeerAddress::UDP(nodeData.ipAddress[i], nodeData.port)); break; } } // last resort, try with what we have if (!foundV6) { - ChipLogError(AppServer, "OnCommissionableNodeFound no v6 returned for instance name=%s", - nodeData.instanceName); - client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.ipAddress[0], nodeData.port)); + ChipLogError(AppServer, "OnCommissionableNodeFound no v6 returned for instance name=%s", nodeData.instanceName); + client->SetPeerAddress(chip::Transport::PeerAddress::UDP(nodeData.ipAddress[0], nodeData.port)); } #endif // INET_CONFIG_ENABLE_IPV4 diff --git a/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp b/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp index c1be77d05eeb64..3d50682dee5dcf 100644 --- a/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp +++ b/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp @@ -89,18 +89,18 @@ void TestUDCServerUserConfirmationProvider(nlTestSuite * inSuite, void * inConte Dnssd::DiscoveredNodeData discNodeData1; discNodeData1.Set(); Dnssd::CommissionNodeData & nodeData1 = discNodeData1.Get(); - nodeData1.port = 5540; - nodeData1.ipAddress[0] = address; - nodeData1.numIPs = 1; + nodeData1.port = 5540; + nodeData1.ipAddress[0] = address; + nodeData1.numIPs = 1; Platform::CopyString(nodeData1.instanceName, instanceName1); Dnssd::DiscoveredNodeData discNodeData2; discNodeData2.Set(); Dnssd::CommissionNodeData & nodeData2 = discNodeData2.Get(); - nodeData2.port = 5540; - nodeData2.ipAddress[0] = address; - nodeData2.numIPs = 1; - nodeData2.longDiscriminator = disc2; + nodeData2.port = 5540; + nodeData2.ipAddress[0] = address; + nodeData2.numIPs = 1; + nodeData2.longDiscriminator = disc2; Platform::CopyString(nodeData2.instanceName, instanceName2); Platform::CopyString(nodeData2.deviceName, deviceName2); From 13726b394af15bb6a6f993dbced8153f6e5858ef Mon Sep 17 00:00:00 2001 From: Suhas Shankar Date: Thu, 18 Apr 2024 16:31:58 +0530 Subject: [PATCH 4/9] updates based on review feedback --- .../commands/common/DeviceScanner.cpp | 3 +- .../core/CastingPlayerDiscovery.cpp | 3 +- src/controller/SetUpCodePairer.cpp | 2 +- .../CHIP/MTRCommissionableBrowser.mm | 5 ++ src/lib/dnssd/ActiveResolveAttempts.h | 13 ++-- src/lib/dnssd/IncrementalResolve.cpp | 3 +- src/lib/dnssd/Types.h | 25 +------ src/lib/dnssd/tests/TestTxtFields.cpp | 75 ++++++++++--------- .../UserDirectedCommissioningServer.cpp | 2 +- 9 files changed, 61 insertions(+), 70 deletions(-) diff --git a/examples/chip-tool/commands/common/DeviceScanner.cpp b/examples/chip-tool/commands/common/DeviceScanner.cpp index 56e8f4566743b9..86b6b456907b04 100644 --- a/examples/chip-tool/commands/common/DeviceScanner.cpp +++ b/examples/chip-tool/commands/common/DeviceScanner.cpp @@ -55,6 +55,7 @@ CHIP_ERROR DeviceScanner::Stop() void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) { + VerifyOrReturn(nodeData.Is()) auto & commissionData = nodeData.Get(); auto discriminator = commissionData.longDiscriminator; @@ -64,7 +65,7 @@ void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) ChipLogProgress(chipTool, "OnNodeDiscovered (MDNS): discriminator: %u, vendorId: %u, productId: %u", discriminator, vendorId, productId); - auto & resolutionData = (CommonResolutionData &) commissionData; + CommonResolutionData & resolutionData = commissionData; auto & instanceData = mDiscoveredResults[commissionData.instanceName]; auto & interfaceData = instanceData[resolutionData.interfaceId.GetPlatformInterface()]; diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp index ee1256023a40b2..531de966810163 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp @@ -73,13 +73,12 @@ CHIP_ERROR CastingPlayerDiscovery::StopDiscovery() return CHIP_NO_ERROR; } -void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & discNodeData) +void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) { ChipLogProgress(Discovery, "DeviceDiscoveryDelegateImpl::OnDiscoveredDevice() called"); VerifyOrReturn(mClientDelegate != nullptr, ChipLogError(Discovery, "DeviceDiscoveryDelegateImpl::OnDiscoveredDevice mClientDelegate is a nullptr")); - auto & nodeData = discNodeData; // convert nodeData to CastingPlayer CastingPlayerAttributes attributes; snprintf(attributes.id, kIdMaxLength + 1, "%s%u", nodeData.hostName, nodeData.port); diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index e341283f65dd72..3dcd95ca915264 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -337,7 +337,7 @@ bool SetUpCodePairer::NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & return false; } - Dnssd::CommissionNodeData nodeData = discNodeData.Get(); + const Dnssd::CommissionNodeData & nodeData = discNodeData.Get(); if (nodeData.commissioningMode == 0) { ChipLogProgress(Controller, "Discovered device does not have an open commissioning window."); diff --git a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm index 760c6f39b65c29..68de4509be8394 100644 --- a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm +++ b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm @@ -161,6 +161,11 @@ void OnNodeDiscovered(const DiscoveredNodeData & nodeData) override { assertChipStackLockedByCurrentThread(); + if (!nodeData.Is()) { + // not commissionable/commissioners node + return; + } + auto & commissionData = nodeData.Get(); auto key = [NSString stringWithUTF8String:commissionData.instanceName]; if ([mDiscoveredResults objectForKey:key] == nil) { diff --git a/src/lib/dnssd/ActiveResolveAttempts.h b/src/lib/dnssd/ActiveResolveAttempts.h index aa5ed2bcd2b446..2fff2b97657128 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.h +++ b/src/lib/dnssd/ActiveResolveAttempts.h @@ -153,6 +153,7 @@ class ActiveResolveAttempts { return false; } + auto & nodeData = data.Get(); switch (browse.filter.type) { @@ -160,17 +161,17 @@ class ActiveResolveAttempts return true; case chip::Dnssd::DiscoveryFilterType::kShortDiscriminator: return browse.filter.code == - static_cast((data.Get().longDiscriminator >> 8) & 0x0F); + static_cast((nodeData.longDiscriminator >> 8) & 0x0F); case chip::Dnssd::DiscoveryFilterType::kLongDiscriminator: - return browse.filter.code == data.Get().longDiscriminator; + return browse.filter.code == nodeData.longDiscriminator; case chip::Dnssd::DiscoveryFilterType::kVendorId: - return browse.filter.code == data.Get().vendorId; + return browse.filter.code == nodeData.vendorId; case chip::Dnssd::DiscoveryFilterType::kDeviceType: - return browse.filter.code == data.Get().deviceType; + return browse.filter.code == nodeData.deviceType; case chip::Dnssd::DiscoveryFilterType::kCommissioningMode: - return browse.filter.code == data.Get().commissioningMode; + return browse.filter.code == nodeData.commissioningMode; case chip::Dnssd::DiscoveryFilterType::kInstanceName: - return strncmp(browse.filter.instanceName, data.Get().instanceName, + return strncmp(browse.filter.instanceName, nodeData.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1) == 0; case chip::Dnssd::DiscoveryFilterType::kCommissioner: case chip::Dnssd::DiscoveryFilterType::kCompressedFabricId: diff --git a/src/lib/dnssd/IncrementalResolve.cpp b/src/lib/dnssd/IncrementalResolve.cpp index a246d16500be0a..279362f3ba6abf 100644 --- a/src/lib/dnssd/IncrementalResolve.cpp +++ b/src/lib/dnssd/IncrementalResolve.cpp @@ -350,7 +350,8 @@ CHIP_ERROR IncrementalResolver::Take(DiscoveredNodeData & outputData) outputData.Set(); CommissionNodeData & nodeData = outputData.Get(); nodeData = mSpecificResolutionData.Get(); - (CommonResolutionData &) nodeData = mCommonResolutionData; + CommonResolutionData & resolutionData = nodeData; + resolutionData = mCommonResolutionData; ResetToInactive(); diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h index 4ad3eb608a78d4..e1de1e429e154b 100644 --- a/src/lib/dnssd/Types.h +++ b/src/lib/dnssd/Types.h @@ -235,6 +235,7 @@ struct CommissionNodeData : public CommonResolutionData void LogDetail() const { + ChipLogDetail(Discovery, "Discovered commissionable/commissioners node:"); CommonResolutionData::LogDetail(); if (rotatingIdLen > 0) @@ -299,30 +300,6 @@ struct ResolvedNodeData using DiscoveredNodeData = Variant; -#if 0 -struct DiscoveredNodeData -{ - CommonResolutionData resolutionData; - CommissionNodeData nodeData; - DiscoveryType nodeType; - - void Reset() - { - resolutionData.Reset(); - nodeData.Reset(); - nodeType = DiscoveryType::kUnknown; - } - DiscoveredNodeData() { Reset(); } - - void LogDetail() const - { - ChipLogDetail(Discovery, "Discovered node:"); - resolutionData.LogDetail(); - nodeData.LogDetail(); - } -}; -#endif - /// Callbacks for discovering nodes advertising non-operational status: /// - Commissioners /// - Nodes in commissioning modes over IP (e.g. ethernet devices, devices already diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 336171b6759658..e2540859fe965a 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -455,18 +455,19 @@ void DiscoveredTxtFieldSessionIdleInterval() char val[16]; DiscoveredNodeData nodeData; nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); // Minimum strcpy(key, "SII"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().Value() == 1_ms32); // Maximum strcpy(key, "SII"); strcpy(val, "3600000"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().Value() == 3600000_ms32); @@ -477,37 +478,37 @@ void DiscoveredTxtFieldSessionIdleInterval() // Invalid SII - negative value strcpy(key, "SII"); strcpy(val, "-1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - greater than maximum strcpy(key, "SII"); strcpy(val, "3600001"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - much greater than maximum strcpy(key, "SII"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - hexadecimal value strcpy(key, "SII"); strcpy(val, "0x20"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - leading zeros strcpy(key, "SII"); strcpy(val, "0700"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - text at the end strcpy(key, "SII"); strcpy(val, "123abc"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); } @@ -519,18 +520,19 @@ void DiscoveredTxtFieldSessionActiveInterval() char val[16]; DiscoveredNodeData nodeData; nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); // Minimum strcpy(key, "SAI"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().HasValue()); EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().Value() == 1_ms32); // Maximum strcpy(key, "SAI"); strcpy(val, "3600000"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().HasValue()); EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().Value() == 3600000_ms32); @@ -541,37 +543,37 @@ void DiscoveredTxtFieldSessionActiveInterval() // Invalid SAI - negative value strcpy(key, "SAI"); strcpy(val, "-1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - greater than maximum strcpy(key, "SAI"); strcpy(val, "3600001"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - much greater than maximum strcpy(key, "SAI"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - hexadecimal value strcpy(key, "SAI"); strcpy(val, "0x20"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - leading zeros strcpy(key, "SAI"); strcpy(val, "0700"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - text at the end strcpy(key, "SAI"); strcpy(val, "123abc"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); } @@ -583,18 +585,19 @@ void DiscoveredTxtFieldSessionActiveThreshold() char val[16]; DiscoveredNodeData nodeData; nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); // Minimum strcpy(key, "SAT"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().Value() == 1_ms16); // Maximum strcpy(key, "SAT"); strcpy(val, "65535"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().Value() == 65535_ms16); @@ -605,37 +608,37 @@ void DiscoveredTxtFieldSessionActiveThreshold() // Invalid SAI - negative value strcpy(key, "SAT"); strcpy(val, "-1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAI - greater than maximum strcpy(key, "SAT"); strcpy(val, "65536"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAT - much greater than maximum strcpy(key, "SAT"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAT - hexadecimal value strcpy(key, "SAT"); strcpy(val, "0x20"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAT - leading zeros strcpy(key, "SAT"); strcpy(val, "0700"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAT - text at the end strcpy(key, "SAT"); strcpy(val, "123abc"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); } @@ -647,11 +650,12 @@ void DiscoveredTxtFieldTcpSupport() char val[8]; DiscoveredNodeData nodeData; nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); // True strcpy(key, "T"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().supportsTcp); // Test no other fields were populated @@ -661,13 +665,13 @@ void DiscoveredTxtFieldTcpSupport() // False strcpy(key, "T"); strcpy(val, "0"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().supportsTcp == false); // Invalid value, stil false strcpy(key, "T"); strcpy(val, "asdf"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().supportsTcp == false); } @@ -679,11 +683,12 @@ void DiscoveredTxtFieldICDoperatesAsLIT() char val[16]; DiscoveredNodeData nodeData; nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); // ICD is operating as a LIT device strcpy(key, "ICD"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue()); EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.Value()); @@ -694,7 +699,7 @@ void DiscoveredTxtFieldICDoperatesAsLIT() // ICD is operating as a SIT device strcpy(key, "ICD"); strcpy(val, "0"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue()); EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.Value() == false); @@ -703,7 +708,7 @@ void DiscoveredTxtFieldICDoperatesAsLIT() // Invalid value, No key set strcpy(key, "ICD"); strcpy(val, "asdf"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue() == false); } @@ -717,6 +722,7 @@ void DiscoveredTestIsDeviceSessionIdle() nodeData.Set(); const ReliableMessageProtocolConfig defaultMRPConfig(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL); + CommonResolutionData & resolutionData = nodeData.Get(); // No key/val set, so the device can't be sleepy EXPECT_TRUE( !nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); @@ -724,13 +730,13 @@ void DiscoveredTestIsDeviceSessionIdle() // If the interval is the default value, the device is not sleepy strcpy(key, "SII"); sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL.count())); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().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_LOCAL_IDLE_RETRY_INTERVAL.count() + 1)); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); } @@ -744,6 +750,7 @@ void DiscoveredTestIsDeviceSessionActive() nodeData.Set(); const ReliableMessageProtocolConfig defaultMRPConfig(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL); + CommonResolutionData & resolutionData = nodeData.Get(); // No key/val set, so the device can't be sleepy EXPECT_TRUE( !nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); @@ -751,13 +758,13 @@ void DiscoveredTestIsDeviceSessionActive() // If the interval is the default value, the device is not sleepy sprintf(key, "SAI"); sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL.count())); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( !nodeData.Get().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_LOCAL_ACTIVE_RETRY_INTERVAL.count() + 1)); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), (CommonResolutionData &)nodeData.Get()); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); EXPECT_TRUE( nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); } diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp index 46f40a701944d1..cb953c8a60e5ca 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp @@ -473,7 +473,7 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis return; } - Dnssd::CommissionNodeData nodeData = discNodeData.Get(); + const Dnssd::CommissionNodeData & nodeData = discNodeData.Get(); if (nodeData.numIPs == 0) { ChipLogError(AppServer, "OnCommissionableNodeFound no IP addresses returned for instance name=%s", nodeData.instanceName); From 893c5d1a6cefd66a5de6f22d57e190e2ade427d8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 18 Apr 2024 11:02:23 +0000 Subject: [PATCH 5/9] Restyled by whitespace --- src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm index 68de4509be8394..6cd70f05065516 100644 --- a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm +++ b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm @@ -162,7 +162,7 @@ void OnNodeDiscovered(const DiscoveredNodeData & nodeData) override assertChipStackLockedByCurrentThread(); if (!nodeData.Is()) { - // not commissionable/commissioners node + // not commissionable/commissioners node return; } From 1f70a7aa8b1d06e869973e9624cdbf3aacbd1dcc Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 18 Apr 2024 11:02:24 +0000 Subject: [PATCH 6/9] Restyled by clang-format --- examples/chip-tool/commands/common/DeviceScanner.cpp | 3 +-- src/lib/dnssd/ActiveResolveAttempts.h | 3 +-- src/lib/dnssd/IncrementalResolve.cpp | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/chip-tool/commands/common/DeviceScanner.cpp b/examples/chip-tool/commands/common/DeviceScanner.cpp index 86b6b456907b04..75dcd31abcebce 100644 --- a/examples/chip-tool/commands/common/DeviceScanner.cpp +++ b/examples/chip-tool/commands/common/DeviceScanner.cpp @@ -55,8 +55,7 @@ CHIP_ERROR DeviceScanner::Stop() void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) { - VerifyOrReturn(nodeData.Is()) - auto & commissionData = nodeData.Get(); + VerifyOrReturn(nodeData.Is()) auto & commissionData = nodeData.Get(); auto discriminator = commissionData.longDiscriminator; auto vendorId = static_cast(commissionData.vendorId); diff --git a/src/lib/dnssd/ActiveResolveAttempts.h b/src/lib/dnssd/ActiveResolveAttempts.h index 2fff2b97657128..55790bd1e3821e 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.h +++ b/src/lib/dnssd/ActiveResolveAttempts.h @@ -160,8 +160,7 @@ class ActiveResolveAttempts case chip::Dnssd::DiscoveryFilterType::kNone: return true; case chip::Dnssd::DiscoveryFilterType::kShortDiscriminator: - return browse.filter.code == - static_cast((nodeData.longDiscriminator >> 8) & 0x0F); + return browse.filter.code == static_cast((nodeData.longDiscriminator >> 8) & 0x0F); case chip::Dnssd::DiscoveryFilterType::kLongDiscriminator: return browse.filter.code == nodeData.longDiscriminator; case chip::Dnssd::DiscoveryFilterType::kVendorId: diff --git a/src/lib/dnssd/IncrementalResolve.cpp b/src/lib/dnssd/IncrementalResolve.cpp index 279362f3ba6abf..f083f852d7402f 100644 --- a/src/lib/dnssd/IncrementalResolve.cpp +++ b/src/lib/dnssd/IncrementalResolve.cpp @@ -348,10 +348,10 @@ CHIP_ERROR IncrementalResolver::Take(DiscoveredNodeData & outputData) IPAddressSorter::Sort(mCommonResolutionData.ipAddress, mCommonResolutionData.numIPs, mCommonResolutionData.interfaceId); outputData.Set(); - CommissionNodeData & nodeData = outputData.Get(); - nodeData = mSpecificResolutionData.Get(); + CommissionNodeData & nodeData = outputData.Get(); + nodeData = mSpecificResolutionData.Get(); CommonResolutionData & resolutionData = nodeData; - resolutionData = mCommonResolutionData; + resolutionData = mCommonResolutionData; ResetToInactive(); From e6356d856d2e9011b2dd3e99017009aca1570d18 Mon Sep 17 00:00:00 2001 From: Suhas Shankar Date: Thu, 18 Apr 2024 18:29:52 +0530 Subject: [PATCH 7/9] fix for build failure --- examples/chip-tool/commands/common/DeviceScanner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/common/DeviceScanner.cpp b/examples/chip-tool/commands/common/DeviceScanner.cpp index 75dcd31abcebce..548e461f96ca8e 100644 --- a/examples/chip-tool/commands/common/DeviceScanner.cpp +++ b/examples/chip-tool/commands/common/DeviceScanner.cpp @@ -55,7 +55,8 @@ CHIP_ERROR DeviceScanner::Stop() void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) { - VerifyOrReturn(nodeData.Is()) auto & commissionData = nodeData.Get(); + VerifyOrReturn(nodeData.Is()); + auto & commissionData = nodeData.Get(); auto discriminator = commissionData.longDiscriminator; auto vendorId = static_cast(commissionData.vendorId); @@ -64,7 +65,7 @@ void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData) ChipLogProgress(chipTool, "OnNodeDiscovered (MDNS): discriminator: %u, vendorId: %u, productId: %u", discriminator, vendorId, productId); - CommonResolutionData & resolutionData = commissionData; + const CommonResolutionData & resolutionData = commissionData; auto & instanceData = mDiscoveredResults[commissionData.instanceName]; auto & interfaceData = instanceData[resolutionData.interfaceId.GetPlatformInterface()]; From 8675480dfa234b923cf6a809ec06f7b8dde3dc6b Mon Sep 17 00:00:00 2001 From: Suhas Shankar Date: Wed, 24 Apr 2024 10:25:28 +0530 Subject: [PATCH 8/9] Updates as per feedback --- examples/chip-tool/commands/common/RemoteDataModelLogger.cpp | 2 +- examples/chip-tool/commands/pairing/PairingCommand.cpp | 2 +- src/controller/SetUpCodePairer.cpp | 2 +- src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm | 2 +- src/lib/dnssd/Types.h | 3 +-- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp index f036069fa48f33..9a996051957ccf 100644 --- a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp +++ b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp @@ -209,7 +209,7 @@ CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeDat VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR); auto & commissionData = nodeData; - auto & resolutionData = (chip::Dnssd::CommonResolutionData &) commissionData; + auto & resolutionData = commissionData; if (!chip::CanCastTo(resolutionData.numIPs)) { diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index c0a1e677ddb8d3..31da1329308c5b 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -484,7 +484,7 @@ void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & // Ignore nodes with closed commissioning window VerifyOrReturn(nodeData.commissioningMode != 0); - auto & resolutionData = (chip::Dnssd::CommonResolutionData &) nodeData; + auto & resolutionData = nodeData; const uint16_t port = resolutionData.port; char buf[chip::Inet::IPAddress::kMaxStringLength]; diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 3dcd95ca915264..c3aecbfdd36f66 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -387,7 +387,7 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover ChipLogProgress(Controller, "Discovered device to be commissioned over DNS-SD"); - NotifyCommissionableDeviceDiscovered((Dnssd::CommonResolutionData &) nodeData.Get()); + NotifyCommissionableDeviceDiscovered(nodeData.Get()); } void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::CommonResolutionData & resolutionData) diff --git a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm index 6cd70f05065516..2b3e2814ecd220 100644 --- a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm +++ b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm @@ -180,7 +180,7 @@ void OnNodeDiscovered(const DiscoveredNodeData & nodeData) override result.discriminator = @(commissionData.longDiscriminator); result.commissioningMode = commissionData.commissioningMode != 0; - auto & resolutionData = commissionData; + const CommonResolutionData & resolutionData = commissionData; auto * interfaces = result.interfaces; interfaces[@(resolutionData.interfaceId.GetPlatformInterface())].resolutionData = chip::MakeOptional(resolutionData); diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h index e1de1e429e154b..e62c9a52418efe 100644 --- a/src/lib/dnssd/Types.h +++ b/src/lib/dnssd/Types.h @@ -225,7 +225,6 @@ struct CommissionNodeData : public CommonResolutionData void Reset() { - CommonResolutionData::Reset(); // Let constructor clear things as default this->~CommissionNodeData(); new (this) CommissionNodeData(); @@ -235,7 +234,7 @@ struct CommissionNodeData : public CommonResolutionData void LogDetail() const { - ChipLogDetail(Discovery, "Discovered commissionable/commissioners node:"); + ChipLogDetail(Discovery, "Discovered commissionable/commissioner node:"); CommonResolutionData::LogDetail(); if (rotatingIdLen > 0) From 97d10cce1858905dee99dae7bdf038d5c0107c36 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 24 Apr 2024 12:56:05 +0000 Subject: [PATCH 9/9] Restyled by clang-format --- src/lib/dnssd/tests/TestTxtFields.cpp | 110 +++++++++++++------------- 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index e2540859fe965a..ce206e34ae46aa 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -303,12 +303,10 @@ TEST(TestTxtFields, TestGetCommissionerPasscode) bool NodeDataIsEmpty(const CommissionNodeData & node) { - if (node.longDiscriminator != 0 || node.vendorId != 0 || node.productId != 0 || - node.commissioningMode != 0 || node.deviceType != 0 || node.rotatingIdLen != 0 || - node.pairingHint != 0 || node.mrpRetryIntervalIdle.HasValue() || - node.mrpRetryIntervalActive.HasValue() || node.mrpRetryActiveThreshold.HasValue() || - node.isICDOperatingAsLIT.HasValue() || node.supportsTcp || - node.supportsCommissionerGeneratedPasscode != 0) + if (node.longDiscriminator != 0 || node.vendorId != 0 || node.productId != 0 || node.commissioningMode != 0 || + node.deviceType != 0 || node.rotatingIdLen != 0 || node.pairingHint != 0 || node.mrpRetryIntervalIdle.HasValue() || + node.mrpRetryIntervalActive.HasValue() || node.mrpRetryActiveThreshold.HasValue() || node.isICDOperatingAsLIT.HasValue() || + node.supportsTcp || node.supportsCommissionerGeneratedPasscode != 0) { return false; } @@ -461,55 +459,55 @@ void DiscoveredTxtFieldSessionIdleInterval() strcpy(key, "SII"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); - EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().Value() == 1_ms32); + EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalIdle().Value() == 1_ms32); // Maximum strcpy(key, "SII"); strcpy(val, "3600000"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); - EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalIdle().Value() == 3600000_ms32); + EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalIdle().Value() == 3600000_ms32); // Test no other fields were populated ResetRetryIntervalIdle(nodeData); - EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); // Invalid SII - negative value strcpy(key, "SII"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - greater than maximum strcpy(key, "SII"); strcpy(val, "3600001"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - much greater than maximum strcpy(key, "SII"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - hexadecimal value strcpy(key, "SII"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - leading zeros strcpy(key, "SII"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); // Invalid SII - text at the end strcpy(key, "SII"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); } // Test SAI (formerly CRA) @@ -526,55 +524,55 @@ void DiscoveredTxtFieldSessionActiveInterval() strcpy(key, "SAI"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().HasValue()); - EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().Value() == 1_ms32); + EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalActive().Value() == 1_ms32); // Maximum strcpy(key, "SAI"); strcpy(val, "3600000"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().HasValue()); - EXPECT_TRUE( nodeData.Get().GetMrpRetryIntervalActive().Value() == 3600000_ms32); + EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalActive().Value() == 3600000_ms32); // Test no other fields were populated ResetRetryIntervalActive(nodeData); - EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); // Invalid SAI - negative value strcpy(key, "SAI"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - greater than maximum strcpy(key, "SAI"); strcpy(val, "3600001"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - much greater than maximum strcpy(key, "SAI"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - hexadecimal value strcpy(key, "SAI"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - leading zeros strcpy(key, "SAI"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); // Invalid SAI - text at the end strcpy(key, "SAI"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); } // Test SAT (Session Active Threshold) @@ -591,55 +589,55 @@ void DiscoveredTxtFieldSessionActiveThreshold() strcpy(key, "SAT"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); - EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().Value() == 1_ms16); + EXPECT_TRUE(nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE(nodeData.Get().GetMrpRetryActiveThreshold().Value() == 1_ms16); // Maximum strcpy(key, "SAT"); strcpy(val, "65535"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); - EXPECT_TRUE( nodeData.Get().GetMrpRetryActiveThreshold().Value() == 65535_ms16); + EXPECT_TRUE(nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE(nodeData.Get().GetMrpRetryActiveThreshold().Value() == 65535_ms16); // Test no other fields were populated ResetRetryActiveThreshold(nodeData); - EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); // Invalid SAI - negative value strcpy(key, "SAT"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAI - greater than maximum strcpy(key, "SAT"); strcpy(val, "65536"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAT - much greater than maximum strcpy(key, "SAT"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAT - hexadecimal value strcpy(key, "SAT"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAT - leading zeros strcpy(key, "SAT"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); // Invalid SAT - text at the end strcpy(key, "SAT"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); } // Test T (TCP support) @@ -656,23 +654,23 @@ void DiscoveredTxtFieldTcpSupport() strcpy(key, "T"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().supportsTcp); + EXPECT_TRUE(nodeData.Get().supportsTcp); // Test no other fields were populated nodeData.Get().supportsTcp = false; - EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); // False strcpy(key, "T"); strcpy(val, "0"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().supportsTcp == false); + EXPECT_TRUE(nodeData.Get().supportsTcp == false); // Invalid value, stil false strcpy(key, "T"); strcpy(val, "asdf"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().supportsTcp == false); + EXPECT_TRUE(nodeData.Get().supportsTcp == false); } // Test ICD (ICD operation Mode) @@ -689,27 +687,27 @@ void DiscoveredTxtFieldICDoperatesAsLIT() strcpy(key, "ICD"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue()); - EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.Value()); + EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.HasValue()); + EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.Value()); // Test no other fields were populated nodeData.Get().isICDOperatingAsLIT.ClearValue(); - EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); // ICD is operating as a SIT device strcpy(key, "ICD"); strcpy(val, "0"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue()); - EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.Value() == false); + EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.HasValue()); + EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.Value() == false); nodeData.Get().isICDOperatingAsLIT.ClearValue(); - EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get())); + EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); // Invalid value, No key set strcpy(key, "ICD"); strcpy(val, "asdf"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().isICDOperatingAsLIT.HasValue() == false); + EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.HasValue() == false); } // Test IsDeviceTreatedAsSleepy() with CRI @@ -725,19 +723,19 @@ void DiscoveredTestIsDeviceSessionIdle() CommonResolutionData & resolutionData = nodeData.Get(); // No key/val set, so the device can't be sleepy - EXPECT_TRUE( !nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_TRUE(!nodeData.Get().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_LOCAL_IDLE_RETRY_INTERVAL.count())); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_TRUE(!nodeData.Get().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_LOCAL_IDLE_RETRY_INTERVAL.count() + 1)); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_TRUE(nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); } // Test IsDeviceTreatedAsSleepy() with CRA @@ -753,19 +751,19 @@ void DiscoveredTestIsDeviceSessionActive() CommonResolutionData & resolutionData = nodeData.Get(); // No key/val set, so the device can't be sleepy - EXPECT_TRUE( !nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_TRUE(!nodeData.Get().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_LOCAL_ACTIVE_RETRY_INTERVAL.count())); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( !nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_TRUE(!nodeData.Get().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_LOCAL_ACTIVE_RETRY_INTERVAL.count() + 1)); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE( nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_TRUE(nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); } // Test SAI (formally CRI)