Skip to content

Commit

Permalink
Merge e4727c9 into a5124a9
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen authored Jul 26, 2024
2 parents a5124a9 + e4727c9 commit 1537665
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 23 deletions.
3 changes: 3 additions & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ endif()

if (CONFIG_ENABLE_MATTER_OVER_THREAD)
chip_gn_arg_append("chip_enable_openthread" "true")
if (CONFIG_THREAD_NETWORK_COMMISSIONING_DRIVER)
chip_gn_arg_append("chip_device_config_thread_network_endpoint_id" ${CONFIG_THREAD_NETWORK_ENDPOINT_ID})
endif()
else()
chip_gn_arg_append("chip_enable_openthread" "false")
endif()
Expand Down
54 changes: 54 additions & 0 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ menu "CHIP Core"
help
Option to enable/disable CHIP log level filtering APIs.

config ENABLE_CHIP_DATA_MODEL
bool "Enable CHIP data model"
default y
help
Option to enable/disable CHIP data model.

endmenu # "General Options"

menu "Networking Options"
Expand Down Expand Up @@ -1289,4 +1295,52 @@ menu "CHIP Device Layer"

endmenu

menu "Network Commissioning Driver Endpoint Id"
config THREAD_NETWORK_COMMISSIONING_DRIVER
bool "Use the generic Thread network commissioning driver"
depends on ENABLE_MATTER_OVER_THREAD && ENABLE_CHIP_DATA_MODEL
default y
help
Option to enable/disable the use of generic Thread network commissioning driver.

config THREAD_NETWORK_ENDPOINT_ID
int "Endpoint Id for Thread network"
depends on THREAD_NETWORK_COMMISSIONING_DRIVER
range 0 65534
default 0
help
The endpoint id for the generic Thread network commissioning driver.

config WIFI_NETWORK_COMMISSIONING_DRIVER
bool "Use ESP Wi-Fi network commissioning driver"
depends on (ENABLE_WIFI_STATION || ENABLE_WIFI_AP) && ENABLE_CHIP_DATA_MODEL
default y
help
Option to enable/disable the use of ESP Wi-Fi network commissioning driver.

config WIFI_NETWORK_ENDPOINT_ID
int "Endpoint Id for Wi-Fi network"
depends on WIFI_NETWORK_COMMISSIONING_DRIVER
range 0 65534
default 0
help
The endpoint id for the ESP Wi-Fi network commissioning driver.

config ETHERNET_NETWORK_COMMISSIONING_DRIVER
bool "Use ESP Ethernet network commissioning driver"
depends on ENABLE_ETHERNET_TELEMETRY && ENABLE_CHIP_DATA_MODEL
default y
help
Option to enable/disable the use of ESP Ethernet network commissioning driver.

config ETHERNET_NETWORK_ENDPOINT_ID
int "Endpoint Id for Ethernet network"
depends on ETHERNET_NETWORK_COMMISSIONING_DRIVER
range 0 65534
default 0
help
The endpoint id for the ESP Ethernet network commissioning driver.

endmenu

endmenu
18 changes: 12 additions & 6 deletions examples/all-clusters-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@ NetworkCommissioning Endpoint can be used to manage the driver of extra network
interface.

For ESP32-C6 DevKits, if `CHIP_DEVICE_CONFIG_ENABLE_WIFI` and
`CHIP_DEVICE_CONFIG_ENABLE_THREAD` are both enabled, the NetworkCommissioning
cluster in Endpoint 0 will be used for Thread network driver and the same
cluster on Endpoint 65534 will be used for Wi-Fi network driver.
`CHIP_DEVICE_CONFIG_ENABLE_THREAD` are both enabled, please set
`CONFIG_THREAD_NETWORK_ENDPOINT_ID` to 0 and set
`CONFIG_WIFI_NETWORK_ENDPOINT_ID` to 65534, which presents that the
NetworkCommissioning cluster in Endpoint 0 will be used for Thread network
driver and the same cluster on Endpoint 65534 will be used for Wi-Fi network
driver. Or vice versa.

For ESP32-Ethernet-Kits, if `CHIP_DEVICE_CONFIG_ENABLE_WIFI` and
`CHIP_DEVICE_CONFIG_ENABLE_ETHERNET` are both enabled, the NetworkCommissioning
cluster in Endpoint 0 will be used for Ethernet network driver and the same
cluster on Endpoint 65534 will be used for Wi-Fi network driver.
`CHIP_DEVICE_CONFIG_ENABLE_ETHERNET` are both enabled, please set
`CONFIG_ETHERNET_NETWORK_ENDPOINT_ID` to 0 and set
`CONFIG_WIFI_NETWORK_ENDPOINT_ID` to 65534, which presents that the
NetworkCommissioning cluster in Endpoint 0 will be used for Ethernet network
driver and the same cluster on Endpoint 65534 will be used for Wi-Fi network
driver. Or vice versa.

---

Expand Down
3 changes: 3 additions & 0 deletions examples/persistent-storage/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ CONFIG_DEVICE_PRODUCT_ID=0x8009

# Enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y

# Disable CHIP data model
CONFIG_ENABLE_CHIP_DATA_MODEL=n
18 changes: 1 addition & 17 deletions examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ using namespace chip::DeviceLayer;
static constexpr char TAG[] = "ESP32Appserver";

