From 792fe006792714edd515dc9b439c625330618a42 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 9 Jan 2024 18:35:50 +0100 Subject: [PATCH 1/2] [Python] Parse Interface ID from IP address string as well Currently, when passing a link-local address with an interface specified using the % notation leads to "CHIP Error 0x0000002F: Invalid argument". Correctly parse the interface ID as well and pass it to the PeerAddress object. --- .../python/ChipDeviceController-ScriptBinding.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index 4979da8acdbe35..5dbe3a3780ea06 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -385,13 +385,14 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission uint32_t setupPINCode, chip::NodeId nodeid) { chip::Inet::IPAddress peerAddr; + chip::Inet::InterfaceId ifaceOutput; chip::Transport::PeerAddress addr; chip::RendezvousParameters params = chip::RendezvousParameters().SetSetupPINCode(setupPINCode); - VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr), ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); + VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr, ifaceOutput), ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); // TODO: IP rendezvous should use TCP connection. - addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr); + addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr).SetInterface(ifaceOutput); params.SetPeerAddress(addr).SetDiscriminator(0); sPairingDelegate.SetExpectingPairingComplete(true); @@ -594,10 +595,11 @@ PyChipError pychip_DeviceController_EstablishPASESessionIP(chip::Controller::Dev uint32_t setupPINCode, chip::NodeId nodeid, uint16_t port) { chip::Inet::IPAddress peerAddr; + chip::Inet::InterfaceId ifaceOutput; chip::Transport::PeerAddress addr; RendezvousParameters params = chip::RendezvousParameters().SetSetupPINCode(setupPINCode); - VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr), ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); - addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr); + VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr, ifaceOutput), ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); + addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr).SetInterface(ifaceOutput); if (port != 0) { addr.SetPort(port); From 329fc47a702f1f8486548b182aa8b2e56848b229 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 9 Jan 2024 17:44:20 +0000 Subject: [PATCH 2/2] Restyled by clang-format --- .../python/ChipDeviceController-ScriptBinding.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index 5dbe3a3780ea06..b8d95292770d71 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -389,7 +389,8 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission chip::Transport::PeerAddress addr; chip::RendezvousParameters params = chip::RendezvousParameters().SetSetupPINCode(setupPINCode); - VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr, ifaceOutput), ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); + VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr, ifaceOutput), + ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); // TODO: IP rendezvous should use TCP connection. addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr).SetInterface(ifaceOutput); @@ -598,7 +599,8 @@ PyChipError pychip_DeviceController_EstablishPASESessionIP(chip::Controller::Dev chip::Inet::InterfaceId ifaceOutput; chip::Transport::PeerAddress addr; RendezvousParameters params = chip::RendezvousParameters().SetSetupPINCode(setupPINCode); - VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr, ifaceOutput), ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); + VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr, ifaceOutput), + ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr).SetInterface(ifaceOutput); if (port != 0) {