Skip to content

Commit 327eb11

Browse files
alxelaxcarlescufi
authored andcommitted
Bluetooth: Mesh: add tf-m support for ble mesh
This PR adds ability to build mesh with tf-m psa for platforms those support tf-m. Signed-off-by: Aleksandr Khromykh <[email protected]>
1 parent 9748250 commit 327eb11

22 files changed

+132
-12
lines changed

include/zephyr/bluetooth/mesh/keys.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_KEYS_H_
1313

1414
#include <stdint.h>
15-
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA
15+
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA || defined CONFIG_BT_MESH_USES_TFM_PSA
1616
#include <psa/crypto.h>
1717
#endif
1818

1919
#ifdef __cplusplus
2020
extern "C" {
2121
#endif
2222

23-
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA
23+
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA || defined CONFIG_BT_MESH_USES_TFM_PSA
2424

2525
/** The structure that keeps representation of key. */
2626
struct bt_mesh_key {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
CONFIG_IPC_SERVICE=y
2+
CONFIG_MBOX=y
3+
4+
CONFIG_HEAP_MEM_POOL_SIZE=8192
5+
6+
CONFIG_MAIN_STACK_SIZE=512
7+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
8+
9+
CONFIG_BT=y
10+
CONFIG_BT_HCI_RAW=y
11+
CONFIG_BT_HCI_RAW_RESERVE=1
12+
CONFIG_BT_MAX_CONN=16
13+
14+
15+
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
16+
# Host number of completed commands does not follow normal flow control.
17+
CONFIG_BT_BUF_CMD_TX_COUNT=10
18+
19+
# Controller
20+
CONFIG_BT_LL_SW_SPLIT=y
21+
22+
# Disable unused Bluetooth features
23+
CONFIG_BT_CTLR_DUP_FILTER_LEN=0
24+
CONFIG_BT_CTLR_LE_ENC=n
25+
CONFIG_BT_CTLR_LE_PING=n
26+
CONFIG_BT_DATA_LEN_UPDATE=n
27+
CONFIG_BT_PHY_UPDATE=n
28+
CONFIG_BT_CTLR_MIN_USED_CHAN=n
29+
CONFIG_BT_CTLR_PRIVACY=n
30+
31+
CONFIG_BT_OBSERVER=y
32+
CONFIG_BT_BROADCASTER=y
33+
CONFIG_BT_EXT_ADV=y

samples/bluetooth/hci_rpmsg/sample.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,10 @@ tests:
8282
platform_allow: nrf5340dk_nrf5340_cpunet
8383
integration_platforms:
8484
- nrf5340dk_nrf5340_cpunet
85+
sample.bluetooth.hci_rpmsg.mesh.bt_ll_sw_split:
86+
harness: bluetooth
87+
tags: bluetooth
88+
extra_args: CONF_FILE="nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf"
89+
platform_allow: nrf5340dk_nrf5340_cpunet
90+
integration_platforms:
91+
- nrf5340dk_nrf5340_cpunet

samples/bluetooth/mesh/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ if (BOARD STREQUAL bbc_microbit)
1313
else()
1414
target_sources(app PRIVATE src/board.c)
1515
endif()
16+
17+
if (CONFIG_BUILD_WITH_TFM)
18+
target_include_directories(app PRIVATE
19+
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
20+
)
21+
endif()

samples/bluetooth/mesh/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ For other boards, build and flash the application as follows:
4444
Refer to your :ref:`board's documentation <boards>` for alternative
4545
flash instructions if your board doesn't support the ``flash`` target.
4646

47+
To run the application on an :ref:`nrf5340dk_nrf5340`, a Bluetooth controller application
48+
must also run on the network core. The :ref:`bluetooth-hci-rpmsg-sample` sample
49+
application may be used. Build this sample with configuration
50+
:zephyr_file:`samples/bluetooth/hci_rpmg/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf`
51+
to enable mesh support.
52+
4753
Interacting with the sample
4854
***************************
4955

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Known issue: non secure platforms do not work with settings subsystem.
2+
CONFIG_SETTINGS=n
3+
CONFIG_BT_SETTINGS=n

samples/bluetooth/mesh/microbit_gatt.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ CONFIG_BT_MESH_PB_ADV=n
1313

1414
CONFIG_BT=y
1515
CONFIG_BT_DEVICE_NAME="Zephyr Mesh"
16-
CONFIG_BT_TINYCRYPT_ECC=y
1716
CONFIG_BT_RX_STACK_SIZE=1400
1817
CONFIG_BT_L2CAP_TX_BUF_COUNT=5
1918
CONFIG_BT_EXT_ADV=n

samples/bluetooth/mesh/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ CONFIG_SETTINGS=y
88
CONFIG_HWINFO=y
99

1010
CONFIG_BT=y
11-
CONFIG_BT_TINYCRYPT_ECC=y
1211
CONFIG_BT_L2CAP_TX_BUF_COUNT=5
1312
CONFIG_BT_PERIPHERAL=y
1413
CONFIG_BT_OBSERVER=y

samples/bluetooth/mesh/sample.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ tests:
77
- bbc_microbit
88
- qemu_x86
99
- nrf52840dk_nrf52840
10+
- nrf5340dk_nrf5340_cpuapp_ns
1011
integration_platforms:
1112
- qemu_x86
1213
tags: bluetooth

samples/bluetooth/mesh_demo/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ target_sources_ifdef(CONFIG_BOARD_BBC_MICROBIT app PRIVATE src/microbit.c)
1212
if(NODE_ADDR)
1313
zephyr_compile_definitions(NODE_ADDR=${NODE_ADDR})
1414
endif()
15+
16+
if (CONFIG_BUILD_WITH_TFM)
17+
target_include_directories(app PRIVATE
18+
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
19+
)
20+
endif()

samples/bluetooth/mesh_demo/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ For other boards, build and flash the application as follows:
5454

5555
Refer to your :ref:`board's documentation <boards>` for alternative
5656
flash instructions if your board doesn't support the ``flash`` target.
57+
58+
To run the application on an :ref:`nrf5340dk_nrf5340`, a Bluetooth controller application
59+
must also run on the network core. The :ref:`bluetooth-hci-rpmsg-sample` sample
60+
application may be used. Build this sample with configuration
61+
:zephyr_file:`samples/bluetooth/hci_rpmg/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf`
62+
to enable mesh support.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Known issue: non secure platforms do not work with settings subsystem.
2+
CONFIG_SETTINGS=n
3+
CONFIG_BT_SETTINGS=n

samples/bluetooth/mesh_demo/prj.conf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ CONFIG_MAIN_STACK_SIZE=512
22
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
33

44
CONFIG_BT=y
5-
CONFIG_BT_TINYCRYPT_ECC=y
65
CONFIG_BT_OBSERVER=y
76
CONFIG_BT_BROADCASTER=y
87

8+
CONFIG_BT_CTLR_DUP_FILTER_LEN=0
9+
CONFIG_BT_CTLR_LE_ENC=n
10+
CONFIG_BT_CTLR_LE_PING=n
11+
CONFIG_BT_DATA_LEN_UPDATE=n
12+
CONFIG_BT_PHY_UPDATE=n
13+
CONFIG_BT_CTLR_MIN_USED_CHAN=n
14+
CONFIG_BT_CTLR_PRIVACY=n
15+
CONFIG_BT_CTLR_CHAN_SEL_2=n
16+
917
CONFIG_BT_MESH=y
1018
CONFIG_BT_MESH_RELAY=y
1119
CONFIG_BT_MESH_SUBNET_COUNT=1

samples/bluetooth/mesh_demo/sample.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ tests:
77
- bbc_microbit
88
- qemu_x86
99
- nrf52840dk_nrf52840
10+
- nrf5340dk_nrf5340_cpuapp_ns
1011
integration_platforms:
1112
- qemu_x86
1213
- bbc_microbit

samples/bluetooth/mesh_provisioner/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
77
project(mesh_provisioner)
88

99
target_sources(app PRIVATE src/main.c)
10+
11+
if (CONFIG_BUILD_WITH_TFM)
12+
target_include_directories(app PRIVATE
13+
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
14+
)
15+
endif()

samples/bluetooth/mesh_provisioner/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ For other boards, build and flash the application as follows:
5252

5353
Refer to your :ref:`board's documentation <boards>` for alternative
5454
flash instructions if your board doesn't support the ``flash`` target.
55+
56+
To run the application on an :ref:`nrf5340dk_nrf5340`, a Bluetooth controller application
57+
must also run on the network core. The :ref:`bluetooth-hci-rpmsg-sample` sample
58+
application may be used. Build this sample with configuration
59+
:zephyr_file:`samples/bluetooth/hci_rpmg/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf`
60+
to enable mesh support.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Known issue: non secure platforms do not work with settings subsystem.
2+
CONFIG_SETTINGS=n
3+
CONFIG_BT_SETTINGS=n

samples/bluetooth/mesh_provisioner/prj.conf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
55
CONFIG_MAIN_THREAD_PRIORITY=-2
66

77
CONFIG_BT=y
8-
CONFIG_BT_TINYCRYPT_ECC=y
98
#CONFIG_BT_DEBUG_LOG=y
109
CONFIG_BT_OBSERVER=y
1110
CONFIG_BT_BROADCASTER=y
1211

12+
CONFIG_BT_CTLR_DUP_FILTER_LEN=0
13+
CONFIG_BT_CTLR_LE_ENC=n
14+
CONFIG_BT_CTLR_LE_PING=n
15+
CONFIG_BT_DATA_LEN_UPDATE=n
16+
CONFIG_BT_PHY_UPDATE=n
17+
CONFIG_BT_CTLR_MIN_USED_CHAN=n
18+
CONFIG_BT_CTLR_PRIVACY=n
19+
CONFIG_BT_CTLR_CHAN_SEL_2=n
20+
1321
CONFIG_BT_MESH=y
1422
CONFIG_BT_MESH_SUBNET_COUNT=1
1523
CONFIG_BT_MESH_APP_KEY_COUNT=1

samples/bluetooth/mesh_provisioner/sample.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tests:
66
platform_allow:
77
- qemu_x86
88
- nrf52840dk_nrf52840
9+
- nrf5340dk_nrf5340_cpuapp_ns
910
integration_platforms:
1011
- qemu_x86
1112
tags: bluetooth

subsys/bluetooth/mesh/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,16 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV sol_pdu_rpl_srv.c)
120120

121121
zephyr_library_sources_ifdef(CONFIG_BT_MESH_SOLICITATION solicitation.c)
122122

123-
zephyr_library_sources_ifdef(CONFIG_BT_MESH_USES_TINYCRYPT crypto_tc.c)
124-
125-
zephyr_library_sources_ifdef(CONFIG_BT_MESH_USES_MBEDTLS_PSA crypto_psa.c)
123+
if (CONFIG_BT_MESH_USES_TINYCRYPT)
124+
zephyr_library_sources(crypto_tc.c)
125+
else()
126+
zephyr_library_sources(crypto_psa.c)
127+
endif()
126128

127129
zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS)
130+
131+
if (CONFIG_BUILD_WITH_TFM)
132+
target_include_directories(${ZEPHYR_CURRENT_LIBRARY} PRIVATE
133+
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
134+
)
135+
endif()

