Skip to content
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

[TI] Factory Reset updates for CC13X2_26X2 #23963

Merged
merged 16 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions examples/platform/cc13x2_26x2/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@

import("//build_overrides/chip.gni")

config("chip_examples_project_config") {
include_dirs = [ "project_include" ]
config("attestation-credentials-config") {
include_dirs = [ "${chip_root}" ]

defines = [ "CC13X2_26X2_ATTESTATION_CREDENTIALS" ]
}

source_set("openthread_core_config_cc13x2_26x2_chip_examples") {
sources = [ "project_include/OpenThreadConfig.h" ]
public_configs = [ ":chip_examples_project_config" ]
source_set("cc13x2_26x2-attestation-credentials") {
sources = [
"CC13X2_26X2DeviceAttestationCreds.cpp",
"CC13X2_26X2DeviceAttestationCreds.h",
]

public_deps = [
"${chip_root}/src/credentials",
"${chip_root}/src/platform:platform_base",
]

public_configs = [ ":attestation-credentials-config" ]
}
258 changes: 258 additions & 0 deletions examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
*
* 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 <credentials/DeviceAttestationCredsProvider.h>

namespace chip {
namespace Credentials {
namespace CC13X2_26X2 {

/**
* @brief Get implementation of a sample DAC provider to validate device
* attestation procedure.
*
* @returns a singleton DeviceAttestationCredentialsProvider that relies on no
* storage abstractions.
*/
DeviceAttestationCredentialsProvider * GetCC13X2_26X2DacProvider();

} // namespace CC13X2_26X2
} // namespace Credentials
} // namespace chip
1 change: 1 addition & 0 deletions examples/pump-app/cc13x2x7_26x2x7/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ti_simplelink_executable("pump_app") {
deps = [
":sdk",
":sysconfig",
"${chip_root}/examples/platform/cc13x2_26x2:cc13x2_26x2-attestation-credentials",
"${chip_root}/examples/pump-app/pump-common",
"${chip_root}/src/lib",
]
Expand Down
12 changes: 8 additions & 4 deletions examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
#include <app/server/Server.h>

#include "FreeRTOS.h"
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#include <app/EventLogging.h>
#include <app/util/af-types.h>
#include <app/util/af.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.h>

#if defined(CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR)
#include <app/clusters/ota-requestor/BDXDownloader.h>
Expand Down Expand Up @@ -221,8 +221,12 @@ int AppTask::Init()
(void) initParams.InitializeStaticResourcesBeforeServerInit();
chip::Server::GetInstance().Init(initParams);

// Initialize device attestation config
// Initialize device attestation config
#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS
SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider());
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif

ConfigurationMgr().LogDeviceConfig();

Expand Down
175 changes: 111 additions & 64 deletions src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,89 @@ namespace Internal {
/* itemID and subID are limited to 10 bits, even though their types are uint16_t */

// Keys stored in the Chip-factory namespace
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SerialNum = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0001 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceId = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0002 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceCert = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0003 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceICACerts = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0004 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDevicePrivateKey = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0005 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_HardwareVersion = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0006 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ManufacturingDate = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0007 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupPinCode = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0008 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupDiscriminator = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x0009 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pIterationCount = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x000a } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pSalt = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x000b } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pVerifier = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x000c } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_BootCount = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x000d } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_TotalOperationalHours = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x000f } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SerialNum = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0001 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceId = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0002 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceCert = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0003 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceICACerts = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0004 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDevicePrivateKey = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0005 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_HardwareVersion = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0006 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ManufacturingDate = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0007 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupPinCode = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0008 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupDiscriminator = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0009 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pIterationCount = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000a }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pSalt = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000b }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pVerifier = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000c }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LifeTimeCounter = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0010 }
};

// Keys stored in the Chip-counters namespace
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_BootCount = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipCounters, .subID = 0x000d }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_TotalOperationalHours = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipCounters, .subID = 0x000f }
};

// Keys stored in the Chip-config namespace
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceConfig = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x0012 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_PairedAccountId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x0013 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x0014 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LastUsedEpochKeyId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x0017 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FailSafeArmed = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x0018 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_WiFiStationSecType = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x0019 } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_RegulatoryLocation = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x001a } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_CountryCode = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x001b } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceConfig = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0012 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_PairedAccountId = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0013 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceId = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0014 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LastUsedEpochKeyId = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00017 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FailSafeArmed = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00018 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_WiFiStationSecType = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00019 }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_RegulatoryLocation = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001a }
};
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_CountryCode = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001b }
};
// itemID 0x001c is unused (used to be breadcrumb).
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_UniqueId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid,
.itemID = 0x001d } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_UniqueId = {
{ .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001d }
};

