From 57b81c22295121695fe64d55ddfc0c07da7d5ff1 Mon Sep 17 00:00:00 2001 From: abiradarti <104591549+abiradarti@users.noreply.github.com> Date: Mon, 6 Feb 2023 19:20:14 -0600 Subject: [PATCH] Add TI CC32XX to Github CI (#24806) * add TI CC32xx CI * Update README.md * Update README.md * Update README.md * update lock-app readme sysconfig version * fixed lock app example path in cc32xx.py * wrap dmm source set with cc13xx family check * added cc32xx as a platform for freertos submodule, added path to dnssd.h * trying again to add dnssd.h path * adding path to public deps * adding src to include path and taking out public dependency * trying to add dnssd lib as a dependency * saved from August * moved DNSSD Start Server call and CommonDeviceCallbacks into examples/lock-app/cc32xx, string library error appears during build * removed dnssd.h file include from connectivitymanagerimpl.cpp * moved commondevicecallbacks and chipdevicemanager into example src files in build.gn * added implementation for deviceeventcallback * removed DeviceCallbacks.cpp and .h and renamed CommonDeviceCallbacks.cpp and .h as DeviceCallbacks.cpp and .h * merge conflict resolution on targets.py * fixed build command for lock-app * added missing header in CC32XXConfig.cpp and corrected header in AppTask.cpp * updated cc32xx yaml file to have the correct docker img version * removed StartEventLoop Task so that CHIPDeviceManager can start it * added CC32xx DAC certs and code cleanup * removed CHIP-tool modification section in lock-app readme, not needed anymore * more code cleanup * forgot to add platform BUILD.gn to prev commit * added DAC instructions in lock-app readme * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Restyled by prettier-markdown * Restyled by autopep8 * misspell correction * correcting merge conflict resolution mistake and adding Accessors.h back as an include file to AppTask * corrected contents of testdata folder * code cleanup from PR feedback * removed brackets from lock in all_targets_linux_x64.txt * empty commit * increased job timeout limit --------- Co-authored-by: Restyled.io --- .github/workflows/examples-cc32xx.yaml | 89 ++++ .gitmodules | 2 +- README.md | 1 + examples/lock-app/cc32xx/BUILD.gn | 4 + examples/lock-app/cc32xx/README.md | 22 +- examples/lock-app/cc32xx/main/AppTask.cpp | 32 +- .../cc32xx/main/CHIPDeviceManager.cpp | 63 +++ .../lock-app/cc32xx/main/DeviceCallbacks.cpp | 45 ++ .../cc32xx/main/include/CHIPDeviceManager.h | 106 +++++ .../cc32xx/main/include/DeviceCallbacks.h | 40 ++ examples/platform/cc32xx/BUILD.gn | 20 + .../cc32xx/CC32XXDeviceAttestationCreds.cpp | 396 ++++++++++++++++++ .../cc32xx/CC32XXDeviceAttestationCreds.h | 36 ++ scripts/build/build/targets.py | 15 +- scripts/build/builders/cc32xx.py | 71 ++++ .../build/testdata/all_targets_linux_x64.txt | 1 + src/platform/cc32xx/BUILD.gn | 3 - src/platform/cc32xx/CC32XXConfig.cpp | 3 +- .../cc32xx/ConnectivityManagerImpl.cpp | 15 +- .../ti_simplelink_sdk/ti_simplelink_sdk.gni | 93 ++-- 20 files changed, 976 insertions(+), 81 deletions(-) create mode 100644 .github/workflows/examples-cc32xx.yaml create mode 100644 examples/lock-app/cc32xx/main/CHIPDeviceManager.cpp create mode 100644 examples/lock-app/cc32xx/main/DeviceCallbacks.cpp create mode 100644 examples/lock-app/cc32xx/main/include/CHIPDeviceManager.h create mode 100644 examples/lock-app/cc32xx/main/include/DeviceCallbacks.h create mode 100644 examples/platform/cc32xx/CC32XXDeviceAttestationCreds.cpp create mode 100644 examples/platform/cc32xx/CC32XXDeviceAttestationCreds.h create mode 100644 scripts/build/builders/cc32xx.py diff --git a/.github/workflows/examples-cc32xx.yaml b/.github/workflows/examples-cc32xx.yaml new file mode 100644 index 00000000000000..eb82b9c340d48f --- /dev/null +++ b/.github/workflows/examples-cc32xx.yaml @@ -0,0 +1,89 @@ +# Copyright (c) 2021 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. + +name: Build example - TI CC32XX + +on: + push: + pull_request: + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }} + cancel-in-progress: true + +jobs: + cc32xx: + name: cc32xx + timeout-minutes: 100 + + env: + BUILD_TYPE: gn_cc32xx + + runs-on: ubuntu-latest + if: github.actor != 'restyled-io[bot]' + + container: + image: connectedhomeip/chip-build-ti:0.6.34 + volumes: + - "/tmp/bloat_reports:/tmp/bloat_reports" + steps: + - uses: Wandalen/wretry.action@v1.0.15 + name: Checkout + with: + action: actions/checkout@v3 + with: | + token: ${{ github.token }} + attempt_limit: 3 + attempt_delay: 2000 + - name: Checkout submodules + run: scripts/checkout_submodules.py --shallow --platform cc32xx + - name: Set up environment for size reports + if: ${{ !env.ACT }} + env: + GH_CONTEXT: ${{ toJson(github) }} + run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}" + - name: Bootstrap + timeout-minutes: 25 + run: scripts/build/gn_bootstrap.sh + - name: Uploading bootstrap logs + uses: actions/upload-artifact@v2 + if: ${{ always() && !env.ACT }} + with: + name: bootstrap-logs + path: | + .environment/gn_out/.ninja_log + .environment/pigweed-venv/*.log + - name: Build examples + timeout-minutes: 60 + run: | + scripts/run_in_build_env.sh "\ + ./scripts/build/build_examples.py \ + --target cc32xx-lock build \ + --copy-artifacts-to out/artifacts \ + " + - name: Get lock app size stats + timeout-minutes: 5 + run: | + .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ + cc32xx CC3235SF_LAUNCHXL lock \ + out/artifacts/cc32xx-lock/chip-CC3235SF_LAUNCHXL-lock-example.out \ + /tmp/bloat_reports/ + + - name: Uploading Size Reports + uses: actions/upload-artifact@v2 + if: ${{ !env.ACT }} + with: + name: Size,cc32xx-Examples,${{ env.GH_EVENT_PR }},${{ env.GH_EVENT_HASH }},${{ env.GH_EVENT_PARENT }},${{ github.event_name }} + path: | + /tmp/bloat_reports/ diff --git a/.gitmodules b/.gitmodules index 048d1f48b7734b..a1b9865c8b3a17 100644 --- a/.gitmodules +++ b/.gitmodules @@ -58,7 +58,7 @@ path = third_party/freertos/repo url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git branch = V10.3.1-kernel-only - platforms = ameba,cc13x2_26x2,bouffalolab,efr32,esp32,k32w0,infineon,qpg + platforms = ameba,cc13x2_26x2,bouffalolab,efr32,esp32,k32w0,infineon,qpg,cc32xx [submodule "simw-top-mini"] path = third_party/simw-top-mini/repo url = https://github.com/NXP/plug-and-trust.git diff --git a/README.md b/README.md index 5a332bba03a711..5cee1dc72ded9a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ [![Examples - nRF Connect SDK](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20nRF%20Connect%20SDK/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-nrfconnect.yaml) [![Examples - QPG](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20QPG/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-qpg.yaml) [![Examples - TI CC26X2X7](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20TI%20CC26X2X7/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-cc13x2x7_26x2x7.yaml) +[![Examples - TI CC32XX](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20TI%20CC32XX/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-cc32xx.yaml) [![Build example - Infineon](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-infineon.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-infineon.yaml) [![Build example - BouffaloLab](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20BouffaloLab/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-bouffalolab.yaml) diff --git a/examples/lock-app/cc32xx/BUILD.gn b/examples/lock-app/cc32xx/BUILD.gn index d8fd3d4cceeef8..e1eb3041555d70 100755 --- a/examples/lock-app/cc32xx/BUILD.gn +++ b/examples/lock-app/cc32xx/BUILD.gn @@ -65,6 +65,7 @@ source_set("lock_app_sdk") { "${project_dir}/main", "${project_dir}/main/ifmod/", "${chip_root}/src/platform/cc32xx", + "${chip_root}/examples/platform/cc32xx", ] deps = [ @@ -83,7 +84,9 @@ ti_simplelink_executable("lock_app") { sources = [ "${project_dir}/main/AppTask.cpp", "${project_dir}/main/BoltLockManager.cpp", + "${project_dir}/main/CHIPDeviceManager.cpp", "${project_dir}/main/CXXExceptionStubs.cpp", + "${project_dir}/main/DeviceCallbacks.cpp", "${project_dir}/main/ZclCallbacks.cpp", ] @@ -92,6 +95,7 @@ ti_simplelink_executable("lock_app") { ":sdk", ":sysconfig", "${chip_root}/examples/lock-app/lock-common", + "${chip_root}/examples/platform/cc32xx:cc32xx-attestation-credentials", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", ] diff --git a/examples/lock-app/cc32xx/README.md b/examples/lock-app/cc32xx/README.md index 4cd77f6faeb235..b149a72388685a 100644 --- a/examples/lock-app/cc32xx/README.md +++ b/examples/lock-app/cc32xx/README.md @@ -58,9 +58,9 @@ guide assumes that the environment is linux based, and recommends Ubuntu 20.04. ``` $ cd ~ - $ wget https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.12.1_2446-setup.run - $ chmod +x sysconfig-1.12.1_2446-setup.run - $ ./sysconfig-1.12.1_2446-setup.run + $ wget https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.13.0_2553-setup.run + $ chmod +x sysconfig-1.13.0_2553-setup.run + $ ./sysconfig-1.13.0_2553-setup.run ``` - Run the bootstrap script to setup the build environment. @@ -85,17 +85,23 @@ Ninja to build the executable. - Run the build to produce a default executable. By default on Linux the Sysconfig is located in a `ti` folder in the user's home directory, and you must provide the absolute path for it. For example - `/home/username/ti/sysconfig_1.12.1`. On Windows the default directory is + `/home/username/ti/sysconfig_1.13.0`. On Windows the default directory is `C:\ti`. Take note of this install path, as it will be used in the next step. ``` $ cd ~/connectedhomeip/examples/lock-app/cc32xx - $ gn gen out/debug --args="ti_sysconfig_root=\"$HOME/ti/sysconfig_1.12.1\"" + $ gn gen out/debug --args="ti_sysconfig_root=\"$HOME/ti/sysconfig_1.13.0\"" $ ninja -C out/debug ``` +## Adding DAC Certificates + +To add custom DAC Certificates, the `CC32XXDeviceAttestationCreds.cpp` file in +`examples/platform/cc32xx` can be modified. The private key, public key, DAC +cert and PAI cert arrays all need to be replaced. + ## Programming Loading the built image onto a LaunchPad is supported through Code Composer @@ -160,12 +166,6 @@ the device is connected to the local AP, commissioning can be triggered using BLE provisioning is not supported currently. -### CHIP tool changes needed for Wi-Fi example - -The timeout for the CHIP tool needs to be increased from 10 to 15 seconds. This -can be done in `chip::System::Clock::Timeout GetWaitDuration` in -`connectedhomeip/examples/chip-tool/commands/clusters/ModelCommand.h` - ## TI Support For technical support, please consider creating a post on TI's [E2E forum][e2e]. diff --git a/examples/lock-app/cc32xx/main/AppTask.cpp b/examples/lock-app/cc32xx/main/AppTask.cpp index a556fee7514f3d..28c0675b8c717a 100644 --- a/examples/lock-app/cc32xx/main/AppTask.cpp +++ b/examples/lock-app/cc32xx/main/AppTask.cpp @@ -20,8 +20,9 @@ #include "AppTask.h" #include "AppConfig.h" #include "AppEvent.h" + #include -#include +#include #include #include @@ -29,7 +30,10 @@ #include #include +#include +#include +#include #include #include #include @@ -59,6 +63,7 @@ using namespace ::chip::System; using namespace ::chip::Credentials; using namespace ::chip::DeviceLayer; +using namespace ::chip::DeviceManager; static TaskHandle_t sAppTaskHandle; static QueueHandle_t sAppEventQueue; @@ -68,6 +73,8 @@ static Button_Handle gButtonRightHandle; AppTask AppTask::sAppTask; +static DeviceCallbacks EchoCallbacks; + int AppTask::StartAppTask() { int ret = 0; @@ -139,14 +146,6 @@ int AppTask::Init() while (true) ; } - PLAT_LOG("Start Event Loop Task"); - ret = PlatformMgr().StartEventLoopTask(); - if (ret != CHIP_NO_ERROR) - { - PLAT_LOG("PlatformMgr().StartEventLoopTask() failed"); - while (true) - ; - } // Init ZCL Data Model and start server PLAT_LOG("Initialize Server"); @@ -156,7 +155,12 @@ int AppTask::Init() // Initialize device attestation config PLAT_LOG("Initialize device attestation config"); +#ifdef CC32XX_ATTESTATION_CREDENTIALS + SetDeviceAttestationCredentialsProvider(CC32XX::GetCC32XXDacProvider()); +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif // Initialize BoltLock module PLAT_LOG("Initialize BoltLock"); @@ -170,6 +174,16 @@ int AppTask::Init() PLAT_LOG("Print Onboarding Codes"); PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kOnNetwork)); + PLAT_LOG("Start CHIPDeviceManager and Start Event Loop Task"); + CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); + ret = deviceMgr.Init(&EchoCallbacks); + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("CHIPDeviceManager::Init() failed: %s", ErrorStr(ret)); + while (1) + ; + } + return 0; } diff --git a/examples/lock-app/cc32xx/main/CHIPDeviceManager.cpp b/examples/lock-app/cc32xx/main/CHIPDeviceManager.cpp new file mode 100644 index 00000000000000..3ac2484808c9a5 --- /dev/null +++ b/examples/lock-app/cc32xx/main/CHIPDeviceManager.cpp @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2020 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. + */ + +/** + * @file + * This file implements the CHIP Device Interface that is used by + * applications to interact with the CHIP stack + * + */ + +#include + +#include "CHIPDeviceManager.h" + +using namespace ::chip; + +namespace chip { + +namespace DeviceManager { + +using namespace ::chip::DeviceLayer; + +void CHIPDeviceManager::DeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg) +{ + CHIPDeviceManagerCallbacks * cb = reinterpret_cast(arg); + if (cb != nullptr) + { + cb->DeviceEventCallback(event, reinterpret_cast(cb)); + } +} + +CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) +{ + mCB = cb; + + // Register a function to receive events from the CHIP device layer. Note that calls to + // this function will happen on the CHIP event loop thread, not the app_main thread. + PlatformMgr().AddEventHandler(CHIPDeviceManager::DeviceEventHandler, reinterpret_cast(cb)); + + // Start a task to run the CHIP Device event loop. + return PlatformMgr().StartEventLoopTask(); +} + +void CHIPDeviceManagerCallbacks::DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) {} + +CHIPDeviceManagerCallbacks::~CHIPDeviceManagerCallbacks() {} + +} // namespace DeviceManager +} // namespace chip diff --git a/examples/lock-app/cc32xx/main/DeviceCallbacks.cpp b/examples/lock-app/cc32xx/main/DeviceCallbacks.cpp new file mode 100644 index 00000000000000..70ed6234b100a5 --- /dev/null +++ b/examples/lock-app/cc32xx/main/DeviceCallbacks.cpp @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2022 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. + */ + +#include "DeviceCallbacks.h" +#include + +using namespace chip; +using namespace chip::DeviceLayer; +using namespace chip::System; + +DeviceCallbacksDelegate * appDelegate = nullptr; +extern "C" void cc32xxLog(const char * aFormat, ...); + +void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg) +{ + switch (event->Type) + { + case DeviceEventType::kInterfaceIpAddressChanged: + if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || + (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) + { + // MDNS server restart on any ip assignment: if link local ipv6 is configured, that + // will not trigger a 'internet connectivity change' as there is no internet + // connectivity. MDNS still wants to refresh its listening interfaces to include the + // newly selected address. + cc32xxLog("DeviceEventCallback:Start DNS Server"); + chip::app::DnssdServer::Instance().StartServer(); + } + } +} diff --git a/examples/lock-app/cc32xx/main/include/CHIPDeviceManager.h b/examples/lock-app/cc32xx/main/include/CHIPDeviceManager.h new file mode 100644 index 00000000000000..b3b7db5cd0eba0 --- /dev/null +++ b/examples/lock-app/cc32xx/main/include/CHIPDeviceManager.h @@ -0,0 +1,106 @@ +/* + * + * Copyright (c) 2020 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. + */ + +/** + * @file + * This file contains definitions for the CHIP DeviceManager Interface + * + * This object will co-ordinate multiple activities such as + * initialisation, rendezvous, session mgmt and other such + * activities within the CHIP stack. This is a singleton object. + */ + +#pragma once + +#include +#include +#include + +#include + +#include +#include + +namespace chip { +namespace DeviceManager { + +/** + * @brief + * This class provides a skeleton for all the callback functions. The functions will be + * called by other objects within the CHIP stack for specific events. + * Applications interested in receiving specific callbacks can specialize this class and handle + * these events in their implementation of this class. + */ +class DLL_EXPORT CHIPDeviceManagerCallbacks +{ +public: + /** + * @brief + * Called when CHIP Device events (PublicEventTypes) are triggered. + * + * @param event ChipDeviceEvent that occurred + * @param arg arguments specific to the event, if any + */ + virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + + virtual ~CHIPDeviceManagerCallbacks(); +}; + +/** + * @brief + * A common class that drives other components of the CHIP stack + */ +class DLL_EXPORT CHIPDeviceManager +{ +public: + CHIPDeviceManager(const CHIPDeviceManager &) = delete; + CHIPDeviceManager(const CHIPDeviceManager &&) = delete; + CHIPDeviceManager & operator=(const CHIPDeviceManager &) = delete; + + static CHIPDeviceManager & GetInstance() + { + static CHIPDeviceManager instance; + return instance; + } + + /** + * @brief + * Initialise CHIPDeviceManager + * + * @param cb Application's instance of the CHIPDeviceManagerCallbacks for consuming events + */ + CHIP_ERROR Init(CHIPDeviceManagerCallbacks * cb); + + /** + * @brief + * Fetch a pointer to the registered CHIPDeviceManagerCallbacks object. + * + */ + CHIPDeviceManagerCallbacks * GetCHIPDeviceManagerCallbacks() { return mCB; } + + /** + * Use internally for registration of the ChipDeviceEvents + */ + static void DeviceEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + +private: + CHIPDeviceManagerCallbacks * mCB = nullptr; + CHIPDeviceManager() {} +}; + +} // namespace DeviceManager +} // namespace chip diff --git a/examples/lock-app/cc32xx/main/include/DeviceCallbacks.h b/examples/lock-app/cc32xx/main/include/DeviceCallbacks.h new file mode 100644 index 00000000000000..97031703ebcf1b --- /dev/null +++ b/examples/lock-app/cc32xx/main/include/DeviceCallbacks.h @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2022 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. + */ +#pragma once + +#include +#include + +class DeviceCallbacks : public chip::DeviceManager::CHIPDeviceManagerCallbacks +{ +public: + void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); +}; + +class DeviceCallbacksDelegate +{ +public: + static DeviceCallbacksDelegate & Instance() + { + static DeviceCallbacksDelegate instance; + return instance; + } + DeviceCallbacksDelegate * mDelegate = nullptr; + void SetAppDelegate(DeviceCallbacksDelegate * delegate) { mDelegate = delegate; } + DeviceCallbacksDelegate * GetAppDelegate() { return mDelegate; } +}; diff --git a/examples/platform/cc32xx/BUILD.gn b/examples/platform/cc32xx/BUILD.gn index 031d054e190927..b026595b407641 100644 --- a/examples/platform/cc32xx/BUILD.gn +++ b/examples/platform/cc32xx/BUILD.gn @@ -17,3 +17,23 @@ import("//build_overrides/chip.gni") config("chip_examples_project_config") { include_dirs = [ "project_include" ] } + +config("attestation-credentials-config") { + include_dirs = [ "${chip_root}" ] + + defines = [ "CC32XX_ATTESTATION_CREDENTIALS" ] +} + +source_set("cc32xx-attestation-credentials") { + sources = [ + "CC32XXDeviceAttestationCreds.cpp", + "CC32XXDeviceAttestationCreds.h", + ] + + public_deps = [ + "${chip_root}/src/credentials", + "${chip_root}/src/platform:platform_base", + ] + + public_configs = [ ":attestation-credentials-config" ] +} diff --git a/examples/platform/cc32xx/CC32XXDeviceAttestationCreds.cpp b/examples/platform/cc32xx/CC32XXDeviceAttestationCreds.cpp new file mode 100644 index 00000000000000..ce0494a0e7b4c7 --- /dev/null +++ b/examples/platform/cc32xx/CC32XXDeviceAttestationCreds.cpp @@ -0,0 +1,396 @@ +/* + * + * 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. + */ +#include "CC32XXDeviceAttestationCreds.h" +#include +#include +#include +#include +#include +#include + +extern uint32_t __attestation_credentials_base; + +namespace chip { +namespace Credentials { +namespace CC32XX { + +namespace { + +extern "C" { + +typedef struct +{ + const uint32_t len; + uint8_t const * data; +} data_ptr; + +typedef struct +{ + data_ptr dac_priv_key; + data_ptr dac_pub_key; + data_ptr dac_cert; + data_ptr pai_cert; +} factoryData; + +#define LOCK 1 + +#if LOCK +#if 0 +const uint8_t gDacPrivKey[] = { + 0x50, 0x5a, 0x21, 0x1d, 0xbd, 0xa8, 0x71, 0x33, 0x0d, 0x63, 0x5d, 0xa3, 0xb0, 0x7e, 0xb1, + 0xc5, 0x08, 0x8a, 0x8f, 0xc7, 0x01, 0x24, 0xfb, 0xb3, 0x3e, 0x93, 0xd5, 0x06, 0x05, 0x82, + 0xc7, 0xc5, +}; +const uint8_t gDacPubKey[] = { + 0x04, 0xc5, 0x65, 0xfd, 0xad, 0xfd, 0x16, 0xdd, 0x62, 0xe4, 0x3f, 0x19, 0x60, 0xb9, 0x93, + 0xbb, 0x57, 0x2c, 0xfd, 0xd8, 0x1f, 0x6d, 0x71, 0x67, 0x67, 0x1b, 0x77, 0x45, 0xdc, 0xbe, + 0x6f, 0x65, 0xaf, 0x66, 0x5a, 0x1d, 0x93, 0x1c, 0x05, 0xb9, 0xf9, 0xa3, 0xe9, 0x45, 0x66, + 0x85, 0x60, 0x2c, 0x05, 0xc6, 0x96, 0x46, 0xb8, 0xf7, 0x59, 0x98, 0xdb, 0xaa, 0x68, 0x7a, + 0x5c, 0x56, 0x49, 0x02, 0xda, +}; +const uint8_t gDacCert[] = { + 0x30, 0x82, 0x01, 0xf7, 0x30, 0x82, 0x01, 0x9d, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x46, + 0x88, 0xeb, 0x94, 0xad, 0x32, 0xb2, 0xe4, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x04, 0x03, 0x02, 0x30, 0x4d, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, + 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x6d, 0x65, + 0x6e, 0x74, 0x20, 0x50, 0x41, 0x49, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, + 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, + 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, + 0x30, 0x36, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, 0x32, 0x33, + 0x34, 0x33, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, + 0x39, 0x35, 0x39, 0x5a, 0x30, 0x52, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, + 0x1b, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x20, 0x44, 0x41, 0x43, 0x20, 0x30, 0x30, 0x30, 0x30, 0x31, 0x14, 0x30, 0x12, + 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, + 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, + 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, 0x36, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, + 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, + 0x42, 0x00, 0x04, 0xc5, 0x65, 0xfd, 0xad, 0xfd, 0x16, 0xdd, 0x62, 0xe4, 0x3f, 0x19, 0x60, 0xb9, + 0x93, 0xbb, 0x57, 0x2c, 0xfd, 0xd8, 0x1f, 0x6d, 0x71, 0x67, 0x67, 0x1b, 0x77, 0x45, 0xdc, 0xbe, + 0x6f, 0x65, 0xaf, 0x66, 0x5a, 0x1d, 0x93, 0x1c, 0x05, 0xb9, 0xf9, 0xa3, 0xe9, 0x45, 0x66, 0x85, + 0x60, 0x2c, 0x05, 0xc6, 0x96, 0x46, 0xb8, 0xf7, 0x59, 0x98, 0xdb, 0xaa, 0x68, 0x7a, 0x5c, 0x56, + 0x49, 0x02, 0xda, 0xa3, 0x60, 0x30, 0x5e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, + 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, + 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, + 0x9b, 0x40, 0x60, 0x6f, 0x9e, 0x04, 0x7f, 0xb8, 0x60, 0x78, 0x8e, 0x3d, 0xc1, 0x12, 0xd7, 0x5e, + 0x87, 0x95, 0x77, 0x68, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, + 0x14, 0x43, 0x34, 0x57, 0x12, 0xba, 0x2c, 0x87, 0xef, 0x25, 0x49, 0x7b, 0x11, 0xd7, 0x98, 0x58, + 0x9b, 0x84, 0x35, 0x7f, 0x88, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, + 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, 0xb9, 0x28, 0xf9, 0x3e, 0xe3, 0x87, 0xef, + 0x3e, 0x00, 0x72, 0x88, 0x22, 0x84, 0xbd, 0x8a, 0xdd, 0x5c, 0xd6, 0xd0, 0x55, 0x81, 0xbf, 0xcc, + 0x55, 0x17, 0xcf, 0x9e, 0x9b, 0xcd, 0xd4, 0x37, 0xda, 0x02, 0x20, 0x10, 0x07, 0x9c, 0xcf, 0x7f, + 0x1f, 0x2d, 0xda, 0x46, 0xac, 0xe9, 0x67, 0xae, 0x5b, 0xe9, 0x66, 0xe7, 0xf2, 0x8a, 0xdf, 0xa0, + 0x28, 0xb8, 0xf8, 0x7f, 0x93, 0x9e, 0xd4, 0x15, 0x8d, 0xc0, 0xf8, +}; +#else +const uint8_t gDacPrivKey[] = { + 0x56, 0xdd, 0xea, 0x13, 0x80, 0xa1, 0x0f, 0x7e, 0x3d, 0xe0, 0xf2, 0xc5, 0x26, 0x1d, 0xb9, 0x98, + 0x72, 0xf0, 0xc1, 0x6c, 0x6e, 0x03, 0x2f, 0xc8, 0x01, 0x20, 0xe1, 0xcc, 0x20, 0x8f, 0x5f, 0x71, +}; +const uint8_t gDacPubKey[] = { + 0x04, 0x9d, 0x29, 0xc0, 0x89, 0x0d, 0x45, 0x5a, 0xfa, 0xfc, 0x57, 0x0a, 0x07, 0x17, 0xf8, 0xf6, 0xe0, + 0xc8, 0x3b, 0x5c, 0xff, 0x73, 0xe1, 0xd0, 0x0a, 0xfc, 0x65, 0x76, 0x84, 0x41, 0x78, 0xf7, 0xcf, 0x49, + 0x22, 0x42, 0x64, 0xb8, 0x17, 0x0d, 0x00, 0xcf, 0x9d, 0x15, 0x07, 0x55, 0x56, 0xe8, 0x42, 0xbe, 0xf9, + 0xd8, 0x37, 0x76, 0x64, 0xb2, 0xc8, 0x45, 0x29, 0xba, 0x11, 0xdd, 0xb3, 0x5f, 0x19, +}; +const uint8_t gDacCert[] = { + 0x30, 0x82, 0x01, 0xf7, 0x30, 0x82, 0x01, 0x9d, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x72, 0xbe, 0xbd, 0xfe, 0x0f, 0xa8, + 0x6f, 0x61, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x4d, 0x31, 0x1f, 0x30, 0x1d, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x20, 0x50, 0x41, 0x49, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, + 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, + 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, 0x36, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, + 0x32, 0x33, 0x34, 0x33, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, + 0x5a, 0x30, 0x52, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1b, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, + 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x44, 0x41, 0x43, 0x20, 0x30, 0x30, 0x30, 0x31, 0x31, + 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, 0x31, + 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, + 0x36, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x9d, 0x29, 0xc0, 0x89, 0x0d, 0x45, 0x5a, 0xfa, 0xfc, 0x57, 0x0a, 0x07, 0x17, 0xf8, + 0xf6, 0xe0, 0xc8, 0x3b, 0x5c, 0xff, 0x73, 0xe1, 0xd0, 0x0a, 0xfc, 0x65, 0x76, 0x84, 0x41, 0x78, 0xf7, 0xcf, 0x49, 0x22, 0x42, + 0x64, 0xb8, 0x17, 0x0d, 0x00, 0xcf, 0x9d, 0x15, 0x07, 0x55, 0x56, 0xe8, 0x42, 0xbe, 0xf9, 0xd8, 0x37, 0x76, 0x64, 0xb2, 0xc8, + 0x45, 0x29, 0xba, 0x11, 0xdd, 0xb3, 0x5f, 0x19, 0xa3, 0x60, 0x30, 0x5e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, + 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, + 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x03, 0xcc, 0x51, 0xfb, 0x25, 0x7c, 0x95, 0x0b, 0xbd, 0x62, + 0x20, 0xd6, 0xc1, 0xde, 0xdf, 0xa5, 0x22, 0x78, 0x44, 0xfb, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, + 0x80, 0x14, 0x43, 0x34, 0x57, 0x12, 0xba, 0x2c, 0x87, 0xef, 0x25, 0x49, 0x7b, 0x11, 0xd7, 0x98, 0x58, 0x9b, 0x84, 0x35, 0x7f, + 0x88, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, + 0xe3, 0xe0, 0x39, 0xef, 0x41, 0xe3, 0x8f, 0x58, 0xf0, 0xe4, 0x37, 0x00, 0xdf, 0x45, 0x9a, 0xe4, 0xb8, 0xf1, 0xb9, 0x70, 0x30, + 0x0c, 0xca, 0x43, 0x2a, 0x49, 0xd0, 0x50, 0xf0, 0xa3, 0x74, 0x65, 0x02, 0x20, 0x1c, 0x17, 0x8b, 0x93, 0xe9, 0xea, 0xb1, 0x7a, + 0xda, 0xe5, 0xe9, 0x95, 0x6f, 0xa2, 0xdc, 0x97, 0xcf, 0x21, 0x07, 0x81, 0x47, 0xf6, 0x75, 0x2c, 0x1f, 0x9d, 0xa5, 0xcb, 0xa4, + 0xaf, 0x98, 0x60, +}; +#endif +const uint8_t gPaiCert[] = { + 0x30, 0x82, 0x01, 0xdc, 0x30, 0x82, 0x01, 0x81, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x7f, 0x7e, 0xf3, 0xdb, 0x08, 0xa3, + 0x8f, 0x68, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x30, 0x31, 0x18, 0x30, 0x16, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x50, 0x41, 0x41, + 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, + 0x31, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, 0x32, 0x33, 0x34, 0x33, 0x5a, 0x18, 0x0f, 0x39, + 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x4d, 0x31, 0x1f, 0x30, 0x1d, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x20, 0x50, 0x41, 0x49, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, + 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, + 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, 0x36, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x42, 0x93, 0x55, 0x77, 0x35, 0x35, + 0x15, 0xce, 0xfa, 0x8f, 0x0e, 0x30, 0xe2, 0x34, 0x7e, 0x90, 0xee, 0xd6, 0xfd, 0x51, 0x5b, 0xe8, 0x82, 0xd1, 0xbc, 0xba, 0x74, + 0x83, 0xd7, 0xff, 0x6e, 0xf4, 0xde, 0xdf, 0x98, 0xf7, 0xf7, 0x4f, 0x17, 0x42, 0x1d, 0xe5, 0x45, 0x0c, 0xff, 0xfb, 0x3e, 0x7f, + 0x6d, 0x4f, 0x62, 0x28, 0x53, 0x41, 0x14, 0xfb, 0xb8, 0x5c, 0x2d, 0x52, 0xd1, 0x82, 0xb6, 0x6a, 0xa3, 0x66, 0x30, 0x64, 0x30, + 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x0e, + 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, + 0x04, 0x16, 0x04, 0x14, 0x43, 0x34, 0x57, 0x12, 0xba, 0x2c, 0x87, 0xef, 0x25, 0x49, 0x7b, 0x11, 0xd7, 0x98, 0x58, 0x9b, 0x84, + 0x35, 0x7f, 0x88, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x6a, 0xfd, 0x22, 0x77, 0x1f, + 0x51, 0x1f, 0xec, 0xbf, 0x16, 0x41, 0x97, 0x67, 0x10, 0xdc, 0xdc, 0x31, 0xa1, 0x71, 0x7e, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, + 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xff, 0x25, 0xf1, 0xd1, 0x54, 0xc3, 0x13, + 0x7e, 0x0e, 0x08, 0x6d, 0x82, 0xab, 0x0b, 0x11, 0xb5, 0x66, 0x18, 0x39, 0xb7, 0x12, 0xb1, 0x34, 0x2c, 0x6c, 0xde, 0x94, 0xfb, + 0xe3, 0x18, 0xa9, 0x2b, 0x02, 0x21, 0x00, 0x92, 0xe2, 0x81, 0xf9, 0x8a, 0x2f, 0xcc, 0x14, 0xcd, 0xf4, 0x07, 0x50, 0xd2, 0x80, + 0xd7, 0xdf, 0xea, 0x3f, 0x4d, 0xa4, 0x6f, 0x35, 0x7a, 0xfe, 0xac, 0xb8, 0x9b, 0x26, 0x77, 0x06, 0xd2, 0x8a, +}; + +#else +// pump +#if 0 +const uint8_t gDacPrivKey[] = { + 0x9c, 0x7c, 0x36, 0x37, 0x2f, 0x39, 0xe0, 0x6b, 0xf3, 0xbc, 0x6e, 0xc9, 0x11, 0xa1, 0x7f, + 0x38, 0x17, 0xa6, 0xff, 0x37, 0x08, 0xd7, 0x09, 0xd6, 0x32, 0x95, 0x3b, 0x24, 0xa0, 0xf7, + 0x7a, 0x9d, +}; +const uint8_t gDacPubKey[] = { + 0x04, 0x74, 0x60, 0x3f, 0xea, 0x01, 0xb3, 0x90, 0xf4, 0xad, 0xd4, 0x9f, 0xec, 0xc5, 0x20, + 0x20, 0xd2, 0x9f, 0x57, 0x7f, 0xe9, 0xc5, 0x53, 0x6d, 0x1f, 0x4b, 0x72, 0x37, 0xf5, 0xd8, + 0xff, 0x90, 0xff, 0xe8, 0x4e, 0x58, 0x4a, 0xd4, 0xde, 0x7f, 0x17, 0x9a, 0x52, 0x9a, 0xe9, + 0x12, 0x92, 0x51, 0x2c, 0x75, 0xd3, 0x25, 0xa9, 0x9e, 0x80, 0x56, 0x2d, 0x32, 0x1a, 0x36, + 0x6c, 0x9f, 0xfa, 0xe5, 0xd2, +}; +const uint8_t gDacCert[] = { + 0x30, 0x82, 0x01, 0xe9, 0x30, 0x82, 0x01, 0x8f, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x1c, + 0x45, 0x43, 0xa7, 0x37, 0x62, 0x09, 0x7c, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x04, 0x03, 0x02, 0x30, 0x46, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, + 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x50, 0x41, 0x49, 0x31, + 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, + 0x04, 0x46, 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, + 0x82, 0xa2, 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, 0x41, 0x30, 0x20, 0x17, 0x0d, 0x32, + 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, 0x32, 0x33, 0x34, 0x33, 0x5a, 0x18, 0x0f, 0x39, 0x39, + 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x4b, 0x31, + 0x1d, 0x30, 0x1b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x14, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, + 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x44, 0x41, 0x43, 0x20, 0x30, 0x30, 0x30, 0x30, 0x31, 0x14, + 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, + 0x46, 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, + 0xa2, 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, 0x41, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, + 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, + 0x07, 0x03, 0x42, 0x00, 0x04, 0x74, 0x60, 0x3f, 0xea, 0x01, 0xb3, 0x90, 0xf4, 0xad, 0xd4, 0x9f, + 0xec, 0xc5, 0x20, 0x20, 0xd2, 0x9f, 0x57, 0x7f, 0xe9, 0xc5, 0x53, 0x6d, 0x1f, 0x4b, 0x72, 0x37, + 0xf5, 0xd8, 0xff, 0x90, 0xff, 0xe8, 0x4e, 0x58, 0x4a, 0xd4, 0xde, 0x7f, 0x17, 0x9a, 0x52, 0x9a, + 0xe9, 0x12, 0x92, 0x51, 0x2c, 0x75, 0xd3, 0x25, 0xa9, 0x9e, 0x80, 0x56, 0x2d, 0x32, 0x1a, 0x36, + 0x6c, 0x9f, 0xfa, 0xe5, 0xd2, 0xa3, 0x60, 0x30, 0x5e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, + 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, + 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, + 0x04, 0x14, 0x12, 0x93, 0x39, 0xe3, 0xf4, 0x9b, 0xf6, 0x6e, 0x99, 0xb1, 0xef, 0xec, 0xad, 0xef, + 0x70, 0x73, 0x82, 0x93, 0xe1, 0x88, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, + 0x16, 0x80, 0x14, 0x64, 0xc1, 0x61, 0x97, 0xcb, 0xea, 0x15, 0xb9, 0x4d, 0xb4, 0xb0, 0x49, 0x2f, + 0x66, 0xce, 0x6a, 0x50, 0xaa, 0x51, 0x6a, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, 0xcd, 0x9d, 0xf2, 0x87, 0x89, + 0xd9, 0xfc, 0x3b, 0x70, 0x6c, 0xf0, 0x0e, 0xe0, 0x1c, 0xcb, 0x3c, 0x05, 0x90, 0x5e, 0xdb, 0xc3, + 0xda, 0xb3, 0x7e, 0x9d, 0x88, 0x57, 0xc3, 0x31, 0xb6, 0x95, 0x3c, 0x02, 0x20, 0x29, 0x75, 0x05, + 0x54, 0xdb, 0xba, 0xcb, 0xfa, 0xd2, 0xd1, 0xb2, 0x91, 0xda, 0x2b, 0x72, 0xdf, 0x84, 0xc1, 0xe9, + 0x3a, 0xf0, 0xb5, 0x78, 0xdc, 0x90, 0x14, 0xb7, 0x27, 0x97, 0xfd, 0xc4, 0x29, +}; +#else +const uint8_t gDacPrivKey[] = {}; +const uint8_t gDacPubKey[] = {}; +const uint8_t gDacCert[] = {}; +#endif +const uint8_t gPaiCert[] = { + 0x30, 0x82, 0x01, 0xd4, 0x30, 0x82, 0x01, 0x7a, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x66, 0xd2, 0xa2, 0xc8, 0xa1, 0x41, + 0x29, 0xd3, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x30, 0x31, 0x18, 0x30, 0x16, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x50, 0x41, 0x41, + 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, + 0x31, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, 0x32, 0x33, 0x34, 0x33, 0x5a, 0x18, 0x0f, 0x39, + 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x46, 0x31, 0x18, 0x30, 0x16, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x50, 0x41, 0x49, + 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, + 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, + 0x30, 0x41, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, + 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x09, 0x2c, 0x43, 0x97, 0xbe, 0x8f, 0xb7, 0xea, 0x29, 0xd9, 0x7c, 0x82, 0x94, + 0x42, 0xd6, 0x5a, 0x70, 0x33, 0x96, 0xee, 0xc4, 0xba, 0xc1, 0xc6, 0xd4, 0xd4, 0x25, 0x0e, 0xbc, 0x7d, 0xc4, 0x86, 0xb7, 0xe1, + 0xc0, 0x4a, 0xb9, 0x28, 0x79, 0x80, 0x9e, 0x20, 0x1b, 0x41, 0x85, 0x7e, 0xc3, 0xec, 0x0d, 0x39, 0xa0, 0x46, 0xc5, 0xf5, 0xf8, + 0x81, 0x52, 0x56, 0x84, 0xbb, 0x6c, 0x47, 0xed, 0x00, 0xa3, 0x66, 0x30, 0x64, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, + 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, + 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x64, 0xc1, 0x61, + 0x97, 0xcb, 0xea, 0x15, 0xb9, 0x4d, 0xb4, 0xb0, 0x49, 0x2f, 0x66, 0xce, 0x6a, 0x50, 0xaa, 0x51, 0x6a, 0x30, 0x1f, 0x06, 0x03, + 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x6a, 0xfd, 0x22, 0x77, 0x1f, 0x51, 0x1f, 0xec, 0xbf, 0x16, 0x41, 0x97, + 0x67, 0x10, 0xdc, 0xdc, 0x31, 0xa1, 0x71, 0x7e, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, + 0x48, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, 0x94, 0xc3, 0xfa, 0x48, 0xb3, 0xd0, 0x5d, 0x8c, 0x6a, 0x83, 0x5e, 0xe2, 0x13, 0xf5, + 0xda, 0xb0, 0x93, 0x07, 0xb3, 0xd2, 0x17, 0x7d, 0x5a, 0x4d, 0xfb, 0xf9, 0xef, 0xc5, 0xe0, 0x29, 0xbb, 0xad, 0x02, 0x20, 0x59, + 0x29, 0xb2, 0x32, 0xa1, 0x37, 0x56, 0xa4, 0xca, 0xda, 0x66, 0x7f, 0x42, 0x49, 0xfd, 0x82, 0x10, 0xec, 0xd3, 0x99, 0x0e, 0x89, + 0x9d, 0x52, 0x4a, 0x78, 0x4c, 0x82, 0x5c, 0xdd, 0x72, 0x5e, +}; + +#endif + +const factoryData gFactoryData = { + .dac_priv_key = { + .len = sizeof(gDacPrivKey), + .data = gDacPrivKey, + }, + .dac_pub_key = { + .len = sizeof(gDacPubKey), + .data = gDacPubKey, + }, + .dac_cert = { + .len = sizeof(gDacCert), + .data = gDacCert, + }, + .pai_cert = { + .len = sizeof(gPaiCert), + .data = gPaiCert, + }, +}; + +} // extern "C" + +// TODO: This should be moved to a method of P256Keypair +CHIP_ERROR LoadKeypairFromRaw(ByteSpan private_key, ByteSpan public_key, Crypto::P256Keypair & keypair) +{ + Crypto::P256SerializedKeypair serialized_keypair; + ReturnErrorOnFailure(serialized_keypair.SetLength(private_key.size() + public_key.size())); + memcpy(serialized_keypair.Bytes(), public_key.data(), public_key.size()); + memcpy(serialized_keypair.Bytes() + public_key.size(), private_key.data(), private_key.size()); + return keypair.Deserialize(serialized_keypair); +} + +class DeviceAttestationCredsCC32XX : public DeviceAttestationCredentialsProvider +{ + +public: + CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & out_buffer) override; + CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override; + CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & out_buffer) override; + CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & out_buffer) override; + CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, MutableByteSpan & out_buffer) override; + +private: + factoryData const * mFactoryData = &gFactoryData; +}; + +CHIP_ERROR DeviceAttestationCredsCC32XX::GetCertificationDeclaration(MutableByteSpan & out_buffer) +{ + //-> format_version = 1 + //-> vendor_id = 0xFFF1 + //-> product_id_array = [ 0x8000, 0x8001, 0x8002, 0x8003, 0x8004, 0x8005, 0x8006, 0x8007, 0x8008, 0x8009, 0x800A, 0x800B, + // 0x800C, 0x800D, 0x800E, 0x800F, 0x8010, 0x8011, 0x8012, 0x8013, 0x8014, 0x8015, 0x8016, 0x8017, 0x8018, 0x8019, 0x801A, + // 0x801B, 0x801C, 0x801D, 0x801E, 0x801F, 0x8020, 0x8021, 0x8022, 0x8023, 0x8024, 0x8025, 0x8026, 0x8027, 0x8028, 0x8029, + // 0x802A, 0x802B, 0x802C, 0x802D, 0x802E, 0x802F, 0x8030, 0x8031, 0x8032, 0x8033, 0x8034, 0x8035, 0x8036, 0x8037, 0x8038, + // 0x8039, 0x803A, 0x803B, 0x803C, 0x803D, 0x803E, 0x803F, 0x8040, 0x8041, 0x8042, 0x8043, 0x8044, 0x8045, 0x8046, 0x8047, + // 0x8048, 0x8049, 0x804A, 0x804B, 0x804C, 0x804D, 0x804E, 0x804F, 0x8050, 0x8051, 0x8052, 0x8053, 0x8054, 0x8055, 0x8056, + // 0x8057, 0x8058, 0x8059, 0x805A, 0x805B, 0x805C, 0x805D, 0x805E, 0x805F, 0x8060, 0x8061, 0x8062, 0x8063 ] + //-> device_type_id = 0x0016 + //-> certificate_id = "ZIG20142ZB330003-24" + //-> security_level = 0 + //-> security_information = 0 + //-> version_number = 0x2694 + //-> certification_type = 0 + //-> dac_origin_vendor_id is not present + //-> dac_origin_product_id is not present + const uint8_t kCdForAllExamples[] = { + 0x30, 0x82, 0x02, 0x19, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x02, 0x0a, 0x30, + 0x82, 0x02, 0x06, 0x02, 0x01, 0x03, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, + 0x01, 0x30, 0x82, 0x01, 0x71, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x01, 0x62, + 0x04, 0x82, 0x01, 0x5e, 0x15, 0x24, 0x00, 0x01, 0x25, 0x01, 0xf1, 0xff, 0x36, 0x02, 0x05, 0x00, 0x80, 0x05, 0x01, 0x80, + 0x05, 0x02, 0x80, 0x05, 0x03, 0x80, 0x05, 0x04, 0x80, 0x05, 0x05, 0x80, 0x05, 0x06, 0x80, 0x05, 0x07, 0x80, 0x05, 0x08, + 0x80, 0x05, 0x09, 0x80, 0x05, 0x0a, 0x80, 0x05, 0x0b, 0x80, 0x05, 0x0c, 0x80, 0x05, 0x0d, 0x80, 0x05, 0x0e, 0x80, 0x05, + 0x0f, 0x80, 0x05, 0x10, 0x80, 0x05, 0x11, 0x80, 0x05, 0x12, 0x80, 0x05, 0x13, 0x80, 0x05, 0x14, 0x80, 0x05, 0x15, 0x80, + 0x05, 0x16, 0x80, 0x05, 0x17, 0x80, 0x05, 0x18, 0x80, 0x05, 0x19, 0x80, 0x05, 0x1a, 0x80, 0x05, 0x1b, 0x80, 0x05, 0x1c, + 0x80, 0x05, 0x1d, 0x80, 0x05, 0x1e, 0x80, 0x05, 0x1f, 0x80, 0x05, 0x20, 0x80, 0x05, 0x21, 0x80, 0x05, 0x22, 0x80, 0x05, + 0x23, 0x80, 0x05, 0x24, 0x80, 0x05, 0x25, 0x80, 0x05, 0x26, 0x80, 0x05, 0x27, 0x80, 0x05, 0x28, 0x80, 0x05, 0x29, 0x80, + 0x05, 0x2a, 0x80, 0x05, 0x2b, 0x80, 0x05, 0x2c, 0x80, 0x05, 0x2d, 0x80, 0x05, 0x2e, 0x80, 0x05, 0x2f, 0x80, 0x05, 0x30, + 0x80, 0x05, 0x31, 0x80, 0x05, 0x32, 0x80, 0x05, 0x33, 0x80, 0x05, 0x34, 0x80, 0x05, 0x35, 0x80, 0x05, 0x36, 0x80, 0x05, + 0x37, 0x80, 0x05, 0x38, 0x80, 0x05, 0x39, 0x80, 0x05, 0x3a, 0x80, 0x05, 0x3b, 0x80, 0x05, 0x3c, 0x80, 0x05, 0x3d, 0x80, + 0x05, 0x3e, 0x80, 0x05, 0x3f, 0x80, 0x05, 0x40, 0x80, 0x05, 0x41, 0x80, 0x05, 0x42, 0x80, 0x05, 0x43, 0x80, 0x05, 0x44, + 0x80, 0x05, 0x45, 0x80, 0x05, 0x46, 0x80, 0x05, 0x47, 0x80, 0x05, 0x48, 0x80, 0x05, 0x49, 0x80, 0x05, 0x4a, 0x80, 0x05, + 0x4b, 0x80, 0x05, 0x4c, 0x80, 0x05, 0x4d, 0x80, 0x05, 0x4e, 0x80, 0x05, 0x4f, 0x80, 0x05, 0x50, 0x80, 0x05, 0x51, 0x80, + 0x05, 0x52, 0x80, 0x05, 0x53, 0x80, 0x05, 0x54, 0x80, 0x05, 0x55, 0x80, 0x05, 0x56, 0x80, 0x05, 0x57, 0x80, 0x05, 0x58, + 0x80, 0x05, 0x59, 0x80, 0x05, 0x5a, 0x80, 0x05, 0x5b, 0x80, 0x05, 0x5c, 0x80, 0x05, 0x5d, 0x80, 0x05, 0x5e, 0x80, 0x05, + 0x5f, 0x80, 0x05, 0x60, 0x80, 0x05, 0x61, 0x80, 0x05, 0x62, 0x80, 0x05, 0x63, 0x80, 0x18, 0x24, 0x03, 0x16, 0x2c, 0x04, + 0x13, 0x5a, 0x49, 0x47, 0x32, 0x30, 0x31, 0x34, 0x32, 0x5a, 0x42, 0x33, 0x33, 0x30, 0x30, 0x30, 0x33, 0x2d, 0x32, 0x34, + 0x24, 0x05, 0x00, 0x24, 0x06, 0x00, 0x25, 0x07, 0x94, 0x26, 0x24, 0x08, 0x00, 0x18, 0x31, 0x7d, 0x30, 0x7b, 0x02, 0x01, + 0x03, 0x80, 0x14, 0x62, 0xfa, 0x82, 0x33, 0x59, 0xac, 0xfa, 0xa9, 0x96, 0x3e, 0x1c, 0xfa, 0x14, 0x0a, 0xdd, 0xf5, 0x04, + 0xf3, 0x71, 0x60, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x0a, 0x06, 0x08, + 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x04, 0x47, 0x30, 0x45, 0x02, 0x20, 0x24, 0xe5, 0xd1, 0xf4, 0x7a, 0x7d, + 0x7b, 0x0d, 0x20, 0x6a, 0x26, 0xef, 0x69, 0x9b, 0x7c, 0x97, 0x57, 0xb7, 0x2d, 0x46, 0x90, 0x89, 0xde, 0x31, 0x92, 0xe6, + 0x78, 0xc7, 0x45, 0xe7, 0xf6, 0x0c, 0x02, 0x21, 0x00, 0xf8, 0xaa, 0x2f, 0xa7, 0x11, 0xfc, 0xb7, 0x9b, 0x97, 0xe3, 0x97, + 0xce, 0xda, 0x66, 0x7b, 0xae, 0x46, 0x4e, 0x2b, 0xd3, 0xff, 0xdf, 0xc3, 0xcc, 0xed, 0x7a, 0xa8, 0xca, 0x5f, 0x4c, 0x1a, + 0x7c, + }; + + return CopySpanToMutableSpan(ByteSpan{ kCdForAllExamples }, out_buffer); +} + +CHIP_ERROR DeviceAttestationCredsCC32XX::GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) +{ + out_firmware_info_buffer.reduce_size(0); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DeviceAttestationCredsCC32XX::GetDeviceAttestationCert(MutableByteSpan & out_buffer) +{ + ReturnErrorCodeIf(out_buffer.size() < mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + + return CopySpanToMutableSpan(ByteSpan{ mFactoryData->dac_cert.data, mFactoryData->dac_cert.len }, out_buffer); + return CHIP_NO_ERROR; +} + +CHIP_ERROR DeviceAttestationCredsCC32XX::GetProductAttestationIntermediateCert(MutableByteSpan & out_buffer) +{ + ReturnErrorCodeIf(out_buffer.size() < mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + + return CopySpanToMutableSpan(ByteSpan{ mFactoryData->pai_cert.data, mFactoryData->pai_cert.len }, out_buffer); +} + +CHIP_ERROR DeviceAttestationCredsCC32XX::SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, + MutableByteSpan & out_buffer) +{ + Crypto::P256ECDSASignature signature; + Crypto::P256Keypair keypair; + + VerifyOrReturnError(IsSpanUsable(out_buffer), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(out_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL); + + // In a non-exemplary implementation, the public key is not needed here. It is used here merely because + // Crypto::P256Keypair is only (currently) constructable from raw keys if both private/public keys are present. + ReturnErrorOnFailure(LoadKeypairFromRaw(ByteSpan(mFactoryData->dac_priv_key.data, mFactoryData->dac_priv_key.len), + ByteSpan(mFactoryData->dac_pub_key.data, mFactoryData->dac_pub_key.len), keypair)); + ReturnErrorOnFailure(keypair.ECDSA_sign_msg(message_to_sign.data(), message_to_sign.size(), signature)); + + return CopySpanToMutableSpan(ByteSpan{ signature.ConstBytes(), signature.Length() }, out_buffer); +} + +} // namespace + +DeviceAttestationCredentialsProvider * GetCC32XXDacProvider() +{ + static DeviceAttestationCredsCC32XX dac_provider; + return &dac_provider; +} + +} // namespace CC32XX +} // namespace Credentials +} // namespace chip diff --git a/examples/platform/cc32xx/CC32XXDeviceAttestationCreds.h b/examples/platform/cc32xx/CC32XXDeviceAttestationCreds.h new file mode 100644 index 00000000000000..744f1c205e0f47 --- /dev/null +++ b/examples/platform/cc32xx/CC32XXDeviceAttestationCreds.h @@ -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 + +namespace chip { +namespace Credentials { +namespace CC32XX { + +/** + * @brief Get implementation of a sample DAC provider to validate device + * attestation procedure. + * + * @returns a singleton DeviceAttestationCredentialsProvider that relies on no + * storage abstractions. + */ +DeviceAttestationCredentialsProvider * GetCC32XXDacProvider(); + +} // namespace CC32XX +} // namespace Credentials +} // namespace chip diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index ef8d863e727d4e..c9ebdfc00728a9 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -21,6 +21,7 @@ from builders.android import AndroidApp, AndroidBoard, AndroidBuilder from builders.bouffalolab import BouffalolabApp, BouffalolabBoard, BouffalolabBuilder from builders.cc13x2x7_26x2x7 import cc13x2x7_26x2x7App, cc13x2x7_26x2x7Builder +from builders.cc32xx import cc32xxApp, cc32xxBuilder from builders.cyw30739 import Cyw30739App, Cyw30739Board, Cyw30739Builder from builders.efr32 import Efr32App, Efr32Board, Efr32Builder from builders.esp32 import Esp32App, Esp32Board, Esp32Builder @@ -403,9 +404,20 @@ def Buildcc13x2x7_26x2x7Target(): return target +def Buildcc32xxTarget(): + target = BuildTarget('cc32xx', cc32xxBuilder) + + # apps + target.AppendFixedTargets([ + TargetPart('lock', app=cc32xxApp.LOCK), + + ]) + + return target + + def BuildCyw30739Target(): target = BuildTarget('cyw30739', Cyw30739Builder) - # board target.AppendFixedTargets([ TargetPart('cyw930739m2evb_01', board=Cyw30739Board.CYW930739M2EVB_01), @@ -553,6 +565,7 @@ def BuildOpenIotSdkTargets(): BuildAndroidTarget(), BuildBouffalolabTarget(), Buildcc13x2x7_26x2x7Target(), + Buildcc32xxTarget(), BuildCyw30739Target(), BuildEfr32Target(), BuildEsp32Target(), diff --git a/scripts/build/builders/cc32xx.py b/scripts/build/builders/cc32xx.py new file mode 100644 index 00000000000000..7685b6a66af0fd --- /dev/null +++ b/scripts/build/builders/cc32xx.py @@ -0,0 +1,71 @@ +# Copyright (c) 2021 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. + +import os +from enum import Enum, auto + +from .gn import GnBuilder + + +class cc32xxApp(Enum): + LOCK = auto() + + def ExampleName(self): + if self == cc32xxApp.LOCK: + return 'lock-app' + else: + raise Exception('Unknown app type: %r' % self) + + def AppNamePrefix(self): + if self == cc32xxApp.LOCK: + return 'chip-CC3235SF_LAUNCHXL-lock-example' + else: + raise Exception('Unknown app type: %r' % self) + + def BuildRoot(self, root): + return os.path.join(root, 'examples', self.ExampleName(), 'cc32xx') + + +class cc32xxBuilder(GnBuilder): + + def __init__(self, + root, + runner, + app: cc32xxApp = cc32xxApp.LOCK): + super(cc32xxBuilder, self).__init__( + root=app.BuildRoot(root), + runner=runner) + self.code_root = root + self.app = app + + def GnBuildArgs(self): + args = [ + 'ti_sysconfig_root="%s"' % os.environ['TI_SYSCONFIG_ROOT'], + ] + + return args + + def build_outputs(self): + items = {} + if (self.app == cc32xxApp.LOCK): + extensions = [".out", ".bin", ".out.map"] + + else: + raise Exception('Unknown app type: %r' % self.app) + + for extension in extensions: + name = '%s%s' % (self.app.AppNamePrefix(), extension) + items[name] = os.path.join(self.output_dir, name) + + return items diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 015f917dac3200..f6cdca0035930a 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -2,6 +2,7 @@ ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed} 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} bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light}-light[-shell][-115200][-rpc] cc13x2x7_26x2x7-{all-clusters,all-clusters-minimal,lock,pump,pump-controller,shell}[-ftd][-mtd] +cc32xx-lock cyw30739-cyw930739m2evb_01-{light,lock,ota-requestor}[-no-progress-logging] efr32-{brd4161a,brd4187c,brd4163a,brd4164a,brd4166a,brd4170a,brd4186a,brd4187a,brd4304a}-{window-covering,switch,unit-test,light,lock}[-rpc][-with-ota-requestor][-sed][-low-power][-shell][-no_logging][-openthread_mtd][-enable_heap_monitoring][-no_openthread_cli][-show_qr_code][-wifi][-rs911x][-wf200][-wifi_ipv4][-additional_data_advertising][-use_ot_lib][-use_ot_coap_lib][-no-version] esp32-{m5stack,c3devkit,devkitc,qemu}-{all-clusters,all-clusters-minimal,ota-provider,ota-requestor,shell,light,lock,bridge,temperature-measurement,ota-requestor,tests}[-rpc][-ipv6only] diff --git a/src/platform/cc32xx/BUILD.gn b/src/platform/cc32xx/BUILD.gn index ab82558b3a82f9..6dfa080ee610e1 100644 --- a/src/platform/cc32xx/BUILD.gn +++ b/src/platform/cc32xx/BUILD.gn @@ -44,9 +44,6 @@ static_library("cc32xx") { "SystemPlatformConfig.h", ] - include_dirs = [ "ifmod/" ] - deps = [] - public_deps = [ "${chip_root}/src/crypto", "${chip_root}/src/platform:platform_base", diff --git a/src/platform/cc32xx/CC32XXConfig.cpp b/src/platform/cc32xx/CC32XXConfig.cpp index db570f732cd503..ad0e52ce5571c0 100644 --- a/src/platform/cc32xx/CC32XXConfig.cpp +++ b/src/platform/cc32xx/CC32XXConfig.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -322,7 +323,7 @@ CC32XXKVSList * pList; CHIP_ERROR CC32XXConfig::Init() { - cc32xxLog("[%s], KVS List created", __FUNCTION__); + cc32xxLog("[CC32XXConfig::Init] KVS List created"); pList = new CC32XXKVSList(); ReadKVSFromNV(); return CHIP_NO_ERROR; diff --git a/src/platform/cc32xx/ConnectivityManagerImpl.cpp b/src/platform/cc32xx/ConnectivityManagerImpl.cpp index f9e5dc12e2ffd1..c42bfb426a55e0 100644 --- a/src/platform/cc32xx/ConnectivityManagerImpl.cpp +++ b/src/platform/cc32xx/ConnectivityManagerImpl.cpp @@ -37,7 +37,6 @@ #include -#include #include #include #include @@ -170,16 +169,8 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) if (event->Type == DeviceLayer::DeviceEventType::kCommissioningComplete) { - // if (event->CommissioningComplete.Status == CHIP_NO_ERROR) - // { ChipLogProgress(AppServer, "Commissioning completed successfully"); DeviceLayer::Internal::CC32XXConfig::WriteKVSToNV(); - // } - // else - // { - // ChipLogError(AppServer, "Commissioning failed with error %" CHIP_ERROR_FORMAT, - // event->CommissioningComplete.Status.Format()); - // } } } @@ -199,6 +190,7 @@ void ConnectivityManagerImpl::_OnLwipEvent(struct netif * pNetIf, NetIfStatus_e { case E_NETIF_STATUS_IP_ACQUIRED: PlatformMgr().ScheduleWork(_OnIpAcquired); + cc32xxLog("ConnectivityManagerImpl::OnLwipEvent() : Scheduled OnIpAcquired"); break; default: break; @@ -208,7 +200,10 @@ void ConnectivityManagerImpl::_OnLwipEvent(struct netif * pNetIf, NetIfStatus_e void ConnectivityManagerImpl::_OnIpAcquired(intptr_t arg) { cc32xxLog("ConnectivityManagerImpl::OnIpAcquired() : Start DNS Server"); - chip::app::DnssdServer::Instance().StartServer(); + ChipDeviceEvent event; + event.Type = DeviceEventType::kInterfaceIpAddressChanged; + event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV4_Assigned; + PlatformMgr().PostEventOrDie(&event); } void ConnectivityManagerImpl::OnStationConnected() diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni index 3613a0bb6b6fe7..dfbdb5f841bc87 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni @@ -456,56 +456,59 @@ template("ti_simplelink_sdk") { } source_set("${sdk_target_name}_dmm") { - defines = [] - include_dirs = [ - "${chip_root}/third_party/openthread/repo/include/", - "${chip_root}/src/", - ] - configs -= - [ "${build_root}/config/compiler:warnings_default" ] # removed for - # -Wshadow + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + defines = [] + include_dirs = [ + "${chip_root}/third_party/openthread/repo/include/", + "${chip_root}/src/", + ] + configs -= + [ "${build_root}/config/compiler:warnings_default" ] # removed for + # -Wshadow - cflags = [ - "-Wno-sign-compare", - "-Wno-unused-variable", - "-Wno-implicit-function-declaration", # asm not defined - ] + cflags = [ + "-Wno-sign-compare", + "-Wno-unused-variable", + "-Wno-implicit-function-declaration", # asm not defined + ] - sources = [ - "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/TI_heap_wrapper.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/bget.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/rcosc/rcosc_calibration.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/host/gatt_uuid.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/host/gattservapp_util.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/app/icall_api_lite.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/icall_cc2650.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/icall_user_config.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/stack/ble_user_config_stack.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/profiles/dev_info/cc26xx/devinfoservice.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/rom/agama_r1/rom_init.c", - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/ble_remote_display/stack/osal_icall_ble.c", - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/icall_FreeRTOS.c", - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/util.c", - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/source/activity/dmm_thread_activity.c", - "${ti_simplelink_sdk_root}/source/ti/dmm/dmm_priority_ble_thread.c", - - # Move this into the SDK - "${chip_root}/src/platform/cc13x2_26x2/ble_user_config.c", - "${chip_root}/src/platform/cc13x2_26x2/chipOBleProfile.c", - ] + sources = [ + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/TI_heap_wrapper.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/bget.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/rcosc/rcosc_calibration.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/host/gatt_uuid.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/host/gattservapp_util.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/app/icall_api_lite.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/icall_cc2650.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/icall_user_config.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/stack/ble_user_config_stack.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/profiles/dev_info/cc26xx/devinfoservice.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/rom/agama_r1/rom_init.c", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/ble_remote_display/stack/osal_icall_ble.c", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/icall_FreeRTOS.c", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/util.c", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/source/activity/dmm_thread_activity.c", + "${ti_simplelink_sdk_root}/source/ti/dmm/dmm_priority_ble_thread.c", + + # Move this into the SDK + "${chip_root}/src/platform/cc13x2_26x2/ble_user_config.c", + "${chip_root}/src/platform/cc13x2_26x2/chipOBleProfile.c", + ] - configs -= [ "${build_root}/config/compiler:std_default" ] - configs += [ ":${sdk_target_name}_posix_config" ] + configs -= [ "${build_root}/config/compiler:std_default" ] + configs += [ ":${sdk_target_name}_posix_config" ] - public_deps = [ - "${chip_root}/third_party/ti_simplelink_sdk:freertos", - "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig", - ] + public_deps = [ + "${chip_root}/third_party/ti_simplelink_sdk:freertos", + "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig", + ] - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_dmm_config", - ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_dmm_config", + ] + } } group(sdk_target_name) {