From cc822edd905fc25c14658f9424f6e7a3a635dd23 Mon Sep 17 00:00:00 2001 From: Suhas Shankar <118879678+su-shanka@users.noreply.github.com> Date: Wed, 10 Apr 2024 10:52:29 +0530 Subject: [PATCH 1/3] Refactored mDNS Browse Interface (#32866) * Refactored mDNS Browse Interface and necessary renaming done * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../commands/common/DeviceScanner.cpp | 2 +- .../chip-tool/commands/common/DeviceScanner.h | 4 +- .../commands/common/RemoteDataModelLogger.cpp | 2 +- .../commands/pairing/PairingCommand.cpp | 2 +- .../linux/ControllerShellCommands.cpp | 4 +- .../app/src/main/jni/cpp/ConversionUtils.cpp | 31 ++++--- .../MatterTvCastingBridge/ConversionUtils.mm | 40 +++++----- .../core/CastingPlayerDiscovery.cpp | 10 +-- .../tv-casting-common/src/CastingServer.cpp | 10 +-- .../tv-casting-common/src/ConversionUtils.cpp | 11 ++- .../src/TargetVideoPlayerInfo.cpp | 2 +- .../AbstractDnssdDiscoveryController.h | 2 +- .../CHIPCommissionableNodeController.cpp | 4 +- src/controller/CHIPDeviceController.cpp | 2 +- src/controller/SetUpCodePairer.cpp | 13 ++- .../java/CHIPDeviceController-JNI.cpp | 22 ++--- ...issionableNodeController-ScriptBinding.cpp | 22 ++--- .../python/ChipDeviceController-Discovery.cpp | 46 +++++------ ...r-ScriptPairingDeviceDiscoveryDelegate.cpp | 2 +- .../TestCommissionableNodeController.cpp | 5 +- .../CHIP/MTRCommissionableBrowser.mm | 6 +- src/lib/dnssd/ActiveResolveAttempts.h | 12 +-- src/lib/dnssd/Discovery_ImplPlatform.cpp | 17 +++- src/lib/dnssd/Discovery_ImplPlatform.h | 5 +- src/lib/dnssd/IncrementalResolve.cpp | 14 ++-- src/lib/dnssd/IncrementalResolve.h | 8 +- src/lib/dnssd/Resolver.h | 28 ++----- src/lib/dnssd/ResolverProxy.cpp | 6 +- src/lib/dnssd/ResolverProxy.h | 4 +- src/lib/dnssd/Resolver_ImplMinimalMdns.cpp | 21 ++--- src/lib/dnssd/Resolver_ImplNone.cpp | 6 +- src/lib/dnssd/TxtFields.cpp | 2 +- src/lib/dnssd/TxtFields.h | 2 +- src/lib/dnssd/Types.h | 20 ++--- src/lib/dnssd/platform/Dnssd.h | 3 +- .../dnssd/tests/TestActiveResolveAttempts.cpp | 4 +- .../dnssd/tests/TestIncrementalResolve.cpp | 20 ++--- src/lib/dnssd/tests/TestTxtFields.cpp | 80 +++++++++---------- src/lib/shell/commands/Dns.cpp | 24 +++--- src/platform/Darwin/DnssdContexts.cpp | 4 +- src/platform/Darwin/DnssdImpl.cpp | 4 +- src/platform/Darwin/DnssdImpl.h | 4 +- .../UserDirectedCommissioningServer.cpp | 19 +++-- .../tests/TestUdcMessages.cpp | 14 ++-- 44 files changed, 276 insertions(+), 287 deletions(-) diff --git a/examples/chip-tool/commands/common/DeviceScanner.cpp b/examples/chip-tool/commands/common/DeviceScanner.cpp index 35d74bd06c844f..9d3dbca98f8db9 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.commissionData; + auto & commissionData = nodeData.nodeData; auto discriminator = commissionData.longDiscriminator; auto vendorId = static_cast(commissionData.vendorId); diff --git a/examples/chip-tool/commands/common/DeviceScanner.h b/examples/chip-tool/commands/common/DeviceScanner.h index bcdcf26c84feb1..89ff88e2b5a433 100644 --- a/examples/chip-tool/commands/common/DeviceScanner.h +++ b/examples/chip-tool/commands/common/DeviceScanner.h @@ -41,7 +41,7 @@ struct DeviceScannerResult chip::Optional mResolutionData; }; -class DeviceScanner : public chip::Dnssd::CommissioningResolveDelegate, +class DeviceScanner : public chip::Dnssd::DiscoverNodeDelegate, public chip::Dnssd::DnssdBrowseDelegate #if CONFIG_NETWORK_LAYER_BLE , @@ -55,7 +55,7 @@ class DeviceScanner : public chip::Dnssd::CommissioningResolveDelegate, CHIP_ERROR Get(uint16_t index, chip::Dnssd::CommonResolutionData & resolutionData); void Log() const; - /////////// CommissioningResolveDelegate Interface ///////// + /////////// DiscoverNodeDelegate Interface ///////// void OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData) override; /////////// DnssdBrowseDelegate Interface ///////// diff --git a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp index 37955e821e8b82..9e3026262db97d 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::DiscoveredNodeData & nodeDat VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR); auto & resolutionData = nodeData.resolutionData; - auto & commissionData = nodeData.commissionData; + auto & commissionData = nodeData.nodeData; if (!chip::CanCastTo(resolutionData.numIPs)) { diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index ed80bc007df796..48697098ae1cba 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -478,7 +478,7 @@ void PairingCommand::OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedA void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) { // Ignore nodes with closed commissioning window - VerifyOrReturn(nodeData.commissionData.commissioningMode != 0); + VerifyOrReturn(nodeData.nodeData.commissioningMode != 0); auto & resolutionData = nodeData.resolutionData; diff --git a/examples/platform/linux/ControllerShellCommands.cpp b/examples/platform/linux/ControllerShellCommands.cpp index 49b1e20dc97eb8..aefbb3fafa4353 100644 --- a/examples/platform/linux/ControllerShellCommands.cpp +++ b/examples/platform/linux/ControllerShellCommands.cpp @@ -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->commissionData.instanceName, next->resolutionData.hostName, - next->commissionData.longDiscriminator, next->commissionData.vendorId, next->commissionData.productId); + next->nodeData.instanceName, next->resolutionData.hostName, next->nodeData.longDiscriminator, + next->nodeData.vendorId, next->nodeData.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 2c3001cf5cabea..fd66ba44649cea 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,53 +324,50 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered jstring jInstanceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getInstanceNameField)); if (jInstanceName != nullptr) { - chip::Platform::CopyString(outCppDiscoveredNodeData.commissionData.instanceName, + chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, env->GetStringUTFChars(jInstanceName, 0)); } jfieldID jLongDiscriminatorField = env->GetFieldID(jDiscoveredNodeDataClass, "longDiscriminator", "J"); - outCppDiscoveredNodeData.commissionData.vendorId = + outCppDiscoveredNodeData.nodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jLongDiscriminatorField)); - jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J"); - outCppDiscoveredNodeData.commissionData.vendorId = - static_cast(env->GetLongField(jDiscoveredNodeData, jVendorIdField)); + jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J"); + outCppDiscoveredNodeData.nodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jVendorIdField)); - jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J"); - outCppDiscoveredNodeData.commissionData.productId = - static_cast(env->GetLongField(jDiscoveredNodeData, jProductIdField)); + jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J"); + outCppDiscoveredNodeData.nodeData.productId = static_cast(env->GetLongField(jDiscoveredNodeData, jProductIdField)); jfieldID jCommissioningModeField = env->GetFieldID(jDiscoveredNodeDataClass, "commissioningMode", "B"); - outCppDiscoveredNodeData.commissionData.commissioningMode = + outCppDiscoveredNodeData.nodeData.commissioningMode = static_cast(env->GetByteField(jDiscoveredNodeData, jCommissioningModeField)); - jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J"); - outCppDiscoveredNodeData.commissionData.deviceType = - static_cast(env->GetLongField(jDiscoveredNodeData, jDeviceTypeField)); + jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J"); + outCppDiscoveredNodeData.nodeData.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.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, + chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, env->GetStringUTFChars(jDeviceName, 0)); } // TODO: map rotating ID jfieldID jRotatingIdLenField = env->GetFieldID(jDiscoveredNodeDataClass, "rotatingIdLen", "I"); - outCppDiscoveredNodeData.commissionData.rotatingIdLen = + outCppDiscoveredNodeData.nodeData.rotatingIdLen = static_cast(env->GetIntField(jDiscoveredNodeData, jRotatingIdLenField)); jfieldID jPairingHintField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingHint", "S"); - outCppDiscoveredNodeData.commissionData.pairingHint = + outCppDiscoveredNodeData.nodeData.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.commissionData.pairingInstruction, - chip::Dnssd::kMaxPairingInstructionLen + 1, env->GetStringUTFChars(jPairingInstruction, 0)); + chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.pairingInstruction, chip::Dnssd::kMaxPairingInstructionLen + 1, + env->GetStringUTFChars(jPairingInstruction, 0)); } jfieldID jPortField = env->GetFieldID(jDiscoveredNodeDataClass, "port", "I"); diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm index a13f231b09b6c0..902e386ae551e1 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm @@ -48,20 +48,20 @@ + (CHIP_ERROR)convertToCppDiscoveredNodeDataFrom:(DiscoveredNodeData * _Nonnull) outDiscoveredNodeData:(chip::Dnssd::DiscoveredNodeData &)outDiscoveredNodeData { // setting CommissionNodeData - outDiscoveredNodeData.commissionData.deviceType = objCDiscoveredNodeData.deviceType; - outDiscoveredNodeData.commissionData.vendorId = objCDiscoveredNodeData.vendorId; - outDiscoveredNodeData.commissionData.productId = objCDiscoveredNodeData.productId; - outDiscoveredNodeData.commissionData.longDiscriminator = objCDiscoveredNodeData.longDiscriminator; - outDiscoveredNodeData.commissionData.commissioningMode = objCDiscoveredNodeData.commissioningMode; - outDiscoveredNodeData.commissionData.pairingHint = objCDiscoveredNodeData.pairingHint; - memset(outDiscoveredNodeData.commissionData.deviceName, '\0', sizeof(outDiscoveredNodeData.commissionData.deviceName)); + 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)); if (objCDiscoveredNodeData.deviceName != nullptr) { - chip::Platform::CopyString(outDiscoveredNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, + chip::Platform::CopyString(outDiscoveredNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, [objCDiscoveredNodeData.deviceName UTF8String]); } - outDiscoveredNodeData.commissionData.rotatingIdLen = objCDiscoveredNodeData.rotatingIdLen; + outDiscoveredNodeData.nodeData.rotatingIdLen = objCDiscoveredNodeData.rotatingIdLen; memcpy( - outDiscoveredNodeData.commissionData.rotatingId, objCDiscoveredNodeData.rotatingId, objCDiscoveredNodeData.rotatingIdLen); + outDiscoveredNodeData.nodeData.rotatingId, objCDiscoveredNodeData.rotatingId, objCDiscoveredNodeData.rotatingIdLen); // setting CommonResolutionData outDiscoveredNodeData.resolutionData.port = objCDiscoveredNodeData.port; @@ -121,17 +121,17 @@ + (DiscoveredNodeData *)convertToObjCDiscoveredNodeDataFrom:(const chip::Dnssd:: DiscoveredNodeData * objCDiscoveredNodeData = [DiscoveredNodeData new]; // from CommissionNodeData - objCDiscoveredNodeData.deviceType = cppDiscoveredNodedata->commissionData.deviceType; - objCDiscoveredNodeData.vendorId = cppDiscoveredNodedata->commissionData.vendorId; - objCDiscoveredNodeData.productId = cppDiscoveredNodedata->commissionData.productId; - objCDiscoveredNodeData.longDiscriminator = cppDiscoveredNodedata->commissionData.longDiscriminator; - objCDiscoveredNodeData.commissioningMode = cppDiscoveredNodedata->commissionData.commissioningMode; - objCDiscoveredNodeData.pairingHint = cppDiscoveredNodedata->commissionData.pairingHint; - objCDiscoveredNodeData.deviceName = [NSString stringWithCString:cppDiscoveredNodedata->commissionData.deviceName + 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 encoding:NSUTF8StringEncoding]; - objCDiscoveredNodeData.rotatingIdLen = cppDiscoveredNodedata->commissionData.rotatingIdLen; - objCDiscoveredNodeData.rotatingId = cppDiscoveredNodedata->commissionData.rotatingId; - objCDiscoveredNodeData.instanceName = [NSString stringWithCString:cppDiscoveredNodedata->commissionData.instanceName + objCDiscoveredNodeData.rotatingIdLen = cppDiscoveredNodedata->nodeData.rotatingIdLen; + objCDiscoveredNodeData.rotatingId = cppDiscoveredNodedata->nodeData.rotatingId; + objCDiscoveredNodeData.instanceName = [NSString stringWithCString:cppDiscoveredNodedata->nodeData.instanceName encoding:NSUTF8StringEncoding]; // from CommonResolutionData 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 402febdb9f6b97..9b26a868efd8c1 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp @@ -83,10 +83,10 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover CastingPlayerAttributes attributes; snprintf(attributes.id, kIdMaxLength + 1, "%s%u", nodeData.resolutionData.hostName, nodeData.resolutionData.port); - chip::Platform::CopyString(attributes.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, nodeData.commissionData.deviceName); + 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.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, - nodeData.commissionData.instanceName); + nodeData.nodeData.instanceName); attributes.numIPs = (unsigned int) nodeData.resolutionData.numIPs; for (unsigned j = 0; j < attributes.numIPs; j++) @@ -95,9 +95,9 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover } attributes.interfaceId = nodeData.resolutionData.interfaceId; attributes.port = nodeData.resolutionData.port; - attributes.productId = nodeData.commissionData.productId; - attributes.vendorId = nodeData.commissionData.vendorId; - attributes.deviceType = nodeData.commissionData.deviceType; + attributes.productId = nodeData.nodeData.productId; + attributes.vendorId = nodeData.nodeData.vendorId; + attributes.deviceType = nodeData.nodeData.deviceType; memory::Strong player = std::make_shared(attributes); 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 4cb72732292a2e..b98647db802050 100644 --- a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp @@ -226,20 +226,20 @@ CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(Dnssd::Discovered getIpAddressForUDCRequest(selectedCommissioner->resolutionData.ipAddress, selectedCommissioner->resolutionData.numIPs); ReturnErrorOnFailure(SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP( *ipAddressToUse, selectedCommissioner->resolutionData.port, selectedCommissioner->resolutionData.interfaceId))); - mTargetVideoPlayerVendorId = selectedCommissioner->commissionData.vendorId; - mTargetVideoPlayerProductId = selectedCommissioner->commissionData.productId; - mTargetVideoPlayerDeviceType = selectedCommissioner->commissionData.deviceType; + mTargetVideoPlayerVendorId = selectedCommissioner->nodeData.vendorId; + mTargetVideoPlayerProductId = selectedCommissioner->nodeData.productId; + mTargetVideoPlayerDeviceType = selectedCommissioner->nodeData.deviceType; mTargetVideoPlayerNumIPs = selectedCommissioner->resolutionData.numIPs; for (size_t i = 0; i < mTargetVideoPlayerNumIPs && i < chip::Dnssd::CommonResolutionData::kMaxIPAddresses; i++) { mTargetVideoPlayerIpAddress[i] = selectedCommissioner->resolutionData.ipAddress[i]; } chip::Platform::CopyString(mTargetVideoPlayerDeviceName, chip::Dnssd::kMaxDeviceNameLen + 1, - selectedCommissioner->commissionData.deviceName); + selectedCommissioner->nodeData.deviceName); chip::Platform::CopyString(mTargetVideoPlayerHostName, chip::Dnssd::kHostNameMaxLength + 1, selectedCommissioner->resolutionData.hostName); chip::Platform::CopyString(mTargetVideoPlayerInstanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, - selectedCommissioner->commissionData.instanceName); + selectedCommissioner->nodeData.instanceName); mTargetVideoPlayerPort = selectedCommissioner->resolutionData.port; return CHIP_NO_ERROR; } 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 322e9d46bec8c4..a57e2548009ada 100644 --- a/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/ConversionUtils.cpp @@ -23,10 +23,10 @@ CHIP_ERROR ConvertToDiscoveredNodeData(TargetVideoPlayerInfo * inPlayer, chip::D if (inPlayer == nullptr) return CHIP_ERROR_INVALID_ARGUMENT; - outNodeData.commissionData.vendorId = inPlayer->GetVendorId(); - outNodeData.commissionData.productId = static_cast(inPlayer->GetProductId()); - outNodeData.commissionData.deviceType = inPlayer->GetDeviceType(); - outNodeData.resolutionData.numIPs = inPlayer->GetNumIPs(); + outNodeData.nodeData.vendorId = inPlayer->GetVendorId(); + outNodeData.nodeData.productId = static_cast(inPlayer->GetProductId()); + outNodeData.nodeData.deviceType = inPlayer->GetDeviceType(); + outNodeData.resolutionData.numIPs = inPlayer->GetNumIPs(); const chip::Inet::IPAddress * ipAddresses = inPlayer->GetIpAddresses(); if (ipAddresses != nullptr) @@ -37,8 +37,7 @@ CHIP_ERROR ConvertToDiscoveredNodeData(TargetVideoPlayerInfo * inPlayer, chip::D } } - chip::Platform::CopyString(outNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, - inPlayer->GetDeviceName()); + chip::Platform::CopyString(outNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, inPlayer->GetDeviceName()); chip::Platform::CopyString(outNodeData.resolutionData.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 7d9c7d51168eaf..c182856039975a 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::DiscoveredNodeData * dis return false; } - return IsSameAs(discoveredNodeData->resolutionData.hostName, discoveredNodeData->commissionData.deviceName, + return IsSameAs(discoveredNodeData->resolutionData.hostName, discoveredNodeData->nodeData.deviceName, discoveredNodeData->resolutionData.numIPs, discoveredNodeData->resolutionData.ipAddress); } diff --git a/src/controller/AbstractDnssdDiscoveryController.h b/src/controller/AbstractDnssdDiscoveryController.h index 6e50d7b40c89ca..c8c9053f878ff3 100644 --- a/src/controller/AbstractDnssdDiscoveryController.h +++ b/src/controller/AbstractDnssdDiscoveryController.h @@ -36,7 +36,7 @@ namespace Controller { * to maintain a list of DiscoveredNodes and providing the implementation * of the template GetDiscoveredNodes() function. */ -class DLL_EXPORT AbstractDnssdDiscoveryController : public Dnssd::CommissioningResolveDelegate +class DLL_EXPORT AbstractDnssdDiscoveryController : public Dnssd::DiscoverNodeDelegate { public: explicit AbstractDnssdDiscoveryController(Dnssd::Resolver * resolver = nullptr) : mDNSResolver(resolver) {} diff --git a/src/controller/CHIPCommissionableNodeController.cpp b/src/controller/CHIPCommissionableNodeController.cpp index d187cc1289a851..f116928b585d82 100644 --- a/src/controller/CHIPCommissionableNodeController.cpp +++ b/src/controller/CHIPCommissionableNodeController.cpp @@ -36,13 +36,13 @@ CHIP_ERROR CommissionableNodeController::DiscoverCommissioners(Dnssd::DiscoveryF mDNSResolver.Shutdown(); // reset if already inited ReturnErrorOnFailure(mDNSResolver.Init(DeviceLayer::UDPEndPointManager())); #endif - mDNSResolver.SetCommissioningDelegate(this); + mDNSResolver.SetDiscoveryDelegate(this); return mDNSResolver.DiscoverCommissioners(discoveryFilter); } CommissionableNodeController::~CommissionableNodeController() { - mDNSResolver.SetCommissioningDelegate(nullptr); + mDNSResolver.SetDiscoveryDelegate(nullptr); } const Dnssd::DiscoveredNodeData * CommissionableNodeController::GetDiscoveredCommissioner(int idx) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index af0a66ea834da3..a534d7d94c067d 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -108,7 +108,7 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params) VerifyOrReturnError(params.systemState->TransportMgr() != nullptr, CHIP_ERROR_INVALID_ARGUMENT); ReturnErrorOnFailure(mDNSResolver.Init(params.systemState->UDPEndPointManager())); - mDNSResolver.SetCommissioningDelegate(this); + mDNSResolver.SetDiscoveryDelegate(this); RegisterDeviceDiscoveryDelegate(params.deviceDiscoveryDelegate); VerifyOrReturnError(params.operationalCredentialsDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT); diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index db09d91fd74441..3a995a6e93579a 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -332,23 +332,22 @@ bool SetUpCodePairer::IdIsPresent(uint16_t vendorOrProductID) bool SetUpCodePairer::NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & nodeData) const { - if (nodeData.commissionData.commissioningMode == 0) + if (nodeData.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.commissionData.vendorId) && - mPayloadVendorID != nodeData.commissionData.vendorId) + if (IdIsPresent(mPayloadVendorID) && IdIsPresent(nodeData.nodeData.vendorId) && mPayloadVendorID != nodeData.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.commissionData.productId) && - mPayloadProductID != nodeData.commissionData.productId) + if (IdIsPresent(mPayloadProductID) && IdIsPresent(nodeData.nodeData.productId) && + mPayloadProductID != nodeData.nodeData.productId) { ChipLogProgress(Controller, "Discovered device does not match our product id."); return false; @@ -358,10 +357,10 @@ bool SetUpCodePairer::NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & switch (mCurrentFilter.type) { case Dnssd::DiscoveryFilterType::kShortDiscriminator: - discriminatorMatches = (((nodeData.commissionData.longDiscriminator >> 8) & 0x0F) == mCurrentFilter.code); + discriminatorMatches = (((nodeData.nodeData.longDiscriminator >> 8) & 0x0F) == mCurrentFilter.code); break; case Dnssd::DiscoveryFilterType::kLongDiscriminator: - discriminatorMatches = (nodeData.commissionData.longDiscriminator == mCurrentFilter.code); + discriminatorMatches = (nodeData.nodeData.longDiscriminator == mCurrentFilter.code); break; default: ChipLogError(Controller, "Unknown filter type; all matches will fail"); diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index ceb655b8c46af8..345ad5489f56e7 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1903,7 +1903,7 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl jobject discoveredObj = env->NewObject(discoveredDeviceCls, constructor); - env->SetLongField(discoveredObj, discrminatorID, data->commissionData.longDiscriminator); + env->SetLongField(discoveredObj, discrminatorID, data->nodeData.longDiscriminator); char ipAddress[100]; data->resolutionData.ipAddress[0].ToString(ipAddress, 100); @@ -1911,13 +1911,13 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl env->SetObjectField(discoveredObj, ipAddressID, jniipAdress); env->SetIntField(discoveredObj, portID, static_cast(data->resolutionData.port)); - env->SetLongField(discoveredObj, deviceTypeID, static_cast(data->commissionData.deviceType)); - env->SetIntField(discoveredObj, vendorIdID, static_cast(data->commissionData.vendorId)); - env->SetIntField(discoveredObj, productIdID, static_cast(data->commissionData.productId)); + 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)); jbyteArray jRotatingId; - CHIP_ERROR err = JniReferences::GetInstance().N2J_ByteArray( - env, data->commissionData.rotatingId, static_cast(data->commissionData.rotatingIdLen), jRotatingId); + CHIP_ERROR err = JniReferences::GetInstance().N2J_ByteArray(env, data->nodeData.rotatingId, + static_cast(data->nodeData.rotatingIdLen), jRotatingId); if (err != CHIP_NO_ERROR) { @@ -1925,12 +1925,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->commissionData.instanceName)); - env->SetObjectField(discoveredObj, deviceNameID, env->NewStringUTF(data->commissionData.deviceName)); - env->SetObjectField(discoveredObj, pairingInstructionID, env->NewStringUTF(data->commissionData.pairingInstruction)); + 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->CallVoidMethod(discoveredObj, setCommissioningModeID, static_cast(data->commissionData.commissioningMode)); - env->CallVoidMethod(discoveredObj, setPairingHintID, static_cast(data->commissionData.pairingHint)); + env->CallVoidMethod(discoveredObj, setCommissioningModeID, static_cast(data->nodeData.commissioningMode)); + env->CallVoidMethod(discoveredObj, setPairingHintID, static_cast(data->nodeData.pairingHint)); return discoveredObj; } diff --git a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp index c82dd13f0e452f..39d70e350ae4db 100644 --- a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp +++ b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp @@ -82,22 +82,22 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( continue; } char rotatingId[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->commissionData.rotatingId, dnsSdInfo->commissionData.rotatingIdLen, - rotatingId, sizeof(rotatingId)); + Encoding::BytesToUppercaseHexString(dnsSdInfo->nodeData.rotatingId, dnsSdInfo->nodeData.rotatingIdLen, rotatingId, + sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissioner %d", i); - ChipLogProgress(Discovery, "\tInstance name:\t\t%s", dnsSdInfo->commissionData.instanceName); + 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->commissionData.longDiscriminator); - ChipLogProgress(Discovery, "\tVendor ID:\t\t%u", dnsSdInfo->commissionData.vendorId); - ChipLogProgress(Discovery, "\tProduct ID:\t\t%u", dnsSdInfo->commissionData.productId); - ChipLogProgress(Discovery, "\tCommissioning Mode\t%u", dnsSdInfo->commissionData.commissioningMode); - ChipLogProgress(Discovery, "\tDevice Type\t\t%u", dnsSdInfo->commissionData.deviceType); - ChipLogProgress(Discovery, "\tDevice Name\t\t%s", dnsSdInfo->commissionData.deviceName); + 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, "\tRotating Id\t\t%s", rotatingId); - ChipLogProgress(Discovery, "\tPairing Instruction\t%s", dnsSdInfo->commissionData.pairingInstruction); - ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->commissionData.pairingHint); + 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, "\tMrp Interval idle\t%u", diff --git a/src/controller/python/ChipDeviceController-Discovery.cpp b/src/controller/python/ChipDeviceController-Discovery.cpp index 7b502140a36bb6..a8896628680a8f 100644 --- a/src/controller/python/ChipDeviceController-Discovery.cpp +++ b/src/controller/python/ChipDeviceController-Discovery.cpp @@ -110,21 +110,21 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De Json::Value jsonVal; char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->commissionData.rotatingId, dnsSdInfo->commissionData.rotatingIdLen, - rotatingId, sizeof(rotatingId)); + Encoding::BytesToUppercaseHexString(dnsSdInfo->nodeData.rotatingId, dnsSdInfo->nodeData.rotatingIdLen, rotatingId, + sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissionable Node %d", i); - jsonVal["instanceName"] = dnsSdInfo->commissionData.instanceName; + jsonVal["instanceName"] = dnsSdInfo->nodeData.instanceName; jsonVal["hostName"] = dnsSdInfo->resolutionData.hostName; jsonVal["port"] = dnsSdInfo->resolutionData.port; - jsonVal["longDiscriminator"] = dnsSdInfo->commissionData.longDiscriminator; - jsonVal["vendorId"] = dnsSdInfo->commissionData.vendorId; - jsonVal["productId"] = dnsSdInfo->commissionData.productId; - jsonVal["commissioningMode"] = dnsSdInfo->commissionData.commissioningMode; - jsonVal["deviceType"] = dnsSdInfo->commissionData.deviceType; - jsonVal["deviceName"] = dnsSdInfo->commissionData.deviceName; - jsonVal["pairingInstruction"] = dnsSdInfo->commissionData.pairingInstruction; - jsonVal["pairingHint"] = dnsSdInfo->commissionData.pairingHint; + 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["mrpRetryIntervalIdle"] = dnsSdInfo->resolutionData.GetMrpRetryIntervalIdle().Value().count(); @@ -152,7 +152,7 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De { jsonVal["isICDOperatingAsLIT"] = dnsSdInfo->resolutionData.isICDOperatingAsLIT.Value(); } - if (dnsSdInfo->commissionData.rotatingIdLen > 0) + if (dnsSdInfo->nodeData.rotatingIdLen > 0) { jsonVal["rotatingId"] = rotatingId; } @@ -174,22 +174,22 @@ void pychip_DeviceController_PrintDiscoveredDevices(Controller::DeviceCommission continue; } char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->commissionData.rotatingId, dnsSdInfo->commissionData.rotatingIdLen, - rotatingId, sizeof(rotatingId)); + Encoding::BytesToUppercaseHexString(dnsSdInfo->nodeData.rotatingId, dnsSdInfo->nodeData.rotatingIdLen, rotatingId, + sizeof(rotatingId)); ChipLogProgress(Discovery, "Commissionable Node %d", i); - ChipLogProgress(Discovery, "\tInstance name:\t\t%s", dnsSdInfo->commissionData.instanceName); + 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->commissionData.longDiscriminator); - ChipLogProgress(Discovery, "\tVendor ID:\t\t%u", dnsSdInfo->commissionData.vendorId); - ChipLogProgress(Discovery, "\tProduct ID:\t\t%u", dnsSdInfo->commissionData.productId); - ChipLogProgress(Discovery, "\tCommissioning Mode\t%u", dnsSdInfo->commissionData.commissioningMode); - ChipLogProgress(Discovery, "\tDevice Type\t\t%u", dnsSdInfo->commissionData.deviceType); - ChipLogProgress(Discovery, "\tDevice Name\t\t%s", dnsSdInfo->commissionData.deviceName); + 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, "\tRotating Id\t\t%s", rotatingId); - ChipLogProgress(Discovery, "\tPairing Instruction\t%s", dnsSdInfo->commissionData.pairingInstruction); - ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->commissionData.pairingHint); + 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, "\tMrp Interval idle\t%u", diff --git a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp index 850ec208ac3e4b..54e917a6292b01 100644 --- a/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp +++ b/src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp @@ -24,7 +24,7 @@ namespace Controller { void ScriptPairingDeviceDiscoveryDelegate::OnDiscoveredDevice(const Dnssd::DiscoveredNodeData & nodeData) { // Ignore nodes with closed comissioning window - VerifyOrReturn(nodeData.commissionData.commissioningMode != 0); + VerifyOrReturn(nodeData.nodeData.commissioningMode != 0); VerifyOrReturn(mActiveDeviceCommissioner != nullptr); const uint16_t port = nodeData.resolutionData.port; diff --git a/src/controller/tests/TestCommissionableNodeController.cpp b/src/controller/tests/TestCommissionableNodeController.cpp index c2aafe500c293d..760b62e97386b0 100644 --- a/src/controller/tests/TestCommissionableNodeController.cpp +++ b/src/controller/tests/TestCommissionableNodeController.cpp @@ -38,9 +38,10 @@ class MockResolver : public Resolver void SetOperationalDelegate(OperationalResolveDelegate * delegate) override {} CHIP_ERROR ResolveNodeId(const PeerId & peerId) override { return ResolveNodeIdStatus; } void NodeIdResolutionNoLongerNeeded(const PeerId & peerId) override {} - CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext &) override { return DiscoverCommissionersStatus; } - CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext &) override + CHIP_ERROR StartDiscovery(DiscoveryType type, DiscoveryFilter filter, DiscoveryContext &) override { + if (DiscoveryType::kCommissionerNode == type) + return DiscoverCommissionersStatus; return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR StopDiscovery(DiscoveryContext &) override { return CHIP_ERROR_NOT_IMPLEMENTED; } diff --git a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm index 4e7b253fff5831..d867aa2c4b8b68 100644 --- a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm +++ b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm @@ -49,7 +49,7 @@ @interface MTRCommissionableBrowserResult () @implementation MTRCommissionableBrowserResult @end -class CommissionableBrowserInternal : public CommissioningResolveDelegate, +class CommissionableBrowserInternal : public DiscoverNodeDelegate, public DnssdBrowseDelegate #if CONFIG_NETWORK_LAYER_BLE , @@ -144,12 +144,12 @@ void ClearDnssdDiscoveredDevices() mDiscoveredResults = discoveredResultsCopy; } - /////////// CommissioningResolveDelegate Interface ///////// + /////////// DiscoverNodeDelegate Interface ///////// void OnNodeDiscovered(const DiscoveredNodeData & nodeData) override { assertChipStackLockedByCurrentThread(); - auto & commissionData = nodeData.commissionData; + auto & commissionData = nodeData.nodeData; auto key = [NSString stringWithUTF8String:commissionData.instanceName]; if ([mDiscoveredResults objectForKey:key] == nil) { // It should not happens. diff --git a/src/lib/dnssd/ActiveResolveAttempts.h b/src/lib/dnssd/ActiveResolveAttempts.h index 15796abf85b20c..ba6d8cf7a54f6e 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.commissionData.longDiscriminator >> 8) & 0x0F); + return browse.filter.code == static_cast((data.nodeData.longDiscriminator >> 8) & 0x0F); case chip::Dnssd::DiscoveryFilterType::kLongDiscriminator: - return browse.filter.code == data.commissionData.longDiscriminator; + return browse.filter.code == data.nodeData.longDiscriminator; case chip::Dnssd::DiscoveryFilterType::kVendorId: - return browse.filter.code == data.commissionData.vendorId; + return browse.filter.code == data.nodeData.vendorId; case chip::Dnssd::DiscoveryFilterType::kDeviceType: - return browse.filter.code == data.commissionData.deviceType; + return browse.filter.code == data.nodeData.deviceType; case chip::Dnssd::DiscoveryFilterType::kCommissioningMode: - return browse.filter.code == data.commissionData.commissioningMode; + return browse.filter.code == data.nodeData.commissioningMode; case chip::Dnssd::DiscoveryFilterType::kInstanceName: - return strncmp(browse.filter.instanceName, data.commissionData.instanceName, + return strncmp(browse.filter.instanceName, data.nodeData.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 3369f8c00b3b3b..065220a3996f08 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -340,7 +340,7 @@ void DiscoveryImplPlatform::HandleNodeIdResolve(void * context, DnssdService * r void DnssdService::ToDiscoveredNodeData(const Span & addresses, DiscoveredNodeData & nodeData) { auto & resolutionData = nodeData.resolutionData; - auto & commissionData = nodeData.commissionData; + auto & commissionData = nodeData.nodeData; Platform::CopyString(resolutionData.hostName, mHostName); Platform::CopyString(commissionData.instanceName, mName); @@ -743,6 +743,21 @@ CHIP_ERROR DiscoveryImplPlatform::DiscoverCommissioners(DiscoveryFilter filter, return error; } +CHIP_ERROR DiscoveryImplPlatform::StartDiscovery(DiscoveryType type, DiscoveryFilter filter, DiscoveryContext & context) +{ + switch (type) + { + case DiscoveryType::kCommissionableNode: + return DiscoverCommissionableNodes(filter, context); + case DiscoveryType::kCommissionerNode: + return DiscoverCommissioners(filter, context); + case DiscoveryType::kOperational: + return CHIP_ERROR_NOT_IMPLEMENTED; + default: + return CHIP_ERROR_INVALID_ARGUMENT; + } +} + CHIP_ERROR DiscoveryImplPlatform::StopDiscovery(DiscoveryContext & context) { if (!context.GetBrowseIdentifier().HasValue()) diff --git a/src/lib/dnssd/Discovery_ImplPlatform.h b/src/lib/dnssd/Discovery_ImplPlatform.h index a3f79796ca535c..c6ba929801ba7b 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.h +++ b/src/lib/dnssd/Discovery_ImplPlatform.h @@ -53,8 +53,9 @@ class DiscoveryImplPlatform : public ServiceAdvertiser, public Resolver void SetOperationalDelegate(OperationalResolveDelegate * delegate) override { mOperationalDelegate = delegate; } CHIP_ERROR ResolveNodeId(const PeerId & peerId) override; void NodeIdResolutionNoLongerNeeded(const PeerId & peerId) override; - CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext & context) override; - CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext & context) override; + CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext & context); + CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext & context); + CHIP_ERROR StartDiscovery(DiscoveryType type, DiscoveryFilter filter, DiscoveryContext & context) override; CHIP_ERROR StopDiscovery(DiscoveryContext & context) override; CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) override; diff --git a/src/lib/dnssd/IncrementalResolve.cpp b/src/lib/dnssd/IncrementalResolve.cpp index c36efbde177a6d..766d979e33a4ba 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; @@ -304,9 +304,9 @@ CHIP_ERROR IncrementalResolver::OnTxtRecord(const ResourceData & data, BytesRang } } - if (IsActiveCommissionParse()) + if (IsActiveBrowseParse()) { - TxtParser delegate(mSpecificResolutionData.Get()); + TxtParser delegate(mSpecificResolutionData.Get()); if (!ParseTxtRecord(data.GetData(), &delegate)) { return CHIP_ERROR_INVALID_ARGUMENT; @@ -343,12 +343,12 @@ CHIP_ERROR IncrementalResolver::OnIpAddress(Inet::InterfaceId interface, const I CHIP_ERROR IncrementalResolver::Take(DiscoveredNodeData & outputData) { - VerifyOrReturnError(IsActiveCommissionParse(), CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(IsActiveBrowseParse(), CHIP_ERROR_INCORRECT_STATE); IPAddressSorter::Sort(mCommonResolutionData.ipAddress, mCommonResolutionData.numIPs, mCommonResolutionData.interfaceId); outputData.resolutionData = mCommonResolutionData; - outputData.commissionData = mSpecificResolutionData.Get(); + outputData.nodeData = mSpecificResolutionData.Get(); ResetToInactive(); diff --git a/src/lib/dnssd/IncrementalResolve.h b/src/lib/dnssd/IncrementalResolve.h index b28b3cb897b5f3..9d2386472d7eba 100644 --- a/src/lib/dnssd/IncrementalResolve.h +++ b/src/lib/dnssd/IncrementalResolve.h @@ -99,7 +99,7 @@ class IncrementalResolver /// method. bool IsActive() const { return mSpecificResolutionData.Valid(); } - bool IsActiveCommissionParse() const { return mSpecificResolutionData.Is(); } + bool IsActiveBrowseParse() const { return mSpecificResolutionData.Is(); } bool IsActiveOperationalParse() const { return mSpecificResolutionData.Is(); } ServiceNameType GetCurrentType() const { return mServiceNameType; } @@ -143,7 +143,7 @@ class IncrementalResolver /// Take the current value of the object and clear it once returned. /// - /// Object must be in `IsActiveCommissionParse()` for this to succeed. + /// Object must be in `IsActiveBrowseParse()` for this to succeed. /// Data will be returned (and cleared) even if not yet complete based /// on `GetMissingRequiredInformation()`. This method takes as much data as /// it was parsed so far. @@ -170,7 +170,7 @@ class IncrementalResolver /// Input data MUST have GetType() == QType::TXT CHIP_ERROR OnTxtRecord(const mdns::Minimal::ResourceData & data, mdns::Minimal::BytesRange packetRange); - /// Notify that a new IP addres has been found. + /// Notify that a new IP address has been found. /// /// This is to be called on both A (if IPv4 support is enabled) and AAAA /// addresses. @@ -178,7 +178,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.h b/src/lib/dnssd/Resolver.h index d2541205bafd6d..388138e50fe14d 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -78,12 +78,12 @@ class DiscoveryContext : public ReferenceCounted void ClearBrowseIdentifier() { mBrowseIdentifier.ClearValue(); } const Optional & GetBrowseIdentifier() const { return mBrowseIdentifier; } - void SetCommissioningDelegate(CommissioningResolveDelegate * delegate) { mCommissioningDelegate = delegate; } + void SetDiscoveryDelegate(DiscoverNodeDelegate * delegate) { mDelegate = delegate; } void OnNodeDiscovered(const DiscoveredNodeData & nodeData) { - if (mCommissioningDelegate != nullptr) + if (mDelegate != nullptr) { - mCommissioningDelegate->OnNodeDiscovered(nodeData); + mDelegate->OnNodeDiscovered(nodeData); } else { @@ -92,7 +92,7 @@ class DiscoveryContext : public ReferenceCounted } private: - CommissioningResolveDelegate * mCommissioningDelegate = nullptr; + DiscoverNodeDelegate * mDelegate = nullptr; Optional mBrowseIdentifier; }; @@ -168,31 +168,19 @@ class Resolver virtual void NodeIdResolutionNoLongerNeeded(const PeerId & peerId) = 0; /** - * Finds all commissionable nodes matching the given filter. + * Finds all nodes of given type matching the given filter. * * Whenever a new matching node is found, the node information is passed to - * the `OnNodeDiscovered` method of the commissioning delegate configured + * the `OnNodeDiscovered` method of the discovery delegate configured * in the context object. * * This method is expected to increase the reference count of the context * object for as long as it takes to complete the discovery request. */ - virtual CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext & context) = 0; + virtual CHIP_ERROR StartDiscovery(DiscoveryType type, DiscoveryFilter filter, DiscoveryContext & context) = 0; /** - * Finds all commissioner nodes matching the given filter. - * - * Whenever a new matching node is found, the node information is passed to - * the `OnNodeDiscovered` method of the commissioning delegate configured - * in the context object. - * - * This method is expected to increase the reference count of the context - * object for as long as it takes to complete the discovery request. - */ - virtual CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext & context) = 0; - - /** - * Stop discovery (of commissionable or commissioner nodes). + * Stop discovery (of all node types). * * Some back ends may not support stopping discovery, so consumers should * not assume they will stop getting callbacks after calling this. diff --git a/src/lib/dnssd/ResolverProxy.cpp b/src/lib/dnssd/ResolverProxy.cpp index 3e7446ebbbdc6b..e43028ee54023d 100644 --- a/src/lib/dnssd/ResolverProxy.cpp +++ b/src/lib/dnssd/ResolverProxy.cpp @@ -36,7 +36,7 @@ CHIP_ERROR ResolverProxy::Init(Inet::EndPointManager * udpEnd void ResolverProxy::Shutdown() { VerifyOrReturn(mContext != nullptr); - mContext->SetCommissioningDelegate(nullptr); + mContext->SetDiscoveryDelegate(nullptr); mContext->Release(); mContext = nullptr; } @@ -45,14 +45,14 @@ CHIP_ERROR ResolverProxy::DiscoverCommissionableNodes(DiscoveryFilter filter) { VerifyOrReturnError(mContext != nullptr, CHIP_ERROR_INCORRECT_STATE); - return mResolver.DiscoverCommissionableNodes(filter, *mContext); + return mResolver.StartDiscovery(DiscoveryType::kCommissionableNode, filter, *mContext); } CHIP_ERROR ResolverProxy::DiscoverCommissioners(DiscoveryFilter filter) { VerifyOrReturnError(mContext != nullptr, CHIP_ERROR_INCORRECT_STATE); - return mResolver.DiscoverCommissioners(filter, *mContext); + return mResolver.StartDiscovery(DiscoveryType::kCommissionerNode, filter, *mContext); } CHIP_ERROR ResolverProxy::StopDiscovery() diff --git a/src/lib/dnssd/ResolverProxy.h b/src/lib/dnssd/ResolverProxy.h index 09a50e89c1a209..58617b0d0162d7 100644 --- a/src/lib/dnssd/ResolverProxy.h +++ b/src/lib/dnssd/ResolverProxy.h @@ -44,11 +44,11 @@ class ResolverProxy CHIP_ERROR Init(Inet::EndPointManager * udpEndPoint = nullptr); void Shutdown(); - void SetCommissioningDelegate(CommissioningResolveDelegate * delegate) + void SetDiscoveryDelegate(DiscoverNodeDelegate * delegate) { if (mContext != nullptr) { - mContext->SetCommissioningDelegate(delegate); + mContext->SetDiscoveryDelegate(delegate); } } diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index 64461965367b13..72e44603d916b8 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -285,8 +285,7 @@ class MinMdnsResolver : public Resolver, public MdnsPacketDelegate void SetOperationalDelegate(OperationalResolveDelegate * delegate) override { mOperationalDelegate = delegate; } CHIP_ERROR ResolveNodeId(const PeerId & peerId) override; void NodeIdResolutionNoLongerNeeded(const PeerId & peerId) override; - CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext & context) override; - CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext & context) override; + CHIP_ERROR StartDiscovery(DiscoveryType type, DiscoveryFilter filter, DiscoveryContext & context) override; CHIP_ERROR StopDiscovery(DiscoveryContext & context) override; CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) override; @@ -386,7 +385,7 @@ void MinMdnsResolver::AdvancePendingResolverStates() } // SUCCESS. Call the delegates - if (resolver->IsActiveCommissionParse()) + if (resolver->IsActiveBrowseParse()) { MATTER_TRACE_SCOPE("Active commissioning delegate call", "MinMdnsResolver"); DiscoveredNodeData nodeData; @@ -412,13 +411,15 @@ 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 commission data parsing"); + ChipLogError(Discovery, "Unexpected type for browse data parsing"); continue; } @@ -685,20 +686,12 @@ void MinMdnsResolver::ExpireIncrementalResolvers() } } -CHIP_ERROR MinMdnsResolver::DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext & context) +CHIP_ERROR MinMdnsResolver::StartDiscovery(DiscoveryType type, DiscoveryFilter filter, DiscoveryContext & context) { // minmdns currently supports only one discovery context at a time so override the previous context SetDiscoveryContext(&context); - return BrowseNodes(DiscoveryType::kCommissionableNode, filter); -} - -CHIP_ERROR MinMdnsResolver::DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext & context) -{ - // minmdns currently supports only one discovery context at a time so override the previous context - SetDiscoveryContext(&context); - - return BrowseNodes(DiscoveryType::kCommissionerNode, filter); + return BrowseNodes(type, filter); } CHIP_ERROR MinMdnsResolver::StopDiscovery(DiscoveryContext & context) diff --git a/src/lib/dnssd/Resolver_ImplNone.cpp b/src/lib/dnssd/Resolver_ImplNone.cpp index 9a1f40f3008dff..e1094d4d1e2780 100644 --- a/src/lib/dnssd/Resolver_ImplNone.cpp +++ b/src/lib/dnssd/Resolver_ImplNone.cpp @@ -40,11 +40,7 @@ class NoneResolver : public Resolver { ChipLogError(Discovery, "Failed to stop resolving node ID: dnssd resolving not available"); } - CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext & context) override - { - return CHIP_ERROR_NOT_IMPLEMENTED; - } - CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext & context) override + CHIP_ERROR StartDiscovery(DiscoveryType type, DiscoveryFilter filter, DiscoveryContext & context) override { return CHIP_ERROR_NOT_IMPLEMENTED; } diff --git a/src/lib/dnssd/TxtFields.cpp b/src/lib/dnssd/TxtFields.cpp index d43650748e53a2..b77d991784867d 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, CommissionNodeData & nodeData) +void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & val, DnssdNodeData & nodeData) { TxtFieldKey keyType = Internal::GetTxtFieldKey(key); switch (keyType) diff --git a/src/lib/dnssd/TxtFields.h b/src/lib/dnssd/TxtFields.h index 5546493624119d..194750451289a4 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, CommissionNodeData & nodeData); +void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & value, DnssdNodeData & nodeData); } // namespace Dnssd } // namespace chip diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h index a835ebf5647a97..be64f5de7c7dd4 100644 --- a/src/lib/dnssd/Types.h +++ b/src/lib/dnssd/Types.h @@ -205,7 +205,7 @@ inline constexpr size_t kMaxRotatingIdLen = 50; inline constexpr size_t kMaxPairingInstructionLen = 128; /// Data that is specific to commisionable/commissioning node discovery -struct CommissionNodeData +struct DnssdNodeData { size_t rotatingIdLen = 0; uint32_t deviceType = 0; @@ -220,13 +220,13 @@ struct CommissionNodeData char deviceName[kMaxDeviceNameLen + 1] = {}; char pairingInstruction[kMaxPairingInstructionLen + 1] = {}; - CommissionNodeData() {} + DnssdNodeData() {} void Reset() { // Let constructor clear things as default - this->~CommissionNodeData(); - new (this) CommissionNodeData(); + this->~DnssdNodeData(); + new (this) DnssdNodeData(); } bool IsInstanceName(const char * instance) const { return strcmp(instance, instanceName) == 0; } @@ -300,12 +300,14 @@ struct ResolvedNodeData struct DiscoveredNodeData { CommonResolutionData resolutionData; - CommissionNodeData commissionData; + DnssdNodeData nodeData; + DiscoveryType nodeType; void Reset() { resolutionData.Reset(); - commissionData.Reset(); + nodeData.Reset(); + nodeType = DiscoveryType::kUnknown; } DiscoveredNodeData() { Reset(); } @@ -313,7 +315,7 @@ struct DiscoveredNodeData { ChipLogDetail(Discovery, "Discovered node:"); resolutionData.LogDetail(); - commissionData.LogDetail(); + nodeData.LogDetail(); } }; @@ -321,10 +323,10 @@ struct DiscoveredNodeData /// - Commissioners /// - Nodes in commissioning modes over IP (e.g. ethernet devices, devices already /// connected to thread/wifi or devices with a commissioning window open) -class CommissioningResolveDelegate +class DiscoverNodeDelegate { public: - virtual ~CommissioningResolveDelegate() = default; + virtual ~DiscoverNodeDelegate() = default; /// Called within the CHIP event loop once a node is discovered. /// diff --git a/src/lib/dnssd/platform/Dnssd.h b/src/lib/dnssd/platform/Dnssd.h index 778e9bc05f1d9c..fcbeabe1ce8d51 100644 --- a/src/lib/dnssd/platform/Dnssd.h +++ b/src/lib/dnssd/platform/Dnssd.h @@ -288,8 +288,7 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId * @retval Error code The resolve fails. * */ -CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId interface, - CommissioningResolveDelegate * delegate); +CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId interface, DiscoverNodeDelegate * delegate); #endif // CHIP_DEVICE_LAYER_TARGET_DARWIN /** diff --git a/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp b/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp index 574268bb3c8e55..f4ef2f202c4def 100644 --- a/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp +++ b/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp @@ -126,7 +126,7 @@ void TestSingleBrowseAddRemove(nlTestSuite * inSuite, void * inContext) // once complete, nothing to schedule Dnssd::DiscoveredNodeData data; - data.commissionData.longDiscriminator = 1234; + data.nodeData.longDiscriminator = 1234; attempts.CompleteCommissionable(data); NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue()); NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue()); @@ -375,7 +375,7 @@ void TestCombination(nlTestSuite * inSuite, void * inContext) attempts.Complete(MakePeerId(2)); attempts.Complete(MakePeerId(1)); Dnssd::DiscoveredNodeData data; - data.commissionData.longDiscriminator = 1234; + data.nodeData.longDiscriminator = 1234; attempts.CompleteCommissionable(data); NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue()); diff --git a/src/lib/dnssd/tests/TestIncrementalResolve.cpp b/src/lib/dnssd/tests/TestIncrementalResolve.cpp index 1cc3b714d28ae3..03b585c4ce14c3 100644 --- a/src/lib/dnssd/tests/TestIncrementalResolve.cpp +++ b/src/lib/dnssd/tests/TestIncrementalResolve.cpp @@ -163,7 +163,7 @@ void TestCreation(nlTestSuite * inSuite, void * inContext) IncrementalResolver resolver; NL_TEST_ASSERT(inSuite, !resolver.IsActive()); - NL_TEST_ASSERT(inSuite, !resolver.IsActiveCommissionParse()); + NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse()); NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse()); NL_TEST_ASSERT( inSuite, @@ -183,7 +183,7 @@ void TestInactiveResetOnInitError(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestHostName.Serialized(), srvRecord) != CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, !resolver.IsActive()); - NL_TEST_ASSERT(inSuite, !resolver.IsActiveCommissionParse()); + NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse()); NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse()); } @@ -199,7 +199,7 @@ void TestStartOperational(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestOperationalName.Serialized(), srvRecord) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, resolver.IsActive()); - NL_TEST_ASSERT(inSuite, !resolver.IsActiveCommissionParse()); + NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse()); NL_TEST_ASSERT(inSuite, resolver.IsActiveOperationalParse()); NL_TEST_ASSERT(inSuite, resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)); @@ -218,7 +218,7 @@ void TestStartCommissionable(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionableNode.Serialized(), srvRecord) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, resolver.IsActive()); - NL_TEST_ASSERT(inSuite, resolver.IsActiveCommissionParse()); + NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse()); NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse()); NL_TEST_ASSERT(inSuite, resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)); @@ -237,7 +237,7 @@ void TestStartCommissioner(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionerNode.Serialized(), srvRecord) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, resolver.IsActive()); - NL_TEST_ASSERT(inSuite, resolver.IsActiveCommissionParse()); + NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse()); NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse()); NL_TEST_ASSERT(inSuite, resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)); @@ -336,7 +336,7 @@ void TestParseCommissionable(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionableNode.Serialized(), srvRecord) == CHIP_NO_ERROR); // once initialized, parsing should be ready however no IP address is available - NL_TEST_ASSERT(inSuite, resolver.IsActiveCommissionParse()); + NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse()); NL_TEST_ASSERT(inSuite, resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)); NL_TEST_ASSERT(inSuite, resolver.GetTargetHostName() == kTestHostName.Serialized()); @@ -414,10 +414,10 @@ void TestParseCommissionable(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, nodeData.resolutionData.ipAddress[1] == addr); // parsed txt data for discovered nodes - NL_TEST_ASSERT(inSuite, nodeData.commissionData.longDiscriminator == 22345); - NL_TEST_ASSERT(inSuite, nodeData.commissionData.vendorId == 321); - NL_TEST_ASSERT(inSuite, nodeData.commissionData.productId == 654); - NL_TEST_ASSERT(inSuite, strcmp(nodeData.commissionData.deviceName, "mytest") == 0); + NL_TEST_ASSERT(inSuite, nodeData.nodeData.longDiscriminator == 22345); + NL_TEST_ASSERT(inSuite, nodeData.nodeData.vendorId == 321); + NL_TEST_ASSERT(inSuite, nodeData.nodeData.productId == 654); + NL_TEST_ASSERT(inSuite, strcmp(nodeData.nodeData.deviceName, "mytest") == 0); } const nlTest sTests[] = { diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 95f13b5d60c091..4593a4903b1a01 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -304,20 +304,20 @@ void TestGetCommissionerPasscode(nlTestSuite * inSuite, void * inContext) bool NodeDataIsEmpty(const DiscoveredNodeData & node) { - if (node.commissionData.longDiscriminator != 0 || node.commissionData.vendorId != 0 || node.commissionData.productId != 0 || - node.commissionData.commissioningMode != 0 || node.commissionData.deviceType != 0 || - node.commissionData.rotatingIdLen != 0 || node.commissionData.pairingHint != 0 || - node.resolutionData.mrpRetryIntervalIdle.HasValue() || node.resolutionData.mrpRetryIntervalActive.HasValue() || - node.resolutionData.mrpRetryActiveThreshold.HasValue() || node.resolutionData.isICDOperatingAsLIT.HasValue() || - node.resolutionData.supportsTcp || node.commissionData.commissionerPasscode != 0) + 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.commissionerPasscode != 0) { return false; } - if (strcmp(node.commissionData.deviceName, "") != 0 || strcmp(node.commissionData.pairingInstruction, "") != 0) + if (strcmp(node.nodeData.deviceName, "") != 0 || strcmp(node.nodeData.pairingInstruction, "") != 0) { return false; } - for (uint8_t id : node.commissionData.rotatingId) + for (uint8_t id : node.nodeData.rotatingId) { if (id != 0) { @@ -337,78 +337,78 @@ void TestFillDiscoveredNodeDataFromTxt(nlTestSuite * inSuite, void * inContext) // Long discriminator strcpy(key, "D"); strcpy(val, "840"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, filled.commissionData.longDiscriminator == 840); - filled.commissionData.longDiscriminator = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, filled.nodeData.longDiscriminator == 840); + filled.nodeData.longDiscriminator = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // vendor and product strcpy(key, "VP"); strcpy(val, "123+456"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, filled.commissionData.vendorId == 123); - NL_TEST_ASSERT(inSuite, filled.commissionData.productId == 456); - filled.commissionData.vendorId = 0; - filled.commissionData.productId = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, filled.nodeData.vendorId == 123); + NL_TEST_ASSERT(inSuite, filled.nodeData.productId == 456); + filled.nodeData.vendorId = 0; + filled.nodeData.productId = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Commissioning mode strcpy(key, "CM"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, filled.commissionData.commissioningMode == 1); - filled.commissionData.commissioningMode = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, filled.nodeData.commissioningMode == 1); + filled.nodeData.commissioningMode = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Commissioning mode strcpy(key, "CP"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, filled.commissionData.commissionerPasscode == 1); - filled.commissionData.commissionerPasscode = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, filled.nodeData.commissionerPasscode == 1); + filled.nodeData.commissionerPasscode = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Device type strcpy(key, "DT"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, filled.commissionData.deviceType == 1); - filled.commissionData.deviceType = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, filled.nodeData.deviceType == 1); + filled.nodeData.deviceType = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Device name strcpy(key, "DN"); strcpy(val, "abc"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, strcmp(filled.commissionData.deviceName, "abc") == 0); - memset(filled.commissionData.deviceName, 0, sizeof(filled.commissionData.deviceName)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, strcmp(filled.nodeData.deviceName, "abc") == 0); + memset(filled.nodeData.deviceName, 0, sizeof(filled.nodeData.deviceName)); NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Rotating device id strcpy(key, "RI"); strcpy(val, "1A2B"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, filled.commissionData.rotatingId[0] == 0x1A); - NL_TEST_ASSERT(inSuite, filled.commissionData.rotatingId[1] == 0x2B); - NL_TEST_ASSERT(inSuite, filled.commissionData.rotatingIdLen == 2); - filled.commissionData.rotatingIdLen = 0; - memset(filled.commissionData.rotatingId, 0, sizeof(filled.commissionData.rotatingId)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingId[0] == 0x1A); + NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingId[1] == 0x2B); + NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingIdLen == 2); + filled.nodeData.rotatingIdLen = 0; + memset(filled.nodeData.rotatingId, 0, sizeof(filled.nodeData.rotatingId)); NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Pairing instruction strcpy(key, "PI"); strcpy(val, "hint"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, strcmp(filled.commissionData.pairingInstruction, "hint") == 0); - memset(filled.commissionData.pairingInstruction, 0, sizeof(filled.commissionData.pairingInstruction)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, strcmp(filled.nodeData.pairingInstruction, "hint") == 0); + memset(filled.nodeData.pairingInstruction, 0, sizeof(filled.nodeData.pairingInstruction)); NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Pairing hint strcpy(key, "PH"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.commissionData); - NL_TEST_ASSERT(inSuite, filled.commissionData.pairingHint == 1); - filled.commissionData.pairingHint = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); + NL_TEST_ASSERT(inSuite, filled.nodeData.pairingHint == 1); + filled.nodeData.pairingHint = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); } diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 6abb2dc0393fec..14955335daaad0 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -40,7 +40,7 @@ Shell::Engine sShellDnsBrowseSubcommands; Shell::Engine sShellDnsSubcommands; Dnssd::ResolverProxy sResolverProxy; -class DnsShellResolverDelegate : public Dnssd::CommissioningResolveDelegate, public AddressResolve::NodeListener +class DnsShellResolverDelegate : public Dnssd::DiscoverNodeDelegate, public AddressResolve::NodeListener { public: DnsShellResolverDelegate() { mSelfHandle.SetListener(this); } @@ -92,20 +92,20 @@ class DnsShellResolverDelegate : public Dnssd::CommissioningResolveDelegate, pub } char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1]; - Encoding::BytesToUppercaseHexString(nodeData.commissionData.rotatingId, nodeData.commissionData.rotatingIdLen, rotatingId, + Encoding::BytesToUppercaseHexString(nodeData.nodeData.rotatingId, nodeData.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.commissionData.vendorId); - streamer_printf(streamer_get(), " Product ID: %u\r\n", nodeData.commissionData.productId); - streamer_printf(streamer_get(), " Long discriminator: %u\r\n", nodeData.commissionData.longDiscriminator); - streamer_printf(streamer_get(), " Device type: %u\r\n", nodeData.commissionData.deviceType); - streamer_printf(streamer_get(), " Device name: %s\n", nodeData.commissionData.deviceName); - streamer_printf(streamer_get(), " Commissioning mode: %d\r\n", - static_cast(nodeData.commissionData.commissioningMode)); - streamer_printf(streamer_get(), " Pairing hint: %u\r\n", nodeData.commissionData.pairingHint); - streamer_printf(streamer_get(), " Pairing instruction: %s\r\n", nodeData.commissionData.pairingInstruction); + 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(), " Rotating ID %s\r\n", rotatingId); auto retryInterval = nodeData.resolutionData.GetMrpRetryIntervalIdle(); @@ -237,7 +237,7 @@ CHIP_ERROR BrowseHandler(int argc, char ** argv) } sResolverProxy.Init(DeviceLayer::UDPEndPointManager()); - sResolverProxy.SetCommissioningDelegate(&sDnsShellResolverDelegate); + sResolverProxy.SetDiscoveryDelegate(&sDnsShellResolverDelegate); return sShellDnsBrowseSubcommands.ExecCommand(argc, argv); } diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index f1335641d67dbf..fd7e395f74d2b7 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -476,7 +476,7 @@ ResolveContext::ResolveContext(void * cbContext, DnssdResolveCallback cb, chip:: consumerCounter = std::move(consumerCounterToUse); } -ResolveContext::ResolveContext(CommissioningResolveDelegate * delegate, chip::Inet::IPAddressType cbAddressType, +ResolveContext::ResolveContext(DiscoverNodeDelegate * delegate, chip::Inet::IPAddressType cbAddressType, const char * instanceNameToResolve, std::shared_ptr && consumerCounterToUse) : browseThatCausedResolve(nullptr) { @@ -583,7 +583,7 @@ bool ResolveContext::TryReportingResultsForInterfaceIndex(uint32_t interfaceInde auto addresses = Span(ips.data(), ips.size()); if (nullptr == callback) { - auto delegate = static_cast(context); + auto delegate = static_cast(context); DiscoveredNodeData nodeData; service.ToDiscoveredNodeData(addresses, nodeData); delegate->OnNodeDiscovered(nodeData); diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index 7e9e7af521686d..d514bf58b04416 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -299,7 +299,7 @@ static CHIP_ERROR Resolve(void * context, DnssdResolveCallback callback, uint32_ return Resolve(sdCtx, interfaceId, addressType, type, name); } -static CHIP_ERROR Resolve(CommissioningResolveDelegate * delegate, uint32_t interfaceId, chip::Inet::IPAddressType addressType, +static CHIP_ERROR Resolve(DiscoverNodeDelegate * delegate, uint32_t interfaceId, chip::Inet::IPAddressType addressType, const char * type, const char * name) { auto counterHolder = GetCounterHolder(name); @@ -447,7 +447,7 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId inte return Resolve(context, callback, interfaceId, service->mAddressType, regtype.c_str(), service->mName); } -CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId interface, CommissioningResolveDelegate * delegate) +CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId interface, DiscoverNodeDelegate * delegate) { VerifyOrReturnError(service != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(IsSupportedProtocol(service->mProtocol), CHIP_ERROR_INVALID_ARGUMENT); diff --git a/src/platform/Darwin/DnssdImpl.h b/src/platform/Darwin/DnssdImpl.h index 18f1d93baaab27..5932125312c576 100644 --- a/src/platform/Darwin/DnssdImpl.h +++ b/src/platform/Darwin/DnssdImpl.h @@ -237,8 +237,8 @@ struct ResolveContext : public GenericContext ResolveContext(void * cbContext, DnssdResolveCallback cb, chip::Inet::IPAddressType cbAddressType, const char * instanceNameToResolve, BrowseContext * browseCausingResolve, std::shared_ptr && consumerCounterToUse); - ResolveContext(CommissioningResolveDelegate * delegate, chip::Inet::IPAddressType cbAddressType, - const char * instanceNameToResolve, std::shared_ptr && consumerCounterToUse); + ResolveContext(DiscoverNodeDelegate * delegate, chip::Inet::IPAddressType cbAddressType, const char * instanceNameToResolve, + std::shared_ptr && consumerCounterToUse); virtual ~ResolveContext(); void DispatchFailure(const char * errorStr, CHIP_ERROR err) override; diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp index 9e787124507536..f63a10c94965f5 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp @@ -405,17 +405,16 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis if (nodeData.resolutionData.numIPs == 0) { ChipLogError(AppServer, "OnCommissionableNodeFound no IP addresses returned for instance name=%s", - nodeData.commissionData.instanceName); + nodeData.nodeData.instanceName); return; } if (nodeData.resolutionData.port == 0) { - ChipLogError(AppServer, "OnCommissionableNodeFound no port returned for instance name=%s", - nodeData.commissionData.instanceName); + ChipLogError(AppServer, "OnCommissionableNodeFound no port returned for instance name=%s", nodeData.nodeData.instanceName); return; } - UDCClientState * client = mUdcClients.FindUDCClientState(nodeData.commissionData.instanceName); + UDCClientState * client = mUdcClients.FindUDCClientState(nodeData.nodeData.instanceName); if (client != nullptr && client->GetUDCClientProcessingState() == UDCClientProcessingState::kDiscoveringNode) { ChipLogDetail(AppServer, "OnCommissionableNodeFound instance: name=%s old_state=%d new_state=%d", client->GetInstanceName(), @@ -458,17 +457,17 @@ void UserDirectedCommissioningServer::OnCommissionableNodeFound(const Dnssd::Dis if (!foundV6) { ChipLogError(AppServer, "OnCommissionableNodeFound no v6 returned for instance name=%s", - nodeData.commissionData.instanceName); + nodeData.nodeData.instanceName); client->SetPeerAddress( chip::Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], nodeData.resolutionData.port)); } #endif // INET_CONFIG_ENABLE_IPV4 - client->SetDeviceName(nodeData.commissionData.deviceName); - client->SetLongDiscriminator(nodeData.commissionData.longDiscriminator); - client->SetVendorId(nodeData.commissionData.vendorId); - client->SetProductId(nodeData.commissionData.productId); - client->SetRotatingId(nodeData.commissionData.rotatingId, nodeData.commissionData.rotatingIdLen); + 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); // 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 f7e7c2ab4a65d9..9c171b5efad5b8 100644 --- a/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp +++ b/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp @@ -86,15 +86,15 @@ void TestUDCServerUserConfirmationProvider(nlTestSuite * inSuite, void * inConte nodeData1.resolutionData.port = 5540; nodeData1.resolutionData.ipAddress[0] = address; nodeData1.resolutionData.numIPs = 1; - Platform::CopyString(nodeData1.commissionData.instanceName, instanceName1); + Platform::CopyString(nodeData1.nodeData.instanceName, instanceName1); Dnssd::DiscoveredNodeData nodeData2; - nodeData2.resolutionData.port = 5540; - nodeData2.resolutionData.ipAddress[0] = address; - nodeData2.resolutionData.numIPs = 1; - nodeData2.commissionData.longDiscriminator = disc2; - Platform::CopyString(nodeData2.commissionData.instanceName, instanceName2); - Platform::CopyString(nodeData2.commissionData.deviceName, deviceName2); + 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); // test empty UserConfirmationProvider udcServer.OnCommissionableNodeFound(nodeData2); From c0b635a74edf41dd8dbb06b8573283d47b1ed343 Mon Sep 17 00:00:00 2001 From: Suhas Shankar <118879678+su-shanka@users.noreply.github.com> Date: Thu, 25 Apr 2024 18:48:49 +0530 Subject: [PATCH 2/3] [Dnssd] Refactored DiscoveredNodeData definition and usage (#33025) * Refactored DiscoveredNodeData definition and usage * Restyled by whitespace * Restyled by clang-format * updates based on review feedback * Restyled by whitespace * Restyled by clang-format * fix for build failure * Updates as per feedback * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../commands/common/DeviceScanner.cpp | 7 +- .../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 | 5 +- .../app/src/main/jni/cpp/ConversionUtils.cpp | 55 ++- .../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 | 25 +- .../core/CastingPlayerDiscovery.h | 2 +- .../tv-casting-common/include/CastingServer.h | 4 +- .../include/TargetVideoPlayerInfo.h | 2 +- .../tv-casting-common/src/CastingServer.cpp | 32 +- .../tv-casting-common/src/ConversionUtils.cpp | 21 +- .../src/TargetVideoPlayerInfo.cpp | 6 +- .../AbstractDnssdDiscoveryController.cpp | 21 +- .../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 | 21 +- .../java/CHIPDeviceController-JNI.cpp | 28 +- ...issionableNodeController-ScriptBinding.cpp | 48 +- .../python/ChipDeviceController-Discovery.cpp | 105 ++--- ...r-ScriptPairingDeviceDiscoveryDelegate.cpp | 13 +- ...ler-ScriptPairingDeviceDiscoveryDelegate.h | 2 +- .../TestCommissionableNodeController.cpp | 75 +-- .../CHIP/MTRCommissionableBrowser.mm | 9 +- src/lib/dnssd/ActiveResolveAttempts.h | 13 +- src/lib/dnssd/Discovery_ImplPlatform.cpp | 24 +- src/lib/dnssd/IncrementalResolve.cpp | 15 +- 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 | 34 +- .../dnssd/tests/TestActiveResolveAttempts.cpp | 6 +- .../dnssd/tests/TestIncrementalResolve.cpp | 32 +- src/lib/dnssd/tests/TestTxtFields.cpp | 434 +++++++++++++++--- src/lib/shell/commands/Dns.cpp | 55 ++- .../UserDirectedCommissioningServer.cpp | 52 +-- .../tests/TestUdcMessages.cpp | 42 +- 54 files changed, 832 insertions(+), 502 deletions(-) diff --git a/examples/chip-tool/commands/common/DeviceScanner.cpp b/examples/chip-tool/commands/common/DeviceScanner.cpp index 9d3dbca98f8db9..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) { - auto & commissionData = nodeData.nodeData; + 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); - auto & resolutionData = nodeData.resolutionData; + const CommonResolutionData & resolutionData = commissionData; auto & instanceData = mDiscoveredResults[commissionData.instanceName]; auto & interfaceData = instanceData[resolutionData.interfaceId.GetPlatformInterface()]; @@ -76,7 +77,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..9a996051957ccf 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 = 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 48697098ae1cba..93005743944ae7 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -475,12 +475,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 = 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..b2bc8af2d8f92b 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,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->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..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 @@ -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,58 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered jstring jInstanceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getInstanceNameField)); if (jInstanceName != nullptr) { - chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.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.nodeData.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"); - outCppDiscoveredNodeData.nodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jVendorIdField)); + jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J"); + outCppDiscoveredNodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jVendorIdField)); - jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J"); - outCppDiscoveredNodeData.nodeData.productId = static_cast(env->GetLongField(jDiscoveredNodeData, jProductIdField)); + jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J"); + 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)); + jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J"); + 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 = - 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.nodeData.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)); 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)); + jfieldID jPortField = env->GetFieldID(jDiscoveredNodeDataClass, "port", "I"); + outCppDiscoveredNodeData.port = static_cast(env->GetIntField(jDiscoveredNodeData, jPortField)); - jfieldID jNumIpsField = env->GetFieldID(jDiscoveredNodeDataClass, "numIPs", "I"); - outCppDiscoveredNodeData.resolutionData.numIPs = static_cast(env->GetIntField(jDiscoveredNodeData, jNumIpsField)); + jfieldID jNumIpsField = env->GetFieldID(jDiscoveredNodeDataClass, "numIPs", "I"); + 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 +397,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 9b26a868efd8c1..0db6328d7d682d 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp @@ -73,7 +73,7 @@ CHIP_ERROR CastingPlayerDiscovery::StopDiscovery() return CHIP_NO_ERROR; } -void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) +void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) { ChipLogProgress(Discovery, "DeviceDiscoveryDelegateImpl::OnDiscoveredDevice() called"); VerifyOrReturn(mClientDelegate != nullptr, @@ -81,23 +81,22 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover // 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.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1, - nodeData.nodeData.instanceName); + 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); - 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.interfaceId = nodeData.interfaceId; + attributes.port = nodeData.port; + attributes.productId = nodeData.productId; + attributes.vendorId = nodeData.vendorId; + attributes.deviceType = nodeData.deviceType; 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 d64f5049df1a8f..9036179f8831f0 100644 --- a/examples/tv-casting-app/tv-casting-common/include/CastingServer.h +++ b/examples/tv-casting-app/tv-casting-common/include/CastingServer.h @@ -62,7 +62,7 @@ class CastingServer : public AppDelegate void InitAppDelegation(); 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, @@ -71,7 +71,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 8c00cf61da4031..2fda932b905d7a 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 b98647db802050..e48015ec74cd5d 100644 --- a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp @@ -218,37 +218,35 @@ 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); - 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; + getIpAddressForUDCRequest(selectedCommissioner->ipAddress, selectedCommissioner->numIPs); + ReturnErrorOnFailure(SendUserDirectedCommissioningRequest( + chip::Transport::PeerAddress::UDP(*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); - chip::Platform::CopyString(mTargetVideoPlayerHostName, chip::Dnssd::kHostNameMaxLength + 1, - selectedCommissioner->resolutionData.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->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..3c098aa9b4fbf3 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; - outNodeData.nodeData.vendorId = inPlayer->GetVendorId(); - outNodeData.nodeData.productId = static_cast(inPlayer->GetProductId()); - outNodeData.nodeData.deviceType = inPlayer->GetDeviceType(); - outNodeData.resolutionData.numIPs = inPlayer->GetNumIPs(); + outDiscNodeData.Set(); + auto & outNodeData = outDiscNodeData.Get(); + + 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..a3ded0d7db8f26 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..3d3ca4c8097955 100644 --- a/src/controller/AbstractDnssdDiscoveryController.cpp +++ b/src/controller/AbstractDnssdDiscoveryController.cpp @@ -25,20 +25,23 @@ 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 +54,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 +64,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 +77,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 a534d7d94c067d..a34359f491750c 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1628,7 +1628,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 dd7b5bc31eec46..b4990b30d1b77a 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -376,7 +376,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(); @@ -694,7 +694,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..c3aecbfdd36f66 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -330,24 +330,29 @@ 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; + } + + const 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 +362,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 +387,7 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover ChipLogProgress(Controller, "Discovered device to be commissioned over DNS-SD"); - NotifyCommissionableDeviceDiscovered(nodeData.resolutionData); + NotifyCommissionableDeviceDiscovered(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 345ad5489f56e7..1c54b4816008e2 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1876,7 +1876,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) { @@ -1903,21 +1903,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) { @@ -1925,12 +1925,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..6df32c6940667a 100644 --- a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp +++ b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp @@ -76,58 +76,54 @@ 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, - sizeof(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()); + ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", 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()); + ChipLogProgress(Discovery, "\tMrp Interval active\t%u", 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"); + ChipLogProgress(Discovery, "\tICD is operating as a\t%s", 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..b7589791b41eab 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,48 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De Json::Value jsonVal; char rotatingId[Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(dnsSdInfo->nodeData.rotatingId, dnsSdInfo->nodeData.rotatingIdLen, rotatingId, - sizeof(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 +167,52 @@ 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, - 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->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()); + ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", 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()); + ChipLogProgress(Discovery, "\tMrp Interval active\t%u", 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"); + ChipLogProgress(Discovery, "\tICD is operating as a\t%s", 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 +221,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 54e917a6292b01..6e4b869de567cf 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. @@ -38,9 +38,8 @@ void ScriptPairingDeviceDiscoveryDelegate::OnDiscoveredDevice(const Dnssd::Disco // Stop Mdns discovery. mActiveDeviceCommissioner->RegisterDeviceDiscoveryDelegate(nullptr); - Inet::InterfaceId interfaceId = - nodeData.resolutionData.ipAddress[0].IsIPv6LinkLocal() ? nodeData.resolutionData.interfaceId : Inet::InterfaceId::Null(); - PeerAddress peerAddress = PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], port, interfaceId); + Inet::InterfaceId interfaceId = nodeData.ipAddress[0].IsIPv6LinkLocal() ? nodeData.interfaceId : Inet::InterfaceId::Null(); + PeerAddress peerAddress = 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..5e866b4b25ea72 100644 --- a/src/controller/tests/TestCommissionableNodeController.cpp +++ b/src/controller/tests/TestCommissionableNodeController.cpp @@ -66,33 +66,35 @@ 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); - 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); + 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); } 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 +106,28 @@ 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); - 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); + 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); 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 d867aa2c4b8b68..529c663a923fa6 100644 --- a/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm +++ b/src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm @@ -149,7 +149,12 @@ void OnNodeDiscovered(const DiscoveredNodeData & nodeData) override { assertChipStackLockedByCurrentThread(); - auto & commissionData = nodeData.nodeData; + if (!nodeData.Is()) { + // not commissionable/commissioners node + return; + } + + auto & commissionData = nodeData.Get(); auto key = [NSString stringWithUTF8String:commissionData.instanceName]; if ([mDiscoveredResults objectForKey:key] == nil) { // It should not happens. @@ -163,7 +168,7 @@ void OnNodeDiscovered(const DiscoveredNodeData & nodeData) override result.discriminator = @(commissionData.longDiscriminator); result.commissioningMode = commissionData.commissioningMode != 0; - auto & resolutionData = nodeData.resolutionData; + const CommonResolutionData & 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 ba6d8cf7a54f6e..b26a552d3e787f 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.h +++ b/src/lib/dnssd/ActiveResolveAttempts.h @@ -153,23 +153,24 @@ class ActiveResolveAttempts { return false; } + auto & nodeData = data.Get(); switch (browse.filter.type) { 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((nodeData.longDiscriminator >> 8) & 0x0F); case chip::Dnssd::DiscoveryFilterType::kLongDiscriminator: - return browse.filter.code == data.nodeData.longDiscriminator; + return browse.filter.code == nodeData.longDiscriminator; case chip::Dnssd::DiscoveryFilterType::kVendorId: - return browse.filter.code == data.nodeData.vendorId; + return browse.filter.code == nodeData.vendorId; case chip::Dnssd::DiscoveryFilterType::kDeviceType: - return browse.filter.code == data.nodeData.deviceType; + return browse.filter.code == nodeData.deviceType; case chip::Dnssd::DiscoveryFilterType::kCommissioningMode: - return browse.filter.code == data.nodeData.commissioningMode; + return browse.filter.code == nodeData.commissioningMode; case chip::Dnssd::DiscoveryFilterType::kInstanceName: - return strncmp(browse.filter.instanceName, data.nodeData.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/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index 065220a3996f08..5f784c3fa89f93 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..f083f852d7402f 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,11 @@ 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 & resolutionData = nodeData; + resolutionData = mCommonResolutionData; ResetToInactive(); diff --git a/src/lib/dnssd/IncrementalResolve.h b/src/lib/dnssd/IncrementalResolve.h index 9d2386472d7eba..30bcb4ad0cee15 100644 --- a/src/lib/dnssd/IncrementalResolve.h +++ b/src/lib/dnssd/IncrementalResolve.h @@ -99,7 +99,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; } @@ -178,7 +178,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 72e44603d916b8..29abc34b8888fe 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -411,12 +411,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 b77d991784867d..d43650748e53a2 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 be64f5de7c7dd4..2920410a8e9f76 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() { // 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 { + ChipLogDetail(Discovery, "Discovered commissionable/commissioner node:"); + CommonResolutionData::LogDetail(); + if (rotatingIdLen > 0) { char rotatingIdString[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; @@ -297,27 +301,7 @@ struct ResolvedNodeData } }; -struct DiscoveredNodeData -{ - CommonResolutionData resolutionData; - DnssdNodeData 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(); - } -}; +using DiscoveredNodeData = Variant; /// 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 f4ef2f202c4def..767e02f296bf8a 100644 --- a/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp +++ b/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp @@ -126,7 +126,8 @@ void TestSingleBrowseAddRemove(nlTestSuite * inSuite, void * inContext) // once complete, nothing to schedule Dnssd::DiscoveredNodeData data; - data.nodeData.longDiscriminator = 1234; + data.Set(); + data.Get().longDiscriminator = 1234; attempts.CompleteCommissionable(data); NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue()); NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue()); @@ -375,7 +376,8 @@ void TestCombination(nlTestSuite * inSuite, void * inContext) attempts.Complete(MakePeerId(2)); attempts.Complete(MakePeerId(1)); Dnssd::DiscoveredNodeData data; - data.nodeData.longDiscriminator = 1234; + data.Set(); + data.Get().longDiscriminator = 1234; attempts.CompleteCommissionable(data); NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue()); diff --git a/src/lib/dnssd/tests/TestIncrementalResolve.cpp b/src/lib/dnssd/tests/TestIncrementalResolve.cpp index 03b585c4ce14c3..bb9a9dde32a324 100644 --- a/src/lib/dnssd/tests/TestIncrementalResolve.cpp +++ b/src/lib/dnssd/tests/TestIncrementalResolve.cpp @@ -394,30 +394,34 @@ void TestParseCommissionable(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, !resolver.GetMissingRequiredInformation().HasAny()); // At this point taking value should work. Once taken, the resolver is reset. - DiscoveredNodeData nodeData; - NL_TEST_ASSERT(inSuite, resolver.Take(nodeData) == CHIP_NO_ERROR); + + DiscoveredNodeData discoveredNodeData; + NL_TEST_ASSERT(inSuite, resolver.Take(discoveredNodeData) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, !resolver.IsActive()); + NL_TEST_ASSERT(inSuite, discoveredNodeData.Is()); + CommissionNodeData nodeData = discoveredNodeData.Get(); + // validate data as it was passed in - NL_TEST_ASSERT(inSuite, nodeData.resolutionData.numIPs == 2); - NL_TEST_ASSERT(inSuite, nodeData.resolutionData.port == 0x1234); - NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.supportsTcp); - NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.numIPs == 2); + NL_TEST_ASSERT(inSuite, nodeData.port == 0x1234); + NL_TEST_ASSERT(inSuite, !nodeData.supportsTcp); + NL_TEST_ASSERT(inSuite, nodeData.GetMrpRetryIntervalActive().HasValue()); NL_TEST_ASSERT(inSuite, - nodeData.resolutionData.GetMrpRetryIntervalActive().Value() == chip::System::Clock::Milliseconds32(321)); - NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); + nodeData.GetMrpRetryIntervalActive().Value() == chip::System::Clock::Milliseconds32(321)); + NL_TEST_ASSERT(inSuite, !nodeData.GetMrpRetryIntervalIdle().HasValue()); Inet::IPAddress addr; NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr)); - NL_TEST_ASSERT(inSuite, nodeData.resolutionData.ipAddress[0] == addr); + NL_TEST_ASSERT(inSuite, nodeData.ipAddress[0] == addr); NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::f0f1:f2f3:f4f5:1234", addr)); - NL_TEST_ASSERT(inSuite, nodeData.resolutionData.ipAddress[1] == addr); + NL_TEST_ASSERT(inSuite, nodeData.ipAddress[1] == addr); // parsed txt data for discovered nodes - NL_TEST_ASSERT(inSuite, nodeData.nodeData.longDiscriminator == 22345); - NL_TEST_ASSERT(inSuite, nodeData.nodeData.vendorId == 321); - NL_TEST_ASSERT(inSuite, nodeData.nodeData.productId == 654); - NL_TEST_ASSERT(inSuite, strcmp(nodeData.nodeData.deviceName, "mytest") == 0); + NL_TEST_ASSERT(inSuite, nodeData.longDiscriminator == 22345); + NL_TEST_ASSERT(inSuite, nodeData.vendorId == 321); + NL_TEST_ASSERT(inSuite, nodeData.productId == 654); + NL_TEST_ASSERT(inSuite, strcmp(nodeData.deviceName, "mytest") == 0); } const nlTest sTests[] = { diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 4593a4903b1a01..6fc3b449b8b24d 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -301,23 +301,23 @@ void TestGetCommissionerPasscode(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, 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.commissionerPasscode != 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.commissionerPasscode != 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) { @@ -332,83 +332,86 @@ void TestFillDiscoveredNodeDataFromTxt(nlTestSuite * inSuite, void * inContext) { 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); - NL_TEST_ASSERT(inSuite, filled.nodeData.longDiscriminator == 840); - filled.nodeData.longDiscriminator = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, filled.longDiscriminator == 840); + filled.longDiscriminator = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); - + // vendor and product strcpy(key, "VP"); strcpy(val, "123+456"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - NL_TEST_ASSERT(inSuite, filled.nodeData.vendorId == 123); - NL_TEST_ASSERT(inSuite, filled.nodeData.productId == 456); - filled.nodeData.vendorId = 0; - filled.nodeData.productId = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, filled.vendorId == 123); + NL_TEST_ASSERT(inSuite, filled.productId == 456); + filled.vendorId = 0; + filled.productId = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Commissioning mode strcpy(key, "CM"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - NL_TEST_ASSERT(inSuite, filled.nodeData.commissioningMode == 1); - filled.nodeData.commissioningMode = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, filled.commissioningMode == 1); + filled.commissioningMode = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); - // Commissioning mode + // Supports Commissioner Generated Passcode strcpy(key, "CP"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - NL_TEST_ASSERT(inSuite, filled.nodeData.commissionerPasscode == 1); - filled.nodeData.commissionerPasscode = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, filled.commissionerPasscode == 1); + filled.commissionerPasscode = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); + // Device type strcpy(key, "DT"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - NL_TEST_ASSERT(inSuite, filled.nodeData.deviceType == 1); - filled.nodeData.deviceType = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, filled.deviceType == 1); + filled.deviceType = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); + // Device name + NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); strcpy(key, "DN"); strcpy(val, "abc"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - NL_TEST_ASSERT(inSuite, strcmp(filled.nodeData.deviceName, "abc") == 0); - memset(filled.nodeData.deviceName, 0, sizeof(filled.nodeData.deviceName)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, strcmp(filled.deviceName, "abc") == 0); + memset(filled.deviceName, 0, sizeof(filled.deviceName)); NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Rotating device id strcpy(key, "RI"); strcpy(val, "1A2B"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingId[0] == 0x1A); - NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingId[1] == 0x2B); - NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingIdLen == 2); - filled.nodeData.rotatingIdLen = 0; - memset(filled.nodeData.rotatingId, 0, sizeof(filled.nodeData.rotatingId)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, filled.rotatingId[0] == 0x1A); + NL_TEST_ASSERT(inSuite, filled.rotatingId[1] == 0x2B); + NL_TEST_ASSERT(inSuite, filled.rotatingIdLen == 2); + filled.rotatingIdLen = 0; + memset(filled.rotatingId, 0, sizeof(filled.rotatingId)); NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Pairing instruction strcpy(key, "PI"); strcpy(val, "hint"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - NL_TEST_ASSERT(inSuite, strcmp(filled.nodeData.pairingInstruction, "hint") == 0); - memset(filled.nodeData.pairingInstruction, 0, sizeof(filled.nodeData.pairingInstruction)); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, strcmp(filled.pairingInstruction, "hint") == 0); + memset(filled.pairingInstruction, 0, sizeof(filled.pairingInstruction)); NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); // Pairing hint strcpy(key, "PH"); strcpy(val, "1"); - FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData); - NL_TEST_ASSERT(inSuite, filled.nodeData.pairingHint == 1); - filled.nodeData.pairingHint = 0; + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled); + NL_TEST_ASSERT(inSuite, filled.pairingHint == 1); + filled.pairingHint = 0; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled)); } @@ -422,7 +425,7 @@ bool NodeDataIsEmpty(const ResolvedNodeData & nodeData) void ResetRetryIntervalIdle(DiscoveredNodeData & nodeData) { - nodeData.resolutionData.mrpRetryIntervalIdle.ClearValue(); + nodeData.Get().mrpRetryIntervalIdle.ClearValue(); } void ResetRetryIntervalIdle(ResolvedNodeData & nodeData) @@ -432,7 +435,7 @@ void ResetRetryIntervalIdle(ResolvedNodeData & nodeData) void ResetRetryIntervalActive(DiscoveredNodeData & nodeData) { - nodeData.resolutionData.mrpRetryIntervalActive.ClearValue(); + nodeData.Get().mrpRetryIntervalActive.ClearValue(); } void ResetRetryIntervalActive(ResolvedNodeData & nodeData) @@ -442,7 +445,7 @@ void ResetRetryIntervalActive(ResolvedNodeData & nodeData) void ResetRetryActiveThreshold(DiscoveredNodeData & nodeData) { - nodeData.resolutionData.mrpRetryActiveThreshold.ClearValue(); + nodeData.Get().mrpRetryActiveThreshold.ClearValue(); } void ResetRetryActiveThreshold(ResolvedNodeData & nodeData) @@ -450,6 +453,326 @@ void ResetRetryActiveThreshold(ResolvedNodeData & nodeData) nodeData.resolutionData.mrpRetryActiveThreshold.ClearValue(); } +template +void DiscoveredTxtFieldSessionIdleInterval(nlTestSuite * inSuite, void * inContext) +{ + char key[4]; + char val[16]; + DiscoveredNodeData nodeData; + nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); + + // Minimum + strcpy(key, "SII"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryIntervalIdle().Value() == 1_ms32); + + // Maximum + strcpy(key, "SII"); + strcpy(val, "3600000"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryIntervalIdle().Value() == 3600000_ms32); + + // Test no other fields were populated + ResetRetryIntervalIdle(nodeData); + NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData.Get())); + + // Invalid SII - negative value + strcpy(key, "SII"); + strcpy(val, "-1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - greater than maximum + strcpy(key, "SII"); + strcpy(val, "3600001"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !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); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - hexadecimal value + strcpy(key, "SII"); + strcpy(val, "0x20"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - leading zeros + strcpy(key, "SII"); + strcpy(val, "0700"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + + // Invalid SII - text at the end + strcpy(key, "SII"); + strcpy(val, "123abc"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); +} + +// Test SAI (formerly CRA) +template +void DiscoveredTxtFieldSessionActiveInterval(nlTestSuite * inSuite, void * inContext) +{ + char key[4]; + char val[16]; + DiscoveredNodeData nodeData; + nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); + + // Minimum + strcpy(key, "SAI"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryIntervalActive().Value() == 1_ms32); + + // Maximum + strcpy(key, "SAI"); + strcpy(val, "3600000"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryIntervalActive().Value() == 3600000_ms32); + + // Test no other fields were populated + ResetRetryIntervalActive(nodeData); + NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData.Get())); + + // Invalid SAI - negative value + strcpy(key, "SAI"); + strcpy(val, "-1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - greater than maximum + strcpy(key, "SAI"); + strcpy(val, "3600001"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !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); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - hexadecimal value + strcpy(key, "SAI"); + strcpy(val, "0x20"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - leading zeros + strcpy(key, "SAI"); + strcpy(val, "0700"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + + // Invalid SAI - text at the end + strcpy(key, "SAI"); + strcpy(val, "123abc"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryIntervalActive().HasValue()); +} + +// Test SAT (Session Active Threshold) +template +void DiscoveredTxtFieldSessionActiveThreshold(nlTestSuite * inSuite, void * inContext) +{ + char key[4]; + char val[16]; + DiscoveredNodeData nodeData; + nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); + + // Minimum + strcpy(key, "SAT"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryActiveThreshold().Value() == 1_ms16); + + // Maximum + strcpy(key, "SAT"); + strcpy(val, "65535"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.Get().GetMrpRetryActiveThreshold().Value() == 65535_ms16); + + // Test no other fields were populated + ResetRetryActiveThreshold(nodeData); + NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData.Get())); + + // Invalid SAI - negative value + strcpy(key, "SAT"); + strcpy(val, "-1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAI - greater than maximum + strcpy(key, "SAT"); + strcpy(val, "65536"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !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); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAT - hexadecimal value + strcpy(key, "SAT"); + strcpy(val, "0x20"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAT - leading zeros + strcpy(key, "SAT"); + strcpy(val, "0700"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + + // Invalid SAT - text at the end + strcpy(key, "SAT"); + strcpy(val, "123abc"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, !nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); +} + +// Test T (TCP support) +template +void DiscoveredTxtFieldTcpSupport(nlTestSuite * inSuite, void * inContext) +{ + char key[4]; + char val[8]; + DiscoveredNodeData nodeData; + nodeData.Set(); + CommonResolutionData & resolutionData = nodeData.Get(); + + // True + strcpy(key, "T"); + strcpy(val, "1"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().supportsTcp); + + // Test no other fields were populated + nodeData.Get().supportsTcp = false; + NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData.Get())); + + // False + strcpy(key, "T"); + strcpy(val, "0"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().supportsTcp == false); + + // Invalid value, stil false + strcpy(key, "T"); + strcpy(val, "asdf"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().supportsTcp == false); +} + +// Test ICD (ICD operation Mode) +template +void DiscoveredTxtFieldICDoperatesAsLIT(nlTestSuite * inSuite, void * inContext) +{ + char key[4]; + 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), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().isICDOperatingAsLIT.HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.Get().isICDOperatingAsLIT.Value()); + + // Test no other fields were populated + nodeData.Get().isICDOperatingAsLIT.ClearValue(); + NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData.Get())); + + // ICD is operating as a SIT device + strcpy(key, "ICD"); + strcpy(val, "0"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().isICDOperatingAsLIT.HasValue()); + NL_TEST_ASSERT(inSuite, nodeData.Get().isICDOperatingAsLIT.Value() == false); + + nodeData.Get().isICDOperatingAsLIT.ClearValue(); + NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData.Get())); + // Invalid value, No key set + strcpy(key, "ICD"); + strcpy(val, "asdf"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + NL_TEST_ASSERT(inSuite, nodeData.Get().isICDOperatingAsLIT.HasValue() == false); +} + +// Test IsDeviceTreatedAsSleepy() with CRI +template +void DiscoveredTestIsDeviceSessionIdle(nlTestSuite * inSuite, void * inContext) +{ + 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); + CommonResolutionData & resolutionData = nodeData.Get(); + + // No key/val set, so the device can't be sleepy + NL_TEST_ASSERT(inSuite, !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); + NL_TEST_ASSERT(inSuite, !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); + NL_TEST_ASSERT(inSuite, nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); +} + +// Test IsDeviceTreatedAsSleepy() with CRA +template +void DiscoveredTestIsDeviceSessionActive(nlTestSuite * inSuite, void * inContext) +{ + 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); + CommonResolutionData & resolutionData = nodeData.Get(); + + // No key/val set, so the device can't be sleepy + NL_TEST_ASSERT(inSuite, !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); + NL_TEST_ASSERT(inSuite, !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); + NL_TEST_ASSERT(inSuite, nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); +} + // Test SAI (formally CRI) template void TxtFieldSessionIdleInterval(nlTestSuite * inSuite, void * inContext) @@ -636,7 +959,6 @@ void TxtFieldSessionActiveThreshold(nlTestSuite * inSuite, void * inContext) strcpy(key, "SAT"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); } // Test T (TCP support) @@ -652,7 +974,7 @@ void TxtFieldTcpSupport(nlTestSuite * inSuite, void * inContext) strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); NL_TEST_ASSERT(inSuite, nodeData.resolutionData.supportsTcp); - + // Test no other fields were populated nodeData.resolutionData.supportsTcp = false; NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData)); @@ -771,13 +1093,13 @@ const nlTest sTests[] = { NL_TEST_DEF("TxtFieldPairingInstruction", TestGetPairingInstruction), // NL_TEST_DEF("TxtFieldCommissionerPasscode", TestGetCommissionerPasscode), // NL_TEST_DEF("TxtFieldFillDiscoveredNodeDataFromTxt", TestFillDiscoveredNodeDataFromTxt), // - NL_TEST_DEF("TxtDiscoveredFieldMrpRetryIntervalIdle", TxtFieldSessionIdleInterval), - NL_TEST_DEF("TxtDiscoveredFieldMrpRetryIntervalActive", TxtFieldSessionActiveInterval), - NL_TEST_DEF("TxtDiscoveredFieldMrpRetryActiveThreshold", TxtFieldSessionActiveThreshold), - NL_TEST_DEF("TxtDiscoveredFieldTcpSupport", (TxtFieldTcpSupport) ), - NL_TEST_DEF("TxtDiscoveredIsICDoperatingAsLIT", (TxtFieldICDoperatesAsLIT) ), - NL_TEST_DEF("TxtDiscoveredIsDeviceSessionIdle", TestIsDeviceSessionIdle), - NL_TEST_DEF("TxtDiscoveredIsDeviceSessionActive", TestIsDeviceSessionActive), + NL_TEST_DEF("TxtDiscoveredFieldMrpRetryIntervalIdle", DiscoveredTxtFieldSessionIdleInterval), + NL_TEST_DEF("TxtDiscoveredFieldMrpRetryIntervalActive", DiscoveredTxtFieldSessionActiveInterval), + NL_TEST_DEF("TxtDiscoveredFieldMrpRetryActiveThreshold", DiscoveredTxtFieldSessionActiveThreshold), + NL_TEST_DEF("TxtDiscoveredFieldTcpSupport", (DiscoveredTxtFieldTcpSupport) ), + NL_TEST_DEF("TxtDiscoveredIsICDoperatingAsLIT", (DiscoveredTxtFieldICDoperatesAsLIT) ), + NL_TEST_DEF("TxtDiscoveredIsDeviceSessionIdle", DiscoveredTestIsDeviceSessionIdle), + NL_TEST_DEF("TxtDiscoveredIsDeviceSessionActive", DiscoveredTestIsDeviceSessionActive), NL_TEST_DEF("TxtResolvedFieldMrpRetryIntervalIdle", TxtFieldSessionIdleInterval), NL_TEST_DEF("TxtResolvedFieldMrpRetryIntervalActive", TxtFieldSessionActiveInterval), NL_TEST_DEF("TxtResolvedFieldMrpRetryActiveThreshold", TxtFieldSessionActiveThreshold), diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 14955335daaad0..04d82313d7d3d4 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -83,57 +83,66 @@ 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, - sizeof(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.ipAddress[i].ToString(ipAddressBuf)); + } + if (nodeData.port > 0) { - streamer_printf(streamer_get(), " %s\r\n", nodeData.resolutionData.ipAddress[i].ToString(ipAddressBuf)); + 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 f63a10c94965f5..0d75678b9d7b1c 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp @@ -400,21 +400,26 @@ 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()) { - ChipLogError(AppServer, "OnCommissionableNodeFound no IP addresses returned for instance name=%s", - nodeData.nodeData.instanceName); return; } - if (nodeData.resolutionData.port == 0) + + const Dnssd::CommissionNodeData & nodeData = discNodeData.Get(); + if (nodeData.numIPs == 0) + { + ChipLogError(AppServer, "OnCommissionableNodeFound no IP addresses returned for instance name=%s", nodeData.instanceName); + return; + } + 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(), @@ -424,50 +429,45 @@ 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)); + 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.resolutionData.ipAddress[0], nodeData.resolutionData.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 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)); + 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.nodeData.instanceName); - client->SetPeerAddress( - chip::Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], nodeData.resolutionData.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 - 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 9c171b5efad5b8..c7ebd5d21d3147 100644 --- a/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp +++ b/src/protocols/user_directed_commissioning/tests/TestUdcMessages.cpp @@ -82,23 +82,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()); @@ -111,8 +115,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()); @@ -128,9 +132,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 ebac43082f9677295e5ad1aba3d020c2d092b15f Mon Sep 17 00:00:00 2001 From: Suhas Shankar <118879678+su-shanka@users.noreply.github.com> Date: Thu, 9 May 2024 18:32:56 +0530 Subject: [PATCH 3/3] [Dns-sd] Added Operational Discovery and made browse delegate common (#32750) * Added operational discovery support * Restyled by whitespace * Restyled by clang-format * Updates as per review feedback * Restyled by whitespace * Restyled by clang-format * Updates based on additional feedback * Restyled by whitespace * updates as per feedback from review --------- Co-authored-by: Restyled.io --- src/lib/dnssd/IncrementalResolve.cpp | 19 ++++++---- src/lib/dnssd/IncrementalResolve.h | 7 ++-- src/lib/dnssd/ResolverProxy.cpp | 7 ++++ src/lib/dnssd/ResolverProxy.h | 1 + src/lib/dnssd/Resolver_ImplMinimalMdns.cpp | 36 +++++++++++++++---- src/lib/dnssd/Types.h | 20 +++++++++-- .../dnssd/tests/TestIncrementalResolve.cpp | 26 +++++++------- src/lib/shell/commands/Dns.cpp | 29 ++++++++++++--- 8 files changed, 109 insertions(+), 36 deletions(-) diff --git a/src/lib/dnssd/IncrementalResolve.cpp b/src/lib/dnssd/IncrementalResolve.cpp index f083f852d7402f..867b1a8dcddb6c 100644 --- a/src/lib/dnssd/IncrementalResolve.cpp +++ b/src/lib/dnssd/IncrementalResolve.cpp @@ -137,7 +137,8 @@ SerializedQNameIterator StoredServerName::Get() const return SerializedQNameIterator(BytesRange(mNameBuffer, mNameBuffer + sizeof(mNameBuffer)), mNameBuffer); } -CHIP_ERROR IncrementalResolver::InitializeParsing(mdns::Minimal::SerializedQNameIterator name, const mdns::Minimal::SrvRecord & srv) +CHIP_ERROR IncrementalResolver::InitializeParsing(mdns::Minimal::SerializedQNameIterator name, const uint64_t ttl, + const mdns::Minimal::SrvRecord & srv) { AutoInactiveResetter inactiveReset(*this); @@ -183,6 +184,7 @@ CHIP_ERROR IncrementalResolver::InitializeParsing(mdns::Minimal::SerializedQName { return err; } + mSpecificResolutionData.Get().hasZeroTTL = (ttl == 0); } LogFoundOperationalSrvRecord(mSpecificResolutionData.Get().peerId, mTargetHostName.Get()); @@ -304,7 +306,7 @@ CHIP_ERROR IncrementalResolver::OnTxtRecord(const ResourceData & data, BytesRang } } - if (IsActiveBrowseParse()) + if (IsActiveCommissionParse()) { TxtParser delegate(mSpecificResolutionData.Get()); if (!ParseTxtRecord(data.GetData(), &delegate)) @@ -343,14 +345,17 @@ CHIP_ERROR IncrementalResolver::OnIpAddress(Inet::InterfaceId interface, const I CHIP_ERROR IncrementalResolver::Take(DiscoveredNodeData & outputData) { - VerifyOrReturnError(IsActiveBrowseParse(), CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(IsActiveCommissionParse(), CHIP_ERROR_INCORRECT_STATE); IPAddressSorter::Sort(mCommonResolutionData.ipAddress, mCommonResolutionData.numIPs, mCommonResolutionData.interfaceId); - outputData.Set(); - CommissionNodeData & nodeData = outputData.Get(); - nodeData = mSpecificResolutionData.Get(); - CommonResolutionData & resolutionData = nodeData; + // Set the DiscoveredNodeData with CommissionNodeData info specific to commissionable/commisssioner + // node available in mSpecificResolutionData. + outputData.Set(mSpecificResolutionData.Get()); + + // IncrementalResolver stored CommonResolutionData separately in mCommonResolutionData hence copy the + // CommonResolutionData info from mCommonResolutionData, to CommissionNodeData within DiscoveredNodeData + CommonResolutionData & resolutionData = outputData.Get(); resolutionData = mCommonResolutionData; ResetToInactive(); diff --git a/src/lib/dnssd/IncrementalResolve.h b/src/lib/dnssd/IncrementalResolve.h index 30bcb4ad0cee15..ea7a2513698f8c 100644 --- a/src/lib/dnssd/IncrementalResolve.h +++ b/src/lib/dnssd/IncrementalResolve.h @@ -99,7 +99,7 @@ class IncrementalResolver /// method. bool IsActive() const { return mSpecificResolutionData.Valid(); } - bool IsActiveBrowseParse() const { return mSpecificResolutionData.Is(); } + bool IsActiveCommissionParse() const { return mSpecificResolutionData.Is(); } bool IsActiveOperationalParse() const { return mSpecificResolutionData.Is(); } ServiceNameType GetCurrentType() const { return mServiceNameType; } @@ -108,7 +108,8 @@ class IncrementalResolver /// interested on, after which TXT and A/AAAA are looked for. /// /// If this function returns with error, the object will be in an inactive state. - CHIP_ERROR InitializeParsing(mdns::Minimal::SerializedQNameIterator name, const mdns::Minimal::SrvRecord & srv); + CHIP_ERROR InitializeParsing(mdns::Minimal::SerializedQNameIterator name, const uint64_t ttl, + const mdns::Minimal::SrvRecord & srv); /// Notify that a new record is being processed. /// Will handle filtering and processing of data to determine if the entry is relevant for @@ -143,7 +144,7 @@ class IncrementalResolver /// Take the current value of the object and clear it once returned. /// - /// Object must be in `IsActiveBrowseParse()` for this to succeed. + /// Object must be in `IsActive()` for this to succeed. /// Data will be returned (and cleared) even if not yet complete based /// on `GetMissingRequiredInformation()`. This method takes as much data as /// it was parsed so far. diff --git a/src/lib/dnssd/ResolverProxy.cpp b/src/lib/dnssd/ResolverProxy.cpp index e43028ee54023d..2fbf5b13a468e7 100644 --- a/src/lib/dnssd/ResolverProxy.cpp +++ b/src/lib/dnssd/ResolverProxy.cpp @@ -55,6 +55,13 @@ CHIP_ERROR ResolverProxy::DiscoverCommissioners(DiscoveryFilter filter) return mResolver.StartDiscovery(DiscoveryType::kCommissionerNode, filter, *mContext); } +CHIP_ERROR ResolverProxy::DiscoverOperationalNodes(DiscoveryFilter filter) +{ + VerifyOrReturnError(mContext != nullptr, CHIP_ERROR_INCORRECT_STATE); + + return mResolver.StartDiscovery(DiscoveryType::kOperational, filter, *mContext); +} + CHIP_ERROR ResolverProxy::StopDiscovery() { VerifyOrReturnError(mContext != nullptr, CHIP_ERROR_INCORRECT_STATE); diff --git a/src/lib/dnssd/ResolverProxy.h b/src/lib/dnssd/ResolverProxy.h index 58617b0d0162d7..d1888c36c1512d 100644 --- a/src/lib/dnssd/ResolverProxy.h +++ b/src/lib/dnssd/ResolverProxy.h @@ -54,6 +54,7 @@ class ResolverProxy CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()); CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()); + CHIP_ERROR DiscoverOperationalNodes(DiscoveryFilter filter = DiscoveryFilter()); CHIP_ERROR StopDiscovery(); private: diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index 29abc34b8888fe..7b2d8899f71d60 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -215,7 +215,7 @@ void PacketParser::ParseSRVResource(const ResourceData & data) continue; } - CHIP_ERROR err = resolver.InitializeParsing(data.GetName(), srv); + CHIP_ERROR err = resolver.InitializeParsing(data.GetName(), data.GetTtlSeconds(), srv); if (err != CHIP_NO_ERROR) { // Receiving records that we do not need to parse is normal: @@ -365,6 +365,7 @@ void MinMdnsResolver::AdvancePendingResolverStates() { if (!resolver->IsActive()) { + ChipLogError(Discovery, "resolver inactive, continue to next"); continue; } @@ -385,7 +386,7 @@ void MinMdnsResolver::AdvancePendingResolverStates() } // SUCCESS. Call the delegates - if (resolver->IsActiveBrowseParse()) + if (resolver->IsActiveCommissionParse()) { MATTER_TRACE_SCOPE("Active commissioning delegate call", "MinMdnsResolver"); DiscoveredNodeData nodeData; @@ -438,18 +439,39 @@ void MinMdnsResolver::AdvancePendingResolverStates() else if (resolver->IsActiveOperationalParse()) { MATTER_TRACE_SCOPE("Active operational delegate call", "MinMdnsResolver"); - ResolvedNodeData nodeData; + ResolvedNodeData nodeResolvedData; + CHIP_ERROR err = resolver->Take(nodeResolvedData); - CHIP_ERROR err = resolver->Take(nodeData); if (err != CHIP_NO_ERROR) { - ChipLogError(Discovery, "Failed to take discovery result: %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(Discovery, "Failed to take NodeData - result: %" CHIP_ERROR_FORMAT, err.Format()); + continue; + } + + if (mActiveResolves.HasBrowseFor(chip::Dnssd::DiscoveryType::kOperational)) + { + if (mDiscoveryContext != nullptr) + { + DiscoveredNodeData nodeData; + OperationalNodeBrowseData opNodeData; + + opNodeData.peerId = nodeResolvedData.operationalData.peerId; + opNodeData.hasZeroTTL = nodeResolvedData.operationalData.hasZeroTTL; + nodeData.Set(opNodeData); + mDiscoveryContext->OnNodeDiscovered(nodeData); + } + else + { +#if CHIP_MINMDNS_HIGH_VERBOSITY + ChipLogError(Discovery, "No delegate to report operational node discovery"); +#endif + } } - mActiveResolves.Complete(nodeData.operationalData.peerId); + mActiveResolves.Complete(nodeResolvedData.operationalData.peerId); if (mOperationalDelegate != nullptr) { - mOperationalDelegate->OnOperationalNodeResolved(nodeData); + mOperationalDelegate->OnOperationalNodeResolved(nodeResolvedData); } else { diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h index 2920410a8e9f76..f2d0052558703b 100644 --- a/src/lib/dnssd/Types.h +++ b/src/lib/dnssd/Types.h @@ -197,10 +197,23 @@ struct CommonResolutionData struct OperationalNodeData { PeerId peerId; - + bool hasZeroTTL; void Reset() { peerId = PeerId(); } }; +struct OperationalNodeBrowseData : public OperationalNodeData +{ + OperationalNodeBrowseData() { Reset(); }; + void LogDetail() const + { + ChipLogDetail(Discovery, "Discovered Operational node:\r\n"); + ChipLogDetail(Discovery, "\tNode Instance: " ChipLogFormatX64 ":" ChipLogFormatX64 "\r\n", + ChipLogValueX64(peerId.GetCompressedFabricId()), + ChipLogValueX64(peerId.GetNodeId())); + ChipLogDetail(Discovery, "\thasZeroTTL: %s\r\n", hasZeroTTL ? "true" : "false"); + } +}; + inline constexpr size_t kMaxDeviceNameLen = 32; inline constexpr size_t kMaxRotatingIdLen = 50; inline constexpr size_t kMaxPairingInstructionLen = 128; @@ -301,12 +314,13 @@ struct ResolvedNodeData } }; -using DiscoveredNodeData = Variant; +using DiscoveredNodeData = Variant; -/// Callbacks for discovering nodes advertising non-operational status: +/// Callbacks for discovering nodes advertising both operational and non-operational status: /// - Commissioners /// - Nodes in commissioning modes over IP (e.g. ethernet devices, devices already /// connected to thread/wifi or devices with a commissioning window open) +/// - Operational nodes class DiscoverNodeDelegate { public: diff --git a/src/lib/dnssd/tests/TestIncrementalResolve.cpp b/src/lib/dnssd/tests/TestIncrementalResolve.cpp index bb9a9dde32a324..2657fd9cdedfa9 100644 --- a/src/lib/dnssd/tests/TestIncrementalResolve.cpp +++ b/src/lib/dnssd/tests/TestIncrementalResolve.cpp @@ -20,6 +20,7 @@ #include +#include #include #include #include @@ -163,7 +164,7 @@ void TestCreation(nlTestSuite * inSuite, void * inContext) IncrementalResolver resolver; NL_TEST_ASSERT(inSuite, !resolver.IsActive()); - NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse()); + NL_TEST_ASSERT(inSuite, !resolver.IsActiveCommissionParse()); NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse()); NL_TEST_ASSERT( inSuite, @@ -180,10 +181,10 @@ void TestInactiveResetOnInitError(nlTestSuite * inSuite, void * inContext) PreloadSrvRecord(inSuite, srvRecord); // test host name is not a 'matter' name - NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestHostName.Serialized(), srvRecord) != CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestHostName.Serialized(), 0, srvRecord) != CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, !resolver.IsActive()); - NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse()); + NL_TEST_ASSERT(inSuite, !resolver.IsActiveCommissionParse()); NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse()); } @@ -196,10 +197,10 @@ void TestStartOperational(nlTestSuite * inSuite, void * inContext) SrvRecord srvRecord; PreloadSrvRecord(inSuite, srvRecord); - NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestOperationalName.Serialized(), srvRecord) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestOperationalName.Serialized(), 1, srvRecord) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, resolver.IsActive()); - NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse()); + NL_TEST_ASSERT(inSuite, !resolver.IsActiveCommissionParse()); NL_TEST_ASSERT(inSuite, resolver.IsActiveOperationalParse()); NL_TEST_ASSERT(inSuite, resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)); @@ -215,10 +216,10 @@ void TestStartCommissionable(nlTestSuite * inSuite, void * inContext) SrvRecord srvRecord; PreloadSrvRecord(inSuite, srvRecord); - NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionableNode.Serialized(), srvRecord) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionableNode.Serialized(), 0, srvRecord) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, resolver.IsActive()); - NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse()); + NL_TEST_ASSERT(inSuite, resolver.IsActiveCommissionParse()); NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse()); NL_TEST_ASSERT(inSuite, resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)); @@ -234,10 +235,10 @@ void TestStartCommissioner(nlTestSuite * inSuite, void * inContext) SrvRecord srvRecord; PreloadSrvRecord(inSuite, srvRecord); - NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionerNode.Serialized(), srvRecord) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionerNode.Serialized(), 0, srvRecord) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, resolver.IsActive()); - NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse()); + NL_TEST_ASSERT(inSuite, resolver.IsActiveCommissionParse()); NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse()); NL_TEST_ASSERT(inSuite, resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)); @@ -253,7 +254,7 @@ void TestParseOperational(nlTestSuite * inSuite, void * inContext) SrvRecord srvRecord; PreloadSrvRecord(inSuite, srvRecord); - NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestOperationalName.Serialized(), srvRecord) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestOperationalName.Serialized(), 1, srvRecord) == CHIP_NO_ERROR); // once initialized, parsing should be ready however no IP address is available NL_TEST_ASSERT(inSuite, resolver.IsActiveOperationalParse()); @@ -312,6 +313,7 @@ void TestParseOperational(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, nodeData.operationalData.peerId == PeerId().SetCompressedFabricId(0x1234567898765432LL).SetNodeId(0xABCDEFEDCBAABCDELL)); + NL_TEST_ASSERT(inSuite, !nodeData.operationalData.hasZeroTTL); NL_TEST_ASSERT(inSuite, nodeData.resolutionData.numIPs == 1); NL_TEST_ASSERT(inSuite, nodeData.resolutionData.port == 0x1234); NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.supportsTcp); @@ -333,10 +335,10 @@ void TestParseCommissionable(nlTestSuite * inSuite, void * inContext) SrvRecord srvRecord; PreloadSrvRecord(inSuite, srvRecord); - NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionableNode.Serialized(), srvRecord) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionableNode.Serialized(), 0, srvRecord) == CHIP_NO_ERROR); // once initialized, parsing should be ready however no IP address is available - NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse()); + NL_TEST_ASSERT(inSuite, resolver.IsActiveCommissionParse()); NL_TEST_ASSERT(inSuite, resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)); NL_TEST_ASSERT(inSuite, resolver.GetTargetHostName() == kTestHostName.Serialized()); diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 04d82313d7d3d4..2ea89be8f8f3df 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -83,15 +83,25 @@ class DnsShellResolverDelegate : public Dnssd::DiscoverNodeDelegate, public Addr AddressResolve::NodeLookupHandle & Handle() { return mSelfHandle; } + void LogOperationalNodeDiscovered(const Dnssd::OperationalNodeBrowseData & nodeData) + { + streamer_printf(streamer_get(), "DNS browse operational succeeded: \r\n"); + streamer_printf(streamer_get(), " Node Instance: " ChipLogFormatX64 ":" ChipLogFormatX64 "\r\n", + ChipLogValueX64(nodeData.peerId.GetCompressedFabricId()), + ChipLogValueX64(nodeData.peerId.GetNodeId())); + streamer_printf(streamer_get(), " hasZeroTTL: %s\r\n", nodeData.hasZeroTTL ? "true" : "false"); + } + void OnNodeDiscovered(const Dnssd::DiscoveredNodeData & discNodeData) override { - if (!discNodeData.Is()) + if (discNodeData.Is()) { - streamer_printf(streamer_get(), "DNS browse failed - not commission type node \r\n"); + LogOperationalNodeDiscovered(discNodeData.Get()); return; } - Dnssd::CommissionNodeData nodeData = discNodeData.Get(); + const auto & nodeData = discNodeData.Get(); + if (!nodeData.IsValid()) { streamer_printf(streamer_get(), "DNS browse failed - not found valid services \r\n"); @@ -237,6 +247,16 @@ CHIP_ERROR BrowseCommissionerHandler(int argc, char ** argv) return sResolverProxy.DiscoverCommissioners(filter); } +CHIP_ERROR BrowseOperationalHandler(int argc, char ** argv) +{ + Dnssd::DiscoveryFilter filter; + VerifyOrReturnError(ParseSubType(argc, argv, filter), CHIP_ERROR_INVALID_ARGUMENT); + + streamer_printf(streamer_get(), "Browsing operational...\r\n"); + + return sResolverProxy.DiscoverOperationalNodes(filter); +} + CHIP_ERROR BrowseHandler(int argc, char ** argv) { if (argc == 0) @@ -271,13 +291,14 @@ void RegisterDnsCommands() "Browse Matter commissionable nodes. Usage: dns browse commissionable [subtype]" }, { &BrowseCommissionerHandler, "commissioner", "Browse Matter commissioner nodes. Usage: dns browse commissioner [subtype]" }, + { &BrowseOperationalHandler, "operational", "Browse Matter operational nodes. Usage: dns browse operational" }, }; static const shell_command_t sDnsSubCommands[] = { { &ResolveHandler, "resolve", "Resolve the DNS service. Usage: dns resolve (e.g. dns resolve 5544332211 1)" }, { &BrowseHandler, "browse", - "Browse DNS services published by Matter nodes. Usage: dns browse " }, + "Browse DNS services published by Matter nodes. Usage: dns browse " }, }; static const shell_command_t sDnsCommand = { &DnsHandler, "dns", "Dns client commands" };