From 8ae8954dabd50675afa4bbdfb081306c19c27606 Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Wed, 22 May 2024 18:48:09 +0800 Subject: [PATCH] ESP32: fix some build errors when enabling platform mdns/disabling srp client (#33544) * ESP32: fix some build errors when enabling platform mdns/disable srp client * Restyled by clang-format --------- Co-authored-by: Restyled.io --- src/platform/ESP32/CHIPDevicePlatformConfig.h | 9 +++++++++ src/platform/ESP32/DnssdImpl.cpp | 19 +++++++++---------- src/platform/ESP32/ESP32DnssdImpl.cpp | 2 +- ...GenericThreadStackManagerImpl_OpenThread.h | 3 ++- .../OpenThread/OpenThreadDnssdImpl.cpp | 4 ++++ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/platform/ESP32/CHIPDevicePlatformConfig.h b/src/platform/ESP32/CHIPDevicePlatformConfig.h index e6d7870c35fda6..e347df109d1e3a 100644 --- a/src/platform/ESP32/CHIPDevicePlatformConfig.h +++ b/src/platform/ESP32/CHIPDevicePlatformConfig.h @@ -54,8 +54,17 @@ #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0 #endif // CONFIG_ENABLE_MATTER_OVER_THREAD +#ifdef CONFIG_OPENTHREAD_SRP_CLIENT #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT CONFIG_OPENTHREAD_SRP_CLIENT +#else +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 0 +#endif // CONFIG_OPENTHREAD_SRP_CLIENT + +#ifdef CONFIG_OPENTHREAD_DNS_CLIENT #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT CONFIG_OPENTHREAD_DNS_CLIENT +#else +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 0 +#endif // CONFIG_OPENTHREAD_DNS_CLIENT #ifdef CONFIG_ENABLE_ETHERNET_TELEMETRY #define CHIP_DEVICE_CONFIG_ENABLE_ETHERNET 1 diff --git a/src/platform/ESP32/DnssdImpl.cpp b/src/platform/ESP32/DnssdImpl.cpp index 1ca07213a866c6..df83ec818ead57 100644 --- a/src/platform/ESP32/DnssdImpl.cpp +++ b/src/platform/ESP32/DnssdImpl.cpp @@ -30,6 +30,7 @@ #endif using namespace ::chip::DeviceLayer; +using chip::DeviceLayer::Internal::ESP32Utils; namespace chip { namespace Dnssd { @@ -39,7 +40,7 @@ CHIP_ERROR ChipDnssdInit(DnssdAsyncReturnCallback initCallback, DnssdAsyncReturn #if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET ReturnErrorOnFailure(EspDnssdInit(initCallback, errorCallback, context)); #endif -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT ReturnErrorOnFailure(OpenThreadDnssdInit(initCallback, errorCallback, context)); #endif return CHIP_NO_ERROR; @@ -52,7 +53,7 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service, DnssdPublishCal #if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET ReturnErrorOnFailure(EspDnssdPublishService(service, callback, context)); #endif -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT if (ConnectivityMgr().IsThreadProvisioned()) { ReturnErrorOnFailure(OpenThreadDnssdPublishService(service, callback, context)); @@ -66,7 +67,7 @@ CHIP_ERROR ChipDnssdRemoveServices() #if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET ReturnErrorOnFailure(EspDnssdRemoveServices()); #endif -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT if (ConnectivityMgr().IsThreadProvisioned()) { ReturnErrorOnFailure(OpenThreadDnssdRemoveServices()); @@ -77,7 +78,7 @@ CHIP_ERROR ChipDnssdRemoveServices() CHIP_ERROR ChipDnssdFinalizeServiceUpdate() { -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT if (ConnectivityMgr().IsThreadProvisioned()) { ReturnErrorOnFailure(OpenThreadDnssdFinalizeServiceUpdate()); @@ -91,13 +92,12 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi intptr_t * browseIdentifier) { #if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET - if (ConnectivityMgr().IsWiFiStationProvisioned() || - Internal::ESP32Utils::HasIPv6LinkLocalAddress(Internal::ESP32Utils::kDefaultEthernetNetifKey)) + if (ConnectivityMgr().IsWiFiStationProvisioned() || ESP32Utils::HasIPv6LinkLocalAddress(ESP32Utils::kDefaultEthernetNetifKey)) { ReturnErrorOnFailure(EspDnssdBrowse(type, protocol, addressType, interface, callback, context, browseIdentifier)); } #endif -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT if (ConnectivityMgr().IsThreadProvisioned()) { ReturnErrorOnFailure(OpenThreadDnssdBrowse(type, protocol, addressType, interface, callback, context, browseIdentifier)); @@ -115,13 +115,12 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId inte void * context) { #if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET - if (ConnectivityMgr().IsWiFiStationProvisioned() || - Internal::ESP32Utils::HasIPv6LinkLocalAddress(Internal::ESP32Utils::kDefaultEthernetNetifKey)) + if (ConnectivityMgr().IsWiFiStationProvisioned() || ESP32Utils::HasIPv6LinkLocalAddress(ESP32Utils::kDefaultEthernetNetifKey)) { ReturnErrorOnFailure(EspDnssdResolve(service, interface, callback, context)); } #endif -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT if (ConnectivityMgr().IsThreadProvisioned()) { ReturnErrorOnFailure(OpenThreadDnssdResolve(service, interface, callback, context)); diff --git a/src/platform/ESP32/ESP32DnssdImpl.cpp b/src/platform/ESP32/ESP32DnssdImpl.cpp index 2c896a0d5904db..e898a9cadf767d 100644 --- a/src/platform/ESP32/ESP32DnssdImpl.cpp +++ b/src/platform/ESP32/ESP32DnssdImpl.cpp @@ -355,7 +355,7 @@ static CHIP_ERROR OnBrowseDone(BrowseContext * ctx) Inet::IPAddress IPAddr; error = GetIPAddress(IPAddr, currentResult->addr); SuccessOrExit(error); - ctx->mService[servicesIndex].mAddress.SetValue(IPAddr); + ctx->mService[servicesIndex].mAddress.emplace(IPAddr); } currentResult = currentResult->next; servicesIndex++; diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index 6b9e1f7432612c..317bff7c05403e 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -230,7 +230,6 @@ class GenericThreadStackManagerImpl_OpenThread DnsBrowseCallback mDnsBrowseCallback; DnsResolveCallback mDnsResolveCallback; - GeneralFaults mNetworkFaults; struct DnsServiceTxtEntries { @@ -264,6 +263,8 @@ class GenericThreadStackManagerImpl_OpenThread #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT + GeneralFaults mNetworkFaults; + inline ImplClass * Impl() { return static_cast(this); } }; diff --git a/src/platform/OpenThread/OpenThreadDnssdImpl.cpp b/src/platform/OpenThread/OpenThreadDnssdImpl.cpp index cb205df95eb72b..f5b0a85f2d0d83 100644 --- a/src/platform/OpenThread/OpenThreadDnssdImpl.cpp +++ b/src/platform/OpenThread/OpenThreadDnssdImpl.cpp @@ -24,6 +24,7 @@ namespace Dnssd { CHIP_ERROR OpenThreadDnssdInit(DnssdAsyncReturnCallback initCallback, DnssdAsyncReturnCallback errorCallback, void * context) { +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT ReturnErrorOnFailure(ThreadStackMgr().SetSrpDnsCallbacks(initCallback, errorCallback, context)); uint8_t macBuffer[ConfigurationManager::kPrimaryMACAddressLength]; @@ -33,6 +34,9 @@ CHIP_ERROR OpenThreadDnssdInit(DnssdAsyncReturnCallback initCallback, DnssdAsync MakeHostName(hostname, sizeof(hostname), mac); return ThreadStackMgr().ClearSrpHost(hostname); +#else + return CHIP_ERROR_NOT_IMPLEMENTED; +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT } const char * GetProtocolString(DnssdServiceProtocol protocol)