-
Notifications
You must be signed in to change notification settings - Fork 31
[SL-UP] Full integration of CTM credentials and migration. #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release_2.7-1.4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| */ | ||
|
|
||
| #include "MigrationManager.h" | ||
| #include <headers/ProvisionManager.h> | ||
| #include <headers/ProvisionStorage.h> | ||
| #include <platform/CHIPDeviceLayer.h> | ||
| #include <platform/silabs/SilabsConfig.h> | ||
| #include <stdio.h> | ||
|
|
@@ -41,6 +43,7 @@ static migrationData_t migrationTable[] = { | |
| { .migrationGroup = 2, .migrationFunc = MigrateDacProvider }, | ||
| { .migrationGroup = 3, .migrationFunc = MigrateCounterConfigs }, | ||
| { .migrationGroup = 4, .migrationFunc = MigrateHardwareVersion }, | ||
| { .migrationGroup = 5, .migrationFunc = MigrateCTM }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning !!! There is also a catch22 here. Once this is merged, all apps must use CTM by default, else Migration will be done when CTM is not in use and will never be called again. IF CTM implementation can become default, then we shouldn't keep SilabsConfig and SilabsConfigCTM. Does the Mig also work for 917? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are keeping it since Series 2 cannot move to CTM right now because in series 2 the token interface relies on zigbee or embernet. Regarding 917, I do not think the CTM supports it but I have to confirm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding the catch 22, the nvm location will be the same for all, however since Series2 cannot use the CTM API currently, we need to keep the SilabsConfig. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The final version of the DoorLock migration do not use the MigrationManager. It required to move the migrations later on on the initialization, which I deemed too risky, so the DoorLock migration end up being a standalone process. |
||
| // add any additional migration neccesary. migrationGroup should stay equal if done in the same commit or increment by 1 for | ||
| // each new entry. | ||
| }; | ||
|
|
@@ -132,6 +135,15 @@ void MigrateHardwareVersion(void) | |
| MigrationManager::MigrateUint16(kOldKey_HardwareVersion, SilabsConfig::kConfigKey_HardwareVersion); | ||
| } | ||
|
|
||
| void MigrateCTM(void) | ||
| { | ||
| CHIP_ERROR err = Provision::Manager::GetInstance().GetStorage().MigrateAttestationCredentialAPI(); | ||
| if (err != CHIP_NO_ERROR) | ||
| { | ||
| ChipLogError(DeviceLayer, "Failed to migrate CTM: %s", ErrorStr(err)); | ||
| } | ||
| } | ||
|
|
||
| } // namespace Silabs | ||
| } // namespace DeviceLayer | ||
| } // namespace chip | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,11 +27,11 @@ | |
| #include <functional> | ||
| #include <platform/CHIPDeviceError.h> | ||
|
|
||
| #ifndef SL_COMMON_TOKEN_MANAGER_ENABLE_DYNAMIC_TOKENS | ||
| #ifdef SL_TOKEN_MANAGER_DEFINES_H | ||
| #include <sl_token_manager_defines.h> | ||
| #else | ||
| #include "nvm3.h" | ||
| #include "nvm3_hal_flash.h" | ||
| #else | ||
| #include <sl_token_manager_defines.h> | ||
| #endif | ||
|
|
||
| #ifndef KVS_MAX_ENTRIES | ||
|
|
@@ -61,7 +61,20 @@ namespace Internal { | |
| * the template class (e.g. the ReadConfigValue() method). | ||
| */ | ||
|
|
||
| #ifndef SL_COMMON_TOKEN_MANAGER_ENABLE_DYNAMIC_TOKENS | ||
| #ifdef SL_TOKEN_MANAGER_DEFINES_H | ||
| inline constexpr uint32_t kUserNvm3KeyDomainLoLimit = SL_TOKEN_NVM3_REGION_USER; | ||
| inline constexpr uint32_t kUserNvm3KeyDomainHiLimit = SL_TOKEN_NVM3_REGION_ZIGBEE - 1; | ||
|
|
||
| // Only keep the MSBs of the Matter Region. The LSB of the region is determined by the keyBaseOffset. | ||
| // with SilabsConfigKey Helper function. | ||
| inline constexpr uint32_t kMatterNvm3KeyDomain = (SL_TOKEN_NVM3_REGION_MATTER & 0xFFFF000); | ||
|
|
||
| constexpr inline uint32_t SilabsConfigKey(uint8_t keyBaseOffset, uint8_t id) | ||
| { | ||
| return SL_TOKEN_TYPE_NVM3 | kMatterNvm3KeyDomain | static_cast<uint32_t>(keyBaseOffset) << 8 | id; | ||
| } | ||
|
|
||
| #else | ||
| // Silabs NVM3 objects use a 20-bit number, | ||
| // NVM3 Key 19:16 Stack region | ||
| // NVM3 Key 15:0 Available NVM3 keys 0x0000 -> 0xFFFF. | ||
|
|
@@ -77,24 +90,6 @@ constexpr inline uint32_t SilabsConfigKey(uint8_t keyBaseOffset, uint8_t id) | |
| { | ||
| return kMatterNvm3KeyDomain | static_cast<uint32_t>(keyBaseOffset) << 8 | id; | ||
| } | ||
| #else | ||
|
|
||
| inline constexpr uint32_t kUserNvm3KeyDomainLoLimit = SL_TOKEN_NVM3_REGION_USER; | ||
| inline constexpr uint32_t kUserNvm3KeyDomainHiLimit = SL_TOKEN_NVM3_REGION_ZIGBEE - 1; | ||
|
|
||
| // Only keep the MSBs of the Matter Region. The LSB of the region is determined by the keyBaseOffset. | ||
| // with SilabsConfigKey Helper function. | ||
| inline constexpr uint32_t kMatterNvm3KeyDomain = (SL_TOKEN_NVM3_REGION_MATTER & 0xFFFF000); | ||
|
|
||
| constexpr inline uint32_t SilabsConfigKey(uint8_t keyBaseOffset, uint8_t id) | ||
| { | ||
| return SL_TOKEN_TYPE_NVM3 | kMatterNvm3KeyDomain | static_cast<uint32_t>(keyBaseOffset) << 8 | id; | ||
| } | ||
|
|
||
| constexpr inline uint32_t SilabsSecureTokenKey(uint8_t keyBaseOffset, uint8_t id) | ||
| { | ||
| return SL_TOKEN_TYPE_STATIC_SECURE | static_cast<uint32_t>(keyBaseOffset) << 8 | id; | ||
| } | ||
|
Comment on lines
-94
to
-97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the story with this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were going to use NVM3, then we weren't, now we are going to use it again. |
||
| #endif | ||
|
|
||
| inline constexpr uint32_t kMatterNvm3KeyLoLimit = 0x087200U; // Do not modify without Silabs GSDK team approval | ||
|
|
@@ -151,16 +146,23 @@ class SilabsConfig | |
| // SHALL NOT be the same as the UniqueID attribute exposed in the Basic Information cluster. | ||
| static constexpr Key kConfigKey_PersistentUniqueId = SilabsConfigKey(kMatterFactory_KeyBase, 0x1F); | ||
| static constexpr Key kConfigKey_Creds_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x20); | ||
| static constexpr Key kConfigKey_Creds_Base_Addr = SilabsConfigKey(kMatterFactory_KeyBase, 0x21); | ||
| static constexpr Key kConfigKey_Creds_DAC_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x22); | ||
| static constexpr Key kConfigKey_Creds_DAC_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x23); | ||
| static constexpr Key kConfigKey_Creds_PAI_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x24); | ||
| static constexpr Key kConfigKey_Creds_PAI_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x25); | ||
| static constexpr Key kConfigKey_Creds_CD_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x26); | ||
| static constexpr Key kConfigKey_Creds_CD_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x27); | ||
| static constexpr Key kConfigKey_Provision_Request = SilabsConfigKey(kMatterFactory_KeyBase, 0x28); | ||
| static constexpr Key kConfigKey_Provision_Version = SilabsConfigKey(kMatterFactory_KeyBase, 0x29); | ||
| static constexpr Key kOtaTlvEncryption_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x30); | ||
|
|
||
| // DEPRECATED KEYS : BEGIN | ||
| static constexpr Key kConfigKey_Creds_Base_Addr = SilabsConfigKey(kMatterFactory_KeyBase, 0x21); | ||
| static constexpr Key kConfigKey_Creds_DAC_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x22); | ||
| static constexpr Key kConfigKey_Creds_PAI_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x24); | ||
| static constexpr Key kConfigKey_Creds_CD_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x26); | ||
| // DEPRECATED KEYS : END | ||
|
|
||
| static constexpr Key kConfigKey_Creds_DAC_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x23); | ||
| static constexpr Key kConfigKey_Creds_PAI_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x25); | ||
| static constexpr Key kConfigKey_Creds_CD_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x27); | ||
| static constexpr Key kConfigKey_Provision_Request = SilabsConfigKey(kMatterFactory_KeyBase, 0x28); | ||
| static constexpr Key kConfigKey_Provision_Version = SilabsConfigKey(kMatterFactory_KeyBase, 0x29); | ||
lpbeliveau-silabs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| static constexpr Key kOtaTlvEncryption_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x30); | ||
| static constexpr Key kConfigKey_Creds_Dac = SilabsConfigKey(kMatterFactory_KeyBase, 0x31); | ||
| static constexpr Key kConfigKey_Creds_Pai = SilabsConfigKey(kMatterFactory_KeyBase, 0x32); | ||
| static constexpr Key kConfigKey_Creds_CD = SilabsConfigKey(kMatterFactory_KeyBase, 0x33); | ||
|
Comment on lines
+163
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need follow-up/aggrement on where to store does. I don't think nvm3 is the way to go. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NVM3 would have been the easy way to get series 2 on board as well. |
||
|
|
||
| // Matter Config Keys | ||
| static constexpr Key kConfigKey_ServiceConfig = SilabsConfigKey(kMatterConfig_KeyBase, 0x01); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright (c) 2025 Project CHIP Authors | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * @file | ||
| * Utility functions for Silicon Labs platform error handling | ||
| * and common operations. | ||
| */ | ||
|
|
||
| #include <platform/silabs/SilabsConfigUtils.h> | ||
|
|
||
| #include <lib/core/CHIPError.h> | ||
| #include <lib/support/CodeUtils.h> | ||
| #include <platform/CHIPDeviceError.h> | ||
|
|
||
| namespace chip { | ||
| namespace DeviceLayer { | ||
| namespace Internal { | ||
|
|
||
| CHIP_ERROR MapNvm3Error(sl_status_t nvm3Res) | ||
| { | ||
| CHIP_ERROR err; | ||
|
|
||
| switch (nvm3Res) | ||
| { | ||
| case SL_STATUS_OK: | ||
| err = CHIP_NO_ERROR; | ||
| break; | ||
| case SL_STATUS_NOT_FOUND: | ||
| err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; | ||
| break; | ||
| default: | ||
| err = CHIP_ERROR(ChipError::Range::kPlatform, (nvm3Res & 0xFF) + CHIP_DEVICE_CONFIG_SILABS_NVM3_ERROR_MIN); | ||
| break; | ||
| } | ||
|
|
||
| return err; | ||
| } | ||
|
|
||
| } // namespace Internal | ||
| } // namespace DeviceLayer | ||
| } // namespace chip |
Uh oh!
There was an error while loading. Please reload this page.