From 3ca49ffe57ddabb54ac98dbf50622ad4d9e6c0fb Mon Sep 17 00:00:00 2001 From: PSONALl Date: Fri, 17 Mar 2023 14:49:44 +0530 Subject: [PATCH] Fix ethernet commissioning for esp32 --- .../platform/esp32/common/Esp32AppServer.cpp | 5 ++++ .../ConnectivityManagerImpl_Ethernet.cpp | 2 ++ .../ESP32/NetworkCommissioningDriver.h | 29 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/examples/platform/esp32/common/Esp32AppServer.cpp b/examples/platform/esp32/common/Esp32AppServer.cpp index 448463033c383e..d00a0bab049056 100644 --- a/examples/platform/esp32/common/Esp32AppServer.cpp +++ b/examples/platform/esp32/common/Esp32AppServer.cpp @@ -35,6 +35,9 @@ namespace { #if CHIP_DEVICE_CONFIG_ENABLE_WIFI app::Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPWiFiDriver::GetInstance())); +#elif CHIP_DEVICE_CONFIG_ENABLE_ETHERNET +static app::Clusters::NetworkCommissioning::Instance + sEthernetNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPEthernetDriver::GetInstance())); #endif #if CONFIG_TEST_EVENT_TRIGGER_ENABLED @@ -108,6 +111,8 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate) #if CHIP_DEVICE_CONFIG_ENABLE_WIFI sWiFiNetworkCommissioningInstance.Init(); +#elif CHIP_DEVICE_CONFIG_ENABLE_ETHERNET + sEthernetNetworkCommissioningInstance.Init(); #endif #if CHIP_DEVICE_CONFIG_ENABLE_THREAD if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() && 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