diff --git a/examples/platform/esp32/common/Esp32AppServer.cpp b/examples/platform/esp32/common/Esp32AppServer.cpp index 448463033c383e..4ea0b256237244 100644 --- a/examples/platform/esp32/common/Esp32AppServer.cpp +++ b/examples/platform/esp32/common/Esp32AppServer.cpp @@ -37,6 +37,11 @@ app::Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPWiFiDriver::GetInstance())); #endif +#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 static uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, @@ -109,6 +114,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)) diff --git a/src/platform/ESP32/ConnectivityManagerImpl_Ethernet.cpp b/src/platform/ESP32/ConnectivityManagerImpl_Ethernet.cpp index ed0a5f059f4106..3168d15058c31a 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl_Ethernet.cpp +++ b/src/platform/ESP32/ConnectivityManagerImpl_Ethernet.cpp @@ -51,6 +51,8 @@ namespace DeviceLayer { CHIP_ERROR ConnectivityManagerImpl::InitEthernet() { + // Initialize TCP/IP network interface (should be called only once in application) + ESP_ERROR_CHECK(esp_netif_init()); esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); esp_netif_t * eth_netif = esp_netif_new(&cfg); diff --git a/src/platform/ESP32/NetworkCommissioningDriver.h b/src/platform/ESP32/NetworkCommissioningDriver.h index c6175938d76478..fab2598072e48c 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.h +++ b/src/platform/ESP32/NetworkCommissioningDriver.h @@ -136,6 +136,35 @@ class ESPWiFiDriver final : public WiFiDriver uint16_t mLastDisconnectedReason; }; +class ESPEthernetDriver final : public EthernetDriver +{ +public: + class EthernetNetworkIterator final : public NetworkIterator + { + public: + EthernetNetworkIterator(ESPEthernetDriver * aDriver) : mDriver(aDriver) {} + size_t Count() { return 1; } + bool Next(Network & item) { return true; } + void Release() override { delete this; } + ~EthernetNetworkIterator() = default; + + private: + ESPEthernetDriver * mDriver; + }; + + // BaseDriver + NetworkIterator * GetNetworks() override { return new EthernetNetworkIterator(this); } + uint8_t GetMaxNetworks() { return 1; } + CHIP_ERROR Init(NetworkStatusChangeCallback * networkStatusChangeCallback) { return CHIP_NO_ERROR; } + void Shutdown() {} + + static ESPEthernetDriver & GetInstance() + { + static ESPEthernetDriver instance; + return instance; + } +}; + } // namespace NetworkCommissioning } // namespace DeviceLayer } // namespace chip