Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32: Set the InterfaceId to Wi-Fi Station netif by default for platform mDNS #28769

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")));
wqx6 marked this conversation as resolved.
Show resolved Hide resolved
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