From 8ada09c4e1b0e89ccccc24178ac663311aa61cd8 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 5 Mar 2024 09:20:36 +0100 Subject: [PATCH 01/11] Update to master branch --- ...kit-requirement-to-fix-ptpython-vers.patch | 27 --- ...3-Linux-Increase-number-of-endpoints.patch | 0 ...ommissioning-with-code-on-network-on.patch | 90 --------- ...erface-ID-from-IP-address-string-as-.patch | 54 ----- ...w-early-logging-initialization-31945.patch | 51 ----- ...-Make-Logging-Filtering-global-31944.patch | 186 ------------------ ...ip-interfaces-without-IPv4-addresses.patch | 96 --------- connectedhomeip | 2 +- 8 files changed, 1 insertion(+), 505 deletions(-) delete mode 100644 0003-Bump-prompt-toolkit-requirement-to-fix-ptpython-vers.patch rename 0009-Linux-Increase-number-of-endpoints.patch => 0003-Linux-Increase-number-of-endpoints.patch (100%) delete mode 100644 0004-Python-Support-commissioning-with-code-on-network-on.patch delete mode 100644 0005-Python-Parse-Interface-ID-from-IP-address-string-as-.patch delete mode 100644 0006-Python-Allow-early-logging-initialization-31945.patch delete mode 100644 0007-Python-Make-Logging-Filtering-global-31944.patch delete mode 100644 0008-MinMDNS-skip-interfaces-without-IPv4-addresses.patch diff --git a/0003-Bump-prompt-toolkit-requirement-to-fix-ptpython-vers.patch b/0003-Bump-prompt-toolkit-requirement-to-fix-ptpython-vers.patch deleted file mode 100644 index 27c20c0..0000000 --- a/0003-Bump-prompt-toolkit-requirement-to-fix-ptpython-vers.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 1536ca20c5917578ca40ce509400e97b52751788 Mon Sep 17 00:00:00 2001 -Message-ID: <1536ca20c5917578ca40ce509400e97b52751788.1703082429.git.stefan@agner.ch> -From: Andrei Litvin -Date: Wed, 13 Dec 2023 13:27:16 -0500 -Subject: [PATCH] Bump prompt-toolkit requirement to fix ptpython version - update (#30987) - ---- - scripts/setup/constraints.txt | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/scripts/setup/constraints.txt b/scripts/setup/constraints.txt -index b0e9aed4ae..ad80df20c4 100644 ---- a/scripts/setup/constraints.txt -+++ b/scripts/setup/constraints.txt -@@ -163,7 +163,7 @@ portpicker==1.5.2 - # via - # -r requirements.all.txt - # mobly --prompt-toolkit==3.0.38 -+prompt-toolkit==3.0.43 - # via ipython - protobuf==4.24.4 - # via --- -2.43.0 - diff --git a/0009-Linux-Increase-number-of-endpoints.patch b/0003-Linux-Increase-number-of-endpoints.patch similarity index 100% rename from 0009-Linux-Increase-number-of-endpoints.patch rename to 0003-Linux-Increase-number-of-endpoints.patch diff --git a/0004-Python-Support-commissioning-with-code-on-network-on.patch b/0004-Python-Support-commissioning-with-code-on-network-on.patch deleted file mode 100644 index ba5a222..0000000 --- a/0004-Python-Support-commissioning-with-code-on-network-on.patch +++ /dev/null @@ -1,90 +0,0 @@ -From e34fbf7b58908fa777335cbc4da4a0d6b26fe6d7 Mon Sep 17 00:00:00 2001 -Message-ID: -From: Stefan Agner -Date: Thu, 14 Dec 2023 13:33:05 +0100 -Subject: [PATCH] [Python] Support commissioning with code on network only - (#31000) - -* [Python] Support commissioning with code on network only - -Add an additional parameter to support commissioning on network only. -This is useful when a manual pairing code is given and we know the -device is on the network already. - -* Use consistent casing for newly added parameter ---- - .../python/ChipDeviceController-ScriptBinding.cpp | 10 +++++++--- - src/controller/python/chip/ChipDeviceCtrl.py | 6 +++--- - 2 files changed, 10 insertions(+), 6 deletions(-) - -diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp -index a7732a4836..c4b12570fd 100644 ---- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp -+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp -@@ -50,6 +50,7 @@ - #include - #include - #include -+#include - - #include - #include -@@ -135,7 +136,7 @@ PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissio - PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommissioner * devCtrl, const char * peerAddrStr, - uint32_t setupPINCode, chip::NodeId nodeid); - PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload, -- chip::NodeId nodeid); -+ chip::NodeId nodeid, bool networkOnly); - PyChipError pychip_DeviceController_UnpairDevice(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId remoteDeviceId, - DeviceUnpairingCompleteFunct callback); - PyChipError pychip_DeviceController_SetThreadOperationalDataset(const char * threadOperationalDataset, uint32_t size); -@@ -397,10 +398,13 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission - } - - PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload, -- chip::NodeId nodeid) -+ chip::NodeId nodeid, bool networkOnly) - { -+ chip::Controller::DiscoveryType discoveryType = chip::Controller::DiscoveryType::kAll; - sPairingDelegate.SetExpectingPairingComplete(true); -- return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters)); -+ if (networkOnly) -+ discoveryType = chip::Controller::DiscoveryType::kDiscoveryNetworkOnly; -+ return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters, discoveryType)); - } - - namespace { -diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py -index 22ae11cda6..de6f1fff03 100644 ---- a/src/controller/python/chip/ChipDeviceCtrl.py -+++ b/src/controller/python/chip/ChipDeviceCtrl.py -@@ -1422,7 +1422,7 @@ class ChipDeviceControllerBase(): - self._dmLib.pychip_DeviceController_ConnectIP.restype = PyChipError - - self._dmLib.pychip_DeviceController_ConnectWithCode.argtypes = [ -- c_void_p, c_char_p, c_uint64] -+ c_void_p, c_char_p, c_uint64, c_bool] - self._dmLib.pychip_DeviceController_ConnectWithCode.restype = PyChipError - - self._dmLib.pychip_DeviceController_UnpairDevice.argtypes = [ -@@ -1726,7 +1726,7 @@ class ChipDeviceController(ChipDeviceControllerBase): - return PyChipError(CHIP_ERROR_TIMEOUT) - return self._ChipStack.commissioningEventRes - -- def CommissionWithCode(self, setupPayload: str, nodeid: int) -> PyChipError: -+ def CommissionWithCode(self, setupPayload: str, nodeid: int, networkOnly: bool = False) -> PyChipError: - self.CheckIsActive() - - setupPayload = setupPayload.encode() + b'\0' -@@ -1739,7 +1739,7 @@ class ChipDeviceController(ChipDeviceControllerBase): - - self._ChipStack.CallAsync( - lambda: self._dmLib.pychip_DeviceController_ConnectWithCode( -- self.devCtrl, setupPayload, nodeid) -+ self.devCtrl, setupPayload, nodeid, networkOnly) - ) - if not self._ChipStack.commissioningCompleteEvent.isSet(): - # Error 50 is a timeout --- -2.43.0 - diff --git a/0005-Python-Parse-Interface-ID-from-IP-address-string-as-.patch b/0005-Python-Parse-Interface-ID-from-IP-address-string-as-.patch deleted file mode 100644 index f42625c..0000000 --- a/0005-Python-Parse-Interface-ID-from-IP-address-string-as-.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 5b5e383674e78115107c7a95eb563902cd6b6014 Mon Sep 17 00:00:00 2001 -Message-ID: <5b5e383674e78115107c7a95eb563902cd6b6014.1704821887.git.stefan@agner.ch> -From: Stefan Agner -Date: Tue, 9 Jan 2024 18:35:50 +0100 -Subject: [PATCH] [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 a7732a4836..e3e4de8d88 100644 ---- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp -+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp -@@ -383,13 +383,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); -@@ -577,10 +578,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); --- -2.43.0 - diff --git a/0006-Python-Allow-early-logging-initialization-31945.patch b/0006-Python-Allow-early-logging-initialization-31945.patch deleted file mode 100644 index 57dbbff..0000000 --- a/0006-Python-Allow-early-logging-initialization-31945.patch +++ /dev/null @@ -1,51 +0,0 @@ -From e4d6e50d1485110068e85ec28836b37d386fbd47 Mon Sep 17 00:00:00 2001 -From: Stefan Agner -Date: Tue, 13 Feb 2024 22:38:46 +0100 -Subject: [PATCH] [Python] Allow early logging initialization (#31945) - -* [Python] Allow early logging initialization - -Allow to initialize logging before initializing the stack. Similar to -tracing, logging doesn't need the stack to be setup. This allows to -redirect logging to Python as early as possible. - -* Log using chip.native module for clarity - -Use chip.native module for all redirected logs. This separates it from -logs written by the Python bindings themselfs. ---- - src/controller/python/chip/logging/__init__.py | 2 +- - src/controller/python/chip/logging/library_handle.py | 4 +++- - 2 files changed, 4 insertions(+), 2 deletions(-) - -diff --git a/src/controller/python/chip/logging/__init__.py b/src/controller/python/chip/logging/__init__.py -index 980c33ac92..6916c8b272 100644 ---- a/src/controller/python/chip/logging/__init__.py -+++ b/src/controller/python/chip/logging/__init__.py -@@ -32,7 +32,7 @@ def _RedirectToPythonLogging(category, module, message): - module = module.decode('utf-8') - message = message.decode('utf-8') - -- logger = logging.getLogger('chip.%s' % module) -+ logger = logging.getLogger('chip.native.%s' % module) - - if category == ERROR_CATEGORY_ERROR: - logger.error("%s", message) -diff --git a/src/controller/python/chip/logging/library_handle.py b/src/controller/python/chip/logging/library_handle.py -index ae34f502fd..f74a810b46 100644 ---- a/src/controller/python/chip/logging/library_handle.py -+++ b/src/controller/python/chip/logging/library_handle.py -@@ -27,7 +27,9 @@ def _GetLoggingLibraryHandle() -> ctypes.CDLL: - native methods. - """ - -- handle = chip.native.GetLibraryHandle() -+ # Getting a handle without requiring init, as logging methods -+ # do not require chip stack startup -+ handle = chip.native.GetLibraryHandle(chip.native.HandleFlags(0)) - - # Uses one of the type decorators as an indicator for everything being - # initialized. --- -2.43.0 - diff --git a/0007-Python-Make-Logging-Filtering-global-31944.patch b/0007-Python-Make-Logging-Filtering-global-31944.patch deleted file mode 100644 index 5242566..0000000 --- a/0007-Python-Make-Logging-Filtering-global-31944.patch +++ /dev/null @@ -1,186 +0,0 @@ -From bf8ce26830a60e0d247f37f3b26d2f2244cb986d Mon Sep 17 00:00:00 2001 -From: Stefan Agner -Date: Wed, 14 Feb 2024 15:11:44 +0100 -Subject: [PATCH] [Python] Make Logging Filtering global (#31944) - -Log filtering is a global affair, so move the filtering functions to a -global context too. This allows to setup logging before creating any -device controller. It aligns with how the SDK treats logging. - -Also enable log filtering for the Linux platform to make the -functionality useful on Linux. ---- - src/controller/python/BUILD.gn | 1 + - .../ChipDeviceController-ScriptBinding.cpp | 20 ---------- - src/controller/python/chip/ChipDeviceCtrl.py | 17 --------- - .../python/chip/logging/LoggingFilter.cpp | 37 +++++++++++++++++++ - .../python/chip/logging/__init__.py | 13 +++++++ - src/platform/Linux/CHIPPlatformConfig.h | 2 +- - 6 files changed, 52 insertions(+), 38 deletions(-) - create mode 100644 src/controller/python/chip/logging/LoggingFilter.cpp - -diff --git a/src/controller/python/BUILD.gn b/src/controller/python/BUILD.gn -index 140ef1e08d..5fc2212098 100644 ---- a/src/controller/python/BUILD.gn -+++ b/src/controller/python/BUILD.gn -@@ -81,6 +81,7 @@ shared_library("ChipDeviceCtrl") { - "chip/internal/ChipThreadWork.cpp", - "chip/internal/ChipThreadWork.h", - "chip/internal/CommissionerImpl.cpp", -+ "chip/logging/LoggingFilter.cpp", - "chip/logging/LoggingRedirect.cpp", - "chip/native/ChipMainLoopWork.h", - "chip/native/PyChipError.cpp", -diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp -index 2576a36030..b4f2edb295 100644 ---- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp -+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp -@@ -71,7 +71,6 @@ - #include - #include - #include --#include - #include - #include - #include -@@ -200,9 +199,6 @@ PyChipError pychip_ScriptDevicePairingDelegate_SetOpenWindowCompleteCallback( - // BLE - PyChipError pychip_DeviceCommissioner_CloseBleConnection(chip::Controller::DeviceCommissioner * devCtrl); - --uint8_t pychip_DeviceController_GetLogFilter(); --void pychip_DeviceController_SetLogFilter(uint8_t category); -- - const char * pychip_Stack_ErrorToString(ChipError::StorageType err); - const char * pychip_Stack_StatusReportToString(uint32_t profileId, uint16_t statusCode); - void pychip_Stack_SetLogFunct(LogMessageFunct logFunct); -@@ -353,22 +349,6 @@ const char * pychip_DeviceController_StatusReportToString(uint32_t profileId, ui - return nullptr; - } - --uint8_t pychip_DeviceController_GetLogFilter() --{ --#if _CHIP_USE_LOGGING -- return chip::Logging::GetLogFilter(); --#else -- return chip::Logging::kLogCategory_None; --#endif --} -- --void pychip_DeviceController_SetLogFilter(uint8_t category) --{ --#if _CHIP_USE_LOGGING -- chip::Logging::SetLogFilter(category); --#endif --} -- - PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissioner * devCtrl, uint16_t discriminator, - uint32_t setupPINCode, chip::NodeId nodeid) - { -diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py -index 2297dfff30..2400d543f6 100644 ---- a/src/controller/python/chip/ChipDeviceCtrl.py -+++ b/src/controller/python/chip/ChipDeviceCtrl.py -@@ -1480,23 +1480,6 @@ class ChipDeviceControllerBase(): - - return self._Cluster.ListClusterAttributes() - -- def SetLogFilter(self, category): -- self.CheckIsActive() -- -- if category < 0 or category > pow(2, 8): -- raise ValueError("category must be an unsigned 8-bit integer") -- -- self._ChipStack.Call( -- lambda: self._dmLib.pychip_DeviceController_SetLogFilter(category) -- ) -- -- def GetLogFilter(self): -- self.CheckIsActive() -- -- self._ChipStack.Call( -- lambda: self._dmLib.pychip_DeviceController_GetLogFilter() -- ) -- - def SetBlockingCB(self, blockingCB): - self.CheckIsActive() - -diff --git a/src/controller/python/chip/logging/LoggingFilter.cpp b/src/controller/python/chip/logging/LoggingFilter.cpp -new file mode 100644 -index 0000000000..52271dc3ae ---- /dev/null -+++ b/src/controller/python/chip/logging/LoggingFilter.cpp -@@ -0,0 +1,37 @@ -+/* -+ * -+ * Copyright (c) 2024 Project CHIP Authors -+ * -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+#include -+ -+extern "C" { -+ -+uint8_t pychip_logging_GetLogFilter() -+{ -+#if _CHIP_USE_LOGGING -+ return chip::Logging::GetLogFilter(); -+#else -+ return chip::Logging::kLogCategory_None; -+#endif -+} -+ -+void pychip_logging_SetLogFilter(uint8_t category) -+{ -+#if _CHIP_USE_LOGGING -+ chip::Logging::SetLogFilter(category); -+#endif -+} -+} -diff --git a/src/controller/python/chip/logging/__init__.py b/src/controller/python/chip/logging/__init__.py -index 6916c8b272..047d3f4f8e 100644 ---- a/src/controller/python/chip/logging/__init__.py -+++ b/src/controller/python/chip/logging/__init__.py -@@ -51,3 +51,16 @@ def RedirectToPythonLogging(): - - handle = _GetLoggingLibraryHandle() - handle.pychip_logging_set_callback(_RedirectToPythonLogging) -+ -+ -+def SetLogFilter(category): -+ if category < 0 or category > pow(2, 8): -+ raise ValueError("category must be an unsigned 8-bit integer") -+ -+ handle = _GetLoggingLibraryHandle() -+ handle.pychip_logging_SetLogFilter(category) -+ -+ -+def GetLogFilter(): -+ handle = _GetLoggingLibraryHandle() -+ return handle.pychip_logging_GetLogFilter() -diff --git a/src/platform/Linux/CHIPPlatformConfig.h b/src/platform/Linux/CHIPPlatformConfig.h -index 788fe9b80c..9e2832307f 100644 ---- a/src/platform/Linux/CHIPPlatformConfig.h -+++ b/src/platform/Linux/CHIPPlatformConfig.h -@@ -57,7 +57,7 @@ using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *; - #endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS - - #ifndef CHIP_LOG_FILTERING --#define CHIP_LOG_FILTERING 0 -+#define CHIP_LOG_FILTERING 1 - #endif // CHIP_LOG_FILTERING - - #ifndef CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS --- -2.43.0 - diff --git a/0008-MinMDNS-skip-interfaces-without-IPv4-addresses.patch b/0008-MinMDNS-skip-interfaces-without-IPv4-addresses.patch deleted file mode 100644 index 0e6a8b2..0000000 --- a/0008-MinMDNS-skip-interfaces-without-IPv4-addresses.patch +++ /dev/null @@ -1,96 +0,0 @@ -From 72e9a1c20118b6c41c750a8bcaca578ff85488e2 Mon Sep 17 00:00:00 2001 -From: Stefan Agner -Date: Wed, 28 Feb 2024 10:38:37 +0100 -Subject: [PATCH] MinMDNS skip interfaces without IPv4 addresses - -IPv4 multicast require an IPv4 address to be present on a particular -interface. Skip interfaces without IPv4 addresses in the default -address policy. This avoids errors when trying to join the multicast -group later on: -MDNS failed to join multicast group on veth3cdf62f for address type IPv4: src/inet/UDPEndPointImplSockets.cpp:777: Inet Error 0x00000110: Address not found ---- - .../minimal_mdns/AddressPolicy_LibNlImpl.cpp | 42 +++++++++++++++++-- - 1 file changed, 38 insertions(+), 4 deletions(-) - -diff --git a/src/lib/dnssd/minimal_mdns/AddressPolicy_LibNlImpl.cpp b/src/lib/dnssd/minimal_mdns/AddressPolicy_LibNlImpl.cpp -index e73627f423..b1802c8d25 100644 ---- a/src/lib/dnssd/minimal_mdns/AddressPolicy_LibNlImpl.cpp -+++ b/src/lib/dnssd/minimal_mdns/AddressPolicy_LibNlImpl.cpp -@@ -48,6 +48,7 @@ private: - - nl_sock * mNlSocket = nullptr; - nl_cache * mNlCache = nullptr; -+ nl_cache * mNlAddrCache = nullptr; - nl_object * mCurrentLink = nullptr; - IPAddressType mCurrentLinkType = IPAddressType::kUnknown; - -@@ -94,6 +95,12 @@ AllListenIterator::~AllListenIterator() - mNlCache = nullptr; - } - -+ if (mNlAddrCache != nullptr) -+ { -+ nl_cache_free(mNlAddrCache); -+ mNlAddrCache = nullptr; -+ } -+ - if (mNlSocket != nullptr) - { - nl_socket_free(mNlSocket); -@@ -151,7 +158,6 @@ bool AllListenIterator::Next(InterfaceId * id, IPAddressType * type) - while (true) - { - #if INET_CONFIG_ENABLE_IPV4 -- // FOR IPv4, report all interfaces as 'try IPv4 here as well' - if (mCurrentLinkType == IPAddressType::kIPv6) - { - mCurrentLinkType = IPAddressType::kIPv4; -@@ -176,14 +182,42 @@ bool AllListenIterator::Next(InterfaceId * id, IPAddressType * type) - continue; - } - -- int idx = rtnl_link_get_ifindex(CurrentLink()); -- if (idx == 0) -+ int ifindex = rtnl_link_get_ifindex(CurrentLink()); -+ if (ifindex == 0) - { - // Invalid index, move to the next interface - continue; - } - -- *id = InterfaceId(idx); -+ // For IPv4, report only interfaces which have an IPv4 address -+ if (mCurrentLinkType == IPAddressType::kIPv4) -+ { -+ if (mNlAddrCache == nullptr) -+ { -+ int result = rtnl_addr_alloc_cache(mNlSocket, &mNlAddrCache); -+ if (result != 0) -+ { -+ ChipLogError(Inet, "Failed to cache addresses"); -+ return false; -+ } -+ } -+ -+ // Find IPv4 address for this interface -+ struct rtnl_addr * filter = rtnl_addr_alloc(); -+ rtnl_addr_set_family(filter, AF_INET); -+ rtnl_addr_set_ifindex(filter, ifindex); -+ -+ struct nl_object * addr = nl_cache_find(mNlAddrCache, OBJ_CAST(filter)); -+ nl_object_put(OBJ_CAST(filter)); -+ -+ // No IPv4 address, skip this interface for IPv4. -+ if (addr == nullptr) -+ continue; -+ -+ nl_object_put(addr); -+ } -+ -+ *id = InterfaceId(ifindex); - *type = mCurrentLinkType; // advancing should have set this - return true; - } --- -2.44.0 - diff --git a/connectedhomeip b/connectedhomeip index 181b0cb..3d47e35 160000 --- a/connectedhomeip +++ b/connectedhomeip @@ -1 +1 @@ -Subproject commit 181b0cb14ff007ec912f2ba6627e05dfb066c008 +Subproject commit 3d47e357d7626103c97d8a9abc3a64ea1f88276a From 3554056a4859ea182e348e40f77b18b4499e4316 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 5 Mar 2024 11:25:53 +0100 Subject: [PATCH 02/11] Adjust configuration for depandabot --- .github/dependabot.yml | 1 + .gitmodules | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9d26334..dcc2e6b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,6 +6,7 @@ updates: - dependency-name: "connectedhomeip" schedule: interval: "daily" + target-branch: main - package-ecosystem: "github-actions" directory: "/" schedule: diff --git a/.gitmodules b/.gitmodules index 682e0dc..9edf119 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "connectedhomeip"] path = connectedhomeip url = https://github.com/project-chip/connectedhomeip.git + branch = master From e84f14d078ba80281bb4245b7899e257a82d1fab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 04:16:28 +0000 Subject: [PATCH 03/11] Bump connectedhomeip from `3d47e35` to `e52724f` Bumps [connectedhomeip](https://github.com/project-chip/connectedhomeip) from `3d47e35` to `e52724f`. - [Release notes](https://github.com/project-chip/connectedhomeip/releases) - [Commits](https://github.com/project-chip/connectedhomeip/compare/3d47e357d7626103c97d8a9abc3a64ea1f88276a...e52724f70f990dc1bb7daeb114db651f19653e6d) --- updated-dependencies: - dependency-name: connectedhomeip dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- connectedhomeip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectedhomeip b/connectedhomeip index 3d47e35..e52724f 160000 --- a/connectedhomeip +++ b/connectedhomeip @@ -1 +1 @@ -Subproject commit 3d47e357d7626103c97d8a9abc3a64ea1f88276a +Subproject commit e52724f70f990dc1bb7daeb114db651f19653e6d From 29c1c507361f19d530aa360a04d669ff12f04837 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 04:11:06 +0000 Subject: [PATCH 04/11] Bump connectedhomeip from `e52724f` to `f7a9b59` Bumps [connectedhomeip](https://github.com/project-chip/connectedhomeip) from `e52724f` to `f7a9b59`. - [Release notes](https://github.com/project-chip/connectedhomeip/releases) - [Commits](https://github.com/project-chip/connectedhomeip/compare/e52724f70f990dc1bb7daeb114db651f19653e6d...f7a9b5931bb733fd6f07bd5ae491ec0b841be292) --- updated-dependencies: - dependency-name: connectedhomeip dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- connectedhomeip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectedhomeip b/connectedhomeip index e52724f..f7a9b59 160000 --- a/connectedhomeip +++ b/connectedhomeip @@ -1 +1 @@ -Subproject commit e52724f70f990dc1bb7daeb114db651f19653e6d +Subproject commit f7a9b5931bb733fd6f07bd5ae491ec0b841be292 From 84086fa6ebffb5c9f2d271e51c47344c0dd45287 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 04:44:22 +0000 Subject: [PATCH 05/11] Bump softprops/action-gh-release from 1 to 2 Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2. - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2) --- updated-dependencies: - dependency-name: softprops/action-gh-release dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3b1f444..164a513 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -139,7 +139,7 @@ jobs: name: chip-wheels-linux-${{ matrix.arch.name }} path: ./connectedhomeip/out/controller/python/*.whl - name: Upload wheels as release assets - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: files: project-chip/out/controller/python/*.whl @@ -231,7 +231,7 @@ jobs: name: chip-wheels-macosx-${{ matrix.arch.name }} path: project-chip/out/controller/python/*.whl - name: Upload wheels as release assets - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: files: connectedhomeip/out/controller/python/*.whl From d21ec4a5cf70f617e02e8adaeb23c3e958f481ab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 04:34:02 +0000 Subject: [PATCH 06/11] Bump connectedhomeip from `f7a9b59` to `a97bad9` Bumps [connectedhomeip](https://github.com/project-chip/connectedhomeip) from `f7a9b59` to `a97bad9`. - [Release notes](https://github.com/project-chip/connectedhomeip/releases) - [Commits](https://github.com/project-chip/connectedhomeip/compare/f7a9b5931bb733fd6f07bd5ae491ec0b841be292...a97bad9386921ea7a0c1e8cfe0e71e0b298f6a85) --- updated-dependencies: - dependency-name: connectedhomeip dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- connectedhomeip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectedhomeip b/connectedhomeip index f7a9b59..a97bad9 160000 --- a/connectedhomeip +++ b/connectedhomeip @@ -1 +1 @@ -Subproject commit f7a9b5931bb733fd6f07bd5ae491ec0b841be292 +Subproject commit a97bad9386921ea7a0c1e8cfe0e71e0b298f6a85 From 487b22e6e89b13f858ef54977f275d5dabdb3cb9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 04:17:10 +0000 Subject: [PATCH 07/11] Bump connectedhomeip from `a97bad9` to `12d8487` Bumps [connectedhomeip](https://github.com/project-chip/connectedhomeip) from `a97bad9` to `12d8487`. - [Release notes](https://github.com/project-chip/connectedhomeip/releases) - [Commits](https://github.com/project-chip/connectedhomeip/compare/a97bad9386921ea7a0c1e8cfe0e71e0b298f6a85...12d8487e4542f6f13f8f96785dac7ec70f93b1d4) --- updated-dependencies: - dependency-name: connectedhomeip dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- connectedhomeip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectedhomeip b/connectedhomeip index a97bad9..12d8487 160000 --- a/connectedhomeip +++ b/connectedhomeip @@ -1 +1 @@ -Subproject commit a97bad9386921ea7a0c1e8cfe0e71e0b298f6a85 +Subproject commit 12d8487e4542f6f13f8f96785dac7ec70f93b1d4 From bec8b918531f02563b049e5771693aaaaba29cf9 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 18 Mar 2024 22:53:38 +0100 Subject: [PATCH 08/11] Don't fetch the Matter SDK recursively The checkout scripts will take care of submodule updates within the connectedhomeip repsitory. --- .gitmodules | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitmodules b/.gitmodules index 9edf119..c51b07a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,4 @@ path = connectedhomeip url = https://github.com/project-chip/connectedhomeip.git branch = master + fetchRecurseSubmodules = false From 23f65bc1fa38bb42a1064cdb41834b994e35014a Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 27 Mar 2024 16:01:18 +0100 Subject: [PATCH 09/11] Bump connectedhomeip from `12d8487` to `5bb5c9e` Bumps [connectedhomeip](https://github.com/project-chip/connectedhomeip) from `12d8487` to `5bb5c9e`. - [Commits](https://github.com/project-chip/connectedhomeip/compare/12d8487e4542f6f13f8f96785dac7ec70f93b1d4...5bb5c9e23d532cea40476fc0bd1d3008522792ba) Commit `5bb5c9e` happens to be the divergence point and the current commit of the v1.3-branch. --- connectedhomeip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectedhomeip b/connectedhomeip index 12d8487..5bb5c9e 160000 --- a/connectedhomeip +++ b/connectedhomeip @@ -1 +1 @@ -Subproject commit 12d8487e4542f6f13f8f96785dac7ec70f93b1d4 +Subproject commit 5bb5c9e23d532cea40476fc0bd1d3008522792ba From 6a48e360d65fa27d84b2e78e50db70063d28596c Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 27 Mar 2024 19:13:52 +0100 Subject: [PATCH 10/11] Upload all wheels from correct path Upload wheels from the connectedhomeip directory which is now where the Matter SDK lives. This makes sure that wheel builds for macOS are available as well. --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 164a513..ed821ba 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -142,7 +142,7 @@ jobs: uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: - files: project-chip/out/controller/python/*.whl + files: ./connectedhomeip/out/controller/python/*.whl - name: Upload wheels to PyPI if: startsWith(github.ref, 'refs/tags/') env: @@ -229,7 +229,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: chip-wheels-macosx-${{ matrix.arch.name }} - path: project-chip/out/controller/python/*.whl + path: ./connectedhomeip/out/controller/python/*.whl - name: Upload wheels as release assets uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') From 2e9bad34cba34d73cd2adbd300c4d33f76541fa1 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 28 Mar 2024 12:16:01 +0100 Subject: [PATCH 11/11] Add patch which implements async GetConnectedDevice The call GetConnectedDeviceSync may block for an extended period of time, especially when the CASE session needs to get reestablished. This adds an implementation of GetConnectedDeviceSync which uses asyncio to keep the asyncio event loop running. --- ...nt-async-friendly-GetConnectedDevice.patch | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 0004-Python-Implement-async-friendly-GetConnectedDevice.patch diff --git a/0004-Python-Implement-async-friendly-GetConnectedDevice.patch b/0004-Python-Implement-async-friendly-GetConnectedDevice.patch new file mode 100644 index 0000000..3759f7a --- /dev/null +++ b/0004-Python-Implement-async-friendly-GetConnectedDevice.patch @@ -0,0 +1,133 @@ +From f9fc067ad51d3989a2045f19fc5641971ce1ee20 Mon Sep 17 00:00:00 2001 +From: Stefan Agner +Date: Wed, 27 Mar 2024 22:13:19 +0100 +Subject: [PATCH] [Python] Implement async friendly GetConnectedDevice + +Currently GetConnectedDeviceSync() is blocking e.g. when a new session +needs to be created. This is not asyncio friendly as it blocks the +whole event loop. + +Implement a asyncio friendly variant GetConnectedDevice() which is +a co-routine function which can be awaited. +--- + src/controller/python/chip/ChipDeviceCtrl.py | 62 ++++++++++++++++++-- + 1 file changed, 56 insertions(+), 6 deletions(-) + +diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py +index 369260787d..b3d0aa2d7f 100644 +--- a/src/controller/python/chip/ChipDeviceCtrl.py ++++ b/src/controller/python/chip/ChipDeviceCtrl.py +@@ -823,6 +823,56 @@ class ChipDeviceControllerBase(): + + return DeviceProxyWrapper(returnDevice, self._dmLib) + ++ async def GetConnectedDevice(self, nodeid, allowPASE=True, timeoutMs: int = None): ++ ''' Returns DeviceProxyWrapper upon success.''' ++ self.CheckIsActive() ++ ++ if allowPASE: ++ returnDevice = c_void_p(None) ++ res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceBeingCommissioned( ++ self.devCtrl, nodeid, byref(returnDevice)), timeoutMs) ++ if res.is_success: ++ logging.info('Using PASE connection') ++ return DeviceProxyWrapper(returnDevice) ++ ++ eventLoop = asyncio.get_running_loop() ++ future = eventLoop.create_future() ++ ++ class DeviceAvailableClosure(): ++ def __init__(self, loop, future: asyncio.Future): ++ self._returnDevice = c_void_p(None) ++ self._returnErr = None ++ self._event_loop = loop ++ self._future = future ++ ++ def _deviceAvailable(self): ++ if self._returnDevice.value is not None: ++ self._future.set_result(self._returnDevice) ++ else: ++ self._future.set_exception(self._returnErr.to_exception()) ++ ++ def deviceAvailable(self, device, err): ++ self._returnDevice = c_void_p(device) ++ self._returnErr = err ++ self._event_loop.call_soon_threadsafe(self._deviceAvailable) ++ ctypes.pythonapi.Py_DecRef(ctypes.py_object(self)) ++ ++ closure = DeviceAvailableClosure(eventLoop, future) ++ ctypes.pythonapi.Py_IncRef(ctypes.py_object(closure)) ++ self._ChipStack.Call(lambda: self._dmLib.pychip_GetConnectedDeviceByNodeId( ++ self.devCtrl, nodeid, ctypes.py_object(closure), _DeviceAvailableCallback), ++ timeoutMs).raise_on_error() ++ ++ # The callback might have been received synchronously (during self._ChipStack.Call()). ++ # In that case the Future has already been set it will return immediately ++ if (timeoutMs): ++ timeout = float(timeoutMs) / 1000 ++ await asyncio.wait_for(future, timeout=timeout) ++ else: ++ await future ++ ++ return DeviceProxyWrapper(future.result(), self._dmLib) ++ + def ComputeRoundTripTimeout(self, nodeid, upperLayerProcessingTimeoutMs: int = 0): + ''' Returns a computed timeout value based on the round-trip time it takes for the peer at the other end of the session to + receive a message, process it and send it back. This is computed based on the session type, the type of transport, +@@ -887,7 +937,7 @@ class ChipDeviceControllerBase(): + eventLoop = asyncio.get_running_loop() + future = eventLoop.create_future() + +- device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs) ++ device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs) + + ClusterCommand.TestOnlySendBatchCommands( + future, eventLoop, device.deviceProxy, commands, +@@ -908,7 +958,7 @@ class ChipDeviceControllerBase(): + eventLoop = asyncio.get_running_loop() + future = eventLoop.create_future() + +- device = self.GetConnectedDeviceSync(nodeid, timeoutMs=None) ++ device = await self.GetConnectedDevice(nodeid, timeoutMs=None) + ClusterCommand.TestOnlySendCommandTimedRequestFlagWithNoTimedInvoke( + future, eventLoop, responseType, device.deviceProxy, ClusterCommand.CommandPath( + EndpointId=endpoint, +@@ -940,7 +990,7 @@ class ChipDeviceControllerBase(): + eventLoop = asyncio.get_running_loop() + future = eventLoop.create_future() + +- device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs) ++ device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs) + ClusterCommand.SendCommand( + future, eventLoop, responseType, device.deviceProxy, ClusterCommand.CommandPath( + EndpointId=endpoint, +@@ -981,7 +1031,7 @@ class ChipDeviceControllerBase(): + eventLoop = asyncio.get_running_loop() + future = eventLoop.create_future() + +- device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs) ++ device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs) + + ClusterCommand.SendBatchCommands( + future, eventLoop, device.deviceProxy, commands, +@@ -1031,7 +1081,7 @@ class ChipDeviceControllerBase(): + eventLoop = asyncio.get_running_loop() + future = eventLoop.create_future() + +- device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs) ++ device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs) + + attrs = [] + for v in attributes: +@@ -1259,7 +1309,7 @@ class ChipDeviceControllerBase(): + eventLoop = asyncio.get_running_loop() + future = eventLoop.create_future() + +- device = self.GetConnectedDeviceSync(nodeid) ++ device = await self.GetConnectedDevice(nodeid) + attributePaths = [self._parseAttributePathTuple( + v) for v in attributes] if attributes else None + clusterDataVersionFilters = [self._parseDataVersionFilterTuple( +-- +2.44.0 +