Skip to content

Commit

Permalink
ESP32: Set the InterfaceId to Wi-Fi Station netif by default for plat…
Browse files Browse the repository at this point in the history
…form mDNS (project-chip#28769)
  • Loading branch information
wqx6 authored and abpoth committed Sep 12, 2023
1 parent 52a6160 commit 0fe2336
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/platform/ESP32/WiFiDnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "lib/dnssd/platform/Dnssd.h"

#include <esp_err.h>
#include <esp_netif_net_stack.h>
#include <lwip/ip4_addr.h>
#include <lwip/ip6_addr.h>

Expand Down Expand Up @@ -323,12 +324,22 @@ static CHIP_ERROR OnBrowseDone(BrowseContext * ctx)
ctx->mService[servicesIndex].mAddressType = MapAddressType(currentResult->ip_protocol);
ctx->mService[servicesIndex].mTransportType = ctx->mAddressType;
ctx->mService[servicesIndex].mPort = currentResult->port;
ctx->mService[servicesIndex].mInterface = ctx->mInterfaceId;
ctx->mService[servicesIndex].mTextEntries =
GetTextEntry(currentResult->txt, currentResult->txt_value_len, currentResult->txt_count);
ctx->mService[servicesIndex].mTextEntrySize = currentResult->txt_count;
ctx->mService[servicesIndex].mSubTypes = NULL;
ctx->mService[servicesIndex].mSubTypeSize = 0;
if (ctx->mInterfaceId == chip::Inet::InterfaceId::Null())
{
// If the InterfaceId in the context is Null, we will use the Station netif by default.
struct netif * lwip_netif =
reinterpret_cast<struct netif *>(esp_netif_get_netif_impl(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")));
ctx->mService[servicesIndex].mInterface = chip::Inet::InterfaceId(lwip_netif);
}
else
{
ctx->mService[servicesIndex].mInterface = ctx->mInterfaceId;
}
if (currentResult->addr)
{
Inet::IPAddress IPAddr;
Expand Down Expand Up @@ -403,9 +414,20 @@ static CHIP_ERROR ParseSrvResult(ResolveContext * ctx)
ctx->mService->mAddressType = MapAddressType(ctx->mSrvQueryResult->ip_protocol);
ctx->mService->mTransportType = ctx->mService->mAddressType;
ctx->mService->mPort = ctx->mSrvQueryResult->port;
ctx->mService->mInterface = ctx->mInterfaceId;
ctx->mService->mSubTypes = nullptr;
ctx->mService->mSubTypeSize = 0;
if (ctx->mInterfaceId == chip::Inet::InterfaceId::Null())
{
// If the InterfaceId in the context is Null, we will use the Station netif by default.
struct netif * lwip_netif =
reinterpret_cast<struct netif *>(esp_netif_get_netif_impl(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")));
ctx->mService->mInterface = chip::Inet::InterfaceId(lwip_netif);
}
else
{
ctx->mService->mInterface = ctx->mInterfaceId;
}

return CHIP_NO_ERROR;
}
else
Expand Down

0 comments on commit 0fe2336

Please sign in to comment.