diff --git a/examples/all-clusters-app/esp32/main/main.cpp b/examples/all-clusters-app/esp32/main/main.cpp index ef742c53da078c..5f0aab155c8a10 100644 --- a/examples/all-clusters-app/esp32/main/main.cpp +++ b/examples/all-clusters-app/esp32/main/main.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -68,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -542,6 +544,8 @@ class AppCallbacks : public AppDelegate AppCallbacks sCallbacks; +ACLPersistentStorage gACLStorage; + } // namespace static void InitServer(intptr_t context) @@ -590,6 +594,9 @@ extern "C" void app_main() ESP_LOGE(TAG, "nvs_flash_init() failed: %s", esp_err_to_name(err)); return; } + + Access::Examples::SetAccessControlDelegateStorage(&gACLStorage); + #if CONFIG_ENABLE_PW_RPC chip::rpc::Init(); #endif diff --git a/src/platform/ESP32/ACLPersistentStorage.h b/src/platform/ESP32/ACLPersistentStorage.h new file mode 100644 index 00000000000000..ae94f0737c4e02 --- /dev/null +++ b/src/platform/ESP32/ACLPersistentStorage.h @@ -0,0 +1,65 @@ +/* + * + * 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. + */ +#pragma once + +#include +#include +#include + +class ACLPersistentStorage : public chip::PersistentStorageDelegate +{ +public: + CHIP_ERROR SyncGetKeyValue(const char * key, void * buffer, uint16_t & size) override + { + size_t outSize = 0; + chip::DeviceLayer::Internal::ESP32Config::Key getKey = { + chip::DeviceLayer::Internal::ESP32Config::kConfigNamespace_ChipConfig, key + }; + + CHIP_ERROR err = + chip::DeviceLayer::Internal::ESP32Config::ReadConfigValueBin(getKey, static_cast(buffer), size, outSize); + if (err == CHIP_NO_ERROR) + { + if (outSize > std::numeric_limits::max()) + { + err = CHIP_ERROR_BUFFER_TOO_SMALL; + } + else + { + size = static_cast(outSize); + } + } + return err; + } + + CHIP_ERROR SyncSetKeyValue(const char * key, const void * value, uint16_t size) override + { + chip::DeviceLayer::Internal::ESP32Config::Key setKey = { + chip::DeviceLayer::Internal::ESP32Config::kConfigNamespace_ChipConfig, key + }; + return chip::DeviceLayer::Internal::ESP32Config::WriteConfigValueBin(setKey, static_cast(value), + static_cast(size)); + } + + CHIP_ERROR SyncDeleteKeyValue(const char * key) override + { + chip::DeviceLayer::Internal::ESP32Config::Key delKey = { + chip::DeviceLayer::Internal::ESP32Config::kConfigNamespace_ChipConfig, key + }; + return chip::DeviceLayer::Internal::ESP32Config::ClearConfigValue(delKey); + } +}; diff --git a/src/platform/ESP32/BUILD.gn b/src/platform/ESP32/BUILD.gn index 67a8c304661c7b..293ed0befd671e 100644 --- a/src/platform/ESP32/BUILD.gn +++ b/src/platform/ESP32/BUILD.gn @@ -21,6 +21,7 @@ assert(chip_device_platform == "esp32") static_library("ESP32") { sources = [ "../SingletonConfigurationManager.cpp", + "ACLPersistentStorage.h", "BLEManagerImpl.h", "CHIPDevicePlatformConfig.h", "CHIPDevicePlatformEvent.h",