From c6462e20e4d382929f2b4c01385e52216a77b520 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Sat, 15 Jul 2023 04:20:45 +0800 Subject: [PATCH] [Bouffalolab] Add build option to enable rotating device id (#27906) * add option to enable rotating device id * add more files for mbedtls for bl702 * fix restyle and test data --- scripts/build/build/targets.py | 1 + scripts/build/builders/bouffalolab.py | 7 ++++++- scripts/build/testdata/all_targets_linux_x64.txt | 2 +- src/platform/bouffalolab/BL602/args.gni | 2 -- src/platform/bouffalolab/common/BLConfig.h | 6 ++++-- src/platform/bouffalolab/common/BLEManagerImpl.cpp | 1 + src/platform/bouffalolab/common/CHIPPlatformConfig.h | 2 +- src/platform/bouffalolab/common/FactoryDataProvider.cpp | 5 ++++- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 2 ++ 9 files changed, 20 insertions(+), 8 deletions(-) diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index b444a8652e1599..ee9e3df64aaf55 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -603,6 +603,7 @@ def BuildBouffalolabTarget(): target.AppendModifier('115200', baudrate=115200) target.AppendModifier('rpc', enable_rpcs=True) target.AppendModifier('cdc', enable_cdc=True) + target.AppendModifier('rotating_device_id', enable_rotating_device_id=True) return target diff --git a/scripts/build/builders/bouffalolab.py b/scripts/build/builders/bouffalolab.py index 52477be7519ebf..8281ba99e8ca89 100644 --- a/scripts/build/builders/bouffalolab.py +++ b/scripts/build/builders/bouffalolab.py @@ -80,7 +80,8 @@ def __init__(self, module_type: str = "BL706C-22", baudrate=2000000, enable_shell: bool = False, - enable_cdc: bool = False + enable_cdc: bool = False, + enable_rotating_device_id: bool = False ): if 'BL602' == module_type: @@ -125,6 +126,10 @@ def __init__(self, elif enable_shell: self.argsOpt.append('chip_build_libshell=true') + if enable_rotating_device_id: + self.argsOpt.append('chip_enable_additional_data_advertising=true') + self.argsOpt.append('chip_enable_rotating_device_id=true') + try: self.argsOpt.append('bouffalolab_sdk_root="%s"' % os.environ['BOUFFALOLAB_SDK_ROOT']) except KeyError as err: diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index f6c21f3b393ee0..9cf2354a871e40 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -1,7 +1,7 @@ ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed} asr-{asr582x,asr595x}-{all-clusters,all-clusters-minimal,lighting,light-switch,lock,bridge,temperature-measurement,thermostat,ota-requestor}[-ota][-shell][-no_logging][-factory][-rotating_id] android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller}[-no-debug] -bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light,bl704l-dvk}-light[-shell][-115200][-rpc][-cdc] +bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light,bl704l-dvk}-light[-shell][-115200][-rpc][-cdc][-rotating_device_id] cc32xx-lock ti-cc13x2x7_26x2x7-{lighting,lock,pump,pump-controller}[-mtd] ti-cc13x4_26x4-{all-clusters,lighting,lock,pump,pump-controller}[-mtd][-ftd] diff --git a/src/platform/bouffalolab/BL602/args.gni b/src/platform/bouffalolab/BL602/args.gni index 9a4f156ce3ee8c..dd482f9a0d6725 100644 --- a/src/platform/bouffalolab/BL602/args.gni +++ b/src/platform/bouffalolab/BL602/args.gni @@ -26,8 +26,6 @@ lwip_platform = "bl602" chip_inet_config_enable_ipv4 = true -chip_enable_rotating_device_id = false - chip_build_tests = false chip_inet_config_enable_dns_resolver = false chip_inet_config_enable_tun_endpoint = false diff --git a/src/platform/bouffalolab/common/BLConfig.h b/src/platform/bouffalolab/common/BLConfig.h index 3b533a08f5e142..916e849bdbc8fb 100644 --- a/src/platform/bouffalolab/common/BLConfig.h +++ b/src/platform/bouffalolab/common/BLConfig.h @@ -70,8 +70,10 @@ class BLConfig static constexpr const char * kConfigKey_ActiveLocale = ("active-locale"); static constexpr const char * kConfigKey_Breadcrumb = ("breadcrumb"); static constexpr const char * kConfigKey_GroupKeyIndex = ("group-key-index"); - static constexpr const char * kBLConfigKey_wifissid = ("blConfig_wifi-ssid"); - static constexpr const char * kBLConfigKey_wifipassword = ("blConfig_wifi-pwd"); + static constexpr const char * kConfigKey_LifeTimeCounter = ("life-time-counter"); + + static constexpr const char * kBLConfigKey_wifissid = ("blConfig_wifi-ssid"); + static constexpr const char * kBLConfigKey_wifipassword = ("blConfig_wifi-pwd"); /** Counter Keys, diagnostic information */ static constexpr const char * kCounterKey_RebootCount = ("reboot-count"); diff --git a/src/platform/bouffalolab/common/BLEManagerImpl.cpp b/src/platform/bouffalolab/common/BLEManagerImpl.cpp index 29c00c2b3226bd..47cfbd8938ade7 100644 --- a/src/platform/bouffalolab/common/BLEManagerImpl.cpp +++ b/src/platform/bouffalolab/common/BLEManagerImpl.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING #include diff --git a/src/platform/bouffalolab/common/CHIPPlatformConfig.h b/src/platform/bouffalolab/common/CHIPPlatformConfig.h index c3e39f3d2d22d9..fce5146e2c4a89 100644 --- a/src/platform/bouffalolab/common/CHIPPlatformConfig.h +++ b/src/platform/bouffalolab/common/CHIPPlatformConfig.h @@ -26,7 +26,7 @@ #define CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID 1 #define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 2 -#define CHIP_CONFIG_LIFETIIME_PERSISTED_COUNTER_KEY 0x01 +#define CHIP_CONFIG_LIFETIIME_PERSISTED_COUNTER_KEY BLConfig::kConfigKey_LifeTimeCounter // ==================== Security Adaptations ==================== //#define CHIP_CONFIG_SHA256_CONTEXT_SIZE sizeof(bl_sha_ctx_t) diff --git a/src/platform/bouffalolab/common/FactoryDataProvider.cpp b/src/platform/bouffalolab/common/FactoryDataProvider.cpp index 2bee53f6aa9829..77630740776682 100644 --- a/src/platform/bouffalolab/common/FactoryDataProvider.cpp +++ b/src/platform/bouffalolab/common/FactoryDataProvider.cpp @@ -678,7 +678,10 @@ CHIP_ERROR FactoryDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & un #else constexpr uint8_t uniqueId[] = CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID; - uniqueIdSpan = MutableByteSpan((uint8_t *) uniqueId, sizeof(uniqueId)); + VerifyOrReturnValue(uniqueIdSpan.size() >= sizeof(uniqueId), CHIP_ERROR_INVALID_ARGUMENT); + + memcpy(uniqueIdSpan.data(), uniqueId, sizeof(uniqueId)); + uniqueIdSpan.reduce_size(sizeof(uniqueId)); return CHIP_NO_ERROR; #endif diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index 6d3bdcb825eb08..8b69f1b2941cc4 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -542,7 +542,9 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/platform_util.c", "${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/sha256.c", "${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/sha512.c", + "${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/x509.c", "${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/x509_create.c", + "${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/x509_crt.c", "${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/x509write_csr.c", ]