/* Internal for the KVS interface. */
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_key = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x001d } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_value = { { .systemID = kCC13X2_26X2ChipFactory_Sysid,
.itemID = 0x001e } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_key = { { .systemID = kCC13X2_26X2Matter_SysID,
.itemID = kCC13X2_26X2Matter_ItemID_ChipKVS_key } };
const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_value = { { .systemID = kCC13X2_26X2Matter_SysID,
.itemID = kCC13X2_26X2Matter_ItemID_ChipKVS_value } };

/* Static local variables */
static NVINTF_nvFuncts_t sNvoctpFps = { 0 };
Expand Down Expand Up @@ -389,43 +417,62 @@ CHIP_ERROR CC13X2_26X2Config::FactoryResetConfig(void)
NVINTF_nvProxy_t nvProxy = { 0 };
uint8_t status = NVINTF_SUCCESS;

// Delete items with the config, counter, kvs_key and kvs_value itemIDs. Items with the factory
// itemIDs are not deleted.

intptr_t key = sNvoctpFps.lockNV();

/* Setup doNext call */
nvProxy.sysid = kCC13X2_26X2ChipConfig_Sysid;
nvProxy.flag = NVINTF_DOSTART | NVINTF_DOSYSID | NVINTF_DODELETE;
nvProxy.sysid = kCC13X2_26X2Matter_SysID;
nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipConfig;
nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE;

/* Lock and wipe all items with sysid TIOP */
/* Lock and wipe all items with config itemid */
do
{
status = sNvoctpFps.doNext(&nvProxy);
} while (NVINTF_SUCCESS == status);
/* check we ran out of elements */
VerifyOrExit(status != NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);
VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

/* Setup doNext call. Sysid is the same here, but it doesn't necessarily have to be. Matching POSIX impl */
nvProxy.sysid = kCC13X2_26X2ChipFactory_Sysid;
nvProxy.flag = NVINTF_DOSTART | NVINTF_DOSYSID | NVINTF_DODELETE;
/* Setup doNext call */
nvProxy.sysid = kCC13X2_26X2Matter_SysID;
nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipCounters;
nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE;

/* Lock and wipe all items with sysid TIOP */
/* Lock and wipe all items with counters itemid */
do
{
status = sNvoctpFps.doNext(&nvProxy);
} while (NVINTF_SUCCESS == status);
/* check we ran out of elements */
VerifyOrExit(status != NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);
VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

/* Setup doNext call */
nvProxy.sysid = kCC13X2_26X2Matter_SysID;
nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipKVS_key;
nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE;

/* Setup doNext call. Sysid is the same here, but it doesn't necessarily have to be. Matching POSIX impl */
nvProxy.sysid = kCC13X2_26X2ChipCounters_Sysid;
nvProxy.flag = NVINTF_DOSTART | NVINTF_DOSYSID | NVINTF_DODELETE;
/* Lock and wipe all items with kvs_key itemid */
do
{
status = sNvoctpFps.doNext(&nvProxy);
} while (NVINTF_SUCCESS == status);
/* check we ran out of elements */
VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

/* Setup doNext call */
nvProxy.sysid = kCC13X2_26X2Matter_SysID;
nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipKVS_value;
nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE;

/* Lock and wipe all items with sysid TIOP */
/* Lock and wipe all items with key_value itemid */
do
{
status = sNvoctpFps.doNext(&nvProxy);
} while (NVINTF_SUCCESS == status);
/* check we ran out of elements */
VerifyOrExit(status != NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);
VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

exit:
sNvoctpFps.unlockNV(key);
Expand Down
19 changes: 15 additions & 4 deletions src/platform/cc13x2_26x2/CC13X2_26X2Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,21 @@ class CC13X2_26X2Config
struct Key;

// TODO: Define a proper system ID in upstream driver
static constexpr uint16_t kNvinf_sysid_chip = (13);
static constexpr uint16_t kNvinf_sysid_chip = 13;

static const uint16_t kCC13X2_26X2ChipConfig_Sysid = kNvinf_sysid_chip;
static const uint16_t kCC13X2_26X2ChipFactory_Sysid = kNvinf_sysid_chip;
static const uint16_t kCC13X2_26X2ChipCounters_Sysid = kNvinf_sysid_chip;
static constexpr uint16_t kNVinf_itemid_chipConfig = 1;
static constexpr uint16_t kNVinf_itemid_chipFactory = 2;
static constexpr uint16_t kNVinf_itemid_chipCounters = 3;
static constexpr uint16_t kNVinf_itemid_chipKVS_key = 4;
static constexpr uint16_t kNVinf_itemid_chipKVS_value = 5;

static const uint16_t kCC13X2_26X2Matter_SysID = kNvinf_sysid_chip;

static const uint16_t kCC13X2_26X2Matter_ItemID_ChipConfig = kNVinf_itemid_chipConfig;
static const uint16_t kCC13X2_26X2Matter_ItemID_ChipFactory = kNVinf_itemid_chipFactory;
static const uint16_t kCC13X2_26X2Matter_ItemID_ChipCounters = kNVinf_itemid_chipCounters;
static const uint16_t kCC13X2_26X2Matter_ItemID_ChipKVS_key = kNVinf_itemid_chipKVS_key;
static const uint16_t kCC13X2_26X2Matter_ItemID_ChipKVS_value = kNVinf_itemid_chipKVS_value;

// Key definitions for well-known keys.
static const Key kConfigKey_SerialNum;
Expand Down Expand Up @@ -70,6 +80,7 @@ class CC13X2_26X2Config
static const Key kConfigKey_Spake2pVerifier;
static const Key kConfigKey_BootCount;
static const Key kConfigKey_TotalOperationalHours;
static const Key kConfigKey_LifeTimeCounter;

static CHIP_ERROR Init(void);

Expand Down
Loading