Skip to content

Commit

Permalink
ESP32: Fix IEEE802154 MAC address in diagnostic provider (project-chi…
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 authored Dec 5, 2024
1 parent 735b69f commit 62b2437
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/platform/ESP32/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,33 +217,38 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface **
{
NetworkInterface * ifp = new NetworkInterface();
esp_netif_ip_info_t ipv4_info;
uint8_t addressSize = 0;
Platform::CopyString(ifp->Name, esp_netif_get_ifkey(ifa));
ifp->name = CharSpan::fromCharString(ifp->Name);
ifp->isOperational = true;
ifp->type = GetInterfaceType(esp_netif_get_desc(ifa));
ifp->offPremiseServicesReachableIPv4.SetNull();
ifp->offPremiseServicesReachableIPv6.SetNull();
#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (esp_netif_get_mac(ifa, ifp->MacAddress) != ESP_OK)
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (ifp->type == InterfaceTypeEnum::kThread)
{
ChipLogError(DeviceLayer, "Failed to get network hardware address");
static_assert(OT_EXT_ADDRESS_SIZE <= sizeof(ifp->MacAddress), "Unexpected extended address size");
if (ThreadStackMgr().GetPrimary802154MACAddress(ifp->MacAddress) == CHIP_NO_ERROR)
{
addressSize = OT_EXT_ADDRESS_SIZE;
}
}
else
#endif
if (esp_netif_get_mac(ifa, ifp->MacAddress) == ESP_OK)
{
ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6);
// For Wi-Fi or Ethernet interface, the MAC address size should be 6
addressSize = 6;
}
#else
if (esp_read_mac(ifp->MacAddress, ESP_MAC_IEEE802154) != ESP_OK)
if (addressSize != 0)
{
ChipLogError(DeviceLayer, "Failed to get network hardware address");
ifp->hardwareAddress = ByteSpan(ifp->MacAddress, addressSize);
}
else
{
ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 8);
ChipLogError(DeviceLayer, "Failed to get network hardware address");
}
#endif

#if !CONFIG_DISABLE_IPV4
#ifndef CONFIG_DISABLE_IPV4
if (esp_netif_get_ip_info(ifa, &ipv4_info) == ESP_OK)
{
memcpy(ifp->Ipv4AddressesBuffer[0], &(ipv4_info.ip.addr), kMaxIPv4AddrSize);
Expand Down

0 comments on commit 62b2437

Please sign in to comment.