subsys/bluetooth/mesh/Kconfig

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if BT_MESH
1515

1616
choice BT_MESH_CRYPTO_LIB
1717
prompt "Crypto library selection for mesh security"
18+
default BT_MESH_USES_TFM_PSA if BUILD_WITH_TFM
1819
default BT_MESH_USES_TINYCRYPT
1920

2021
config BT_MESH_USES_TINYCRYPT
@@ -53,9 +54,18 @@ config BT_MESH_USES_MBEDTLS_PSA
5354
on Zephyr's settings subsystem.
5455
Not possible to use for embedded devices yet.
5556

57+
config BT_MESH_USES_TFM_PSA
58+
bool "Use TF-M PSA [EXPERIMENTAL]"
59+
select EXPERIMENTAL
60+
depends on BUILD_WITH_TFM
61+
help
62+
Use TF-M that implements PSA security framework. Support of TF-M is
63+
experimental. It is only possible to use with platforms that TF-M supports.
64+
For more platform details see TF-M documentation.
65+
5666
endchoice
5767

58-
if BT_MESH_USES_MBEDTLS_PSA
68+
if BT_MESH_USES_MBEDTLS_PSA || BT_MESH_USES_TFM_PSA
5969

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

72-
endif # BT_MESH_USES_MBEDTLS_PSA
82+
endif # BT_MESH_USES_MBEDTLS_PSA || BT_MESH_USES_TFM_PSA
7383

7484
# Virtual option enabled whenever Generic Provisioning layer is needed
7585
config BT_MESH_PROV

subsys/bluetooth/mesh/keys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enum bt_mesh_key_type {
1313
BT_MESH_KEY_TYPE_DEV
1414
};
1515

16-
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA
16+
#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA || defined CONFIG_BT_MESH_USES_TFM_PSA
1717

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

0 commit comments

Comments
 (0)