namespace {
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#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()));
#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
static uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
Expand Down Expand Up @@ -150,14 +137,11 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
chip::Server::GetInstance().Init(initParams);

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
sWiFiNetworkCommissioningInstance.Init();
#ifdef CONFIG_ENABLE_CHIP_SHELL
chip::Shell::SetWiFiDriver(&(chip::DeviceLayer::NetworkCommissioning::ESPWiFiDriver::GetInstance()));
#endif
#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
3 changes: 3 additions & 0 deletions examples/shell/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ CONFIG_ENABLE_CHIP_SHELL=y

# Enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y

# Disable CHIP data model
CONFIG_ENABLE_CHIP_DATA_MODEL=n
15 changes: 15 additions & 0 deletions src/platform/ESP32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@

#ifdef CONFIG_ENABLE_MATTER_OVER_THREAD
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD CONFIG_ENABLE_MATTER_OVER_THREAD
#ifndef CONFIG_THREAD_NETWORK_COMMISSIONING_DRIVER
#define _NO_NETWORK_COMMISSIONING_DRIVER_ 1
#endif
#else
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0
#endif // CONFIG_ENABLE_MATTER_OVER_THREAD
Expand Down Expand Up @@ -164,3 +167,15 @@
#define CHIP_DEVICE_CONFIG_BG_TASK_PRIORITY CONFIG_BG_CHIP_TASK_PRIORITY
#define CHIP_DEVICE_CONFIG_BG_MAX_EVENT_QUEUE_SIZE CONFIG_BG_MAX_EVENT_QUEUE_SIZE
#define CHIP_DEVICE_CONFIG_BG_TASK_STACK_SIZE CONFIG_BG_CHIP_TASK_STACK_SIZE

#ifdef CONFIG_WIFI_NETWORK_COMMISSIONING_DRIVER
#define CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER CONFIG_WIFI_NETWORK_COMMISSIONING_DRIVER
#else
#define CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER 0
#endif // CONFIG_WIFI_NETWORK_COMMISSIONING_DRIVER

#ifdef CONFIG_ETHERNET_NETWORK_COMMISSIONING_DRIVER
#define CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER CONFIG_ETHERNET_NETWORK_COMMISSIONING_DRIVER
#else
#define CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER 0
#endif // CONFIG_ETHERNET_NETWORK_COMMISSIONING_DRIVER
34 changes: 34 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.ipp>
#endif

#include <app/clusters/network-commissioning/network-commissioning.h>
#include <esp_wifi.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/ESP32/NetworkCommissioningDriver.h>
#include <platform/internal/BLEManager.h>

using namespace ::chip;
Expand All @@ -53,6 +55,18 @@ namespace chip {
namespace DeviceLayer {

ConnectivityManagerImpl ConnectivityManagerImpl::sInstance;

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI && CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER
app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(CONFIG_WIFI_NETWORK_ENDPOINT_ID /* Endpoint Id */,
&(NetworkCommissioning::ESPWiFiDriver::GetInstance()));
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET && CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER
app::Clusters::NetworkCommissioning::Instance
sEthernetNetworkCommissioningInstance(CONFIG_ETHERNET_NETWORK_ENDPOINT_ID /* Endpoint Id */,
&(NetworkCommissioning::ESPEthernetDriver::GetInstance()));
#endif
// ==================== ConnectivityManager Platform Internal Methods ====================

CHIP_ERROR ConnectivityManagerImpl::_Init()
Expand All @@ -62,10 +76,30 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
InitWiFi();
#if CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER
sWiFiNetworkCommissioningInstance.Init();
#endif // CHIP_DEVICE_CONFIG_WIFI_NETWORK_DRIVER
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
InitEthernet();
#if CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER
sEthernetNetworkCommissioningInstance.Init();
#endif // CHIP_DEVICE_CONFIG_ETHERNET_NETWORK_DRIVER
#endif

#if defined(CONFIG_WIFI_NETWORK_ENDPOINT_ID) && defined(CONFIG_THREAD_NETWORK_ENDPOINT_ID)
static_assert(CONFIG_WIFI_NETWORK_ENDPOINT_ID != CONFIG_THREAD_NETWORK_ENDPOINT_ID,
"Wi-Fi network endpoint id and Thread network endpoint id should not be the same.");
#endif
#if defined(CONFIG_WIFI_NETWORK_ENDPOINT_ID) && defined(CONFIG_ETHERNET_NETWORK_ENDPOINT_ID)
static_assert(CONFIG_WIFI_NETWORK_ENDPOINT_ID != CONFIG_ETHERNET_NETWORK_ENDPOINT_ID,
"Wi-Fi network endpoint id and Ethernet network endpoint id should not be the same.");
#endif
#if defined(CONFIG_THREAD_NETWORK_ENDPOINT_ID) && defined(CONFIG_ETHERNET_NETWORK_ENDPOINT_ID)
static_assert(CONFIG_THREAD_NETWORK_ENDPOINT_ID != CONFIG_ETHERNET_NETWORK_ENDPOINT_ID,
"Thread network endpoint id and Ethernet network endpoint id should not be the same.");
#endif

return CHIP_NO_ERROR;
}

Expand Down

0 comments on commit 1537665

Please sign in to comment.