Skip to content

Commit

Permalink
test for thread border router deinit, ethernet and wifi
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen committed Mar 8, 2024
1 parent d38a649 commit 03ef197
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 97 deletions.
5 changes: 3 additions & 2 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,17 @@ if(CONFIG_OPENTHREAD_ENABLED)
endif()
endif()

if((NOT CONFIG_USE_MINIMAL_MDNS) AND (CONFIG_ENABLE_WIFI_STATION OR CONFIG_ENABLE_WIFI_AP))
if(NOT CONFIG_USE_MINIMAL_MDNS)
idf_build_get_property(build_components BUILD_COMPONENTS)
# For IDF v5.x, the mdns component was moved to idf_managed_components.
# We should use 'espressif__mdns' for 'idf_component_get_property'.
if("espressif__mdns" IN_LIST build_components)
idf_component_get_property(mdns_lib espressif__mdns COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${mdns_lib}>)
elseif("mdns" IN_LIST build_components)
idf_component_get_property(mdns_lib mdns COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${mdns_lib}>)
endif()
list(APPEND chip_libraries $<TARGET_FILE:${mdns_lib}>)
endif()

if (CONFIG_ENABLE_ENCRYPTED_OTA)
Expand Down
2 changes: 1 addition & 1 deletion examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void InitServer(intptr_t context)
{
Esp32AppServer::Init(&sCallbacks); // Init ZCL Data Model and CHIP App Server AND Initialize device attestation config

#if !(CHIP_DEVICE_CONFIG_ENABLE_WIFI && CHIP_DEVICE_CONFIG_ENABLE_THREAD)
#if !(CHIP_DEVICE_CONFIG_ENABLE_WIFI && (CHIP_DEVICE_CONFIG_ENABLE_THREAD || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET))
// We only have network commissioning on endpoint 0.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
#endif
Expand Down
23 changes: 15 additions & 8 deletions examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ static constexpr char TAG[] = "ESP32Appserver";

namespace {
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
constexpr chip::EndpointId kNetworkCommissioningEndpointWiFi = 0xFFFE;
#else
constexpr chip::EndpointId kNetworkCommissioningEndpointWiFi = 0;
#endif
app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointWiFi, &(NetworkCommissioning::ESPWiFiDriver::GetInstance()));
#elif CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
static app::Clusters::NetworkCommissioning::Instance
sEthernetNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPEthernetDriver::GetInstance()));
#endif

#if CONFIG_TEST_EVENT_TRIGGER_ENABLED
#if CONFIG_TEST_EVENT_TRIGGER_ENABLED && CONFIG_ENABLE_OTA_REQUESTOR
static uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
0xcc, 0xdd, 0xee, 0xff };
Expand All @@ -72,7 +73,7 @@ static ICDSubscriptionCallback sICDSubscriptionHandler;
#endif
} // namespace

#if CONFIG_TEST_EVENT_TRIGGER_ENABLED
#if CONFIG_TEST_EVENT_TRIGGER_ENABLED && CONFIG_ENABLE_OTA_REQUESTOR
static int hex_digit_to_int(char hex)
{
if ('A' <= hex && hex <= 'F')
Expand Down Expand Up @@ -111,7 +112,7 @@ static size_t hex_string_to_binary(const char * hex_string, uint8_t * buf, size_

return buf_size;
}
#endif // CONFIG_TEST_EVENT_TRIGGER_ENABLED
#endif // CONFIG_TEST_EVENT_TRIGGER_ENABLED && CONFIG_ENABLE_OTA_REQUESTOR

void Esp32AppServer::DeInitBLEIfCommissioned(void)
{
Expand Down Expand Up @@ -168,9 +169,12 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
ESP_LOGE(TAG, "Failed to convert the EnableKey string to octstr type value");
memset(sTestEventTriggerEnableKey, 0, sizeof(sTestEventTriggerEnableKey));
}
static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
initParams.testEventTriggerDelegate = &testEventTriggerDelegate;
#endif // CONFIG_TEST_EVENT_TRIGGER_ENABLED
static SimpleTestEventTriggerDelegate sTestEventTriggerDelegate{};
static OTATestEventTriggerHandler sOtaTestEventTriggerHandler{};
VerifyOrDie(sTestEventTriggerDelegate.Init(ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR);
VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR);
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
#endif // CONFIG_TEST_EVENT_TRIGGER_ENABLED && CONFIG_ENABLE_OTA_REQUESTOR
(void) initParams.InitializeStaticResourcesBeforeServerInit();
if (sAppDelegate != nullptr)
{
Expand All @@ -185,6 +189,9 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
sWiFiNetworkCommissioningInstance.Init();
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
sEthernetNetworkCommissioningInstance.Init();
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() &&
(chip::Server::GetInstance().GetFabricTable().FabricCount() != 0))
Expand Down
29 changes: 16 additions & 13 deletions src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,24 @@ static_library("ESP32") {
"NetworkCommissioningDriver.cpp",
"NetworkCommissioningDriver.h",
]
}

