Skip to content

Commit

Permalink
[Silabs] DIC integration changes under DIC flag and DIC macro (#25694)
Browse files Browse the repository at this point in the history
* DIC integration changes under mqtt flag and DIC macro

* Restyled by clang-format

* changed use_mqtt flag to enable_dic

* added DIC comments

* Restyled by clang-format

* addressing review comments

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jan 11, 2024
1 parent 5218eb2 commit bf78d3d
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 6 deletions.
27 changes: 27 additions & 0 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ config("chip_examples_project_config") {
]
}

if (enable_dic) {
config("efr32_dic_config") {
include_dirs = [
"${chip_root}/third_party/silabs/mqtt/stack",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/include",
"${chip_root}/examples/platform/silabs/DIC/matter_abs_interface/include",
]
}

source_set("efr32-dic") {
sources = [
"${chip_root}/examples/platform/silabs/DIC/matter_abs_interface/src/dic.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/MQTT_transport.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp_alloc.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp_tcp.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp_tls_mbedtls.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp_tls_mbedtls_mem.c",
]
public_deps = [
"${chip_root}/src/inet",
"${chip_root}/src/lwip",
]
public_configs = [ ":efr32_dic_config" ]
}
}

source_set("efr-matter-shell") {
if (chip_build_libshell) {
defines = [ "ENABLE_CHIP_SHELL" ]
Expand Down
4 changes: 4 additions & 0 deletions examples/platform/silabs/SiWx917/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configSUPPORT_DYNAMIC_ALLOCATION (1)

#ifndef configTOTAL_HEAP_SIZE
#ifdef DIC_ENABLE
#define configTOTAL_HEAP_SIZE ((size_t)(44 * 1024))
#else
#define configTOTAL_HEAP_SIZE ((size_t)(34 * 1024))
#endif // DIC_ENABLE
#endif // configTOTAL_HEAP_SIZE

/* Optional functions - most linkers will remove unused functions anyway. */
Expand Down
32 changes: 32 additions & 0 deletions examples/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ config("chip_examples_project_config") {
]
}

if (enable_dic) {
config("efr32_dic_config") {
include_dirs = [
"${chip_root}/third_party/silabs/mqtt/stack",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/include",
"${chip_root}/examples/platform/silabs/DIC/matter_abs_interface/include",
]
}

source_set("efr32-dic") {
sources = [
"${chip_root}/examples/platform/silabs/DIC/matter_abs_interface/src/dic.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/MQTT_transport.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp_alloc.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp_tcp.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp_tls_mbedtls.c",
"${chip_root}/examples/platform/silabs/DIC/mqtt_transport_interface/src/altcp_tls_mbedtls_mem.c",
]
public_deps = [
"${chip_root}/src/inet",
"${chip_root}/src/lwip",
]
public_configs = [ ":efr32_dic_config" ]
}
}

source_set("openthread_core_config_efr32_chip_examples") {
if (chip_enable_openthread) {
sources = [ "project_include/OpenThreadConfig.h" ]
Expand Down Expand Up @@ -244,6 +271,11 @@ source_set("efr32-common") {
"${efr32_sdk_build_root}:silabs_config",
]

# MQTT
if (enable_dic) {
deps += [ "${examples_plat_dir}:efr32-dic" ]
}

include_dirs = [ "." ]

sources = [
Expand Down
6 changes: 5 additions & 1 deletion examples/platform/silabs/efr32/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */

#ifndef configTOTAL_HEAP_SIZE
#ifdef SL_WIFI
#ifdef DIC_ENABLE
#define configTOTAL_HEAP_SIZE ((size_t)(50 * 1024))
#else
#define configTOTAL_HEAP_SIZE ((size_t)(34 * 1024))
#else // SL_WIFI
#endif // DIC
#else // SL_WIFI
#if SL_CONFIG_OPENTHREAD_LIB == 1
#define configTOTAL_HEAP_SIZE ((size_t)(22 * 1024))
#else
Expand Down
4 changes: 4 additions & 0 deletions src/lwip/silabs/lwipopts-wf200.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@

#define LWIP_SOCKET 0

#ifdef DIC_ENABLE
#define MEM_SIZE 5632
#endif // DIC_ENABLE

#define LWIP_FREERTOS_USE_STATIC_TCPIP_TASK 1

#define LWIP_RAW 1
Expand Down
24 changes: 22 additions & 2 deletions src/platform/silabs/SiWx917/siwx917-chip-mbedtls-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
typedef void mbedtls_ecp_restart_ctx;
#endif

#ifdef DIC_ENABLE
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_RSA_NO_CRT
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
#define MBEDTLS_RSA_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SSL_IN_CONTENT_LEN 5120
#define MBEDTLS_SSL_OUT_CONTENT_LEN 1560
#define MBEDTLS_DEBUG_C
#define MBEDTLS_CIPHER_MODE_WITH_PADDING
#endif
#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf

#define MBEDTLS_AES_ROM_TABLES
Expand Down Expand Up @@ -114,8 +126,12 @@ typedef void mbedtls_ecp_restart_ctx;
#define MBEDTLS_X509_CSR_PARSE_C
#define MBEDTLS_X509_USE_C

#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */
#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
#ifdef DIC_ENABLE
#define MBEDTLS_MPI_MAX_SIZE 512 /**< Maximum number of bytes for usable MPIs. */
#else
#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */
#endif
#define MBEDTLS_ECP_MAX_BITS 256 /**< Maximum bit size of groups */
#define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */
Expand All @@ -124,7 +140,11 @@ typedef void mbedtls_ecp_restart_ctx;
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
#define MBEDTLS_SSL_MAX_CONTENT_LEN 900 /**< Maxium fragment length in bytes */
#else
#ifdef DIC_ENABLE
#define MBEDTLS_SSL_MAX_CONTENT_LEN 5120 /**< Maxium fragment length in bytes */
#else
#define MBEDTLS_SSL_MAX_CONTENT_LEN 768 /**< Maxium fragment length in bytes */
#endif // DIC
#endif

#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
Expand Down
15 changes: 14 additions & 1 deletion src/platform/silabs/efr32/efr32-chip-mbedtls-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#ifdef DIC_ENABLE
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_RSA_NO_CRT
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
#define MBEDTLS_RSA_C
#define MBEDTLS_SSL_IN_CONTENT_LEN 5120
#define MBEDTLS_SSL_OUT_CONTENT_LEN 1560
#endif // DIC_ENABLE

#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf

Expand Down Expand Up @@ -118,8 +127,12 @@
#define MBEDTLS_X509_CSR_PARSE_C
#define MBEDTLS_X509_USE_C

#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
#ifdef DIC_ENABLE
#define MBEDTLS_MPI_MAX_SIZE 512 /**< Maximum number of bytes for usable MPIs. */
#else
#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */
#endif // DIC_ENABLE
#define MBEDTLS_ECP_MAX_BITS 256 /**< Maximum bit size of groups */
#define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */
Expand Down
3 changes: 3 additions & 0 deletions src/platform/silabs/efr32/psa_crypto_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
#define PSA_WANT_ALG_HKDF
#define PSA_WANT_ALG_HMAC
#define PSA_WANT_KEY_TYPE_HMAC
#ifdef DIC_ENABLE
#define PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
#endif // DIC_ENABLE
#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
#define MBEDTLS_PSA_ACCEL_ALG_SHA_1
#define MBEDTLS_PSA_ACCEL_ALG_SHA_224
Expand Down
25 changes: 25 additions & 0 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ template("efr32_sdk") {
"PLATFORM_HEADER=\"platform-header.h\"",
"USE_NVM3=1",
"RSI_ARM_CM4F",
"SIWX_917",
"BRD4325A",
"CHIP_9117",
"RSI_BLE_ENABLE=1",
Expand All @@ -149,6 +150,9 @@ template("efr32_sdk") {
if (chip_enable_wifi_ipv4) {
defines += [ "CHIP_DEVICE_CONFIG_ENABLE_IPV4=1" ]
}
if (invoker.enable_dic) {
_include_dirs += [ "${chip_root}/third_party/silabs/mqtt/stack" ]
}

# Enabling led interface
if (use_wstk_leds) {
Expand Down Expand Up @@ -197,6 +201,9 @@ template("efr32_sdk") {
"${efr32_sdk_root}/platform/emdrv/uartdrv/config",
"${efr32_sdk_root}/hardware/driver/memlcd/inc/memlcd_usart",
]
if (enable_dic) {
defines += [ "DIC_ENABLE=1" ]
}
}

libs += [ "${sdk_support_root}/platform/emdrv/nvm3/lib/libnvm3_CM4_gcc.a" ]
Expand Down Expand Up @@ -340,6 +347,24 @@ template("efr32_sdk") {
if (defined(invoker.sources)) {
sources += invoker.sources
}
if (invoker.enable_dic) {
sources += [
"${chip_root}/third_party/mbedtls/repo/library/base64.c",
"${chip_root}/third_party/mbedtls/repo/library/debug.c",
"${chip_root}/third_party/mbedtls/repo/library/ecjpake.c",
"${chip_root}/third_party/mbedtls/repo/library/pem.c",
"${chip_root}/third_party/mbedtls/repo/library/rsa.c",
"${chip_root}/third_party/mbedtls/repo/library/rsa_internal.c",
"${chip_root}/third_party/mbedtls/repo/library/sha1.c",
"${chip_root}/third_party/mbedtls/repo/library/ssl_ciphersuites.c",
"${chip_root}/third_party/mbedtls/repo/library/ssl_cli.c",
"${chip_root}/third_party/mbedtls/repo/library/ssl_msg.c",
"${chip_root}/third_party/mbedtls/repo/library/ssl_srv.c",
"${chip_root}/third_party/mbedtls/repo/library/ssl_tls.c",
"${chip_root}/third_party/mbedtls/repo/library/x509.c",
"${chip_root}/third_party/silabs/mqtt/stack/mqtt.c",
]
}

public_configs = [ ":${sdk_target_name}_config" ]
}
Expand Down
14 changes: 12 additions & 2 deletions third_party/silabs/efr32_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ template("efr32_sdk") {
}

if (defined(invoker.chip_enable_wifi) && invoker.chip_enable_wifi) {
if (enable_dic) {
defines += [ "DIC_ENABLE=1" ]
}
if (chip_enable_wifi_ipv4) {
defines += [ "CHIP_DEVICE_CONFIG_ENABLE_IPV4=1" ]
}
Expand Down Expand Up @@ -330,7 +333,9 @@ template("efr32_sdk") {
"${efr32_sdk_root}/hardware/driver/memlcd/inc/memlcd_usart",
]
}

if (invoker.enable_dic) {
_include_dirs += [ "${chip_root}/third_party/silabs/mqtt/stack" ]
}
if (silabs_family == "efr32mg12") {
_include_dirs += [
"${efr32_sdk_root}/platform/Device/SiliconLabs/EFR32MG12P/Include",
Expand Down Expand Up @@ -651,7 +656,12 @@ template("efr32_sdk") {
"${sdk_support_root}/matter/efr32/${silabs_family}/${silabs_board}/autogen/sl_device_init_clocks.c",
"${sdk_support_root}/matter/efr32/${silabs_family}/${silabs_board}/autogen/sl_event_handler.c",
]

if (enable_dic) {
sources += [
"${chip_root}/third_party/silabs/mqtt/stack/mqtt.c",
"${efr32_sdk_root}/util/third_party/mbedtls/library/rsa_alt_helpers.c",
]
}
if (silabs_family != "mgm24") {
sources +=
[ "${efr32_sdk_root}/platform/radio/rail_lib/hal/efr32/hal_efr.c" ]
Expand Down
3 changes: 3 additions & 0 deletions third_party/silabs/silabs_board.gni
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ declare_args() {
use_SiWx917 = false
use_rs911x_sockets = false
chip_enable_ble_rs911x = false

#Disable MQTT my default
enable_dic = false
}

declare_args() {
Expand Down

0 comments on commit bf78d3d

Please sign in to comment.