Skip to content

Commit

Permalink
Fix ethernet commissioning for esp32
Browse files Browse the repository at this point in the history
  • Loading branch information
PSONALl committed Mar 29, 2023
1 parent a193746 commit 7183647
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl_Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
29 changes: 29 additions & 0 deletions src/platform/ESP32/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7183647

Please sign in to comment.