if (chip_mdns == "platform") {
sources += [ "DnssdImpl.cpp" ]
}

if (chip_enable_ethernet) {
sources += [
"ConnectivityManagerImpl_Ethernet.cpp",
"NetworkCommissioningDriver_Ethernet.cpp",
]
}

if (chip_enable_ethernet || chip_enable_wifi) {
if (chip_mdns == "platform") {
sources += [
"WiFiDnssdImpl.cpp",
"WiFiDnssdImpl.h",
"ESP32DnssdImpl.cpp",
"ESP32DnssdImpl.h",
]
}
if (chip_enable_route_hook) {
Expand All @@ -138,17 +152,6 @@ static_library("ESP32") {
}
}

if (chip_mdns == "platform") {
sources += [ "DnssdImpl.cpp" ]
}

if (chip_enable_ethernet) {
sources += [
"ConnectivityManagerImpl_Ethernet.cpp",
"NetworkCommissioningDriver_Ethernet.cpp",
]
}

if (chip_enable_openthread) {
sources += [
"../OpenThread/GenericNetworkCommissioningThreadDriver.cpp",
Expand Down
13 changes: 6 additions & 7 deletions src/platform/ESP32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT CONFIG_OPENTHREAD_DNS_CLIENT

#if CONFIG_ENABLE_ETHERNET_TELEMETRY
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI 0
#define CHIP_DEVICE_CONFIG_ENABLE_ETHERNET 1
#elif CONFIG_IDF_TARGET_ESP32H2
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI 0
#else
#endif

#define CHIP_DEVICE_CONFIG_ENABLE_WIFI CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP | CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY CONFIG_ENABLE_WIFI_TELEMETRY
#define CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL CONFIG_WIFI_STATION_RECONNECT_INTERVAL
#define CHIP_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS CONFIG_MAX_SCAN_NETWORKS_RESULTS
#define CHIP_DEVICE_CONFIG_WIFI_SCAN_COMPLETION_TIMEOUT CONFIG_WIFI_SCAN_COMPLETION_TIMEOUT
Expand All @@ -69,9 +70,7 @@
#define CHIP_DEVICE_CONFIG_WIFI_AP_BEACON_INTERVAL CONFIG_WIFI_AP_BEACON_INTERVAL
#define CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT CONFIG_WIFI_AP_IDLE_TIMEOUT
#endif /* CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP */
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY CONFIG_ENABLE_WIFI_TELEMETRY
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP | CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
#endif // CONFIG_IDF_TARGET_ESP32H2
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

#if CONFIG_ENABLE_ICD_SERVER
#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_ICD_SLOW_POLL_INTERVAL_MS)
Expand Down
53 changes: 33 additions & 20 deletions src/platform/ESP32/ConnectivityManagerImpl_Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <platform/ESP32/NetworkCommissioningDriver.h>
#include <platform/internal/BLEManager.h>

#include "esp_eth_com.h"
#include "esp_eth.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_wifi.h"
Expand Down Expand Up @@ -88,28 +88,41 @@ void ConnectivityManagerImpl::OnEthernetIPv6AddressAvailable(const ip_event_got_

void ConnectivityManagerImpl::OnEthernetPlatformEvent(const ChipDeviceEvent * event)
{
switch (event->Platform.ESPSystemEvent.Id)
if (event->Type == DeviceEventType::kESPSystemEvent)
{
case IP_EVENT_ETH_GOT_IP:
OnEthernetIPv4AddressAvailable(event->Platform.ESPSystemEvent.Data.IpGotIp);
break;
case IP_EVENT_ETH_LOST_IP:
OnEthernetIPv4AddressLost();
break;
case IP_EVENT_GOT_IP6:
if (strcmp(esp_netif_get_ifkey(event->Platform.ESPSystemEvent.Data.IpGotIp6.esp_netif), "ETH_DEF") == 0)
if (event->Platform.ESPSystemEvent.Base == IP_EVENT) {
switch (event->Platform.ESPSystemEvent.Id)
{
case IP_EVENT_ETH_GOT_IP:
OnEthernetIPv4AddressAvailable(event->Platform.ESPSystemEvent.Data.IpGotIp);
break;
case IP_EVENT_ETH_LOST_IP:
OnEthernetIPv4AddressLost();
break;
case IP_EVENT_GOT_IP6:
if (strcmp(esp_netif_get_ifkey(event->Platform.ESPSystemEvent.Data.IpGotIp6.esp_netif), "ETH_DEF") == 0)
{
OnEthernetIPv6AddressAvailable(event->Platform.ESPSystemEvent.Data.IpGotIp6);
}
break;
default:
break;
}
}
else if (event->Platform.ESPSystemEvent.Base == ETH_EVENT)
{
OnEthernetIPv6AddressAvailable(event->Platform.ESPSystemEvent.Data.IpGotIp6);
switch (event->Platform.ESPSystemEvent.Id)
{
case ETHERNET_EVENT_START:
ChipLogProgress(DeviceLayer, "Ethernet Started");
break;
case ETHERNET_EVENT_STOP:
ChipLogProgress(DeviceLayer, "Ethernet Stopped");
break;
default:
break;
}
}
break;
case ETHERNET_EVENT_START:
ChipLogProgress(DeviceLayer, "Ethernet Started");
break;
case ETHERNET_EVENT_STOP:
ChipLogProgress(DeviceLayer, "Ethernet Stopped");
break;
default:
break;
}
}

Expand Down
37 changes: 17 additions & 20 deletions src/platform/ESP32/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@

#include "lib/dnssd/platform/Dnssd.h"
#include "platform/CHIPDeviceLayer.h"
#include "platform/ESP32/ESP32Utils.h"

#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <platform/OpenThread/OpenThreadDnssdImpl.h>
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include <platform/ESP32/WiFiDnssdImpl.h>
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
#include <platform/ESP32/ESP32DnssdImpl.h>
#endif

using namespace ::chip::DeviceLayer;
Expand All @@ -35,8 +36,8 @@ namespace Dnssd {

CHIP_ERROR ChipDnssdInit(DnssdAsyncReturnCallback initCallback, DnssdAsyncReturnCallback errorCallback, void * context)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
ReturnErrorOnFailure(WiFiDnssdInit(initCallback, errorCallback, context));
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
ReturnErrorOnFailure(EspDnssdInit(initCallback, errorCallback, context));
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
ReturnErrorOnFailure(OpenThreadDnssdInit(initCallback, errorCallback, context));
Expand All @@ -48,11 +49,8 @@ void ChipDnssdShutdown() {}

CHIP_ERROR ChipDnssdPublishService(const DnssdService * service, DnssdPublishCallback callback, void * context)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
if (ConnectivityMgr().IsWiFiStationProvisioned())
{
ReturnErrorOnFailure(WiFiDnssdPublishService(service, callback, context));
}
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
ReturnErrorOnFailure(EspDnssdPublishService(service, callback, context));
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (ConnectivityMgr().IsThreadProvisioned())
Expand All @@ -65,11 +63,8 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service, DnssdPublishCal

CHIP_ERROR ChipDnssdRemoveServices()
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
if (ConnectivityMgr().IsWiFiStationProvisioned())
{
ReturnErrorOnFailure(WiFiDnssdRemoveServices());
}
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
ReturnErrorOnFailure(EspDnssdRemoveServices());
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (ConnectivityMgr().IsThreadProvisioned())
Expand All @@ -95,10 +90,11 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi
chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context,
intptr_t * browseIdentifier)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
if (ConnectivityMgr().IsWiFiStationProvisioned())
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
if (ConnectivityMgr().IsWiFiStationProvisioned() ||
Internal::ESP32Utils::HasIPv6LinkLocalAddress(Internal::ESP32Utils::kDefaultEthernetNetifKey))
{
ReturnErrorOnFailure(WiFiDnssdBrowse(type, protocol, addressType, interface, callback, context, browseIdentifier));
ReturnErrorOnFailure(EspDnssdBrowse(type, protocol, addressType, interface, callback, context, browseIdentifier));
}
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
Expand All @@ -118,10 +114,11 @@ CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier)
CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId interface, DnssdResolveCallback callback,
void * context)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
if (ConnectivityMgr().IsWiFiStationProvisioned())
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
if (ConnectivityMgr().IsWiFiStationProvisioned() ||
Internal::ESP32Utils::HasIPv6LinkLocalAddress(Internal::ESP32Utils::kDefaultEthernetNetifKey))
{
ReturnErrorOnFailure(WiFiDnssdResolve(service, interface, callback, context));
ReturnErrorOnFailure(EspDnssdResolve(service, interface, callback, context));
}
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
Expand Down
Loading

0 comments on commit 03ef197

Please sign in to comment.