diff --git a/docs/guides/images/matter_ti_overview_simplified.png b/docs/guides/images/matter_ti_overview_simplified.png new file mode 100755 index 00000000000000..2586fa41fdd97a Binary files /dev/null and b/docs/guides/images/matter_ti_overview_simplified.png differ diff --git a/docs/guides/ti_platform_overview.md b/docs/guides/ti_platform_overview.md new file mode 100644 index 00000000000000..37a8e065232810 --- /dev/null +++ b/docs/guides/ti_platform_overview.md @@ -0,0 +1,121 @@ +# Texas Instruments platform overview + +The TI platform is a [Matter][matter_gh] platform based on the Texas Instruments +Incorporated SimpleLink SDK. + +The following diagram is a simplified representation of a Matter application +which built on the TI Platform. + +

+ matter_ti_overview_simplified +

+ +## Texas Instruments SimpleLink SDK + +The SimpleLink™ CC13xx and CC26xx Software Development Kit (SDK) delivers +components that enable engineers to develop applications on the Texas +Instruments SimpleLink CC13xx and CC26xx family of wireless microcontrollers +(MCUs). This software toolkit provides a cohesive and consistent software +experience for all SimpleLink CC13xx and CC26xx wireless MCU users by packaging +essential software components, such as a Bluetooth® Low Energy (BLE) protocol +stack supporting Bluetooth 5.2, Bluetooth Mesh, Thread 1.1.1 networking stack +based on OpenThread, Zigbee 3.0 compliant protocol suite, RF-Proprietary +examples, TI’s 15.4 Stack as well as the TI-RTOS kernel and TI Drivers in one +easy-to-use software package along with example applications and documentation. +In addition, the Dynamic Multi-Protocol Manager (DMM) software component enables +multiprotocol development on a single SimpleLink wireless MCU through +time-division multiplexing. + +The SimpleLink MCU portfolio offers a single development environment that +delivers flexible hardware, software, and tool options for customers developing +wired and wireless applications. With 100 percent code reuse across host MCUs, +Wi-Fi™, Bluetooth Low Energy, Sub-1GHz devices and more, choose the MCU or +connectivity standard that fits your design. A one-time investment with the +SimpleLink software development kit allows you to reuse often, opening the door +to create unlimited applications. For more information, visit +www.ti.com/simplelink. + +
+ +## BLE and Thread stacks + +In the TI example applications the Bluetooth Low Energy protocol is used to +provision the Thread protocol to enable Matter communication. Then Thread is +used for IP communication with other Matter devices. + +The TI applications leverage the Bluetooth Low Energy stack on the CC13X2 and +CC26X2 families. This BLE software is distributed in binary form within the TI +SimpleLink SDK. The BLE stack leverages code that is present in the device ROM +for certain common BLE operations. + +These applications leverage the OpenThread stack available within the Matter +repository for Thread communication. Platform support source is built from the +SimpleLink SDK. + +These connection protocols can be run concurrently by using the Texas +Instruments Dynamic Multi-protocol Manager. + +
+ +## LwIP stack + +The Lightweight IP stack interfaces with the OpenThread stack to offer standard +IP connectivity protocols that OpenThread does not natively support. This offers +a standard socket based interface to the Matter platform. + +
+ +## MbedTLS + +The MbedTLS library is used by OpenThread and Matter for a wide variety of +protocols. This ranges from basic AES and SHA to cryptographic protocols like +ECDSA and ECDH. + +The MbedTLS library is hardware accelerated using the TI SimpleLink SDK drivers. +This is achieved through the usage of `_ALT` defines in the MbedTLS +configuration file. + +
+ +## Matter integration + +Matter interacts with LwIP, OpenThread, and the TI BLE stack to achieve the +protocol and application functionality. A BLE profile is registered with the +TI-BLE stack to enable provisioning and configuration. Once the device is +provisioned Matter will configure the OpenThread interface to connect to an +existing Thread network or to start its own network. From there the Matter IP +messages are sent to the LwIP stack to be routed to the OpenThread stack for +transmission. + +Overall, applications generally only need to interface with the Cluster Library +from Matter. The transport of messages and configuration of the device is all +handled by the platform implementation files. + +
+ +# Matter example applications + +Sample Matter applications are provided for the TI platform. These can be used +as reference for your own application. + +- [lock-app](../../examples/lock-app/cc13x2x7_26x2x7/README.md) +- [pump-app](../../examples/pump-app/cc13x2x7_26x2x7/README.md) +- [pump-controller-app](../../examples/pump-controller-app/cc13x2x7_26x2x7/README.md) + +
+ +## Build system + +The TI platform uses GN to generate ninja build scripts. Build files have +already been written to build and link the TI specific code within the +SimpleLink SDK. + +
+ +## TI Support + +For technical support, please consider creating a post on TI's [E2E forum][e2e]. +Additionally, we welcome any feedback. + +[e2e]: https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread +[matter_gh]: https://github.com/project-chip/connectedhomeip diff --git a/examples/lock-app/cc13x2x7_26x2x7/README.md b/examples/lock-app/cc13x2x7_26x2x7/README.md index 857dc6bf552159..d2c14aa666cc18 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/README.md +++ b/examples/lock-app/cc13x2x7_26x2x7/README.md @@ -1,11 +1,11 @@ -# CHIP CC1352 CC2652 Lock Example Application +# Matter CC1352 CC2652 Lock Example Application -An example application showing the use [CHIP][chip] on the Texas Instruments -CC13X2_26X2 family of Wireless MCUs. +An example application showing the use of [Matter][matter] on the Texas +Instruments CC13X2_26X2 family of Wireless MCUs. --- -- [CHIP CC1352 CC2652 Lock Example Application](#chip-cc1352-cc2652-lock-example-application) +- [Matter CC1352 CC2652 Lock Example Application](#matter-cc1352-cc2652-lock-example-application) - [Introduction](#introduction) - [Device UI](#device-ui) - [Building](#building) @@ -19,7 +19,7 @@ CC13X2_26X2 family of Wireless MCUs. - [Provisioning](#provisioning) - [Bluetooth LE Advertising](#bluetooth-le-advertising) - [Bluetooth LE Rendezvous](#bluetooth-le-rendezvous) - - [CHIP Remote Commands](#chip-remote-commands) + - [Matter Remote Commands](#matter-remote-commands) - [TI Support](#ti-support) --- @@ -29,16 +29,16 @@ CC13X2_26X2 family of Wireless MCUs. ![CC1352R1_LAUNCHXL](doc/images/cc1352r1_launchxl.jpg) The CC13X2_26X2 lock example application provides a working demonstration of a -connected door lock device. This uses the open-source CHIP implementation and +connected door lock device. This uses the open-source Matter implementation and the Texas Instruments SimpleLink™ CC13x2 and CC26x2 software development kit. This example is enabled to build for CC2652R7 devices. This upcoming devices are currently not yet in full production. For more information on device -availability or early access to an engineering build of our CHIP-enabled SDK, -please reach out [here][ti_cc13x2_26x2_r7_chip_request]. +availability or early access to an engineering build of our Matter-enabled SDK, +please reach out [here][ti_cc13x2_26x2_r7_matter_request]. The lock example is intended to serve both as a means to explore the workings of -CHIP, as well as a template for creating real products based on the Texas +Matter, as well as a template for creating real products based on the Texas Instruments devices. ## Device UI @@ -66,7 +66,7 @@ section will need to be done when migrating to new versions of the SDK. This guide assumes that the environment is linux based, and recommends Ubuntu 20.04. - An engineering SDK from TI is required. Please request access for it - [here][ti_cc13x2_26x2_r7_chip_request]. + [here][ti_cc13x2_26x2_r7_matter_request]. - Follow the default installation instructions when executing the installer. @@ -152,15 +152,15 @@ Ninja to build the executable. - Run the build to produce a default executable. By default on Linux both the TI SimpleLink SDK and Sysconfig are located in a `ti` folder in the user's home directory, and you must provide the absolute path to them. For example - `/home/username/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng` and - `/home/username/ti/sysconfig_1.7.0`. On Windows the default directory is + `/home/username/ti/simplelink_cc13xx_cc26xx_sdk_5_30_03_01_eng` and + `/home/username/ti/sysconfig_1.10.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/cc13x2x7_26x2x7 - $ export TI_SIMPLELINK_SDK_ROOT=$HOME/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng - $ export TI_SYSCONFIG_ROOT=$HOME/ti/sysconfig_1.7.0 + $ export TI_SIMPLELINK_SDK_ROOT=$HOME/ti/simplelink_cc13xx_cc26xx_sdk_5_30_03_01_eng + $ export TI_SYSCONFIG_ROOT=$HOME/ti/sysconfig_1.10.0 $ gn gen out/debug --args="ti_simplelink_sdk_root=\"${TI_SIMPLELINK_SDK_ROOT}\" ti_sysconfig_root=\"${TI_SYSCONFIG_ROOT}\"" $ ninja -C out/debug @@ -252,8 +252,8 @@ Router][ot_border_router_setup]. ### Provisioning -The first step to bring the CHIP device onto the network is to provision it. Our -example accomplishes this with Bluetooth Low Energy (BLE) and the +The first step to bring the Matter device onto the network is to provision it. +Our example accomplishes this with Bluetooth Low Energy (BLE) and the [CHIPTool](../../../src/android/CHIPTool/README.md) mobile app. #### Bluetooth LE Advertising @@ -265,9 +265,9 @@ fully provisioned, BLE advertising will stop. #### Bluetooth LE Rendezvous -To commission and control this application within a CHIP-enabled Thread network, -consult the [CHIPTool README](../../../src/android/CHIPTool/README.md) for -information on the Android smartphone application. Reference the Device +To commission and control this application within a Matter-enabled Thread +network, consult the [CHIPTool README](../../../src/android/CHIPTool/README.md) +for information on the Android smartphone application. Reference the Device Configuration information printed in the Logging Output of this application. ## TI Support @@ -275,7 +275,7 @@ Configuration information printed in the Logging Output of this application. For technical support, please consider creating a post on TI's [E2E forum][e2e]. Additionally, we welcome any feedback. -[chip]: https://github.com/project-chip/connectedhomeip +[matter]: https://github.com/project-chip/connectedhomeip [ccs]: https://www.ti.com/tool/CCSTUDIO [ccs_after_launch]: https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html?configuration#after-launch @@ -287,14 +287,11 @@ Additionally, we welcome any feedback. https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html?configuration#manual-method [cc1352r1_launchxl]: https://www.ti.com/tool/LAUNCHXL-CC1352R1 [e2e]: https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread -[simplelink_sdk]: https://www.ti.com/tool/SIMPLELINK-CC13X2-26X2-SDK -[simplelink_sdk_4.30.00.54]: - https://www.ti.com/tool/download/SIMPLELINK-CC13X2-26X2-SDK/4.30.00.54 [sysconfig]: https://www.ti.com/tool/SYSCONFIG [sysconfig_recommended]: - https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.7.0_1746-setup.run + https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.10.0_2163-setup.run [ti_thread_dnd]: https://www.ti.com/wireless-connectivity/thread/design-development.html -[ti_cc13x2_26x2_r7_chip_request]: https://ti.com/chip_sdk +[ti_cc13x2_26x2_r7_matter_request]: https://ti.com/chip_sdk [ot_border_router_setup]: https://openthread.io/guides/border-router/build [uniflash]: https://www.ti.com/tool/download/UNIFLASH diff --git a/examples/lock-app/cc13x2x7_26x2x7/chip.syscfg b/examples/lock-app/cc13x2x7_26x2x7/chip.syscfg index c93e60f4846aaa..f195ca15ec32d7 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/lock-app/cc13x2x7_26x2x7/chip.syscfg @@ -17,6 +17,7 @@ * limitations under the License. */ + /* Modules */ var AESCCM = scripting.addModule("/ti/drivers/AESCCM"); var AESECB = scripting.addModule("/ti/drivers/AESECB"); @@ -38,7 +39,6 @@ var ECDH = scripting.addModule("/ti/drivers/ECDH"); /* Instances */ var AESCCM1 = AESCCM.addInstance(); -var AESCCM2 = AESCCM.addInstance(); var AESECB1 = AESECB.addInstance(); var AESECB2 = AESECB.addInstance(); var Button1 = Button.addInstance(); @@ -52,22 +52,18 @@ var TRNG1 = TRNG.addInstance(); var TRNG2 = TRNG.addInstance(); var TRNG3 = TRNG.addInstance(); var UART1 = UART.addInstance(); -var UART2 = UART.addInstance(); var AESCTRDRBG1 = AESCTRDRBG.addInstance(); var ECDH1 = ECDH.addInstance(); -var ECDH2 = ECDH.addInstance(); AESCTRDRBG1.$name = "CONFIG_AESCTRDRBG_0"; AESCTRDRBG1.aesctrObject.$name = "CONFIG_AESCTR_0"; AESCCM1.$name = "CONFIG_AESCCM0"; -AESCCM2.$name = "CONFIG_AESCCM_1"; AESECB1.$name = "CONFIG_AESECB0"; AESECB2.$name = "CONFIG_AESECB_1"; ECDH1.$name = "CONFIG_ECDH0"; -ECDH2.$name = "CONFIG_ECDH_1"; /* RTOS */ RTOS.name = "FreeRTOS"; @@ -78,7 +74,6 @@ Button1.$hardware = system.deviceData.board.components["BTN-1" Button1.gpioPin.$name = "CONFIG_GPIO_BTN1"; Button1.gpioPin.pull = "Pull Up"; Button1.gpioPin.interruptTrigger = "Falling Edge"; -Button1.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN1"; /* Left Button */ Button2.$name = "CONFIG_BTN_RIGHT"; @@ -86,7 +81,6 @@ Button2.$hardware = system.deviceData.board.components["BTN-2" Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; Button2.gpioPin.pull = "Pull Up"; Button2.gpioPin.interruptTrigger = "Falling Edge"; -Button2.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN2"; /* ======== CCFG ======== */ var CCFG = scripting.addModule("/ti/devices/CCFG"); @@ -104,11 +98,10 @@ if(deviceName.includes("RB")) } /* NVS */ NVS1.$name = "CONFIG_NVSINTERNAL"; -NVS1.internalFlash.regionBase = 0x78000; +NVS1.internalFlash.regionBase = 0xAA000; NVS1.internalFlash.regionSize = 0x4000; /* RF */ -RF.$name = "CONFIG_RF0"; /* if an antenna component exists, assign it to the rf instance */ if (system.deviceData.board && system.deviceData.board.components.RF) { RF.$hardware = system.deviceData.board.components.RF; @@ -126,7 +119,6 @@ LED1.$hardware = system.deviceData.board.components.LED_RED; LED1.gpioPin.$name = "CONFIG_GPIO_RLED"; LED1.gpioPin.mode = "Output"; LED1.gpioPin.callbackFunction = ""; -LED1.gpioPin.pinInstance.$name = "CONFIG_PIN_RLED"; /* Green LED */ LED2.$name = "CONFIG_LED_GREEN"; @@ -134,17 +126,11 @@ LED2.$hardware = system.deviceData.board.components.LED_GREEN; LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; LED2.gpioPin.mode = "Output"; LED2.gpioPin.callbackFunction = ""; -LED2.gpioPin.pinInstance.$name = "CONFIG_PIN_GLED"; /* Debug UART */ UART1.$hardware = system.deviceData.board.components.XDS110UART; UART1.$name = "CONFIG_UART_DEBUG"; -/* Display UART */ -UART2.$name = "CONFIG_DISPLAY_UART"; -UART2.uart.txPin.$suggestSolution = "boosterpack.32"; -UART2.uart.rxPin.$suggestSolution = "boosterpack.18"; - /* TRNG */ TRNG1.$name = "CONFIG_TRNG_0"; TRNG2.$name = "CONFIG_TRNG_1"; diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp index e0d522d588560f..8649f916b3ebb1 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -82,7 +82,7 @@ int AppTask::StartAppTask() int AppTask::Init() { LED_Params ledParams; - Button_Params buttionParams; + Button_Params buttonParams; cc13x2_26x2LogInit(); @@ -152,15 +152,17 @@ int AppTask::Init() PLAT_LOG("Initialize buttons"); Button_init(); - Button_Params_init(&buttionParams); - buttionParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; - buttionParams.longPressDuration = 1000U; // ms - sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, ButtonLeftEventHandler, &buttionParams); - - Button_Params_init(&buttionParams); - buttionParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; - buttionParams.longPressDuration = 1000U; // ms - sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, ButtonRightEventHandler, &buttionParams); + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; + buttonParams.longPressDuration = 1000U; // ms + sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams); + Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; + buttonParams.longPressDuration = 1000U; // ms + sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); + Button_setCallback(sAppRightHandle, ButtonRightEventHandler); // Initialize BoltLock module PLAT_LOG("Initialize BoltLock"); diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h index 96d0e31bcee6b0..5b5c95c5721145 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ b/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h @@ -30,20 +30,8 @@ #if BUILD_RELEASE // release build -// Security and Authentication enabled for release build. -#define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 - #else // development build -// Security and Authentication disabled for development build. -// For convenience, enable CHIP Security Test Mode and disable the requirement for -// authentication in various protocols. -// WARNING: These options make it possible to circumvent basic CHIP security functionality, -// including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. -#define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 0 - // Use a default pairing code if one hasn't been provisioned in flash. #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 @@ -138,10 +126,6 @@ */ #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1 -#define CHIP_DEVICE_CONFIG_ENABLE_SED 1 -#define CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL 5000 -#define CHIP_DEVICE_CONFIG_SED_FAST_POLLING_INTERVAL 5000 - /** * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE * diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/main.cpp b/examples/lock-app/cc13x2x7_26x2x7/main/main.cpp index 4db8ab020823a4..cc1c08bd82cf78 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/main/main.cpp +++ b/examples/lock-app/cc13x2x7_26x2x7/main/main.cpp @@ -33,11 +33,13 @@ #include #include +#include +#include #include #include #include -#define TOTAL_ICALL_HEAP_SIZE (0xf000) +#define TOTAL_ICALL_HEAP_SIZE (0xc800) using namespace ::chip; using namespace ::chip::Inet; @@ -71,6 +73,10 @@ int main(void) UART_init(); + ECDH_init(); + + ECDSA_init(); + ECJPAKE_init(); AESECB_init(); diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/README.md b/examples/persistent-storage/cc13x2x7_26x2x7/README.md index dba97e2896a48c..c07fd6b3864f54 100644 --- a/examples/persistent-storage/cc13x2x7_26x2x7/README.md +++ b/examples/persistent-storage/cc13x2x7_26x2x7/README.md @@ -1,11 +1,11 @@ -# CHIP CC1352 CC2652 Persistent Storage Example Application +# Matter CC1352 CC2652 Persistent Storage Example Application An example test application showing the persistent storage system for -[CHIP][chip] on the Texas Instruments CC13X2_26X2 family of Wireless MCUs. +[Matter][matter] on the Texas Instruments CC13X2_26X2 family of Wireless MCUs. --- -- [CHIP CC1352 CC2652 Persistent Storage Application](#chip-cc1352-cc2652-persistent-storage-example-application) +- [Matter CC1352 CC2652 Persistent Storage Application](#matter-cc1352-cc2652-persistent-storage-example-application) - [Introduction](#introduction) - [Device UI](#device-ui) - [Building](#building) @@ -26,8 +26,8 @@ offers information on proper usage of the KVS system. This example is enabled to build for CC2652R7 devices. This upcoming devices are currently not yet in full production. For more information on device -availability or early access to an engineering build of our CHIP-enabled SDK, -please reach out [here][ti_cc13x2_26x2_r7_chip_request]. +availability or early access to an engineering build of our Matter-enabled SDK, +please reach out [here][ti_cc13x2_26x2_r7_matter_request]. ## Device UI @@ -55,7 +55,7 @@ section will need to be done when migrating to new versions of the SDK. This guide assumes that the environment is linux based, and recommends Ubuntu 20.04. - An engineering SDK from TI is required. Please request access for it - [here][ti_cc13x2_26x2_r7_chip_request]. + [here][ti_cc13x2_26x2_r7_matter_request]. - Follow the default installation instructions when executing the installer. @@ -141,15 +141,15 @@ Ninja to build the executable. - Run the build to produce a default executable. By default on Linux both the TI SimpleLink SDK and Sysconfig are located in a `ti` folder in the user's home directory, and you must provide the absolute path to them. For example - `/home/username/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng` and - `/home/username/ti/sysconfig_1.7.0`. On Windows the default directory is + `/home/username/ti/simplelink_cc13xx_cc26xx_sdk_5_30_03_01_eng` and + `/home/username/ti/sysconfig_1.10.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/cc13x2x7_26x2x7 - $ export TI_SIMPLELINK_SDK_ROOT=$HOME/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng - $ export TI_SYSCONFIG_ROOT=$HOME/ti/sysconfig_1.7.0 + $ export TI_SIMPLELINK_SDK_ROOT=$HOME/ti/simplelink_cc13xx_cc26xx_sdk_5_30_03_01_eng + $ export TI_SYSCONFIG_ROOT=$HOME/ti/sysconfig_1.10.0 $ gn gen out/debug --args="ti_simplelink_sdk_root=\"${TI_SIMPLELINK_SDK_ROOT}\" ti_sysconfig_root=\"${TI_SYSCONFIG_ROOT}\"" $ ninja -C out/debug @@ -237,7 +237,7 @@ terminal emulator to that port to see the output with the following options: For technical support, please consider creating a post on TI's [E2E forum][e2e]. Additionally, we welcome any feedback. -[chip]: https://github.com/project-chip/connectedhomeip +[matter]: https://github.com/project-chip/connectedhomeip [ccs]: https://www.ti.com/tool/CCSTUDIO [ccs_after_launch]: https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html?configuration#after-launch @@ -250,6 +250,6 @@ Additionally, we welcome any feedback. [e2e]: https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread [sysconfig]: https://www.ti.com/tool/SYSCONFIG [sysconfig_recommended]: - https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.7.0_1746-setup.run -[ti_cc13x2_26x2_r7_chip_request]: https://ti.com/chip_sdk + https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.10.0_2163-setup.run +[ti_cc13x2_26x2_r7_matter_request]: https://ti.com/chip_sdk [uniflash]: https://www.ti.com/tool/download/UNIFLASH diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg b/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg index c93e60f4846aaa..f195ca15ec32d7 100644 --- a/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg @@ -17,6 +17,7 @@ * limitations under the License. */ + /* Modules */ var AESCCM = scripting.addModule("/ti/drivers/AESCCM"); var AESECB = scripting.addModule("/ti/drivers/AESECB"); @@ -38,7 +39,6 @@ var ECDH = scripting.addModule("/ti/drivers/ECDH"); /* Instances */ var AESCCM1 = AESCCM.addInstance(); -var AESCCM2 = AESCCM.addInstance(); var AESECB1 = AESECB.addInstance(); var AESECB2 = AESECB.addInstance(); var Button1 = Button.addInstance(); @@ -52,22 +52,18 @@ var TRNG1 = TRNG.addInstance(); var TRNG2 = TRNG.addInstance(); var TRNG3 = TRNG.addInstance(); var UART1 = UART.addInstance(); -var UART2 = UART.addInstance(); var AESCTRDRBG1 = AESCTRDRBG.addInstance(); var ECDH1 = ECDH.addInstance(); -var ECDH2 = ECDH.addInstance(); AESCTRDRBG1.$name = "CONFIG_AESCTRDRBG_0"; AESCTRDRBG1.aesctrObject.$name = "CONFIG_AESCTR_0"; AESCCM1.$name = "CONFIG_AESCCM0"; -AESCCM2.$name = "CONFIG_AESCCM_1"; AESECB1.$name = "CONFIG_AESECB0"; AESECB2.$name = "CONFIG_AESECB_1"; ECDH1.$name = "CONFIG_ECDH0"; -ECDH2.$name = "CONFIG_ECDH_1"; /* RTOS */ RTOS.name = "FreeRTOS"; @@ -78,7 +74,6 @@ Button1.$hardware = system.deviceData.board.components["BTN-1" Button1.gpioPin.$name = "CONFIG_GPIO_BTN1"; Button1.gpioPin.pull = "Pull Up"; Button1.gpioPin.interruptTrigger = "Falling Edge"; -Button1.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN1"; /* Left Button */ Button2.$name = "CONFIG_BTN_RIGHT"; @@ -86,7 +81,6 @@ Button2.$hardware = system.deviceData.board.components["BTN-2" Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; Button2.gpioPin.pull = "Pull Up"; Button2.gpioPin.interruptTrigger = "Falling Edge"; -Button2.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN2"; /* ======== CCFG ======== */ var CCFG = scripting.addModule("/ti/devices/CCFG"); @@ -104,11 +98,10 @@ if(deviceName.includes("RB")) } /* NVS */ NVS1.$name = "CONFIG_NVSINTERNAL"; -NVS1.internalFlash.regionBase = 0x78000; +NVS1.internalFlash.regionBase = 0xAA000; NVS1.internalFlash.regionSize = 0x4000; /* RF */ -RF.$name = "CONFIG_RF0"; /* if an antenna component exists, assign it to the rf instance */ if (system.deviceData.board && system.deviceData.board.components.RF) { RF.$hardware = system.deviceData.board.components.RF; @@ -126,7 +119,6 @@ LED1.$hardware = system.deviceData.board.components.LED_RED; LED1.gpioPin.$name = "CONFIG_GPIO_RLED"; LED1.gpioPin.mode = "Output"; LED1.gpioPin.callbackFunction = ""; -LED1.gpioPin.pinInstance.$name = "CONFIG_PIN_RLED"; /* Green LED */ LED2.$name = "CONFIG_LED_GREEN"; @@ -134,17 +126,11 @@ LED2.$hardware = system.deviceData.board.components.LED_GREEN; LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; LED2.gpioPin.mode = "Output"; LED2.gpioPin.callbackFunction = ""; -LED2.gpioPin.pinInstance.$name = "CONFIG_PIN_GLED"; /* Debug UART */ UART1.$hardware = system.deviceData.board.components.XDS110UART; UART1.$name = "CONFIG_UART_DEBUG"; -/* Display UART */ -UART2.$name = "CONFIG_DISPLAY_UART"; -UART2.uart.txPin.$suggestSolution = "boosterpack.32"; -UART2.uart.rxPin.$suggestSolution = "boosterpack.18"; - /* TRNG */ TRNG1.$name = "CONFIG_TRNG_0"; TRNG2.$name = "CONFIG_TRNG_1"; diff --git a/examples/pump-app/cc13x2x7_26x2x7/README.md b/examples/pump-app/cc13x2x7_26x2x7/README.md index b8e270f63d9e4d..62a688e3aa53b5 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/README.md +++ b/examples/pump-app/cc13x2x7_26x2x7/README.md @@ -48,13 +48,13 @@ pump and to control the state. The user LEDs on the LaunchPad are set on when the pump is started, and are set off when stopped. The LEDs will flash when in the transition state between started and stopped. -Short presses (less than 1000ms) of the left user button (`BTN-1`) are used for +Short presses (less than 1000ms) of the right user button (`BTN-2`) are used for toggling the pump state. -Short presses (less than 1000ms) of the right user button (`BTN-2`) are used for +Short presses (less than 1000ms) of the left user button (`BTN-1`) are used for toggling Matter BLE advertisements. -Long presses (greater than 5000ms) of the right user button (`BTN-2`) will +Long presses (greater than 5000ms) of the left user button (`BTN-1`) will initiate a factory reset of the device clearing all stored provisioning information to allow for a new network setup. @@ -75,8 +75,8 @@ section will need to be done when migrating to new versions of the SDK. packaged with the TI SDK. Check the following section for a list of changes needed. -- Download and install [SysConfig][sysconfig] - ([sysconfig-1.5.0_1397][sysconfig-1.5.0_1397]) +- Download and install [SysConfig][sysconfig] ([recommended + version][sysconfig_recommended]) - This may have already been installed with your SimpleLink SDK install. @@ -100,7 +100,7 @@ section will need to be done when migrating to new versions of the SDK. ``` $ cd ~/connectedhomeip - $ source ./script/bootstrap.sh + $ source ./scripts/bootstrap.sh ``` @@ -113,21 +113,21 @@ Ninja to build the executable. ``` $ cd ~/connectedhomeip - $ source ./script/activate.sh + $ source ./scripts/activate.sh ``` - Run the build to produce a default executable. By default on Linux both the TI SimpleLink SDK and Sysconfig are located in a `ti` folder in the user's home directory, and you must provide the absolute path to them. For example - `/home/username/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng` and - `/home/username/ti/sysconfig_1.6.0`. On Windows the default directory is - `C:\ti` + `/home/username/ti/simplelink_cc13xx_cc26xx_sdk_5_30_03_01_eng` and + `/home/username/ti/sysconfig_1.10.0`. On Windows the default directory is + `C:\ti`. ``` - $ cd ~/connectedhomeip/examples/pump-app/cc13x2_26x2 - $ export TI_SIMPLELINK_SDK_ROOT= - $ export TI_SYSCONFIG_ROOT= + $ cd ~/connectedhomeip/examples/pump-app/cc13x2x7_26x2x7 + $ export TI_SIMPLELINK_SDK_ROOT=$HOME/ti/simplelink_cc13xx_cc26xx_sdk_5_30_03_01_eng + $ export TI_SYSCONFIG_ROOT=$HOME/ti/sysconfig_1.10.0 $ gn gen out/debug --args="ti_simplelink_sdk_root=\"${TI_SIMPLELINK_SDK_ROOT}\" ti_sysconfig_root=\"${TI_SYSCONFIG_ROOT}\"" $ ninja -C out/debug @@ -220,12 +220,9 @@ Additionally, we welcome any feedback. [matter]: https://github.com/project-chip/connectedhomeip [cc1352r1_launchxl]: https://www.ti.com/tool/LAUNCHXL-CC1352R1 [e2e]: https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread -[simplelink_sdk]: https://www.ti.com/tool/SIMPLELINK-CC13X2-26X2-SDK -[simplelink_sdk_4.30.00.54]: - https://www.ti.com/tool/download/SIMPLELINK-CC13X2-26X2-SDK/4.30.00.54 [sysconfig]: https://www.ti.com/tool/SYSCONFIG -[sysconfig-1.5.0_1397]: - http://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.5.0_1397-setup.run +[sysconfig_recommended]: + https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.10.0_2163-setup.run [ti_thread_dnd]: https://www.ti.com/wireless-connectivity/thread/design-development.html [ti_cc13x2_26x2_r7_matter_request]: https://ti.com/chip_sdk diff --git a/examples/pump-app/cc13x2x7_26x2x7/chip.syscfg b/examples/pump-app/cc13x2x7_26x2x7/chip.syscfg index 38a53e57d500fd..3f47781b9f518a 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/pump-app/cc13x2x7_26x2x7/chip.syscfg @@ -145,7 +145,7 @@ ECJPAKE1.$name = "CONFIG_ECJPAKE_0"; NVS1.$name = "CONFIG_NVSINTERNAL"; NVS1.internalFlash.$name = "ti_drivers_nvs_NVSCC26XX0"; -NVS1.internalFlash.regionBase = 0x78000; +NVS1.internalFlash.regionBase = 0xAA000; NVS1.internalFlash.regionSize = 0x4000; RTOS.name = "FreeRTOS"; @@ -169,25 +169,34 @@ UART2.$name = "CONFIG_DISPLAY_UART"; UART2.txPinInstance.$name = "CONFIG_PIN_6"; UART2.rxPinInstance.$name = "CONFIG_PIN_7"; -Button1.$name = "CONFIG_BTN_LEFT"; -Button1.gpioPin.$name = "CONFIG_GPIO_BTN1"; -Button1.gpioPin.gpioPin.$assign = "boosterpack.32"; -Button1.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN1"; - -Button2.$name = "CONFIG_BTN_RIGHT"; -Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; -Button2.gpioPin.gpioPin.$assign = "boosterpack.13"; -Button2.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN2"; - -LED1.$name = "CONFIG_LED_RED"; -LED1.gpioPin.$name = "CONFIG_GPIO_RLED"; -LED1.gpioPin.gpioPin.$assign = "boosterpack.10"; -LED1.gpioPin.pinInstance.$name = "CONFIG_PIN_RLED"; - -LED2.$name = "CONFIG_LED_GREEN"; -LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; -LED2.gpioPin.gpioPin.$assign = "boosterpack.39"; -LED2.gpioPin.pinInstance.$name = "CONFIG_PIN_GLED"; + +/* Left Button */ +Button1.$name = "CONFIG_BTN_LEFT"; +Button1.$hardware = system.deviceData.board.components["BTN-1"]; +Button1.gpioPin.$name = "CONFIG_GPIO_BTN1"; +Button1.gpioPin.pull = "Pull Up"; +Button1.gpioPin.interruptTrigger = "Falling Edge"; + +/* Left Button */ +Button2.$name = "CONFIG_BTN_RIGHT"; +Button2.$hardware = system.deviceData.board.components["BTN-2"]; +Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; +Button2.gpioPin.pull = "Pull Up"; +Button2.gpioPin.interruptTrigger = "Falling Edge"; + +/* Red LED */ +LED1.$name = "CONFIG_LED_RED"; +LED1.$hardware = system.deviceData.board.components.LED_RED; +LED1.gpioPin.$name = "CONFIG_GPIO_RLED"; +LED1.gpioPin.mode = "Output"; +LED1.gpioPin.callbackFunction = ""; + +/* Green LED */ +LED2.$name = "CONFIG_LED_GREEN"; +LED2.$hardware = system.deviceData.board.components.LED_GREEN; +LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; +LED2.gpioPin.mode = "Output"; +LED2.gpioPin.callbackFunction = ""; thread.deviceTypeReadOnly = true; thread.pm.$name = "ti_thread_pm_thread_pm0"; diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp index a5883059abf71c..745949c9f30b56 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -163,15 +163,17 @@ int AppTask::Init() PLAT_LOG("Initialize buttons"); Button_init(); - Button_Params_init(&buttonParams); - buttonParams.buttonEventMask = Button_EV_CLICKED; - buttonParams.longPressDuration = 1000U; // ms - sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, ButtonLeftEventHandler, &buttonParams); - Button_Params_init(&buttonParams); buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGPRESSED; buttonParams.longPressDuration = 5000U; // ms - sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, ButtonRightEventHandler, &buttonParams); + sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams); + Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED; + buttonParams.longPressDuration = 1000U; // ms + sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); + Button_setCallback(sAppRightHandle, ButtonRightEventHandler); // Initialize Pump module PLAT_LOG("Initialize Pump"); @@ -182,7 +184,7 @@ int AppTask::Init() ConfigurationMgr().LogDeviceConfig(); // QR code will be used with CHIP Tool - PrintOnboardingCodes(chip::RendezvousInformationFlag::kBLE); + PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); return 0; } @@ -220,7 +222,10 @@ void AppTask::ButtonLeftEventHandler(Button_Handle handle, Button_EventMask even { event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked; } - + else if (events & Button_EV_LONGPRESSED) + { + event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongPressed; + } // button callbacks are in ISR context if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS) { @@ -237,10 +242,6 @@ void AppTask::ButtonRightEventHandler(Button_Handle handle, Button_EventMask eve { event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked; } - else if (events & Button_EV_LONGPRESSED) - { - event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongPressed; - } // button callbacks are in ISR context if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS) { @@ -300,7 +301,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent) { switch (aEvent->Type) { - case AppEvent::kEventType_ButtonLeft: + case AppEvent::kEventType_ButtonRight: if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) { // Toggle Pump state @@ -315,7 +316,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent) } break; - case AppEvent::kEventType_ButtonRight: + case AppEvent::kEventType_ButtonLeft: if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) { // Toggle BLE advertisements diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/main.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/main.cpp index 03a1b6badebe6f..fb7c602527fea5 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/main.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/main.cpp @@ -33,11 +33,13 @@ #include #include +#include +#include #include #include #include -#define TOTAL_ICALL_HEAP_SIZE (0xC000) +#define TOTAL_ICALL_HEAP_SIZE (0xc000) using namespace ::chip; using namespace ::chip::Inet; @@ -71,6 +73,10 @@ int main(void) UART_init(); + ECDH_init(); + + ECDSA_init(); + ECJPAKE_init(); AESECB_init(); diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/README.md b/examples/pump-controller-app/cc13x2x7_26x2x7/README.md index b252a2fce7d6a1..7c9e21ce726d91 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/README.md +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/README.md @@ -49,13 +49,13 @@ pump and to control the state. The user LEDs on the LaunchPad are set on when the pump is started, and are set off when stopped. The LEDs will flash when in the transition state between started and stopped. -Short presses (less than 1000ms) of the left user button (`BTN-1`) are used for +Short presses (less than 1000ms) of the right user button (`BTN-2`) are used for toggling the pump state. -Short presses (less than 1000ms) of the right user button (`BTN-2`) are used for +Short presses (less than 1000ms) of the left user button (`BTN-1`) are used for toggling Matter BLE advertisements. -Long presses (greater than 5000ms) of the right user button (`BTN-2`) will +Long presses (greater than 5000ms) of the left user button (`BTN-1`) will initiate a factory reset of the device clearing all stored provisioning information to allow for a new network setup. @@ -76,8 +76,8 @@ section will need to be done when migrating to new versions of the SDK. packaged with the TI SDK. Check the following section for a list of changes needed. -- Download and install [SysConfig][sysconfig] - ([sysconfig-1.5.0_1397][sysconfig-1.5.0_1397]) +- Download and install [SysConfig][sysconfig] ([recommended + version][sysconfig_recommended]) - This may have already been installed with your SimpleLink SDK install. @@ -101,7 +101,7 @@ section will need to be done when migrating to new versions of the SDK. ``` $ cd ~/connectedhomeip - $ source ./script/bootstrap.sh + $ source ./scripts/bootstrap.sh ``` @@ -114,21 +114,21 @@ Ninja to build the executable. ``` $ cd ~/connectedhomeip - $ source ./script/activate.sh + $ source ./scripts/activate.sh ``` - Run the build to produce a default executable. By default on Linux both the TI SimpleLink SDK and Sysconfig are located in a `ti` folder in the user's home directory, and you must provide the absolute path to them. For example - `/home/username/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng` and - `/home/username/ti/sysconfig_1.6.0`. On Windows the default directory is - `C:\ti` + `/home/username/ti/simplelink_cc13xx_cc26xx_sdk_5_30_03_01_eng` and + `/home/username/ti/sysconfig_1.10.0`. On Windows the default directory is + `C:\ti`. ``` - $ cd ~/connectedhomeip/examples/pump-controller-app/cc13x2_26x2 - $ export TI_SIMPLELINK_SDK_ROOT= - $ export TI_SYSCONFIG_ROOT= + $ cd ~/connectedhomeip/examples/pump-controller-app/cc13x2x7_26x2x7 + $ export TI_SIMPLELINK_SDK_ROOT=$HOME/ti/simplelink_cc13xx_cc26xx_sdk_5_30_03_01_eng + $ export TI_SYSCONFIG_ROOT=$HOME/ti/sysconfig_1.10.0 $ gn gen out/debug --args="ti_simplelink_sdk_root=\"${TI_SIMPLELINK_SDK_ROOT}\" ti_sysconfig_root=\"${TI_SYSCONFIG_ROOT}\"" $ ninja -C out/debug @@ -221,12 +221,9 @@ Additionally, we welcome any feedback. [matter]: https://github.com/project-chip/connectedhomeip [cc1352r1_launchxl]: https://www.ti.com/tool/LAUNCHXL-CC1352R1 [e2e]: https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread -[simplelink_sdk]: https://www.ti.com/tool/SIMPLELINK-CC13X2-26X2-SDK -[simplelink_sdk_4.30.00.54]: - https://www.ti.com/tool/download/SIMPLELINK-CC13X2-26X2-SDK/4.30.00.54 [sysconfig]: https://www.ti.com/tool/SYSCONFIG -[sysconfig-1.5.0_1397]: - http://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.5.0_1397-setup.run +[sysconfig_recommended]: + https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.10.0_2163-setup.run [ti_thread_dnd]: https://www.ti.com/wireless-connectivity/thread/design-development.html [ti_cc13x2_26x2_r7_matter_request]: https://ti.com/chip_sdk diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/chip.syscfg b/examples/pump-controller-app/cc13x2x7_26x2x7/chip.syscfg index 38a53e57d500fd..cd153a744fea1d 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/chip.syscfg @@ -145,7 +145,7 @@ ECJPAKE1.$name = "CONFIG_ECJPAKE_0"; NVS1.$name = "CONFIG_NVSINTERNAL"; NVS1.internalFlash.$name = "ti_drivers_nvs_NVSCC26XX0"; -NVS1.internalFlash.regionBase = 0x78000; +NVS1.internalFlash.regionBase = 0xAA000; NVS1.internalFlash.regionSize = 0x4000; RTOS.name = "FreeRTOS"; @@ -169,25 +169,33 @@ UART2.$name = "CONFIG_DISPLAY_UART"; UART2.txPinInstance.$name = "CONFIG_PIN_6"; UART2.rxPinInstance.$name = "CONFIG_PIN_7"; -Button1.$name = "CONFIG_BTN_LEFT"; -Button1.gpioPin.$name = "CONFIG_GPIO_BTN1"; -Button1.gpioPin.gpioPin.$assign = "boosterpack.32"; -Button1.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN1"; - -Button2.$name = "CONFIG_BTN_RIGHT"; -Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; -Button2.gpioPin.gpioPin.$assign = "boosterpack.13"; -Button2.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN2"; - -LED1.$name = "CONFIG_LED_RED"; -LED1.gpioPin.$name = "CONFIG_GPIO_RLED"; -LED1.gpioPin.gpioPin.$assign = "boosterpack.10"; -LED1.gpioPin.pinInstance.$name = "CONFIG_PIN_RLED"; - -LED2.$name = "CONFIG_LED_GREEN"; -LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; -LED2.gpioPin.gpioPin.$assign = "boosterpack.39"; -LED2.gpioPin.pinInstance.$name = "CONFIG_PIN_GLED"; +/* Left Button */ +Button1.$name = "CONFIG_BTN_LEFT"; +Button1.$hardware = system.deviceData.board.components["BTN-1"]; +Button1.gpioPin.$name = "CONFIG_GPIO_BTN1"; +Button1.gpioPin.pull = "Pull Up"; +Button1.gpioPin.interruptTrigger = "Falling Edge"; + +/* Left Button */ +Button2.$name = "CONFIG_BTN_RIGHT"; +Button2.$hardware = system.deviceData.board.components["BTN-2"]; +Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; +Button2.gpioPin.pull = "Pull Up"; +Button2.gpioPin.interruptTrigger = "Falling Edge"; + +/* Red LED */ +LED1.$name = "CONFIG_LED_RED"; +LED1.$hardware = system.deviceData.board.components.LED_RED; +LED1.gpioPin.$name = "CONFIG_GPIO_RLED"; +LED1.gpioPin.mode = "Output"; +LED1.gpioPin.callbackFunction = ""; + +/* Green LED */ +LED2.$name = "CONFIG_LED_GREEN"; +LED2.$hardware = system.deviceData.board.components.LED_GREEN; +LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; +LED2.gpioPin.mode = "Output"; +LED2.gpioPin.callbackFunction = ""; thread.deviceTypeReadOnly = true; thread.pm.$name = "ti_thread_pm_thread_pm0"; diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp index fd87dd8e650e05..ee332a4dadbd10 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -158,15 +158,17 @@ int AppTask::Init() PLAT_LOG("Initialize buttons"); Button_init(); - Button_Params_init(&buttonParams); - buttonParams.buttonEventMask = Button_EV_CLICKED; - buttonParams.longPressDuration = 1000U; // ms - sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, ButtonLeftEventHandler, &buttonParams); - Button_Params_init(&buttonParams); buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGPRESSED; buttonParams.longPressDuration = 5000U; // ms - sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, ButtonRightEventHandler, &buttonParams); + sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams); + Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED; + buttonParams.longPressDuration = 1000U; // ms + sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); + Button_setCallback(sAppRightHandle, ButtonRightEventHandler); // Initialize Pump module PLAT_LOG("Initialize Pump"); @@ -177,7 +179,7 @@ int AppTask::Init() ConfigurationMgr().LogDeviceConfig(); // QR code will be used with CHIP Tool - PrintOnboardingCodes(chip::RendezvousInformationFlag::kBLE); + PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); return 0; } @@ -215,7 +217,10 @@ void AppTask::ButtonLeftEventHandler(Button_Handle handle, Button_EventMask even { event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked; } - + else if (events & Button_EV_LONGPRESSED) + { + event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongPressed; + } // button callbacks are in ISR context if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS) { @@ -232,10 +237,6 @@ void AppTask::ButtonRightEventHandler(Button_Handle handle, Button_EventMask eve { event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked; } - else if (events & Button_EV_LONGPRESSED) - { - event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongPressed; - } // button callbacks are in ISR context if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS) { @@ -295,7 +296,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent) { switch (aEvent->Type) { - case AppEvent::kEventType_ButtonLeft: + case AppEvent::kEventType_ButtonRight: if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) { // Toggle Pump state @@ -310,7 +311,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent) } break; - case AppEvent::kEventType_ButtonRight: + case AppEvent::kEventType_ButtonLeft: if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) { // Toggle BLE advertisements diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/main.cpp b/examples/pump-controller-app/cc13x2x7_26x2x7/main/main.cpp index 03a1b6badebe6f..fb7c602527fea5 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/main.cpp +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/main.cpp @@ -33,11 +33,13 @@ #include #include +#include +#include #include #include #include -#define TOTAL_ICALL_HEAP_SIZE (0xC000) +#define TOTAL_ICALL_HEAP_SIZE (0xc000) using namespace ::chip; using namespace ::chip::Inet; @@ -71,6 +73,10 @@ int main(void) UART_init(); + ECDH_init(); + + ECDSA_init(); + ECJPAKE_init(); AESECB_init(); diff --git a/src/platform/cc13x2_26x2/BLEManagerImpl.cpp b/src/platform/cc13x2_26x2/BLEManagerImpl.cpp index 15d28f75ffef88..e917cedeee1066 100644 --- a/src/platform/cc13x2_26x2/BLEManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/BLEManagerImpl.cpp @@ -692,8 +692,6 @@ CHIP_ERROR BLEManagerImpl::CreateEventHandler(void) */ uint8_t BLEManagerImpl::ProcessStackEvent(ICall_Hdr * pMsg) { - BLEMGR_LOG("BLEMGR: BLE Process Stack Event"); - // Always dealloc pMsg unless set otherwise uint8_t safeToDealloc = TRUE; @@ -783,8 +781,6 @@ void BLEManagerImpl::ProcessEvtHdrMsg(QueuedEvt_t * pMsg) { bool dealloc = TRUE; - BLEMGR_LOG("BLEMGR: ProcessEvtHdrMsg"); - switch (pMsg->event) { /* External CHIPoBLE Event trigger */ @@ -1391,7 +1387,6 @@ status_t BLEManagerImpl::EnqueueEvtHdrMsg(uint8_t event, void * pData) if (sInstance.mFlags.Has(Flags::kBLEStackInitialized)) { QueuedEvt_t * pMsg = (QueuedEvt_t *) ICall_malloc(sizeof(QueuedEvt_t)); - BLEMGR_LOG("BLEMGR: EnqueueEvtHdrMsg"); // Create dynamic pointer to message. if (pMsg) @@ -1402,8 +1397,6 @@ status_t BLEManagerImpl::EnqueueEvtHdrMsg(uint8_t event, void * pData) // Enqueue the message. success = Util_enqueueMsg(sEventHandlerMsgQueueID, BLEManagerImpl::sSyncEvent, (uint8_t *) pMsg); - BLEMGR_LOG("BLEMGR: Util_enqueueMsg compelte"); - return (success) ? SUCCESS : FAILURE; } @@ -1620,7 +1613,6 @@ void BLEManagerImpl::ClearPendingBLEParamUpdate(uint16_t connHandle) void BLEManagerImpl::UpdateBLERPA(void) { uint8_t * pRpaNew; - BLEMGR_LOG("BLEMGR: UpdateBLERPA"); // Read the current RPA. pRpaNew = GAP_GetDevAddress(FALSE); @@ -1633,7 +1625,6 @@ void BLEManagerImpl::UpdateBLERPA(void) void BLEManagerImpl::EventHandler(void * arg) { - BLEMGR_LOG("BLEMGR: EventHandler"); PlatformMgr().LockChipStack(); sInstance.EventHandler_init(); @@ -1657,12 +1648,9 @@ void BLEManagerImpl::EventHandler(void * arg) /* Lock CHIP Stack while processing BLE Stack/App events */ PlatformMgr().LockChipStack(); - BLEMGR_LOG("BLEMGR: EventHandler: Events received"); // Fetch any available messages that might have been sent from the stack if (ICall_fetchServiceMsg(&src, &dest, (void **) &hcipMsg) == ICALL_ERRNO_SUCCESS) { - BLEMGR_LOG("BLEMGR: EventHandler: Stack Event"); - uint8 safeToDealloc = TRUE; if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == BLEManagerImpl::sSelfEntity)) @@ -1686,8 +1674,6 @@ void BLEManagerImpl::EventHandler(void * arg) // If RTOS queue is not empty, process CHIP messages. if (events & QUEUE_EVT) { - BLEMGR_LOG("BLEMGR: EventHandler: App Event"); - QueuedEvt_t * pMsg; for (;;) { @@ -1767,11 +1753,9 @@ void BLEManagerImpl::AdvTimeoutHandler(uintptr_t arg) void BLEManagerImpl::ClockHandler(uintptr_t arg) { ClockEventData_t * pData = (ClockEventData_t *) arg; - BLEMGR_LOG("BLEMGR: ClockHandler"); if (pData->event == READ_RPA_EVT) { - BLEMGR_LOG("BLEMGR: ClockHandler RPA EVT"); // Start the next period Util_startClock(&sInstance.clkRpaRead); @@ -1780,7 +1764,6 @@ void BLEManagerImpl::ClockHandler(uintptr_t arg) } else if (pData->event == SEND_PARAM_UPDATE_EVT) { - BLEMGR_LOG("BLEMGR: ClockHandler PARAM UPDATE EVT"); // Send message to app if (sInstance.EnqueueEvtHdrMsg(SEND_PARAM_UPDATE_EVT, pData) != SUCCESS) { diff --git a/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h b/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h index bddae508acea2b..26a1537fe9c178 100644 --- a/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h +++ b/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h @@ -39,7 +39,7 @@ // ========== CHIP Platform Configuration ========= -#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE (5120) +#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE (6144) #define BLEMANAGER_EVENT_HANDLER_STACK_SIZE (4096) #define BLEMANAGER_EVENT_HANDLER_PRIORITY (2) diff --git a/src/platform/cc13x2_26x2/FreeRTOSConfig.h b/src/platform/cc13x2_26x2/FreeRTOSConfig.h index 532b7767270d67..1d3798b6c8dcc3 100644 --- a/src/platform/cc13x2_26x2/FreeRTOSConfig.h +++ b/src/platform/cc13x2_26x2/FreeRTOSConfig.h @@ -106,7 +106,7 @@ #define configTIMER_TASK_PRIORITY (6) #define configTIMER_QUEUE_LENGTH (20) #define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) - +#define configIDLE_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE) #define configENABLE_BACKWARD_COMPATIBILITY 1 #if defined(__TI_COMPILER_VERSION__) || defined(__ti_version__) diff --git a/src/platform/cc13x2_26x2/ThreadStackManagerImpl.cpp b/src/platform/cc13x2_26x2/ThreadStackManagerImpl.cpp index efb645eaa0b3e6..ca5bfaacba426a 100644 --- a/src/platform/cc13x2_26x2/ThreadStackManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/ThreadStackManagerImpl.cpp @@ -210,3 +210,13 @@ extern "C" void otSysProcessDrivers(otInstance * aInstance) { ThreadStackMgrImpl()._ProcMessage(aInstance); } + +/** + * Get a pointer to the OpenThread instance object. + * + * @return Pointer to the OpenThread instance object. + */ +extern "C" otInstance * OtInstance_get(void) +{ + return ThreadStackMgrImpl().OTInstance(); +} diff --git a/src/platform/cc13x2_26x2/ble_user_config.c b/src/platform/cc13x2_26x2/ble_user_config.c new file mode 100644 index 00000000000000..4cc4e2f12c1695 --- /dev/null +++ b/src/platform/cc13x2_26x2/ble_user_config.c @@ -0,0 +1,530 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020 Texas Instruments Incorporated + * + * 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 user configurable variables for the BLE + * Application. + * + */ + +/******************************************************************************* + * INCLUDES + */ + +#include "ble_user_config.h" +#include "hal_types.h" +#ifndef FREERTOS +#include +#endif +#ifdef SYSCFG +#include "ti_ble_config.h" +#else +#include +#endif + +#if defined(AOA_SYSCFG) +#include "ti_aoa_config.h" +#endif + +#include "ble_overrides.h" +#include "ti_radio_config.h" + +#include + +#include "ecc/ECCROMCC26XX.h" + +#include +#include +#include +#include +#include + +#ifdef FREERTOS +#define Swi_restore SwiP_restore +#define Swi_disable SwiP_disable +#include +#else +#include +#endif +#include +#include + +#if !defined(DeviceFamily_CC26X1) +#include +#include +#else +#include +#endif + +/******************************************************************************* + * MACROS + */ + +/******************************************************************************* + * CONSTANTS + */ + +// Tx Power +#define NUM_TX_POWER_VALUES (RF_BLE_TX_POWER_TABLE_SIZE - 1) + +#ifndef SYSCFG +// Default Tx Power Index +#if defined(CC13X2P) +#define DEFAULT_TX_POWER HCI_EXT_TX_POWER_0_DBM +#else // !CC13X2 +#define DEFAULT_TX_POWER HCI_EXT_TX_POWER_0_DBM +#endif // CC13X2 +#endif // SYSCFG + +// Override NOP +#define OVERRIDE_NOP 0xC0000001 + +/******************************************************************************* + * TYPEDEFS + */ + +/******************************************************************************* + * LOCAL VARIABLES + */ + +/********************************************************************* + * LOCAL FUNCTIONS + */ + +void driverTable_fnSpinlock(void); + +/******************************************************************************* + * GLOBAL VARIABLES + */ + +// Tx Power Table +txPwrTbl_t appTxPwrTbl = { (txPwrVal_t *) RF_BLE_txPowerTable, + NUM_TX_POWER_VALUES, // max + DEFAULT_TX_POWER }; // default + +#if defined(CC13X2P) && defined(CC13X2P_2_LAUNCHXL) + +// Tx Power Backoff Values (txPwrBackoff1MPhy,txPwrBackoff2MPhy ,txPwrBackoffCoded) +const txPwrBackoffVal_t TxPowerBackoffTable[] = { + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 0 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 1 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 2 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 3 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 4 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 5 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 6 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 7 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 8 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 9 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 10 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 11 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 12 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 13 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 14 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 15 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 16 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 17 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 18 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 19 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 20 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 21 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 22 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 23 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 24 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 25 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 26 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 27 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 28 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 29 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 30 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 31 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 32 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 33 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_17_DBM_P4_9_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 34 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_18_DBM_P4_10_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 35 + { HCI_EXT_TX_POWER_P2_19_DBM, HCI_EXT_TX_POWER_P2_18_DBM_P4_10_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 36 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 37 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 38 + { HCI_EXT_TX_POWER_P2_14_DBM_P4_6_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM } +}; // max tx power for channel 39 + +txPwrBackoffTbl_t appTxPwrBackoffTbl = { TxPowerBackoffTable }; + +#endif // defined(CC13X2P) && defined(CC13X2P_2_LAUNCHXL) + +#if !defined(AOA_SYSCFG) +// Antenna board configurations (example for a 12-antenna board) +// Maximum number of antennas +#define ANTENNA_TABLE_SIZE 12 +// BitMask of all the relevant GPIOs which needed for the antennas +#define ANTENNA_IO_MASK BV(27) | BV(28) | BV(29) | BV(30) + +// Antenna GPIO configuration (should be adapted to the antenna board design) +antennaIOEntry_t antennaTbl[ANTENNA_TABLE_SIZE] = { + 0, // antenna 0 GPIO configuration (all GPIOs in ANTENNA_IO_MASK are LOW) + BV(28), // antenna 1 + BV(29), // antenna 2 + BV(28) | BV(29), // antenna 3 + BV(30), // antenna 4 + BV(28) | BV(30), // antenna 5 + BV(27), // antenna 6 + BV(27) | BV(28), // antenna 7 + BV(27) | BV(29), // antenna 8 + BV(27) | BV(28) | BV(29), // antenna 9 + BV(27) | BV(30), // antenna 10 + BV(27) | BV(28) | BV(30) // antenna 11 +}; + +#endif //! defined(AOA_SYSCFG) + +// Antenna properties passes to the stack +cteAntProp_t appCTEAntProp = { ANTENNA_IO_MASK, ANTENNA_TABLE_SIZE, antennaTbl }; + +#if !defined(DeviceFamily_CC26X1) +ECCParams_CurveParams eccParams_NISTP256 = { .curveType = ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_AN3, + .length = NISTP256_PARAM_SIZE_BYTES, + .prime = NISTP256_prime.byte, + .order = NISTP256_order.byte, + .a = NISTP256_a.byte, + .b = NISTP256_b.byte, + .generatorX = NISTP256_generator.x.byte, + .generatorY = NISTP256_generator.y.byte, + .cofactor = 1 }; +#else +ECCParams_CurveParams eccParams_NISTP256 = { .curveType = ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_AN3, + .length = ECC_NISTP256_PARAM_LENGTH_BYTES, + .prime = ECC_NISTP256_prime.byte, + .order = ECC_NISTP256_order.byte, + .a = ECC_NISTP256_a.byte, + .b = ECC_NISTP256_b.byte, + .generatorX = ECC_NISTP256_generatorX.byte, + .generatorY = ECC_NISTP256_generatorY.byte, + .cofactor = 1 }; +#endif + +#if defined(USE_COEX) +// 2 structures generated by the sysconfig RF for coexistence configuration +extern rfCoreHal_bleCoExConfig_t coexConfig; +extern RF_CoexOverride_BLEUseCases coexConfigBle; +// from coexConfig struct we will get the coex enable and coex type (3 or 1 wire) +// from coexConfigBle struct we will get the priority and rx request per use case: +// initiator, connected, Broadcaster and Observer. +coexUseCaseConfig_t coexSysConfig = { &coexConfig, &coexConfigBle }; +#endif + +#ifdef ICALL_JT +#include + +// RF Driver API Table +rfDrvTblPtr_t rfDriverTableBLE[] = { + (uint32) RF_open, + (uint32) driverTable_fnSpinlock, // RF_close +#ifdef RF_SINGLEMODE + (uint32) RF_postCmd, +#else // !RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_postCmd +#endif // RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_pendCmd +#ifdef RF_SINGLEMODE + (uint32) RF_runCmd, +#else // !RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_runCmd +#endif // RF_SINGLEMODE + (uint32) RF_cancelCmd, + (uint32) RF_flushCmd, + (uint32) driverTable_fnSpinlock, // RF_yield + (uint32) RF_Params_init, + (uint32) RF_runImmediateCmd, + (uint32) RF_runDirectCmd, + (uint32) RF_ratCompare, + (uint32) driverTable_fnSpinlock, // RF_ratCapture + (uint32) RF_ratDisableChannel, + (uint32) RF_getCurrentTime, + (uint32) RF_getRssi, + (uint32) RF_getInfo, + (uint32) RF_getCmdOp, + (uint32) RF_control, + (uint32) driverTable_fnSpinlock, // RF_getTxPower + (uint32) RF_setTxPower, // RF_setTxPower + (uint32) driverTable_fnSpinlock, // RF_TxPowerTable_findPowerLevel + (uint32) driverTable_fnSpinlock, // RF_TxPowerTable_findValue +#ifndef RF_SINGLEMODE + (uint32) RF_scheduleCmd, + (uint32) RF_runScheduleCmd, + (uint32) driverTable_fnSpinlock, // RF_requestAccess +#endif // !RF_SINGLEMODE +}; + +cryptoDrvTblPtr_t cryptoDriverTableBLE[] = { (uint32) AESCCM_init, + (uint32) AESCCM_open, + (uint32) AESCCM_close, + (uint32) AESCCM_Params_init, + (uint32) AESCCM_Operation_init, + (uint32) AESCCM_oneStepEncrypt, + (uint32) AESCCM_oneStepDecrypt, + (uint32) AESECB_init, + (uint32) AESECB_open, + (uint32) AESECB_close, + (uint32) AESECB_Params_init, + (uint32) AESECB_Operation_init, + (uint32) AESECB_oneStepEncrypt, + (uint32) AESECB_oneStepDecrypt, + (uint32) CryptoKeyPlaintext_initKey, + (uint32) CryptoKeyPlaintext_initBlankKey }; + +// Swi APIs needed by BLE controller +rtosApiTblPtr_t rtosApiTable[] = { (uint32_t) Swi_disable, (uint32_t) Swi_restore }; + +// BLE Stack Configuration Structure +const stackSpecific_t bleStackConfig = { .maxNumConns = MAX_NUM_BLE_CONNS, + .maxNumPDUs = MAX_NUM_PDU, + .maxPduSize = 0, + .maxNumPSM = L2CAP_NUM_PSM, + .maxNumCoChannels = L2CAP_NUM_CO_CHANNELS, + .maxWhiteListElems = MAX_NUM_WL_ENTRIES, + .maxResolvListElems = CFG_MAX_NUM_RL_ENTRIES, + .pfnBMAlloc = &pfnBMAlloc, + .pfnBMFree = &pfnBMFree, + .rfDriverParams.powerUpDurationMargin = RF_POWER_UP_DURATION_MARGIN, + .rfDriverParams.inactivityTimeout = RF_INACTIVITY_TIMEOUT, + .rfDriverParams.powerUpDuration = RF_POWER_UP_DURATION, + .rfDriverParams.pErrCb = &(RF_ERR_CB), + .eccParams = &eccParams_NISTP256, + .fastStateUpdateCb = NULL, + .bleStackType = 0, +#ifdef CC2652RB_LAUNCHXL + .extStackSettings = EXTENDED_STACK_SETTINGS | CC2652RB_OVERRIDE_USED, +#else + .extStackSettings = EXTENDED_STACK_SETTINGS, +#endif + .maxNumCteBuffers = MAX_NUM_CTE_BUFS }; + +uint16_t bleUserCfg_maxPduSize = MAX_PDU_SIZE; + +#ifdef OSAL_SNV_EXTFLASH +const extflashDrvTblPtr_t extflashDriverTable[] = { (uint32) ExtFlash_open, (uint32) ExtFlash_close, (uint32) ExtFlash_read, + (uint32) ExtFlash_write, (uint32) ExtFlash_erase }; +#endif // OSAL_SNV_EXTFLASH + +// Table for Driver can be found in icall_user_config.c +// if a driver is not to be used, then the pointer shoul dbe set to NULL, +// for this example, this is done in ble_user_config.h +const drvTblPtr_t driverTable = { + .rfDrvTbl = rfDriverTableBLE, + .eccDrvTbl = eccDriverTable, + .cryptoDrvTbl = cryptoDriverTableBLE, + .trngDrvTbl = trngDriverTable, + .rtosApiTbl = rtosApiTable, + .nvintfStructPtr = &nvintfFncStruct, +#ifdef OSAL_SNV_EXTFLASH + .extflashDrvTbl = extflashDriverTable, +#endif // OSAL_SNV_EXTFLASH +}; + +const boardConfig_t boardConfig = { + .rfFeModeBias = RF_FE_MODE_AND_BIAS, + .rfRegTbl = (regOverride_t *) pOverrides_bleCommon, + .rfRegTbl1M = (regOverride_t *) pOverrides_ble1Mbps, +#if defined(BLE_V50_FEATURES) && (BLE_V50_FEATURES & (PHY_2MBPS_CFG | PHY_LR_CFG)) + // Currently, no overrides for 2M and Coded, so exclude from build. + .rfRegTbl2M = (regOverride_t *) pOverrides_ble2Mbps, + .rfRegTblCoded = (regOverride_t *) pOverrides_bleCoded, +#endif // PHY_2MBPS_CFG | PHY_LR_CFG + .txPwrTbl = &appTxPwrTbl, +#if defined(CC13X2P) +#if defined(CC13X2P_2_LAUNCHXL) + .txPwrBackoffTbl = &appTxPwrBackoffTbl, +#else + .txPwrBackoffTbl = NULL, +#endif // defined(CC13X2P_2_LAUNCHXL) + .rfRegOverrideTxStdTblptr = (regOverride_t *) pOverrides_bleTxStd, // Default PA + .rfRegOverrideTx20TblPtr = (regOverride_t *) pOverrides_bleTx20, // High power PA +#endif // CC13X2P +#if defined(RTLS_CTE) + .rfRegOverrideCtePtr = (regOverride_t *) (pOverrides_bleCommon + BLE_STACK_OVERRIDES_OFFSET + CTE_OVERRIDES_OFFSET), + .cteAntennaPropPtr = &appCTEAntProp, +#else + .rfRegOverrideCtePtr = NULL, + .cteAntennaPropPtr = NULL, +#endif + .privOverrideOffset = BLE_STACK_OVERRIDES_OFFSET + PRIVACY_OVERRIDE_OFFSET, +#if defined(USE_COEX) + .coexUseCaseConfigPtr = &coexSysConfig, +#else + .coexUseCaseConfigPtr = NULL, +#endif +}; + +#else /* !(ICALL_JT) */ + +// RF Driver API Table +rfDrvTblPtr_t rfDriverTable[] = { + (uint32) RF_open, + (uint32) driverTable_fnSpinlock, // RF_close +#ifdef RF_SINGLEMODE + (uint32) RF_postCmd, +#else // !RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_postCmd +#endif // RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_pendCmd +#ifdef RF_SINGLEMODE + (uint32) RF_runCmd, +#else // !RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_runCmd +#endif // RF_SINGLEMODE + (uint32) RF_cancelCmd, + (uint32) RF_flushCmd, + (uint32) driverTable_fnSpinlock, // RF_yield + (uint32) RF_Params_init, + (uint32) RF_runImmediateCmd, + (uint32) RF_runDirectCmd, + (uint32) RF_ratCompare(uint32) driverTable_fnSpinlock, // RF_ratCapture + (uint32) driverTable_fnSpinlock, // RF_ratDisableChannel + (uint32) RF_getCurrentTime, + (uint32) RF_getRssi, + (uint32) RF_getInfo, + (uint32) RF_getCmdOp, + (uint32) RF_control, + (uint32) driverTable_fnSpinlock, // RF_getTxPower + (uint32) RF_setTxPower, // RF_setTxPower + (uint32) driverTable_fnSpinlock, // RF_TxPowerTable_findPowerLevel + (uint32) driverTable_fnSpinlock, // RF_TxPowerTable_findValue +#ifndef RF_SINGLEMODE + (uint32) RF_scheduleCmd, + (uint32) RF_runScheduleCmd, + (uint32) driverTable_fnSpinlock // RF_requestAccess +#endif // !RF_SINGLEMODE +}; + +// ECC Driver API Table +eccDrvTblPtr_t eccDriverTable[] = { (uint32) ECDH_init, + (uint32) ECDH_Params_init, + (uint32) ECDH_open, + (uint32) ECDH_close, + (uint32) ECDH_OperationGeneratePublicKey_init, + (uint32) ECDH_OperationComputeSharedSecret_init, + (uint32) ECDH_generatePublicKey, + (uint32) ECDH_computeSharedSecret }; + +// Crypto Driver API Table +cryptoDrvTblPtr_t cryptoDriverTable[] = { (uint32) AESCCM_init, + (uint32) AESCCM_open, + (uint32) AESCCM_close, + (uint32) AESCCM_Params_init, + (uint32) AESCCM_Operation_init, + (uint32) AESCCM_oneStepEncrypt, + (uint32) AESCCM_oneStepDecrypt, + (uint32) AESECB_init, + (uint32) AESECB_open, + (uint32) AESECB_close, + (uint32) AESECB_Params_init, + (uint32) AESECB_Operation_init, + (uint32) AESECB_oneStepEncrypt, + (uint32) AESECB_oneStepDecrypt, + (uint32) CryptoKeyPlaintext_initKey, + (uint32) CryptoKeyPlaintext_initBlankKey }; + +trngDrvTblPtr_t trngDriverTable[] = { (uint32) TRNG_init, (uint32) TRNG_open, (uint32) TRNG_generateEntropy, (uint32) TRNG_close }; + +#endif /* ICALL_JT */ + +/******************************************************************************* + * @fn RegisterAssertCback + * + * @brief This routine registers the Application's assert handler. + * + * input parameters + * + * @param appAssertHandler - Application's assert handler. + * + * output parameters + * + * @param None. + * + * @return None. + */ +void RegisterAssertCback(assertCback_t appAssertHandler) +{ + appAssertCback = appAssertHandler; + +#ifdef EXT_HAL_ASSERT + // also set the Assert callback pointer used by halAssertHandlerExt + // Note: Normally, this pointer will be intialized by the stack, but in the + // event HAL_ASSERT is used by the Application, we initialize it + // directly here. + halAssertCback = appAssertHandler; +#endif // EXT_HAL_ASSERT + + return; +} + +/******************************************************************************* + * @fn driverTable_fnSpinLock + * + * @brief This routine is used to trap calls to unpopulated indexes of + * driver function pointer tables. + * + * input parameters + * + * @param None. + * + * output parameters + * + * @param None. + * + * @return None. + */ +void driverTable_fnSpinlock(void) +{ + volatile uint8 i = 1; + + while (i) + ; +} + +/******************************************************************************* + * @fn DefaultAssertCback + * + * @brief This is the Application default assert callback, in the event + * none is registered. + * + * input parameters + * + * @param assertCause - Assert cause as defined in hal_assert.h. + * @param assertSubcause - Optional assert subcause (see hal_assert.h). + * + * output parameters + * + * @param None. + * + * @return None. + */ +void DefaultAssertCback(uint8 assertCause, uint8 assertSubcause1) +{ +#ifdef HAL_ASSERT_SPIN + driverTable_fnSpinlock(); +#endif // HAL_ASSERT_SPIN + + return; +} + +// Application Assert Callback Function Pointer +assertCback_t appAssertCback = DefaultAssertCback; + +/******************************************************************************* + */ diff --git a/src/platform/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h b/src/platform/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h index efca6840f5d25d..04e91bae54616b 100644 --- a/src/platform/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h +++ b/src/platform/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h @@ -39,10 +39,14 @@ /* Enable Hardware Acceleration */ -#define MBEDTLS_ECJPAKE_ALT #define MBEDTLS_AES_ALT -#define MBEDTLS_SHA256_ALT +#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT +#define MBEDTLS_ECDH_GEN_PUBLIC_ALT +#define MBEDTLS_ECDSA_SIGN_ALT +#define MBEDTLS_ECDSA_VERIFY_ALT +#define MBEDTLS_ECJPAKE_ALT #define MBEDTLS_ENTROPY_HARDWARE_ALT +#define MBEDTLS_SHA256_ALT /** * Enable Crypto and Entropy modules diff --git a/src/platform/cc13x2_26x2/crypto/ecdh_alt.c b/src/platform/cc13x2_26x2/crypto/ecdh_alt.c new file mode 100644 index 00000000000000..a3074a9c8a2435 --- /dev/null +++ b/src/platform/cc13x2_26x2/crypto/ecdh_alt.c @@ -0,0 +1,314 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021 Texas Instruments Incorporated + * + * 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. + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined MBEDTLS_ECDH_COMPUTE_SHARED_ALT || defined MBEDTLS_ECDH_GEN_PUBLIC_ALT + +#include + +#include +#include +#include +#include + +#include "ti_drivers_config.h" + +#include +#include +#include + +/* Parameter validation macros based on platform_util.h */ +#define ECDH_VALIDATE_RET(cond) MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_ECP_BAD_INPUT_DATA) +#define ECDH_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) + +#if defined MBEDTLS_ECDH_GEN_PUBLIC_ALT +/* + * Generate public key (restartable version) + */ +static int ecdh_gen_public_restartable(mbedtls_ecp_group * grp, mbedtls_mpi * d, mbedtls_ecp_point * Q, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng, + mbedtls_ecp_restart_ctx * rs_ctx) +{ + int ret = 0; + size_t plen = grp->nbits / 8U; + uint8_t * q_buf = (uint8_t *) mbedtls_calloc(1, (plen * 2U) + 1); + uint8_t * d_buf = (uint8_t *) mbedtls_calloc(1, plen); + CryptoKey myPrivateKey; + CryptoKey myPublicKey; + ECDH_Config config = { 0 }; + ECDH_Handle handle = NULL; + ECDH_OperationGeneratePublicKey operationGeneratePublicKey; + ECDHCC26X2_HWAttrs hwAttrs = { 0 }; + ECDHCC26X2_Object object = { 0 }; + + if (NULL == q_buf || NULL == d_buf) + { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + + hwAttrs.intPriority = (1 << 5); + + config.object = (void *) &object; + config.hwAttrs = (void *) &hwAttrs; + + handle = ECDH_construct(&config, NULL); + + if (NULL == handle) + { + ret = MBEDTLS_ERR_ECP_HW_ACCEL_FAILED; + goto cleanup; + } + + CryptoKeyPlaintext_initKey(&myPrivateKey, d_buf, plen); + CryptoKeyPlaintext_initKey(&myPublicKey, q_buf, (plen * 2U) + 1); + + if (0 != f_rng(p_rng, d_buf, plen)) + { + ret = MBEDTLS_ERR_ECP_RANDOM_FAILED; + goto cleanup; + } + + ECDH_OperationGeneratePublicKey_init(&operationGeneratePublicKey); + operationGeneratePublicKey.myPrivateKey = &myPrivateKey; + operationGeneratePublicKey.myPublicKey = &myPublicKey; + + /* Load the ROM curve params */ + switch (grp->id) + { + case MBEDTLS_ECP_DP_SECP224R1: + operationGeneratePublicKey.curve = &ECCParams_NISTP224; + break; + + case MBEDTLS_ECP_DP_SECP256R1: + operationGeneratePublicKey.curve = &ECCParams_NISTP256; + break; + + case MBEDTLS_ECP_DP_SECP384R1: + operationGeneratePublicKey.curve = &ECCParams_NISTP384; + break; + + case MBEDTLS_ECP_DP_SECP521R1: + operationGeneratePublicKey.curve = &ECCParams_NISTP521; + break; + + case MBEDTLS_ECP_DP_BP256R1: + operationGeneratePublicKey.curve = &ECCParams_BrainpoolP256R1; + break; + + case MBEDTLS_ECP_DP_BP384R1: + operationGeneratePublicKey.curve = &ECCParams_BrainpoolP384R1; + break; + + case MBEDTLS_ECP_DP_BP512R1: + operationGeneratePublicKey.curve = &ECCParams_BrainpoolP512R1; + break; + + case MBEDTLS_ECP_DP_CURVE25519: + operationGeneratePublicKey.curve = &ECCParams_Curve25519; + break; + + default: + /* Possible extension to load an arbitrary curve */ + ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + goto cleanup; + } + + if (ECDH_STATUS_SUCCESS == ECDH_generatePublicKey(handle, &operationGeneratePublicKey)) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; + } + + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(d, d_buf, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&(Q->X), q_buf + 1, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&(Q->Y), q_buf + 1 + plen, plen)); + +cleanup: + mbedtls_free(q_buf); + mbedtls_free(d_buf); + + if (NULL != handle) + { + ECDH_close(handle); + } + + return (ret); +} + +/* + * Generate public key + */ +int mbedtls_ecdh_gen_public(mbedtls_ecp_group * grp, mbedtls_mpi * d, mbedtls_ecp_point * Q, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + ECDH_VALIDATE_RET(grp != NULL); + ECDH_VALIDATE_RET(d != NULL); + ECDH_VALIDATE_RET(Q != NULL); + ECDH_VALIDATE_RET(f_rng != NULL); + return (ecdh_gen_public_restartable(grp, d, Q, f_rng, p_rng, NULL)); +} +#endif /* MBEDTLS_ECDH_GEN_PUBLIC_ALT */ + +#if defined MBEDTLS_ECDH_COMPUTE_SHARED_ALT +/* + * Compute shared secret (SEC1 3.3.1) + */ +static int ecdh_compute_shared_restartable(mbedtls_ecp_group * grp, mbedtls_mpi * z, const mbedtls_ecp_point * Q, + const mbedtls_mpi * d, int (*f_rng)(void *, unsigned char *, size_t), void * p_rng, + mbedtls_ecp_restart_ctx * rs_ctx) +{ + int ret = 0; + size_t plen = grp->nbits / 8U; + uint8_t * q_buf = (uint8_t *) mbedtls_calloc(1, (plen * 2U) + 1); + uint8_t * s_buf = (uint8_t *) mbedtls_calloc(1, (plen * 2U) + 1); + uint8_t * d_buf = (uint8_t *) mbedtls_calloc(1, plen); + CryptoKey myPrivateKey; + CryptoKey theirPublicKey; + CryptoKey sharedSecret; + ECDH_Config config = { 0 }; + ECDH_Handle handle = NULL; + ECDH_OperationComputeSharedSecret operationComputeSharedSecret; + ECDHCC26X2_HWAttrs hwAttrs = { 0 }; + ECDHCC26X2_Object object = { 0 }; + + if (NULL == q_buf || NULL == s_buf || NULL == d_buf) + { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + + hwAttrs.intPriority = (1 << 5); + + config.object = (void *) &object; + config.hwAttrs = (void *) &hwAttrs; + + handle = ECDH_construct(&config, NULL); + + if (NULL == handle) + { + ret = MBEDTLS_ERR_ECP_HW_ACCEL_FAILED; + goto cleanup; + } + + CryptoKeyPlaintext_initKey(&sharedSecret, s_buf, (2U * plen) + 1); + + /* The driver consumes network byte order. Copy this number and reverse them again. */ + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(d, d_buf, plen)); + CryptoKeyPlaintext_initKey(&myPrivateKey, d_buf, plen); + + /* The driver consumes an octet string in network byte order. Copy this + * point and reverse them again. */ + q_buf[0] = 0x04; + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&(Q->X), q_buf + 1, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&(Q->Y), q_buf + 1 + plen, plen)); + CryptoKeyPlaintext_initKey(&theirPublicKey, q_buf, (2U * plen) + 1); + + ECDH_OperationComputeSharedSecret_init(&operationComputeSharedSecret); + operationComputeSharedSecret.myPrivateKey = &myPrivateKey; + operationComputeSharedSecret.theirPublicKey = &theirPublicKey; + operationComputeSharedSecret.sharedSecret = &sharedSecret; + + /* Load the ROM curve params */ + switch (grp->id) + { + case MBEDTLS_ECP_DP_SECP224R1: + operationComputeSharedSecret.curve = &ECCParams_NISTP224; + break; + + case MBEDTLS_ECP_DP_SECP256R1: + operationComputeSharedSecret.curve = &ECCParams_NISTP256; + break; + + case MBEDTLS_ECP_DP_SECP384R1: + operationComputeSharedSecret.curve = &ECCParams_NISTP384; + break; + + case MBEDTLS_ECP_DP_SECP521R1: + operationComputeSharedSecret.curve = &ECCParams_NISTP521; + break; + + case MBEDTLS_ECP_DP_BP256R1: + operationComputeSharedSecret.curve = &ECCParams_BrainpoolP256R1; + break; + + case MBEDTLS_ECP_DP_BP384R1: + operationComputeSharedSecret.curve = &ECCParams_BrainpoolP384R1; + break; + + case MBEDTLS_ECP_DP_BP512R1: + operationComputeSharedSecret.curve = &ECCParams_BrainpoolP512R1; + break; + + case MBEDTLS_ECP_DP_CURVE25519: + operationComputeSharedSecret.curve = &ECCParams_Curve25519; + break; + + default: + /* Possible extension to load an arbitrary curve */ + ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + goto cleanup; + } + + if (ECDH_STATUS_SUCCESS == ECDH_computeSharedSecret(handle, &operationComputeSharedSecret)) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; + } + + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(z, s_buf + 1, plen)); + +cleanup: + mbedtls_free(q_buf); + mbedtls_free(d_buf); + mbedtls_free(s_buf); + + if (NULL != handle) + { + ECDH_close(handle); + } + + return (ret); +} + +/* + * Compute shared secret (SEC1 3.3.1) + */ +int mbedtls_ecdh_compute_shared(mbedtls_ecp_group * grp, mbedtls_mpi * z, const mbedtls_ecp_point * Q, const mbedtls_mpi * d, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + ECDH_VALIDATE_RET(grp != NULL); + ECDH_VALIDATE_RET(Q != NULL); + ECDH_VALIDATE_RET(d != NULL); + ECDH_VALIDATE_RET(z != NULL); + return (ecdh_compute_shared_restartable(grp, z, Q, d, f_rng, p_rng, NULL)); +} +#endif /* MBEDTLS_ECDH_COMPUTE_SHARED_ALT */ + +#endif /* MBEDTLS_ECDH_COMPUTE_SHARED_ALT || MBEDTLS_ECDH_GEN_PUBLIC_ALT */ diff --git a/src/platform/cc13x2_26x2/crypto/ecdsa_alt.c b/src/platform/cc13x2_26x2/crypto/ecdsa_alt.c new file mode 100755 index 00000000000000..18bb44fd1364e3 --- /dev/null +++ b/src/platform/cc13x2_26x2/crypto/ecdsa_alt.c @@ -0,0 +1,289 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021 Texas Instruments Incorporated + * + * 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. + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined MBEDTLS_ECDSA_VERIFY_ALT || defined MBEDTLS_ECDSA_SIGN_ALT + +/* NOTE: The TI drivers consume these points and big numbers in network byte + * order. This is in contrast to the mbedtls_mpi structures which story + * these numbers and points in little endian byte order. This file uses + * the mpi functions to re-write the buffers into network byte order. + */ + +#include + +#include +#include +#include +#include + +#include "ti_drivers_config.h" + +#include +#include +#include + +#ifdef MBEDTLS_ECDSA_VERIFY_ALT + +/* + * Verify ECDSA signature of hashed message + */ +int mbedtls_ecdsa_verify(mbedtls_ecp_group * grp, const unsigned char * buf, size_t blen, const mbedtls_ecp_point * Q, + const mbedtls_mpi * r, const mbedtls_mpi * s) +{ + int ret = 0; + size_t plen = grp->nbits / 8U; + uint8_t * r_buf = (uint8_t *) mbedtls_calloc(1, plen); + uint8_t * s_buf = (uint8_t *) mbedtls_calloc(1, plen); + uint8_t * q_buf = (uint8_t *) mbedtls_calloc(1, (plen * 2U) + 1); + CryptoKey theirPublicKey; + ECDSA_Config config = { 0 }; + ECDSA_Handle handle = NULL; + ECDSA_OperationVerify operationVerify; + ECDSACC26X2_HWAttrs hwAttrs = { 0 }; + ECDSACC26X2_Object object = { 0 }; + + if (NULL == r_buf || NULL == s_buf || NULL == q_buf) + { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + + hwAttrs.intPriority = (1 << 5); + hwAttrs.trngIntPriority = (1 << 5); + + config.object = (void *) &object; + config.hwAttrs = (void *) &hwAttrs; + + handle = ECDSA_construct(&config, NULL); + + if (NULL == handle) + { + ret = MBEDTLS_ERR_ECP_HW_ACCEL_FAILED; + goto cleanup; + } + + /* The driver consumes an octet string in network byte order. Copy this + * point and reverse them again. */ + q_buf[0] = 0x04; + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&(Q->X), q_buf + 1, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&(Q->Y), q_buf + 1 + plen, plen)); + CryptoKeyPlaintext_initKey(&theirPublicKey, q_buf, (2U * plen) + 1); + + /* The driver also consumes the r and s in network byte order. Copy these + * buffers and them reverse them again */ + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(r, r_buf, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(s, s_buf, plen)); + + /* prepare the operation */ + ECDSA_OperationVerify_init(&operationVerify); + operationVerify.theirPublicKey = &theirPublicKey; + operationVerify.hash = buf; + operationVerify.r = r_buf; + operationVerify.s = s_buf; + + /* Load the ROM curve params */ + switch (grp->id) + { + case MBEDTLS_ECP_DP_SECP224R1: + operationVerify.curve = &ECCParams_NISTP224; + break; + + case MBEDTLS_ECP_DP_SECP256R1: + operationVerify.curve = &ECCParams_NISTP256; + break; + + case MBEDTLS_ECP_DP_SECP384R1: + operationVerify.curve = &ECCParams_NISTP384; + break; + + case MBEDTLS_ECP_DP_SECP521R1: + operationVerify.curve = &ECCParams_NISTP521; + break; + + case MBEDTLS_ECP_DP_BP256R1: + operationVerify.curve = &ECCParams_BrainpoolP256R1; + break; + + case MBEDTLS_ECP_DP_BP384R1: + operationVerify.curve = &ECCParams_BrainpoolP384R1; + break; + + case MBEDTLS_ECP_DP_BP512R1: + operationVerify.curve = &ECCParams_BrainpoolP512R1; + break; + + case MBEDTLS_ECP_DP_CURVE25519: + operationVerify.curve = &ECCParams_Curve25519; + break; + + default: + /* Possible extension to load an arbitrary curve */ + ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + goto cleanup; + } + + if (ECDSA_STATUS_SUCCESS == ECDSA_verify(handle, &operationVerify)) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_ECP_VERIFY_FAILED; + } + +cleanup: + mbedtls_free(r_buf); + mbedtls_free(s_buf); + mbedtls_free(q_buf); + + if (NULL != handle) + { + ECDSA_close(handle); + } + + return ret; +} + +#endif /* MBEDTLS_ECDSA_VERIFY_ALT */ + +#ifdef MBEDTLS_ECDSA_SIGN_ALT + +/* + * Compute ECDSA signature of a hashed message + */ +int mbedtls_ecdsa_sign(mbedtls_ecp_group * grp, mbedtls_mpi * r, mbedtls_mpi * s, const mbedtls_mpi * d, const unsigned char * buf, + size_t blen, int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + int ret = 0; + size_t plen = grp->nbits / 8U; + uint8_t * r_buf = (uint8_t *) mbedtls_calloc(1, plen); + uint8_t * s_buf = (uint8_t *) mbedtls_calloc(1, plen); + uint8_t * d_buf = (uint8_t *) mbedtls_calloc(1, plen); + CryptoKey myPrivateKey; + ECDSA_Config config = { 0 }; + ECDSA_Handle handle = NULL; + ECDSA_OperationSign operationSign; + ECDSACC26X2_HWAttrs hwAttrs = { 0 }; + ECDSACC26X2_Object object = { 0 }; + + if (NULL == r_buf || NULL == s_buf || NULL == d_buf) + { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + + hwAttrs.intPriority = (1 << 5); + hwAttrs.trngIntPriority = (1 << 5); + + config.object = (void *) &object; + config.hwAttrs = (void *) &hwAttrs; + + handle = ECDSA_construct(&config, NULL); + + if (NULL == handle) + { + ret = MBEDTLS_ERR_ECP_HW_ACCEL_FAILED; + goto cleanup; + } + + /* The driver consumes numbers in network byte order */ + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(d, d_buf, plen)); + + CryptoKeyPlaintext_initKey(&myPrivateKey, d_buf, plen); + ECDSA_OperationSign_init(&operationSign); + operationSign.myPrivateKey = &myPrivateKey; + operationSign.hash = buf; + operationSign.r = r_buf; + operationSign.s = s_buf; + + /* Load the ROM curve params */ + switch (grp->id) + { + case MBEDTLS_ECP_DP_SECP224R1: + operationSign.curve = &ECCParams_NISTP224; + break; + + case MBEDTLS_ECP_DP_SECP256R1: + operationSign.curve = &ECCParams_NISTP256; + break; + + case MBEDTLS_ECP_DP_SECP384R1: + operationSign.curve = &ECCParams_NISTP384; + break; + + case MBEDTLS_ECP_DP_SECP521R1: + operationSign.curve = &ECCParams_NISTP521; + break; + + case MBEDTLS_ECP_DP_BP256R1: + operationSign.curve = &ECCParams_BrainpoolP256R1; + break; + + case MBEDTLS_ECP_DP_BP384R1: + operationSign.curve = &ECCParams_BrainpoolP384R1; + break; + + case MBEDTLS_ECP_DP_BP512R1: + operationSign.curve = &ECCParams_BrainpoolP512R1; + break; + + case MBEDTLS_ECP_DP_CURVE25519: + operationSign.curve = &ECCParams_Curve25519; + break; + + default: + /* Possible extension to load an arbitrary curve */ + ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + goto cleanup; + } + + if (ECDSA_STATUS_SUCCESS == ECDSA_sign(handle, &operationSign)) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_ECP_VERIFY_FAILED; + } + + /* The driver produces r and s in network byte order. copy into mbedtls mpi + * format. This incurs an extra byte reversal when written to ASN1. */ + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(r, r_buf, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(s, s_buf, plen)); + +cleanup: + mbedtls_free(r_buf); + mbedtls_free(s_buf); + mbedtls_free(d_buf); + + if (NULL != handle) + { + ECDSA_close(handle); + } + + return ret; +} +#endif /* MBEDTLS_ECDSA_SIGN_ALT */ + +#endif /* defined MBEDTLS_ECDSA_VERIFY_ALT || defined MBEDTLS_ECDSA_SIGN_ALT */ diff --git a/src/platform/cc13x2_26x2/crypto/sha256_alt.c b/src/platform/cc13x2_26x2/crypto/sha256_alt.c index 8dabab6f88dff3..0ef01f48fe34ba 100644 --- a/src/platform/cc13x2_26x2/crypto/sha256_alt.c +++ b/src/platform/cc13x2_26x2/crypto/sha256_alt.c @@ -136,6 +136,8 @@ void mbedtls_sha256_clone(mbedtls_sha256_context * dst, const mbedtls_sha256_con dst->object.bytesInBuffer = src->object.bytesInBuffer; dst->object.bytesProcessed = src->object.bytesProcessed; memcpy(dst->object.buffer, src->object.buffer, sizeof(dst->object.buffer)); + // copy the digest to support cloning after finalization has happened + memcpy(dst->object.digest, src->object.digest, sizeof(dst->object.digest)); } int mbedtls_sha256_finish_ret(mbedtls_sha256_context * ctx, unsigned char output[32]) diff --git a/third_party/ti_simplelink_sdk/BUILD.gn b/third_party/ti_simplelink_sdk/BUILD.gn index 73e9b3e965603e..f968324d78170f 100644 --- a/third_party/ti_simplelink_sdk/BUILD.gn +++ b/third_party/ti_simplelink_sdk/BUILD.gn @@ -48,6 +48,8 @@ mbedtls_target("mbedtls") { # Hardware acceleration sources = [ "${chip_root}/src/platform/cc13x2_26x2/crypto/aes_alt.c", + "${chip_root}/src/platform/cc13x2_26x2/crypto/ecdh_alt.c", + "${chip_root}/src/platform/cc13x2_26x2/crypto/ecdsa_alt.c", "${chip_root}/src/platform/cc13x2_26x2/crypto/ecjpake_alt.c", "${chip_root}/src/platform/cc13x2_26x2/crypto/sha256_alt.c", ] diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni index aebec3c96940f2..538bae5ee02413 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni @@ -87,6 +87,8 @@ template("ti_sysconfig") { "gcc", "--board", "/ti/boards/" + ti_simplelink_board, + "--rtos", + "freertos", ] foreach(source, sources) { @@ -316,6 +318,8 @@ template("ti_simplelink_sdk") { "${ti_simplelink_sdk_root}/source/ti/", "${ti_simplelink_sdk_root}/source/ti/dmm/", "${ti_simplelink_sdk_root}/source/ti/dmm/apps/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/source/activity/", "${ti_simplelink_sdk_root}/source/ti/common/nv", "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7", @@ -374,7 +378,7 @@ template("ti_simplelink_sdk") { if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { libs += [ - "${ti_simplelink_sdk_root}/source/ti/dmm/library/freertos/gcc/bin/dmmlib_cc26x2.a", + "${ti_simplelink_sdk_root}/source/ti/dmm/lib/gcc/m4f/libdmmlib_freertos.a", "${ti_simplelink_sdk_root}/source/ti/ble5stack/libraries/cc26x2r1/OneLib.a", "${ti_simplelink_sdk_root}/source/ti/ble5stack/libraries/cc26x2r1/StackWrapper.a", "${ti_simplelink_sdk_root}/source/ti/ble5stack/libraries/cc26x2r1/ble_r2.symbols", @@ -391,8 +395,10 @@ template("ti_simplelink_sdk") { source_set("${sdk_target_name}_dmm") { defines = [] - include_dirs = [] - + include_dirs = [ + "${chip_root}/third_party/openthread/repo/include/", + "${chip_root}/src/", + ] configs -= [ "${build_root}/config/compiler:warnings_default" ] # removed for # -Wshadow @@ -409,7 +415,6 @@ template("ti_simplelink_sdk") { "${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/ble_user_config.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", @@ -418,11 +423,12 @@ template("ti_simplelink_sdk") { "${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/itm/itm.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", ]