Skip to content

Commit

Permalink
ESP32: fix some build errors when enabling platform mdns/disabling sr…
Browse files Browse the repository at this point in the history
…p client (#33544)

* ESP32: fix some build errors when enabling platform mdns/disable srp client

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
wqx6 and restyled-commits authored May 22, 2024
1 parent 25cf97c commit 8ae8954
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/platform/ESP32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions src/platform/ESP32/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#endif

using namespace ::chip::DeviceLayer;
using chip::DeviceLayer::Internal::ESP32Utils;

namespace chip {
namespace Dnssd {
Expand All @@ -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;
Expand All @@ -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));
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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));
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/ESP32DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ class GenericThreadStackManagerImpl_OpenThread

DnsBrowseCallback mDnsBrowseCallback;
DnsResolveCallback mDnsResolveCallback;
GeneralFaults<kMaxNetworkFaults> mNetworkFaults;

struct DnsServiceTxtEntries
{
Expand Down Expand Up @@ -264,6 +263,8 @@ class GenericThreadStackManagerImpl_OpenThread
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT

GeneralFaults<kMaxNetworkFaults> mNetworkFaults;

inline ImplClass * Impl() { return static_cast<ImplClass *>(this); }
};

Expand Down
4 changes: 4 additions & 0 deletions src/platform/OpenThread/OpenThreadDnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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)
Expand Down

0 comments on commit 8ae8954

Please sign in to comment.