diff --git a/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.cpp b/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.cpp index 9b1f30f5d..5e6fd216f 100644 --- a/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.cpp +++ b/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.cpp @@ -60,6 +60,17 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s return 0; } +CHIP_ERROR PlatformManagerImpl::DisableESPEventDispatch() +{ + esp_err_t err = esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent); + if (err != ESP_OK) + { + return Internal::ESP32Utils::MapError(err); + } + err = esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent); + return Internal::ESP32Utils::MapError(err); +} + CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { // Arrange for CHIP-encapsulated ESP32 errors to be translated to text diff --git a/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.h b/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.h deleted file mode 120000 index fc9a57796..000000000 --- a/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../connectedhomeip/connectedhomeip/src/platform/ESP32/PlatformManagerImpl.h \ No newline at end of file diff --git a/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.h b/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.h new file mode 100644 index 000000000..29bebb1eb --- /dev/null +++ b/examples/common/secondary_ble_adv/platform/ESP32_custom/PlatformManagerImpl.h @@ -0,0 +1,97 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018 Nest Labs, Inc. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Provides an implementation of the PlatformManager object + * for the ESP32 platform. + */ + +#pragma once + +#include +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the PlatformManager singleton object for the ESP32 platform. + */ +class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl_FreeRTOS +{ + // Allow the PlatformManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend PlatformManager; + + // Allow the generic implementation base class to call helper methods on + // this class. +#ifndef DOXYGEN_SHOULD_SKIP_THIS + friend Internal::GenericPlatformManagerImpl_FreeRTOS; +#endif + +public: + // ===== Platform-specific members that may be accessed directly by the application. + + CHIP_ERROR InitLwIPCoreLock(void); + + static void HandleESPSystemEvent(void * arg, esp_event_base_t eventBase, int32_t eventId, void * eventData); + System::Clock::Timestamp GetStartTime() { return mStartTime; } + static CHIP_ERROR DisableESPEventDispatch(); + +private: + // ===== Methods that implement the PlatformManager abstract interface. + + CHIP_ERROR _InitChipStack(void); + void _Shutdown(); + + // ===== Members for internal use by the following friends. + + friend PlatformManager & PlatformMgr(void); + friend PlatformManagerImpl & PlatformMgrImpl(void); + + System::Clock::Timestamp mStartTime = System::Clock::kZero; + + static PlatformManagerImpl sInstance; +}; + +/** + * Returns the public interface of the PlatformManager singleton object. + * + * Chip applications should use this to access features of the PlatformManager object + * that are common to all platforms. + */ +inline PlatformManager & PlatformMgr(void) +{ + return PlatformManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the PlatformManager singleton object. + * + * Chip applications can use this to gain access to features of the PlatformManager + * that are specific to the ESP32 platform. + */ +inline PlatformManagerImpl & PlatformMgrImpl(void) +{ + return PlatformManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/examples/light_wifi_prov/main/app_wifi.cpp b/examples/light_wifi_prov/main/app_wifi.cpp index e6fbf80a1..f0dfa6870 100644 --- a/examples/light_wifi_prov/main/app_wifi.cpp +++ b/examples/light_wifi_prov/main/app_wifi.cpp @@ -26,6 +26,8 @@ #include #include #include "app_wifi.h" +#include +#include ESP_EVENT_DEFINE_BASE(APP_WIFI_EVENT); @@ -159,6 +161,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, switch (event_id) { case PROTOCOMM_SECURITY_SESSION_SETUP_OK: ESP_LOGI(TAG, "Secured session established!"); + chip::DeviceLayer::PlatformManagerImpl::DisableESPEventDispatch(); break; case PROTOCOMM_SECURITY_SESSION_INVALID_SECURITY_PARAMS: /* fall-through */ diff --git a/examples/light_wifi_prov/partitions.csv b/examples/light_wifi_prov/partitions.csv index 0ae463db0..49b9cc59c 100644 --- a/examples/light_wifi_prov/partitions.csv +++ b/examples/light_wifi_prov/partitions.csv @@ -5,5 +5,6 @@ nvs, data, nvs, 0x10000, 0xC000, nvs_keys, data, nvs_keys,, 0x1000, encrypted otadata, data, ota, , 0x2000 phy_init, data, phy, , 0x1000, -ota_0, app, ota_0, 0x20000, 0x250000, -fctry, data, nvs, 0x3E0000, 0x6000 +ota_0, app, ota_0, 0x20000, 1900K, +ota_1, app, ota_1, , 1900K, +fctry, data, nvs, , 0x6000 diff --git a/examples/light_wifi_prov/sdkconfig.defaults.esp32c3 b/examples/light_wifi_prov/sdkconfig.defaults.esp32c3 new file mode 100644 index 000000000..3d1401bbc --- /dev/null +++ b/examples/light_wifi_prov/sdkconfig.defaults.esp32c3 @@ -0,0 +1,71 @@ +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +# Enable Extended advertisement of NIMBLE +CONFIG_BT_NIMBLE_EXT_ADV=y +CONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES=2 + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0xC000 + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# Button +CONFIG_BUTTON_PERIOD_TIME_MS=20 +CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# ESP32-S3-DevKitC-1 Settings +# Buttons +CONFIG_BSP_BUTTONS_NUM=1 +CONFIG_BSP_BUTTON_1_TYPE_GPIO=y +CONFIG_BSP_BUTTON_1_GPIO=0 +CONFIG_BSP_BUTTON_1_LEVEL=0 + +# mbedtls +CONFIG_MBEDTLS_DYNAMIC_BUFFER=y +CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y +CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y +CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y + +# For additional security on reset to factory +CONFIG_ESP_RMAKER_USER_ID_CHECK=y + +# Fix for Timer Overflows +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=3120 + +# External Platform +CONFIG_CHIP_ENABLE_EXTERNAL_PLATFORM=y +CONFIG_CHIP_EXTERNAL_PLATFORM_DIR="../../../../examples/common/secondary_ble_adv/platform/ESP32_custom" +CONFIG_CHIP_EXTERNAL_PLATFORM_INCLUDE_DIR="../../../../examples/common/secondary_ble_adv" + +# Memory Optimization +CONFIG_ESP_WIFI_IRAM_OPT=n +CONFIG_ESP_WIFI_RX_IRAM_OPT=n +CONFIG_ESP_MATTER_MAX_DEVICE_TYPE_COUNT=2 +CONFIG_ESP_MATTER_BINDING_TABLE_SIZE=1 +CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE=512 +CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE=256 +CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE=256 +CONFIG_MAX_EXCHANGE_CONTEXTS=5 +CONFIG_MAX_BINDINGS=2 +CONFIG_MAX_PEER_NODES=8 +CONFIG_DISABLE_IPV4=y +CONFIG_NUM_TCP_ENDPOINTS=1 +CONFIG_NUM_UDP_ENDPOINTS=6