From 5f94d380c22c46267c521a008aff36653b902ecb Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Tue, 23 Aug 2022 18:48:29 +0530 Subject: [PATCH 01/16] [ESP32] Support disabling SOFTAP for saving some flash (#22096) * [ESP32] Support disabling SOFTAP support for saving some flash * Disable softap by default in examples * If rendezvous mode is softap then enable softap configurations --- config/esp32/components/chip/Kconfig | 1 + .../esp32/main/Kconfig.projbuild | 2 + .../all-clusters-app/esp32/sdkconfig.defaults | 3 ++ .../esp32/main/Kconfig.projbuild | 2 + .../esp32/sdkconfig.defaults | 3 ++ examples/bridge-app/esp32/sdkconfig.defaults | 3 ++ examples/chef/esp32/main/Kconfig.projbuild | 2 + examples/chef/esp32/sdkconfig.defaults | 3 ++ .../light-switch-app/esp32/sdkconfig.defaults | 5 ++- .../lighting-app/esp32/sdkconfig.defaults | 3 ++ examples/lock-app/esp32/sdkconfig.defaults | 3 ++ .../ota-provider-app/esp32/sdkconfig.defaults | 3 ++ .../esp32/sdkconfig.defaults | 3 ++ .../esp32/sdkconfig.defaults | 3 ++ src/platform/ESP32/CHIPDevicePlatformConfig.h | 2 + src/platform/ESP32/ConnectivityManagerImpl.h | 42 +++++++++++-------- .../ESP32/ConnectivityManagerImpl_WiFi.cpp | 23 ++++++++-- src/platform/ESP32/ESP32Utils.cpp | 9 +++- src/platform/ESP32/ESP32Utils.h | 2 + src/platform/ESP32/PlatformManagerImpl.cpp | 3 +- 20 files changed, 95 insertions(+), 25 deletions(-) diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index 4a6cc6dd6e889e..55cafa1c8a07a8 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -387,6 +387,7 @@ menu "CHIP Device Layer" menu "WiFi AP Options" config ENABLE_WIFI_AP + depends on ESP_WIFI_SOFTAP_SUPPORT bool "Enable CHIP WIFI AP" default y help diff --git a/examples/all-clusters-app/esp32/main/Kconfig.projbuild b/examples/all-clusters-app/esp32/main/Kconfig.projbuild index 8791a80a443e71..22edca7a03b264 100644 --- a/examples/all-clusters-app/esp32/main/Kconfig.projbuild +++ b/examples/all-clusters-app/esp32/main/Kconfig.projbuild @@ -53,6 +53,7 @@ menu "Demo" config RENDEZVOUS_MODE_SOFTAP bool "Soft-AP" + select ESP_WIFI_SOFTAP_SUPPORT config RENDEZVOUS_MODE_BLE bool "BLE" depends on BT_ENABLED @@ -60,6 +61,7 @@ menu "Demo" bool "On-Network" config RENDEZVOUS_MODE_SOFTAP_ON_NETWORK bool "Soft-AP / On-Network" + select ESP_WIFI_SOFTAP_SUPPORT config RENDEZVOUS_MODE_BLE_ON_NETWORK bool "BLE / On-Network" endchoice diff --git a/examples/all-clusters-app/esp32/sdkconfig.defaults b/examples/all-clusters-app/esp32/sdkconfig.defaults index 5f996f40946d68..a9c28a1a863a25 100644 --- a/examples/all-clusters-app/esp32/sdkconfig.defaults +++ b/examples/all-clusters-app/esp32/sdkconfig.defaults @@ -53,3 +53,6 @@ CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y # Serial Flasher config CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/all-clusters-minimal-app/esp32/main/Kconfig.projbuild b/examples/all-clusters-minimal-app/esp32/main/Kconfig.projbuild index 8791a80a443e71..22edca7a03b264 100644 --- a/examples/all-clusters-minimal-app/esp32/main/Kconfig.projbuild +++ b/examples/all-clusters-minimal-app/esp32/main/Kconfig.projbuild @@ -53,6 +53,7 @@ menu "Demo" config RENDEZVOUS_MODE_SOFTAP bool "Soft-AP" + select ESP_WIFI_SOFTAP_SUPPORT config RENDEZVOUS_MODE_BLE bool "BLE" depends on BT_ENABLED @@ -60,6 +61,7 @@ menu "Demo" bool "On-Network" config RENDEZVOUS_MODE_SOFTAP_ON_NETWORK bool "Soft-AP / On-Network" + select ESP_WIFI_SOFTAP_SUPPORT config RENDEZVOUS_MODE_BLE_ON_NETWORK bool "BLE / On-Network" endchoice diff --git a/examples/all-clusters-minimal-app/esp32/sdkconfig.defaults b/examples/all-clusters-minimal-app/esp32/sdkconfig.defaults index 5f996f40946d68..a9c28a1a863a25 100644 --- a/examples/all-clusters-minimal-app/esp32/sdkconfig.defaults +++ b/examples/all-clusters-minimal-app/esp32/sdkconfig.defaults @@ -53,3 +53,6 @@ CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y # Serial Flasher config CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/bridge-app/esp32/sdkconfig.defaults b/examples/bridge-app/esp32/sdkconfig.defaults index 6a6589e1040577..d76496f541c9ba 100644 --- a/examples/bridge-app/esp32/sdkconfig.defaults +++ b/examples/bridge-app/esp32/sdkconfig.defaults @@ -39,3 +39,6 @@ CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/chef/esp32/main/Kconfig.projbuild b/examples/chef/esp32/main/Kconfig.projbuild index 307b7f6ccb83bc..695222b7f43c45 100644 --- a/examples/chef/esp32/main/Kconfig.projbuild +++ b/examples/chef/esp32/main/Kconfig.projbuild @@ -55,6 +55,7 @@ menu "Demo" bool "Bypass" config RENDEZVOUS_MODE_SOFTAP bool "Soft-AP" + select ESP_WIFI_SOFTAP_SUPPORT config RENDEZVOUS_MODE_BLE bool "BLE" depends on BT_ENABLED @@ -62,6 +63,7 @@ menu "Demo" bool "On-Network" config RENDEZVOUS_MODE_SOFTAP_ON_NETWORK bool "Soft-AP / On-Network" + select ESP_WIFI_SOFTAP_SUPPORT config RENDEZVOUS_MODE_BLE_ON_NETWORK bool "BLE / On-Network" endchoice diff --git a/examples/chef/esp32/sdkconfig.defaults b/examples/chef/esp32/sdkconfig.defaults index ab2bb7c5dcb419..a3a1d8a272b8b3 100644 --- a/examples/chef/esp32/sdkconfig.defaults +++ b/examples/chef/esp32/sdkconfig.defaults @@ -47,3 +47,6 @@ CONFIG_STACK_CHECK=y # Serial Flasher config CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/light-switch-app/esp32/sdkconfig.defaults b/examples/light-switch-app/esp32/sdkconfig.defaults index f8d119e98c2bec..4e780d862ad614 100644 --- a/examples/light-switch-app/esp32/sdkconfig.defaults +++ b/examples/light-switch-app/esp32/sdkconfig.defaults @@ -45,4 +45,7 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_ESPTOOLPY_FLASHSIZE="4MB" #enable debug shell -CONFIG_ENABLE_CHIP_SHELL=y \ No newline at end of file +CONFIG_ENABLE_CHIP_SHELL=y + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/lighting-app/esp32/sdkconfig.defaults b/examples/lighting-app/esp32/sdkconfig.defaults index 23a3766c340c04..e051a3f2b37aee 100644 --- a/examples/lighting-app/esp32/sdkconfig.defaults +++ b/examples/lighting-app/esp32/sdkconfig.defaults @@ -43,3 +43,6 @@ CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y # Serial Flasher config CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/lock-app/esp32/sdkconfig.defaults b/examples/lock-app/esp32/sdkconfig.defaults index c9b513d752fc6c..d53bfc85c76c22 100644 --- a/examples/lock-app/esp32/sdkconfig.defaults +++ b/examples/lock-app/esp32/sdkconfig.defaults @@ -43,3 +43,6 @@ CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y #Lock app PID CONFIG_DEVICE_PRODUCT_ID=0x8006 + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/ota-provider-app/esp32/sdkconfig.defaults b/examples/ota-provider-app/esp32/sdkconfig.defaults index 537c6deab2897f..7fce894e5a80d8 100644 --- a/examples/ota-provider-app/esp32/sdkconfig.defaults +++ b/examples/ota-provider-app/esp32/sdkconfig.defaults @@ -58,3 +58,6 @@ CONFIG_USE_TEST_SETUP_DISCRIMINATOR=0xF01 # Enable chip shell CONFIG_ENABLE_CHIP_SHELL=y + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/ota-requestor-app/esp32/sdkconfig.defaults b/examples/ota-requestor-app/esp32/sdkconfig.defaults index beec4822b35cdf..17b6e378f65ca9 100644 --- a/examples/ota-requestor-app/esp32/sdkconfig.defaults +++ b/examples/ota-requestor-app/esp32/sdkconfig.defaults @@ -59,3 +59,6 @@ CONFIG_DEVICE_SOFTWARE_VERSION_NUMBER=2 # Enable Chip Shell CONFIG_ENABLE_CHIP_SHELL=y + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/examples/temperature-measurement-app/esp32/sdkconfig.defaults b/examples/temperature-measurement-app/esp32/sdkconfig.defaults index 4659af909a144f..dcd05c0734f36a 100644 --- a/examples/temperature-measurement-app/esp32/sdkconfig.defaults +++ b/examples/temperature-measurement-app/esp32/sdkconfig.defaults @@ -84,3 +84,6 @@ CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 #enable lwIP route hooks CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# Disable softap support by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n diff --git a/src/platform/ESP32/CHIPDevicePlatformConfig.h b/src/platform/ESP32/CHIPDevicePlatformConfig.h index 3bc56162c00350..c40cd8c565e11d 100644 --- a/src/platform/ESP32/CHIPDevicePlatformConfig.h +++ b/src/platform/ESP32/CHIPDevicePlatformConfig.h @@ -59,11 +59,13 @@ #define CHIP_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS CONFIG_MAX_SCAN_NETWORKS_RESULTS #define CHIP_DEVICE_CONFIG_WIFI_SCAN_COMPLETION_TIMEOUT CONFIG_WIFI_SCAN_COMPLETION_TIMEOUT #define CHIP_DEVICE_CONFIG_WIFI_CONNECTIVITY_TIMEOUT CONFIG_WIFI_CONNECTIVITY_TIMEOUT +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP #define CHIP_DEVICE_CONFIG_WIFI_AP_SSID_PREFIX CONFIG_WIFI_AP_SSID_PREFIX #define CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL CONFIG_WIFI_AP_CHANNEL #define CHIP_DEVICE_CONFIG_WIFI_AP_MAX_STATIONS CONFIG_WIFI_AP_MAX_STATIONS #define CHIP_DEVICE_CONFIG_WIFI_AP_BEACON_INTERVAL CONFIG_WIFI_AP_BEACON_INTERVAL #define CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT CONFIG_WIFI_AP_IDLE_TIMEOUT +#endif /* CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP */ #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY CONFIG_ENABLE_WIFI_TELEMETRY #define CHIP_DEVICE_CONFIG_ENABLE_WIFI CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP | CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION #endif // CONFIG_IDF_TARGET_ESP32H2 diff --git a/src/platform/ESP32/ConnectivityManagerImpl.h b/src/platform/ESP32/ConnectivityManagerImpl.h index 3bdd1418c23564..9c7f7774317318 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl.h +++ b/src/platform/ESP32/ConnectivityManagerImpl.h @@ -109,15 +109,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, CHIP_ERROR _SetWiFiStationReconnectInterval(System::Clock::Timeout val); bool _IsWiFiStationProvisioned(void); void _ClearWiFiStationProvision(void); - WiFiAPMode _GetWiFiAPMode(void); - CHIP_ERROR _SetWiFiAPMode(WiFiAPMode val); - bool _IsWiFiAPActive(void); - bool _IsWiFiAPApplicationControlled(void); - void _DemandStartWiFiAP(void); - void _StopOnDemandWiFiAP(void); - void _MaintainOnDemandWiFiAP(void); - System::Clock::Timeout _GetWiFiAPIdleTimeout(void); - void _SetWiFiAPIdleTimeout(System::Clock::Timeout val); CHIP_ERROR _GetAndLogWiFiStatsCounters(void); bool _CanStartWiFiScan(); void _OnWiFiScanDone(); @@ -126,13 +117,9 @@ class ConnectivityManagerImpl final : public ConnectivityManager, // ===== Private members reserved for use by this class only. System::Clock::Timestamp mLastStationConnectFailTime; - System::Clock::Timestamp mLastAPDemandTime; WiFiStationMode mWiFiStationMode; WiFiStationState mWiFiStationState; - WiFiAPMode mWiFiAPMode; - WiFiAPState mWiFiAPState; System::Clock::Timeout mWiFiStationReconnectInterval; - System::Clock::Timeout mWiFiAPIdleTimeout; BitFlags mFlags; CHIP_ERROR InitWiFi(void); @@ -144,10 +131,27 @@ class ConnectivityManagerImpl final : public ConnectivityManager, void ChangeWiFiStationState(WiFiStationState newState); static void DriveStationState(::chip::System::Layer * aLayer, void * aAppState); +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP + WiFiAPMode _GetWiFiAPMode(void); + CHIP_ERROR _SetWiFiAPMode(WiFiAPMode val); + bool _IsWiFiAPActive(void); + void _DemandStartWiFiAP(void); + void _StopOnDemandWiFiAP(void); + void _MaintainOnDemandWiFiAP(void); + System::Clock::Timeout _GetWiFiAPIdleTimeout(void); + void _SetWiFiAPIdleTimeout(System::Clock::Timeout val); + bool _IsWiFiAPApplicationControlled(void); + + System::Clock::Timestamp mLastAPDemandTime; + WiFiAPMode mWiFiAPMode; + WiFiAPState mWiFiAPState; + System::Clock::Timeout mWiFiAPIdleTimeout; + void DriveAPState(void); CHIP_ERROR ConfigureWiFiAP(void); void ChangeWiFiAPState(WiFiAPState newState); static void DriveAPState(::chip::System::Layer * aLayer, void * aAppState); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP void UpdateInternetConnectivityState(void); void OnStationIPv4AddressAvailable(const ip_event_got_ip_t & got_ip); @@ -174,16 +178,12 @@ inline bool ConnectivityManagerImpl::_IsWiFiStationConnected(void) return mWiFiStationState == kWiFiStationState_Connected; } -inline bool ConnectivityManagerImpl::_IsWiFiAPApplicationControlled(void) -{ - return mWiFiAPMode == kWiFiAPMode_ApplicationControlled; -} - inline System::Clock::Timeout ConnectivityManagerImpl::_GetWiFiStationReconnectInterval(void) { return mWiFiStationReconnectInterval; } +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP inline ConnectivityManager::WiFiAPMode ConnectivityManagerImpl::_GetWiFiAPMode(void) { return mWiFiAPMode; @@ -199,6 +199,12 @@ inline System::Clock::Timeout ConnectivityManagerImpl::_GetWiFiAPIdleTimeout(voi return mWiFiAPIdleTimeout; } +inline bool ConnectivityManagerImpl::_IsWiFiAPApplicationControlled(void) +{ + return mWiFiAPMode == kWiFiAPMode_ApplicationControlled; +} +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP + inline bool ConnectivityManagerImpl::_CanStartWiFiScan() { return mWiFiStationState != kWiFiStationState_Connecting; diff --git a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp index f00c92803908aa..2eb2e1b3ad11e0 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp +++ b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp @@ -110,10 +110,13 @@ void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) esp_wifi_set_config(WIFI_IF_STA, &stationConfig); DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP DeviceLayer::SystemLayer().ScheduleWork(DriveAPState, NULL); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP } } +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP CHIP_ERROR ConnectivityManagerImpl::_SetWiFiAPMode(WiFiAPMode val) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -167,6 +170,7 @@ void ConnectivityManagerImpl::_SetWiFiAPIdleTimeout(System::Clock::Timeout val) mWiFiAPIdleTimeout = val; DeviceLayer::SystemLayer().ScheduleWork(DriveAPState, NULL); } +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP #define WIFI_BAND_2_4GHZ 2400 #define WIFI_BAND_5_0GHZ 5000 @@ -382,13 +386,17 @@ CHIP_ERROR ConnectivityManagerImpl::_GetAndLogWiFiStatsCounters(void) CHIP_ERROR ConnectivityManagerImpl::InitWiFi() { mLastStationConnectFailTime = System::Clock::kZero; - mLastAPDemandTime = System::Clock::kZero; mWiFiStationMode = kWiFiStationMode_Disabled; mWiFiStationState = kWiFiStationState_NotConnected; - mWiFiAPMode = kWiFiAPMode_Disabled; - mWiFiAPState = kWiFiAPState_NotActive; mWiFiStationReconnectInterval = System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL); - mWiFiAPIdleTimeout = System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT); + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP + mLastAPDemandTime = System::Clock::kZero; + mWiFiAPMode = kWiFiAPMode_Disabled; + mWiFiAPState = kWiFiAPState_NotActive; + mWiFiAPIdleTimeout = System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP + mFlags.SetRaw(0); // TODO Initialize the Chip Addressing and Routing Module. @@ -435,7 +443,10 @@ CHIP_ERROR ConnectivityManagerImpl::InitWiFi() // Queue work items to bootstrap the AP and station state machines once the Chip event loop is running. ReturnErrorOnFailure(DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL)); + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP ReturnErrorOnFailure(DeviceLayer::SystemLayer().ScheduleWork(DriveAPState, NULL)); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP return CHIP_NO_ERROR; } @@ -478,6 +489,7 @@ void ConnectivityManagerImpl::OnWiFiPlatformEvent(const ChipDeviceEvent * event) ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_STOP"); DriveStationState(); break; +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP case WIFI_EVENT_AP_START: ChipLogProgress(DeviceLayer, "WIFI_EVENT_AP_START"); ChangeWiFiAPState(kWiFiAPState_Active); @@ -492,6 +504,7 @@ void ConnectivityManagerImpl::OnWiFiPlatformEvent(const ChipDeviceEvent * event) ChipLogProgress(DeviceLayer, "WIFI_EVENT_AP_STACONNECTED"); MaintainOnDemandWiFiAP(); break; +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP default: break; } @@ -769,6 +782,7 @@ void ConnectivityManagerImpl::DriveStationState(::chip::System::Layer * aLayer, sInstance.DriveStationState(); } +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP void ConnectivityManagerImpl::DriveAPState() { CHIP_ERROR err = CHIP_NO_ERROR; @@ -952,6 +966,7 @@ void ConnectivityManagerImpl::DriveAPState(::chip::System::Layer * aLayer, void { sInstance.DriveAPState(); } +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP void ConnectivityManagerImpl::UpdateInternetConnectivityState(void) { diff --git a/src/platform/ESP32/ESP32Utils.cpp b/src/platform/ESP32/ESP32Utils.cpp index 9391ee586e3eb6..e6dd3ea4df09c3 100644 --- a/src/platform/ESP32/ESP32Utils.cpp +++ b/src/platform/ESP32/ESP32Utils.cpp @@ -38,6 +38,7 @@ using namespace ::chip::DeviceLayer::Internal; using chip::DeviceLayer::Internal::DeviceNetworkInfo; +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP CHIP_ERROR ESP32Utils::IsAPEnabled(bool & apEnabled) { wifi_mode_t curWiFiMode; @@ -53,6 +54,7 @@ CHIP_ERROR ESP32Utils::IsAPEnabled(bool & apEnabled) return CHIP_NO_ERROR; } +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP CHIP_ERROR ESP32Utils::IsStationEnabled(bool & staEnabled) { @@ -130,6 +132,7 @@ CHIP_ERROR ESP32Utils::EnableStationMode(void) return ESP32Utils::MapError(err); } +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP // If station mode is not already enabled (implying the current mode is WIFI_MODE_AP), change // the mode to WIFI_MODE_APSTA. if (curWiFiMode == WIFI_MODE_AP) @@ -144,15 +147,19 @@ CHIP_ERROR ESP32Utils::EnableStationMode(void) return ESP32Utils::MapError(err); } } +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP return CHIP_NO_ERROR; } CHIP_ERROR ESP32Utils::SetAPMode(bool enabled) { - wifi_mode_t curWiFiMode, targetWiFiMode; + wifi_mode_t curWiFiMode; + wifi_mode_t targetWiFiMode = WIFI_MODE_STA; +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP targetWiFiMode = (enabled) ? WIFI_MODE_APSTA : WIFI_MODE_STA; +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP // Get the current ESP WiFI mode. esp_err_t err = esp_wifi_get_mode(&curWiFiMode); diff --git a/src/platform/ESP32/ESP32Utils.h b/src/platform/ESP32/ESP32Utils.h index 94a98e0f8b281e..716b85e8434d3a 100644 --- a/src/platform/ESP32/ESP32Utils.h +++ b/src/platform/ESP32/ESP32Utils.h @@ -29,7 +29,9 @@ namespace Internal { class ESP32Utils { public: +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP static CHIP_ERROR IsAPEnabled(bool & apEnabled); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP static CHIP_ERROR IsStationEnabled(bool & staEnabled); static bool IsStationProvisioned(void); static CHIP_ERROR IsStationConnected(bool & connected); diff --git a/src/platform/ESP32/PlatformManagerImpl.cpp b/src/platform/ESP32/PlatformManagerImpl.cpp index c96caeb03934ef..d2254692924cca 100644 --- a/src/platform/ESP32/PlatformManagerImpl.cpp +++ b/src/platform/ESP32/PlatformManagerImpl.cpp @@ -84,8 +84,9 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) wifi_init_config_t cfg; uint8_t ap_mac[6]; wifi_mode_t mode; - +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP esp_netif_create_default_wifi_ap(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP esp_netif_create_default_wifi_sta(); esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL); From 543ae309d7ddcb313a8e706a91f15c2fce35e104 Mon Sep 17 00:00:00 2001 From: jmartinez-silabs <67972863+jmartinez-silabs@users.noreply.github.com> Date: Tue, 23 Aug 2022 09:22:23 -0400 Subject: [PATCH 02/16] address PR22049 post-merge commments (#22085) --- examples/chef/efr32/BUILD.gn | 2 +- examples/light-switch-app/efr32/BUILD.gn | 2 +- examples/lighting-app/efr32/BUILD.gn | 2 +- examples/lock-app/efr32/BUILD.gn | 2 +- examples/shell/shell_common/BUILD.gn | 2 +- examples/thermostat/efr32/BUILD.gn | 2 +- examples/window-app/efr32/BUILD.gn | 2 +- src/inet/BUILD.gn | 2 +- src/platform/EFR32/BUILD.gn | 2 +- src/test_driver/efr32/BUILD.gn | 2 +- third_party/openthread/BUILD.gn | 4 ++-- third_party/silabs/BUILD.gn | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/chef/efr32/BUILD.gn b/examples/chef/efr32/BUILD.gn index c567ae9d8f1cbf..e23b747fcad1dd 100644 --- a/examples/chef/efr32/BUILD.gn +++ b/examples/chef/efr32/BUILD.gn @@ -207,7 +207,7 @@ efr32_executable("chef_app") { if (chip_enable_openthread) { deps += [ "${chip_root}/third_party/openthread:openthread", - "${chip_root}/third_party/openthread:openthread_device", + "${chip_root}/third_party/openthread:openthread-platform", "${examples_plat_dir}:efr-matter-shell", ] } diff --git a/examples/light-switch-app/efr32/BUILD.gn b/examples/light-switch-app/efr32/BUILD.gn index e2705abdedcb65..2d628f537f9f6e 100644 --- a/examples/light-switch-app/efr32/BUILD.gn +++ b/examples/light-switch-app/efr32/BUILD.gn @@ -200,7 +200,7 @@ efr32_executable("light_switch_app") { if (chip_enable_openthread) { deps += [ "${chip_root}/third_party/openthread:openthread", - "${chip_root}/third_party/openthread:openthread_device", + "${chip_root}/third_party/openthread:openthread-platform", "${examples_plat_dir}:efr-matter-shell", ] } diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 060b9f67343aa0..fbd5a88a7909b9 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -205,7 +205,7 @@ efr32_executable("lighting_app") { if (chip_enable_openthread) { deps += [ "${chip_root}/third_party/openthread:openthread", - "${chip_root}/third_party/openthread:openthread_device", + "${chip_root}/third_party/openthread:openthread-platform", "${examples_plat_dir}:efr-matter-shell", ] } diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index 2f8f2dc6bf67b4..e76b9cd48f1d1e 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -202,7 +202,7 @@ efr32_executable("lock_app") { if (chip_enable_openthread) { deps += [ "${chip_root}/third_party/openthread:openthread", - "${chip_root}/third_party/openthread:openthread_device", + "${chip_root}/third_party/openthread:openthread-platform", "${examples_plat_dir}:efr-matter-shell", ] } diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index 0217eb057fdff4..d601f0b54764b8 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -53,8 +53,8 @@ static_library("shell_common") { if (chip_enable_openthread && (current_os == "freertos" || current_os == "zephyr")) { public_deps += [ + "${chip_root}/third_party/openthread:openthread", "${chip_root}/third_party/openthread:openthread_cli", - "${chip_root}/third_party/openthread:openthread_device", ] } diff --git a/examples/thermostat/efr32/BUILD.gn b/examples/thermostat/efr32/BUILD.gn index edb03073686e3e..7e4e923992ff70 100644 --- a/examples/thermostat/efr32/BUILD.gn +++ b/examples/thermostat/efr32/BUILD.gn @@ -196,7 +196,7 @@ efr32_executable("thermostat_app") { if (chip_enable_openthread) { deps += [ "${chip_root}/third_party/openthread:openthread", - "${chip_root}/third_party/openthread:openthread_device", + "${chip_root}/third_party/openthread:openthread-platform", "${examples_plat_dir}:efr-matter-shell", ] } diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index c7a3f57e4b9ff8..a9aa7cf402911c 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -188,7 +188,7 @@ efr32_executable("window_app") { if (chip_enable_openthread) { deps += [ "${chip_root}/third_party/openthread:openthread", - "${chip_root}/third_party/openthread:openthread_device", + "${chip_root}/third_party/openthread:openthread-platform", "${examples_plat_dir}:efr-matter-shell", ] } diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index a042007d02c5a3..cb86a45780df9c 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -107,7 +107,7 @@ static_library("inet") { } if (chip_system_config_use_open_thread_inet_endpoints) { - public_deps += [ "${chip_root}/third_party/openthread:openthread_device" ] + public_deps += [ "${chip_root}/third_party/openthread:openthread" ] } if (chip_inet_config_enable_tcp_endpoint) { diff --git a/src/platform/EFR32/BUILD.gn b/src/platform/EFR32/BUILD.gn index eb73a6f80f85cf..1b5d6c45bbe3ba 100644 --- a/src/platform/EFR32/BUILD.gn +++ b/src/platform/EFR32/BUILD.gn @@ -98,7 +98,7 @@ static_library("EFR32") { "$dir_pw_kvs", ] if (chip_enable_openthread) { - public_deps += [ "${chip_root}/third_party/openthread:openthread_device" ] + public_deps += [ "${chip_root}/third_party/openthread:openthread" ] deps += [ "${chip_root}/third_party/openthread:openthread_cli" ] diff --git a/src/test_driver/efr32/BUILD.gn b/src/test_driver/efr32/BUILD.gn index 8ee3c4f3e59c69..1d6f87637a99db 100644 --- a/src/test_driver/efr32/BUILD.gn +++ b/src/test_driver/efr32/BUILD.gn @@ -96,7 +96,7 @@ efr32_executable("efr32_device_tests") { if (chip_enable_openthread) { deps += [ "${chip_root}/third_party/openthread:openthread", - "${chip_root}/third_party/openthread:openthread_device", + "${chip_root}/third_party/openthread:openthread-platform", "${examples_plat_dir}:efr-matter-shell", ] } diff --git a/third_party/openthread/BUILD.gn b/third_party/openthread/BUILD.gn index 9ee8e905551837..7a183e681867dc 100644 --- a/third_party/openthread/BUILD.gn +++ b/third_party/openthread/BUILD.gn @@ -8,7 +8,7 @@ declare_args() { chip_openthread_target = "" } -group("openthread") { +group("openthread-platform") { if (chip_openthread_target != "") { public_deps = [ chip_openthread_target ] } else { @@ -19,7 +19,7 @@ group("openthread") { } } -group("openthread_device") { +group("openthread") { if (chip_openthread_target != "") { public_deps = [ chip_openthread_target ] } else { diff --git a/third_party/silabs/BUILD.gn b/third_party/silabs/BUILD.gn index 1589f72e7865ae..7e885642cdd6f2 100644 --- a/third_party/silabs/BUILD.gn +++ b/third_party/silabs/BUILD.gn @@ -131,7 +131,7 @@ if (use_silabs_thread_lib) { ":libopenthread-platform", ":openthread_core_config_efr32", "${segger_rtt_root}:segger_rtt", - "${sl_openthread_root}/include/openthread:openthread", + "${sl_openthread_root}/include/openthread:openthread-platform", "${sl_openthread_root}/src/core/:libopenthread_core_headers", ] From 65d9ccf7461f8c45b4a07c4ca3e9c764dcc5793d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Kr=C3=B3lik?= <66667989+Damian-Nordic@users.noreply.github.com> Date: Tue, 23 Aug 2022 15:34:51 +0200 Subject: [PATCH 03/16] [nrfconnect] Fix Docker build due to conflicting PIP packages (#22072) nRF Connect Docker image build started to fail due to some conflicts in documentation dependencies. We don't need those dependencies in Matter CI, so get rid off them. Signed-off-by: Damian Krolik Signed-off-by: Damian Krolik --- integrations/docker/images/chip-build-nrf-platform/Dockerfile | 2 +- integrations/docker/images/chip-build/version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integrations/docker/images/chip-build-nrf-platform/Dockerfile b/integrations/docker/images/chip-build-nrf-platform/Dockerfile index f27f0813c748b3..280534cac6c9fe 100644 --- a/integrations/docker/images/chip-build-nrf-platform/Dockerfile +++ b/integrations/docker/images/chip-build-nrf-platform/Dockerfile @@ -61,7 +61,7 @@ RUN set -x \ && (apt-get remove -fy python3-yaml && apt-get autoremove || exit 0) \ && python3 -m pip install -U --no-cache-dir cmake==3.22.5 \ && python3 -m pip install --no-cache-dir -r /opt/NordicSemiconductor/nrfconnect/zephyr/scripts/requirements.txt \ - && python3 -m pip install --no-cache-dir -r /opt/NordicSemiconductor/nrfconnect/nrf/scripts/requirements.txt \ + && python3 -m pip install --no-cache-dir -r /opt/NordicSemiconductor/nrfconnect/nrf/scripts/requirements-build.txt \ && python3 -m pip install --no-cache-dir -r /opt/NordicSemiconductor/nrfconnect/bootloader/mcuboot/scripts/requirements.txt \ && : # last line diff --git a/integrations/docker/images/chip-build/version b/integrations/docker/images/chip-build/version index 0791656d59351a..1cb8eca1c7f032 100644 --- a/integrations/docker/images/chip-build/version +++ b/integrations/docker/images/chip-build/version @@ -1 +1 @@ -0.5.94 Version bump reason: Install ccache to the chip-build image +0.5.95 Version bump reason: Fix nrfconnect Docker build From ae16a8c75815c6b92c1c2788947a76a3127e3a56 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Tue, 23 Aug 2022 19:07:41 +0530 Subject: [PATCH 04/16] [ESP32] Fix namespace for unique id and added rotating device id (#22063) unique id key in chip-factory namespace Unique-id should be changed after every factory reset and to do that it should be stored in chip-config namespace. Earlier it was stored in chip-factory which is not erased on factory reset. --- .../tools/generate_esp32_chip_factory_bin.py | 12 +++++------ src/platform/ESP32/ESP32Config.cpp | 3 ++- src/platform/ESP32/ESP32Config.h | 21 +++++++++++-------- .../ESP32/ESP32FactoryDataProvider.cpp | 5 +++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/scripts/tools/generate_esp32_chip_factory_bin.py b/scripts/tools/generate_esp32_chip_factory_bin.py index d5f6ed380a91c6..64b6c293fd6510 100755 --- a/scripts/tools/generate_esp32_chip_factory_bin.py +++ b/scripts/tools/generate_esp32_chip_factory_bin.py @@ -140,7 +140,7 @@ 'encoding': 'string', 'value': None, }, - 'unique-id': { + 'rd-id-uid': { 'type': 'data', 'encoding': 'hex2bin', 'value': None, @@ -260,7 +260,7 @@ def validate_args(args): check_str_range(args.product_name, 1, 32, 'Product name') check_str_range(args.hw_ver_str, 1, 64, 'Hardware version string') check_str_range(args.mfg_date, 8, 16, 'Manufacturing date') - check_str_range(args.unique_id, 32, 32, 'Unique id') + check_str_range(args.rd_id_uid, 32, 32, 'Rotating device Unique id') logging.info('Discriminator:{} Passcode:{}'.format(args.discriminator, args.passcode)) @@ -295,8 +295,8 @@ def populate_factory_data(args, spake2p_params): if args.serial_num is not None: FACTORY_DATA['serial-num']['value'] = args.serial_num - if args.unique_id is not None: - FACTORY_DATA['unique-id']['value'] = args.unique_id + if args.rd_id_uid is not None: + FACTORY_DATA['rd-id-uid']['value'] = args.rd_id_uid if args.mfg_date is not None: FACTORY_DATA['mfg-date']['value'] = args.mfg_date if args.vendor_id is not None: @@ -460,8 +460,8 @@ def any_base_int(s): return int(s, 0) parser.add_argument('--hw-ver-str', type=str, required=False, help='Hardware version string') parser.add_argument('--mfg-date', type=str, required=False, help='Manufacturing date in format YYYY-MM-DD') parser.add_argument('--serial-num', type=str, required=False, help='Serial number') - parser.add_argument('--unique-id', type=str, required=False, - help='128-bit unique identifier, provide 32-byte hex string, e.g. "1234567890abcdef1234567890abcdef"') + parser.add_argument('--rd-id-uid', type=str, required=False, + help='128-bit unique identifier for generating rotating device identifier, provide 32-byte hex string, e.g. "1234567890abcdef1234567890abcdef"') # These will be used by DeviceInfoProvider parser.add_argument('--calendar-types', type=str, nargs='+', required=False, diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index 0feaa568886f29..537ec90375c754 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -72,9 +72,9 @@ const ESP32Config::Key ESP32Config::kConfigKey_VendorId = { kConfig const ESP32Config::Key ESP32Config::kConfigKey_VendorName = { kConfigNamespace_ChipFactory, "vendor-name" }; const ESP32Config::Key ESP32Config::kConfigKey_ProductId = { kConfigNamespace_ChipFactory, "product-id" }; const ESP32Config::Key ESP32Config::kConfigKey_ProductName = { kConfigNamespace_ChipFactory, "product-name" }; -const ESP32Config::Key ESP32Config::kConfigKey_UniqueId = { kConfigNamespace_ChipFactory, "unique-id" }; const ESP32Config::Key ESP32Config::kConfigKey_SupportedCalTypes = { kConfigNamespace_ChipFactory, "cal-types" }; const ESP32Config::Key ESP32Config::kConfigKey_SupportedLocaleSize = { kConfigNamespace_ChipFactory, "locale-sz" }; +const ESP32Config::Key ESP32Config::kConfigKey_RotatingDevIdUniqueId = { kConfigNamespace_ChipFactory, "rd-id-uid" }; // Keys stored in the chip-config namespace const ESP32Config::Key ESP32Config::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" }; @@ -85,6 +85,7 @@ const ESP32Config::Key ESP32Config::kConfigKey_FailSafeArmed = { kConfigNam const ESP32Config::Key ESP32Config::kConfigKey_WiFiStationSecType = { kConfigNamespace_ChipConfig, "sta-sec-type" }; const ESP32Config::Key ESP32Config::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "reg-location" }; const ESP32Config::Key ESP32Config::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" }; +const ESP32Config::Key ESP32Config::kConfigKey_UniqueId = { kConfigNamespace_ChipConfig, "unique-id" }; // Keys stored in the Chip-counters namespace const ESP32Config::Key ESP32Config::kCounterKey_RebootCount = { kConfigNamespace_ChipCounters, "reboot-count" }; diff --git a/src/platform/ESP32/ESP32Config.h b/src/platform/ESP32/ESP32Config.h index 86138368352a7f..e038b664fb8a09 100644 --- a/src/platform/ESP32/ESP32Config.h +++ b/src/platform/ESP32/ESP32Config.h @@ -53,7 +53,6 @@ class ESP32Config // Key definitions for well-known keys. static const Key kConfigKey_SerialNum; - static const Key kConfigKey_UniqueId; static const Key kConfigKey_MfrDeviceId; static const Key kConfigKey_MfrDeviceCert; static const Key kConfigKey_MfrDeviceICACerts; @@ -62,15 +61,7 @@ class ESP32Config static const Key kConfigKey_HardwareVersionString; static const Key kConfigKey_ManufacturingDate; static const Key kConfigKey_SetupPinCode; - static const Key kConfigKey_ServiceConfig; - static const Key kConfigKey_PairedAccountId; - static const Key kConfigKey_ServiceId; - static const Key kConfigKey_LastUsedEpochKeyId; - static const Key kConfigKey_FailSafeArmed; - static const Key kConfigKey_WiFiStationSecType; static const Key kConfigKey_SetupDiscriminator; - static const Key kConfigKey_RegulatoryLocation; - static const Key kConfigKey_CountryCode; static const Key kConfigKey_Spake2pIterationCount; static const Key kConfigKey_Spake2pSalt; static const Key kConfigKey_Spake2pVerifier; @@ -85,6 +76,18 @@ class ESP32Config static const Key kConfigKey_ProductName; static const Key kConfigKey_SupportedCalTypes; static const Key kConfigKey_SupportedLocaleSize; + static const Key kConfigKey_RotatingDevIdUniqueId; + + // CHIP Config keys + static const Key kConfigKey_ServiceConfig; + static const Key kConfigKey_PairedAccountId; + static const Key kConfigKey_ServiceId; + static const Key kConfigKey_LastUsedEpochKeyId; + static const Key kConfigKey_FailSafeArmed; + static const Key kConfigKey_WiFiStationSecType; + static const Key kConfigKey_RegulatoryLocation; + static const Key kConfigKey_CountryCode; + static const Key kConfigKey_UniqueId; // CHIP Counter keys static const Key kCounterKey_RebootCount; diff --git a/src/platform/ESP32/ESP32FactoryDataProvider.cpp b/src/platform/ESP32/ESP32FactoryDataProvider.cpp index 443374b2c4421b..8239a96b159f48 100644 --- a/src/platform/ESP32/ESP32FactoryDataProvider.cpp +++ b/src/platform/ESP32/ESP32FactoryDataProvider.cpp @@ -198,12 +198,13 @@ CHIP_ERROR ESP32FactoryDataProvider::GetHardwareVersionString(char * buf, size_t CHIP_ERROR ESP32FactoryDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) { ChipError err = CHIP_ERROR_WRONG_KEY_TYPE; -#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) +#if CHIP_ENABLE_ROTATING_DEVICE_ID static_assert(ConfigurationManager::kRotatingDeviceIDUniqueIDLength >= ConfigurationManager::kMinRotatingDeviceIDUniqueIDLength, "Length of unique ID for rotating device ID is smaller than minimum."); size_t uniqueIdLen = 0; - err = ESP32Config::ReadConfigValueBin(ESP32Config::kConfigKey_UniqueId, uniqueIdSpan.data(), uniqueIdSpan.size(), uniqueIdLen); + err = ESP32Config::ReadConfigValueBin(ESP32Config::kConfigKey_RotatingDevIdUniqueId, uniqueIdSpan.data(), uniqueIdSpan.size(), + uniqueIdLen); ReturnErrorOnFailure(err); uniqueIdSpan.reduce_size(uniqueIdLen); #endif From db3ce611a967ce9a93e3c6cf63519ef020f5c0ea Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Tue, 23 Aug 2022 19:10:03 +0530 Subject: [PATCH 05/16] [ESP32] Remove stale USE_ECHO_CLIENT and ECHO_HOST_IP kconfig options (#22097) --- .../all-clusters-app/esp32/main/Kconfig.projbuild | 7 ------- .../esp32/main/Kconfig.projbuild | 7 ------- examples/chef/esp32/main/Kconfig.projbuild | 7 ------- examples/lock-app/esp32/main/Kconfig.projbuild | 14 -------------- .../esp32/main/Kconfig.projbuild | 14 -------------- 5 files changed, 49 deletions(-) diff --git a/examples/all-clusters-app/esp32/main/Kconfig.projbuild b/examples/all-clusters-app/esp32/main/Kconfig.projbuild index 22edca7a03b264..dbf11ecaab5a57 100644 --- a/examples/all-clusters-app/esp32/main/Kconfig.projbuild +++ b/examples/all-clusters-app/esp32/main/Kconfig.projbuild @@ -66,13 +66,6 @@ menu "Demo" bool "BLE / On-Network" endchoice - config ECHO_HOST_IP - string "IPV4 address" - default "127.0.0.1" - depends on USE_ECHO_CLIENT - help - The IPV4 Address of the ECHO Server. - # NOTE: This config is not displayed as a input in the Kconfig menu, as its value is # entirely derived from the Device Type choice. However the CONFIG_EXAMPLE_DISPLAY_TYPE # define that is produced is needed to configure the TFT library correctly. diff --git a/examples/all-clusters-minimal-app/esp32/main/Kconfig.projbuild b/examples/all-clusters-minimal-app/esp32/main/Kconfig.projbuild index 22edca7a03b264..dbf11ecaab5a57 100644 --- a/examples/all-clusters-minimal-app/esp32/main/Kconfig.projbuild +++ b/examples/all-clusters-minimal-app/esp32/main/Kconfig.projbuild @@ -66,13 +66,6 @@ menu "Demo" bool "BLE / On-Network" endchoice - config ECHO_HOST_IP - string "IPV4 address" - default "127.0.0.1" - depends on USE_ECHO_CLIENT - help - The IPV4 Address of the ECHO Server. - # NOTE: This config is not displayed as a input in the Kconfig menu, as its value is # entirely derived from the Device Type choice. However the CONFIG_EXAMPLE_DISPLAY_TYPE # define that is produced is needed to configure the TFT library correctly. diff --git a/examples/chef/esp32/main/Kconfig.projbuild b/examples/chef/esp32/main/Kconfig.projbuild index 695222b7f43c45..a2b3ea3ce1c34c 100644 --- a/examples/chef/esp32/main/Kconfig.projbuild +++ b/examples/chef/esp32/main/Kconfig.projbuild @@ -68,13 +68,6 @@ menu "Demo" bool "BLE / On-Network" endchoice - config ECHO_HOST_IP - string "IPV4 address" - default "127.0.0.1" - depends on USE_ECHO_CLIENT - help - The IPV4 Address of the ECHO Server. - # NOTE: This config is not displayed as a input in the Kconfig menu, as its value is # entirely derived from the Device Type choice. However the CONFIG_EXAMPLE_DISPLAY_TYPE # define that is produced is needed to configure the TFT library correctly. diff --git a/examples/lock-app/esp32/main/Kconfig.projbuild b/examples/lock-app/esp32/main/Kconfig.projbuild index e2ec051d774fe1..4ec2e859c0b1f5 100644 --- a/examples/lock-app/esp32/main/Kconfig.projbuild +++ b/examples/lock-app/esp32/main/Kconfig.projbuild @@ -36,20 +36,6 @@ menu "Demo" bool "Ethernet" endchoice - config USE_ECHO_CLIENT - bool "Enable the built-in Echo Client" - default "n" - help - This enables a local FreeRTOS Echo Client so that the end-to-end echo server can be - tested easily - - config ECHO_HOST_IP - string "IPV4 address" - default "127.0.0.1" - depends on USE_ECHO_CLIENT - help - The IPV4 Address of the ECHO Server. - config RENDEZVOUS_MODE int range 0 8 diff --git a/examples/temperature-measurement-app/esp32/main/Kconfig.projbuild b/examples/temperature-measurement-app/esp32/main/Kconfig.projbuild index e2ec051d774fe1..4ec2e859c0b1f5 100644 --- a/examples/temperature-measurement-app/esp32/main/Kconfig.projbuild +++ b/examples/temperature-measurement-app/esp32/main/Kconfig.projbuild @@ -36,20 +36,6 @@ menu "Demo" bool "Ethernet" endchoice - config USE_ECHO_CLIENT - bool "Enable the built-in Echo Client" - default "n" - help - This enables a local FreeRTOS Echo Client so that the end-to-end echo server can be - tested easily - - config ECHO_HOST_IP - string "IPV4 address" - default "127.0.0.1" - depends on USE_ECHO_CLIENT - help - The IPV4 Address of the ECHO Server. - config RENDEZVOUS_MODE int range 0 8 From cfdb308152223458dfb28a4a606ef4c68c79245d Mon Sep 17 00:00:00 2001 From: Evgeny Margolis Date: Tue, 23 Aug 2022 06:41:28 -0700 Subject: [PATCH 06/16] TC_RR_1_1: Updated Method that Was Used to Generate Large Sized Operational Certificates (#22088) * TC_RR_1_1: Updated Method that Was Used to Generate Large Sized Operational Certificates. Instead of padding the subject DN this method adds size by adding Future Extension. This new approach doesen't have certain limitations compare to the previous approach and allows generation of larger certificates of approximate sizes: {RCAC, ICAC, NOC} ~ {400, 400, 350} bytes in TLV encoded form. * Update src/credentials/tests/TestChipCert.cpp Co-authored-by: Tennessee Carmel-Veilleux Co-authored-by: Tennessee Carmel-Veilleux --- .../ExampleOperationalCredentialsIssuer.cpp | 39 ++++++++----------- src/credentials/CHIPCert.h | 7 ++++ src/credentials/GenerateChipX509Cert.cpp | 30 +++++++++++++- src/credentials/tests/TestChipCert.cpp | 36 +++++++++++++++++ src/tools/chip-cert/CertUtils.cpp | 4 +- src/tools/chip-cert/Cmd_GenCert.cpp | 26 ++++++------- src/tools/chip-cert/chip-cert.h | 12 +++--- 7 files changed, 109 insertions(+), 45 deletions(-) diff --git a/src/controller/ExampleOperationalCredentialsIssuer.cpp b/src/controller/ExampleOperationalCredentialsIssuer.cpp index 9c0b376b13716c..dc026dbbf88bfd 100644 --- a/src/controller/ExampleOperationalCredentialsIssuer.cpp +++ b/src/controller/ExampleOperationalCredentialsIssuer.cpp @@ -52,10 +52,11 @@ CHIP_ERROR IssueX509Cert(uint32_t now, uint32_t validity, ChipDN issuerDn, ChipD const Crypto::P256PublicKey & subjectPublicKey, Crypto::P256Keypair & issuerKeypair, MutableByteSpan & outX509Cert) { - constexpr size_t kDERCertDnEncodingOverhead = 11; - constexpr size_t kTLVCertDnEncodingOverhead = 3; - constexpr size_t kMaxCertPaddingLength = 150; - constexpr size_t kTLVDesiredSize = kMaxCHIPCertLength - 50; + constexpr size_t kDERCertFutureExtEncodingOverhead = 12; + constexpr size_t kTLVCertFutureExtEncodingOverhead = kDERCertFutureExtEncodingOverhead + 5; + constexpr size_t kMaxCertPaddingLength = 200; + constexpr size_t kTLVDesiredSize = kMaxCHIPCertLength; + constexpr uint8_t sOID_Extension_SubjectAltName[] = { 0x55, 0x1d, 0x11 }; Platform::ScopedMemoryBuffer derBuf; ReturnErrorCodeIf(!derBuf.Alloc(kMaxDERCertLength), CHIP_ERROR_NO_MEMORY); @@ -84,7 +85,7 @@ CHIP_ERROR IssueX509Cert(uint32_t now, uint32_t validity, ChipDN issuerDn, ChipD return CHIP_ERROR_INVALID_ARGUMENT; } - if (maximizeSize && (desiredDn.RDNCount() < CHIP_CONFIG_CERT_MAX_RDN_ATTRIBUTES)) + if (maximizeSize) { Platform::ScopedMemoryBuffer paddedTlvBuf; ReturnErrorCodeIf(!paddedTlvBuf.Alloc(kMaxCHIPCertLength + kMaxCertPaddingLength), CHIP_ERROR_NO_MEMORY); @@ -99,15 +100,8 @@ CHIP_ERROR IssueX509Cert(uint32_t now, uint32_t validity, ChipDN issuerDn, ChipD ReturnErrorCodeIf(!fillerBuf.Alloc(kMaxCertPaddingLength), CHIP_ERROR_NO_MEMORY); memset(fillerBuf.Get(), 'A', kMaxCertPaddingLength); - int derPaddingLen = static_cast(kMaxDERCertLength - kDERCertDnEncodingOverhead - derSpan.size()); - int tlvPaddingLen = static_cast(kTLVDesiredSize - kTLVCertDnEncodingOverhead - paddedTlvSpan.size()); - if (certType == CertType::kRcac) - { - // For RCAC the issuer/subject DN are the same so padding will be present in both - derPaddingLen = (derPaddingLen - static_cast(kDERCertDnEncodingOverhead)) / 2; - tlvPaddingLen = (tlvPaddingLen - static_cast(kTLVCertDnEncodingOverhead)) / 2; - } - + int derPaddingLen = static_cast(kMaxDERCertLength - kDERCertFutureExtEncodingOverhead - derSpan.size()); + int tlvPaddingLen = static_cast(kTLVDesiredSize - kTLVCertFutureExtEncodingOverhead - paddedTlvSpan.size()); size_t paddingLen = 0; if (derPaddingLen >= 1 && tlvPaddingLen >= 1) { @@ -119,24 +113,25 @@ CHIP_ERROR IssueX509Cert(uint32_t now, uint32_t validity, ChipDN issuerDn, ChipD paddedDerSpan = MutableByteSpan{ paddedDerBuf.Get(), kMaxDERCertLength + kMaxCertPaddingLength }; paddedTlvSpan = MutableByteSpan{ paddedTlvBuf.Get(), kMaxCHIPCertLength + kMaxCertPaddingLength }; - ChipDN certDn = desiredDn; - // Fill the padding in the DomainNameQualifier DN - certDn.AddAttribute_DNQualifier(CharSpan(fillerBuf.Get(), paddingLen), false); + Optional futureExt; + FutureExtension ext = { ByteSpan(sOID_Extension_SubjectAltName), + ByteSpan(reinterpret_cast(fillerBuf.Get()), paddingLen) }; + futureExt.SetValue(ext); switch (certType) { case CertType::kRcac: { - X509CertRequestParams rcacRequest = { serialNumber, now, now + validity, certDn, certDn }; + X509CertRequestParams rcacRequest = { serialNumber, now, now + validity, desiredDn, desiredDn, futureExt }; ReturnErrorOnFailure(NewRootX509Cert(rcacRequest, issuerKeypair, paddedDerSpan)); break; } case CertType::kIcac: { - X509CertRequestParams icacRequest = { serialNumber, now, now + validity, certDn, issuerDn }; + X509CertRequestParams icacRequest = { serialNumber, now, now + validity, desiredDn, issuerDn, futureExt }; ReturnErrorOnFailure(NewICAX509Cert(icacRequest, subjectPublicKey, issuerKeypair, paddedDerSpan)); break; } case CertType::kNoc: { - X509CertRequestParams nocRequest = { serialNumber, now, now + validity, certDn, issuerDn }; + X509CertRequestParams nocRequest = { serialNumber, now, now + validity, desiredDn, issuerDn, futureExt }; ReturnErrorOnFailure(NewNodeOperationalX509Cert(nocRequest, subjectPublicKey, issuerKeypair, paddedDerSpan)); break; } @@ -146,10 +141,10 @@ CHIP_ERROR IssueX509Cert(uint32_t now, uint32_t validity, ChipDN issuerDn, ChipD ReturnErrorOnFailure(ConvertX509CertToChipCert(paddedDerSpan, paddedTlvSpan)); - ChipLogProgress(Controller, "Generated maximized certificate with %u DER bytes, %u TLV bytes", - static_cast(paddedDerSpan.size()), static_cast(paddedTlvSpan.size())); if (paddedDerSpan.size() <= kMaxDERCertLength && paddedTlvSpan.size() <= kMaxCHIPCertLength) { + ChipLogProgress(Controller, "Generated maximized certificate with %u DER bytes, %u TLV bytes", + static_cast(paddedDerSpan.size()), static_cast(paddedTlvSpan.size())); return CopySpanToMutableSpan(paddedDerSpan, outX509Cert); } } diff --git a/src/credentials/CHIPCert.h b/src/credentials/CHIPCert.h index 2f3fb7f0d76253..d95671ee74c3a4 100644 --- a/src/credentials/CHIPCert.h +++ b/src/credentials/CHIPCert.h @@ -507,6 +507,12 @@ CHIP_ERROR ConvertChipCertToX509Cert(const ByteSpan chipCert, MutableByteSpan & */ CHIP_ERROR ValidateChipRCAC(const ByteSpan & rcac); +struct FutureExtension +{ + ByteSpan OID; + ByteSpan Extension; +}; + struct X509CertRequestParams { int64_t SerialNumber; @@ -514,6 +520,7 @@ struct X509CertRequestParams uint32_t ValidityEnd; ChipDN SubjectDN; ChipDN IssuerDN; + Optional FutureExt; }; /** diff --git a/src/credentials/GenerateChipX509Cert.cpp b/src/credentials/GenerateChipX509Cert.cpp index e1c6fe5002ce3b..b51c49e0174f22 100644 --- a/src/credentials/GenerateChipX509Cert.cpp +++ b/src/credentials/GenerateChipX509Cert.cpp @@ -230,7 +230,31 @@ CHIP_ERROR EncodeNOCSpecificExtensions(ASN1Writer & writer) return err; } -CHIP_ERROR EncodeExtensions(bool isCA, const Crypto::P256PublicKey & SKI, const Crypto::P256PublicKey & AKI, ASN1Writer & writer) +CHIP_ERROR EncodeFutureExtension(const Optional & futureExt, ASN1Writer & writer) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + VerifyOrReturnError(futureExt.HasValue(), CHIP_NO_ERROR); + + ASN1_START_SEQUENCE + { + ReturnErrorOnFailure(writer.PutObjectId(futureExt.Value().OID.data(), static_cast(futureExt.Value().OID.size()))); + + ASN1_START_OCTET_STRING_ENCAPSULATED + { + ReturnErrorOnFailure(writer.PutOctetString(futureExt.Value().Extension.data(), + static_cast(futureExt.Value().Extension.size()))); + } + ASN1_END_ENCAPSULATED; + } + ASN1_END_SEQUENCE; + +exit: + return err; +} + +CHIP_ERROR EncodeExtensions(bool isCA, const Crypto::P256PublicKey & SKI, const Crypto::P256PublicKey & AKI, + const Optional & futureExt, ASN1Writer & writer) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -250,6 +274,8 @@ CHIP_ERROR EncodeExtensions(bool isCA, const Crypto::P256PublicKey & SKI, const ReturnErrorOnFailure(EncodeSubjectKeyIdentifierExtension(SKI, writer)); ReturnErrorOnFailure(EncodeAuthorityKeyIdentifierExtension(AKI, writer)); + + ReturnErrorOnFailure(EncodeFutureExtension(futureExt, writer)); } ASN1_END_SEQUENCE; } @@ -336,7 +362,7 @@ CHIP_ERROR EncodeTBSCert(const X509CertRequestParams & requestParams, const Cryp ReturnErrorOnFailure(EncodeSubjectPublicKeyInfo(subjectPubkey, writer)); // certificate extensions - ReturnErrorOnFailure(EncodeExtensions(isCA, subjectPubkey, issuerPubkey, writer)); + ReturnErrorOnFailure(EncodeExtensions(isCA, subjectPubkey, issuerPubkey, requestParams.FutureExt, writer)); } ASN1_END_SEQUENCE; diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp index 97c00d7ca555bd..c84b18db79024c 100644 --- a/src/credentials/tests/TestChipCert.cpp +++ b/src/credentials/tests/TestChipCert.cpp @@ -102,6 +102,14 @@ static const BitFlags sKCandCR(sKC, sCR); static const BitFlags sKCandEO(sKC, sEO); static const BitFlags sKCandDO(sKC, sDO); +constexpr uint8_t sOID_Extension_SubjectAltName[] = { 0x55, 0x1d, 0x11 }; +constexpr char kExtension_SubjectAltName[] = "test@example.com"; + +FutureExtension ext{ ByteSpan(sOID_Extension_SubjectAltName), + ByteSpan(reinterpret_cast(const_cast(kExtension_SubjectAltName)), + strlen(kExtension_SubjectAltName)) }; +Optional kSubjectAltNameAsFutureExt(ext); + static CHIP_ERROR LoadTestCertSet01(ChipCertificateSet & certSet) { CHIP_ERROR err; @@ -1247,6 +1255,15 @@ static void TestChipCert_GenerateRootCert(nlTestSuite * inSuite, void * inContex NL_TEST_ASSERT(inSuite, DecodeChipCert(outCert, certData) == CHIP_NO_ERROR); + // Test with FutureExtension + X509CertRequestParams root_params2 = { 1234, 631161876, 729942000, root_dn, root_dn, kSubjectAltNameAsFutureExt }; + MutableByteSpan signed_cert_span2(signed_cert); + NL_TEST_ASSERT(inSuite, NewRootX509Cert(root_params2, keypair, signed_cert_span2) == CHIP_NO_ERROR); + outCert = MutableByteSpan(outCertBuf); + + NL_TEST_ASSERT(inSuite, ConvertX509CertToChipCert(signed_cert_span2, outCert) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, DecodeChipCert(outCert, certData) == CHIP_NO_ERROR); + // Test error case: root cert subject provided ICA OID Attribute. root_params.SubjectDN.Clear(); NL_TEST_ASSERT(inSuite, root_params.SubjectDN.AddAttribute_MatterICACId(0xabcdabcd) == CHIP_NO_ERROR); @@ -1325,6 +1342,15 @@ static void TestChipCert_GenerateICACert(nlTestSuite * inSuite, void * inContext NL_TEST_ASSERT(inSuite, DecodeChipCert(outCert, certData) == CHIP_NO_ERROR); + // Test with FutureExtension + X509CertRequestParams ica_params2 = { 1234, 631161876, 729942000, ica_dn, issuer_dn, kSubjectAltNameAsFutureExt }; + MutableByteSpan signed_cert_span2(signed_cert); + NL_TEST_ASSERT(inSuite, NewICAX509Cert(ica_params2, ica_keypair.Pubkey(), keypair, signed_cert_span2) == CHIP_NO_ERROR); + outCert = MutableByteSpan(outCertBuf); + + NL_TEST_ASSERT(inSuite, ConvertX509CertToChipCert(signed_cert_span2, outCert) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, DecodeChipCert(outCert, certData) == CHIP_NO_ERROR); + // Test error case: ICA cert subject provided a node ID attribute ica_params.SubjectDN.Clear(); NL_TEST_ASSERT(inSuite, ica_params.SubjectDN.AddAttribute_MatterNodeId(0xABCDABCDABCDABCD) == CHIP_NO_ERROR); @@ -1372,6 +1398,16 @@ static void TestChipCert_GenerateNOCRoot(nlTestSuite * inSuite, void * inContext NL_TEST_ASSERT(inSuite, DecodeChipCert(outCert, certData) == CHIP_NO_ERROR); + // Test with FutureExtension + X509CertRequestParams noc_params2 = { 123456, 631161876, 729942000, noc_dn, issuer_dn, kSubjectAltNameAsFutureExt }; + MutableByteSpan signed_cert_span2(signed_cert); + NL_TEST_ASSERT(inSuite, + NewNodeOperationalX509Cert(noc_params2, noc_keypair.Pubkey(), keypair, signed_cert_span2) == CHIP_NO_ERROR); + outCert = MutableByteSpan(outCertBuf); + + NL_TEST_ASSERT(inSuite, ConvertX509CertToChipCert(signed_cert_span2, outCert) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, DecodeChipCert(outCert, certData) == CHIP_NO_ERROR); + // Test error case: NOC cert subject doesn't have NodeId attribute noc_params.SubjectDN.Clear(); NL_TEST_ASSERT(inSuite, noc_params.SubjectDN.AddAttribute_MatterFabricId(0xFAB00000FAB00001) == CHIP_NO_ERROR); diff --git a/src/tools/chip-cert/CertUtils.cpp b/src/tools/chip-cert/CertUtils.cpp index f929e1446317e2..0c22503628bc31 100644 --- a/src/tools/chip-cert/CertUtils.cpp +++ b/src/tools/chip-cert/CertUtils.cpp @@ -772,7 +772,7 @@ bool WriteChipCert(const char * fileName, const ByteSpan & chipCert, CertFormat } bool MakeCert(uint8_t certType, const ToolChipDN * subjectDN, X509 * caCert, EVP_PKEY * caKey, const struct tm & validFrom, - uint32_t validDays, int pathLen, const FutureExtension * futureExts, uint8_t futureExtsCount, X509 * newCert, + uint32_t validDays, int pathLen, const FutureExtensionWithNID * futureExts, uint8_t futureExtsCount, X509 * newCert, EVP_PKEY * newKey, CertStructConfig & certConfig) { bool res = true; @@ -925,7 +925,7 @@ bool MakeCert(uint8_t certType, const ToolChipDN * subjectDN, X509 * caCert, EVP } CHIP_ERROR MakeCertChipTLV(uint8_t certType, const ToolChipDN * subjectDN, X509 * caCert, EVP_PKEY * caKey, - const struct tm & validFrom, uint32_t validDays, int pathLen, const FutureExtension * futureExts, + const struct tm & validFrom, uint32_t validDays, int pathLen, const FutureExtensionWithNID * futureExts, uint8_t futureExtsCount, X509 * x509Cert, EVP_PKEY * newKey, CertStructConfig & certConfig, MutableByteSpan & chipCert) { diff --git a/src/tools/chip-cert/Cmd_GenCert.cpp b/src/tools/chip-cert/Cmd_GenCert.cpp index e944bdb07733c9..6a0a1c6784335d 100644 --- a/src/tools/chip-cert/Cmd_GenCert.cpp +++ b/src/tools/chip-cert/Cmd_GenCert.cpp @@ -243,19 +243,19 @@ OptionSet *gCmdOptionSets[] = // clang-format on ToolChipDN gSubjectDN; -uint8_t gCertType = kCertType_NotSpecified; -int gPathLengthConstraint = kPathLength_NotSpecified; -bool gSelfSign = false; -const char * gCACertFileName = nullptr; -const char * gCAKeyFileName = nullptr; -const char * gInKeyFileName = nullptr; -const char * gOutCertFileName = nullptr; -const char * gOutKeyFileName = nullptr; -CertFormat gOutCertFormat = kCertFormat_Default; -KeyFormat gOutKeyFormat = kKeyFormat_Default; -uint32_t gValidDays = kCertValidDays_Undefined; -FutureExtension gFutureExtensions[3] = { { 0, nullptr } }; -uint8_t gFutureExtensionsCount = 0; +uint8_t gCertType = kCertType_NotSpecified; +int gPathLengthConstraint = kPathLength_NotSpecified; +bool gSelfSign = false; +const char * gCACertFileName = nullptr; +const char * gCAKeyFileName = nullptr; +const char * gInKeyFileName = nullptr; +const char * gOutCertFileName = nullptr; +const char * gOutKeyFileName = nullptr; +CertFormat gOutCertFormat = kCertFormat_Default; +KeyFormat gOutKeyFormat = kKeyFormat_Default; +uint32_t gValidDays = kCertValidDays_Undefined; +FutureExtensionWithNID gFutureExtensions[3] = { { 0, nullptr } }; +uint8_t gFutureExtensionsCount = 0; struct tm gValidFrom; CertStructConfig gCertConfig; diff --git a/src/tools/chip-cert/chip-cert.h b/src/tools/chip-cert/chip-cert.h index 6bdd41855c3a01..39e32fbe580c8b 100644 --- a/src/tools/chip-cert/chip-cert.h +++ b/src/tools/chip-cert/chip-cert.h @@ -141,7 +141,7 @@ enum AttCertType kAttCertType_DAC, /**< Device Attestation Certificate (DAC). */ }; -struct FutureExtension +struct FutureExtensionWithNID { int nid; const char * info; @@ -410,12 +410,12 @@ extern bool WriteCert(const char * fileName, X509 * cert, CertFormat certFmt); extern bool WriteChipCert(const char * fileName, const chip::ByteSpan & cert, CertFormat certFmt); extern bool MakeCert(uint8_t certType, const ToolChipDN * subjectDN, X509 * caCert, EVP_PKEY * caKey, const struct tm & validFrom, - uint32_t validDays, int pathLen, const FutureExtension * futureExts, uint8_t futureExtsCount, X509 * newCert, - EVP_PKEY * newKey, CertStructConfig & certConfig); + uint32_t validDays, int pathLen, const FutureExtensionWithNID * futureExts, uint8_t futureExtsCount, + X509 * newCert, EVP_PKEY * newKey, CertStructConfig & certConfig); extern CHIP_ERROR MakeCertChipTLV(uint8_t certType, const ToolChipDN * subjectDN, X509 * caCert, EVP_PKEY * caKey, - const struct tm & validFrom, uint32_t validDays, int pathLen, const FutureExtension * futureExts, - uint8_t futureExtsCount, X509 * x509Cert, EVP_PKEY * newKey, CertStructConfig & certConfig, - chip::MutableByteSpan & chipCert); + const struct tm & validFrom, uint32_t validDays, int pathLen, + const FutureExtensionWithNID * futureExts, uint8_t futureExtsCount, X509 * x509Cert, + EVP_PKEY * newKey, CertStructConfig & certConfig, chip::MutableByteSpan & chipCert); extern bool ResignCert(X509 * cert, X509 * caCert, EVP_PKEY * caKey); extern bool MakeAttCert(AttCertType attCertType, const char * subjectCN, uint16_t subjectVID, uint16_t subjectPID, From 4ab1882b52a66a99b66126034581ae716e3e668f Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 23 Aug 2022 10:24:52 -0400 Subject: [PATCH 07/16] Add libnl-dev to chip-build Dockerfile (#22047) --- integrations/docker/images/chip-build/Dockerfile | 4 +++- integrations/docker/images/chip-build/version | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/integrations/docker/images/chip-build/Dockerfile b/integrations/docker/images/chip-build/Dockerfile index bfcfea5e40e755..861f5ecb2df4e7 100644 --- a/integrations/docker/images/chip-build/Dockerfile +++ b/integrations/docker/images/chip-build/Dockerfile @@ -28,14 +28,16 @@ RUN set -x \ libcairo2-dev \ libdbus-1-dev \ libdbus-glib-1-dev \ + libdmalloc-dev \ libgif-dev \ libglib2.0-dev \ libical-dev \ libjpeg-dev \ - libdmalloc-dev \ libmbedtls-dev \ libncurses5-dev \ libncursesw5-dev \ + libnl-3-dev \ + libnl-route-3-dev \ libnspr4-dev \ libpango1.0-dev \ libpixman-1-dev \ diff --git a/integrations/docker/images/chip-build/version b/integrations/docker/images/chip-build/version index 1cb8eca1c7f032..b22b98316c9f22 100644 --- a/integrations/docker/images/chip-build/version +++ b/integrations/docker/images/chip-build/version @@ -1 +1 @@ -0.5.95 Version bump reason: Fix nrfconnect Docker build +0.5.96 Version bump reason: add libnl-dev libs to chip-build image From 0f9615d56605ab97e32c53d5cafd8a537666318b Mon Sep 17 00:00:00 2001 From: Seth Rickard Date: Tue, 23 Aug 2022 10:22:32 -0500 Subject: [PATCH 08/16] Update KVS to handle zero length elements (#21977) * allow for nullptr in KVS write * complete audit with chip_support_enable_storage_api_audit=true --- .../cc13x2_26x2/CC13X2_26X2Config.cpp | 83 +++++++++++-------- .../cc13x2_26x2/KeyValueStoreManagerImpl.cpp | 7 +- .../cc32xx/KeyValueStoreManagerImpl.cpp | 7 +- 3 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp index 09e3393e07b1b1..8d25d6673f5ea1 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp +++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -165,7 +166,7 @@ CHIP_ERROR CC13X2_26X2Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t /* Iterate through the key range to find a key that matches. */ static uint8_t FindKVSSubID(const char * key, uint16_t & subID) { - char key_scratch[32]; // 32 characters seems large enough for a key + char key_scratch[PersistentStorageDelegate::kKeyLengthMax + 1]; NVINTF_nvProxy_t nvProxy = { 0 }; uint8_t status = NVINTF_SUCCESS; @@ -209,20 +210,23 @@ CHIP_ERROR CC13X2_26X2Config::ReadKVS(const char * key, void * value, size_t val val_item.subID = subID; len = sNvoctpFps.getItemLen(val_item); - VerifyOrExit(len > 0, err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // key not found - if ((offset_bytes + value_size) > len) + if (value_size >= (len - offset_bytes)) { - // trying to read up to the end of the element + // reading to end of element read_len = len - offset_bytes; } else { read_len = value_size; + err = CHIP_ERROR_BUFFER_TOO_SMALL; } - VerifyOrExit(sNvoctpFps.readItem(val_item, (uint16_t) offset_bytes, read_len, value) == NVINTF_SUCCESS, - err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + if (read_len > 0) + { + VerifyOrExit(sNvoctpFps.readItem(val_item, (uint16_t) offset_bytes, read_len, value) == NVINTF_SUCCESS, + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + } if (read_bytes_size) { @@ -264,22 +268,14 @@ CHIP_ERROR CC13X2_26X2Config::WriteKVS(const char * key, const void * value, siz CHIP_ERROR err = CHIP_NO_ERROR; uint16_t subID; - if (FindKVSSubID(key, subID) == NVINTF_SUCCESS) - { - NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; - // key already exists, update value - val_item.subID = subID; - VerifyOrExit(sNvoctpFps.updateItem(val_item, (uint16_t) value_size, (void *) value) == NVINTF_SUCCESS, - err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); - } - else + NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID; + NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; + + if (FindKVSSubID(key, subID) != NVINTF_SUCCESS) { - // key does not exist, likely case + // key item not found, find an empty subID intptr_t lock_key = sNvoctpFps.lockNV(); - NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID; - NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; - /* Iterate through the subID range to find an unused subID in the * keyspace. SubID is a 10 bit value, reference * `/source/ti/common/nv/nvocmp.c:MVOCMP_MAXSUBID`. @@ -289,26 +285,39 @@ CHIP_ERROR CC13X2_26X2Config::WriteKVS(const char * key, const void * value, siz key_item.subID = i; if (sNvoctpFps.getItemLen(key_item) == 0U) { - val_item.subID = i; + subID = i; break; } } + sNvoctpFps.unlockNV(lock_key); + // write they key item - if (sNvoctpFps.writeItem(key_item, (uint16_t) strlen(key), (void *) key) == NVINTF_SUCCESS) + VerifyOrExit(sNvoctpFps.writeItem(key_item, (uint16_t) strlen(key), (void *) key) == NVINTF_SUCCESS, + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + } + + key_item.subID = subID; + val_item.subID = subID; + + if (value_size == 0U) + { + // delete the value item if it exists + int8_t ret = sNvoctpFps.deleteItem(val_item); + if (ret != NVINTF_SUCCESS && ret != NVINTF_NOTFOUND) { - if (sNvoctpFps.writeItem(val_item, (uint16_t) value_size, (void *) value) != NVINTF_SUCCESS) - { - // try to delete the key item - sNvoctpFps.deleteItem(key_item); - err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; - } + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; } - else + } + else + { + if (sNvoctpFps.writeItem(val_item, (uint16_t) value_size, (void *) value) != NVINTF_SUCCESS) { + // try to delete the key item + sNvoctpFps.deleteItem(key_item); err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; } - sNvoctpFps.unlockNV(lock_key); } + exit: return err; } @@ -325,25 +334,31 @@ CHIP_ERROR CC13X2_26X2Config::WriteConfigValueBin(Key key, const uint8_t * data, CHIP_ERROR CC13X2_26X2Config::ClearKVS(const char * key) { - CHIP_ERROR err = CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; uint16_t subID; NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID; NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; if (FindKVSSubID(key, subID) == NVINTF_SUCCESS) { + int8_t ret; + key_item.subID = subID; val_item.subID = subID; - // delete the value item - if (sNvoctpFps.deleteItem(val_item) != NVINTF_SUCCESS) + // delete the value item if it exists + ret = sNvoctpFps.deleteItem(val_item); + if (ret != NVINTF_SUCCESS && ret != NVINTF_NOTFOUND) { err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; } - // delete the key item - if (sNvoctpFps.deleteItem(key_item) != NVINTF_SUCCESS) + // delete the key item if it exists + ret = sNvoctpFps.deleteItem(key_item); + if (ret != NVINTF_SUCCESS && ret != NVINTF_NOTFOUND) { err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; } + + err = CHIP_NO_ERROR; } return err; diff --git a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp b/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp index b74146c1de3704..5227b55e5e65df 100644 --- a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp @@ -44,7 +44,10 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t CHIP_ERROR err; VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + if (0U != value_size) + { + VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + } err = CC13X2_26X2Config::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes); @@ -58,8 +61,6 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size) { VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value_size > 0, CHIP_ERROR_INVALID_ARGUMENT); return CC13X2_26X2Config::WriteKVS(key, value, value_size); } diff --git a/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp b/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp index 13c1a023443594..ea0f2e546ce6c4 100644 --- a/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp +++ b/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp @@ -42,7 +42,10 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t size_t offset_bytes) const { VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + if (0U != value_size) + { + VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + } return CC32XXConfig::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes); } @@ -50,8 +53,6 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size) { VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value_size > 0, CHIP_ERROR_INVALID_ARGUMENT); return CC32XXConfig::WriteKVS(key, value, value_size); } From 8702d3ab976f06815e3f4d69d2f2a6bdda1852e4 Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Tue, 23 Aug 2022 23:40:33 +0800 Subject: [PATCH 09/16] Support lighting-app on ESP32H2-beta2 with idf tag v5.0-beta1 (#22064) --- config/esp32/components/chip/CMakeLists.txt | 12 ++++++--- docs/guides/esp32/setup_idf_chip.md | 6 ++--- examples/lighting-app/esp32/main/Button.cpp | 18 +++++++++++++ .../lighting-app/esp32/main/CMakeLists.txt | 2 +- .../lighting-app/esp32/main/LEDWidget.cpp | 18 +++++++++++-- .../esp32/main/include/LEDWidget.h | 4 +++ .../esp32/sdkconfig.defaults.esp32h2 | 24 ++++++++---------- .../esp32/common/CommonDeviceCallbacks.cpp | 25 +++++++++++++++---- src/lib/shell/streamer_esp32.cpp | 6 ++++- src/platform/ESP32/ESP32Config.cpp | 6 +++++ src/platform/ESP32/OpenthreadLauncher.c | 2 +- src/platform/ESP32/nimble/BLEManagerImpl.cpp | 7 ++++-- 12 files changed, 98 insertions(+), 32 deletions(-) diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index 63dff3ee1f5589..74b79dffc93466 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -31,7 +31,11 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake) -set(CHIP_REQURIE_COMPONENTS freertos lwip bt mdns mbedtls fatfs app_update console openthread) +set(CHIP_REQURIE_COMPONENTS freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash) + +if(NOT "${IDF_TARGET}" STREQUAL "esp32h2") + list(APPEND CHIP_REQURIE_COMPONENTS mdns) +endif() if (NOT CMAKE_BUILD_EARLY_EXPANSION) if (CONFIG_COMPILER_OPTIMIZATION_DEFAULT OR CONFIG_COMPILER_OPTIMIZATION_NONE) @@ -270,7 +274,9 @@ if(CONFIG_BT_ENABLED) idf_component_get_property(bt_lib bt COMPONENT_LIB) idf_component_get_property(bt_dir bt COMPONENT_DIR) list(APPEND chip_libraries $) - list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/libcontroller_5p0_seq.a) + if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2) + list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/beta2/libble_app.a) + endif() else() idf_component_get_property(bt_lib bt COMPONENT_LIB) list(APPEND chip_libraries $ -lbtdm_app) @@ -287,7 +293,7 @@ if(CONFIG_OPENTHREAD_ENABLED) list(APPEND chip_libraries $) endif() -if(NOT CONFIG_USE_MINIMAL_MDNS) +if(NOT CONFIG_USE_MINIMAL_MDNS AND NOT CONFIG_IDF_TARGET_ESP32H2) idf_component_get_property(mdns_lib mdns COMPONENT_LIB) list(APPEND chip_libraries $) endif() diff --git a/docs/guides/esp32/setup_idf_chip.md b/docs/guides/esp32/setup_idf_chip.md index acc001e67a6874..f6c7f649834fd7 100644 --- a/docs/guides/esp32/setup_idf_chip.md +++ b/docs/guides/esp32/setup_idf_chip.md @@ -39,13 +39,13 @@ step. $ ./install.sh ``` -- For ESP32H2, please checkout commit id - [10f3aba770](https://github.com/espressif/esp-idf/tree/10f3aba770), +- For ESP32H2, please checkout tag + [v5.0-beta1](https://github.com/espressif/esp-idf/tree/v5.0-beta1), currently only lighting-app is supported on H2 ``` $ cd esp-idf - $ git checkout 10f3aba770 + $ git checkout v5.0-beta1 $ git submodule update --init $ ./install.sh ``` diff --git a/examples/lighting-app/esp32/main/Button.cpp b/examples/lighting-app/esp32/main/Button.cpp index 73a3758818070f..aadae002bc2d08 100644 --- a/examples/lighting-app/esp32/main/Button.cpp +++ b/examples/lighting-app/esp32/main/Button.cpp @@ -1,4 +1,22 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * 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. + */ + #include "Button.h" +#include "esp_attr.h" #define GPIO_INPUT_IO_0 9 #define GPIO_INPUT_PIN_SEL (1ULL << GPIO_INPUT_IO_0) diff --git a/examples/lighting-app/esp32/main/CMakeLists.txt b/examples/lighting-app/esp32/main/CMakeLists.txt index 097f5ba8c41357..233b25d29ada1f 100644 --- a/examples/lighting-app/esp32/main/CMakeLists.txt +++ b/examples/lighting-app/esp32/main/CMakeLists.txt @@ -65,7 +65,7 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/group-key-mgmt-server" - PRIV_REQUIRES chip QRCode bt led_strip app_update openthread) + PRIV_REQUIRES chip QRCode bt led_strip app_update openthread driver nvs_flash) set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/lighting-app/esp32/main/LEDWidget.cpp b/examples/lighting-app/esp32/main/LEDWidget.cpp index 12cbf0f6d3295a..bf2221b26446c9 100644 --- a/examples/lighting-app/esp32/main/LEDWidget.cpp +++ b/examples/lighting-app/esp32/main/LEDWidget.cpp @@ -17,6 +17,7 @@ #include "LEDWidget.h" #include "ColorFormat.h" +#include "led_strip.h" static const char * TAG = "LEDWidget"; @@ -26,6 +27,14 @@ void LEDWidget::Init(void) mBrightness = UINT8_MAX; #if CONFIG_LED_TYPE_RMT +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_config_t strip_config = { + .strip_gpio_num = CONFIG_LED_GPIO, + .max_leds = 1, + }; + + led_strip_new_rmt_device(&strip_config, &mStrip); +#else rmt_config_t config = RMT_DEFAULT_CONFIG_TX((gpio_num_t) CONFIG_LED_GPIO, (rmt_channel_t) CONFIG_LED_RMT_CHANNEL); led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t) config.channel); @@ -33,7 +42,8 @@ void LEDWidget::Init(void) rmt_config(&config); rmt_driver_install(config.channel, 0, 0); - mStrip = led_strip_new_rmt_ws2812(&strip_config); + mStrip = led_strip_new_rmt_ws2812(&strip_config); +#endif mHue = 0; mSaturation = 0; #else @@ -121,9 +131,13 @@ void LEDWidget::DoSet(void) { HsvColor_t hsv = { mHue, mSaturation, brightness }; RgbColor_t rgb = HsvToRgb(hsv); - +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b); + led_strip_refresh(mStrip); +#else mStrip->set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b); mStrip->refresh(mStrip, 100); +#endif } #else ESP_LOGI(TAG, "DoSet to GPIO number %d", mGPIONum); diff --git a/examples/lighting-app/esp32/main/include/LEDWidget.h b/examples/lighting-app/esp32/main/include/LEDWidget.h index c390d63ac1024f..f9d00a2b6882a9 100644 --- a/examples/lighting-app/esp32/main/include/LEDWidget.h +++ b/examples/lighting-app/esp32/main/include/LEDWidget.h @@ -50,7 +50,11 @@ class LEDWidget #if CONFIG_LED_TYPE_RMT uint8_t mHue; uint8_t mSaturation; +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_handle_t mStrip; +#else led_strip_t * mStrip; +#endif #else gpio_num_t mGPIONum; #endif diff --git a/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 b/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 index 3a6d8da8ff4033..dc637d31dc7a2e 100644 --- a/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 +++ b/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 @@ -1,4 +1,5 @@ CONFIG_IDF_TARGET="esp32h2" +CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2=y # Default to 921600 baud when flashing and monitoring device CONFIG_ESPTOOLPY_BAUD_921600B=y @@ -16,14 +17,9 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y # NIMBLE CONFIG_BT_ENABLED=y -CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y CONFIG_BT_NIMBLE_EXT_ADV=n -CONFIG_BT_NIMBLE_USE_ESP_TIMER=n -CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y -CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n -CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n # Enable OpenThread @@ -45,22 +41,19 @@ CONFIG_LWIP_MULTICAST_PING=y CONFIG_MBEDTLS_HARDWARE_AES=n CONFIG_MBEDTLS_HARDWARE_MPI=n CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_HARDWARE_ECC=y CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN=n CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY=n CONFIG_MBEDTLS_CMAC_C=y CONFIG_MBEDTLS_SSL_PROTO_DTLS=y CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y +# rtc clk for ble +# CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y + # MDNS platform CONFIG_USE_MINIMAL_MDNS=n - -# Increase stacks size -CONFIG_NIMBLE_CONTROLLER_TASK_STACK_SIZE=5120 -CONFIG_NIMBLE_HOST_TASK_STACK_SIZE=5120 - -# ESP32H2 BLE using a ext 32k crystal -CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y -CONFIG_ESP32H2_RTC_CLK_CAL_CYCLES=576 +CONFIG_ENABLE_EXTENDED_DISCOVERY=y # FreeRTOS should use legacy API CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y @@ -71,3 +64,6 @@ CONFIG_ENABLE_WIFI_AP=n # Enable OTA Requestor CONFIG_ENABLE_OTA_REQUESTOR=y + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y diff --git a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp index e975dce62914f2..ba9eafc19c1397 100644 --- a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp +++ b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp @@ -20,7 +20,9 @@ #if CONFIG_BT_ENABLED #include "esp_bt.h" #if CONFIG_BT_NIMBLE_ENABLED +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "esp_nimble_hci.h" +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "nimble/nimble_port.h" #endif // CONFIG_BT_NIMBLE_ENABLED #endif // CONFIG_BT_ENABLED @@ -45,6 +47,9 @@ using namespace chip::DeviceLayer; using namespace chip::System; DeviceCallbacksDelegate * appDelegate = nullptr; +#if CONFIG_ENABLE_OTA_REQUESTOR +static bool isOTAInitialized = false; +#endif void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg) { @@ -62,17 +67,30 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i ESP_LOGI(TAG, "CHIPoBLE disconnected"); break; + case DeviceEventType::kThreadConnectivityChange: +#if CONFIG_ENABLE_OTA_REQUESTOR + if (event->ThreadConnectivityChange.Result == kConnectivity_Established && !isOTAInitialized) + { + OTAHelpers::Instance().InitOTARequestor(); + isOTAInitialized = true; + } +#endif + break; + case DeviceEventType::kCommissioningComplete: { ESP_LOGI(TAG, "Commissioning complete"); #if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE if (ble_hs_is_enabled()) { - int ret = nimble_port_stop(); + int ret = nimble_port_stop(); + esp_err_t err = ESP_OK; if (ret == 0) { nimble_port_deinit(); - esp_err_t err = esp_nimble_hci_and_controller_deinit(); +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + err = esp_nimble_hci_and_controller_deinit(); +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) err += esp_bt_mem_release(ESP_BT_MODE_BLE); if (err == ESP_OK) { @@ -114,9 +132,6 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i void CommonDeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { -#if CONFIG_ENABLE_OTA_REQUESTOR - static bool isOTAInitialized = false; -#endif appDelegate = DeviceCallbacksDelegate::Instance().GetAppDelegate(); if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { diff --git a/src/lib/shell/streamer_esp32.cpp b/src/lib/shell/streamer_esp32.cpp index c35abed55c5eb0..7d51afd7399cbe 100644 --- a/src/lib/shell/streamer_esp32.cpp +++ b/src/lib/shell/streamer_esp32.cpp @@ -62,7 +62,11 @@ int streamer_esp32_init(streamer_t * streamer) .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_APB, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .source_clk = UART_SCLK_DEFAULT, +#else + .source_clk = UART_SCLK_APB, +#endif }; ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config)); esp_vfs_dev_uart_use_driver(0); diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index 537ec90375c754..dc65ab772d696d 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -353,8 +353,14 @@ CHIP_ERROR ESP32Config::ClearConfigValue(Key key) bool ESP32Config::ConfigValueExists(Key key) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + nvs_iterator_t iterator = NULL; + esp_err_t err = nvs_entry_find(NVS_DEFAULT_PART_NAME, key.Namespace, NVS_TYPE_ANY, &iterator); + for (; iterator && err == ESP_OK; err = nvs_entry_next(&iterator)) +#else nvs_iterator_t iterator = nvs_entry_find(NVS_DEFAULT_PART_NAME, key.Namespace, NVS_TYPE_ANY); for (; iterator; iterator = nvs_entry_next(iterator)) +#endif { nvs_entry_info_t info; nvs_entry_info(iterator, &info); diff --git a/src/platform/ESP32/OpenthreadLauncher.c b/src/platform/ESP32/OpenthreadLauncher.c index c9ef95fb5cb4de..c1ad467e032174 100644 --- a/src/platform/ESP32/OpenthreadLauncher.c +++ b/src/platform/ESP32/OpenthreadLauncher.c @@ -53,7 +53,7 @@ static void ot_task_worker(void * context) // Initialize the OpenThread stack ESP_ERROR_CHECK(esp_openthread_init(&config)); // The OpenThread log level directly matches ESP log level - (void) otLoggingSetLevel(OT_LOG_LEVEL_INFO); + (void) otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL); // Initialize the esp_netif bindings openthread_netif = init_openthread_netif(&config); diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp index 2cf626c1751c50..b4459196fd9baa 100644 --- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp +++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp @@ -40,7 +40,9 @@ #include #include "esp_log.h" +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "esp_nimble_hci.h" +#endif #include "host/ble_hs.h" #include "host/ble_hs_pvcy.h" #include "host/ble_uuid.h" @@ -152,7 +154,7 @@ CHIP_ERROR BLEManagerImpl::_Init() mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART); mFlags.Set(Flags::kFastAdvertisingEnabled, true); mNumGAPCons = 0; - memset(mCons, 0, sizeof(mCons)); + memset(reinterpret_cast(mCons), 0, sizeof(mCons)); mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; memset(mDeviceName, 0, sizeof(mDeviceName)); @@ -613,9 +615,10 @@ CHIP_ERROR BLEManagerImpl::InitESPBleLayer(void) { mSubscribedConIds[i] = BLE_CONNECTION_UNINITIALIZED; } - +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) err = MapBLEError(esp_nimble_hci_and_controller_init()); SuccessOrExit(err); +#endif nimble_port_init(); From 27ca0452dd86d6b777e24ad90b9939e79ce2e9e8 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Wed, 24 Aug 2022 00:08:00 +0800 Subject: [PATCH 10/16] [KVS] Check NULL pointer for getPref_bin_new (#21854) * [KVS] Add NULL pointer check for getPref_bin_new Invalid read_bytes_size pointer could cause hard fault on getPref_bin_new function. * [KVS] Pass in dummy_read_bytes when read_bytes is nullptr * [Restyle] Fix styling * [KVS] Add nullptr check after pvPortMalloc * [Restyle] Fix style Co-authored-by: Andrei Litvin --- src/platform/Ameba/KeyValueStoreManagerImpl.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/platform/Ameba/KeyValueStoreManagerImpl.cpp b/src/platform/Ameba/KeyValueStoreManagerImpl.cpp index 74e8a2882f6cb7..93ec38b8611b58 100644 --- a/src/platform/Ameba/KeyValueStoreManagerImpl.cpp +++ b/src/platform/Ameba/KeyValueStoreManagerImpl.cpp @@ -49,7 +49,20 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t return (err = CHIP_ERROR_NOT_IMPLEMENTED); } - ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, read_bytes_size); + if (read_bytes_size) + { + ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, read_bytes_size); + } + else + { + size_t * dummy_read_bytes_size = (size_t *) pvPortMalloc(sizeof(size_t)); + if (!dummy_read_bytes_size) + { + return CHIP_ERROR_INTERNAL; + } + ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, dummy_read_bytes_size); + vPortFree(dummy_read_bytes_size); + } switch (ret) { case 0: From 1a1d887dfe015a4f85a98846d7a5eddcc1fa4b15 Mon Sep 17 00:00:00 2001 From: Sharad Binjola <31142146+sharadb-amazon@users.noreply.github.com> Date: Tue, 23 Aug 2022 10:13:00 -0700 Subject: [PATCH 11/16] Fixing typo in mapping mediaPlayback_stopPlayback correctly in CastingServerBridge.mm (#22087) --- .../MatterTvCastingBridge/CastingServerBridge.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm index e854db7092e9eb..2eccbf8242a0a9 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm @@ -309,7 +309,7 @@ - (void)mediaPlayback_stopPlayback:(void (^_Nonnull)(bool))responseCallback _mediaPlayback_pauseResponseCallback = responseCallback; dispatch_async(_chipWorkQueue, ^{ - CHIP_ERROR err = CastingServer::GetInstance()->MediaPlayback_Pause([](CHIP_ERROR err) { + CHIP_ERROR err = CastingServer::GetInstance()->MediaPlayback_StopPlayback([](CHIP_ERROR err) { [CastingServerBridge getSharedInstance].mediaPlayback_stopPlaybackResponseCallback(CHIP_NO_ERROR == err); }); dispatch_async(clientQueue, ^{ From c3fcbc1781c4c9e1e1dc8cf986b20837285c0edb Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 23 Aug 2022 13:33:40 -0400 Subject: [PATCH 12/16] Make StartUpColorTemperatureMireds nullable, per spec. (#21858) Fixes https://github.com/project-chip/connectedhomeip/issues/21855 --- .../all-clusters-app.matter | 2 +- ...tnode_extendedcolorlight_8lcaaYJVAa.matter | 2 +- .../light-switch-app.matter | 2 +- .../lighting-common/lighting-app.matter | 2 +- .../placeholder/linux/apps/app1/config.matter | 2 +- .../placeholder/linux/apps/app2/config.matter | 2 +- .../color-control-server.cpp | 16 ++--- .../zcl/data-model/silabs/ha.xml | 2 +- .../data_model/controller-clusters.matter | 2 +- .../CHIPAttributeTLVValueDecoder.cpp | 15 +++-- .../zap-generated/CHIPClustersWrite-JNI.cpp | 12 +++- .../java/zap-generated/CHIPReadCallbacks.cpp | 67 +++++++++++++++++++ .../java/zap-generated/CHIPReadCallbacks.h | 30 +++++++++ .../chip/devicecontroller/ChipClusters.java | 20 ++++-- .../devicecontroller/ClusterReadMapping.java | 4 +- .../python/chip/clusters/Objects.py | 8 +-- .../MTRAttributeTLVValueDecoder.mm | 8 ++- .../CHIP/zap-generated/MTRBaseClusters.h | 4 +- .../CHIP/zap-generated/MTRBaseClusters.mm | 27 +++++--- .../zap-generated/endpoint_config.h | 3 +- .../zap-generated/attributes/Accessors.cpp | 32 +++++++-- .../zap-generated/attributes/Accessors.h | 4 +- .../zap-generated/cluster-objects.h | 8 +-- .../zap-generated/endpoint_config.h | 3 +- .../zap-generated/cluster/Commands.h | 5 +- .../cluster/logging/DataModelLogger.cpp | 2 +- .../chip-tool/zap-generated/test/Commands.h | 2 +- .../zap-generated/cluster/Commands.h | 2 +- .../zap-generated/test/Commands.h | 10 ++- .../zap-generated/endpoint_config.h | 3 +- .../app1/zap-generated/endpoint_config.h | 3 +- .../app2/zap-generated/endpoint_config.h | 3 +- 32 files changed, 238 insertions(+), 69 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index 18d7c48c099ad3..96c706ad0ed1fe 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -2851,7 +2851,7 @@ server cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; diff --git a/examples/chef/devices/rootnode_extendedcolorlight_8lcaaYJVAa.matter b/examples/chef/devices/rootnode_extendedcolorlight_8lcaaYJVAa.matter index e9d7612115a077..7fa6bae61d59dc 100644 --- a/examples/chef/devices/rootnode_extendedcolorlight_8lcaaYJVAa.matter +++ b/examples/chef/devices/rootnode_extendedcolorlight_8lcaaYJVAa.matter @@ -1614,7 +1614,7 @@ server cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute command_id generatedCommandList[] = 65528; readonly attribute command_id acceptedCommandList[] = 65529; readonly attribute attrib_id attributeList[] = 65531; diff --git a/examples/light-switch-app/light-switch-common/light-switch-app.matter b/examples/light-switch-app/light-switch-common/light-switch-app.matter index 0a6d27521c8a74..27a458acdc6195 100644 --- a/examples/light-switch-app/light-switch-common/light-switch-app.matter +++ b/examples/light-switch-app/light-switch-common/light-switch-app.matter @@ -1565,7 +1565,7 @@ client cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute int16u clusterRevision = 65533; request struct MoveToHueRequest { diff --git a/examples/lighting-app/lighting-common/lighting-app.matter b/examples/lighting-app/lighting-common/lighting-app.matter index d538c8232f7bb0..43839293478d6d 100644 --- a/examples/lighting-app/lighting-common/lighting-app.matter +++ b/examples/lighting-app/lighting-common/lighting-app.matter @@ -1511,7 +1511,7 @@ server cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; diff --git a/examples/placeholder/linux/apps/app1/config.matter b/examples/placeholder/linux/apps/app1/config.matter index 48822ed58e83bf..eb235f5eaa24fa 100644 --- a/examples/placeholder/linux/apps/app1/config.matter +++ b/examples/placeholder/linux/apps/app1/config.matter @@ -1916,7 +1916,7 @@ server cluster ColorControl = 768 { readonly attribute int16u currentY = 4; attribute bitmap8 options = 15; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; diff --git a/examples/placeholder/linux/apps/app2/config.matter b/examples/placeholder/linux/apps/app2/config.matter index 48822ed58e83bf..eb235f5eaa24fa 100644 --- a/examples/placeholder/linux/apps/app2/config.matter +++ b/examples/placeholder/linux/apps/app2/config.matter @@ -1916,7 +1916,7 @@ server cluster ColorControl = 768 { readonly attribute int16u currentY = 4; attribute bitmap8 options = 15; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index ec61efd6ac2867..e523921bdaf9b3 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -2071,13 +2071,13 @@ void ColorControlServer::startUpColorTempCommand(EndpointId endpoint) // the StartUpColorTemperatureMireds attribute are listed in the table below. // Value Action on power up // 0x0000-0xffef Set the ColorTemperatureMireds attribute to this value. - // 0xffff Set the ColorTemperatureMireds attribute to its previous value. + // null Set the ColorTemperatureMireds attribute to its previous value. - // Initialize startUpColorTempMireds to "maintain previous value" value 0xFFFF - uint16_t startUpColorTemp = 0xFFFF; - EmberAfStatus status = Attributes::StartUpColorTemperatureMireds::Get(endpoint, &startUpColorTemp); + // Initialize startUpColorTempMireds to "maintain previous value" value null + app::DataModel::Nullable startUpColorTemp; + EmberAfStatus status = Attributes::StartUpColorTemperatureMireds::Get(endpoint, startUpColorTemp); - if (status == EMBER_ZCL_STATUS_SUCCESS) + if (status == EMBER_ZCL_STATUS_SUCCESS && !startUpColorTemp.IsNull()) { uint16_t updatedColorTemp = MAX_TEMPERATURE_VALUE; status = Attributes::ColorTemperature::Get(endpoint, &updatedColorTemp); @@ -2090,13 +2090,13 @@ void ColorControlServer::startUpColorTempCommand(EndpointId endpoint) uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE; Attributes::ColorTempPhysicalMaxMireds::Get(endpoint, &tempPhysicalMax); - if (tempPhysicalMin <= startUpColorTemp && startUpColorTemp <= tempPhysicalMax) + if (tempPhysicalMin <= startUpColorTemp.Value() && startUpColorTemp.Value() <= tempPhysicalMax) { // Apply valid startup color temp value that is within physical limits of device. // Otherwise, the startup value is outside the device's supported range, and the // existing setting of ColorTemp attribute will be left unchanged (i.e., treated as - // if startup color temp was set to 0xFFFF). - updatedColorTemp = startUpColorTemp; + // if startup color temp was set to null). + updatedColorTemp = startUpColorTemp.Value(); status = Attributes::ColorTemperature::Set(endpoint, updatedColorTemp); if (status == EMBER_ZCL_STATUS_SUCCESS) diff --git a/src/app/zap-templates/zcl/data-model/silabs/ha.xml b/src/app/zap-templates/zcl/data-model/silabs/ha.xml index f9ea448209d444..b40807c1b39211 100644 --- a/src/app/zap-templates/zcl/data-model/silabs/ha.xml +++ b/src/app/zap-templates/zcl/data-model/silabs/ha.xml @@ -243,7 +243,7 @@ limitations under the License. CoupleColorTempToLevelMinMireds - + StartUpColorTemperatureMireds diff --git a/src/controller/data_model/controller-clusters.matter b/src/controller/data_model/controller-clusters.matter index f8a88c7b66bb5f..2d71e362638858 100644 --- a/src/controller/data_model/controller-clusters.matter +++ b/src/controller/data_model/controller-clusters.matter @@ -3178,7 +3178,7 @@ client cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute command_id generatedCommandList[] = 65528; readonly attribute command_id acceptedCommandList[] = 65529; readonly attribute attrib_id attributeList[] = 65531; diff --git a/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp b/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp index fe0eb5ce4cd193..d20ce4a2f36cf0 100644 --- a/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp +++ b/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp @@ -12925,10 +12925,17 @@ jobject DecodeAttributeValue(const app::ConcreteAttributePath & aPath, TLV::TLVR return nullptr; } jobject value; - std::string valueClassName = "java/lang/Integer"; - std::string valueCtorSignature = "(I)V"; - chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), - cppValue, value); + if (cppValue.IsNull()) + { + value = nullptr; + } + else + { + std::string valueClassName = "java/lang/Integer"; + std::string valueCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), + cppValue.Value(), value); + } return value; } case Attributes::GeneratedCommandList::Id: { diff --git a/src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp b/src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp index 4612f4b7b96bae..e453c781ffd1f4 100644 --- a/src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp +++ b/src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp @@ -4488,8 +4488,16 @@ JNI_METHOD(void, ColorControlCluster, writeStartUpColorTemperatureMiredsAttribut std::vector> cleanupByteArrays; std::vector> cleanupStrings; - cppValue = - static_cast>(chip::JniReferences::GetInstance().IntegerToPrimitive(value)); + if (value == nullptr) + { + cppValue.SetNull(); + } + else + { + auto & nonNullValue_0 = cppValue.SetNonNull(); + nonNullValue_0 = static_cast>( + chip::JniReferences::GetInstance().IntegerToPrimitive(value)); + } std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); diff --git a/src/controller/java/zap-generated/CHIPReadCallbacks.cpp b/src/controller/java/zap-generated/CHIPReadCallbacks.cpp index 2dab6e13780b9d..d6c410be3f605e 100644 --- a/src/controller/java/zap-generated/CHIPReadCallbacks.cpp +++ b/src/controller/java/zap-generated/CHIPReadCallbacks.cpp @@ -18957,6 +18957,73 @@ void CHIPColorControlColorPointBIntensityAttributeCallback::CallbackFn(void * co env->CallVoidMethod(javaCallbackRef, javaMethod, javaValue); } +CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback::CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback( + jobject javaCallback, bool keepAlive) : + chip::Callback::Callback(CallbackFn, this), + keepAlive(keepAlive) +{ + JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback::~CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback() +{ + JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +} + +void CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback::CallbackFn( + void * context, const chip::app::DataModel::Nullable & value) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNI env")); + std::unique_ptr cppCallback( + reinterpret_cast(context), maybeDestroy); + + // It's valid for javaCallbackRef to be nullptr if the Java code passed in a null callback. + javaCallbackRef = cppCallback.get()->javaCallbackRef; + VerifyOrReturn(javaCallbackRef != nullptr, + ChipLogProgress(Zcl, "Early return from attribute callback since Java callback is null")); + + jmethodID javaMethod; + err = chip::JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Could not find onSuccess() method")); + + jobject javaValue; + if (value.IsNull()) + { + javaValue = nullptr; + } + else + { + std::string javaValueClassName = "java/lang/Integer"; + std::string javaValueCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(javaValueClassName.c_str(), javaValueCtorSignature.c_str(), + value.Value(), javaValue); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, javaValue); +} + CHIPColorControlGeneratedCommandListAttributeCallback::CHIPColorControlGeneratedCommandListAttributeCallback(jobject javaCallback, bool keepAlive) : chip::Callback::Callback(CallbackFn, this), diff --git a/src/controller/java/zap-generated/CHIPReadCallbacks.h b/src/controller/java/zap-generated/CHIPReadCallbacks.h index f5dc7866c0e0c9..d1a4b63b04c84e 100644 --- a/src/controller/java/zap-generated/CHIPReadCallbacks.h +++ b/src/controller/java/zap-generated/CHIPReadCallbacks.h @@ -7912,6 +7912,36 @@ class CHIPColorControlColorPointBIntensityAttributeCallback bool keepAlive; }; +class CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback + : public chip::Callback::Callback +{ +public: + CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback(jobject javaCallback, bool keepAlive = false); + + ~CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback(); + + static void maybeDestroy(CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback * callback) + { + if (!callback->keepAlive) + { + callback->Cancel(); + chip::Platform::Delete(callback); + } + } + + static void CallbackFn(void * context, const chip::app::DataModel::Nullable & value); + static void OnSubscriptionEstablished(void * context) + { + CHIP_ERROR err = chip::JniReferences::GetInstance().CallSubscriptionEstablished( + reinterpret_cast(context)->javaCallbackRef); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error calling onSubscriptionEstablished: %s", ErrorStr(err))); + }; + +private: + jobject javaCallbackRef; + bool keepAlive; +}; + class CHIPColorControlGeneratedCommandListAttributeCallback : public chip::Callback::Callback { diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java index 73c28214ab6173..bd9914f596dbab 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java @@ -16188,6 +16188,14 @@ public interface ColorPointBIntensityAttributeCallback { default void onSubscriptionEstablished() {} } + public interface StartUpColorTemperatureMiredsAttributeCallback { + void onSuccess(@Nullable Integer value); + + void onError(Exception ex); + + default void onSubscriptionEstablished() {} + } + public interface GeneratedCommandListAttributeCallback { void onSuccess(List valueList); @@ -16784,7 +16792,8 @@ public void subscribeCoupleColorTempToLevelMinMiredsAttribute( chipClusterPtr, callback, minInterval, maxInterval); } - public void readStartUpColorTemperatureMiredsAttribute(IntegerAttributeCallback callback) { + public void readStartUpColorTemperatureMiredsAttribute( + StartUpColorTemperatureMiredsAttributeCallback callback) { readStartUpColorTemperatureMiredsAttribute(chipClusterPtr, callback); } @@ -16800,7 +16809,7 @@ public void writeStartUpColorTemperatureMiredsAttribute( } public void subscribeStartUpColorTemperatureMiredsAttribute( - IntegerAttributeCallback callback, int minInterval, int maxInterval) { + StartUpColorTemperatureMiredsAttributeCallback callback, int minInterval, int maxInterval) { subscribeStartUpColorTemperatureMiredsAttribute( chipClusterPtr, callback, minInterval, maxInterval); } @@ -17262,7 +17271,7 @@ private native void subscribeCoupleColorTempToLevelMinMiredsAttribute( long chipClusterPtr, IntegerAttributeCallback callback, int minInterval, int maxInterval); private native void readStartUpColorTemperatureMiredsAttribute( - long chipClusterPtr, IntegerAttributeCallback callback); + long chipClusterPtr, StartUpColorTemperatureMiredsAttributeCallback callback); private native void writeStartUpColorTemperatureMiredsAttribute( long chipClusterPtr, @@ -17271,7 +17280,10 @@ private native void writeStartUpColorTemperatureMiredsAttribute( @Nullable Integer timedWriteTimeoutMs); private native void subscribeStartUpColorTemperatureMiredsAttribute( - long chipClusterPtr, IntegerAttributeCallback callback, int minInterval, int maxInterval); + long chipClusterPtr, + StartUpColorTemperatureMiredsAttributeCallback callback, + int minInterval, + int maxInterval); private native void readGeneratedCommandListAttribute( long chipClusterPtr, GeneratedCommandListAttributeCallback callback); diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java b/src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java index bb881021b50feb..a059be7651a3a9 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java @@ -8715,7 +8715,9 @@ public Map> getReadAttributeMap() { (cluster, callback, commandArguments) -> { ((ChipClusters.ColorControlCluster) cluster) .readStartUpColorTemperatureMiredsAttribute( - (ChipClusters.IntegerAttributeCallback) callback); + (ChipClusters.ColorControlCluster + .StartUpColorTemperatureMiredsAttributeCallback) + callback); }, () -> new ClusterInfoMapping.DelegatedIntegerAttributeCallback(), readColorControlStartUpColorTemperatureMiredsCommandParams); diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index d8032d8f508063..94dbba01c44523 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -18134,7 +18134,7 @@ def descriptor(cls) -> ClusterObjectDescriptor: ClusterObjectFieldDescriptor(Label="colorTempPhysicalMinMireds", Tag=0x0000400B, Type=typing.Optional[uint]), ClusterObjectFieldDescriptor(Label="colorTempPhysicalMaxMireds", Tag=0x0000400C, Type=typing.Optional[uint]), ClusterObjectFieldDescriptor(Label="coupleColorTempToLevelMinMireds", Tag=0x0000400D, Type=typing.Optional[uint]), - ClusterObjectFieldDescriptor(Label="startUpColorTemperatureMireds", Tag=0x00004010, Type=typing.Optional[uint]), + ClusterObjectFieldDescriptor(Label="startUpColorTemperatureMireds", Tag=0x00004010, Type=typing.Union[None, Nullable, uint]), ClusterObjectFieldDescriptor(Label="generatedCommandList", Tag=0x0000FFF8, Type=typing.List[uint]), ClusterObjectFieldDescriptor(Label="acceptedCommandList", Tag=0x0000FFF9, Type=typing.List[uint]), ClusterObjectFieldDescriptor(Label="attributeList", Tag=0x0000FFFB, Type=typing.List[uint]), @@ -18193,7 +18193,7 @@ def descriptor(cls) -> ClusterObjectDescriptor: colorTempPhysicalMinMireds: 'typing.Optional[uint]' = None colorTempPhysicalMaxMireds: 'typing.Optional[uint]' = None coupleColorTempToLevelMinMireds: 'typing.Optional[uint]' = None - startUpColorTemperatureMireds: 'typing.Optional[uint]' = None + startUpColorTemperatureMireds: 'typing.Union[None, Nullable, uint]' = None generatedCommandList: 'typing.List[uint]' = None acceptedCommandList: 'typing.List[uint]' = None attributeList: 'typing.List[uint]' = None @@ -19501,9 +19501,9 @@ def attribute_id(cls) -> int: @ChipUtility.classproperty def attribute_type(cls) -> ClusterObjectFieldDescriptor: - return ClusterObjectFieldDescriptor(Type=typing.Optional[uint]) + return ClusterObjectFieldDescriptor(Type=typing.Union[None, Nullable, uint]) - value: 'typing.Optional[uint]' = None + value: 'typing.Union[None, Nullable, uint]' = None @dataclass class GeneratedCommandList(ClusterAttributeDescriptor): diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm index 671a368001c51d..4e215d6702d9b5 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm @@ -11155,8 +11155,12 @@ id MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader & if (*aError != CHIP_NO_ERROR) { return nil; } - NSNumber * _Nonnull value; - value = [NSNumber numberWithUnsignedShort:cppValue]; + NSNumber * _Nullable value; + if (cppValue.IsNull()) { + value = nil; + } else { + value = [NSNumber numberWithUnsignedShort:cppValue.Value()]; + } return value; } case Attributes::GeneratedCommandList::Id: { diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h index 201b0844d66305..90980c2f1a0f2c 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h @@ -13792,9 +13792,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)readAttributeStartUpColorTemperatureMiredsWithCompletionHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completionHandler; -- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull)value +- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable)value completionHandler:(StatusCompletion)completionHandler; -- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull)value +- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable)value params:(MTRWriteParams * _Nullable)params completionHandler:(StatusCompletion)completionHandler; /** diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm index 1d1c90e8e4359c..7bc25323f1a8d8 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm @@ -57847,24 +57847,24 @@ new MTRInt16uAttributeCallbackBridge(queue, completionHandler, ^(Cancelable * su - (void)readAttributeStartUpColorTemperatureMiredsWithCompletionHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completionHandler { - new MTRInt16uAttributeCallbackBridge(self.callbackQueue, self.device, completionHandler, + new MTRNullableInt16uAttributeCallbackBridge(self.callbackQueue, self.device, completionHandler, ^(ExchangeManager & exchangeManager, const SessionHandle & session, Cancelable * success, Cancelable * failure) { using TypeInfo = ColorControl::Attributes::StartUpColorTemperatureMireds::TypeInfo; - auto successFn = Callback::FromCancelable(success); + auto successFn = Callback::FromCancelable(success); auto failureFn = Callback::FromCancelable(failure); chip::Controller::ColorControlCluster cppCluster(exchangeManager, session, self->_endpoint); return cppCluster.ReadAttribute(successFn->mContext, successFn->mCall, failureFn->mCall); }); } -- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull)value +- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable)value completionHandler:(StatusCompletion)completionHandler { - [self writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull) value + [self writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable) value params:nil completionHandler:completionHandler]; } -- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull)value +- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable)value params:(MTRWriteParams * _Nullable)params completionHandler:(StatusCompletion)completionHandler { @@ -57888,7 +57888,12 @@ new MTRDefaultSuccessCallbackBridge( ListFreer listFreer; using TypeInfo = ColorControl::Attributes::StartUpColorTemperatureMireds::TypeInfo; TypeInfo::Type cppValue; - cppValue = value.unsignedShortValue; + if (value == nil) { + cppValue.SetNull(); + } else { + auto & nonNullValue_0 = cppValue.SetNonNull(); + nonNullValue_0 = value.unsignedShortValue; + } auto successFn = Callback::FromCancelable(success); auto failureFn = Callback::FromCancelable(failure); @@ -57910,7 +57915,7 @@ - (void)subscribeAttributeStartUpColorTemperatureMiredsWithMinInterval:(NSNumber minInterval = [minInterval copy]; maxInterval = [maxInterval copy]; params = [params copy]; - new MTRInt16uAttributeCallbackSubscriptionBridge( + new MTRNullableInt16uAttributeCallbackSubscriptionBridge( self.callbackQueue, self.device, reportHandler, ^(ExchangeManager & exchangeManager, const SessionHandle & session, Cancelable * success, Cancelable * failure) { if (params != nil && params.autoResubscribe != nil && ![params.autoResubscribe boolValue]) { @@ -57918,13 +57923,13 @@ new MTRInt16uAttributeCallbackSubscriptionBridge( return CHIP_ERROR_INVALID_ARGUMENT; } using TypeInfo = ColorControl::Attributes::StartUpColorTemperatureMireds::TypeInfo; - auto successFn = Callback::FromCancelable(success); + auto successFn = Callback::FromCancelable(success); auto failureFn = Callback::FromCancelable(failure); chip::Controller::ColorControlCluster cppCluster(exchangeManager, session, self->_endpoint); return cppCluster.SubscribeAttribute(successFn->mContext, successFn->mCall, failureFn->mCall, [minInterval unsignedShortValue], [maxInterval unsignedShortValue], - MTRInt16uAttributeCallbackSubscriptionBridge::OnSubscriptionEstablished, nil, + MTRNullableInt16uAttributeCallbackSubscriptionBridge::OnSubscriptionEstablished, nil, params == nil || params.fabricFiltered == nil || [params.fabricFiltered boolValue], params != nil && params.keepPreviousSubscriptions != nil && [params.keepPreviousSubscriptions boolValue]); }, @@ -57937,7 +57942,7 @@ + (void)readAttributeStartUpColorTemperatureMiredsWithAttributeCache:(MTRAttribu completionHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completionHandler { - new MTRInt16uAttributeCallbackBridge(queue, completionHandler, ^(Cancelable * success, Cancelable * failure) { + new MTRNullableInt16uAttributeCallbackBridge(queue, completionHandler, ^(Cancelable * success, Cancelable * failure) { if (attributeCacheContainer.cppAttributeCache) { chip::app::ConcreteAttributePath path; using TypeInfo = ColorControl::Attributes::StartUpColorTemperatureMireds::TypeInfo; @@ -57946,7 +57951,7 @@ new MTRInt16uAttributeCallbackBridge(queue, completionHandler, ^(Cancelable * su path.mAttributeId = TypeInfo::GetAttributeId(); TypeInfo::DecodableType value; CHIP_ERROR err = attributeCacheContainer.cppAttributeCache->Get(path, value); - auto successFn = Callback::FromCancelable(success); + auto successFn = Callback::FromCancelable(success); if (err == CHIP_NO_ERROR) { successFn->mCall(successFn->mContext, value); } diff --git a/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h b/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h index 64446dd4aec170..6a2279cb2179ca 100644 --- a/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h +++ b/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h @@ -1153,7 +1153,8 @@ { 0x0000400B, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0000) }, /* ColorTempPhysicalMinMireds */ \ { 0x0000400C, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0xFEFF) }, /* ColorTempPhysicalMaxMireds */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_EMPTY_DEFAULT() }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(37) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0x1F) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp index d1b8ec87b5220a..60f4de6eae617f 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp @@ -19517,24 +19517,27 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) namespace StartUpColorTemperatureMireds { -EmberAfStatus Get(chip::EndpointId endpoint, uint16_t * value) +EmberAfStatus Get(chip::EndpointId endpoint, DataModel::Nullable & value) { using Traits = NumericAttributeTraits; Traits::StorageType temp; uint8_t * readable = Traits::ToAttributeStoreRepresentation(temp); EmberAfStatus status = emberAfReadServerAttribute(endpoint, Clusters::ColorControl::Id, Id, readable, sizeof(temp)); VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == status, status); - if (!Traits::CanRepresentValue(/* isNullable = */ false, temp)) + if (Traits::IsNullValue(temp)) { - return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + value.SetNull(); + } + else + { + value.SetNonNull() = Traits::StorageToWorking(temp); } - *value = Traits::StorageToWorking(temp); return status; } EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) { using Traits = NumericAttributeTraits; - if (!Traits::CanRepresentValue(/* isNullable = */ false, value)) + if (!Traits::CanRepresentValue(/* isNullable = */ true, value)) { return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; } @@ -19544,6 +19547,25 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) return emberAfWriteServerAttribute(endpoint, Clusters::ColorControl::Id, Id, writable, ZCL_INT16U_ATTRIBUTE_TYPE); } +EmberAfStatus SetNull(chip::EndpointId endpoint) +{ + using Traits = NumericAttributeTraits; + Traits::StorageType value; + Traits::SetNull(value); + uint8_t * writable = Traits::ToAttributeStoreRepresentation(value); + return emberAfWriteServerAttribute(endpoint, Clusters::ColorControl::Id, Id, writable, ZCL_INT16U_ATTRIBUTE_TYPE); +} + +EmberAfStatus Set(chip::EndpointId endpoint, const chip::app::DataModel::Nullable & value) +{ + if (value.IsNull()) + { + return SetNull(endpoint); + } + + return Set(endpoint, value.Value()); +} + } // namespace StartUpColorTemperatureMireds namespace FeatureMap { diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h index d26576e7723a10..73deb29ea144ab 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h @@ -3270,8 +3270,10 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value); } // namespace CoupleColorTempToLevelMinMireds namespace StartUpColorTemperatureMireds { -EmberAfStatus Get(chip::EndpointId endpoint, uint16_t * value); // int16u +EmberAfStatus Get(chip::EndpointId endpoint, DataModel::Nullable & value); // int16u EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value); +EmberAfStatus SetNull(chip::EndpointId endpoint); +EmberAfStatus Set(chip::EndpointId endpoint, const chip::app::DataModel::Nullable & value); } // namespace StartUpColorTemperatureMireds namespace FeatureMap { diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index 5500c0d3c8ce28..924bfe735eef96 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -19205,9 +19205,9 @@ struct TypeInfo namespace StartUpColorTemperatureMireds { struct TypeInfo { - using Type = uint16_t; - using DecodableType = uint16_t; - using DecodableArgType = uint16_t; + using Type = chip::app::DataModel::Nullable; + using DecodableType = chip::app::DataModel::Nullable; + using DecodableArgType = const chip::app::DataModel::Nullable &; static constexpr ClusterId GetClusterId() { return Clusters::ColorControl::Id; } static constexpr AttributeId GetAttributeId() { return Attributes::StartUpColorTemperatureMireds::Id; } @@ -19305,7 +19305,7 @@ struct TypeInfo Attributes::ColorTempPhysicalMaxMireds::TypeInfo::DecodableType colorTempPhysicalMaxMireds = static_cast(0); Attributes::CoupleColorTempToLevelMinMireds::TypeInfo::DecodableType coupleColorTempToLevelMinMireds = static_cast(0); - Attributes::StartUpColorTemperatureMireds::TypeInfo::DecodableType startUpColorTemperatureMireds = static_cast(0); + Attributes::StartUpColorTemperatureMireds::TypeInfo::DecodableType startUpColorTemperatureMireds; Attributes::GeneratedCommandList::TypeInfo::DecodableType generatedCommandList; Attributes::AcceptedCommandList::TypeInfo::DecodableType acceptedCommandList; Attributes::AttributeList::TypeInfo::DecodableType attributeList; diff --git a/zzz_generated/chef-rootnode_extendedcolorlight_8lcaaYJVAa/zap-generated/endpoint_config.h b/zzz_generated/chef-rootnode_extendedcolorlight_8lcaaYJVAa/zap-generated/endpoint_config.h index 58cae4639d8ccf..e7f99834ec16d9 100644 --- a/zzz_generated/chef-rootnode_extendedcolorlight_8lcaaYJVAa/zap-generated/endpoint_config.h +++ b/zzz_generated/chef-rootnode_extendedcolorlight_8lcaaYJVAa/zap-generated/endpoint_config.h @@ -505,7 +505,8 @@ { 0x0000400B, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0000) }, /* ColorTempPhysicalMinMireds */ \ { 0x0000400C, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0xFEFF) }, /* ColorTempPhysicalMaxMireds */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0000) }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(3) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0x1f) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index 897d45dff7d486..a812e26aec450c 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -11499,8 +11499,9 @@ void registerClusterColorControl(Commands & commands, CredentialIssuerCommands * credsIssuerConfig), // make_unique>>( Id, "color-point-bintensity", 0, UINT8_MAX, Attributes::ColorPointBIntensity::Id, credsIssuerConfig), // - make_unique>(Id, "start-up-color-temperature-mireds", 0, UINT16_MAX, - Attributes::StartUpColorTemperatureMireds::Id, credsIssuerConfig), // + make_unique>>( + Id, "start-up-color-temperature-mireds", 0, UINT16_MAX, Attributes::StartUpColorTemperatureMireds::Id, + credsIssuerConfig), // make_unique(Id, credsIssuerConfig), // make_unique(Id, "current-hue", Attributes::CurrentHue::Id, credsIssuerConfig), // make_unique(Id, "current-saturation", Attributes::CurrentSaturation::Id, credsIssuerConfig), // diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp index 3c74e880afe835..d0e87f6efe4086 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp @@ -7866,7 +7866,7 @@ CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributeP return DataModelLogger::LogValue("CoupleColorTempToLevelMinMireds", 1, value); } case ColorControl::Attributes::StartUpColorTemperatureMireds::Id: { - uint16_t value; + chip::app::DataModel::Nullable value; ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); return DataModelLogger::LogValue("StartUpColorTemperatureMireds", 1, value); } diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index 1179318cf4ecb9..5a0c3c87c27d82 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -3751,7 +3751,7 @@ class Test_TC_CC_2_1Suite : public TestCommand case 23: VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); { - uint16_t value; + chip::app::DataModel::Nullable value; VerifyOrReturn(CheckDecodeValue(chip::app::DataModel::Decode(*data, value))); VerifyOrReturn(CheckConstraintType("value", "int16u", "int16u")); VerifyOrReturn(CheckConstraintMinValue("value", value, 0U)); diff --git a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h index 59a1a11c980eb2..ec3f6fbaf1e027 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h @@ -57788,7 +57788,7 @@ class WriteColorControlStartUpColorTemperatureMireds : public WriteAttribute { params.timedWriteTimeout = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil; params.dataVersion = mDataVersion.HasValue() ? [NSNumber numberWithUnsignedInt:mDataVersion.Value()] : nil; - NSNumber * _Nonnull value = [NSNumber numberWithUnsignedShort:mValue]; + NSNumber * _Nullable value = [NSNumber numberWithUnsignedShort:mValue]; [cluster writeAttributeStartUpColorTemperatureMiredsWithValue:value diff --git a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h index 3e6b294d6b85c1..2d5a690968a3c5 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h @@ -6267,9 +6267,13 @@ class Test_TC_CC_2_1 : public TestCommandBridge { VerifyOrReturn(CheckValue("status", err ? err.code : 0, 0)); - VerifyOrReturn(CheckConstraintType("startUpColorTemperatureMireds", "int16u", "int16u")); - VerifyOrReturn(CheckConstraintMinValue("startUpColorTemperatureMireds", [value unsignedShortValue], 0U)); - VerifyOrReturn(CheckConstraintMaxValue("startUpColorTemperatureMireds", [value unsignedShortValue], 65279U)); + if (value != nil) { + + VerifyOrReturn(CheckConstraintType("startUpColorTemperatureMireds", "int16u", "int16u")); + VerifyOrReturn(CheckConstraintMinValue("startUpColorTemperatureMireds", [value unsignedShortValue], 0U)); + VerifyOrReturn( + CheckConstraintMaxValue("startUpColorTemperatureMireds", [value unsignedShortValue], 65279U)); + } NextTest(); }]; diff --git a/zzz_generated/lighting-app/zap-generated/endpoint_config.h b/zzz_generated/lighting-app/zap-generated/endpoint_config.h index 1361aff82ab860..4db663755aea03 100644 --- a/zzz_generated/lighting-app/zap-generated/endpoint_config.h +++ b/zzz_generated/lighting-app/zap-generated/endpoint_config.h @@ -532,7 +532,8 @@ { 0x0000400B, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0000) }, /* ColorTempPhysicalMinMireds */ \ { 0x0000400C, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0xFEFF) }, /* ColorTempPhysicalMaxMireds */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_EMPTY_DEFAULT() }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(3) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0x1F) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ diff --git a/zzz_generated/placeholder/app1/zap-generated/endpoint_config.h b/zzz_generated/placeholder/app1/zap-generated/endpoint_config.h index 765846c3745642..9f3438484cfb72 100644 --- a/zzz_generated/placeholder/app1/zap-generated/endpoint_config.h +++ b/zzz_generated/placeholder/app1/zap-generated/endpoint_config.h @@ -626,7 +626,8 @@ { 0x00000004, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x607D) }, /* CurrentY */ \ { 0x0000000F, ZAP_TYPE(BITMAP8), 1, ZAP_ATTRIBUTE_MASK(WRITABLE), ZAP_SIMPLE_DEFAULT(0x00) }, /* Options */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_EMPTY_DEFAULT() }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(16) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ diff --git a/zzz_generated/placeholder/app2/zap-generated/endpoint_config.h b/zzz_generated/placeholder/app2/zap-generated/endpoint_config.h index 765846c3745642..9f3438484cfb72 100644 --- a/zzz_generated/placeholder/app2/zap-generated/endpoint_config.h +++ b/zzz_generated/placeholder/app2/zap-generated/endpoint_config.h @@ -626,7 +626,8 @@ { 0x00000004, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x607D) }, /* CurrentY */ \ { 0x0000000F, ZAP_TYPE(BITMAP8), 1, ZAP_ATTRIBUTE_MASK(WRITABLE), ZAP_SIMPLE_DEFAULT(0x00) }, /* Options */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_EMPTY_DEFAULT() }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(16) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ From f740b750cd5ba8ca079ca42e3698567320991aec Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Tue, 23 Aug 2022 10:54:32 -0700 Subject: [PATCH 13/16] urgent event needs to honor min interval for subscription. (#21938) * Improve urgent event -- In latest spec, urgent event needs to honor min interval for subscription. -- Add new fflag, urgentEvent, and remove unused flag, SuppressResponse -- ForceDirty would be used when recieving the initial request, where it mark the corresponding handler with dirtiness. -- When there is urgent event, we would set new flag, UrgentEvent, in readHandler instead of setting ForceDirty, after minInterval elapsed, the urgent event would be sent out. Modify the existing urgent event test and check if event can be generated after minInterval elapsed. * address comments * address comment --- src/app/ReadHandler.cpp | 2 +- src/app/ReadHandler.h | 16 +++------ src/app/reporting/Engine.cpp | 42 ++-------------------- src/app/reporting/Engine.h | 6 ---- src/app/tests/TestReadInteraction.cpp | 51 ++++++++++++++++++--------- 5 files changed, 43 insertions(+), 74 deletions(-) diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 4422edaf6d0e35..6b609098a87cf4 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -243,7 +243,7 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b if (!aMoreChunks) { mPreviousReportsBeginGeneration = mCurrentReportsBeginGeneration; - ClearDirty(); + ClearForceDirtyFlag(); InteractionModelEngine::GetInstance()->ReleaseDataVersionFilterList(mpDataVersionFilterList); } diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index 88b8ad8e13f2b5..b07ef01b2c956a 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -198,9 +198,7 @@ class ReadHandler : public Messaging::ExchangeDelegate enum class ReadHandlerFlags : uint8_t { // mHoldReport is used to prevent subscription data delivery while we are - // waiting for the min reporting interval to elapse. If we have to send a - // report immediately due to an urgent event being queued, - // UnblockUrgentEventDelivery can be used to force mHoldReport to false. + // waiting for the min reporting interval to elapse. HoldReport = (1 << 0), // mHoldSync is used to prevent subscription empty report delivery while we @@ -219,7 +217,6 @@ class ReadHandler : public Messaging::ExchangeDelegate PrimingReports = (1 << 3), ActiveSubscription = (1 << 4), FabricFiltered = (1 << 5), - // For subscriptions, we record the dirty set generation when we started to generate the last report. // The mCurrentReportsBeginGeneration records the generation at the start of the current report. This only/ // has a meaningful value while IsReporting() is true. @@ -227,6 +224,8 @@ class ReadHandler : public Messaging::ExchangeDelegate // mPreviousReportsBeginGeneration will be set to mCurrentReportsBeginGeneration after we send the last // chunk of the current report. Anything that was dirty with a generation earlier than // mPreviousReportsBeginGeneration has had its value sent to the client. + // when receiving initial request, it needs mark current handler as dirty. + // when there is urgent event, it needs mark current handler as dirty. ForceDirty = (1 << 6), // Don't need the response for report data if true @@ -300,8 +299,7 @@ class ReadHandler : public Messaging::ExchangeDelegate { return (mDirtyGeneration > mPreviousReportsBeginGeneration) || mFlags.Has(ReadHandlerFlags::ForceDirty); } - void ClearDirty() { mFlags.Clear(ReadHandlerFlags::ForceDirty); } - + void ClearForceDirtyFlag() { mFlags.Clear(ReadHandlerFlags::ForceDirty); } NodeId GetInitiatorNodeId() const { auto session = GetSession(); @@ -319,11 +317,7 @@ class ReadHandler : public Messaging::ExchangeDelegate auto GetTransactionStartGeneration() const { return mTransactionStartGeneration; } - void UnblockUrgentEventDelivery() - { - mFlags.Clear(ReadHandlerFlags::HoldReport); - mFlags.Set(ReadHandlerFlags::ForceDirty); - } + void UnblockUrgentEventDelivery() { mFlags.Set(ReadHandlerFlags::ForceDirty); } const AttributeValueEncoder::AttributeEncodeState & GetAttributeEncodeState() const { return mAttributeEncoderState; } void SetAttributeEncodeState(const AttributeValueEncoder::AttributeEncodeState & aState) { mAttributeEncoderState = aState; } diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 792631f58acdac..b1c2f5a3db54ea 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -653,8 +653,7 @@ void Engine::Run() bool allReadClean = true; - imEngine->mReadHandlers.ForEachActiveObject([this, &allReadClean](ReadHandler * handler) { - UpdateReadHandlerDirty(*handler); + imEngine->mReadHandlers.ForEachActiveObject([&allReadClean](ReadHandler * handler) { if (handler->IsDirty()) { allReadClean = false; @@ -850,41 +849,6 @@ CHIP_ERROR Engine::SetDirty(AttributePathParams & aAttributePath) return CHIP_NO_ERROR; } -void Engine::UpdateReadHandlerDirty(ReadHandler & aReadHandler) -{ - if (!aReadHandler.IsDirty()) - { - return; - } - - if (!aReadHandler.IsType(ReadHandler::InteractionType::Subscribe)) - { - return; - } - - bool intersected = false; - for (auto object = aReadHandler.GetAttributePathList(); object != nullptr; object = object->mpNext) - { - mGlobalDirtySet.ForEachActiveObject([&](auto * path) { - if (path->Intersects(object->mValue) && path->mGeneration > aReadHandler.mPreviousReportsBeginGeneration) - { - intersected = true; - return Loop::Break; - } - return Loop::Continue; - }); - if (intersected) - { - break; - } - } - if (!intersected) - { - aReadHandler.ClearDirty(); - ChipLogDetail(InteractionModel, "clear read handler dirty in UpdateReadHandlerDirty!"); - } -} - CHIP_ERROR Engine::SendReport(ReadHandler * apReadHandler, System::PacketBufferHandle && aPayload, bool aHasMoreChunks) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -974,8 +938,8 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBy if (isUrgentEvent) { - ChipLogDetail(DataManagement, "urgent event schedule run"); - return ScheduleRun(); + ChipLogDetail(DataManagement, "urgent event would be sent after min interval"); + return CHIP_NO_ERROR; } return ScheduleBufferPressureEventDelivery(aBytesWritten); diff --git a/src/app/reporting/Engine.h b/src/app/reporting/Engine.h index dc6b6f5ea920a5..45754b490ee7c8 100644 --- a/src/app/reporting/Engine.h +++ b/src/app/reporting/Engine.h @@ -170,12 +170,6 @@ class Engine bool IsClusterDataVersionMatch(const ObjectList * aDataVersionFilterList, const ConcreteReadAttributePath & aPath); - /** - * Check all active subscription, if the subscription has no paths that intersect with global dirty set, - * it would clear dirty flag for that subscription - * - */ - void UpdateReadHandlerDirty(ReadHandler & aReadHandler); /** * Send Report via ReadHandler * diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index d97b11f3213a8d..f96f5279e75023 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -1515,9 +1515,8 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a { app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); - readPrepareParams.mpEventPathParamsList[0].mIsUrgentEvent = true; - delegate.mGotReport = false; - err = readClient.SendRequest(readPrepareParams); + delegate.mGotReport = false; + err = readClient.SendRequest(readPrepareParams); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -1532,8 +1531,6 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); - NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty()); chip::app::AttributePathParams dirtyPath1; dirtyPath1.mClusterId = kTestClusterId; dirtyPath1.mEndpointId = kTestEndpointId; @@ -1563,6 +1560,7 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a // Test report with 2 different path delegate.mpReadHandler->mFlags.Set(ReadHandler::ReadHandlerFlags::HoldReport, false); delegate.mGotReport = false; + delegate.mGotEventResponse = false; delegate.mNumAttributeResponse = 0; printf("HereHere\n"); @@ -1575,6 +1573,7 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a ctx.DrainAndServiceIO(); NL_TEST_ASSERT(apSuite, delegate.mGotReport); + NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse == true); NL_TEST_ASSERT(apSuite, delegate.mNumAttributeResponse == 2); // Test report with 2 different path, and 1 same path @@ -1701,6 +1700,8 @@ void TestReadInteraction::TestSubscribeUrgentWildcardEvent(nlTestSuite * apSuite ctx.DrainAndServiceIO(); + System::Clock::Timestamp startTime = System::SystemClock().GetMonotonicTimestamp(); + NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); delegate.mpReadHandler = engine->ActiveHandlerAt(0); @@ -1711,12 +1712,37 @@ void TestReadInteraction::TestSubscribeUrgentWildcardEvent(nlTestSuite * apSuite NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); + NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty() == true); delegate.mGotEventResponse = false; delegate.mGotReport = false; - ctx.DrainAndServiceIO(); - NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse); + + // wait for min interval 2 seconds(in test, we use 1.9second considering the time variation), expect no event is received, + // then wait for 0.5 seconds, then the urgent event would be sent out + // currently DriveIOUntil will call `DriveIO` at least once, which means that if there is any CPU scheduling issues, + // there's a chance 1.9s will already have elapsed by the time we get there, which will result in DriveIO being called when + // it shouldn't. Better fix could happen inside DriveIOUntil, not sure the sideeffect there. + while (true) + { + if ((System::SystemClock().GetMonotonicTimestamp() - startTime) >= System::Clock::Milliseconds32(1900)) + { + break; + } + ctx.GetIOContext().DriveIO(); // at least one IO loop is guaranteed + } + + NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse != true); + + startTime = System::SystemClock().GetMonotonicTimestamp(); + while (true) + { + if ((System::SystemClock().GetMonotonicTimestamp() - startTime) >= System::Clock::Milliseconds32(500)) + { + break; + } + ctx.GetIOContext().DriveIO(); // at least one IO loop is guaranteed + } + NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse == true); } // By now we should have closed all exchanges and sent all pending acks, so @@ -2228,7 +2254,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripStatusReportTimeout(nlTestSu { app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); - readPrepareParams.mpEventPathParamsList[0].mIsUrgentEvent = true; printf("\nSend first subscribe request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId); delegate.mGotReport = false; err = readClient.SendRequest(readPrepareParams); @@ -2246,8 +2271,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripStatusReportTimeout(nlTestSu NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); - NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty()); chip::app::AttributePathParams dirtyPath1; dirtyPath1.mClusterId = kTestClusterId; dirtyPath1.mEndpointId = kTestEndpointId; @@ -2548,7 +2571,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripChunkStatusReportTimeout(nlT { app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); - readPrepareParams.mpEventPathParamsList[0].mIsUrgentEvent = true; printf("\nSend first subscribe request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId); delegate.mGotReport = false; err = readClient.SendRequest(readPrepareParams); @@ -2565,8 +2587,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripChunkStatusReportTimeout(nlT NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); - NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty()); chip::app::AttributePathParams dirtyPath1; dirtyPath1.mClusterId = Test::MockClusterId(2); dirtyPath1.mEndpointId = Test::kMockEndpoint3; @@ -2645,7 +2665,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripChunkReportTimeout(nlTestSui { app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); - readPrepareParams.mpEventPathParamsList[0].mIsUrgentEvent = true; printf("\nSend first subscribe request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId); delegate.mGotReport = false; err = readClient.SendRequest(readPrepareParams); @@ -2662,8 +2681,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripChunkReportTimeout(nlTestSui NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); - NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty()); chip::app::AttributePathParams dirtyPath1; dirtyPath1.mClusterId = Test::MockClusterId(2); dirtyPath1.mEndpointId = Test::kMockEndpoint3; From 245830b2d3a08b47d32b7bf1c9277e8ddf3f6694 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Tue, 23 Aug 2022 14:59:05 -0400 Subject: [PATCH 14/16] Fix building thermostat (#22073) --- .../platform/efr32/display/demo-ui-bitmaps.h | 30 +++++++++++++++++++ examples/thermostat/efr32/BUILD.gn | 11 +++++-- examples/thermostat/efr32/include/AppConfig.h | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/examples/platform/efr32/display/demo-ui-bitmaps.h b/examples/platform/efr32/display/demo-ui-bitmaps.h index 6f77ce4b733139..4eca9c0c48e7aa 100644 --- a/examples/platform/efr32/display/demo-ui-bitmaps.h +++ b/examples/platform/efr32/display/demo-ui-bitmaps.h @@ -264,6 +264,36 @@ 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +#elif IS_DEMO_THERMOSTAT +#define ON_DEMO_BITMAP \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xE0, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x81, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC1, 0x83, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, \ + 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, \ + 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, \ + 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, \ + 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xE0, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +#define OFF_DEMO_BITMAP ON_DEMO_BITMAP + #else // Unknown demo.... #define ON_DEMO_BITMAP \ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ diff --git a/examples/thermostat/efr32/BUILD.gn b/examples/thermostat/efr32/BUILD.gn index 7e4e923992ff70..415d9c5e80d212 100644 --- a/examples/thermostat/efr32/BUILD.gn +++ b/examples/thermostat/efr32/BUILD.gn @@ -245,8 +245,15 @@ efr32_executable("thermostat_app") { } if (!disable_lcd) { - sources += [ "${examples_plat_dir}/display/lcd.c" ] - defines += [ "DISPLAY_ENABLED" ] + sources += [ + "${examples_plat_dir}/display/demo-ui.c", + "${examples_plat_dir}/display/lcd.cpp", + ] + include_dirs += [ "${examples_plat_dir}/display" ] + defines += [ + "DISPLAY_ENABLED", + "IS_DEMO_THERMOSTAT=1", + ] if (show_qr_code) { defines += [ "QR_CODE_ENABLED" ] deps += [ "${chip_root}/examples/common/QRCode" ] diff --git a/examples/thermostat/efr32/include/AppConfig.h b/examples/thermostat/efr32/include/AppConfig.h index 91501d889a6234..946b593cab50a4 100644 --- a/examples/thermostat/efr32/include/AppConfig.h +++ b/examples/thermostat/efr32/include/AppConfig.h @@ -32,7 +32,7 @@ extern "C" { #endif -void efr32LogInit(void); +void efr32InitLog(void); void efr32Log(const char * aFormat, ...); #define EFR32_LOG(...) efr32Log(__VA_ARGS__); From fee403eeb94824bd759f7dd34e2c6e2a2dcf16be Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Tue, 23 Aug 2022 15:56:32 -0400 Subject: [PATCH 15/16] Fix shutdown ordering in DeviceControllerSystemState::Shutdown (#22048) DeviceControllerSystemState shuts down PlatformMgr before higher level objects that use timers such as ExchangeMgr. This leads to calls into the system layer after it has been shut down. Fix the ordering so that PlatformMgr is shut down last. Co-authored-by: Andrei Litvin --- .../CHIPDeviceControllerFactory.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index 1c06e8217f3eeb..45ab785e508640 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -419,19 +419,6 @@ void DeviceControllerSystemState::Shutdown() mTransportMgr = nullptr; } -#if CONFIG_DEVICE_LAYER - // - // We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(), - // expects to be called with external thread synchronization and will not try to acquire the - // stack lock. - // - // Actually stopping the event queue is a separable call that applications will have to sequence. - // Consumers are expected to call PlaformMgr().StopEventLoopTask() before calling - // DeviceController::Shutdown() in the CONFIG_DEVICE_LAYER configuration - // - DeviceLayer::PlatformMgr().Shutdown(); -#endif - if (mExchangeMgr != nullptr) { mExchangeMgr->Shutdown(); @@ -483,6 +470,19 @@ void DeviceControllerSystemState::Shutdown() // so that SetupController/Commissioner can use it mFabrics = nullptr; } + +#if CONFIG_DEVICE_LAYER + // + // We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(), + // expects to be called with external thread synchronization and will not try to acquire the + // stack lock. + // + // Actually stopping the event queue is a separable call that applications will have to sequence. + // Consumers are expected to call PlaformMgr().StopEventLoopTask() before calling + // DeviceController::Shutdown() in the CONFIG_DEVICE_LAYER configuration + // + DeviceLayer::PlatformMgr().Shutdown(); +#endif } } // namespace Controller From fa24ab6f8c19bdf4817542aba8562142a1ae1c60 Mon Sep 17 00:00:00 2001 From: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:40:44 -0400 Subject: [PATCH 16/16] [EFR32] Add Board Support for efr32 boards (#22099) * add BRD2703A config files * Add Explorer Board to gn files * Update sdk build files * Fix external flash issue * Update submodule to main * remove unwanted change * Add support for BRD4162A --- examples/chef/efr32/BUILD.gn | 5 +++-- examples/light-switch-app/efr32/BUILD.gn | 5 +++-- examples/lighting-app/efr32/BUILD.gn | 5 +++-- examples/lock-app/efr32/BUILD.gn | 5 +++-- examples/thermostat/efr32/BUILD.gn | 5 +++-- examples/window-app/efr32/BUILD.gn | 5 +++-- third_party/silabs/efr32_board.gni | 8 +++++++- third_party/silabs/efr32_sdk.gni | 17 +++++++++++++++-- third_party/silabs/matter_support | 2 +- 9 files changed, 41 insertions(+), 16 deletions(-) diff --git a/examples/chef/efr32/BUILD.gn b/examples/chef/efr32/BUILD.gn index e23b747fcad1dd..3d1bf35352fa93 100644 --- a/examples/chef/efr32/BUILD.gn +++ b/examples/chef/efr32/BUILD.gn @@ -91,8 +91,9 @@ chip_data_model("chef-common") { is_server = true } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/light-switch-app/efr32/BUILD.gn b/examples/light-switch-app/efr32/BUILD.gn index 2d628f537f9f6e..4b6c15741224d0 100644 --- a/examples/light-switch-app/efr32/BUILD.gn +++ b/examples/light-switch-app/efr32/BUILD.gn @@ -84,8 +84,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index fbd5a88a7909b9..6301fede13a30a 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -84,8 +84,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index e76b9cd48f1d1e..d757da6c50c4ff 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -84,8 +84,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/thermostat/efr32/BUILD.gn b/examples/thermostat/efr32/BUILD.gn index 415d9c5e80d212..bb4e2cb7a17e61 100644 --- a/examples/thermostat/efr32/BUILD.gn +++ b/examples/thermostat/efr32/BUILD.gn @@ -81,8 +81,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index a9aa7cf402911c..a9e0c030a9c292 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -77,8 +77,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/third_party/silabs/efr32_board.gni b/third_party/silabs/efr32_board.gni index b697d2bb3afbc8..3de8aa1337bc6a 100644 --- a/third_party/silabs/efr32_board.gni +++ b/third_party/silabs/efr32_board.gni @@ -44,6 +44,9 @@ if (efr32_board == "BRD4304A") { } else if (efr32_board == "BRD4161A") { efr32_family = "efr32mg12" efr32_mcu = "EFR32MG12P432F1024GL125" +} else if (efr32_board == "BRD4162A") { + efr32_family = "efr32mg12" + efr32_mcu = "EFR32MG12P332F1024GL125" } else if (efr32_board == "BRD4163A") { efr32_family = "efr32mg12" efr32_mcu = "EFR32MG12P433F1024GL125" @@ -75,8 +78,11 @@ if (efr32_board == "BRD4304A") { } else if (efr32_board == "BRD2601B") { efr32_family = "efr32mg24" efr32_mcu = "EFR32MG24B310F1536IM48" +} else if (efr32_board == "BRD2703A") { + efr32_family = "efr32mg24" + efr32_mcu = "EFR32MG24B020F1536IM48" } else { print( - "Please provide a valid value for EFR32_BOARD env variable (currently supported BRD4304A, BRD4161A, BRD4163A, BRD4164A BRD4166A, BRD4170A, BRD4186C, BRD4187C, BRD2601B)") + "Please provide a valid value for EFR32_BOARD env variable (currently supported BRD4304A, BRD4161A, BRD4163A, BRD4164A BRD4166A, BRD4170A, BRD4186C, BRD4187C, BRD2601B, BRD2703A)") assert(false, "The board ${efr32_board} is unsupported") } diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 727ecea7acd5ef..93354bcc5594e6 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -33,6 +33,11 @@ declare_args() { use_external_flash = true } +# Explorer Kit does not have external flash +if (efr32_board == "BRD2703A") { + use_external_flash = false +} + assert(efr32_sdk_root != "", "efr32_sdk_root must be specified") # Defines an efr32 SDK build target. @@ -210,13 +215,14 @@ template("efr32_sdk") { if (defined(invoker.use_external_flash) && use_external_flash) { defines += [ "CONFIG_USE_EXTERNAL_FLASH" ] + + _include_dirs += [ "${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/inc/sl_mx25_flash_shutdown_usart" ] } _include_dirs += [ "${efr32_sdk_root}/platform/emdrv/uartdrv/inc", "${efr32_sdk_root}/platform/emdrv/uartdrv/config", "${efr32_sdk_root}/hardware/driver/memlcd/inc/memlcd_usart", - "${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/inc/sl_mx25_flash_shutdown_usart", ] } @@ -226,6 +232,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/radio/rail_lib/chip/efr32/efr32xg1x", "${efr32_sdk_root}/util/third_party/freertos/kernel/portable/GCC/ARM_CM4F", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg1x/config", + "${efr32_sdk_root}/platform/service/device_init/config/s1/", ] libs += [ @@ -243,6 +250,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/util/third_party/freertos/kernel/portable/GCC/ARM_CM33_NTZ/non_secure", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg21", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg21/config", + "${efr32_sdk_root}/platform/service/device_init/config/s2/", ] libs += [ @@ -263,6 +271,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/util/third_party/freertos/kernel/portable/GCC/ARM_CM33_NTZ/non_secure", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg24", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg24/config", + "${efr32_sdk_root}/platform/service/device_init/config/s2/", ] libs += [ @@ -365,6 +374,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/radio/rail_lib/hal/efr32/hal_efr.c", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/pa_conversions_efr32.c", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/rail_util_pti/sl_rail_util_pti.c", + "${efr32_sdk_root}/platform/service/device_init/src/sl_device_init_lfrco.c", "${efr32_sdk_root}/platform/service/device_init/src/sl_device_init_nvic.c", "${efr32_sdk_root}/platform/service/hfxo_manager/src/sl_hfxo_manager.c", "${efr32_sdk_root}/platform/service/legacy_hal/src/token_legacy.c", @@ -527,13 +537,16 @@ template("efr32_sdk") { (defined(invoker.use_external_flash) && use_external_flash)) { sources += [ "${efr32_sdk_root}/hardware/driver/memlcd/src/memlcd_usart/sl_memlcd_spi.c", - "${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/src/sl_mx25_flash_shutdown_usart/sl_mx25_flash_shutdown.c", "${efr32_sdk_root}/platform/emdrv/uartdrv/src/uartdrv.c", "${efr32_sdk_root}/platform/emlib/src/em_eusart.c", "${efr32_sdk_root}/platform/emlib/src/em_leuart.c", "${efr32_sdk_root}/platform/emlib/src/em_usart.c", "${sdk_support_root}/matter/efr32/${efr32_family}/${efr32_board}/autogen/sl_uartdrv_init.c", ] + + if (defined(invoker.use_external_flash) && use_external_flash) { + sources += [ "${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/src/sl_mx25_flash_shutdown_usart/sl_mx25_flash_shutdown.c" ] + } } if ((defined(invoker.show_qr_code) && invoker.show_qr_code) || diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 16c1ed8eca039b..0c84c861c036fb 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 16c1ed8eca039bb9527421411bd605de8ce21442 +Subproject commit 0c84c861c036fba5ba35eccca3f366925700b2b5