Skip to content

Commit

Permalink
Try to pair over all discovered ips instead of only the first one tha…
Browse files Browse the repository at this point in the history
…t has been discovered
  • Loading branch information
vivien-apple committed Oct 20, 2022
1 parent c279578 commit 1fb1192
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions scripts/tools/check_includes_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
# 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'},
}
25 changes: 15 additions & 10 deletions src/controller/SetUpCodePairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ bool SetUpCodePairer::ConnectToDiscoveredDevice()
// connection attempt fails and calls right back into us to try the next
// thing.
RendezvousParameters params(mDiscoveredParameters.front());
mDiscoveredParameters.pop();
mDiscoveredParameters.pop_front();

params.SetSetupPINCode(mSetUpPINCode);

Expand Down Expand Up @@ -268,8 +268,8 @@ void SetUpCodePairer::OnDiscoveredDeviceOverBle(BLE_CONNECTION_OBJECT connObj)
mWaitingForDiscovery[kBLETransport] = false;

Transport::PeerAddress peerAddress = Transport::PeerAddress::BLE();
mDiscoveredParameters.emplace();
mDiscoveredParameters.back().SetPeerAddress(peerAddress).SetConnectionObject(connObj);
mDiscoveredParameters.emplace_front();
mDiscoveredParameters.front().SetPeerAddress(peerAddress).SetConnectionObject(connObj);
ConnectToDiscoveredDevice();
}

Expand Down Expand Up @@ -338,12 +338,17 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover

ChipLogProgress(Controller, "Discovered device to be commissioned over DNS-SD");

Inet::InterfaceId interfaceId =
nodeData.resolutionData.ipAddress[0].IsIPv6LinkLocal() ? nodeData.resolutionData.interfaceId : Inet::InterfaceId::Null();
Transport::PeerAddress peerAddress =
Transport::PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], nodeData.resolutionData.port, interfaceId);
mDiscoveredParameters.emplace();
mDiscoveredParameters.back().SetPeerAddress(peerAddress);
auto & resolutionData = nodeData.resolutionData;
for (size_t i = 0; i < resolutionData.numIPs; i++)
{
Inet::InterfaceId interfaceId =
resolutionData.ipAddress[i].IsIPv6LinkLocal() ? resolutionData.interfaceId : Inet::InterfaceId::Null();
Transport::PeerAddress peerAddress =
Transport::PeerAddress::UDP(resolutionData.ipAddress[i], resolutionData.port, interfaceId);
mDiscoveredParameters.emplace_back();
mDiscoveredParameters.back().SetPeerAddress(peerAddress);
}

ConnectToDiscoveredDevice();
}

Expand Down Expand Up @@ -396,7 +401,7 @@ void SetUpCodePairer::ResetDiscoveryState()

while (!mDiscoveredParameters.empty())
{
mDiscoveredParameters.pop();
mDiscoveredParameters.pop_front();
}

mLastPASEError = CHIP_NO_ERROR;
Expand Down
6 changes: 3 additions & 3 deletions src/controller/SetUpCodePairer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include <controller/DeviceDiscoveryDelegate.h>

#include <queue>
#include <deque>

namespace chip {
namespace Controller {
Expand Down Expand Up @@ -177,10 +177,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<RendezvousParameters> mDiscoveredParameters;
std::deque<RendezvousParameters> mDiscoveredParameters;

// mWaitingForPASE is true if we have called either
// EstablishPASEConnection or PairDevice on mCommissioner and are now just
Expand Down

0 comments on commit 1fb1192

Please sign in to comment.