From 2619d206119708fdd660569fb608344e09ff436d Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 7 Dec 2022 03:05:54 +0100 Subject: [PATCH] Try to pair over all discovered ips instead of only the first one that has been discovered (#22789) --- scripts/tools/check_includes_config.py | 4 ++-- src/controller/SetUpCodePairer.cpp | 17 +++++++++++------ src/controller/SetUpCodePairer.h | 8 ++++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/tools/check_includes_config.py b/scripts/tools/check_includes_config.py index 81b2a481c472f9..cbf0b405c720dd 100644 --- a/scripts/tools/check_includes_config.py +++ b/scripts/tools/check_includes_config.py @@ -149,9 +149,9 @@ # Uses platform-define to switch between list and array 'src/lib/dnssd/minimal_mdns/ResponseSender.h': {'list'}, - # Not really for embedded consumers; uses std::queue to keep track + # Not really for embedded consumers; uses std::deque to keep track # of a list of discovered things. - 'src/controller/SetUpCodePairer.h': {'queue'}, + 'src/controller/SetUpCodePairer.h': {'deque'}, 'src/controller/ExamplePersistentStorage.cpp': {'fstream'} } diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 09ee3a012a4021..d9a372f3d025be 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -224,7 +224,7 @@ bool SetUpCodePairer::ConnectToDiscoveredDevice() // connection attempt fails and calls right back into us to try the next // thing. SetUpCodePairerParameters params(mDiscoveredParameters.front()); - mDiscoveredParameters.pop(); + mDiscoveredParameters.pop_front(); params.SetSetupPINCode(mSetUpPINCode); @@ -272,7 +272,7 @@ void SetUpCodePairer::OnDiscoveredDeviceOverBle(BLE_CONNECTION_OBJECT connObj) mWaitingForDiscovery[kBLETransport] = false; - mDiscoveredParameters.emplace(connObj); + mDiscoveredParameters.emplace_front(connObj); ConnectToDiscoveredDevice(); } @@ -341,7 +341,12 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover ChipLogProgress(Controller, "Discovered device to be commissioned over DNS-SD"); - mDiscoveredParameters.emplace(nodeData.resolutionData); + auto & resolutionData = nodeData.resolutionData; + for (size_t i = 0; i < resolutionData.numIPs; i++) + { + mDiscoveredParameters.emplace_back(nodeData.resolutionData, i); + } + ConnectToDiscoveredDevice(); } @@ -394,7 +399,7 @@ void SetUpCodePairer::ResetDiscoveryState() while (!mDiscoveredParameters.empty()) { - mDiscoveredParameters.pop(); + mDiscoveredParameters.pop_front(); } mCurrentPASEParameters.ClearValue(); @@ -542,12 +547,12 @@ void SetUpCodePairer::OnDeviceDiscoveredTimeoutCallback(System::Layer * layer, v } } -SetUpCodePairerParameters::SetUpCodePairerParameters(const Dnssd::CommonResolutionData & data) +SetUpCodePairerParameters::SetUpCodePairerParameters(const Dnssd::CommonResolutionData & data, size_t index) { mInterfaceId = data.interfaceId; Platform::CopyString(mHostName, data.hostName); - auto & ip = data.ipAddress[0]; + auto & ip = data.ipAddress[index]; SetPeerAddress(Transport::PeerAddress::UDP(ip, data.port, ip.IsIPv6LinkLocal() ? data.interfaceId : Inet::InterfaceId::Null())); if (data.mrpRetryIntervalIdle.HasValue()) diff --git a/src/controller/SetUpCodePairer.h b/src/controller/SetUpCodePairer.h index eae15065d75966..0b665a9cbbaa1b 100644 --- a/src/controller/SetUpCodePairer.h +++ b/src/controller/SetUpCodePairer.h @@ -41,7 +41,7 @@ #include -#include +#include namespace chip { namespace Controller { @@ -51,7 +51,7 @@ class DeviceCommissioner; class SetUpCodePairerParameters : public RendezvousParameters { public: - SetUpCodePairerParameters(const Dnssd::CommonResolutionData & data); + SetUpCodePairerParameters(const Dnssd::CommonResolutionData & data, size_t index); #if CONFIG_NETWORK_LAYER_BLE SetUpCodePairerParameters(BLE_CONNECTION_OBJECT connObj); #endif // CONFIG_NETWORK_LAYER_BLE @@ -188,10 +188,10 @@ class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate // process happening via the relevant transport. bool mWaitingForDiscovery[kTransportTypeCount] = { false }; - // Queue of things we have discovered but not tried connecting to yet. The + // Double ended-queue of things we have discovered but not tried connecting to yet. The // general discovery/pairing process will terminate once this queue is empty // and all the booleans in mWaitingForDiscovery are false. - std::queue mDiscoveredParameters; + std::deque mDiscoveredParameters; // Current thing we are trying to connect to over UDP. If a PASE connection fails with // a CHIP_ERROR_TIMEOUT, the discovered parameters will be used to ask the