diff --git a/src/platform/ASR/ASRConfig.cpp b/src/platform/ASR/ASRConfig.cpp index 86eb4ec9582ebf..1e87f3af518804 100644 --- a/src/platform/ASR/ASRConfig.cpp +++ b/src/platform/ASR/ASRConfig.cpp @@ -221,46 +221,35 @@ bool ASRConfig::ConfigValueExists(Key key) CHIP_ERROR ASRConfig::ReadFactoryConfigValue(asr_matter_partition_t matter_partition, uint8_t * buf, size_t bufSize, size_t & outLen) { - int32_t ret = 0; + factory_error_t ret = asr_factory_config_read(matter_partition, buf, (uint32_t) bufSize, (uint32_t *) &outLen); - ret = asr_factory_config_read(matter_partition, buf, (uint32_t) bufSize, (uint32_t *) &outLen); - - if (ret != 0) - ChipLogProgress(DeviceLayer, "asr_factory_config_read: %d failed, ret = %d\n", matter_partition, static_cast(ret)); - - if (ret == 0) - { - return CHIP_NO_ERROR; - } - else + if (ret != FACTORY_NO_ERROR) { + ChipLogProgress(DeviceLayer, "asr_factory_config_read: %d failed, err = %d\n", matter_partition, ret); outLen = 0; return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } + return CHIP_NO_ERROR; } CHIP_ERROR ASRConfig::ReadFactoryConfigValue(asr_matter_partition_t matter_partition, uint32_t & val) { - int32_t ret = 0; uint8_t buf[4]; - size_t outlen = 0; - - ret = asr_factory_config_read(matter_partition, buf, sizeof(uint32_t), (uint32_t *) &outlen); + size_t outlen = 0; + factory_error_t ret = asr_factory_config_read(matter_partition, buf, sizeof(uint32_t), (uint32_t *) &outlen); if (outlen > sizeof(uint32_t)) - ret = -1; + return CHIP_ERROR_BUFFER_TOO_SMALL; - if (ret != 0) - ChipLogProgress(DeviceLayer, "asr_factory_config_read: %d failed, ret = %d\n", matter_partition, static_cast(ret)); - - if (ret == 0) + if (ret != FACTORY_NO_ERROR) { - val = *((uint32_t *) buf); - return CHIP_NO_ERROR; + ChipLogProgress(DeviceLayer, "asr_factory_config_read: %d failed, err = %d\n", matter_partition, ret); + return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } else { - return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; + val = *((uint32_t *) buf); + return CHIP_NO_ERROR; } } #endif diff --git a/src/platform/ASR/ASRConfig.h b/src/platform/ASR/ASRConfig.h old mode 100644 new mode 100755 index af10b47b08d2f9..71c90a3a79b242 --- a/src/platform/ASR/ASRConfig.h +++ b/src/platform/ASR/ASRConfig.h @@ -25,7 +25,7 @@ #pragma once -#include "asr_factory_config.h" +#include "ASRFactoryDataParser.h" #include namespace chip { diff --git a/src/platform/ASR/ASRFactoryDataParser.cpp b/src/platform/ASR/ASRFactoryDataParser.cpp new file mode 100755 index 00000000000000..9483b5cdac5f94 --- /dev/null +++ b/src/platform/ASR/ASRFactoryDataParser.cpp @@ -0,0 +1,277 @@ +/* + * + * Copyright (c) 2023 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 "ASRFactoryDataParser.h" + +#if CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER +/* Logic partition on flash devices for matter */ +const matter_partition_t asr_matter_partitions_table[] = +{ + [ASR_VERSION_PARTITION] = + { + .partition_name = "version", + }, + [ASR_CONFIG_PARTITION] = + { + .partition_name = "config", + }, + [ASR_ITERATION_COUNT_PARTITION] = + { + .partition_name = "iteration-count", + }, + [ASR_SALT_PARTITION] = + { + .partition_name = "salt", + }, + [ASR_VERIFIER_PARTITION] = + { + .partition_name = "verifier", + }, + [ASR_DISCRIMINATOR_PARTITION] = + { + .partition_name = "discriminator", + }, + [ASR_DAC_CERT_PARTITION] = + { + .partition_name = "dac-cert", + }, + [ASR_DAC_KEY_PARTITION] = + { + .partition_name = "dac-pri-key", + }, + [ASR_DAC_PUB_KEY_PARTITION] = + { + .partition_name = "dac-pub-key", + }, + [ASR_PAI_CERT_PARTITION] = + { + .partition_name = "pai-cert", + }, + [ASR_CERT_DCLRN_PARTITION] = + { + .partition_name = "cert-dclrn", + }, + [ASR_CHIP_ID_PARTITION] = + { + .partition_name = "chip-id", + }, +#if CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER + [ASR_VENDOR_NAME_PARTITION] = + { + .partition_name = "vendor-name", + }, + [ASR_VENDOR_ID_PARTITION] = + { + .partition_name = "vendor-id", + }, + [ASR_PRODUCT_NAME_PARTITION] = + { + .partition_name = "product-name", + }, + [ASR_PRODUCT_ID_PARTITION] = + { + .partition_name = "product-id", + }, + [ASR_ROTATING_UNIQUE_ID_PARTITION] = + { + .partition_name = "rd-id-uid", + }, + [ASR_MANUFACTURY_DATE_PARTITION] = + { + .partition_name = "mfg-date", + }, + [ASR_SERIAL_NUMBER_PARTITION] = + { + .partition_name = "serial-num", + }, + [ASR_HARDWARE_VERSION_PARTITION] = + { + .partition_name = "hardware-ver", + }, + [ASR_HARDWARE_VERSION_STR_PARTITION] = + { + .partition_name = "hw-ver-str", + }, + [ASR_PRODUCT_URL_PARTITION] = + { + .partition_name = "product-url", + }, + [ASR_PRODUCT_LABEL_PARTITION] = + { + .partition_name = "product-label", + }, + [ASR_PART_NUMBER_PARTITION] = + { + .partition_name = "part-number", + }, +#endif + [ASR_MATTER_PARTITION_MAX] = + { + .partition_name = NULL, //for end don't change, + } +}; + +static asr_tlv_context matter_tlv_ctx; + +static factory_error_t asr_matter_find_by_name(const char * name, uint8_t * buf, uint32_t buf_len, uint32_t * out_len) +{ + tlv_header_t tlv; + + if (asr_tlv_find_by_name(&matter_tlv_ctx, &tlv, MIXCLASS_MATTERCONFIG_TAG, + (char *) name)) // parse the data according to the tlv packaging tool + { + uint32_t value_len = tlv_htons(tlv->data_len); + + value_len -= MAX_NAME_LEN; + + if (value_len > buf_len) + { + return FACTORY_BUFFER_TOO_SMALL; + } + + *out_len = value_len; + + memcpy(buf, tlv->data + MAX_NAME_LEN, value_len); + + return FACTORY_NO_ERROR; + } + else + { + return FACTORY_VALUE_NOT_FOUND; + } +} + +static uint32_t asr_find_factory_version() +{ + uint8_t buf[4]; + size_t outlen = 0; + uint32_t value = 0; + if (FACTORY_NO_ERROR == + asr_matter_find_by_name((const char *) asr_matter_partitions_table[ASR_VERSION_PARTITION].partition_name, buf, + sizeof(uint32_t), (uint32_t *) &outlen)) + { + value = *(uint32_t *) buf; + } + return value; +} + +static uint32_t asr_find_factory_config() +{ + uint8_t buf[4]; + size_t outlen = 0; + uint32_t value = 0; + if (FACTORY_NO_ERROR == + asr_matter_find_by_name((const char *) asr_matter_partitions_table[ASR_CONFIG_PARTITION].partition_name, buf, + sizeof(uint32_t), (uint32_t *) &outlen)) + { + value = *(uint32_t *) buf; + } + return value; +} + +static factory_error_t asr_factory_dac_prvkey_get(uint8_t * pRdBuf, uint32_t * pOutLen) +{ + static constexpr uint32_t kDACPrivateKeySize = 32; + if (NULL == pRdBuf || NULL == pOutLen) + { + return FACTORY_INVALID_INPUT; + } + + if (asr_find_factory_config() & ASR_CONFIG_MATTER_NO_KEY) + { +#if defined(CFG_PLF_RV32) || defined(CFG_PLF_DUET) + uint32_t off_set; + uint8_t ucCipher[kDACPrivateKeySize]; + tlv_area_header_t tlv_headr_p = (tlv_area_header_t) MATTER_FLASH_START_ADDR; + off_set = tlv_headr_p->data_len + 3 * sizeof(uint32_t); // magic_num,crc32_value,data_len + // get DAC cipher + if (asr_flash_read(ASR_CONFIG_BASE, (uint32_t *) &off_set, (void *) ucCipher, kDACPrivateKeySize) == 0) + { + if (asr_factory_decrypt_dac_prvkey(ucCipher, kDACPrivateKeySize, pRdBuf, pOutLen) == 0) + { + return FACTORY_NO_ERROR; + } + } +#endif + return FACTORY_NOT_SUPPORTED; + } + else + { + return asr_matter_find_by_name((const char *) asr_matter_partitions_table[ASR_DAC_KEY_PARTITION].partition_name, pRdBuf, + kDACPrivateKeySize, pOutLen); + } +} + +static int asr_partition_members_count_cb(tlv_header_t tlv, void * arg1, void * arg2) +{ + int * count = (int *) arg1; + + *count = *count + 1; + + return 0; +} + +static factory_error_t asr_partition_table_load(void) +{ + int table_members = 0; + + if (asr_tlv_poll_class_members(&matter_tlv_ctx, MIXCLASS_MATTERCONFIG_TAG, asr_partition_members_count_cb, &table_members, + NULL)) + { + if (table_members > 0) + { + if (asr_find_factory_version() == ASR_MATTER_FACTORY_VERSION) + { + return FACTORY_NO_ERROR; + } + else + { + return FACTORY_VERSION_MISMATCH; + } + } + } + return FACTORY_DATA_CHECK_FAILED; +} + +factory_error_t asr_factory_config_read(asr_matter_partition_t matter_partition, uint8_t * buf, uint32_t buf_len, + uint32_t * out_len) +{ + + if (matter_partition >= ASR_MATTER_PARTITION_MAX) + { + return FACTORY_INVALID_INPUT; + } + + if (matter_partition == ASR_DAC_KEY_PARTITION) + { + return asr_factory_dac_prvkey_get(buf, out_len); + } + + return asr_matter_find_by_name((const char *) asr_matter_partitions_table[matter_partition].partition_name, buf, buf_len, + out_len); +} + +factory_error_t asr_factory_check() +{ + if (asr_tlv_init(&matter_tlv_ctx, MATTER_FLASH_START_ADDR) != 0) + { + return FACTORY_DATA_INIT_FAILED; + } + + return asr_partition_table_load(); +} +#endif // CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER diff --git a/src/platform/ASR/ASRFactoryDataParser.h b/src/platform/ASR/ASRFactoryDataParser.h new file mode 100644 index 00000000000000..e3de051fedf7f3 --- /dev/null +++ b/src/platform/ASR/ASRFactoryDataParser.h @@ -0,0 +1,116 @@ +/* + * + * Copyright (c) 2023 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 "stdint.h" +#include "string.h" +#include "tlv_decode.h" +#ifdef CFG_PLF_RV32 +#include "asr_flash.h" +#include "asr_rv32.h" +#elif defined CFG_PLF_DUET +#include "duet_cm4.h" +#include "duet_flash.h" +#define asr_flash_read duet_flash_read +#define asr_factory_decrypt_dac_prvkey duet_factory_decrypt_dac_prvkey +#else +#include "lega_cm4.h" +#include "lega_flash.h" +#define asr_flash_read lega_flash_read +#endif + +#ifndef CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER +#define CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER 0 +#endif // CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER + +#ifndef CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER +#define CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER 0 +#endif // CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER + +#define ASR_CONFIG_BASE PARTITION_MATTER_CONFIG +#define ASR_MATTER_FACTORY_VERSION 2 +#define ASR_CONFIG_MATTER_NO_KEY 0x01 + +#if CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER +typedef enum ASR_MATTER_PARTITION_T +{ + ASR_VERSION_PARTITION = 0x00, + ASR_CONFIG_PARTITION, + ASR_ITERATION_COUNT_PARTITION, + ASR_SALT_PARTITION, + ASR_VERIFIER_PARTITION, + ASR_DISCRIMINATOR_PARTITION, + ASR_DAC_CERT_PARTITION, + ASR_DAC_KEY_PARTITION, + ASR_DAC_PUB_KEY_PARTITION, + ASR_PAI_CERT_PARTITION, + ASR_CERT_DCLRN_PARTITION, + ASR_CHIP_ID_PARTITION, +#if CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER + ASR_VENDOR_NAME_PARTITION, + ASR_VENDOR_ID_PARTITION, + ASR_PRODUCT_NAME_PARTITION, + ASR_PRODUCT_ID_PARTITION, + ASR_ROTATING_UNIQUE_ID_PARTITION, + ASR_MANUFACTURY_DATE_PARTITION, + ASR_SERIAL_NUMBER_PARTITION, + ASR_HARDWARE_VERSION_PARTITION, + ASR_HARDWARE_VERSION_STR_PARTITION, + ASR_PRODUCT_URL_PARTITION, + ASR_PRODUCT_LABEL_PARTITION, + ASR_PART_NUMBER_PARTITION, +#endif + ASR_MATTER_PARTITION_MAX, +} asr_matter_partition_t; + +typedef struct +{ + const char * partition_name; +} matter_partition_t; + +typedef enum +{ + FACTORY_NO_ERROR = 0x00, + FACTORY_BUFFER_TOO_SMALL, + FACTORY_VALUE_NOT_FOUND, + FACTORY_INVALID_INPUT, + FACTORY_NOT_SUPPORTED, + FACTORY_VERSION_MISMATCH, + FACTORY_DATA_CHECK_FAILED, + FACTORY_DATA_INIT_FAILED, +} factory_error_t; + +/** + * @brief Tries to read the factory data within the given partition. + * + * @param matter_partition The matter partition to be find out. + * @param buf Output buffer to store found factory data. + * @param buf_len Size of buffer. + * @param outlen Actual size of found factory data. + * @return FACTORY_NO_ERROR on success, other factory_error_t values from implementation on other errors. + */ +factory_error_t asr_factory_config_read(asr_matter_partition_t matter_partition, uint8_t * buf, uint32_t buf_len, + uint32_t * out_len); +/** + * @brief Init and check if the factory data filed is valid. + * + * @return FACTORY_NO_ERROR on success, other factory_error_t values from implementation on other errors. + */ +factory_error_t asr_factory_check(); + +#endif // CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER diff --git a/src/platform/ASR/ASRFactoryDataProvider.cpp b/src/platform/ASR/ASRFactoryDataProvider.cpp index 0e28c014a72937..c1a436168f6246 100755 --- a/src/platform/ASR/ASRFactoryDataProvider.cpp +++ b/src/platform/ASR/ASRFactoryDataProvider.cpp @@ -46,11 +46,11 @@ CHIP_ERROR ASRFactoryDataProvider::Init() { CHIP_ERROR err = CHIP_NO_ERROR; #if CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER - uint8_t ret = asr_factory_check(); - if (ret != 0) + factory_error_t ret = asr_factory_check(); + if (ret != FACTORY_NO_ERROR) { err = CHIP_ERROR_INTERNAL; - ChipLogError(DeviceLayer, "ASR factory data check failed."); + ChipLogError(DeviceLayer, "ASR factory data check failed. err = %d", ret); } #endif return err; @@ -355,9 +355,8 @@ CHIP_ERROR ASRFactoryDataProvider::GetVendorName(char * buf, size_t bufSize) ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME); #else -#define BUFFER_MAX_SIZE 32 - uint8_t buffer[BUFFER_MAX_SIZE + 1] = { 0 }; - size_t buffer_len = BUFFER_MAX_SIZE + 1; + size_t buffer_len = ConfigurationManager::kMaxVendorNameLength + 1; + uint8_t buffer[ConfigurationManager::kMaxVendorNameLength + 1] = { 0 }; ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_VENDOR_NAME_PARTITION, buffer, buffer_len, buffer_len)); ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(buf, buffer, buffer_len); @@ -373,7 +372,7 @@ CHIP_ERROR ASRFactoryDataProvider::GetVendorId(uint16_t & vendorId) #else uint32_t vendorId32; ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_VENDOR_ID_PARTITION, vendorId32)); - vendorId = static_cast(vendorId32); + vendorId = static_cast(vendorId32); #endif return CHIP_NO_ERROR; } @@ -384,9 +383,8 @@ CHIP_ERROR ASRFactoryDataProvider::GetProductName(char * buf, size_t bufSize) ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME); #else -#define BUFFER_MAX_SIZE 32 - uint8_t buffer[BUFFER_MAX_SIZE + 1] = { 0 }; - size_t buffer_len = BUFFER_MAX_SIZE + 1; + size_t buffer_len = ConfigurationManager::kMaxProductNameLength + 1; + uint8_t buffer[ConfigurationManager::kMaxProductNameLength + 1] = { 0 }; ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_PRODUCT_NAME_PARTITION, buffer, buffer_len, buffer_len)); ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(buf, buffer, buffer_len); @@ -402,24 +400,54 @@ CHIP_ERROR ASRFactoryDataProvider::GetProductId(uint16_t & productId) #else uint32_t productId32; ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_PRODUCT_ID_PARTITION, productId32)); - productId = static_cast(productId32); + productId = static_cast(productId32); #endif return CHIP_NO_ERROR; } CHIP_ERROR ASRFactoryDataProvider::GetPartNumber(char * buf, size_t bufSize) { +#if !CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +#else + size_t buffer_len = ConfigurationManager::kMaxPartNumberLength + 1; + uint8_t buffer[ConfigurationManager::kMaxPartNumberLength + 1] = { 0 }; + ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_PART_NUMBER_PARTITION, buffer, buffer_len, buffer_len)); + ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(buf, buffer, buffer_len); + buf[buffer_len] = 0; +#endif + return CHIP_NO_ERROR; } CHIP_ERROR ASRFactoryDataProvider::GetProductURL(char * buf, size_t bufSize) { +#if !CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +#else + size_t buffer_len = ConfigurationManager::kMaxProductURLLength + 1; + uint8_t buffer[ConfigurationManager::kMaxProductURLLength + 1] = { 0 }; + ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_PRODUCT_URL_PARTITION, buffer, buffer_len, buffer_len)); + ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(buf, buffer, buffer_len); + buf[buffer_len] = 0; +#endif + return CHIP_NO_ERROR; } CHIP_ERROR ASRFactoryDataProvider::GetProductLabel(char * buf, size_t bufSize) { +#if !CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +#else + size_t buffer_len = ConfigurationManager::kMaxProductLabelLength + 1; + uint8_t buffer[ConfigurationManager::kMaxProductLabelLength + 1] = { 0 }; + ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_PRODUCT_LABEL_PARTITION, buffer, buffer_len, buffer_len)); + ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(buf, buffer, buffer_len); + buf[buffer_len] = 0; +#endif + return CHIP_NO_ERROR; } CHIP_ERROR ASRFactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize) @@ -428,9 +456,8 @@ CHIP_ERROR ASRFactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize) ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER); #else -#define BUFFER_MAX_SIZE 32 - uint8_t buffer[BUFFER_MAX_SIZE + 1] = { 0 }; - size_t buffer_len = BUFFER_MAX_SIZE + 1; + size_t buffer_len = ConfigurationManager::kMaxSerialNumberLength + 1; + uint8_t buffer[ConfigurationManager::kMaxSerialNumberLength + 1] = { 0 }; ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_SERIAL_NUMBER_PARTITION, buffer, buffer_len, buffer_len)); ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(buf, buffer, buffer_len); @@ -487,7 +514,7 @@ CHIP_ERROR ASRFactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion #else uint32_t hardwareVersion32; ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_HARDWARE_VERSION_PARTITION, hardwareVersion32)); - hardwareVersion = static_cast(hardwareVersion32); + hardwareVersion = static_cast(hardwareVersion32); #endif return CHIP_NO_ERROR; } @@ -498,9 +525,8 @@ CHIP_ERROR ASRFactoryDataProvider::GetHardwareVersionString(char * buf, size_t b ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING); #else -#define BUFFER_MAX_SIZE 32 - uint8_t buffer[BUFFER_MAX_SIZE + 1] = { 0 }; - size_t buffer_len = BUFFER_MAX_SIZE + 1; + size_t buffer_len = ConfigurationManager::kMaxHardwareVersionStringLength + 1; + uint8_t buffer[ConfigurationManager::kMaxHardwareVersionStringLength + 1] = { 0 }; ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_HARDWARE_VERSION_STR_PARTITION, buffer, buffer_len, buffer_len)); ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(buf, buffer, buffer_len); diff --git a/src/platform/ASR/BUILD.gn b/src/platform/ASR/BUILD.gn index eff3c98881cf94..033f07e977835a 100755 --- a/src/platform/ASR/BUILD.gn +++ b/src/platform/ASR/BUILD.gn @@ -26,6 +26,8 @@ static_library("ASR") { "../SingletonConfigurationManager.cpp", "ASRConfig.cpp", "ASRConfig.h", + "ASRFactoryDataParser.cpp", + "ASRFactoryDataParser.h", "ASRFactoryDataProvider.cpp", "ASRUtils.cpp", "ASRUtils.h", diff --git a/src/platform/ASR/route_hook/asr_route_hook.c b/src/platform/ASR/route_hook/asr_route_hook.c old mode 100644 new mode 100755 index 0dae344f057e99..85902550aebe19 --- a/src/platform/ASR/route_hook/asr_route_hook.c +++ b/src/platform/ASR/route_hook/asr_route_hook.c @@ -3,7 +3,7 @@ #include "asr_route_hook.h" #include "asr_route_table.h" - +#include "lega_rtos_api.h" #include "lwip/icmp6.h" #include "lwip/mld6.h" #include "lwip/netif.h" @@ -166,7 +166,7 @@ int8_t asr_route_hook_init() return -1; } - for (asr_route_hook_t * iter = s_hooks; iter != NULL; iter++) + for (asr_route_hook_t * iter = s_hooks; iter != NULL; iter = iter->next) { if (iter->netif == lwip_netif) { @@ -175,7 +175,7 @@ int8_t asr_route_hook_init() } } - hook = (asr_route_hook_t *) malloc(sizeof(asr_route_hook_t)); + hook = (asr_route_hook_t *) lega_rtos_malloc(sizeof(asr_route_hook_t)); if (hook == NULL) { ASR_LOG("Cannot allocate hook"); @@ -203,7 +203,7 @@ int8_t asr_route_hook_init() exit: if (ret != 0 && hook != NULL) { - free(hook); + lega_rtos_free(hook); } return ret; } diff --git a/third_party/asr/asr550x/BUILD.gn b/third_party/asr/asr550x/BUILD.gn index 4f9364a80dc5b5..480935ea1eaa93 100755 --- a/third_party/asr/asr550x/BUILD.gn +++ b/third_party/asr/asr550x/BUILD.gn @@ -28,7 +28,6 @@ config("asr_sdk_config") { _include_dirs = [ "${asr_sdk_build_root}/asr_sdk/config", "${asr_sdk_build_root}/asr_sdk/config/lwip_if", - "${asr_sdk_build_root}/asr_sdk/matter", "${asr_sdk_build_root}/asr_sdk/lib", "${asr_sdk_build_root}/asr_sdk/lib/security", "${asr_sdk_build_root}/asr_sdk/version", diff --git a/third_party/asr/asr550x/asr_sdk b/third_party/asr/asr550x/asr_sdk index 9a1bc5e475786a..f2c231f00f647d 160000 --- a/third_party/asr/asr550x/asr_sdk +++ b/third_party/asr/asr550x/asr_sdk @@ -1 +1 @@ -Subproject commit 9a1bc5e475786ad4f857924afe2b4c0d09fce5c3 +Subproject commit f2c231f00f647d35d484b0d16b29d4bbba7a97c3 diff --git a/third_party/asr/asr550x/asr_sdk.gni b/third_party/asr/asr550x/asr_sdk.gni old mode 100644 new mode 100755 index d4e12c226871a8..cb2e18724b10e1 --- a/third_party/asr/asr550x/asr_sdk.gni +++ b/third_party/asr/asr550x/asr_sdk.gni @@ -92,9 +92,6 @@ template("asr_sdk_sources") { "../../components/freertos/Source/portable/MemMang/heap_4.c", "../../components/freertos/Source/portable/GCC/ARM_CM4F/port.c", - #matter - "matter/asr_factory_config.c", - #elog "common/easylogger/elog_async.c", "common/easylogger/elog_buf.c", diff --git a/third_party/asr/asr582x/BUILD.gn b/third_party/asr/asr582x/BUILD.gn index 69b730218b87fa..b4ac418b3169f4 100755 --- a/third_party/asr/asr582x/BUILD.gn +++ b/third_party/asr/asr582x/BUILD.gn @@ -22,6 +22,8 @@ declare_args() { # Must be "4M" or "2M". For matter, ASR582X use 4M flash default. asr_flash_max_size = "4M" + + asr_enable_secureboot = false } assert(asr_target_project != "", "asr_target_project must be specified") @@ -31,7 +33,6 @@ config("asr_sdk_config") { _include_dirs = [ "${asr_sdk_build_root}/asr_sdk/config", "${asr_sdk_build_root}/asr_sdk/config/lwip_if", - "${asr_sdk_build_root}/asr_sdk/matter", "${asr_sdk_build_root}/asr_sdk/lib/wifi", "${asr_sdk_build_root}/asr_sdk/lib/ble", "${asr_sdk_build_root}/asr_sdk/lib/sys", @@ -141,6 +142,10 @@ config("asr_sdk_config") { defines += [ "CFG_DUET_5822T" ] } + if (asr_enable_secureboot) { + defines += [ "_CFG_SECUREBOOT_" ] + } + cflags_c = [ "-mcpu=cortex-m4", "-Os", diff --git a/third_party/asr/asr582x/asr_sdk b/third_party/asr/asr582x/asr_sdk index 8f79b90d61768f..54644715210812 160000 --- a/third_party/asr/asr582x/asr_sdk +++ b/third_party/asr/asr582x/asr_sdk @@ -1 +1 @@ -Subproject commit 8f79b90d61768f453877d588a1bc8951e81a6818 +Subproject commit 54644715210812fa6c1e6e9433b5b824ba735c67 diff --git a/third_party/asr/asr582x/asr_sdk.gni b/third_party/asr/asr582x/asr_sdk.gni index 188a561856ed4c..f083f4cf9f3787 100755 --- a/third_party/asr/asr582x/asr_sdk.gni +++ b/third_party/asr/asr582x/asr_sdk.gni @@ -101,9 +101,6 @@ template("asr_sdk_sources") { "demo/matter_demo/app/ble_demo/duet_hl_matter/app.c", "demo/matter_demo/app/ble_demo/duet_hl_matter/user_platform.c", - #matter - "matter/asr_factory_config.c", - #elog "common/duet/easylogger/elog_async.c", "common/duet/easylogger/elog_buf.c", diff --git a/third_party/asr/asr595x/BUILD.gn b/third_party/asr/asr595x/BUILD.gn index aecf90a3ae10d3..272075049ce06b 100755 --- a/third_party/asr/asr595x/BUILD.gn +++ b/third_party/asr/asr595x/BUILD.gn @@ -28,7 +28,6 @@ config("asr_sdk_config") { _include_dirs = [ "${asr_sdk_build_root}/asr_sdk/config", "${asr_sdk_build_root}/asr_sdk/config/lwip_if", - "${asr_sdk_build_root}/asr_sdk/matter", "${asr_sdk_build_root}/asr_sdk/at_cmd", "${asr_sdk_build_root}/asr_sdk/common/alto/inc", "${asr_sdk_build_root}/asr_sdk/common/alto/easylogger", diff --git a/third_party/asr/asr595x/asr_sdk b/third_party/asr/asr595x/asr_sdk index 651085cd81a112..c0e661fe67c069 160000 --- a/third_party/asr/asr595x/asr_sdk +++ b/third_party/asr/asr595x/asr_sdk @@ -1 +1 @@ -Subproject commit 651085cd81a1127116a43b84a507301201ef4cf8 +Subproject commit c0e661fe67c06937870bb82e55b9eefa8a3dd6d7 diff --git a/third_party/asr/asr595x/asr_sdk.gni b/third_party/asr/asr595x/asr_sdk.gni index 45a7913ba5074a..074ded5d604d32 100755 --- a/third_party/asr/asr595x/asr_sdk.gni +++ b/third_party/asr/asr595x/asr_sdk.gni @@ -123,9 +123,6 @@ template("asr_sdk_sources") { "projects/alto_demo/ble_demo/duet_hl_matter/app.c", "projects/alto_demo/ble_demo/duet_hl_matter/user_platform.c", - #matter - "matter/asr_factory_config.c", - #lwip "../../components/lwip_2.1.2/netif/ethernet.c", "../../components/lwip_2.1.2/port/sys_arch.c",