Skip to content

Commit

Permalink
ESP32: Add IPAddresses for the network interfaces in generaldiagnosti…
Browse files Browse the repository at this point in the history
…c cluster (#21271)

* ESP32: Add IPAddresses for the netif in generaldiagnostic cluster

* Restyled by whitespace

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 13, 2023
1 parent 00e1dd0 commit 5fc29b1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/platform/ESP32/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface **
{
esp_netif_t * netif = esp_netif_next(NULL);
NetworkInterface * head = NULL;
uint8_t ipv6_addr_count = 0;
esp_ip6_addr_t ip6_addr[kMaxIPv6AddrCount];
if (netif == NULL)
{
ChipLogError(DeviceLayer, "Failed to get network interfaces");
Expand All @@ -207,6 +209,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface **
for (esp_netif_t * ifa = netif; ifa != NULL; ifa = esp_netif_next(ifa))
{
NetworkInterface * ifp = new NetworkInterface();
esp_netif_ip_info_t ipv4_info;
strncpy(ifp->Name, esp_netif_get_ifkey(ifa), Inet::InterfaceId::kMaxIfNameLength);
ifp->Name[Inet::InterfaceId::kMaxIfNameLength - 1] = '\0';
ifp->name = CharSpan::fromCharString(ifp->Name);
Expand All @@ -222,6 +225,20 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface **
{
ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6);
}
if (esp_netif_get_ip_info(ifa, &ipv4_info) == ESP_OK)
{
memcpy(ifp->Ipv4AddressesBuffer[0], &(ipv4_info.ip.addr), kMaxIPv4AddrSize);
ifp->Ipv4AddressSpans[0] = ByteSpan(ifp->Ipv4AddressesBuffer[0], kMaxIPv4AddrSize);
ifp->IPv4Addresses = chip::app::DataModel::List<chip::ByteSpan>(ifp->Ipv4AddressSpans, 1);
}
ipv6_addr_count = esp_netif_get_all_ip6(ifa, ip6_addr);
for (uint8_t idx = 0; idx < ipv6_addr_count; ++idx)
{
memcpy(ifp->Ipv6AddressesBuffer[idx], ip6_addr[idx].addr, kMaxIPv6AddrSize);
ifp->Ipv6AddressSpans[idx] = ByteSpan(ifp->Ipv6AddressesBuffer[idx], kMaxIPv6AddrSize);
}
ifp->IPv6Addresses = chip::app::DataModel::List<chip::ByteSpan>(ifp->Ipv6AddressSpans, ipv6_addr_count);

ifp->Next = head;
head = ifp;
}
Expand Down

0 comments on commit 5fc29b1

Please sign in to comment.