diff --git a/src/controller/python/test/test_scripts/network_commissioning.py b/src/controller/python/test/test_scripts/network_commissioning.py index 39a6d875aec9ca..d33d0b6d11108c 100644 --- a/src/controller/python/test/test_scripts/network_commissioning.py +++ b/src/controller/python/test/test_scripts/network_commissioning.py @@ -279,8 +279,6 @@ async def test_thread(self, endpointId): raise AssertionError( f"LastNetworkID, LastConnectErrorValue and LastNetworkingStatus should not be Null") - # TODO: Linux Thread driver cannot get infomation of current connected networks. - ''' logger.info(f"Check network list") res = await self._devCtrl.ReadAttribute(nodeid=self._nodeid, attributes=[(endpointId, Clusters.NetworkCommissioning.Attributes.Networks)], returnClusterObject=True) networkList = res[endpointId][Clusters.NetworkCommissioning].networks @@ -294,7 +292,6 @@ async def test_thread(self, endpointId): if not networkList[0].connected: raise AssertionError( f"Unexpected result: network is not marked as connected") - ''' async def run(self): try: diff --git a/src/platform/Linux/ThreadStackManagerImpl.cpp b/src/platform/Linux/ThreadStackManagerImpl.cpp index bdf8c5ba74c5f2..e66ab2d06aab81 100644 --- a/src/platform/Linux/ThreadStackManagerImpl.cpp +++ b/src/platform/Linux/ThreadStackManagerImpl.cpp @@ -238,15 +238,25 @@ CHIP_ERROR ThreadStackManagerImpl::_GetThreadProvision(ByteSpan & netInfo) VerifyOrReturnError(mProxy, CHIP_ERROR_INCORRECT_STATE); { - // TODO: The following code does not works actually, since otbr-posix does not emit signals for properties changes. Which is - // required for gdbus to caching properties. + std::unique_ptr err; + std::unique_ptr value( - openthread_io_openthread_border_router_dup_active_dataset_tlvs(mProxy.get())); + g_dbus_proxy_call_sync(G_DBUS_PROXY(mProxy.get()), "org.freedesktop.DBus.Properties.Get", + g_variant_new("(ss)", "io.openthread.BorderRouter", "ActiveDatasetTlvs"), G_DBUS_CALL_FLAGS_NONE, + -1, nullptr, &MakeUniquePointerReceiver(err).Get())); + + if (err) + { + ChipLogError(DeviceLayer, "openthread: failed to read ActiveDatasetTlvs property: %s", err->message); + return CHIP_ERROR_INTERNAL; + } + if (value == nullptr) { netInfo = ByteSpan(); return CHIP_ERROR_KEY_NOT_FOUND; } + GBytes * bytes = g_variant_get_data_as_bytes(value.get()); gsize size; const uint8_t * data = reinterpret_cast(g_bytes_get_data(bytes, &size)); @@ -270,13 +280,29 @@ void ThreadStackManagerImpl::_ErasePersistentInfo() bool ThreadStackManagerImpl::_IsThreadEnabled() { - if (!mProxy) + VerifyOrReturnError(mProxy, false); + + std::unique_ptr err; + + std::unique_ptr value( + g_dbus_proxy_call_sync(G_DBUS_PROXY(mProxy.get()), "org.freedesktop.DBus.Properties.Get", + g_variant_new("(ss)", "io.openthread.BorderRouter", "DeviceRole"), G_DBUS_CALL_FLAGS_NONE, -1, + nullptr, &MakeUniquePointerReceiver(err).Get())); + + if (err) { + ChipLogError(DeviceLayer, "openthread: failed to read DeviceRole property: %s", err->message); return false; } - std::unique_ptr role(openthread_io_openthread_border_router_dup_device_role(mProxy.get())); - return (strcmp(role.get(), kOpenthreadDeviceRoleDisabled) != 0); + if (value == nullptr) + { + return false; + } + + const gchar * role = g_variant_get_string(value.get(), nullptr); + + return (strcmp(role, kOpenthreadDeviceRoleDisabled) != 0); } bool ThreadStackManagerImpl::_IsThreadAttached()