Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: Mesh: add tf-m support for ble mesh #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/zephyr/bluetooth/mesh/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_KEYS_H_

#include <stdint.h>
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA || defined CONFIG_BT_MESH_USES_TFM_PSA
#include <psa/crypto.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA || defined CONFIG_BT_MESH_USES_TFM_PSA

/** The structure that keeps representation of key. */
struct bt_mesh_key {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CONFIG_IPC_SERVICE=y
CONFIG_MBOX=y

CONFIG_HEAP_MEM_POOL_SIZE=8192

CONFIG_MAIN_STACK_SIZE=512
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512

CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=16


# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

# Controller
CONFIG_BT_LL_SW_SPLIT=y

# Disable unused Bluetooth features
CONFIG_BT_CTLR_DUP_FILTER_LEN=0
CONFIG_BT_CTLR_LE_ENC=n
CONFIG_BT_CTLR_LE_PING=n
CONFIG_BT_DATA_LEN_UPDATE=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_CTLR_MIN_USED_CHAN=n
CONFIG_BT_CTLR_PRIVACY=n

CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y
CONFIG_BT_EXT_ADV=y
PavelVPV marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions samples/bluetooth/hci_rpmsg/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ tests:
platform_allow: nrf5340dk_nrf5340_cpunet
integration_platforms:
- nrf5340dk_nrf5340_cpunet
sample.bluetooth.hci_rpmsg.mesh.bt_ll_sw_split:
harness: bluetooth
tags: bluetooth
extra_args: CONF_FILE="nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf"
platform_allow: nrf5340dk_nrf5340_cpunet
integration_platforms:
- nrf5340dk_nrf5340_cpunet
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ if (BOARD STREQUAL bbc_microbit)
else()
target_sources(app PRIVATE src/board.c)
endif()

if (CONFIG_BUILD_WITH_TFM)
target_include_directories(app PRIVATE
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
)
endif()
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ For other boards, build and flash the application as follows:
Refer to your :ref:`board's documentation <boards>` for alternative
flash instructions if your board doesn't support the ``flash`` target.

To run the application on an :ref:`nrf5340dk_nrf5340`, a Bluetooth controller application
must also run on the network core. The :ref:`bluetooth-hci-rpmsg-sample` sample
application may be used. Build this sample with configuration
:zephyr_file:`samples/bluetooth/hci_rpmg/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf`
to enable mesh support.

Interacting with the sample
***************************

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Known issue: non secure platforms do not work with settings subsystem.
CONFIG_SETTINGS=n
CONFIG_BT_SETTINGS=n
1 change: 0 additions & 1 deletion samples/bluetooth/mesh/microbit_gatt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ CONFIG_BT_MESH_PB_ADV=n

CONFIG_BT=y
CONFIG_BT_DEVICE_NAME="Zephyr Mesh"
CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_BT_RX_STACK_SIZE=1400
CONFIG_BT_L2CAP_TX_BUF_COUNT=5
CONFIG_BT_EXT_ADV=n
Expand Down
1 change: 0 additions & 1 deletion samples/bluetooth/mesh/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CONFIG_SETTINGS=y
CONFIG_HWINFO=y

CONFIG_BT=y
CONFIG_BT_TINYCRYPT_ECC=y
PavelVPV marked this conversation as resolved.
Show resolved Hide resolved
CONFIG_BT_L2CAP_TX_BUF_COUNT=5
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_OBSERVER=y
Expand Down
1 change: 1 addition & 0 deletions samples/bluetooth/mesh/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tests:
- bbc_microbit
- qemu_x86
- nrf52840dk_nrf52840
- nrf5340dk_nrf5340_cpuapp_ns
integration_platforms:
- qemu_x86
tags: bluetooth
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ target_sources_ifdef(CONFIG_BOARD_BBC_MICROBIT app PRIVATE src/microbit.c)
if(NODE_ADDR)
zephyr_compile_definitions(NODE_ADDR=${NODE_ADDR})
endif()

if (CONFIG_BUILD_WITH_TFM)
target_include_directories(app PRIVATE
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
)
endif()
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh_demo/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ For other boards, build and flash the application as follows:

Refer to your :ref:`board's documentation <boards>` for alternative
flash instructions if your board doesn't support the ``flash`` target.

To run the application on an :ref:`nrf5340dk_nrf5340`, a Bluetooth controller application
must also run on the network core. The :ref:`bluetooth-hci-rpmsg-sample` sample
application may be used. Build this sample with configuration
:zephyr_file:`samples/bluetooth/hci_rpmg/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf`
to enable mesh support.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Known issue: non secure platforms do not work with settings subsystem.
CONFIG_SETTINGS=n
CONFIG_BT_SETTINGS=n
10 changes: 9 additions & 1 deletion samples/bluetooth/mesh_demo/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ CONFIG_MAIN_STACK_SIZE=512
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_BT=y
CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y

CONFIG_BT_CTLR_DUP_FILTER_LEN=0
CONFIG_BT_CTLR_LE_ENC=n
CONFIG_BT_CTLR_LE_PING=n
CONFIG_BT_DATA_LEN_UPDATE=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_CTLR_MIN_USED_CHAN=n
CONFIG_BT_CTLR_PRIVACY=n
CONFIG_BT_CTLR_CHAN_SEL_2=n

CONFIG_BT_MESH=y
CONFIG_BT_MESH_RELAY=y
CONFIG_BT_MESH_SUBNET_COUNT=1
Expand Down
1 change: 1 addition & 0 deletions samples/bluetooth/mesh_demo/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tests:
- bbc_microbit
- qemu_x86
- nrf52840dk_nrf52840
- nrf5340dk_nrf5340_cpuapp_ns
integration_platforms:
- qemu_x86
- bbc_microbit
Expand Down
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh_provisioner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(mesh_provisioner)

target_sources(app PRIVATE src/main.c)

if (CONFIG_BUILD_WITH_TFM)
target_include_directories(app PRIVATE
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
)
endif()
PavelVPV marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh_provisioner/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ For other boards, build and flash the application as follows:

Refer to your :ref:`board's documentation <boards>` for alternative
flash instructions if your board doesn't support the ``flash`` target.

To run the application on an :ref:`nrf5340dk_nrf5340`, a Bluetooth controller application
must also run on the network core. The :ref:`bluetooth-hci-rpmsg-sample` sample
application may be used. Build this sample with configuration
:zephyr_file:`samples/bluetooth/hci_rpmg/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf`
to enable mesh support.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Known issue: non secure platforms do not work with settings subsystem.
CONFIG_SETTINGS=n
CONFIG_BT_SETTINGS=n
10 changes: 9 additions & 1 deletion samples/bluetooth/mesh_provisioner/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_MAIN_THREAD_PRIORITY=-2

CONFIG_BT=y
CONFIG_BT_TINYCRYPT_ECC=y
#CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y

CONFIG_BT_CTLR_DUP_FILTER_LEN=0
CONFIG_BT_CTLR_LE_ENC=n
CONFIG_BT_CTLR_LE_PING=n
CONFIG_BT_DATA_LEN_UPDATE=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_CTLR_MIN_USED_CHAN=n
CONFIG_BT_CTLR_PRIVACY=n
CONFIG_BT_CTLR_CHAN_SEL_2=n

CONFIG_BT_MESH=y
CONFIG_BT_MESH_SUBNET_COUNT=1
CONFIG_BT_MESH_APP_KEY_COUNT=1
Expand Down
1 change: 1 addition & 0 deletions samples/bluetooth/mesh_provisioner/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ tests:
platform_allow:
- qemu_x86
- nrf52840dk_nrf52840
- nrf5340dk_nrf5340_cpuapp_ns
integration_platforms:
- qemu_x86
tags: bluetooth
14 changes: 11 additions & 3 deletions subsys/bluetooth/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,16 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV sol_pdu_rpl_srv.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_SOLICITATION solicitation.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_USES_TINYCRYPT crypto_tc.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_USES_MBEDTLS_PSA crypto_psa.c)
if (CONFIG_BT_MESH_USES_TINYCRYPT)
zephyr_library_sources(crypto_tc.c)
else()
zephyr_library_sources(crypto_psa.c)
endif()

zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS)

if (CONFIG_BUILD_WITH_TFM)
target_include_directories(${ZEPHYR_CURRENT_LIBRARY} PRIVATE
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
)
endif()
14 changes: 12 additions & 2 deletions subsys/bluetooth/mesh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if BT_MESH

choice BT_MESH_CRYPTO_LIB
prompt "Crypto library selection for mesh security"
default BT_MESH_USES_TFM_PSA if BUILD_WITH_TFM
default BT_MESH_USES_TINYCRYPT

config BT_MESH_USES_TINYCRYPT
Expand Down Expand Up @@ -53,9 +54,18 @@ config BT_MESH_USES_MBEDTLS_PSA
on Zephyr's settings subsystem.
Not possible to use for embedded devices yet.

config BT_MESH_USES_TFM_PSA
bool "Use TF-M PSA [EXPERIMENTAL]"
select EXPERIMENTAL
PavelVPV marked this conversation as resolved.
Show resolved Hide resolved
depends on BUILD_WITH_TFM
help
Use TF-M that implements PSA security framework. Support of TF-M is
experimental. It is only possible to use with platforms that TF-M supports.
For more platform details see TF-M documentation.

endchoice

if BT_MESH_USES_MBEDTLS_PSA
if BT_MESH_USES_MBEDTLS_PSA || BT_MESH_USES_TFM_PSA

config BT_MESH_PSA_KEY_ID_USER_MIN_OFFSET
int "Offset of BLE Mesh key id range regarding PSA_KEY_ID_USER_MIN"
Expand All @@ -69,7 +79,7 @@ config BT_MESH_PSA_KEY_ID_USER_MIN_OFFSET
for each application key, and two ids for the device key and device key candidate.
It should consider the Mesh Configuration Database instances if database enabled.

endif # BT_MESH_USES_MBEDTLS_PSA
endif # BT_MESH_USES_MBEDTLS_PSA || BT_MESH_USES_TFM_PSA

# Virtual option enabled whenever Generic Provisioning layer is needed
config BT_MESH_PROV
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/mesh/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum bt_mesh_key_type {
BT_MESH_KEY_TYPE_DEV
};

#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA || defined CONFIG_BT_MESH_USES_TFM_PSA

int bt_mesh_key_import(enum bt_mesh_key_type type, const uint8_t in[16], struct bt_mesh_key *out);
int bt_mesh_key_export(uint8_t out[16], const struct bt_mesh_key *in);
Expand Down