diff --git a/boards/native/native_sim/Kconfig.defconfig b/boards/native/native_sim/Kconfig.defconfig index 0cb80bbcf4524..03f3811302f1c 100644 --- a/boards/native/native_sim/Kconfig.defconfig +++ b/boards/native/native_sim/Kconfig.defconfig @@ -32,5 +32,14 @@ config UART_CONSOLE endif # CONSOLE +# BT relies on PSA Crypto API to perform crypto operations. On this platform +# this is implemented by Mbed TLS which requires a (possibly true) random +# number generator to initialize properly. We enable ENTROPY_GENERATOR here +# instead of manually adding it to all samples/tests configuration files because +# it looks more compact and easier to maintain. +config ENTROPY_GENERATOR + bool + default y if BT + endif # BOARD_NATIVE_SIM diff --git a/boards/qemu/cortex_m3/Kconfig.defconfig b/boards/qemu/cortex_m3/Kconfig.defconfig index 07f168ce4145b..092453a51a340 100644 --- a/boards/qemu/cortex_m3/Kconfig.defconfig +++ b/boards/qemu/cortex_m3/Kconfig.defconfig @@ -12,4 +12,13 @@ choice NULL_POINTER_EXCEPTION_DETECTION default NULL_POINTER_EXCEPTION_DETECTION_NONE endchoice +# BT relies on PSA Crypto API to perform crypto operations and, on this platform, +# these APIs are provided thougth Mbed TLS. Unfortunately this platform is not +# provided with a true random number generator which is required to properly +# initialize the PSA Crypto core, so we need to enable the fake TEST_RANDOM_GENERATOR. +config TEST_RANDOM_GENERATOR + bool + depends on BT + default y + endif # BOARD_QEMU_CORTEX_M3 diff --git a/doc/releases/migration-guide-4.0.rst b/doc/releases/migration-guide-4.0.rst index 0503995eac174..2a6842785560c 100644 --- a/doc/releases/migration-guide-4.0.rst +++ b/doc/releases/migration-guide-4.0.rst @@ -76,6 +76,12 @@ Mbed TLS corresponding build symbol was removed in Mbed TLS 3.1.0 and is now assumed to be enabled. (:github:`77657`) +* If a platform has a CSPRNG source available (i.e. :kconfig:option:`CONFIG_CSPRNG_ENABLED` + is set), then the Kconfig option :kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG` + is the default choice for random number source instead of + :kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_LEGACY_RNG`. This helps in reducing + ROM/RAM footprint of the Mbed TLS library. + TinyCrypt ========= @@ -218,6 +224,15 @@ Disk Enhanced Serial Peripheral Interface (eSPI) =========================================== +Entropy +======= + +* BT HCI based entropy driver now directly sends the HCI command to parse random + data instead of waiting for BT connection to be ready. This is helpful on + platforms where the BT controller owns the HW random generator and the application + processor needs to get random data before BT is fully enabled. + (:github:`79931`) + GNSS ==== diff --git a/doc/releases/release-notes-4.0.rst b/doc/releases/release-notes-4.0.rst index afeddfeb6f42f..c2991bf027353 100644 --- a/doc/releases/release-notes-4.0.rst +++ b/doc/releases/release-notes-4.0.rst @@ -1123,6 +1123,18 @@ Libraries / Subsystems * :kconfig:option:`CONFIG_MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED` for TLS 1.3 PSK ephemeral key exchange mode. + * The Kconfig symbol :kconfig:option:`CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS` was + added to allow Mbed TLS to use pre-allocated static buffers to store key material + in its PSA Crypto core instead of heap allocated ones. This can help reducing + (or removing, if no other components makes use of it) heap memory requirements + from the final application. + + * The Kconfig symbol :kconfig:option:`CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT` was + added to allow selecting the number of key slots available in the Mbed TLS's + implementation of the PSA Crypto core. The default value is 32, the same used in + Mbed TLS by default. Since each slot consumes RAM memory even if unused, this + value can be tweaked in order to minimize RAM usage. + * CMSIS-NN * FPGA diff --git a/drivers/bluetooth/hci/Kconfig b/drivers/bluetooth/hci/Kconfig index c18142dcbe6b6..665044c4254ca 100644 --- a/drivers/bluetooth/hci/Kconfig +++ b/drivers/bluetooth/hci/Kconfig @@ -112,7 +112,6 @@ config BT_SILABS_EFR32 select MBEDTLS select MBEDTLS_PSA_CRYPTO_C select MBEDTLS_ENTROPY_C - select MBEDTLS_ENTROPY_POLL_ZEPHYR help Use Silicon Labs binary Bluetooth library to connect to the controller. diff --git a/drivers/entropy/entropy_bt_hci.c b/drivers/entropy/entropy_bt_hci.c index 0ae7faa210844..ed547fc885d11 100644 --- a/drivers/entropy/entropy_bt_hci.c +++ b/drivers/entropy/entropy_bt_hci.c @@ -20,9 +20,18 @@ static int entropy_bt_init(const struct device *dev) static int entropy_bt_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length) { - if (!bt_is_ready()) { - return -EAGAIN; - } + /* Do not wait for BT to be ready (i.e. bt_is_ready()) before issueing + * the command. The reason is that when crypto is enabled and the PSA + * Crypto API support is provided through Mbed TLS, random number generator + * needs to be available since the very first call to psa_crypto_init() + * which is usually done before BT is completely initialized. + * On the other hand, in devices like the nrf5340, the crytographically + * secure RNG is owned by the cpu_net, so the cpu_app needs to poll it + * to get random data. Again, there is no need to wait for BT to be + * completely initialized for this kind of support. Just try to send the + * request through HCI. If the command fails for any reason, then + * we return failure anyway. + */ return bt_hci_le_rand(buffer, length); } diff --git a/drivers/wifi/esp32/Kconfig.esp32 b/drivers/wifi/esp32/Kconfig.esp32 index 6732bd5ff7eb8..0da3e58c62ae4 100644 --- a/drivers/wifi/esp32/Kconfig.esp32 +++ b/drivers/wifi/esp32/Kconfig.esp32 @@ -377,7 +377,6 @@ config ESP32_WIFI_MBEDTLS_CRYPTO select MBEDTLS_CIPHER_MODE_CTR_ENABLED select MBEDTLS_CMAC select MBEDTLS_ENTROPY_C - select MBEDTLS_ENTROPY_POLL_ZEPHYR help Select this option to use MbedTLS crypto APIs which utilize hardware acceleration. diff --git a/include/zephyr/bluetooth/mesh/keys.h b/include/zephyr/bluetooth/mesh/keys.h index 73e0a8a2a9383..9c47c47cfd57b 100644 --- a/include/zephyr/bluetooth/mesh/keys.h +++ b/include/zephyr/bluetooth/mesh/keys.h @@ -28,14 +28,6 @@ struct bt_mesh_key { psa_key_id_t key; }; -#elif defined CONFIG_BT_MESH_USES_TINYCRYPT - -/** The structure that keeps representation of key. */ -struct bt_mesh_key { - /** tinycrypt key representation is the pure key value. */ - uint8_t key[16]; -}; - #else #error "Crypto library has not been chosen" #endif diff --git a/modules/mbedtls/Kconfig.tls-generic b/modules/mbedtls/Kconfig.tls-generic index 3ea0a49dd3424..bb6ff771874f7 100644 --- a/modules/mbedtls/Kconfig.tls-generic +++ b/modules/mbedtls/Kconfig.tls-generic @@ -246,6 +246,7 @@ config MBEDTLS_SOME_CIPHER_ENABLED config MBEDTLS_CIPHER_AES_ENABLED bool "AES block cipher" + default y if PSA_WANT_KEY_TYPE_AES && MBEDTLS_PSA_CRYPTO_C if MBEDTLS_CIPHER_AES_ENABLED @@ -397,6 +398,7 @@ config MBEDTLS_ENTROPY_C config MBEDTLS_ENTROPY_POLL_ZEPHYR bool "Provide entropy data to Mbed TLS through entropy driver or random generator" + default y depends on MBEDTLS_ENTROPY_C help Provide entropy data to the Mbed TLS's entropy module through either @@ -480,6 +482,7 @@ config MBEDTLS_SSL_EXTENDED_MASTER_SECRET choice MBEDTLS_PSA_CRYPTO_RNG_SOURCE prompt "Select random source for built-in PSA crypto" depends on MBEDTLS_PSA_CRYPTO_C + default MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG if CSPRNG_ENABLED default MBEDTLS_PSA_CRYPTO_LEGACY_RNG config MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG @@ -551,9 +554,10 @@ config MBEDTLS_LMS depends on MBEDTLS_SHA256 select PSA_WANT_ALG_SHA_256 +if MBEDTLS_PSA_CRYPTO_C + config MBEDTLS_PSA_P256M_DRIVER_ENABLED bool "P256-M driver" - depends on MBEDTLS_PSA_CRYPTO_C imply PSA_WANT_ALG_SHA_256 help Enable support for the optimized sofware implementation of the secp256r1 @@ -567,6 +571,38 @@ config MBEDTLS_PSA_P256M_DRIVER_RAW Warning: Usage of this Kconfig option is prohibited in Zephyr's codebase. Users can enable it in case of very memory-constrained devices, but be aware that the p256-m interface is absolutely not guaranted to remain stable over time. +config MBEDTLS_PSA_STATIC_KEY_SLOTS + bool "Use statically allocated key buffers to store key material" + default y if !MBEDTLS_ENABLE_HEAP + help + By default Mbed TLS's PSA Crypto core uses heap memory to store the + key's material for each key slot. This might impose an undesired + requirement to support heap memory and its management code affecting + RAM and ROM footprints at the same time. + Enabling this symbol cause Mbed TLS to pre-allocate all the key slot + buffers that are used to store the key's material at built time, thus + removing the need for heap memory. Each buffer will be sized to + contain the largest asymmetric/symmetric key type enabled in the build + through PSA_WANT symbols. + +config MBEDTLS_PSA_KEY_SLOT_COUNT + int "Number of key slots in PSA Crypto core" + default 16 + depends on MBEDTLS_PSA_CRYPTO_C + help + Set the number of key slots that are available in the PSA Crypto core. + Be aware that each slots, even if unused, increases RAM memory + consumption as follows: + * if MBEDTLS_PSA_STATIC_KEY_SLOTS is set: ~40 bytes of overhead for each + slot + the length of the largest asymmetric/symmetric key type + enabled in the build through PSA_WANT symbols. All defined statically + at build time. + * if MBEDTLS_PSA_STATIC_KEY_SLOTS is not set: ~40 bytes of overhead + for each slot defined statically at build time + key material allocated + on heap memory at runtime. + +endif # MBEDTLS_PSA_CRYPTO_C + config MBEDTLS_SSL_DTLS_CONNECTION_ID bool "DTLS Connection ID extension" depends on MBEDTLS_DTLS diff --git a/modules/mbedtls/configs/config-tls-generic.h b/modules/mbedtls/configs/config-tls-generic.h index aff59f9e17e76..989d0ad70f2cd 100644 --- a/modules/mbedtls/configs/config-tls-generic.h +++ b/modules/mbedtls/configs/config-tls-generic.h @@ -483,7 +483,6 @@ #endif #if defined(CONFIG_ARCH_POSIX) && !defined(CONFIG_PICOLIBC) -#define MBEDTLS_PSA_KEY_SLOT_COUNT 64 /* for BLE Mesh tests */ #define MBEDTLS_PSA_ITS_FILE_C #define MBEDTLS_FS_IO #endif @@ -494,6 +493,14 @@ #endif /* CONFIG_MBEDTLS_PSA_CRYPTO_C */ +#if defined(CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS) +#define MBEDTLS_PSA_STATIC_KEY_SLOTS +#endif + +#if defined(CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT) +#define MBEDTLS_PSA_KEY_SLOT_COUNT CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT +#endif + #if defined(CONFIG_MBEDTLS_USE_PSA_CRYPTO) #define MBEDTLS_USE_PSA_CRYPTO #endif diff --git a/samples/bluetooth/bap_broadcast_assistant/prj.conf b/samples/bluetooth/bap_broadcast_assistant/prj.conf index 8880c02eaf1a9..be97e4f5fa13e 100644 --- a/samples/bluetooth/bap_broadcast_assistant/prj.conf +++ b/samples/bluetooth/bap_broadcast_assistant/prj.conf @@ -7,7 +7,7 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=191 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_EXT_ADV=y CONFIG_BT_BAP_BASS_MAX_SUBGROUPS=2 diff --git a/samples/bluetooth/bap_broadcast_sink/boards/nrf5340bsim_nrf5340_cpuapp.conf b/samples/bluetooth/bap_broadcast_sink/boards/nrf5340bsim_nrf5340_cpuapp.conf new file mode 100644 index 0000000000000..5858c7b6db1b3 --- /dev/null +++ b/samples/bluetooth/bap_broadcast_sink/boards/nrf5340bsim_nrf5340_cpuapp.conf @@ -0,0 +1 @@ +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/bap_broadcast_sink/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/bluetooth/bap_broadcast_sink/boards/nrf5340dk_nrf5340_cpuapp.conf index 69b3cc51473c7..56dfa4c00db56 100644 --- a/samples/bluetooth/bap_broadcast_sink/boards/nrf5340dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/bap_broadcast_sink/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -1,3 +1,4 @@ # Use USB Audio as audio sink CONFIG_USE_USB_AUDIO_OUTPUT=y CONFIG_USB_DEVICE_PRODUCT="USB Broadcast Sink" +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/bap_broadcast_sink/prj.conf b/samples/bluetooth/bap_broadcast_sink/prj.conf index df18314cfa1e0..08fed05283e05 100644 --- a/samples/bluetooth/bap_broadcast_sink/prj.conf +++ b/samples/bluetooth/bap_broadcast_sink/prj.conf @@ -23,4 +23,4 @@ CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE=64 CONFIG_BT_DEVICE_NAME="Broadcast Audio Sink" -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y diff --git a/samples/bluetooth/bap_broadcast_source/boards/nrf5340bsim_nrf5340_cpuapp.conf b/samples/bluetooth/bap_broadcast_source/boards/nrf5340bsim_nrf5340_cpuapp.conf new file mode 100644 index 0000000000000..5858c7b6db1b3 --- /dev/null +++ b/samples/bluetooth/bap_broadcast_source/boards/nrf5340bsim_nrf5340_cpuapp.conf @@ -0,0 +1 @@ +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/bap_broadcast_source/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/bluetooth/bap_broadcast_source/boards/nrf5340dk_nrf5340_cpuapp.conf index 8b65fa9a9d857..53a732b7970eb 100644 --- a/samples/bluetooth/bap_broadcast_source/boards/nrf5340dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/bap_broadcast_source/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -1,3 +1,4 @@ # Use USB Audio as audio source CONFIG_USE_USB_AUDIO_INPUT=y CONFIG_USB_DEVICE_PRODUCT="Zephyr Broadcast Source" +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/bap_unicast_client/boards/native_sim.conf b/samples/bluetooth/bap_unicast_client/boards/native_sim.conf index 3d06b9f321f3d..f68381ade8eb9 100644 --- a/samples/bluetooth/bap_unicast_client/boards/native_sim.conf +++ b/samples/bluetooth/bap_unicast_client/boards/native_sim.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y @@ -8,3 +8,5 @@ CONFIG_FPU=y # than every 10 ms as each PDU for some reason takes 2 ticks to process. CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 CONFIG_NATIVE_POSIX_SLOWDOWN_TO_REAL_TIME=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/bap_unicast_client/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/samples/bluetooth/bap_unicast_client/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf index f28300b84c50e..80bb3b7222ccb 100644 --- a/samples/bluetooth/bap_unicast_client/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/bap_unicast_client/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -10,4 +10,6 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/bap_unicast_client/boards/nrf5340bsim_nrf5340_cpuapp.conf b/samples/bluetooth/bap_unicast_client/boards/nrf5340bsim_nrf5340_cpuapp.conf index 7c6a3aecc2687..ffb0e27ed64d5 100644 --- a/samples/bluetooth/bap_unicast_client/boards/nrf5340bsim_nrf5340_cpuapp.conf +++ b/samples/bluetooth/bap_unicast_client/boards/nrf5340bsim_nrf5340_cpuapp.conf @@ -7,4 +7,4 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y diff --git a/samples/bluetooth/bap_unicast_client/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/bluetooth/bap_unicast_client/boards/nrf5340dk_nrf5340_cpuapp.conf index 76df8dba27a4f..e02323fb3f790 100644 --- a/samples/bluetooth/bap_unicast_client/boards/nrf5340dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/bap_unicast_client/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -10,4 +10,4 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y diff --git a/samples/bluetooth/bap_unicast_server/boards/native_sim.conf b/samples/bluetooth/bap_unicast_server/boards/native_sim.conf index 3d06b9f321f3d..c951fcc8c3366 100644 --- a/samples/bluetooth/bap_unicast_server/boards/native_sim.conf +++ b/samples/bluetooth/bap_unicast_server/boards/native_sim.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y diff --git a/samples/bluetooth/bap_unicast_server/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/samples/bluetooth/bap_unicast_server/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf index 7c6a3aecc2687..ffb0e27ed64d5 100644 --- a/samples/bluetooth/bap_unicast_server/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/bap_unicast_server/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -7,4 +7,4 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y diff --git a/samples/bluetooth/bap_unicast_server/boards/nrf5340bsim_nrf5340_cpuapp.conf b/samples/bluetooth/bap_unicast_server/boards/nrf5340bsim_nrf5340_cpuapp.conf index 7c6a3aecc2687..5074cec30912a 100644 --- a/samples/bluetooth/bap_unicast_server/boards/nrf5340bsim_nrf5340_cpuapp.conf +++ b/samples/bluetooth/bap_unicast_server/boards/nrf5340bsim_nrf5340_cpuapp.conf @@ -7,4 +7,6 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/bap_unicast_server/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/bluetooth/bap_unicast_server/boards/nrf5340dk_nrf5340_cpuapp.conf index 76df8dba27a4f..e02323fb3f790 100644 --- a/samples/bluetooth/bap_unicast_server/boards/nrf5340dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/bap_unicast_server/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -10,4 +10,4 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y diff --git a/samples/bluetooth/beacon/boards/nrf54l15dk_nrf54l15_cpuapp.conf b/samples/bluetooth/beacon/boards/nrf54l15dk_nrf54l15_cpuapp.conf new file mode 100644 index 0000000000000..350b42b0f67ab --- /dev/null +++ b/samples/bluetooth/beacon/boards/nrf54l15dk_nrf54l15_cpuapp.conf @@ -0,0 +1,13 @@ +# We need a random number generator to properly initialize the PSA Crypto core +# implemented by Mbed TLS. The proper thing to do in this platform would be +# to enable ENTROPY_GENERATOR, but this is not supported right now for the +# following reasons: +# - at device-tree level (nrf54l15_cpuapp.dtsi) the only RNG source available +# is "zephyr,psa-crypto-rng" which means that TF-M is required in order for +# this to work. Unfortunately TF-M is still not supported for this platform, yet. +# - cpuapp does not have a direct access to the RNG without TF-M, so there's +# no other way it can make use of it as of now. +# +# Since both options are not viable, we fall back to the test random generator +# until further support is added to the platform. +CONFIG_TEST_RANDOM_GENERATOR=y diff --git a/samples/bluetooth/cap_acceptor/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/samples/bluetooth/cap_acceptor/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf index 96dc0eb4e3b2c..7bc366e7af118 100644 --- a/samples/bluetooth/cap_acceptor/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/cap_acceptor/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -3,4 +3,5 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/cap_acceptor/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/bluetooth/cap_acceptor/boards/nrf5340dk_nrf5340_cpuapp.conf index 96dc0eb4e3b2c..7bc366e7af118 100644 --- a/samples/bluetooth/cap_acceptor/boards/nrf5340dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/cap_acceptor/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -3,4 +3,5 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/cap_initiator/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/samples/bluetooth/cap_initiator/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf index 96dc0eb4e3b2c..7bc366e7af118 100644 --- a/samples/bluetooth/cap_initiator/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/cap_initiator/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -3,4 +3,5 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/cap_initiator/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/bluetooth/cap_initiator/boards/nrf5340dk_nrf5340_cpuapp.conf index 96dc0eb4e3b2c..7bc366e7af118 100644 --- a/samples/bluetooth/cap_initiator/boards/nrf5340dk_nrf5340_cpuapp.conf +++ b/samples/bluetooth/cap_initiator/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -3,4 +3,5 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/central_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf b/samples/bluetooth/central_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf index 7ffe275701c93..427362ec3e6c6 100644 --- a/samples/bluetooth/central_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf +++ b/samples/bluetooth/central_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf @@ -1,3 +1,4 @@ # Set same the ACL RX buffer size as in hci_ipc on netcore so that # HCI Controller to Host Flowcontrol is supported. CONFIG_BT_BUF_ACL_RX_SIZE=255 +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/central_hr/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/bluetooth/central_hr/boards/nrf5340dk_nrf5340_cpuapp.conf new file mode 100644 index 0000000000000..5858c7b6db1b3 --- /dev/null +++ b/samples/bluetooth/central_hr/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -0,0 +1 @@ +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/central_hr/prj_minimal.conf b/samples/bluetooth/central_hr/prj_minimal.conf index 1dcf300b1ef75..a5f58816beb46 100644 --- a/samples/bluetooth/central_hr/prj_minimal.conf +++ b/samples/bluetooth/central_hr/prj_minimal.conf @@ -101,3 +101,14 @@ CONFIG_BT_L2CAP_TX_BUF_COUNT=2 CONFIG_BT_CTLR_RX_BUFFERS=1 CONFIG_BT_BUF_ACL_TX_COUNT=3 CONFIG_BT_BUF_ACL_TX_SIZE=27 + +# Limit the number of key slots in PSA Crypto core to reduce +# RAM footprint +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=5 + +# This is required because otherwise there won't be +# __heap_start/__heap_end symbols defined in the build. This +# is due to Mbed TLS which at boot uses standard calloc/free +# functions and only after the initialization done from Zephyr +# it switches to its internal memory management functions. +CONFIG_COMMON_LIBC_MALLOC=y diff --git a/samples/bluetooth/central_ht/boards/frdm_rw612.conf b/samples/bluetooth/central_ht/boards/frdm_rw612.conf index 2df782efc7115..6bec2cd6b3781 100644 --- a/samples/bluetooth/central_ht/boards/frdm_rw612.conf +++ b/samples/bluetooth/central_ht/boards/frdm_rw612.conf @@ -1 +1,2 @@ CONFIG_PM=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/central_ht/boards/rd_rw612_bga.conf b/samples/bluetooth/central_ht/boards/rd_rw612_bga.conf index 2df782efc7115..6bec2cd6b3781 100644 --- a/samples/bluetooth/central_ht/boards/rd_rw612_bga.conf +++ b/samples/bluetooth/central_ht/boards/rd_rw612_bga.conf @@ -1 +1,2 @@ CONFIG_PM=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/direction_finding_central/boards/nrf5340dk_nrf5340_cpuapp.conf b/samples/bluetooth/direction_finding_central/boards/nrf5340dk_nrf5340_cpuapp.conf new file mode 100644 index 0000000000000..5858c7b6db1b3 --- /dev/null +++ b/samples/bluetooth/direction_finding_central/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -0,0 +1 @@ +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/hap_ha/boards/native_sim.conf b/samples/bluetooth/hap_ha/boards/native_sim.conf index abce1c1111e5d..6c6fa830d1c3b 100644 --- a/samples/bluetooth/hap_ha/boards/native_sim.conf +++ b/samples/bluetooth/hap_ha/boards/native_sim.conf @@ -1,7 +1,9 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y # For LE-audio at 10ms intervals we need the tick counter to occur more frequently # than every 10 ms as each PDU for some reason takes 2 ticks to process. CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y + +CONFIG_TEST_RANDOM_GENERATOR=y diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_bis-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_bis-bt_ll_sw_split.conf index a7487118694a0..211d846a6f430 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_bis-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_bis-bt_ll_sw_split.conf @@ -5,7 +5,7 @@ CONFIG_ISR_STACK_SIZE=1024 CONFIG_IDLE_STACK_SIZE=256 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_BT=y CONFIG_BT_HCI_RAW=y @@ -40,7 +40,11 @@ CONFIG_BT_ISO_PERIPHERAL=n # ISO Streams CONFIG_BT_ISO_MAX_CHAN=4 -CONFIG_BT_ISO_TX_BUF_COUNT=1 +# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count +# is used in the context of IPC which falls into a "Newton's Cradle" effect +# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT) +# buffers get throttled. Hence, always have the value equal or greater. +CONFIG_BT_ISO_TX_BUF_COUNT=12 CONFIG_BT_ISO_RX_BUF_COUNT=1 # Controller @@ -72,6 +76,7 @@ CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=6 CONFIG_BT_CTLR_SCAN_AUX_SET=1 CONFIG_BT_CTLR_ADV_RESERVE_MAX=n +CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW=y CONFIG_BT_CTLR_SCAN_UNRESERVED=y CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf index 0d78cf862eedb..9b52daefe8b52 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf @@ -1,7 +1,7 @@ CONFIG_IPC_SERVICE=y CONFIG_MBOX=y -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_cis-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_cis-bt_ll_sw_split.conf index f7e1f8fc6737d..3f04703c5b6bf 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_cis-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_cis-bt_ll_sw_split.conf @@ -5,7 +5,7 @@ CONFIG_ISR_STACK_SIZE=1024 CONFIG_IDLE_STACK_SIZE=256 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_BT=y CONFIG_BT_HCI_RAW=y @@ -39,7 +39,11 @@ CONFIG_BT_ISO_PERIPHERAL=y # ISO Streams CONFIG_BT_ISO_MAX_CHAN=4 -CONFIG_BT_ISO_TX_BUF_COUNT=1 +# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count +# is used in the context of IPC which falls into a "Newton's Cradle" effect +# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT) +# buffers get throttled. Hence, always have the value equal or greater. +CONFIG_BT_ISO_TX_BUF_COUNT=12 CONFIG_BT_ISO_RX_BUF_COUNT=1 # Controller @@ -82,8 +86,8 @@ CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 # ISO Connection Oriented CONFIG_BT_CTLR_CENTRAL_ISO=y CONFIG_BT_CTLR_PERIPHERAL_ISO=y -CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_GROUPS=1 +CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=2 CONFIG_BT_CTLR_CONN_ISO_SDU_LEN_MAX=247 CONFIG_BT_CTLR_CONN_ISO_PDU_LEN_MAX=251 diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_df-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_df-bt_ll_sw_split.conf index b183a4c9825fc..76a5a8db0a04f 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_df-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_df-bt_ll_sw_split.conf @@ -5,7 +5,7 @@ CONFIG_ISR_STACK_SIZE=1024 CONFIG_IDLE_STACK_SIZE=256 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_BT=y CONFIG_BT_HCI_RAW=y diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso-bt_ll_sw_split.conf index 925eac8e34e63..87139fb778a56 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso-bt_ll_sw_split.conf @@ -5,7 +5,7 @@ CONFIG_ISR_STACK_SIZE=1024 CONFIG_IDLE_STACK_SIZE=256 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_CBPRINTF_REDUCED_INTEGRAL=y CONFIG_ISR_TABLES_LOCAL_DECLARATION=y @@ -46,7 +46,11 @@ CONFIG_BT_ISO_PERIPHERAL=y CONFIG_BT_ISO_TX_MTU=310 CONFIG_BT_ISO_RX_MTU=310 CONFIG_BT_ISO_MAX_CHAN=4 -CONFIG_BT_ISO_TX_BUF_COUNT=1 +# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count +# is used in the context of IPC which falls into a "Newton's Cradle" effect +# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT) +# buffers get throttled. Hence, always have the value equal or greater. +CONFIG_BT_ISO_TX_BUF_COUNT=8 CONFIG_BT_ISO_RX_BUF_COUNT=1 # Controller @@ -80,6 +84,7 @@ CONFIG_BT_CTLR_SCAN_AUX_SET=1 # CONFIG_BT_CTLR_SCAN_AUX_CHAIN_COUNT=1 CONFIG_BT_CTLR_ADV_RESERVE_MAX=n +CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW=y CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX=y CONFIG_BT_CTLR_SYNC_ISO_RESERVE_MAX=n CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n @@ -100,8 +105,8 @@ CONFIG_BT_CTLR_ADV_EXT=y CONFIG_BT_CTLR_ADV_PERIODIC=y CONFIG_BT_CTLR_SYNC_TRANSFER_SENDER=y CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_ADV_ISO_SET=2 -CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT=4 +CONFIG_BT_CTLR_ADV_ISO_SET=1 +CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT=2 CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=247 @@ -118,16 +123,16 @@ CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 # ISO Connection Oriented CONFIG_BT_CTLR_CENTRAL_ISO=y CONFIG_BT_CTLR_PERIPHERAL_ISO=y -CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_GROUPS=1 +CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=2 CONFIG_BT_CTLR_CONN_ISO_SDU_LEN_MAX=247 CONFIG_BT_CTLR_CONN_ISO_PDU_LEN_MAX=251 CONFIG_BT_CTLR_CONN_ISO_LOW_LATENCY_POLICY=y # ISO Transmissions -CONFIG_BT_CTLR_ISOAL_SOURCES=4 -CONFIG_BT_CTLR_ISO_TX_BUFFERS=12 +CONFIG_BT_CTLR_ISOAL_SOURCES=2 +CONFIG_BT_CTLR_ISO_TX_BUFFERS=8 CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=255 # ISO Receptions @@ -139,3 +144,19 @@ CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y # Ignore HCI ISO data Tx sequence numbers # CONFIG_BT_CTLR_ISOAL_PSN_IGNORE=y + +# The hci_ipc image has a quite high RAM usage so we need to carefully +# tweak Mbed TLS parameters in order to build successfully: +# - use CSPRNG source as random source for PSA. This removes +# requiement for legacy Mbed TLS entropy+ctr-drbg modules, which +# saves RAM and ROM; +# - use ROM pre-computed tables for AES; +# - reduce the number of key slots to 3 in the PSA core. This is not a +# huge limitation since PSA crypto is only used for AES-CMAC in hci_ipc. +CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y +CONFIG_MBEDTLS_AES_ROM_TABLES=y +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=3 + +# Reduce RAM footprint further otherwise the image won't fit in cpu_net. +CONFIG_BT_CTLR_ADV_ISO_SET=1 +CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT=2 diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_broadcast-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_broadcast-bt_ll_sw_split.conf index 67c5854c9c0c7..aa45b2a652b1c 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_broadcast-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_broadcast-bt_ll_sw_split.conf @@ -5,7 +5,7 @@ CONFIG_ISR_STACK_SIZE=1024 CONFIG_IDLE_STACK_SIZE=256 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_BT=y CONFIG_BT_HCI_RAW=y @@ -20,11 +20,18 @@ CONFIG_BT_OBSERVER=n CONFIG_BT_EXT_ADV=y CONFIG_BT_PER_ADV=y CONFIG_BT_ISO_BROADCASTER=y -CONFIG_BT_ISO_MAX_CHAN=4 -CONFIG_BT_ISO_TX_BUF_COUNT=1 CONFIG_BT_CENTRAL=n CONFIG_BT_PERIPHERAL=n +# ISO Streams +CONFIG_BT_ISO_MAX_CHAN=4 +# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count +# is used in the context of IPC which falls into a "Newton's Cradle" effect +# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT) +# buffers get throttled. Hence, always have the value equal or greater. +CONFIG_BT_ISO_TX_BUF_COUNT=12 +CONFIG_BT_ISO_RX_BUF_COUNT=1 + # ISO Broadcast Controller CONFIG_BT_LL_SW_SPLIT=y CONFIG_BT_CTLR_ADV_PERIODIC=y diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_central-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_central-bt_ll_sw_split.conf index 505b9d352ba0e..72a9544745898 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_central-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_central-bt_ll_sw_split.conf @@ -5,7 +5,7 @@ CONFIG_ISR_STACK_SIZE=1024 CONFIG_IDLE_STACK_SIZE=256 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_BT=y CONFIG_BT_HCI_RAW=y @@ -35,7 +35,11 @@ CONFIG_BT_ISO_PERIPHERAL=n # ISO Streams CONFIG_BT_ISO_MAX_CHAN=2 -CONFIG_BT_ISO_TX_BUF_COUNT=1 +# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count +# is used in the context of IPC which falls into a "Newton's Cradle" effect +# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT) +# buffers get throttled. Hence, always have the value equal or greater. +CONFIG_BT_ISO_TX_BUF_COUNT=12 CONFIG_BT_ISO_RX_BUF_COUNT=1 # Controller @@ -46,8 +50,8 @@ CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=191 # ISO Connection Oriented CONFIG_BT_CTLR_CENTRAL_ISO=y CONFIG_BT_CTLR_PERIPHERAL_ISO=n -CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_GROUPS=1 +CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=2 CONFIG_BT_CTLR_CONN_ISO_SDU_LEN_MAX=247 CONFIG_BT_CTLR_CONN_ISO_PDU_LEN_MAX=251 diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_peripheral-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_peripheral-bt_ll_sw_split.conf index 05c9a9d39033e..674c9896e645b 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_peripheral-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_peripheral-bt_ll_sw_split.conf @@ -5,7 +5,7 @@ CONFIG_ISR_STACK_SIZE=1024 CONFIG_IDLE_STACK_SIZE=256 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_BT=y CONFIG_BT_HCI_RAW=y @@ -35,7 +35,11 @@ CONFIG_BT_ISO_PERIPHERAL=y # ISO Streams CONFIG_BT_ISO_MAX_CHAN=2 -CONFIG_BT_ISO_TX_BUF_COUNT=1 +# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count +# is used in the context of IPC which falls into a "Newton's Cradle" effect +# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT) +# buffers get throttled. Hence, always have the value equal or greater. +CONFIG_BT_ISO_TX_BUF_COUNT=12 CONFIG_BT_ISO_RX_BUF_COUNT=1 # Controller @@ -46,8 +50,8 @@ CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191 # ISO Connection Oriented CONFIG_BT_CTLR_CENTRAL_ISO=n CONFIG_BT_CTLR_PERIPHERAL_ISO=y -CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_GROUPS=1 +CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=2 CONFIG_BT_CTLR_CONN_ISO_SDU_LEN_MAX=247 CONFIG_BT_CTLR_CONN_ISO_PDU_LEN_MAX=251 diff --git a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_receive-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_receive-bt_ll_sw_split.conf index 51ca53e83f233..0d9bfdb53ed85 100644 --- a/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_receive-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_receive-bt_ll_sw_split.conf @@ -5,7 +5,7 @@ CONFIG_ISR_STACK_SIZE=1024 CONFIG_IDLE_STACK_SIZE=256 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_HEAP_MEM_POOL_SIZE=7168 CONFIG_BT=y CONFIG_BT_HCI_RAW=y diff --git a/samples/bluetooth/hci_ipc/overlay-nrf5340_cpunet_iso_nrf21540_ek-bt_ll_sw_split.conf b/samples/bluetooth/hci_ipc/overlay-nrf5340_cpunet_iso_nrf21540_ek-bt_ll_sw_split.conf new file mode 100644 index 0000000000000..e54e07c7d53e7 --- /dev/null +++ b/samples/bluetooth/hci_ipc/overlay-nrf5340_cpunet_iso_nrf21540_ek-bt_ll_sw_split.conf @@ -0,0 +1,6 @@ +# Reduce from 310 bytes, in nrf5340_cpunet_iso-bt_ll_sw_split.conf +# to be able to fit in 64KB RAM. + +# Example: +# CONFIG_BT_ISO_TX_MTU=247 +# CONFIG_BT_ISO_RX_MTU=251 diff --git a/samples/bluetooth/hci_ipc/sample.yaml b/samples/bluetooth/hci_ipc/sample.yaml index dd9edc4e9eeb7..b758b25476880 100644 --- a/samples/bluetooth/hci_ipc/sample.yaml +++ b/samples/bluetooth/hci_ipc/sample.yaml @@ -87,6 +87,7 @@ tests: tags: bluetooth extra_args: - CONF_FILE="nrf5340_cpunet_iso-bt_ll_sw_split.conf" + - EXTRA_CONF_FILE="overlay-nrf5340_cpunet_iso_nrf21540_ek-bt_ll_sw_split.conf" - DTC_OVERLAY_FILE="./boards/nrf5340_audio_dk_nrf5340_cpunet_nrf21540_ek.overlay" platform_allow: - nrf5340_audio_dk/nrf5340/cpunet diff --git a/samples/bluetooth/hci_spi/prj.conf b/samples/bluetooth/hci_spi/prj.conf index 65ce21c799cf4..68c1cdb5a083f 100644 --- a/samples/bluetooth/hci_spi/prj.conf +++ b/samples/bluetooth/hci_spi/prj.conf @@ -5,7 +5,7 @@ CONFIG_MAIN_STACK_SIZE=512 CONFIG_BT=y CONFIG_BT_HCI_RAW=y CONFIG_BT_MAX_CONN=16 -CONFIG_BT_TINYCRYPT_ECC=n +CONFIG_BT_SEND_ECC_EMULATION=n # Workaround: Unable to allocate command buffer when using K_NO_WAIT since # Host number of completed commands does not follow normal flow control. diff --git a/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf b/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf index a4054de093452..43374481eeb4e 100644 --- a/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf @@ -57,6 +57,7 @@ CONFIG_BT_CTLR_SCAN_AUX_SET=1 # CONFIG_BT_CTLR_SCAN_AUX_CHAIN_COUNT=1 CONFIG_BT_CTLR_ADV_RESERVE_MAX=n +CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW=y CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX=y CONFIG_BT_CTLR_SYNC_ISO_RESERVE_MAX=n CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n diff --git a/samples/bluetooth/hci_uart/prj.conf b/samples/bluetooth/hci_uart/prj.conf index bdc73dd68e2e0..036a97489104d 100644 --- a/samples/bluetooth/hci_uart/prj.conf +++ b/samples/bluetooth/hci_uart/prj.conf @@ -13,7 +13,7 @@ CONFIG_BT_BUF_CMD_TX_SIZE=255 CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255 CONFIG_BT_CTLR_ASSERT_HANDLER=y CONFIG_BT_MAX_CONN=16 -CONFIG_BT_TINYCRYPT_ECC=n +CONFIG_BT_SEND_ECC_EMULATION=n CONFIG_BT_CTLR_DTM_HCI=y CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 diff --git a/samples/bluetooth/hci_uart_3wire/overlay-all-bt_ll_sw_split.conf b/samples/bluetooth/hci_uart_3wire/overlay-all-bt_ll_sw_split.conf index 8a0f9d3364acc..e4e783ca2d87a 100644 --- a/samples/bluetooth/hci_uart_3wire/overlay-all-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_uart_3wire/overlay-all-bt_ll_sw_split.conf @@ -56,6 +56,7 @@ CONFIG_BT_CTLR_SCAN_AUX_SET=1 # CONFIG_BT_CTLR_SCAN_AUX_CHAIN_COUNT=1 CONFIG_BT_CTLR_ADV_RESERVE_MAX=n +CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW=y CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX=y CONFIG_BT_CTLR_SYNC_ISO_RESERVE_MAX=n CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n diff --git a/samples/bluetooth/hci_uart_3wire/prj.conf b/samples/bluetooth/hci_uart_3wire/prj.conf index 02f16a24138b3..670bcec3234da 100644 --- a/samples/bluetooth/hci_uart_3wire/prj.conf +++ b/samples/bluetooth/hci_uart_3wire/prj.conf @@ -12,7 +12,7 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_CMD_TX_SIZE=255 CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255 CONFIG_BT_MAX_CONN=16 -CONFIG_BT_TINYCRYPT_ECC=n +CONFIG_BT_SEND_ECC_EMULATION=n CONFIG_BT_CTLR_DTM_HCI=y CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 diff --git a/samples/bluetooth/iso_connected_benchmark/prj.conf b/samples/bluetooth/iso_connected_benchmark/prj.conf index 09781083adbc5..eb099a3497aba 100644 --- a/samples/bluetooth/iso_connected_benchmark/prj.conf +++ b/samples/bluetooth/iso_connected_benchmark/prj.conf @@ -15,3 +15,5 @@ CONFIG_MAIN_STACK_SIZE=2048 CONFIG_LOG=y CONFIG_CBPRINTF_FP_SUPPORT=y CONFIG_LOG_BUFFER_SIZE=2048 + +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf deleted file mode 100644 index ee6d1210e8df7..0000000000000 --- a/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ /dev/null @@ -1,2 +0,0 @@ -# Enable PSA as a crypto backend in host -CONFIG_BT_USE_PSA_API=y diff --git a/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf deleted file mode 100644 index ee6d1210e8df7..0000000000000 --- a/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ /dev/null @@ -1,2 +0,0 @@ -# Enable PSA as a crypto backend in host -CONFIG_BT_USE_PSA_API=y diff --git a/samples/bluetooth/mesh_demo/prj.conf b/samples/bluetooth/mesh_demo/prj.conf index df67555b021ba..c8c52aaffce3b 100644 --- a/samples/bluetooth/mesh_demo/prj.conf +++ b/samples/bluetooth/mesh_demo/prj.conf @@ -31,3 +31,14 @@ CONFIG_FLASH_MAP=y CONFIG_NVS=y CONFIG_SETTINGS=y CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600 + +# Limit the number of key slots in PSA Crypto core to reduce +# RAM footprint +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=5 + +# This is required because otherwise there won't be +# __heap_start/__heap_end symbols defined in the build. This +# is due to Mbed TLS which at boot uses standard calloc/free +# functions and only after the initialization done from Zephyr +# it switches to its internal memory management functions. +CONFIG_COMMON_LIBC_MALLOC=y diff --git a/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf deleted file mode 100644 index ee6d1210e8df7..0000000000000 --- a/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ /dev/null @@ -1,2 +0,0 @@ -# Enable PSA as a crypto backend in host -CONFIG_BT_USE_PSA_API=y diff --git a/samples/bluetooth/peripheral_esp/prj.conf b/samples/bluetooth/peripheral_esp/prj.conf index 70f9b5d27e2f9..fd13ca2f3e428 100644 --- a/samples/bluetooth/peripheral_esp/prj.conf +++ b/samples/bluetooth/peripheral_esp/prj.conf @@ -1,7 +1,6 @@ CONFIG_BT=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_SMP=y -CONFIG_TINYCRYPT=y CONFIG_BT_DEVICE_NAME="ESP peripheral" CONFIG_BT_DIS=y CONFIG_BT_DIS_PNP=n diff --git a/samples/bluetooth/peripheral_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf b/samples/bluetooth/peripheral_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf index 7ffe275701c93..427362ec3e6c6 100644 --- a/samples/bluetooth/peripheral_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf +++ b/samples/bluetooth/peripheral_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf @@ -1,3 +1,4 @@ # Set same the ACL RX buffer size as in hci_ipc on netcore so that # HCI Controller to Host Flowcontrol is supported. CONFIG_BT_BUF_ACL_RX_SIZE=255 +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/peripheral_hr/boards/nrf54l15dk_nrf54l15_cpuapp.conf b/samples/bluetooth/peripheral_hr/boards/nrf54l15dk_nrf54l15_cpuapp.conf new file mode 100644 index 0000000000000..350b42b0f67ab --- /dev/null +++ b/samples/bluetooth/peripheral_hr/boards/nrf54l15dk_nrf54l15_cpuapp.conf @@ -0,0 +1,13 @@ +# We need a random number generator to properly initialize the PSA Crypto core +# implemented by Mbed TLS. The proper thing to do in this platform would be +# to enable ENTROPY_GENERATOR, but this is not supported right now for the +# following reasons: +# - at device-tree level (nrf54l15_cpuapp.dtsi) the only RNG source available +# is "zephyr,psa-crypto-rng" which means that TF-M is required in order for +# this to work. Unfortunately TF-M is still not supported for this platform, yet. +# - cpuapp does not have a direct access to the RNG without TF-M, so there's +# no other way it can make use of it as of now. +# +# Since both options are not viable, we fall back to the test random generator +# until further support is added to the platform. +CONFIG_TEST_RANDOM_GENERATOR=y diff --git a/samples/bluetooth/peripheral_hr/prj_minimal.conf b/samples/bluetooth/peripheral_hr/prj_minimal.conf index 6446273584ae9..2b7ddea131992 100644 --- a/samples/bluetooth/peripheral_hr/prj_minimal.conf +++ b/samples/bluetooth/peripheral_hr/prj_minimal.conf @@ -107,3 +107,14 @@ CONFIG_BT_L2CAP_TX_BUF_COUNT=2 CONFIG_BT_CTLR_RX_BUFFERS=1 CONFIG_BT_BUF_ACL_TX_COUNT=3 CONFIG_BT_BUF_ACL_TX_SIZE=27 + +# Limit the number of key slots in PSA Crypto core to reduce +# RAM footprint +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=5 + +# This is required because otherwise there won't be +# __heap_start/__heap_end symbols defined in the build. This +# is due to Mbed TLS which at boot uses standard calloc/free +# functions and only after the initialization done from Zephyr +# it switches to its internal memory management functions. +CONFIG_COMMON_LIBC_MALLOC=y diff --git a/samples/bluetooth/peripheral_ht/boards/frdm_rw612.conf b/samples/bluetooth/peripheral_ht/boards/frdm_rw612.conf index 2df782efc7115..6bec2cd6b3781 100644 --- a/samples/bluetooth/peripheral_ht/boards/frdm_rw612.conf +++ b/samples/bluetooth/peripheral_ht/boards/frdm_rw612.conf @@ -1 +1,2 @@ CONFIG_PM=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/peripheral_ht/boards/mimxrt1020_evk_mimxrt1021.conf b/samples/bluetooth/peripheral_ht/boards/mimxrt1020_evk_mimxrt1021.conf new file mode 100644 index 0000000000000..5858c7b6db1b3 --- /dev/null +++ b/samples/bluetooth/peripheral_ht/boards/mimxrt1020_evk_mimxrt1021.conf @@ -0,0 +1 @@ +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/peripheral_ht/boards/rd_rw612_bga.conf b/samples/bluetooth/peripheral_ht/boards/rd_rw612_bga.conf index 2df782efc7115..6bec2cd6b3781 100644 --- a/samples/bluetooth/peripheral_ht/boards/rd_rw612_bga.conf +++ b/samples/bluetooth/peripheral_ht/boards/rd_rw612_bga.conf @@ -1 +1,2 @@ CONFIG_PM=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/peripheral_sc_only/boards/tlsr9518adk80d.conf b/samples/bluetooth/peripheral_sc_only/boards/tlsr9518adk80d.conf index 04d0a95bd895e..ce0a87933b7d8 100644 --- a/samples/bluetooth/peripheral_sc_only/boards/tlsr9518adk80d.conf +++ b/samples/bluetooth/peripheral_sc_only/boards/tlsr9518adk80d.conf @@ -1,4 +1,4 @@ # Copyright (c) 2022 Telink Semiconductor # SPDX-License-Identifier: Apache-2.0 -CONFIG_BT_TINYCRYPT_ECC=n +CONFIG_BT_SEND_ECC_EMULATION=n diff --git a/samples/bluetooth/peripheral_sc_only/prj.conf b/samples/bluetooth/peripheral_sc_only/prj.conf index c43abee996dca..b8086b247fe58 100644 --- a/samples/bluetooth/peripheral_sc_only/prj.conf +++ b/samples/bluetooth/peripheral_sc_only/prj.conf @@ -7,6 +7,6 @@ CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_SMP=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_MAX_PAIRED=2 CONFIG_BT_DEVICE_NAME="SC only peripheral" diff --git a/samples/bluetooth/st_ble_sensor/prj.conf b/samples/bluetooth/st_ble_sensor/prj.conf index eb6dae37fbec7..4bcba44c6062a 100644 --- a/samples/bluetooth/st_ble_sensor/prj.conf +++ b/samples/bluetooth/st_ble_sensor/prj.conf @@ -4,3 +4,4 @@ CONFIG_BT_DEVICE_NAME="P2PSRV1" CONFIG_BT_GATT_CLIENT=y CONFIG_LOG=y CONFIG_LOG_BUFFER_SIZE=2048 +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/tmap_bmr/boards/native_posix.conf b/samples/bluetooth/tmap_bmr/boards/native_posix.conf index 3d06b9f321f3d..c951fcc8c3366 100644 --- a/samples/bluetooth/tmap_bmr/boards/native_posix.conf +++ b/samples/bluetooth/tmap_bmr/boards/native_posix.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y diff --git a/samples/bluetooth/tmap_bmr/boards/native_sim.conf b/samples/bluetooth/tmap_bmr/boards/native_sim.conf index e06b299938194..3ae70aa8abd5f 100644 --- a/samples/bluetooth/tmap_bmr/boards/native_sim.conf +++ b/samples/bluetooth/tmap_bmr/boards/native_sim.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y @@ -8,3 +8,5 @@ CONFIG_FPU=y # than every 10 ms as each PDU for some reason takes 2 ticks to process. CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/tmap_bms/boards/native_posix.conf b/samples/bluetooth/tmap_bms/boards/native_posix.conf index 3d06b9f321f3d..c951fcc8c3366 100644 --- a/samples/bluetooth/tmap_bms/boards/native_posix.conf +++ b/samples/bluetooth/tmap_bms/boards/native_posix.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y diff --git a/samples/bluetooth/tmap_bms/boards/native_sim.conf b/samples/bluetooth/tmap_bms/boards/native_sim.conf index e06b299938194..3ae70aa8abd5f 100644 --- a/samples/bluetooth/tmap_bms/boards/native_sim.conf +++ b/samples/bluetooth/tmap_bms/boards/native_sim.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y @@ -8,3 +8,5 @@ CONFIG_FPU=y # than every 10 ms as each PDU for some reason takes 2 ticks to process. CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/tmap_central/boards/native_posix.conf b/samples/bluetooth/tmap_central/boards/native_posix.conf index 3d06b9f321f3d..c951fcc8c3366 100644 --- a/samples/bluetooth/tmap_central/boards/native_posix.conf +++ b/samples/bluetooth/tmap_central/boards/native_posix.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y diff --git a/samples/bluetooth/tmap_central/boards/native_sim.conf b/samples/bluetooth/tmap_central/boards/native_sim.conf index e06b299938194..3ae70aa8abd5f 100644 --- a/samples/bluetooth/tmap_central/boards/native_sim.conf +++ b/samples/bluetooth/tmap_central/boards/native_sim.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y @@ -8,3 +8,5 @@ CONFIG_FPU=y # than every 10 ms as each PDU for some reason takes 2 ticks to process. CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/bluetooth/tmap_peripheral/boards/native_posix.conf b/samples/bluetooth/tmap_peripheral/boards/native_posix.conf index 3d06b9f321f3d..c951fcc8c3366 100644 --- a/samples/bluetooth/tmap_peripheral/boards/native_posix.conf +++ b/samples/bluetooth/tmap_peripheral/boards/native_posix.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y diff --git a/samples/bluetooth/tmap_peripheral/boards/native_sim.conf b/samples/bluetooth/tmap_peripheral/boards/native_sim.conf index e06b299938194..3ae70aa8abd5f 100644 --- a/samples/bluetooth/tmap_peripheral/boards/native_sim.conf +++ b/samples/bluetooth/tmap_peripheral/boards/native_sim.conf @@ -1,5 +1,5 @@ CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_LIBLC3=y CONFIG_FPU=y @@ -8,3 +8,5 @@ CONFIG_FPU=y # than every 10 ms as each PDU for some reason takes 2 ticks to process. CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/boards/nordic/mesh/onoff-app/prj.conf b/samples/boards/nordic/mesh/onoff-app/prj.conf index e6f744fb95ab2..4c65164456452 100644 --- a/samples/boards/nordic/mesh/onoff-app/prj.conf +++ b/samples/boards/nordic/mesh/onoff-app/prj.conf @@ -27,7 +27,7 @@ CONFIG_BT_CTLR_PRIVACY=n CONFIG_BT_PERIPHERAL=y CONFIG_BT=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_L2CAP_TX_BUF_COUNT=8 CONFIG_BT_MESH=y diff --git a/samples/boards/nordic/mesh/onoff_level_lighting_vnd_app/prj.conf b/samples/boards/nordic/mesh/onoff_level_lighting_vnd_app/prj.conf index f23b4dc2a304b..b9ce470b9eb6e 100644 --- a/samples/boards/nordic/mesh/onoff_level_lighting_vnd_app/prj.conf +++ b/samples/boards/nordic/mesh/onoff_level_lighting_vnd_app/prj.conf @@ -22,7 +22,7 @@ CONFIG_BT_CTLR_TX_PWR_PLUS_8=y CONFIG_BT_PERIPHERAL=y CONFIG_BT=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_RX_STACK_SIZE=4096 CONFIG_BT_L2CAP_TX_BUF_COUNT=8 diff --git a/samples/boards/st/power_mgmt/stm32wb_ble/prj.conf b/samples/boards/st/power_mgmt/stm32wb_ble/prj.conf index 1dff53f1da721..a04a0c309c32f 100644 --- a/samples/boards/st/power_mgmt/stm32wb_ble/prj.conf +++ b/samples/boards/st/power_mgmt/stm32wb_ble/prj.conf @@ -2,3 +2,4 @@ CONFIG_BT=y CONFIG_BT_DEVICE_NAME="Test beacon" CONFIG_POWEROFF=y CONFIG_PM=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/net/wifi/shell/boards/frdm_rw612.conf b/samples/net/wifi/shell/boards/frdm_rw612.conf index 87de6bc8dbdee..e9ba4d7df6f34 100644 --- a/samples/net/wifi/shell/boards/frdm_rw612.conf +++ b/samples/net/wifi/shell/boards/frdm_rw612.conf @@ -103,7 +103,6 @@ CONFIG_MBEDTLS_USER_CONFIG_FILE="wpa_supp_els_pkc_mbedtls_config.h" CONFIG_ENTROPY_GENERATOR=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y CONFIG_MBEDTLS_ENTROPY_C=y -CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR=y CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=8192 # power management diff --git a/samples/net/wifi/shell/boards/rd_rw612_bga.conf b/samples/net/wifi/shell/boards/rd_rw612_bga.conf index 633137e3fb02d..5ecd5b4f1e705 100644 --- a/samples/net/wifi/shell/boards/rd_rw612_bga.conf +++ b/samples/net/wifi/shell/boards/rd_rw612_bga.conf @@ -102,7 +102,6 @@ CONFIG_MBEDTLS_USER_CONFIG_FILE="wpa_supp_els_pkc_mbedtls_config.h" CONFIG_ENTROPY_GENERATOR=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y CONFIG_MBEDTLS_ENTROPY_C=y -CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR=y CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=8192 # power management diff --git a/samples/psa/its/overlay-entropy_driver.conf b/samples/psa/its/overlay-entropy_driver.conf index b2fea61e044a3..0feb3ad09493f 100644 --- a/samples/psa/its/overlay-entropy_driver.conf +++ b/samples/psa/its/overlay-entropy_driver.conf @@ -1,4 +1,3 @@ # SPDX-License-Identifier: Apache-2.0 CONFIG_ENTROPY_GENERATOR=y -CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y diff --git a/samples/psa/its/overlay-entropy_not_secure.conf b/samples/psa/its/overlay-entropy_not_secure.conf index 2aba3a2c7e27d..f2ab17793542e 100644 --- a/samples/psa/its/overlay-entropy_not_secure.conf +++ b/samples/psa/its/overlay-entropy_not_secure.conf @@ -2,4 +2,3 @@ CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TIMER_RANDOM_GENERATOR=y -CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR=y diff --git a/samples/psa/persistent_key/overlay-entropy_driver.conf b/samples/psa/persistent_key/overlay-entropy_driver.conf index b2fea61e044a3..0feb3ad09493f 100644 --- a/samples/psa/persistent_key/overlay-entropy_driver.conf +++ b/samples/psa/persistent_key/overlay-entropy_driver.conf @@ -1,4 +1,3 @@ # SPDX-License-Identifier: Apache-2.0 CONFIG_ENTROPY_GENERATOR=y -CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y diff --git a/samples/psa/persistent_key/overlay-entropy_not_secure.conf b/samples/psa/persistent_key/overlay-entropy_not_secure.conf index 2aba3a2c7e27d..f2ab17793542e 100644 --- a/samples/psa/persistent_key/overlay-entropy_not_secure.conf +++ b/samples/psa/persistent_key/overlay-entropy_not_secure.conf @@ -2,4 +2,3 @@ CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TIMER_RANDOM_GENERATOR=y -CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR=y diff --git a/samples/subsys/logging/ble_backend/prj.conf b/samples/subsys/logging/ble_backend/prj.conf index f98016410b981..0a290f80da395 100644 --- a/samples/subsys/logging/ble_backend/prj.conf +++ b/samples/subsys/logging/ble_backend/prj.conf @@ -8,3 +8,5 @@ CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=2048 # Uncomment to use the maximum buffer size # CONFIG_BT_L2CAP_TX_MTU=600 # CONFIG_BT_BUF_ACL_RX_SIZE=600 + +CONFIG_TEST_RANDOM_GENERATOR=y diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index d5560d6d5d0ea..e03501d6500cd 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -241,13 +241,6 @@ config BT_SHELL Activate shell module that provides Bluetooth commands to the console. -config BT_USE_PSA_API - bool "Use PSA APIs instead of TinyCrypt for crypto operations" - depends on BT_CRYPTO || BT_HOST_CRYPTO || BT_ECC - depends on PSA_CRYPTO_CLIENT - help - Use PSA APIs instead of TinyCrypt for crypto operations - endif # BT_HCI config BT_COMPANY_ID diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index 8bec5ba90d5d8..a5fde079b7df3 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -231,8 +231,7 @@ config BT_WAIT_NOP config BT_RPA bool - select TINYCRYPT - select TINYCRYPT_AES + depends on BT_HOST_CRYPTO || BT_CTLR_CRYPTO config BT_ASSERT bool "Custom Bluetooth assert implementation" diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 90d5413a05be6..bf8bb39ec3015 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -437,6 +437,14 @@ config BT_CTLR_ADV_RESERVE_MAX corresponding to the Advertising Data present at the time of the start/enable of Advertising is used. +config BT_CTLR_ADV_AUX_SLOT_WINDOW + bool "Reschedule Extended Advertising Auxiliary PDUs" + depends on BT_TICKER_EXT && \ + BT_BROADCASTER && \ + BT_CTLR_ADV_EXT + help + Reschedule Extended Advertising Auxiliary PDUs. + config BT_CTLR_ADV_ISO_RESERVE_MAX bool "Use maximum Broadcast ISO event time reservation" depends on BT_CTLR_ADV_ISO diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 8fffa01a3feaf..5492092fd7d4f 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -1049,9 +1049,9 @@ static void read_supported_commands(struct net_buf *buf, struct net_buf **evt) rp->commands[41] |= BIT(1); #endif /* CONFIG_BT_CTLR_SYNC_TRANSFER_RECEIVER */ -#if defined(CONFIG_BT_HCI_RAW) && defined(CONFIG_BT_TINYCRYPT_ECC) +#if defined(CONFIG_BT_HCI_RAW) && defined(CONFIG_BT_SEND_ECC_EMULATION) bt_hci_ecc_supported_commands(rp->commands); -#endif /* CONFIG_BT_HCI_RAW && CONFIG_BT_TINYCRYPT_ECC */ +#endif /* CONFIG_BT_HCI_RAW && CONFIG_BT_SEND_ECC_EMULATION */ /* LE Read TX Power. */ rp->commands[38] |= BIT(7); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c index 5eeba29b5e88c..04a20dcb98632 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c @@ -46,6 +46,7 @@ static void prepare_bh(void *param); static int create_prepare_cb(struct lll_prepare_param *p); static int prepare_cb(struct lll_prepare_param *p); static int prepare_cb_common(struct lll_prepare_param *p); +static int is_abort_cb(void *next, void *curr, lll_prepare_cb_t *resume_cb); static void abort_cb(struct lll_prepare_param *prepare_param, void *param); static void isr_rx_estab(void *param); static void isr_rx(void *param); @@ -56,7 +57,8 @@ static void next_chan_calc(struct lll_sync_iso *lll, uint16_t event_counter, static void isr_rx_iso_data_valid(const struct lll_sync_iso *const lll, uint16_t handle, struct node_rx_pdu *node_rx); static void isr_rx_iso_data_invalid(const struct lll_sync_iso *const lll, - uint8_t bn, uint16_t handle, + uint16_t latency, uint8_t bn, + uint16_t handle, struct node_rx_pdu *node_rx); static void isr_rx_ctrl_recv(struct lll_sync_iso *lll, struct pdu_bis *pdu); @@ -146,7 +148,7 @@ static void create_prepare_bh(void *param) int err; /* Invoke common pipeline handling of prepare */ - err = lll_prepare(lll_is_abort_cb, abort_cb, create_prepare_cb, 0U, + err = lll_prepare(is_abort_cb, abort_cb, create_prepare_cb, 0U, param); LL_ASSERT(!err || err == -EINPROGRESS); } @@ -156,7 +158,7 @@ static void prepare_bh(void *param) int err; /* Invoke common pipeline handling of prepare */ - err = lll_prepare(lll_is_abort_cb, abort_cb, prepare_cb, 0U, param); + err = lll_prepare(is_abort_cb, abort_cb, prepare_cb, 0U, param); LL_ASSERT(!err || err == -EINPROGRESS); } @@ -404,6 +406,20 @@ static int prepare_cb_common(struct lll_prepare_param *p) return 0; } +static int is_abort_cb(void *next, void *curr, lll_prepare_cb_t *resume_cb) +{ + if (next != curr) { + struct lll_sync_iso *lll; + + lll = curr; + if (lll->bn_curr <= lll->bn) { + return 0; + } + } + + return -ECANCELED; +} + static void abort_cb(struct lll_prepare_param *prepare_param, void *param) { struct event_done_extra *e; @@ -1217,7 +1233,8 @@ static void isr_rx_done(void *param) pdu->len = 0U; handle = LL_BIS_SYNC_HANDLE_FROM_IDX(stream_handle); - isr_rx_iso_data_invalid(lll, bn, handle, node_rx); + isr_rx_iso_data_invalid(lll, latency_event, bn, + handle, node_rx); iso_rx_put(node_rx->hdr.link, node_rx); } @@ -1381,7 +1398,8 @@ static void isr_rx_iso_data_valid(const struct lll_sync_iso *const lll, } static void isr_rx_iso_data_invalid(const struct lll_sync_iso *const lll, - uint8_t bn, uint16_t handle, + uint16_t latency, uint8_t bn, + uint16_t handle, struct node_rx_pdu *node_rx) { struct lll_sync_iso_stream *stream; @@ -1391,7 +1409,7 @@ static void isr_rx_iso_data_invalid(const struct lll_sync_iso *const lll, node_rx->hdr.handle = handle; iso_meta = &node_rx->rx_iso_meta; - iso_meta->payload_number = lll->payload_count - bn - 1U; + iso_meta->payload_number = lll->payload_count - lll->bn - bn - 1U; stream = ull_sync_iso_lll_stream_get(lll->stream_handle[0]); iso_meta->timestamp = HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + @@ -1399,6 +1417,8 @@ static void isr_rx_iso_data_invalid(const struct lll_sync_iso *const lll, ((stream->bis_index - 1U) * lll->sub_interval * ((lll->irc * lll->bn) + lll->ptc)); + iso_meta->timestamp -= (latency * lll->iso_interval * + PERIODIC_INT_UNIT_US); iso_meta->timestamp %= HAL_TICKER_TICKS_TO_US_64BIT(BIT64(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 1U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 7478bf7332be7..dab8a7fe869ec 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -71,11 +71,18 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, static struct ll_adv_aux_set ll_adv_aux_pool[CONFIG_BT_CTLR_ADV_AUX_SET]; static void *adv_aux_free; -#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) && defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) +#if defined(CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW) || \ + (defined(CONFIG_BT_CTLR_ADV_PERIODIC) && \ + defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO)) +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) && \ + defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) static void ticker_update_op_cb(uint32_t status, void *param); +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC && CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ static struct ticker_ext ll_adv_aux_ticker_ext[CONFIG_BT_CTLR_ADV_AUX_SET]; -#endif /* !CONFIG_BT_CTLR_ADV_PERIODIC && CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ +#endif /* CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW || + * (CONFIG_BT_CTLR_ADV_PERIODIC && CONFIG_BT_TICKER_EXT_EXPIRE_INFO) + */ #endif /* (CONFIG_BT_CTLR_ADV_AUX_SET > 0) */ static uint16_t did_unique[PDU_ADV_SID_COUNT]; @@ -2600,6 +2607,12 @@ uint32_t ull_adv_aux_start(struct ll_adv_aux_set *aux, uint32_t ticks_anchor, aux_handle = ull_adv_aux_handle_get(aux); interval_us = aux->interval * PERIODIC_INT_UNIT_US; +#if defined(CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW) + ll_adv_aux_ticker_ext[aux_handle].ticks_slot_window = + ULL_ADV_RANDOM_DELAY + aux->ull.ticks_slot; + ll_adv_aux_ticker_ext[aux_handle].is_drift_in_window = 1U; +#endif /* CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW */ + #if defined(CONFIG_BT_CTLR_ADV_PERIODIC) && defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) if (aux->lll.adv->sync) { const struct ll_adv_sync_set *sync = HDR_LLL2ULL(aux->lll.adv->sync); @@ -2612,14 +2625,22 @@ uint32_t ull_adv_aux_start(struct ll_adv_aux_set *aux, uint32_t ticks_anchor, } ll_adv_aux_ticker_ext[aux_handle].ext_timeout_func = ticker_cb; +#endif /* !CONFIG_BT_CTLR_ADV_PERIODIC || !CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ +#if defined(CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW) || \ + (defined(CONFIG_BT_CTLR_ADV_PERIODIC) && \ + defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO)) ret_cb = TICKER_STATUS_BUSY; ret = ticker_start_ext( -#else /* !CONFIG_BT_CTLR_ADV_PERIODIC || !CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ +#else /* !CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW && + * !(CONFIG_BT_CTLR_ADV_PERIODIC && CONFIG_BT_TICKER_EXT_EXPIRE_INFO) + */ ret_cb = TICKER_STATUS_BUSY; ret = ticker_start( -#endif /* !CONFIG_BT_CTLR_ADV_PERIODIC || !CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ +#endif /* !CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW && + * !(CONFIG_BT_CTLR_ADV_PERIODIC && CONFIG_BT_TICKER_EXT_EXPIRE_INFO) + */ TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, (TICKER_ID_ADV_AUX_BASE + aux_handle), ticks_anchor, 0U, @@ -2628,10 +2649,14 @@ uint32_t ull_adv_aux_start(struct ll_adv_aux_set *aux, uint32_t ticks_anchor, (aux->ull.ticks_slot + ticks_slot_overhead), ticker_cb, aux, ull_ticker_status_give, (void *)&ret_cb -#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) && defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) +#if defined(CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW) || \ + (defined(CONFIG_BT_CTLR_ADV_PERIODIC) && \ + defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO)) , &ll_adv_aux_ticker_ext[aux_handle] -#endif /* !CONFIG_BT_CTLR_ADV_PERIODIC || !CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ +#endif /* CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW || + * (CONFIG_BT_CTLR_ADV_PERIODIC && CONFIG_BT_TICKER_EXT_EXPIRE_INFO) + */ ); ret = ull_ticker_status_take(ret, &ret_cb); diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c index fbe29c258afe5..57723abd52bbc 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c @@ -417,8 +417,6 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, struct pdu_big_info *bi; uint32_t ready_delay_us; uint32_t ticks_expire; - uint32_t ctrl_spacing; - uint32_t pdu_spacing; uint32_t interval_us; uint32_t ticks_diff; struct pdu_adv *pdu; @@ -581,11 +579,6 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, interval_us -= lll->window_widening_periodic_us; /* Calculate ISO Receiver BIG event timings */ - pdu_spacing = PDU_BIS_US(lll->max_pdu, lll->enc, lll->phy, - PHY_FLAGS_S8) + - EVENT_MSS_US; - ctrl_spacing = PDU_BIS_US(sizeof(struct pdu_big_ctrl), lll->enc, - lll->phy, PHY_FLAGS_S8); /* Number of maximum BISes to sync from the first BIS to sync */ /* NOTE: When ULL scheduling is implemented for subevents, then update @@ -605,26 +598,39 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, */ if (IS_ENABLED(CONFIG_BT_CTLR_SYNC_ISO_RESERVE_MAX)) { - /* Maximum time reservation for both sequential and interleaved + uint32_t ctrl_spacing; + + /* Maximum time reservation for sequential and interleaved * packing. */ - slot_us = (pdu_spacing * lll->nse * num_bis) + ctrl_spacing; + if (lll->bis_spacing >= (lll->sub_interval * lll->nse)) { + slot_us = lll->sub_interval * lll->nse * num_bis; + } else { + slot_us = lll->bis_spacing * lll->nse * num_bis; + } + + ctrl_spacing = PDU_BIS_US(sizeof(struct pdu_big_ctrl), lll->enc, + lll->phy, PHY_FLAGS_S8); + slot_us += ctrl_spacing; } else if (lll->bis_spacing >= (lll->sub_interval * lll->nse)) { /* Time reservation omitting PTC subevents in sequential * packing. */ - slot_us = pdu_spacing * ((lll->nse * num_bis) - lll->ptc); + slot_us = lll->sub_interval * ((lll->nse * num_bis) - lll->ptc); } else { /* Time reservation omitting PTC subevents in interleaved * packing. */ - slot_us = pdu_spacing * ((lll->nse - lll->ptc) * num_bis); + slot_us = lll->bis_spacing * ((lll->nse - lll->ptc) * num_bis); } /* Add radio ready delay */ slot_us += ready_delay_us; + slot_us += lll->window_widening_periodic_us << 1U; + slot_us += EVENT_JITTER_US << 1U; + slot_us += EVENT_TICKER_RES_MARGIN_US << 2U; /* Add implementation defined radio event overheads */ if (IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX)) { diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index c4a36e3cf567c..ce1f464c3dae3 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -946,21 +946,23 @@ static uint8_t ticker_resolve_collision(struct ticker_node *nodes, * the ticks_slot_window. */ uint8_t next_not_ticks_slot_window = - (!TICKER_HAS_SLOT_WINDOW(ticker_next) || - ((acc_ticks_to_expire + - ticker_next->ext_data->ticks_slot_window - - ticker_next->ticks_slot) < - ticker->ticks_slot)); + !TICKER_HAS_SLOT_WINDOW(ticker_next) || + (ticker_next->ext_data->is_drift_in_window && + TICKER_HAS_SLOT_WINDOW(ticker)) || + ((acc_ticks_to_expire + + ticker_next->ext_data->ticks_slot_window - + ticker_next->ticks_slot) < + ticker->ticks_slot); /* Can the current ticker with ticks_slot_window be * scheduled after the colliding ticker? */ uint8_t curr_has_ticks_slot_window = - (TICKER_HAS_SLOT_WINDOW(ticker) && - ((acc_ticks_to_expire + - ticker_next->ticks_slot) < - (ticker->ext_data->ticks_slot_window - - ticker->ticks_slot))); + TICKER_HAS_SLOT_WINDOW(ticker) && + ((acc_ticks_to_expire + + ticker_next->ticks_slot) <= + (ticker->ext_data->ticks_slot_window - + ticker->ticks_slot)); #else /* !CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD */ #if defined(CONFIG_BT_TICKER_PRIORITY_SET) @@ -982,7 +984,7 @@ static uint8_t ticker_resolve_collision(struct ticker_node *nodes, (TICKER_HAS_SLOT_WINDOW(ticker) && !ticker->ticks_slot && ((acc_ticks_to_expire + - ticker_next->ticks_slot) < + ticker_next->ticks_slot) <= (ticker->ext_data->ticks_slot_window))); #endif /* !CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD */ @@ -2551,9 +2553,10 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance) */ if (((window_start_ticks + ticks_slot) <= ticks_slot_window) && - (window_end_ticks > (ticks_start_offset + + (window_end_ticks >= (ticks_start_offset + ticks_slot))) { - if (!ticker_resched->ticks_slot) { + if (!ticker_resched->ticks_slot || + ext_data->is_drift_in_window) { /* Place at start of window */ ticks_to_expire = window_start_ticks; } else { @@ -2590,6 +2593,9 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance) ticks_slot))) { /* Re-scheduled node fits before this node */ break; + } else { + /* Not inside the window */ + ticks_to_expire = 0U; } /* We din't find a valid slot for re-scheduling - try @@ -2600,9 +2606,27 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance) ticker_next->ticks_slot; ticks_to_expire_offset = 0U; - if (!ticker_resched->ticks_slot) { - /* Try at the end of the next node */ - ticks_to_expire = window_start_ticks; + if (!ticker_resched->ticks_slot || + ext_data->is_drift_in_window) { + if (!ticker_resched->ticks_slot || + (window_start_ticks <= (ticks_slot_window - + ticks_slot))) { + /* Try at the end of the next node */ + ticks_to_expire = window_start_ticks; + } + } else if (IS_ENABLED(CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD) && + (ticker_resched->ticks_periodic < + ticker_next->ticks_periodic)) { + /* Try to place it before the overlap and be + * rescheduled to its next periodic interval + * for collision resolution. + */ + if (ticks_start_offset > ticks_slot) { + ticks_to_expire = ticks_start_offset - + ticks_slot; + } else { + ticks_to_expire = 0U; + } } else { /* Try at the end of the slot window. This * ensures that ticker with slot window and that diff --git a/subsys/bluetooth/controller/ticker/ticker.h b/subsys/bluetooth/controller/ticker/ticker.h index f75cd21b80ae6..aa666036ab01c 100644 --- a/subsys/bluetooth/controller/ticker/ticker.h +++ b/subsys/bluetooth/controller/ticker/ticker.h @@ -229,15 +229,24 @@ uint8_t ticker_priority_set(uint8_t instance_index, uint8_t user_id, #if defined(CONFIG_BT_TICKER_EXT) struct ticker_ext { #if !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) - uint32_t ticks_slot_window;/* Window in which the slot - * reservation may be re-scheduled - * to avoid collision - */ - uint32_t ticks_drift; /* Actual drift since last expiry */ - uint8_t reschedule_state; /* State of re-scheduling of the - * node. See defines - * TICKER_RESCHEDULE_STATE_XXX - */ + uint32_t ticks_slot_window; /* Window in which the slot + * reservation may be re-scheduled + * to avoid collision + */ + uint32_t ticks_drift; /* Actual drift since last expiry, + * includes any ticker update interface + * made changes plus drift due to + * reschedule when not + * is_jitter_in_window, otherwise is only + * the value of drift due to reschedule + */ + uint8_t reschedule_state:3; /* State of re-scheduling of the + * node. See defines + * TICKER_RESCHEDULE_STATE_XXX + */ + uint8_t is_drift_in_window:1; /* Drift in slot window, to be placed + * after an overlapping ticker + */ #endif /* CONFIG_BT_TICKER_SLOT_AGNOSTIC */ #if defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) diff --git a/subsys/bluetooth/crypto/CMakeLists.txt b/subsys/bluetooth/crypto/CMakeLists.txt index dc0f83b32c271..073a9c613d748 100644 --- a/subsys/bluetooth/crypto/CMakeLists.txt +++ b/subsys/bluetooth/crypto/CMakeLists.txt @@ -4,15 +4,11 @@ zephyr_library() zephyr_library_sources(bt_crypto.c) -if(CONFIG_BT_USE_PSA_API) - zephyr_library_sources(bt_crypto_psa.c) - zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) - zephyr_library_include_directories_ifdef(CONFIG_BUILD_WITH_TFM - $/api_ns/interface/include - ) -else() - zephyr_library_sources(bt_crypto_tc.c) -endif() +zephyr_library_sources(bt_crypto_psa.c) +zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) +zephyr_library_include_directories_ifdef(CONFIG_BUILD_WITH_TFM + $/api_ns/interface/include +) if(CONFIG_BT_CRYPTO_LOG_LEVEL_DBG) message(WARNING "CONFIG_BT_CRYPTO_LOG_LEVEL_DBG is enabled. diff --git a/subsys/bluetooth/crypto/Kconfig b/subsys/bluetooth/crypto/Kconfig index a59979730f0d5..5c1c2fb20fd8f 100644 --- a/subsys/bluetooth/crypto/Kconfig +++ b/subsys/bluetooth/crypto/Kconfig @@ -3,10 +3,10 @@ config BT_CRYPTO bool - select TINYCRYPT if !BT_USE_PSA_API - select TINYCRYPT_AES if !BT_USE_PSA_API - select TINYCRYPT_AES_CMAC if !BT_USE_PSA_API - select PSA_WANT_KEY_TYPE_AES if BT_USE_PSA_API - select PSA_WANT_ALG_CMAC if BT_USE_PSA_API + select MBEDTLS if !BUILD_WITH_TFM + select MBEDTLS_PSA_CRYPTO_C if !BUILD_WITH_TFM + select PSA_WANT_KEY_TYPE_AES + select PSA_WANT_ALG_CMAC + select MBEDTLS_AES_ROM_TABLES if MBEDTLS_PSA_CRYPTO_C help This option enables the Bluetooth Cryptographic Toolbox. diff --git a/subsys/bluetooth/crypto/bt_crypto.c b/subsys/bluetooth/crypto/bt_crypto.c index 62a475a57d751..604449bf8f156 100644 --- a/subsys/bluetooth/crypto/bt_crypto.c +++ b/subsys/bluetooth/crypto/bt_crypto.c @@ -7,12 +7,7 @@ #include -#if defined(CONFIG_BT_USE_PSA_API) #include "psa/crypto.h" -#else -#include -#include -#endif #include "common/bt_str.h" #include "bt_crypto.h" diff --git a/subsys/bluetooth/crypto/bt_crypto_tc.c b/subsys/bluetooth/crypto/bt_crypto_tc.c deleted file mode 100644 index 95160d55dfd9e..0000000000000 --- a/subsys/bluetooth/crypto/bt_crypto_tc.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (c) 2022 Nordic Semiconductor ASA - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include - -#include -#include - -#include "common/bt_str.h" -#include "bt_crypto.h" - -int bt_crypto_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len, uint8_t *out) -{ - struct tc_aes_key_sched_struct sched; - struct tc_cmac_struct state; - - if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) { - return -EIO; - } - - if (tc_cmac_update(&state, in, len) == TC_CRYPTO_FAIL) { - return -EIO; - } - - if (tc_cmac_final(out, &state) == TC_CRYPTO_FAIL) { - return -EIO; - } - - return 0; -} diff --git a/subsys/bluetooth/host/CMakeLists.txt b/subsys/bluetooth/host/CMakeLists.txt index dd209d4177c53..f92a1f1a7b978 100644 --- a/subsys/bluetooth/host/CMakeLists.txt +++ b/subsys/bluetooth/host/CMakeLists.txt @@ -8,7 +8,7 @@ add_subdirectory_ifdef(CONFIG_BT_SHELL shell) zephyr_library_sources_ifdef(CONFIG_BT_HCI_RAW hci_raw.c hci_common.c) zephyr_library_sources_ifdef(CONFIG_BT_MONITOR monitor.c) -zephyr_library_sources_ifdef(CONFIG_BT_TINYCRYPT_ECC hci_ecc.c) +zephyr_library_sources_ifdef(CONFIG_BT_SEND_ECC_EMULATION hci_ecc.c) zephyr_library_sources_ifdef(CONFIG_BT_SETTINGS settings.c) zephyr_library_sources_ifdef(CONFIG_BT_HOST_CCM aes_ccm.c) zephyr_library_sources_ifdef(CONFIG_BT_LONG_WQ long_wq.c) @@ -32,11 +32,10 @@ if(CONFIG_BT_HCI_HOST) scan.c ) - if(CONFIG_BT_USE_PSA_API) - zephyr_library_sources_ifdef(CONFIG_BT_HOST_CRYPTO crypto_psa.c) - else() - zephyr_library_sources_ifdef(CONFIG_BT_HOST_CRYPTO crypto_tc.c) - endif() + zephyr_library_sources_ifdef( + CONFIG_BT_HOST_CRYPTO + crypto_psa.c + ) zephyr_library_sources_ifdef( CONFIG_BT_ECC @@ -116,12 +115,10 @@ if(CONFIG_BT_CONN_DISABLE_SECURITY) ) endif() -if(CONFIG_BT_USE_PSA_API) - zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) - zephyr_library_include_directories_ifdef(CONFIG_BUILD_WITH_TFM - $/api_ns/interface/include - ) -endif() +zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) +zephyr_library_include_directories_ifdef(CONFIG_BUILD_WITH_TFM + $/api_ns/interface/include +) # Bluetooth Mesh has test dependencies in the host. # In order to compile Bsim tests with these test features diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index db247d76b93c6..ee7e52ba64d73 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -16,7 +16,7 @@ config BT_LONG_WQ_STACK_SIZE # requirements. int default 1300 if BT_GATT_CACHING - default 1140 if BT_TINYCRYPT_ECC + default 1140 if BT_SEND_ECC_EMULATION default 1024 config BT_LONG_WQ_PRIO @@ -168,22 +168,23 @@ rsource "../audio/Kconfig" config BT_HOST_CRYPTO bool "Use crypto functionality implemented in the Bluetooth host" default y if !BT_CTLR_CRYPTO - select TINYCRYPT if !BT_USE_PSA_API - select TINYCRYPT_AES if !BT_USE_PSA_API - select PSA_WANT_KEY_TYPE_AES if BT_USE_PSA_API + select MBEDTLS if !BUILD_WITH_TFM + select MBEDTLS_PSA_CRYPTO_C if !BUILD_WITH_TFM + select PSA_WANT_KEY_TYPE_AES + select PSA_WANT_ALG_ECB_NO_PADDING help - The option adds the AES encryption support using TinyCrypt + The option adds the AES encryption support using PSA Crypto API library if this is not provided by the controller implementation. config BT_HOST_CRYPTO_PRNG - bool "Use Tinycrypt library for random number generation" + bool "Use PSA crypto API library for random number generation" default y - select TINYCRYPT_SHA256 if !BT_USE_PSA_API - select TINYCRYPT_SHA256_HMAC if !BT_USE_PSA_API - select TINYCRYPT_SHA256_HMAC_PRNG if !BT_USE_PSA_API + select PSA_WANT_ALG_SHA_256 + select PSA_WANT_KEY_TYPE_HMAC + select PSA_WANT_ALG_HMAC depends on BT_HOST_CRYPTO help - When selected, will use tinycrypt library for random number generation. + When selected, will use PSA Crypto API library for random number generation. This will consume additional ram, but may speed up the generation of random numbers. @@ -998,15 +999,18 @@ config BT_ECC help This option adds support for ECDH HCI commands. -config BT_TINYCRYPT_ECC - bool "Emulate ECDH in the Host using TinyCrypt library" - select TINYCRYPT - select TINYCRYPT_ECC_DH +config BT_SEND_ECC_EMULATION + bool "Emulate ECDH in the Host using PSA Crypto API library" + select MBEDTLS if !BUILD_WITH_TFM + select MBEDTLS_PSA_CRYPTO_C if !BUILD_WITH_TFM + select PSA_WANT_ALG_ECDH + select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE + select PSA_WANT_ECC_SECP_R1_256 select BT_LONG_WQ depends on BT_ECC && (BT_HCI_RAW || BT_HCI_HOST) default y if BT_CTLR && !BT_CTLR_ECDH help - If this option is set TinyCrypt library is used for emulating the + If this option is set PSA Crypto API library is used for emulating the ECDH HCI commands and events needed by e.g. LE Secure Connections. In builds including the BLE Host, if not set the controller crypto is used for ECDH and if the controller doesn't support the required HCI diff --git a/subsys/bluetooth/host/Kconfig.gatt b/subsys/bluetooth/host/Kconfig.gatt index c9c9247dc91c2..20f9e53833d2c 100644 --- a/subsys/bluetooth/host/Kconfig.gatt +++ b/subsys/bluetooth/host/Kconfig.gatt @@ -115,11 +115,10 @@ config BT_GATT_CACHING bool "GATT Caching support" default y depends on BT_GATT_SERVICE_CHANGED - select TINYCRYPT if !BT_USE_PSA_API - select TINYCRYPT_AES if !BT_USE_PSA_API - select TINYCRYPT_AES_CMAC if !BT_USE_PSA_API - select PSA_WANT_KEY_TYPE_AES if BT_USE_PSA_API - select PSA_WANT_ALG_CMAC if BT_USE_PSA_API + depends on PSA_CRYPTO_CLIENT + select PSA_WANT_KEY_TYPE_AES + select PSA_WANT_ALG_CMAC + select MBEDTLS_AES_ROM_TABLES if MBEDTLS_PSA_CRYPTO_C help This option enables support for GATT Caching. When enabled the stack will register Client Supported Features and Database Hash diff --git a/subsys/bluetooth/host/crypto_psa.c b/subsys/bluetooth/host/crypto_psa.c index 041a2f9cd047e..d3f2de3b88685 100644 --- a/subsys/bluetooth/host/crypto_psa.c +++ b/subsys/bluetooth/host/crypto_psa.c @@ -30,6 +30,7 @@ LOG_MODULE_REGISTER(bt_host_crypto); int prng_init(void) { if (psa_crypto_init() != PSA_SUCCESS) { + LOG_ERR("psa_crypto_init() failed"); return -EIO; } return 0; @@ -42,6 +43,7 @@ int bt_rand(void *buf, size_t len) return 0; } + LOG_ERR("psa_generate_random() failed"); return -EIO; } #else /* !CONFIG_BT_HOST_CRYPTO_PRNG */ diff --git a/subsys/bluetooth/host/crypto_tc.c b/subsys/bluetooth/host/crypto_tc.c deleted file mode 100644 index 1ffe94a459253..0000000000000 --- a/subsys/bluetooth/host/crypto_tc.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2017 Nordic Semiconductor ASA - * Copyright (c) 2015-2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "common/bt_str.h" - -#include "hci_core.h" - -#define LOG_LEVEL CONFIG_BT_HCI_CORE_LOG_LEVEL -#include -LOG_MODULE_REGISTER(bt_host_crypto); - -static struct tc_hmac_prng_struct prng; - -static int prng_reseed(struct tc_hmac_prng_struct *h) -{ - uint8_t seed[32]; - int64_t extra; - int ret; - - ret = bt_hci_le_rand(seed, sizeof(seed)); - if (ret) { - return ret; - } - - extra = k_uptime_get(); - - ret = tc_hmac_prng_reseed(h, seed, sizeof(seed), (uint8_t *)&extra, - sizeof(extra)); - if (ret == TC_CRYPTO_FAIL) { - LOG_ERR("Failed to re-seed PRNG"); - return -EIO; - } - - return 0; -} - -int prng_init(void) -{ - uint8_t perso[8]; - int ret; - - ret = bt_hci_le_rand(perso, sizeof(perso)); - if (ret) { - return ret; - } - - ret = tc_hmac_prng_init(&prng, perso, sizeof(perso)); - if (ret == TC_CRYPTO_FAIL) { - LOG_ERR("Failed to initialize PRNG"); - return -EIO; - } - - /* re-seed is needed after init */ - return prng_reseed(&prng); -} - -#if defined(CONFIG_BT_HOST_CRYPTO_PRNG) -int bt_rand(void *buf, size_t len) -{ - int ret; - - CHECKIF(buf == NULL || len == 0) { - return -EINVAL; - } - - ret = tc_hmac_prng_generate(buf, len, &prng); - if (ret == TC_HMAC_PRNG_RESEED_REQ) { - ret = prng_reseed(&prng); - if (ret) { - return ret; - } - - ret = tc_hmac_prng_generate(buf, len, &prng); - } - - if (ret == TC_CRYPTO_SUCCESS) { - return 0; - } - - return -EIO; -} -#else /* !CONFIG_BT_HOST_CRYPTO_PRNG */ -int bt_rand(void *buf, size_t len) -{ - CHECKIF(buf == NULL || len == 0) { - return -EINVAL; - } - - return bt_hci_le_rand(buf, len); -} -#endif /* CONFIG_BT_HOST_CRYPTO_PRNG */ - -int bt_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16], - uint8_t enc_data[16]) -{ - struct tc_aes_key_sched_struct s; - uint8_t tmp[16]; - - CHECKIF(key == NULL || plaintext == NULL || enc_data == NULL) { - return -EINVAL; - } - - LOG_DBG("key %s", bt_hex(key, 16)); - LOG_DBG("plaintext %s", bt_hex(plaintext, 16)); - - sys_memcpy_swap(tmp, key, 16); - - if (tc_aes128_set_encrypt_key(&s, tmp) == TC_CRYPTO_FAIL) { - return -EINVAL; - } - - sys_memcpy_swap(tmp, plaintext, 16); - - if (tc_aes_encrypt(enc_data, tmp, &s) == TC_CRYPTO_FAIL) { - return -EINVAL; - } - - sys_mem_swap(enc_data, 16); - - LOG_DBG("enc_data %s", bt_hex(enc_data, 16)); - - return 0; -} - -int bt_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16], - uint8_t enc_data[16]) -{ - struct tc_aes_key_sched_struct s; - - CHECKIF(key == NULL || plaintext == NULL || enc_data == NULL) { - return -EINVAL; - } - - LOG_DBG("key %s", bt_hex(key, 16)); - LOG_DBG("plaintext %s", bt_hex(plaintext, 16)); - - if (tc_aes128_set_encrypt_key(&s, key) == TC_CRYPTO_FAIL) { - return -EINVAL; - } - - if (tc_aes_encrypt(enc_data, plaintext, &s) == TC_CRYPTO_FAIL) { - return -EINVAL; - } - - LOG_DBG("enc_data %s", bt_hex(enc_data, 16)); - - return 0; -} - -#ifdef ZTEST_UNITTEST -struct tc_hmac_prng_struct *bt_crypto_get_hmac_prng_instance(void) -{ - return &prng; -} -#endif /* ZTEST_UNITTEST */ diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 118af2097afe0..fe2512f8762ac 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -21,15 +21,7 @@ #include #if defined(CONFIG_BT_GATT_CACHING) -#if defined(CONFIG_BT_USE_PSA_API) #include "psa/crypto.h" -#else /* CONFIG_BT_USE_PSA_API */ -#include -#include -#include -#include -#include -#endif /* CONFIG_BT_USE_PSA_API */ #endif /* CONFIG_BT_GATT_CACHING */ #include @@ -703,7 +695,6 @@ static ssize_t cf_write(struct bt_conn *conn, const struct bt_gatt_attr *attr, return len; } -#if defined(CONFIG_BT_USE_PSA_API) struct gen_hash_state { psa_mac_operation_t operation; psa_key_id_t key; @@ -753,43 +744,6 @@ static int db_hash_finish(struct gen_hash_state *state) return 0; } -#else /* CONFIG_BT_USE_PSA_API */ -struct gen_hash_state { - struct tc_cmac_struct state; - struct tc_aes_key_sched_struct sched; - int err; -}; - -static int db_hash_setup(struct gen_hash_state *state, uint8_t *key) -{ - if (tc_cmac_setup(&(state->state), key, &(state->sched)) == TC_CRYPTO_FAIL) { - LOG_ERR("CMAC setup failed"); - return -EIO; - } - return 0; -} - -static int db_hash_update(struct gen_hash_state *state, uint8_t *data, size_t len) -{ - if (tc_cmac_update(&state->state, data, len) == TC_CRYPTO_FAIL) { - LOG_ERR("CMAC update failed"); - return -EIO; - } - return 0; -} - -static int db_hash_finish(struct gen_hash_state *state) -{ - if (tc_cmac_final(db_hash.hash, &(state->state)) == TC_CRYPTO_FAIL) { - LOG_ERR("CMAC finish failed"); - return -EIO; - } - return 0; -} - - -#endif /* CONFIG_BT_USE_PSA_API */ - union hash_attr_value { /* Bluetooth Core Specification Version 5.3 | Vol 3, Part G * Table 3.1: Service declaration diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 4606c8c9b1f1c..d71fc143fd9fd 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3215,9 +3215,9 @@ static void read_supported_commands_complete(struct net_buf *buf) sizeof(bt_dev.supported_commands)); /* Report additional HCI commands used for ECDH as - * supported if TinyCrypt ECC is used for emulation. + * supported if PSA Crypto API ECC is used for emulation. */ - if (IS_ENABLED(CONFIG_BT_TINYCRYPT_ECC)) { + if (IS_ENABLED(CONFIG_BT_SEND_ECC_EMULATION)) { bt_hci_ecc_supported_commands(bt_dev.supported_commands); } } @@ -4069,7 +4069,7 @@ int bt_send(struct net_buf *buf) bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len); - if (IS_ENABLED(CONFIG_BT_TINYCRYPT_ECC)) { + if (IS_ENABLED(CONFIG_BT_SEND_ECC_EMULATION)) { return bt_hci_ecc_send(buf); } diff --git a/subsys/bluetooth/host/hci_ecc.c b/subsys/bluetooth/host/hci_ecc.c index 39fc7ef47a2f5..a30328d871b28 100644 --- a/subsys/bluetooth/host/hci_ecc.c +++ b/subsys/bluetooth/host/hci_ecc.c @@ -14,14 +14,7 @@ #include #include -#if defined(CONFIG_BT_USE_PSA_API) #include -#else /* !CONFIG_BT_USE_PSA_API */ -#include -#include -#include -#include -#endif /* CONFIG_BT_USE_PSA_API*/ #include #include @@ -109,7 +102,6 @@ static void send_cmd_status(uint16_t opcode, uint8_t status) #endif } -#if defined(CONFIG_BT_USE_PSA_API) static void set_key_attributes(psa_key_attributes_t *attr) { psa_set_key_type(attr, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)); @@ -156,29 +148,6 @@ static uint8_t generate_keys(void) return 0; } -#else -static uint8_t generate_keys(void) -{ - do { - int rc; - - rc = uECC_make_key(ecc.public_key_be, ecc.private_key_be, - &curve_secp256r1); - if (rc == TC_CRYPTO_FAIL) { - LOG_ERR("Failed to create ECC public/private pair"); - return BT_HCI_ERR_UNSPECIFIED; - } - - /* make sure generated key isn't debug key */ - } while (memcmp(ecc.private_key_be, debug_private_key_be, BT_PRIV_KEY_LEN) == 0); - - if (IS_ENABLED(CONFIG_BT_LOG_SNIFFER_INFO)) { - LOG_INF("SC private key 0x%s", bt_hex(ecc.private_key_be, BT_PRIV_KEY_LEN)); - } - - return 0; -} -#endif /* CONFIG_BT_USE_PSA_API */ static void emulate_le_p256_public_key_cmd(void) { @@ -233,7 +202,6 @@ static void emulate_le_generate_dhkey(void) int ret = 0; bool use_debug = atomic_test_bit(flags, USE_DEBUG_KEY); -#if defined(CONFIG_BT_USE_PSA_API) psa_key_attributes_t attr = PSA_KEY_ATTRIBUTES_INIT; psa_key_id_t key_id; /* PSA expects secp256r1 public key to start with a predefined 0x04 byte @@ -265,19 +233,6 @@ static void emulate_le_generate_dhkey(void) ret = -EIO; } -#else /* !CONFIG_BT_USE_PSA_API */ - ret = uECC_valid_public_key(ecc.public_key_be, &curve_secp256r1); - if (ret < 0) { - LOG_ERR("public key is not valid (ret %d)", ret); - ret = -EIO; - goto exit; - } - ret = uECC_shared_secret(ecc.public_key_be, - use_debug ? debug_private_key_be : ecc.private_key_be, - ecc.dhkey_be, &curve_secp256r1); - ret = (ret == TC_CRYPTO_FAIL) ? -EIO : 0; -#endif /* CONFIG_BT_USE_PSA_API */ - exit: buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER); diff --git a/subsys/bluetooth/host/hci_raw.c b/subsys/bluetooth/host/hci_raw.c index 984c8607ee653..ba51959be8353 100644 --- a/subsys/bluetooth/host/hci_raw.c +++ b/subsys/bluetooth/host/hci_raw.c @@ -323,7 +323,7 @@ int bt_send(struct net_buf *buf) } } - if (IS_ENABLED(CONFIG_BT_TINYCRYPT_ECC)) { + if (IS_ENABLED(CONFIG_BT_SEND_ECC_EMULATION)) { return bt_hci_ecc_send(buf); } diff --git a/subsys/bluetooth/mesh/CMakeLists.txt b/subsys/bluetooth/mesh/CMakeLists.txt index 3d5deadc6d92d..6b76809cb1d2c 100644 --- a/subsys/bluetooth/mesh/CMakeLists.txt +++ b/subsys/bluetooth/mesh/CMakeLists.txt @@ -123,11 +123,7 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_STATISTIC statistic.c) zephyr_library_sources_ifdef(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG delayable_msg.c) -if (CONFIG_BT_MESH_USES_TINYCRYPT) - zephyr_library_sources(crypto_tc.c) -else() - zephyr_library_sources(crypto_psa.c) -endif() +zephyr_library_sources(crypto_psa.c) zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index e300e18d799ea..703370b54d7e9 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1448,30 +1448,15 @@ endmenu # Proxy choice BT_MESH_CRYPTO_LIB prompt "Crypto library:" default BT_MESH_USES_TFM_PSA if BUILD_WITH_TFM - default BT_MESH_USES_TINYCRYPT + default BT_MESH_USES_MBEDTLS_PSA help Crypto library selection for mesh security. -config BT_MESH_USES_TINYCRYPT - bool "TinyCrypt" - select TINYCRYPT - select TINYCRYPT_AES - select TINYCRYPT_AES_CMAC - select TINYCRYPT_ECC_DH - select TINYCRYPT_SHA256 - select TINYCRYPT_SHA256_HMAC - select BT_HOST_CCM - help - Use TinyCrypt library to perform crypto operations. - config BT_MESH_USES_MBEDTLS_PSA - bool "mbed TLS PSA [EXPERIMENTAL]" - select EXPERIMENTAL + bool "mbed TLS PSA" select MBEDTLS - select MBEDTLS_ENTROPY_C - select MBEDTLS_ENTROPY_POLL_ZEPHYR select MBEDTLS_PSA_CRYPTO_C - select MBEDTLS_USE_PSA_CRYPTO + select MBEDTLS_ENTROPY_C select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE diff --git a/subsys/bluetooth/mesh/crypto_tc.c b/subsys/bluetooth/mesh/crypto_tc.c deleted file mode 100644 index 68cc9d14ed03c..0000000000000 --- a/subsys/bluetooth/mesh/crypto_tc.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2017 Intel Corporation - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define LOG_LEVEL CONFIG_BT_MESH_CRYPTO_LOG_LEVEL -#include -LOG_MODULE_REGISTER(bt_mesh_crypto_tc); - -#include "mesh.h" -#include "crypto.h" -#include "prov.h" - -static struct { - bool is_ready; - uint8_t private_key_be[PRIV_KEY_SIZE]; - uint8_t public_key_be[PUB_KEY_SIZE]; -} dh_pair; - -int bt_mesh_encrypt(const struct bt_mesh_key *key, const uint8_t plaintext[16], - uint8_t enc_data[16]) -{ - return bt_encrypt_be(key->key, plaintext, enc_data); -} - -int bt_mesh_ccm_encrypt(const struct bt_mesh_key *key, uint8_t nonce[13], const uint8_t *plaintext, - size_t len, const uint8_t *aad, size_t aad_len, uint8_t *enc_data, - size_t mic_size) -{ - return bt_ccm_encrypt(key->key, nonce, plaintext, len, aad, aad_len, enc_data, mic_size); -} - -int bt_mesh_ccm_decrypt(const struct bt_mesh_key *key, uint8_t nonce[13], const uint8_t *enc_data, - size_t len, const uint8_t *aad, size_t aad_len, uint8_t *plaintext, - size_t mic_size) -{ - return bt_ccm_decrypt(key->key, nonce, enc_data, len, aad, aad_len, plaintext, mic_size); -} - -int bt_mesh_aes_cmac_raw_key(const uint8_t key[16], struct bt_mesh_sg *sg, size_t sg_len, - uint8_t mac[16]) -{ - struct tc_aes_key_sched_struct sched; - struct tc_cmac_struct state; - - if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) { - return -EIO; - } - - for (; sg_len; sg_len--, sg++) { - if (tc_cmac_update(&state, sg->data, sg->len) == TC_CRYPTO_FAIL) { - return -EIO; - } - } - - if (tc_cmac_final(mac, &state) == TC_CRYPTO_FAIL) { - return -EIO; - } - - return 0; -} - -int bt_mesh_aes_cmac_mesh_key(const struct bt_mesh_key *key, struct bt_mesh_sg *sg, - size_t sg_len, uint8_t mac[16]) -{ - return bt_mesh_aes_cmac_raw_key(key->key, sg, sg_len, mac); -} - -int bt_mesh_sha256_hmac_raw_key(const uint8_t key[32], struct bt_mesh_sg *sg, size_t sg_len, - uint8_t mac[32]) -{ - struct tc_hmac_state_struct h; - - if (tc_hmac_set_key(&h, key, 32) == TC_CRYPTO_FAIL) { - return -EIO; - } - - if (tc_hmac_init(&h) == TC_CRYPTO_FAIL) { - return -EIO; - } - - for (; sg_len; sg_len--, sg++) { - if (tc_hmac_update(&h, sg->data, sg->len) == TC_CRYPTO_FAIL) { - return -EIO; - } - } - - if (tc_hmac_final(mac, 32, &h) == TC_CRYPTO_FAIL) { - return -EIO; - } - - return 0; -} - -int bt_mesh_pub_key_gen(void) -{ - int rc = uECC_make_key(dh_pair.public_key_be, - dh_pair.private_key_be, - &curve_secp256r1); - - if (rc == TC_CRYPTO_FAIL) { - dh_pair.is_ready = false; - LOG_ERR("Failed to create public/private pair"); - return -EIO; - } - - dh_pair.is_ready = true; - - return 0; -} - -const uint8_t *bt_mesh_pub_key_get(void) -{ - return dh_pair.is_ready ? dh_pair.public_key_be : NULL; -} - -int bt_mesh_dhkey_gen(const uint8_t *pub_key, const uint8_t *priv_key, uint8_t *dhkey) -{ - if (uECC_valid_public_key(pub_key, &curve_secp256r1)) { - LOG_ERR("Public key is not valid"); - return -EIO; - } else if (uECC_shared_secret(pub_key, priv_key ? priv_key : - dh_pair.private_key_be, - dhkey, &curve_secp256r1) != TC_CRYPTO_SUCCESS) { - LOG_ERR("DHKey generation failed"); - return -EIO; - } - - return 0; -} - -__weak int default_CSPRNG(uint8_t *dst, unsigned int len) -{ - return !bt_rand(dst, len); -} - -int bt_mesh_crypto_init(void) -{ - return 0; -} diff --git a/subsys/bluetooth/mesh/keys.h b/subsys/bluetooth/mesh/keys.h index a72236e467831..b04e4f11bcbe3 100644 --- a/subsys/bluetooth/mesh/keys.h +++ b/subsys/bluetooth/mesh/keys.h @@ -13,42 +13,8 @@ enum bt_mesh_key_type { BT_MESH_KEY_TYPE_DEV }; -#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); void bt_mesh_key_assign(struct bt_mesh_key *dst, const struct bt_mesh_key *src); int bt_mesh_key_destroy(const struct bt_mesh_key *key); int bt_mesh_key_compare(const uint8_t raw_key[16], const struct bt_mesh_key *mesh_key); - -#elif defined CONFIG_BT_MESH_USES_TINYCRYPT - -static inline int bt_mesh_key_import(enum bt_mesh_key_type type, const uint8_t in[16], - struct bt_mesh_key *out) -{ - memcpy(out, in, 16); - return 0; -} - -static inline int bt_mesh_key_export(uint8_t out[16], const struct bt_mesh_key *in) -{ - memcpy(out, in, 16); - return 0; -} - -static inline void bt_mesh_key_assign(struct bt_mesh_key *dst, const struct bt_mesh_key *src) -{ - memcpy(dst, src, sizeof(struct bt_mesh_key)); -} - -static inline int bt_mesh_key_destroy(const struct bt_mesh_key *key) -{ - return 0; -} - -static inline int bt_mesh_key_compare(const uint8_t raw_key[16], const struct bt_mesh_key *mesh_key) -{ - return memcmp(mesh_key, raw_key, 16); -} - -#endif diff --git a/tests/bluetooth/bt_crypto/boards/qemu_cortex_m3.conf b/tests/bluetooth/bt_crypto/boards/qemu_cortex_m3.conf new file mode 100644 index 0000000000000..36ace22354cd0 --- /dev/null +++ b/tests/bluetooth/bt_crypto/boards/qemu_cortex_m3.conf @@ -0,0 +1,2 @@ +CONFIG_TEST_EXTRA_STACK_SIZE=1024 +CONFIG_MAIN_STACK_SIZE=2048 diff --git a/tests/bluetooth/host/crypto/CMakeLists.txt b/tests/bluetooth/host/crypto/CMakeLists.txt index 856b27562822a..d3b3c529042e0 100644 --- a/tests/bluetooth/host/crypto/CMakeLists.txt +++ b/tests/bluetooth/host/crypto/CMakeLists.txt @@ -8,11 +8,10 @@ add_library(mocks STATIC mocks/hci_core_expects.c mocks/aes.c mocks/aes_expects.c - mocks/hmac_prng.c - mocks/hmac_prng_expects.c - mocks/crypto_help_utils.c + mocks/prng.c + mocks/prng_expects.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/crypto_tc.c + ${ZEPHYR_BASE}/subsys/bluetooth/host/crypto_psa.c ${ZEPHYR_BASE}/subsys/logging/log_minimal.c ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c @@ -24,7 +23,7 @@ target_include_directories(mocks PUBLIC ${ZEPHYR_BASE}/subsys/bluetooth/host ${ZEPHYR_BASE}/tests/bluetooth/host ${ZEPHYR_BASE}/tests/bluetooth/host/crypto/mocks - ${ZEPHYR_BASE}/../modules/crypto/tinycrypt/lib/include + ${ZEPHYR_MBEDTLS_MODULE_DIR}/include ) target_link_libraries(mocks PRIVATE test_interface) diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c b/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c index 32e9ada29116c..f67bd165ddf7f 100644 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c @@ -28,8 +28,8 @@ ZTEST_SUITE(bt_encrypt_be, NULL, NULL, NULL, NULL, NULL); * Test bt_encrypt_be() succeeds * * Constraints: - * - tc_aes128_set_encrypt_key() succeeds and returns 'TC_CRYPTO_SUCCESS'. - * - tc_aes_encrypt() succeeds and returns 'TC_CRYPTO_SUCCESS'. + * - psa_import_key() succeeds and returns 'PSA_SUCCESS'. + * - psa_cipher_encrypt() succeeds and returns 'PSA_SUCCESS'. * * Expected behaviour: * - bt_encrypt_be() returns 0 (success) @@ -41,12 +41,12 @@ ZTEST(bt_encrypt_be, test_bt_encrypt_be_succeeds) const uint8_t plaintext[16] = {0}; uint8_t enc_data[16] = {0}; - tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_SUCCESS; - tc_aes_encrypt_fake.return_val = TC_CRYPTO_SUCCESS; + psa_import_key_fake.return_val = PSA_SUCCESS; + psa_cipher_encrypt_fake.return_val = PSA_SUCCESS; err = bt_encrypt_be(key, plaintext, enc_data); - expect_single_call_tc_aes_encrypt(enc_data); + expect_single_call_psa_cipher_encrypt(enc_data); zassert_ok(err, "Unexpected error code '%d' was returned", err); } diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c index 2e32d47f3467b..06aab4d114914 100644 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c @@ -12,7 +12,7 @@ #include -ZTEST_SUITE(bt_encrypt_le_invalid_cases, NULL, NULL, NULL, NULL, NULL); +ZTEST_SUITE(bt_encrypt_be_invalid_cases, NULL, NULL, NULL, NULL, NULL); /* * Test passing NULL reference for the key argument @@ -24,7 +24,7 @@ ZTEST_SUITE(bt_encrypt_le_invalid_cases, NULL, NULL, NULL, NULL, NULL); * Expected behaviour: * - An assertion is raised and execution stops */ -ZTEST(bt_encrypt_le_invalid_cases, test_null_key_reference) +ZTEST(bt_encrypt_be_invalid_cases, test_null_key_reference) { const uint8_t plaintext[16] = {0}; uint8_t enc_data[16] = {0}; @@ -43,7 +43,7 @@ ZTEST(bt_encrypt_le_invalid_cases, test_null_key_reference) * Expected behaviour: * - An assertion is raised and execution stops */ -ZTEST(bt_encrypt_le_invalid_cases, test_null_plaintext_reference) +ZTEST(bt_encrypt_be_invalid_cases, test_null_plaintext_reference) { const uint8_t key[16] = {0}; uint8_t enc_data[16] = {0}; @@ -62,7 +62,7 @@ ZTEST(bt_encrypt_le_invalid_cases, test_null_plaintext_reference) * Expected behaviour: * - An assertion is raised and execution stops */ -ZTEST(bt_encrypt_le_invalid_cases, test_null_enc_data_reference) +ZTEST(bt_encrypt_be_invalid_cases, test_null_enc_data_reference) { const uint8_t key[16] = {0}; const uint8_t plaintext[16] = {0}; @@ -75,19 +75,19 @@ ZTEST(bt_encrypt_le_invalid_cases, test_null_enc_data_reference) * Test bt_encrypt_le() fails when tc_aes128_set_encrypt_key() fails * * Constraints: - * - tc_aes128_set_encrypt_key() fails and returns 'TC_CRYPTO_FAIL'. + * - psa_import_key() fails and returns 'PSA_ERROR_GENERIC_ERROR'. * * Expected behaviour: * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) */ -ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes128_set_encrypt_key_fails) +ZTEST(bt_encrypt_be_invalid_cases, test_psa_import_key_fails) { int err; const uint8_t key[16] = {0}; const uint8_t plaintext[16] = {0}; uint8_t enc_data[16] = {0}; - tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_FAIL; + psa_import_key_fake.return_val = PSA_ERROR_GENERIC_ERROR; err = bt_encrypt_le(key, plaintext, enc_data); @@ -98,23 +98,23 @@ ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes128_set_encrypt_key_fails) * Test bt_encrypt_le() fails when tc_aes_encrypt() fails * * Constraints: - * - tc_aes128_set_encrypt_key() succeeds and returns 'TC_CRYPTO_SUCCESS'. - * - tc_aes_encrypt() fails and returns 'TC_CRYPTO_FAIL'. + * - psa_import_key() succeeds and returns 'PSA_SUCCESS'. + * - psa_cipher_encrypt() fails and returns 'PSA_ERROR_GENERIC_ERROR'. * * Expected behaviour: * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) */ -ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes_encrypt_fails) +ZTEST(bt_encrypt_be_invalid_cases, test_psa_cipher_encrypt_fails) { int err; const uint8_t key[16] = {0}; const uint8_t plaintext[16] = {0}; uint8_t enc_data[16] = {0}; - tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_SUCCESS; - tc_aes_encrypt_fake.return_val = TC_CRYPTO_FAIL; + psa_import_key_fake.return_val = PSA_SUCCESS; + psa_cipher_encrypt_fake.return_val = -EINVAL; err = bt_encrypt_le(key, plaintext, enc_data); - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); + zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); } diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c b/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c index 4442885456e81..e59a2802547e6 100644 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c @@ -41,12 +41,12 @@ ZTEST(bt_encrypt_le, test_bt_encrypt_le_succeeds) const uint8_t plaintext[16] = {0}; uint8_t enc_data[16] = {0}; - tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_SUCCESS; - tc_aes_encrypt_fake.return_val = TC_CRYPTO_SUCCESS; + psa_import_key_fake.return_val = PSA_SUCCESS; + psa_cipher_encrypt_fake.return_val = PSA_SUCCESS; err = bt_encrypt_le(key, plaintext, enc_data); - expect_single_call_tc_aes_encrypt(enc_data); + expect_single_call_psa_cipher_encrypt(enc_data); zassert_ok(err, "Unexpected error code '%d' was returned", err); } diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c index 2e32d47f3467b..a2bf6af09dfb7 100644 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c @@ -87,7 +87,7 @@ ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes128_set_encrypt_key_fails) const uint8_t plaintext[16] = {0}; uint8_t enc_data[16] = {0}; - tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_FAIL; + psa_import_key_fake.return_val = PSA_ERROR_GENERIC_ERROR; err = bt_encrypt_le(key, plaintext, enc_data); @@ -98,8 +98,8 @@ ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes128_set_encrypt_key_fails) * Test bt_encrypt_le() fails when tc_aes_encrypt() fails * * Constraints: - * - tc_aes128_set_encrypt_key() succeeds and returns 'TC_CRYPTO_SUCCESS'. - * - tc_aes_encrypt() fails and returns 'TC_CRYPTO_FAIL'. + * - psa_import_key() succeeds and returns 'PSA_SUCCESS'. + * - psa_cipher_encrypt() fails and returns '-EINVAL'. * * Expected behaviour: * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) @@ -111,10 +111,10 @@ ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes_encrypt_fails) const uint8_t plaintext[16] = {0}; uint8_t enc_data[16] = {0}; - tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_SUCCESS; - tc_aes_encrypt_fake.return_val = TC_CRYPTO_FAIL; + psa_import_key_fake.return_val = PSA_SUCCESS; + psa_cipher_encrypt_fake.return_val = -EINVAL; err = bt_encrypt_le(key, plaintext, enc_data); - zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); + zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); } diff --git a/tests/bluetooth/host/crypto/bt_rand/src/main.c b/tests/bluetooth/host/crypto/bt_rand/src/main.c index b288d2172c8f2..0ea192e003673 100644 --- a/tests/bluetooth/host/crypto/bt_rand/src/main.c +++ b/tests/bluetooth/host/crypto/bt_rand/src/main.c @@ -4,11 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "mocks/crypto_help_utils.h" #include "mocks/hci_core.h" #include "mocks/hci_core_expects.h" -#include "mocks/hmac_prng.h" -#include "mocks/hmac_prng_expects.h" +#include "mocks/prng.h" +#include "mocks/prng_expects.h" #include #include @@ -21,7 +20,7 @@ DEFINE_FFF_GLOBALS; static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) { HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); - HMAC_PRNG_FFF_FAKES_LIST(RESET_FAKE); + PRNG_FFF_FAKES_LIST(RESET_FAKE); } ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); @@ -57,74 +56,29 @@ ZTEST(bt_rand, test_bt_rand_succeeds_host_crypto_prng_disabled) } /* - * Test bt_rand() succeeds when tc_hmac_prng_generate() succeeds on the first call while + * Test bt_rand() succeeds when psa_generate_random() succeeds on the first call while * 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. * * Constraints: * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled - * - tc_hmac_prng_generate() succeeds and returns 'TC_CRYPTO_SUCCESS' on the first call. + * - psa_generate_random() succeeds and returns 'PSA_SUCCESS' on the first call. * * Expected behaviour: * - bt_rand() returns 0 (success) */ -ZTEST(bt_rand, test_tc_hmac_prng_generate_succeeds_on_first_call) +ZTEST(bt_rand, test_psa_generate_random_succeeds_on_first_call) { int err; uint8_t buf[16]; size_t buf_len = 16; - struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - tc_hmac_prng_generate_fake.return_val = TC_CRYPTO_SUCCESS; + psa_generate_random_fake.return_val = PSA_SUCCESS; err = bt_rand(buf, buf_len); - expect_call_count_tc_hmac_prng_generate(1, buf, buf_len, hmac_prng); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} - -static int tc_hmac_prng_generate_custom_fake(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng) -{ - if (tc_hmac_prng_generate_fake.call_count == 1) { - return TC_HMAC_PRNG_RESEED_REQ; - } - - return TC_CRYPTO_SUCCESS; -} - -/* - * Test bt_rand() succeeds when tc_hmac_prng_generate() succeeds on the second call after a seeding - * request by tc_hmac_prng_generate() while 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. - * - * Constraints: - * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled - * - tc_hmac_prng_generate() fails and returns 'TC_HMAC_PRNG_RESEED_REQ' on the first call. - * - tc_hmac_prng_generate() succeeds and returns 'TC_CRYPTO_SUCCESS' on the second call. - * - * Expected behaviour: - * - bt_rand() returns 0 (success) - */ -ZTEST(bt_rand, test_tc_hmac_prng_generate_succeeds_on_second_call) -{ - int err; - uint8_t buf[16]; - size_t buf_len = 16; - struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - - tc_hmac_prng_generate_fake.custom_fake = tc_hmac_prng_generate_custom_fake; - - /* This is to make prng_reseed() succeeds and return 0 */ - bt_hci_le_rand_fake.return_val = 0; - tc_hmac_prng_reseed_fake.return_val = TC_CRYPTO_SUCCESS; - - err = bt_rand(buf, buf_len); - - expect_call_count_tc_hmac_prng_generate(2, buf, buf_len, hmac_prng); - expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t)); + expect_single_call_psa_generate_random(buf, buf_len); zassert_ok(err, "Unexpected error code '%d' was returned", err); } diff --git a/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c index b3c9e60e8f59f..78edae4a2e6ab 100644 --- a/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c +++ b/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c @@ -5,11 +5,10 @@ */ #include "host_mocks/assert.h" -#include "mocks/crypto_help_utils.h" #include "mocks/hci_core.h" #include "mocks/hci_core_expects.h" -#include "mocks/hmac_prng.h" -#include "mocks/hmac_prng_expects.h" +#include "mocks/prng.h" +#include "mocks/prng_expects.h" #include #include @@ -81,12 +80,12 @@ ZTEST(bt_rand_invalid_cases, test_bt_hci_le_rand_fails) } /* - * Test bt_rand() fails when tc_hmac_prng_generate() fails on the first call while + * Test bt_rand() fails when psa_generate_random() fails on the first call while * 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. * * Constraints: * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled - * - tc_hmac_prng_generate() fails and returns 'TC_CRYPTO_FAIL' on the first call. + * - psa_generate_random() fails and returns '-EIO' on the first call. * * Expected behaviour: * - bt_rand() returns a negative error code '-EIO' (failure) @@ -96,92 +95,14 @@ ZTEST(bt_rand_invalid_cases, test_tc_hmac_prng_generate_fails_on_first_call) int err; uint8_t buf[16]; size_t buf_len = 16; - struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - tc_hmac_prng_generate_fake.return_val = TC_CRYPTO_FAIL; + psa_generate_random_fake.return_val = -EIO; err = bt_rand(buf, buf_len); - expect_call_count_tc_hmac_prng_generate(1, buf, buf_len, hmac_prng); - - zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); -} - -/* - * Test bt_rand() fails when prng_reseed() fails on seeding request by tc_hmac_prng_generate() - * while 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. - * - * Constraints: - * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled - * - tc_hmac_prng_generate() fails and returns 'TC_HMAC_PRNG_RESEED_REQ' on the first call. - * - prng_reseed() fails and returns a negative error code - * - * Expected behaviour: - * - bt_rand() returns a negative error code (failure) - */ -ZTEST(bt_rand_invalid_cases, test_prng_reseed_fails_on_seeding_request) -{ - int err; - uint8_t buf[16]; - size_t buf_len = 16; - struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - - tc_hmac_prng_generate_fake.return_val = TC_HMAC_PRNG_RESEED_REQ; - - /* This is to make prng_reseed() fails */ - bt_hci_le_rand_fake.return_val = -1; - - err = bt_rand(buf, buf_len); - - expect_call_count_tc_hmac_prng_generate(1, buf, buf_len, hmac_prng); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -static int tc_hmac_prng_generate_custom_fake(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng) -{ - if (tc_hmac_prng_generate_fake.call_count == 1) { - return TC_HMAC_PRNG_RESEED_REQ; - } - - return TC_CRYPTO_FAIL; -} - -/* - * Test bt_rand() fails when tc_hmac_prng_generate() fails on the second call after a seeding - * request by tc_hmac_prng_generate() while 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. - * - * Constraints: - * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled - * - tc_hmac_prng_generate() fails and returns 'TC_HMAC_PRNG_RESEED_REQ' on the first call. - * - tc_hmac_prng_generate() fails and returns 'TC_CRYPTO_FAIL' on the second call. - * - * Expected behaviour: - * - bt_rand() returns a negative error code '-EIO' (failure) - */ -ZTEST(bt_rand_invalid_cases, test_tc_hmac_prng_generate_fails_on_second_call) -{ - int err; - uint8_t buf[16]; - size_t buf_len = 16; - struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); - - Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); - - tc_hmac_prng_generate_fake.custom_fake = tc_hmac_prng_generate_custom_fake; - - /* This is to make prng_reseed() succeeds and return 0 */ - bt_hci_le_rand_fake.return_val = 0; - tc_hmac_prng_reseed_fake.return_val = TC_CRYPTO_SUCCESS; - - err = bt_rand(buf, buf_len); - - expect_call_count_tc_hmac_prng_generate(2, buf, buf_len, hmac_prng); - expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t)); + expect_single_call_psa_generate_random(buf, buf_len); zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); } diff --git a/tests/bluetooth/host/crypto/mocks/aes.c b/tests/bluetooth/host/crypto/mocks/aes.c index e931614ed6f8b..37184f49e6705 100644 --- a/tests/bluetooth/host/crypto/mocks/aes.c +++ b/tests/bluetooth/host/crypto/mocks/aes.c @@ -7,5 +7,10 @@ #include #include "mocks/aes.h" -DEFINE_FAKE_VALUE_FUNC(int, tc_aes_encrypt, uint8_t *, const uint8_t *, const TCAesKeySched_t); -DEFINE_FAKE_VALUE_FUNC(int, tc_aes128_set_encrypt_key, TCAesKeySched_t, const uint8_t *); +DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_crypto_init); +DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_generate_random, uint8_t *, size_t); +DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_import_key, const psa_key_attributes_t *, const uint8_t *, + size_t, mbedtls_svc_key_id_t *); +DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_cipher_encrypt, mbedtls_svc_key_id_t, psa_algorithm_t, + const uint8_t *, size_t, uint8_t *, size_t, size_t *); +DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_destroy_key, mbedtls_svc_key_id_t); diff --git a/tests/bluetooth/host/crypto/mocks/aes.h b/tests/bluetooth/host/crypto/mocks/aes.h index b58b257852eb7..3f072dab76086 100644 --- a/tests/bluetooth/host/crypto/mocks/aes.h +++ b/tests/bluetooth/host/crypto/mocks/aes.h @@ -6,13 +6,20 @@ #include #include -#include -#include +#include /* List of fakes used by this unit tester */ #define AES_FFF_FAKES_LIST(FAKE) \ - FAKE(tc_aes_encrypt) \ - FAKE(tc_aes128_set_encrypt_key) + FAKE(psa_crypto_init) \ + FAKE(psa_generate_random) \ + FAKE(psa_import_key) \ + FAKE(psa_cipher_encrypt) \ + FAKE(psa_destroy_key) -DECLARE_FAKE_VALUE_FUNC(int, tc_aes_encrypt, uint8_t *, const uint8_t *, const TCAesKeySched_t); -DECLARE_FAKE_VALUE_FUNC(int, tc_aes128_set_encrypt_key, TCAesKeySched_t, const uint8_t *); +DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_crypto_init); +DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_generate_random, uint8_t *, size_t); +DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_import_key, const psa_key_attributes_t *, const uint8_t *, + size_t, mbedtls_svc_key_id_t *); +DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_cipher_encrypt, mbedtls_svc_key_id_t, psa_algorithm_t, + const uint8_t *, size_t, uint8_t *, size_t, size_t *); +DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_destroy_key, mbedtls_svc_key_id_t); diff --git a/tests/bluetooth/host/crypto/mocks/aes_expects.c b/tests/bluetooth/host/crypto/mocks/aes_expects.c index 10f627b9087f0..6927354712ac5 100644 --- a/tests/bluetooth/host/crypto/mocks/aes_expects.c +++ b/tests/bluetooth/host/crypto/mocks/aes_expects.c @@ -8,17 +8,19 @@ #include "mocks/aes.h" #include "mocks/aes_expects.h" -void expect_single_call_tc_aes_encrypt(uint8_t *out) +void expect_single_call_psa_cipher_encrypt(uint8_t *out) { - const char *func_name = "tc_aes_encrypt"; + const char *func_name = "psa_cipher_encrypt"; - zassert_equal(tc_aes_encrypt_fake.call_count, 1, "'%s()' was called more than once", + zassert_equal(psa_cipher_encrypt_fake.call_count, 1, "'%s()' was called more than once", func_name); - zassert_equal_ptr(tc_aes_encrypt_fake.arg0_val, out, - "'%s()' was called with incorrect '%s' value", func_name, "out"); - zassert_not_null(tc_aes_encrypt_fake.arg1_val, - "'%s()' was called with incorrect '%s' value", func_name, "in"); - zassert_not_null(tc_aes_encrypt_fake.arg2_val, - "'%s()' was called with incorrect '%s' value", func_name, "s"); + zassert_not_equal(psa_cipher_encrypt_fake.arg1_val, 0, + "'%s()' was called with incorrect '%s' value", func_name, "arg1"); + zassert_not_equal(psa_cipher_encrypt_fake.arg3_val, 0, + "'%s()' was called with incorrect '%s' value", func_name, "arg3"); + zassert_equal_ptr(psa_cipher_encrypt_fake.arg4_val, out, + "'%s()' was called with incorrect '%s' value", func_name, "arg4"); + zassert_not_equal(psa_cipher_encrypt_fake.arg5_val, 0, + "'%s()' was called with incorrect '%s' value", func_name, "arg5"); } diff --git a/tests/bluetooth/host/crypto/mocks/aes_expects.h b/tests/bluetooth/host/crypto/mocks/aes_expects.h index 33022aa4b8efc..031db8439a9c2 100644 --- a/tests/bluetooth/host/crypto/mocks/aes_expects.h +++ b/tests/bluetooth/host/crypto/mocks/aes_expects.h @@ -7,9 +7,9 @@ #include /* - * Validate expected behaviour when tc_aes_encrypt() is called + * Validate expected behaviour when psa_cipher_encrypt() is called * * Expected behaviour: - * - tc_aes_encrypt() to be called once with correct parameters + * - psa_cipher_encrypt() to be called once with correct parameters */ -void expect_single_call_tc_aes_encrypt(uint8_t *out); +void expect_single_call_psa_cipher_encrypt(uint8_t *out); diff --git a/tests/bluetooth/host/crypto/mocks/crypto_help_utils.c b/tests/bluetooth/host/crypto/mocks/crypto_help_utils.c deleted file mode 100644 index 5c0428b0481b4..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/crypto_help_utils.c +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "crypto_help_utils.h" diff --git a/tests/bluetooth/host/crypto/mocks/crypto_help_utils.h b/tests/bluetooth/host/crypto/mocks/crypto_help_utils.h deleted file mode 100644 index 8c408ab4a2c2d..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/crypto_help_utils.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* crypto.c declarations */ -struct tc_hmac_prng_struct *bt_crypto_get_hmac_prng_instance(void); diff --git a/tests/bluetooth/host/crypto/mocks/hmac_prng.c b/tests/bluetooth/host/crypto/mocks/hmac_prng.c deleted file mode 100644 index 9f3536ab6ba9d..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/hmac_prng.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/hmac_prng.h" - -DEFINE_FAKE_VALUE_FUNC(int, tc_hmac_prng_init, TCHmacPrng_t, const uint8_t *, unsigned int); -DEFINE_FAKE_VALUE_FUNC(int, tc_hmac_prng_reseed, TCHmacPrng_t, const uint8_t *, unsigned int, - const uint8_t *, unsigned int); -DEFINE_FAKE_VALUE_FUNC(int, tc_hmac_prng_generate, uint8_t *, unsigned int, TCHmacPrng_t); diff --git a/tests/bluetooth/host/crypto/mocks/hmac_prng.h b/tests/bluetooth/host/crypto/mocks/hmac_prng.h deleted file mode 100644 index bdb1278f22e58..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/hmac_prng.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -/* List of fakes used by this unit tester */ -#define HMAC_PRNG_FFF_FAKES_LIST(FAKE) \ - FAKE(tc_hmac_prng_init) \ - FAKE(tc_hmac_prng_reseed) \ - FAKE(tc_hmac_prng_generate) - -DECLARE_FAKE_VALUE_FUNC(int, tc_hmac_prng_init, TCHmacPrng_t, const uint8_t *, unsigned int); -DECLARE_FAKE_VALUE_FUNC(int, tc_hmac_prng_reseed, TCHmacPrng_t, const uint8_t *, unsigned int, - const uint8_t *, unsigned int); -DECLARE_FAKE_VALUE_FUNC(int, tc_hmac_prng_generate, uint8_t *, unsigned int, TCHmacPrng_t); diff --git a/tests/bluetooth/host/crypto/mocks/hmac_prng_expects.c b/tests/bluetooth/host/crypto/mocks/hmac_prng_expects.c deleted file mode 100644 index 493ceab51e251..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/hmac_prng_expects.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mocks/hmac_prng.h" -#include "mocks/hmac_prng_expects.h" - -void expect_single_call_tc_hmac_prng_init(TCHmacPrng_t prng, unsigned int plen) -{ - const char *func_name = "tc_hmac_prng_init"; - - zassert_equal(tc_hmac_prng_init_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal_ptr(tc_hmac_prng_init_fake.arg0_val, prng, - "'%s()' was called with incorrect '%s' value", func_name, "prng"); - zassert_not_null(tc_hmac_prng_init_fake.arg1_val, - "'%s()' was called with incorrect '%s' value", func_name, "buffer"); - zassert_equal(tc_hmac_prng_init_fake.arg2_val, plen, - "'%s()' was called with incorrect '%s' value", func_name, "plen"); -} - -void expect_single_call_tc_hmac_prng_reseed(TCHmacPrng_t prng, unsigned int seedlen, - unsigned int additionallen) -{ - const char *func_name = "tc_hmac_prng_reseed"; - - zassert_equal(tc_hmac_prng_reseed_fake.call_count, 1, "'%s()' was called more than once", - func_name); - - zassert_equal_ptr(tc_hmac_prng_reseed_fake.arg0_val, prng, - "'%s()' was called with incorrect '%s' value", func_name, "prng"); - zassert_not_null(tc_hmac_prng_reseed_fake.arg1_val, - "'%s()' was called with incorrect '%s' value", func_name, "seed"); - zassert_equal(tc_hmac_prng_reseed_fake.arg2_val, seedlen, - "'%s()' was called with incorrect '%s' value", func_name, "seedlen"); - zassert_not_null(tc_hmac_prng_reseed_fake.arg3_val, - "'%s()' was called with incorrect '%s' value", func_name, - "additional_input"); - zassert_equal(tc_hmac_prng_reseed_fake.arg4_val, additionallen, - "'%s()' was called with incorrect '%s' value", func_name, "additionallen"); -} - -void expect_call_count_tc_hmac_prng_generate(int call_count, uint8_t *out, unsigned int outlen, - TCHmacPrng_t prng) -{ - const char *func_name = "tc_hmac_prng_generate"; - - zassert_equal(tc_hmac_prng_generate_fake.call_count, call_count, - "'%s()' was called more than once", func_name); - - zassert_equal_ptr(tc_hmac_prng_generate_fake.arg0_val, out, - "'%s()' was called with incorrect '%s' value", func_name, "out"); - zassert_equal(tc_hmac_prng_generate_fake.arg1_val, outlen, - "'%s()' was called with incorrect '%s' value", func_name, "outlen"); - zassert_equal_ptr(tc_hmac_prng_generate_fake.arg2_val, prng, - "'%s()' was called with incorrect '%s' value", func_name, "prng"); -} diff --git a/tests/bluetooth/host/crypto/mocks/hmac_prng_expects.h b/tests/bluetooth/host/crypto/mocks/hmac_prng_expects.h deleted file mode 100644 index 07d910917b542..0000000000000 --- a/tests/bluetooth/host/crypto/mocks/hmac_prng_expects.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/* - * Validate expected behaviour when tc_hmac_prng_init() is called - * - * Expected behaviour: - * - tc_hmac_prng_init() to be called once with correct parameters - */ -void expect_single_call_tc_hmac_prng_init(TCHmacPrng_t prng, unsigned int plen); - -/* - * Validate expected behaviour when tc_hmac_prng_reseed() is called - * - * Expected behaviour: - * - tc_hmac_prng_reseed() to be called once with correct parameters - */ -void expect_single_call_tc_hmac_prng_reseed(TCHmacPrng_t prng, unsigned int seedlen, - unsigned int additionallen); - -/* - * Validate expected behaviour when tc_hmac_prng_generate() is called - * - * Expected behaviour: - * - tc_hmac_prng_generate() to be called once with correct parameters - */ -void expect_call_count_tc_hmac_prng_generate(int call_count, uint8_t *out, unsigned int outlen, - TCHmacPrng_t prng); diff --git a/tests/bluetooth/host/crypto/mocks/prng.c b/tests/bluetooth/host/crypto/mocks/prng.c new file mode 100644 index 0000000000000..d38c9c4826a03 --- /dev/null +++ b/tests/bluetooth/host/crypto/mocks/prng.c @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "mocks/prng.h" + +DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_crypto_init); +DEFINE_FAKE_VALUE_FUNC(psa_status_t, psa_generate_random, uint8_t *, size_t); diff --git a/tests/bluetooth/host/crypto/mocks/prng.h b/tests/bluetooth/host/crypto/mocks/prng.h new file mode 100644 index 0000000000000..d5198e49459dd --- /dev/null +++ b/tests/bluetooth/host/crypto/mocks/prng.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +/* List of fakes used by this unit tester */ +#define PRNG_FFF_FAKES_LIST(FAKE) \ + FAKE(psa_crypto_init) \ + FAKE(psa_generate_random) + +DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_crypto_init); +DECLARE_FAKE_VALUE_FUNC(psa_status_t, psa_generate_random, uint8_t *, size_t); diff --git a/tests/bluetooth/host/crypto/mocks/prng_expects.c b/tests/bluetooth/host/crypto/mocks/prng_expects.c new file mode 100644 index 0000000000000..0dc11c639b532 --- /dev/null +++ b/tests/bluetooth/host/crypto/mocks/prng_expects.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "mocks/prng.h" +#include "mocks/prng_expects.h" + +void expect_single_call_tc_psa_crypto_init(void) +{ + const char *func_name = "psa_crypto_init"; + + zassert_equal(psa_crypto_init_fake.call_count, 1, "'%s()' was called more than once", + func_name); +} + +void expect_single_call_psa_generate_random(uint8_t *out, size_t outlen) +{ + const char *func_name = "psa_generate_random"; + + zassert_equal(psa_generate_random_fake.call_count, 1, + "'%s()' was called more than once", func_name); + + zassert_equal_ptr(psa_generate_random_fake.arg0_val, out, + "'%s()' was called with incorrect '%s' value", func_name, "out"); + zassert_equal(psa_generate_random_fake.arg1_val, outlen, + "'%s()' was called with incorrect '%s' value", func_name, "outlen"); +} diff --git a/tests/bluetooth/host/crypto/mocks/prng_expects.h b/tests/bluetooth/host/crypto/mocks/prng_expects.h new file mode 100644 index 0000000000000..43db853c9066d --- /dev/null +++ b/tests/bluetooth/host/crypto/mocks/prng_expects.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/* + * Validate expected behaviour when psa_crypto_init() is called + * + * Expected behaviour: + * - psa_crypto_init() to be called once with correct parameters + */ +void expect_single_call_tc_psa_crypto_init(void); + +/* + * Validate expected behaviour when psa_generate_random() is called + * + * Expected behaviour: + * - psa_generate_random() to be called once with correct parameters + */ +void expect_single_call_psa_generate_random(uint8_t *out, unsigned int outlen); diff --git a/tests/bluetooth/host/crypto/prng_init/CMakeLists.txt b/tests/bluetooth/host/crypto/prng_init/CMakeLists.txt deleted file mode 100644 index 56534b6a92cab..0000000000000 --- a/tests/bluetooth/host/crypto/prng_init/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(prng_init) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/crypto mocks) - -target_sources(testbinary PRIVATE - src/main.c - src/test_suite_invalid_inputs.c -) -target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/crypto/prng_init/prj.conf b/tests/bluetooth/host/crypto/prng_init/prj.conf deleted file mode 100644 index 9b9d1e2cafc40..0000000000000 --- a/tests/bluetooth/host/crypto/prng_init/prj.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_MAX_PAIRED=7 -CONFIG_ASSERT=y -CONFIG_ASSERT_LEVEL=2 -CONFIG_ASSERT_VERBOSE=y -CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/crypto/prng_init/src/main.c b/tests/bluetooth/host/crypto/prng_init/src/main.c deleted file mode 100644 index 2270aea1f135a..0000000000000 --- a/tests/bluetooth/host/crypto/prng_init/src/main.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mocks/crypto_help_utils.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/hmac_prng.h" -#include "mocks/hmac_prng_expects.h" - -#include -#include - -#include - -DEFINE_FFF_GLOBALS; - -static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) -{ - HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); - HMAC_PRNG_FFF_FAKES_LIST(RESET_FAKE); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); - -ZTEST_SUITE(prng_init, NULL, NULL, NULL, NULL, NULL); - -/* - * Test prng_init() succeeds - * - * Constraints: - * - bt_hci_le_rand() succeeds and returns 0 (success) - * - tc_hmac_prng_init() succeeds and returns 'TC_CRYPTO_SUCCESS'. - * - tc_hmac_prng_reseed() succeeds and returns 'TC_CRYPTO_SUCCESS'. - * - * Expected behaviour: - * - prng_init() returns 0 (success) - */ -ZTEST(prng_init, test_prng_init_succeeds) -{ - int err; - uint8_t expected_args_history[] = {8, 32}; - struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); - - bt_hci_le_rand_fake.return_val = 0; - tc_hmac_prng_init_fake.return_val = TC_CRYPTO_SUCCESS; - tc_hmac_prng_reseed_fake.return_val = TC_CRYPTO_SUCCESS; - - err = prng_init(); - - expect_call_count_bt_hci_le_rand(2, expected_args_history); - expect_single_call_tc_hmac_prng_init(hmac_prng, 8); - expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t)); - - zassert_ok(err, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/crypto/prng_init/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/prng_init/src/test_suite_invalid_inputs.c deleted file mode 100644 index fa25017c23e00..0000000000000 --- a/tests/bluetooth/host/crypto/prng_init/src/test_suite_invalid_inputs.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "host_mocks/assert.h" -#include "mocks/crypto_help_utils.h" -#include "mocks/hci_core.h" -#include "mocks/hci_core_expects.h" -#include "mocks/hmac_prng.h" -#include "mocks/hmac_prng_expects.h" - -#include - -#include - -ZTEST_SUITE(prng_init_invalid_cases, NULL, NULL, NULL, NULL, NULL); - -/* - * Test prng_init() fails when bt_hci_le_rand() fails - * - * Constraints: - * - bt_hci_le_rand() fails and returns a negative error code. - * - * Expected behaviour: - * - prng_init() returns a negative error code (failure) - */ -ZTEST(prng_init_invalid_cases, test_bt_hci_le_rand_fails) -{ - int err; - uint8_t expected_args_history[] = {8}; - - bt_hci_le_rand_fake.return_val = -1; - - err = prng_init(); - - expect_call_count_bt_hci_le_rand(1, expected_args_history); - - zassert_true(err < 0, "Unexpected error code '%d' was returned", err); -} - -/* - * Test prng_init() fails when tc_hmac_prng_init() fails - * - * Constraints: - * - bt_hci_le_rand() succeeds and returns 0 (success) - * - tc_hmac_prng_init() fails and returns 'TC_CRYPTO_FAIL'. - * - * Expected behaviour: - * - prng_init() returns a negative error code '-EIO' (failure) - */ -ZTEST(prng_init_invalid_cases, test_tc_hmac_prng_init_fails) -{ - int err; - uint8_t expected_args_history[] = {8}; - struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); - - bt_hci_le_rand_fake.return_val = 0; - tc_hmac_prng_init_fake.return_val = TC_CRYPTO_FAIL; - - err = prng_init(); - - expect_call_count_bt_hci_le_rand(1, expected_args_history); - expect_single_call_tc_hmac_prng_init(hmac_prng, 8); - - zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); -} - -/* - * Test prng_init() fails when prng_reseed() fails - * - * Constraints: - * - bt_hci_le_rand() succeeds and returns 0 (success) - * - tc_hmac_prng_init() succeeds and returns 'TC_CRYPTO_SUCCESS'. - * - tc_hmac_prng_reseed() fails and returns 'TC_CRYPTO_FAIL'. - * - * Expected behaviour: - * - prng_init() returns a negative error code '-EIO' (failure) - */ -ZTEST(prng_init_invalid_cases, test_prng_reseed_fails) -{ - int err; - uint8_t expected_args_history[] = {8, 32}; - struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); - - bt_hci_le_rand_fake.return_val = 0; - tc_hmac_prng_init_fake.return_val = TC_CRYPTO_SUCCESS; - tc_hmac_prng_reseed_fake.return_val = TC_CRYPTO_FAIL; - - err = prng_init(); - - expect_call_count_bt_hci_le_rand(2, expected_args_history); - expect_single_call_tc_hmac_prng_init(hmac_prng, 8); - expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t)); - - zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); -} diff --git a/tests/bluetooth/host/crypto/prng_init/testcase.yaml b/tests/bluetooth/host/crypto/prng_init/testcase.yaml deleted file mode 100644 index c93d73f23d272..0000000000000 --- a/tests/bluetooth/host/crypto/prng_init/testcase.yaml +++ /dev/null @@ -1,7 +0,0 @@ -common: - tags: - - bluetooth - - host -tests: - bluetooth.host.prng_init.default: - type: unit diff --git a/tests/bluetooth/init/prj_10.conf b/tests/bluetooth/init/prj_10.conf index 6aca735797234..317857577d7bf 100644 --- a/tests/bluetooth/init/prj_10.conf +++ b/tests/bluetooth/init/prj_10.conf @@ -4,6 +4,6 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_ZTEST=y diff --git a/tests/bluetooth/init/prj_11.conf b/tests/bluetooth/init/prj_11.conf index 6b46c845df81f..d0523c0fda211 100644 --- a/tests/bluetooth/init/prj_11.conf +++ b/tests/bluetooth/init/prj_11.conf @@ -4,7 +4,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_12.conf b/tests/bluetooth/init/prj_12.conf index 55111c5b28811..2fb4de6e9b3f9 100644 --- a/tests/bluetooth/init/prj_12.conf +++ b/tests/bluetooth/init/prj_12.conf @@ -3,7 +3,7 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_13.conf b/tests/bluetooth/init/prj_13.conf index 0de0be405ce3f..79b995a6b4624 100644 --- a/tests/bluetooth/init/prj_13.conf +++ b/tests/bluetooth/init/prj_13.conf @@ -3,7 +3,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_14.conf b/tests/bluetooth/init/prj_14.conf index a25c48d4bbbc1..d030c856e26df 100644 --- a/tests/bluetooth/init/prj_14.conf +++ b/tests/bluetooth/init/prj_14.conf @@ -3,5 +3,5 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_ZTEST=y diff --git a/tests/bluetooth/init/prj_15.conf b/tests/bluetooth/init/prj_15.conf index 3839272ce11a2..296cfb0dbe3e6 100644 --- a/tests/bluetooth/init/prj_15.conf +++ b/tests/bluetooth/init/prj_15.conf @@ -3,5 +3,5 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_ZTEST=y diff --git a/tests/bluetooth/init/prj_17.conf b/tests/bluetooth/init/prj_17.conf index 4ee00dca586b6..7cd0ea1699611 100644 --- a/tests/bluetooth/init/prj_17.conf +++ b/tests/bluetooth/init/prj_17.conf @@ -4,7 +4,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_20.conf b/tests/bluetooth/init/prj_20.conf index 43022222067fe..6df91453eb677 100644 --- a/tests/bluetooth/init/prj_20.conf +++ b/tests/bluetooth/init/prj_20.conf @@ -4,7 +4,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_21.conf b/tests/bluetooth/init/prj_21.conf index 2c0fad1fa136f..c930cc02c740b 100644 --- a/tests/bluetooth/init/prj_21.conf +++ b/tests/bluetooth/init/prj_21.conf @@ -4,7 +4,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_9.conf b/tests/bluetooth/init/prj_9.conf index be22972e42d6e..5e07e0f94799e 100644 --- a/tests/bluetooth/init/prj_9.conf +++ b/tests/bluetooth/init/prj_9.conf @@ -4,5 +4,5 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_ZTEST=y diff --git a/tests/bluetooth/init/prj_ctlr.conf b/tests/bluetooth/init/prj_ctlr.conf index 3b5ba787a0f21..2c4379487829e 100644 --- a/tests/bluetooth/init/prj_ctlr.conf +++ b/tests/bluetooth/init/prj_ctlr.conf @@ -7,7 +7,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y CONFIG_BT_CLASSIC=n diff --git a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf index 920a9f088609e..b244d14dd036f 100644 --- a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf +++ b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf @@ -59,7 +59,7 @@ CONFIG_BT_ISO_PERIPHERAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_ctlr_dbg.conf b/tests/bluetooth/init/prj_ctlr_dbg.conf index 386e81a33f919..19dda6f9b8216 100644 --- a/tests/bluetooth/init/prj_ctlr_dbg.conf +++ b/tests/bluetooth/init/prj_ctlr_dbg.conf @@ -42,7 +42,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_ctlr_ticker.conf b/tests/bluetooth/init/prj_ctlr_ticker.conf index 47c4f3f70629d..d2b4d31692e56 100644 --- a/tests/bluetooth/init/prj_ctlr_ticker.conf +++ b/tests/bluetooth/init/prj_ctlr_ticker.conf @@ -42,7 +42,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_USE_DEBUG_KEYS=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y diff --git a/tests/bluetooth/init/prj_ctlr_tiny.conf b/tests/bluetooth/init/prj_ctlr_tiny.conf index a9dcf2327e05a..7cffa21530774 100644 --- a/tests/bluetooth/init/prj_ctlr_tiny.conf +++ b/tests/bluetooth/init/prj_ctlr_tiny.conf @@ -35,7 +35,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y CONFIG_BT_CLASSIC=n diff --git a/tests/bluetooth/init/prj_llcp.conf b/tests/bluetooth/init/prj_llcp.conf index 05eb2197c1d64..33dc3aff1a171 100644 --- a/tests/bluetooth/init/prj_llcp.conf +++ b/tests/bluetooth/init/prj_llcp.conf @@ -7,7 +7,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_SIGNING=y CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_GATT_CLIENT=y CONFIG_BT_CLASSIC=n diff --git a/tests/bluetooth/mesh/basic/testcase.yaml b/tests/bluetooth/mesh/basic/testcase.yaml index 1eced45437fcd..dcd2e8abbc8d3 100644 --- a/tests/bluetooth/mesh/basic/testcase.yaml +++ b/tests/bluetooth/mesh/basic/testcase.yaml @@ -46,8 +46,6 @@ tests: bluetooth.mesh.gatt.psa: build_only: true extra_args: CONF_FILE=gatt.conf - extra_configs: - - CONFIG_BT_USE_PSA_API=y platform_allow: - qemu_x86 - nrf5340dk/nrf5340/cpuapp/ns diff --git a/tests/bluetooth/mesh/brg/CMakeLists.txt b/tests/bluetooth/mesh/brg/CMakeLists.txt index d878ad04d50fd..55e77eaef755d 100644 --- a/tests/bluetooth/mesh/brg/CMakeLists.txt +++ b/tests/bluetooth/mesh/brg/CMakeLists.txt @@ -12,11 +12,12 @@ target_sources(app target_include_directories(app PRIVATE - ${ZEPHYR_BASE}/subsys/bluetooth/mesh) + ${ZEPHYR_BASE}/subsys/bluetooth/mesh + ${ZEPHYR_MBEDTLS_MODULE_DIR}/include) target_compile_options(app PRIVATE -DCONFIG_BT_SETTINGS -DCONFIG_BT_MESH_BRG_CFG_SRV -DCONFIG_BT_MESH_BRG_TABLE_ITEMS_MAX=16 - -DCONFIG_BT_MESH_USES_TINYCRYPT) + -DCONFIG_BT_MESH_USES_MBEDTLS_PSA) diff --git a/tests/bluetooth/mesh/delayable_msg/CMakeLists.txt b/tests/bluetooth/mesh/delayable_msg/CMakeLists.txt index 51bf28d832003..96af1f0175cfc 100644 --- a/tests/bluetooth/mesh/delayable_msg/CMakeLists.txt +++ b/tests/bluetooth/mesh/delayable_msg/CMakeLists.txt @@ -12,7 +12,8 @@ target_sources(app target_include_directories(app PRIVATE - ${ZEPHYR_BASE}/subsys/bluetooth/mesh) + ${ZEPHYR_BASE}/subsys/bluetooth/mesh + ${ZEPHYR_MBEDTLS_MODULE_DIR}/include) target_compile_options(app PRIVATE @@ -20,4 +21,4 @@ target_compile_options(app -DCONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_COUNT=4 -DCONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE=20 -DCONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT=20 - -DCONFIG_BT_MESH_USES_TINYCRYPT) + -DCONFIG_BT_MESH_USES_MBEDTLS_PSA) diff --git a/tests/bluetooth/mesh/rpl/CMakeLists.txt b/tests/bluetooth/mesh/rpl/CMakeLists.txt index b22dcae3e7c83..44bb865291a0f 100644 --- a/tests/bluetooth/mesh/rpl/CMakeLists.txt +++ b/tests/bluetooth/mesh/rpl/CMakeLists.txt @@ -12,11 +12,12 @@ target_sources(app target_include_directories(app PRIVATE - ${ZEPHYR_BASE}/subsys/bluetooth/mesh) + ${ZEPHYR_BASE}/subsys/bluetooth/mesh + ${ZEPHYR_MBEDTLS_MODULE_DIR}/include) target_compile_options(app PRIVATE -DCONFIG_BT_MESH_CRPL=10 -DCONFIG_BT_MESH_RPL_STORE_TIMEOUT=1 -DCONFIG_BT_SETTINGS - -DCONFIG_BT_MESH_USES_TINYCRYPT) + -DCONFIG_BT_MESH_USES_MBEDTLS_PSA) diff --git a/tests/bluetooth/shell/audio.conf b/tests/bluetooth/shell/audio.conf index 049c6b766fed8..e2c83eb69b7bc 100644 --- a/tests/bluetooth/shell/audio.conf +++ b/tests/bluetooth/shell/audio.conf @@ -241,3 +241,6 @@ CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=4 # Match the number of unicast streams supported in BAP CONFIG_BT_CTLR_ISOAL_SOURCES=2 CONFIG_BT_CTLR_ISOAL_SINKS=2 + +# Enable entropy source for Mbed TLS's PSA Crypto core +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bluetooth/shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/tests/bluetooth/shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf index 68e0a8a7e50f8..4658bfcca4887 100644 --- a/tests/bluetooth/shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf +++ b/tests/bluetooth/shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -9,4 +9,4 @@ CONFIG_USB_DEVICE_AUDIO=y CONFIG_USB_DEVICE_PRODUCT="Zephyr Shell USB" # Enable encryption in the host -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y diff --git a/tests/bluetooth/shell/boards/nrf5340dk_nrf5340_cpuapp.conf b/tests/bluetooth/shell/boards/nrf5340dk_nrf5340_cpuapp.conf index 68e0a8a7e50f8..4658bfcca4887 100644 --- a/tests/bluetooth/shell/boards/nrf5340dk_nrf5340_cpuapp.conf +++ b/tests/bluetooth/shell/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -9,4 +9,4 @@ CONFIG_USB_DEVICE_AUDIO=y CONFIG_USB_DEVICE_PRODUCT="Zephyr Shell USB" # Enable encryption in the host -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y diff --git a/tests/bluetooth/tester/boards/frdm_rw612.conf b/tests/bluetooth/tester/boards/frdm_rw612.conf index 48958c6ac7cb4..08b4d161fde0e 100644 --- a/tests/bluetooth/tester/boards/frdm_rw612.conf +++ b/tests/bluetooth/tester/boards/frdm_rw612.conf @@ -1,5 +1,6 @@ CONFIG_BT_MAX_CONN=16 CONFIG_BT_BUF_ACL_RX_COUNT=17 +CONFIG_ENTROPY_GENERATOR=y # debug options # CONFIG_UART_CONSOLE=y diff --git a/tests/bluetooth/tester/boards/native_sim.conf b/tests/bluetooth/tester/boards/native_sim.conf index 30abfdbc3d9f1..125be66ab83fd 100644 --- a/tests/bluetooth/tester/boards/native_sim.conf +++ b/tests/bluetooth/tester/boards/native_sim.conf @@ -1,3 +1,4 @@ CONFIG_UART_PIPE=n CONFIG_SERIAL=y CONFIG_UART_NATIVE_POSIX=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bluetooth/tester/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/tests/bluetooth/tester/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf index 6f723ffa16015..5c61346b16973 100644 --- a/tests/bluetooth/tester/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf +++ b/tests/bluetooth/tester/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -22,4 +22,6 @@ CONFIG_BTTESTER_LOG_LEVEL_DBG=y CONFIG_UART_INTERRUPT_DRIVEN=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bluetooth/tester/boards/nrf5340dk_nrf5340_cpuapp.conf b/tests/bluetooth/tester/boards/nrf5340dk_nrf5340_cpuapp.conf index 6f723ffa16015..b55471d8b62d9 100644 --- a/tests/bluetooth/tester/boards/nrf5340dk_nrf5340_cpuapp.conf +++ b/tests/bluetooth/tester/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -22,4 +22,4 @@ CONFIG_BTTESTER_LOG_LEVEL_DBG=y CONFIG_UART_INTERRUPT_DRIVEN=y -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y diff --git a/tests/bluetooth/tester/boards/rd_rw612_bga.conf b/tests/bluetooth/tester/boards/rd_rw612_bga.conf index 48958c6ac7cb4..08b4d161fde0e 100644 --- a/tests/bluetooth/tester/boards/rd_rw612_bga.conf +++ b/tests/bluetooth/tester/boards/rd_rw612_bga.conf @@ -1,5 +1,6 @@ CONFIG_BT_MAX_CONN=16 CONFIG_BT_BUF_ACL_RX_COUNT=17 +CONFIG_ENTROPY_GENERATOR=y # debug options # CONFIG_UART_CONSOLE=y diff --git a/tests/bsim/bluetooth/audio/overlay-bt_ll_sw_split.conf b/tests/bsim/bluetooth/audio/overlay-bt_ll_sw_split.conf index adf5c628b4c35..1219720faa7f3 100644 --- a/tests/bsim/bluetooth/audio/overlay-bt_ll_sw_split.conf +++ b/tests/bsim/bluetooth/audio/overlay-bt_ll_sw_split.conf @@ -1,31 +1,102 @@ -# Controller Settings -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=255 +# Host and Controller common dependencies +CONFIG_BT_BROADCASTER=y +CONFIG_BT_OBSERVER=y +CONFIG_BT_EXT_ADV=y +CONFIG_BT_PER_ADV=y +CONFIG_BT_PER_ADV_SYNC=y +CONFIG_BT_PER_ADV_SYNC_MAX=2 +CONFIG_BT_CENTRAL=y +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_MAX_CONN=3 + +# Broadcast and Connected ISO +CONFIG_BT_ISO_BROADCASTER=y +CONFIG_BT_ISO_SYNC_RECEIVER=y +CONFIG_BT_ISO_CENTRAL=y +CONFIG_BT_ISO_PERIPHERAL=y + +# ISO Streams +CONFIG_BT_ISO_TX_MTU=310 +CONFIG_BT_ISO_RX_MTU=310 +CONFIG_BT_ISO_MAX_CHAN=4 +# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count +# is used in the context of IPC which falls into a "Newton's Cradle" effect +# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT) +# buffers get throttled. Hence, always have the value equal or greater. +# CONFIG_BT_ISO_TX_BUF_COUNT=8 +# CONFIG_BT_ISO_RX_BUF_COUNT=1 + +# Controller +CONFIG_BT_LL_SW_SPLIT=y + +# Rx ACL and Adv Reports +CONFIG_BT_CTLR_RX_BUFFERS=9 +CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 + +# Coded PHY support +CONFIG_BT_CTLR_PHY_CODED=y + +# Advertising Sets and Extended Scanning +CONFIG_BT_CTLR_ADV_EXT=y +CONFIG_BT_CTLR_ADV_SET=3 CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191 +CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -# Controller advanced options CONFIG_BT_CTLR_ADVANCED_FEATURES=y +CONFIG_BT_CTLR_ADV_AUX_SET=3 +CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y +CONFIG_BT_CTLR_ADV_SYNC_SET=3 +CONFIG_BT_CTLR_ADV_SYNC_PDU_BACK2BACK=y +CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=6 + +# Increase the below to receive interleaved advertising chains +CONFIG_BT_CTLR_SCAN_AUX_SET=1 +# CONFIG_BT_CTLR_SCAN_AUX_USE_CHAINS=y +# CONFIG_BT_CTLR_SCAN_AUX_CHAIN_COUNT=1 + CONFIG_BT_CTLR_ADV_RESERVE_MAX=n +CONFIG_BT_CTLR_ADV_AUX_SLOT_WINDOW=y +CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX=y +CONFIG_BT_CTLR_SCAN_AUX_SYNC_RESERVE_MIN=y +CONFIG_BT_CTLR_SYNC_PERIODIC_SKIP_ON_SCAN_AUX=n +CONFIG_BT_CTLR_SYNC_ISO_RESERVE_MAX=n CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n +CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX=n +CONFIG_BT_CTLR_PERIPHERAL_ISO_RESERVE_MAX=n +CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX=y CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE=n CONFIG_BT_CTLR_SCAN_UNRESERVED=y CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y CONFIG_BT_TICKER_EXT=y CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD=y +# Control Procedure +CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 + # ISO Broadcaster Controller +CONFIG_BT_CTLR_ADV_EXT=y +CONFIG_BT_CTLR_ADV_PERIODIC=y +CONFIG_BT_CTLR_SYNC_TRANSFER_SENDER=y CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=247 -CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 +CONFIG_BT_CTLR_ADV_ISO_SET=1 CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT=2 +CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 +CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=247 # ISO Receive Controller +CONFIG_BT_CTLR_ADV_EXT=y +CONFIG_BT_CTLR_SYNC_PERIODIC=y +CONFIG_BT_CTLR_SYNC_TRANSFER_RECEIVER=y CONFIG_BT_CTLR_SYNC_ISO=y -CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 +CONFIG_BT_CTLR_SCAN_SYNC_ISO_SET=1 +CONFIG_BT_CTLR_SYNC_ISO_STREAM_COUNT=2 CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX=2 +CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 # ISO Connection Oriented CONFIG_BT_CTLR_CENTRAL_ISO=y CONFIG_BT_CTLR_PERIPHERAL_ISO=y +CONFIG_BT_CTLR_CONN_ISO_GROUPS=1 CONFIG_BT_CTLR_CONN_ISO_STREAMS=2 CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=2 CONFIG_BT_CTLR_CONN_ISO_SDU_LEN_MAX=247 @@ -33,13 +104,16 @@ CONFIG_BT_CTLR_CONN_ISO_PDU_LEN_MAX=251 CONFIG_BT_CTLR_CONN_ISO_LOW_LATENCY_POLICY=y # ISO Transmissions -CONFIG_BT_ISO_TX_MTU=310 -CONFIG_BT_ISO_TX_BUF_COUNT=4 -CONFIG_BT_CTLR_ISO_TX_BUFFERS=8 +CONFIG_BT_CTLR_ISOAL_SOURCES=4 +CONFIG_BT_CTLR_ISO_TX_BUFFERS=18 CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=255 -CONFIG_BT_CTLR_ISOAL_SOURCES=2 # ISO Receptions -CONFIG_BT_ISO_RX_MTU=310 -CONFIG_BT_CTLR_ISO_RX_BUFFERS=8 CONFIG_BT_CTLR_ISOAL_SINKS=2 +CONFIG_BT_CTLR_ISO_RX_BUFFERS=8 + +# Tx Power Dynamic Control +CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y + +# Ignore HCI ISO data Tx sequence numbers +# CONFIG_BT_CTLR_ISOAL_PSN_IGNORE=y diff --git a/tests/bsim/bluetooth/audio/overlay-nrf5340_cpunet_iso-bt_ll_sw_split.conf b/tests/bsim/bluetooth/audio/overlay-nrf5340_cpunet_iso-bt_ll_sw_split.conf new file mode 100644 index 0000000000000..4e61f830892cd --- /dev/null +++ b/tests/bsim/bluetooth/audio/overlay-nrf5340_cpunet_iso-bt_ll_sw_split.conf @@ -0,0 +1,7 @@ +# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count +# is used in the context of IPC which falls into a "Newton's Cradle" effect +# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT) +# buffers get throttled. Hence, always have the value equal or greater. +CONFIG_BT_ISO_TX_BUF_COUNT=18 + +CONFIG_BT_CTLR_ISO_TX_BUFFERS=18 diff --git a/tests/bsim/bluetooth/audio/prj.conf b/tests/bsim/bluetooth/audio/prj.conf index 87e99c270a9ae..39f3f0793e682 100644 --- a/tests/bsim/bluetooth/audio/prj.conf +++ b/tests/bsim/bluetooth/audio/prj.conf @@ -22,7 +22,7 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_EVT_RX_SIZE=255 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y CONFIG_BT_AUDIO=y CONFIG_BT_BAP_UNICAST_SERVER=y @@ -42,10 +42,11 @@ CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT=1 CONFIG_BT_BAP_BROADCAST_SNK_SUBGROUP_COUNT=1 CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT=2 CONFIG_BT_ISO_PERIPHERAL=y -CONFIG_BT_ISO_TX_BUF_COUNT=4 +CONFIG_BT_ISO_TX_BUF_COUNT=36 CONFIG_BT_ISO_MAX_CHAN=4 CONFIG_BT_ISO_TX_MTU=310 CONFIG_BT_ISO_RX_MTU=310 +CONFIG_BT_ISO_RX_BUF_COUNT=4 CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n @@ -209,3 +210,5 @@ CONFIG_BT_GMAP_LOG_LEVEL_DBG=y # LOGGING CONFIG_LOG_MODE_IMMEDIATE=y + +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c index 330687088f0a7..cbea7d8b96fcd 100644 --- a/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c @@ -26,6 +26,7 @@ #include #include "bap_common.h" +#include "bap_stream_tx.h" #include "bstests.h" #include "common.h" @@ -50,7 +51,6 @@ NET_BUF_POOL_FIXED_DEFINE(tx_pool, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), CONFIG_BT_CONN_TX_USER_DATA_SIZE, NULL); -extern enum bst_result_t bst_result; static struct audio_test_stream broadcast_source_streams[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT]; static struct bt_bap_lc3_preset preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); @@ -210,6 +210,12 @@ static void started_cb(struct bt_bap_stream *stream) return; } + err = stream_tx_register(stream); + if (err != 0) { + FAIL("Failed to register stream %p for TX: %d\n", stream, err); + return; + } + printk("Stream %p started\n", stream); validate_stream_codec_cfg(stream); k_sem_give(&sem_started); @@ -217,53 +223,23 @@ static void started_cb(struct bt_bap_stream *stream) static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason) { - printk("Stream %p stopped with reason 0x%02X\n", stream, reason); - k_sem_give(&sem_stopped); -} - -static void stream_sent_cb(struct bt_bap_stream *stream) -{ - struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream); - struct net_buf *buf; - int ret; - - if (!test_stream->tx_active) { - return; - } - - if ((test_stream->tx_cnt % 100U) == 0U) { - printk("Sent with seq_num %u\n", test_stream->seq_num); - } - - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (buf == NULL) { - printk("Could not allocate buffer when sending on %p\n", - stream); - return; - } - - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, mock_iso_data, test_stream->tx_sdu_size); - ret = bt_bap_stream_send(stream, buf, test_stream->seq_num++); - if (ret < 0) { - /* This will end broadcasting on this stream. */ - net_buf_unref(buf); + int err; - /* Only fail if tx is active (may fail if we are disabling the stream) */ - if (test_stream->tx_active) { - FAIL("Unable to broadcast data on %p: %d\n", stream, ret); - } + printk("Stream %p stopped with reason 0x%02X\n", stream, reason); + err = stream_tx_unregister(stream); + if (err != 0) { + FAIL("Failed to unregister stream %p for TX: %d\n", stream, err); return; } - test_stream->tx_cnt++; + k_sem_give(&sem_stopped); } static struct bt_bap_stream_ops stream_ops = { .started = started_cb, .stopped = stopped_cb, - .sent = stream_sent_cb, + .sent = stream_tx_sent_cb, }; static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool encryption) @@ -505,10 +481,6 @@ static void test_broadcast_source_stop(struct bt_bap_broadcast_source *source) printk("Stopping broadcast source\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) { - broadcast_source_streams[i].tx_active = false; - } - err = bt_bap_broadcast_source_stop(source); if (err != 0) { FAIL("Unable to stop broadcast source: %d\n", err); @@ -573,6 +545,7 @@ static void test_main(void) } printk("Bluetooth initialized\n"); + stream_tx_init(); err = setup_broadcast_source(&source, false); if (err != 0) { @@ -590,17 +563,6 @@ static void test_main(void) test_broadcast_source_start(source, adv); - /* Initialize sending */ - printk("Sending data\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) { - for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { - struct audio_test_stream *test_stream = &broadcast_source_streams[i]; - - test_stream->tx_active = true; - stream_sent_cb(&test_stream->stream.bap_stream); - } - } - /* Wait for other devices to have received what they wanted */ backchannel_sync_wait_any(); @@ -653,6 +615,7 @@ static void test_main_encrypted(void) } printk("Bluetooth initialized\n"); + stream_tx_init(); err = setup_broadcast_source(&source, true); if (err != 0) { @@ -668,17 +631,6 @@ static void test_main_encrypted(void) test_broadcast_source_start(source, adv); - /* Initialize sending */ - printk("Sending data\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) { - for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { - struct audio_test_stream *test_stream = &broadcast_source_streams[i]; - - test_stream->tx_active = true; - stream_sent_cb(&test_stream->stream.bap_stream); - } - } - /* Wait for other devices to have received data */ backchannel_sync_wait_any(); diff --git a/tests/bsim/bluetooth/audio/src/bap_stream_tx.c b/tests/bsim/bluetooth/audio/src/bap_stream_tx.c new file mode 100644 index 0000000000000..8cc5d59d85f00 --- /dev/null +++ b/tests/bsim/bluetooth/audio/src/bap_stream_tx.c @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bap_stream_tx.h" +#include "common.h" + +/** Enqueue at least 2 per stream, but otherwise equal distribution based on the buf count */ +#define ENQUEUE_CNT MAX(2, (CONFIG_BT_ISO_TX_BUF_COUNT / CONFIG_BT_ISO_MAX_CHAN)) + +LOG_MODULE_REGISTER(stream_tx, LOG_LEVEL_INF); + +struct tx_stream { + struct bt_bap_stream *bap_stream; + uint16_t seq_num; + atomic_t enqueued; +}; + +static struct tx_stream tx_streams[CONFIG_BT_ISO_MAX_CHAN]; + +static bool stream_is_streaming(const struct bt_bap_stream *bap_stream) +{ + struct bt_bap_ep_info ep_info; + int err; + + if (bap_stream == NULL) { + return false; + } + + /* No-op if stream is not configured */ + if (bap_stream->ep == NULL) { + return false; + } + + err = bt_bap_ep_get_info(bap_stream->ep, &ep_info); + if (err != 0) { + return false; + } + + if (ep_info.iso_chan == NULL || ep_info.iso_chan->state != BT_ISO_STATE_CONNECTED) { + return false; + } + + return ep_info.state == BT_BAP_EP_STATE_STREAMING; +} + +static void tx_thread_func(void *arg1, void *arg2, void *arg3) +{ + NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT, + BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), + CONFIG_BT_CONN_TX_USER_DATA_SIZE, NULL); + + /* This loop will attempt to send on all streams in the streaming state in a round robin + * fashion. + * The TX is controlled by the number of buffers configured, and increasing + * CONFIG_BT_ISO_TX_BUF_COUNT will allow for more streams in parallel, or to submit more + * buffers per stream. + * Once a buffer has been freed by the stack, it triggers the next TX. + */ + while (true) { + int err = -ENOEXEC; + + for (size_t i = 0U; i < ARRAY_SIZE(tx_streams); i++) { + struct bt_bap_stream *bap_stream = tx_streams[i].bap_stream; + + if (stream_is_streaming(bap_stream) && + atomic_get(&tx_streams[i].enqueued) < ENQUEUE_CNT) { + struct net_buf *buf; + + buf = net_buf_alloc(&tx_pool, K_FOREVER); + net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); + + net_buf_add_mem(buf, mock_iso_data, bap_stream->qos->sdu); + + err = bt_bap_stream_send(bap_stream, buf, tx_streams[i].seq_num); + if (err == 0) { + tx_streams[i].seq_num++; + atomic_inc(&tx_streams[i].enqueued); + } else { + if (!stream_is_streaming(bap_stream)) { + /* Can happen if we disconnected while waiting for a + * buffer - Ignore + */ + } else { + FAIL("Unable to send: %d", err); + } + + net_buf_unref(buf); + } + } /* No-op if stream is not streaming */ + } + + if (err != 0) { + /* In case of any errors, retry with a delay */ + k_sleep(K_MSEC(10)); + } + } +} + +int stream_tx_register(struct bt_bap_stream *bap_stream) +{ + if (bap_stream == NULL) { + return -EINVAL; + } + + if (!stream_is_tx(bap_stream)) { + return -EINVAL; + } + + for (size_t i = 0U; i < ARRAY_SIZE(tx_streams); i++) { + if (tx_streams[i].bap_stream == NULL) { + tx_streams[i].bap_stream = bap_stream; + tx_streams[i].seq_num = 0U; + + LOG_INF("Registered %p for TX", bap_stream); + + return 0; + } + } + + return -ENOMEM; +} + +int stream_tx_unregister(struct bt_bap_stream *bap_stream) +{ + if (bap_stream == NULL) { + return -EINVAL; + } + + for (size_t i = 0U; i < ARRAY_SIZE(tx_streams); i++) { + if (tx_streams[i].bap_stream == bap_stream) { + tx_streams[i].bap_stream = NULL; + + LOG_INF("Unregistered %p for TX", bap_stream); + + return 0; + } + } + + return -ENODATA; +} + +void stream_tx_init(void) +{ + static bool thread_started; + + if (!thread_started) { + static K_KERNEL_STACK_DEFINE(tx_thread_stack, 1024U); + const int tx_thread_prio = K_PRIO_PREEMPT(5); + static struct k_thread tx_thread; + + k_thread_create(&tx_thread, tx_thread_stack, K_KERNEL_STACK_SIZEOF(tx_thread_stack), + tx_thread_func, NULL, NULL, NULL, tx_thread_prio, 0, K_NO_WAIT); + k_thread_name_set(&tx_thread, "TX thread"); + thread_started = true; + } +} + +bool stream_is_tx(const struct bt_bap_stream *stream) +{ + struct bt_bap_ep_info info; + int err; + + if (stream == NULL || stream->ep == NULL) { + return false; + } + + err = bt_bap_ep_get_info(stream->ep, &info); + if (err != 0) { + return false; + } + + return info.can_send; +} + +void stream_tx_sent_cb(struct bt_bap_stream *stream) +{ + struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream); + + if ((test_stream->tx_cnt % 100U) == 0U) { + printk("Stream %p sent %zu SDUs\n", stream, test_stream->tx_cnt); + } + + test_stream->tx_cnt++; + + for (size_t i = 0U; i < ARRAY_SIZE(tx_streams); i++) { + if (tx_streams[i].bap_stream == stream) { + const atomic_val_t old = atomic_dec(&tx_streams[i].enqueued); + + if (old == 0) { + FAIL("Old enqueue count was 0"); + } + } + } +} diff --git a/tests/bsim/bluetooth/audio/src/bap_stream_tx.h b/tests/bsim/bluetooth/audio/src/bap_stream_tx.h new file mode 100644 index 0000000000000..ddb85410682c2 --- /dev/null +++ b/tests/bsim/bluetooth/audio/src/bap_stream_tx.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef STREAM_TX_H +#define STREAM_TX_H + +#include + +#include +#include +#include +#include + +/** + * @brief Initialize TX + * + * This will initialize TX if not already initialized. This creates and starts a thread that + * will attempt to send data on all streams registered with stream_tx_register(). + */ +void stream_tx_init(void); + +/** + * @brief Register a stream for TX + * + * This will add it to the list of streams the TX thread will attempt to send on. + * + * @param bap_stream The stream to register + * + * @retval 0 on success + * @retval -EINVAL @p bap_stream is NULL + * @retval -EINVAL @p bap_stream is not configured for TX + * @retval -EINVAL @p bap_stream.codec_cfg contains invalid values + * @retval -ENOMEM if not more streams can be registered + */ +int stream_tx_register(struct bt_bap_stream *bap_stream); + +/** + * @brief Unregister a stream for TX + * + * This will remove it to the list of streams the TX thread will attempt to send on. + * + * @param bap_stream The stream to unregister + * + * @retval 0 on success + * @retval -EINVAL @p bap_stream is NULL + * @retval -EINVAL @p bap_stream is not configured for TX + * @retval -EALREADY @p bap_stream is currently not registered + */ +int stream_tx_unregister(struct bt_bap_stream *bap_stream); + +/** + * @brief Test if the provided stream has been configured for TX + * + * @param bap_stream The stream to test for TX support + * + * @retval true if it has been configured for TX, and false if not + */ +bool stream_is_tx(const struct bt_bap_stream *stream); + +/** + * @brief Callback to indicate a TX complete + * + * @param stream The stream that completed TX + */ +void stream_tx_sent_cb(struct bt_bap_stream *stream); +#endif /* STREAM_TX_H */ diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c index 913c21b6ecceb..9dc73dfdcb0a8 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c @@ -29,6 +29,7 @@ #include #include +#include "bap_stream_tx.h" #include "bstests.h" #include "common.h" #include "bap_common.h" @@ -105,6 +106,16 @@ static void stream_started(struct bt_bap_stream *stream) { printk("Started stream %p\n", stream); + if (stream_is_tx(stream)) { + int err; + + err = stream_tx_register(stream); + if (err != 0) { + FAIL("Failed to register stream %p for TX: %d\n", stream, err); + return; + } + } + SET_FLAG(flag_stream_started); } @@ -131,10 +142,6 @@ static void stream_metadata_updated(struct bt_bap_stream *stream) static void stream_disabled(struct bt_bap_stream *stream) { - struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream); - - test_stream->tx_active = false; - printk("Disabled stream %p\n", stream); SET_FLAG(flag_stream_disabled); @@ -144,6 +151,16 @@ static void stream_stopped(struct bt_bap_stream *stream, uint8_t reason) { printk("Stopped stream %p with reason 0x%02X\n", stream, reason); + if (stream_is_tx(stream)) { + int err; + + err = stream_tx_unregister(stream); + if (err != 0) { + FAIL("Failed to unregister stream %p for TX: %d\n", stream, err); + return; + } + } + SET_FLAG(flag_stream_stopped); } @@ -191,40 +208,6 @@ static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec } } -static void stream_sent_cb(struct bt_bap_stream *stream) -{ - struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream); - struct net_buf *buf; - int ret; - - if (!test_stream->tx_active) { - return; - } - - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (buf == NULL) { - printk("Could not allocate buffer when sending on %p\n", stream); - return; - } - - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, mock_iso_data, test_stream->tx_sdu_size); - ret = bt_bap_stream_send(stream, buf, test_stream->seq_num++); - if (ret < 0) { - /* This will end broadcasting on this stream. */ - net_buf_unref(buf); - - /* Only fail if tx is active (may fail if we are disabling the stream) */ - if (test_stream->tx_active) { - FAIL("Unable to send data on %p: %d\n", stream, ret); - } - - return; - } - - test_stream->tx_cnt++; -} - static struct bt_bap_stream_ops stream_ops = { .configured = stream_configured, .qos_set = stream_qos_set, @@ -235,7 +218,7 @@ static struct bt_bap_stream_ops stream_ops = { .stopped = stream_stopped, .released = stream_released, .recv = stream_recv_cb, - .sent = stream_sent_cb, + .sent = stream_tx_sent_cb, .connected = stream_connected, .disconnected = stream_disconnected, }; @@ -532,6 +515,9 @@ static void init(void) return; } + printk("Bluetooth initialized\n"); + stream_tx_init(); + for (size_t i = 0; i < ARRAY_SIZE(test_streams); i++) { struct bt_bap_stream *bap_stream = bap_stream_from_audio_test_stream(&test_streams[i]); @@ -882,11 +868,6 @@ static void transceive_streams(void) struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(sink_stream); - test_stream->tx_active = true; - for (unsigned int i = 0U; i < ENQUEUE_COUNT; i++) { - stream_sent_cb(sink_stream); - } - /* Keep sending until we reach the minimum expected */ while (test_stream->tx_cnt < MIN_SEND_COUNT) { k_sleep(K_MSEC(100)); diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c index 7dff0e1a97f9f..fcd59f094b8ca 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c @@ -27,6 +27,7 @@ #include #include "bap_common.h" +#include "bap_stream_tx.h" #include "bstests.h" #include "common.h" @@ -202,12 +203,8 @@ static int lc3_metadata(struct bt_bap_stream *stream, const uint8_t meta[], size static int lc3_disable(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { - struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream); - printk("Disable: stream %p\n", stream); - test_stream->tx_active = false; - return 0; } @@ -270,9 +267,34 @@ static void stream_started_cb(struct bt_bap_stream *stream) { printk("Started: stream %p\n", stream); + if (stream_is_tx(stream)) { + int err; + + err = stream_tx_register(stream); + if (err != 0) { + FAIL("Failed to register stream %p for TX: %d\n", stream, err); + return; + } + } + SET_FLAG(flag_stream_started); } +static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason) +{ + printk("Stopped stream %p with reason 0x%02X\n", stream, reason); + + if (stream_is_tx(stream)) { + int err; + + err = stream_tx_unregister(stream); + if (err != 0) { + FAIL("Failed to unregister stream %p for TX: %d\n", stream, err); + return; + } + } +} + static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info, struct net_buf *buf) { @@ -310,45 +332,12 @@ static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec } } -static void stream_sent_cb(struct bt_bap_stream *stream) -{ - struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream); - struct net_buf *buf; - int ret; - - if (!test_stream->tx_active) { - return; - } - - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (buf == NULL) { - printk("Could not allocate buffer when sending on %p\n", stream); - return; - } - - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, mock_iso_data, test_stream->tx_sdu_size); - ret = bt_bap_stream_send(stream, buf, test_stream->seq_num++); - if (ret < 0) { - /* This will end broadcasting on this stream. */ - net_buf_unref(buf); - - /* Only fail if tx is active (may fail if we are disabling the stream) */ - if (test_stream->tx_active) { - FAIL("Unable to send data on %p: %d\n", stream, ret); - } - - return; - } - - test_stream->tx_cnt++; -} - static struct bt_bap_stream_ops stream_ops = { .enabled = stream_enabled_cb, .started = stream_started_cb, + .stopped = stream_stopped_cb, .recv = stream_recv_cb, - .sent = stream_sent_cb, + .sent = stream_tx_sent_cb, }; static void transceive_test_streams(void) @@ -394,11 +383,6 @@ static void transceive_test_streams(void) struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(source_stream); - test_stream->tx_active = true; - for (unsigned int i = 0U; i < ENQUEUE_COUNT; i++) { - stream_sent_cb(source_stream); - } - /* Keep sending until we reach the minimum expected */ while (test_stream->tx_cnt < MIN_SEND_COUNT) { k_sleep(K_MSEC(100)); @@ -491,6 +475,7 @@ static void init(void) } printk("Bluetooth initialized\n"); + stream_tx_init(); err = bt_bap_unicast_server_register(¶m); if (err != 0) { diff --git a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c index d0a33bdc0a253..3b1a007532784 100644 --- a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,15 @@ #include "bap_common.h" #if defined(CONFIG_BT_CAP_ACCEPTOR) +/* Zephyr Controller works best while Extended Advertising interval to be a multiple + * of the ISO Interval minus 10 ms (max. advertising random delay). This is + * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the + * Broadcast ISO radio events. + */ +#define BT_LE_EXT_ADV_CONN_CUSTOM \ + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CONN, \ + 0x00e0, 0x00e0, NULL) + extern enum bst_result_t bst_result; #define SINK_CONTEXT \ @@ -431,7 +441,22 @@ static struct bt_bap_scan_delegator_cb scan_delegator_cbs = { /* TODO: Expand with CAP service data */ static const struct bt_data cap_acceptor_ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_CAS_VAL)), + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), + BT_DATA_BYTES(BT_DATA_UUID16_SOME, BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL), + BT_UUID_16_ENCODE(BT_UUID_CAS_VAL)), + BT_DATA_BYTES(BT_DATA_SVC_DATA16, BT_UUID_16_ENCODE(BT_UUID_CAS_VAL), + BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED), + IF_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER, + (BT_DATA_BYTES(BT_DATA_SVC_DATA16, + BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL), + BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED, + BT_BYTES_LIST_LE16(SINK_CONTEXT), + BT_BYTES_LIST_LE16(SOURCE_CONTEXT), + 0x00, /* Metadata length */), + )) + IF_ENABLED(CONFIG_BT_BAP_SCAN_DELEGATOR, + (BT_DATA_BYTES(BT_DATA_SVC_DATA16, BT_UUID_16_ENCODE(BT_UUID_BASS_VAL)), + )) }; static struct bt_csip_set_member_svc_inst *csip_set_member; @@ -638,7 +663,7 @@ void test_start_adv(void) struct bt_le_ext_adv *ext_adv; /* Create a connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_ADV_CONN_FAST_1, NULL, &ext_adv); + err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_CUSTOM, NULL, &ext_adv); if (err != 0) { FAIL("Failed to create advertising set (err %d)\n", err); @@ -752,12 +777,6 @@ static void init(void) bt_cap_stream_ops_register(&unicast_streams[i], &unicast_stream_ops); } - err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, cap_acceptor_ad, - ARRAY_SIZE(cap_acceptor_ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } test_start_adv(); } diff --git a/tests/bsim/bluetooth/audio/src/cap_commander_test.c b/tests/bsim/bluetooth/audio/src/cap_commander_test.c index 43e57a2e6f5b7..b673eb9756c5c 100644 --- a/tests/bsim/bluetooth/audio/src/cap_commander_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_commander_test.c @@ -298,7 +298,7 @@ static bool scan_check_and_sync_broadcast(struct bt_data *data, void *user_data) printk("Found broadcaster with ID 0x%06X and addr %s and sid 0x%02X\n", broadcast_id, le_addr, info->sid); - printk("Adv type %02X interval %u", info->adv_type, info->interval); + printk("Adv type %02X interval %u\n", info->adv_type, info->interval); SET_FLAG(flag_broadcaster_found); @@ -487,8 +487,75 @@ static struct bt_bap_broadcast_assistant_cb ba_cbs = { .add_src = bap_broadcast_assistant_add_src_cb, }; +static bool check_audio_support_and_connect_cb(struct bt_data *data, void *user_data) +{ + char addr_str[BT_ADDR_LE_STR_LEN]; + bt_addr_le_t *addr = user_data; + const struct bt_uuid *uuid; + uint16_t uuid_val; + int err; + + printk("data->type %u\n", data->type); + + if (data->type != BT_DATA_SVC_DATA16) { + return true; /* Continue parsing to next AD data type */ + } + + if (data->data_len < sizeof(uuid_val)) { + return true; /* Continue parsing to next AD data type */ + } + + /* We are looking for the CAS service data */ + uuid_val = sys_get_le16(data->data); + uuid = BT_UUID_DECLARE_16(uuid_val); + if (bt_uuid_cmp(uuid, BT_UUID_CAS) != 0) { + return true; /* Continue parsing to next AD data type */ + } + + bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); + printk("Device found: %s\n", addr_str); + + printk("Stopping scan\n"); + if (bt_le_scan_stop()) { + FAIL("Could not stop scan"); + return false; + } + + err = bt_conn_le_create( + addr, BT_CONN_LE_CREATE_CONN, + BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, BT_GAP_INIT_CONN_INT_MIN, 0, 400), + &connected_conns[connected_conn_cnt]); + if (err != 0) { + FAIL("Could not connect to peer: %d", err); + } + + return false; /* Stop parsing */ +} + +static void scan_recv_cb(const struct bt_le_scan_recv_info *info, struct net_buf_simple *buf) +{ + struct bt_conn *conn; + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, info->addr); + if (conn != NULL) { + /* Already connected to this device */ + bt_conn_unref(conn); + return; + } + + /* Check for connectable, extended advertising */ + if (((info->adv_props & BT_GAP_ADV_PROP_EXT_ADV) != 0) && + ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE)) != 0) { + /* Check for TMAS support in advertising data */ + bt_data_parse(buf, check_audio_support_and_connect_cb, (void *)info->addr); + } +} + static void init(size_t acceptor_cnt) { + static struct bt_le_scan_cb scan_callbacks = { + .recv = scan_recv_cb, + }; static struct bt_conn_cb conn_cb = { .disconnected = cap_disconnected_cb, }; @@ -501,6 +568,12 @@ static void init(size_t acceptor_cnt) } bt_gatt_cb_register(&gatt_callbacks); + err = bt_le_scan_cb_register(&scan_callbacks); + if (err != 0) { + FAIL("Failed to register scan callbacks (err %d)\n", err); + return; + } + bt_conn_cb_register(&conn_cb); err = bt_cap_commander_register_cb(&cap_cb); @@ -552,56 +625,13 @@ static void init(size_t acceptor_cnt) UNSET_FLAG(flag_syncable); } -static void cap_device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - struct bt_conn *conn; - int err; - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr); - if (conn != NULL) { - /* Already connected to this device */ - bt_conn_unref(conn); - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - /* connect only to devices in close proximity */ - if (rssi < -70) { - FAIL("RSSI too low"); - return; - } - - printk("Stopping scan\n"); - if (bt_le_scan_stop()) { - FAIL("Could not stop scan"); - return; - } - - err = bt_conn_le_create( - addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, BT_GAP_INIT_CONN_INT_MIN, 0, 400), - &connected_conns[connected_conn_cnt]); - if (err) { - FAIL("Could not connect to peer: %d", err); - } -} - static void scan_and_connect(void) { int err; UNSET_FLAG(flag_connected); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, cap_device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c index 9b9ad2d335490..27aed447aa307 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c @@ -29,6 +29,7 @@ #include #include "bap_common.h" +#include "bap_stream_tx.h" #include "bstests.h" #include "common.h" @@ -40,15 +41,15 @@ */ #define BT_LE_EXT_ADV_CUSTOM \ BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, \ - 0x0080, 0x0080, NULL) + 0x00e0, 0x00e0, NULL) #define BT_LE_PER_ADV_CUSTOM \ - BT_LE_PER_ADV_PARAM(0x0048, \ - 0x0048, \ + BT_LE_PER_ADV_PARAM(0x0078, \ + 0x0078, \ BT_LE_PER_ADV_OPT_NONE) #define BROADCAST_STREMT_CNT CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT -#define BROADCAST_ENQUEUE_COUNT 2U +#define BROADCAST_ENQUEUE_COUNT 18U #define TOTAL_BUF_NEEDED (BROADCAST_ENQUEUE_COUNT * BROADCAST_STREMT_CNT) #define CAP_AC_MAX_STREAM 2 #define LOCATION (BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT) @@ -117,66 +118,38 @@ static const struct named_lc3_preset lc3_broadcast_presets[] = { static void broadcast_started_cb(struct bt_bap_stream *stream) { - printk("Stream %p started\n", stream); - k_sem_give(&sem_broadcast_started); -} - -static void broadcast_stopped_cb(struct bt_bap_stream *stream, uint8_t reason) -{ - printk("Stream %p stopped with reason 0x%02X\n", stream, reason); - k_sem_give(&sem_broadcast_stopped); -} - -static void broadcast_sent_cb(struct bt_bap_stream *bap_stream) -{ - struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(bap_stream); - struct bt_cap_stream *cap_stream = cap_stream_from_audio_test_stream(test_stream); - struct net_buf *buf; - int ret; - - if (!test_stream->tx_active) { - return; - } + int err; - if ((test_stream->tx_cnt % 100U) == 0U) { - printk("[%zu]: Stream %p sent with seq_num %u\n", test_stream->tx_cnt, cap_stream, - test_stream->seq_num); - } + printk("Stream %p started\n", stream); - if (test_stream->tx_sdu_size > CONFIG_BT_ISO_TX_MTU) { - FAIL("Invalid SDU %u for the MTU: %d", test_stream->tx_sdu_size, - CONFIG_BT_ISO_TX_MTU); + err = stream_tx_register(stream); + if (err != 0) { + FAIL("Failed to register stream %p for TX: %d\n", stream, err); return; } - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (buf == NULL) { - printk("Could not allocate buffer when sending on %p\n", bap_stream); - return; - } + k_sem_give(&sem_broadcast_started); +} - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, mock_iso_data, test_stream->tx_sdu_size); - ret = bt_cap_stream_send(cap_stream, buf, test_stream->seq_num++); - if (ret < 0) { - /* This will end broadcasting on this stream. */ - net_buf_unref(buf); +static void broadcast_stopped_cb(struct bt_bap_stream *stream, uint8_t reason) +{ + int err; - /* Only fail if tx is active (may fail if we are disabling the stream) */ - if (test_stream->tx_active) { - FAIL("Unable to broadcast data on %p: %d\n", cap_stream, ret); - } + printk("Stream %p stopped with reason 0x%02X\n", stream, reason); + err = stream_tx_unregister(stream); + if (err != 0) { + FAIL("Failed to unregister stream %p for TX: %d\n", stream, err); return; } - test_stream->tx_cnt++; + k_sem_give(&sem_broadcast_stopped); } static struct bt_bap_stream_ops broadcast_stream_ops = { .started = broadcast_started_cb, .stopped = broadcast_stopped_cb, - .sent = broadcast_sent_cb, + .sent = stream_tx_sent_cb, }; static void init(void) @@ -189,6 +162,9 @@ static void init(void) return; } + printk("Bluetooth initialized\n"); + stream_tx_init(); + (void)memset(broadcast_source_streams, 0, sizeof(broadcast_source_streams)); for (size_t i = 0; i < ARRAY_SIZE(broadcast_streams); i++) { @@ -588,10 +564,6 @@ static void test_broadcast_audio_stop(struct bt_cap_broadcast_source *broadcast_ printk("Stopping broadcast source\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) { - broadcast_source_streams[i].tx_active = false; - } - err = bt_cap_initiator_broadcast_audio_stop(broadcast_source); if (err != 0) { FAIL("Failed to stop broadcast source: %d\n", err); @@ -678,17 +650,6 @@ static void test_main_cap_initiator_broadcast(void) k_sem_take(&sem_broadcast_started, K_FOREVER); } - /* Initialize sending */ - for (size_t i = 0U; i < stream_count; i++) { - struct audio_test_stream *test_stream = &broadcast_source_streams[i]; - - test_stream->tx_active = true; - - for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { - broadcast_sent_cb(bap_stream_from_audio_test_stream(test_stream)); - } - } - /* Wait for other devices to have received what they wanted */ backchannel_sync_wait_any(); @@ -784,17 +745,6 @@ static int test_cap_initiator_ac(const struct cap_initiator_ac_param *param) k_sem_take(&sem_broadcast_started, K_FOREVER); } - /* Initialize sending */ - for (size_t i = 0U; i < stream_count; i++) { - struct audio_test_stream *test_stream = &broadcast_source_streams[i]; - - test_stream->tx_active = true; - - for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { - broadcast_sent_cb(bap_stream_from_audio_test_stream(test_stream)); - } - } - /* Wait for other devices to have received what they wanted */ backchannel_sync_wait_any(); diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c index bd98e6a5c0928..73cba2e44ef25 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -367,8 +368,75 @@ static struct bt_gatt_cb gatt_callbacks = { .att_mtu_updated = att_mtu_updated, }; +static bool check_audio_support_and_connect_cb(struct bt_data *data, void *user_data) +{ + char addr_str[BT_ADDR_LE_STR_LEN]; + bt_addr_le_t *addr = user_data; + const struct bt_uuid *uuid; + uint16_t uuid_val; + int err; + + printk("data->type %u\n", data->type); + + if (data->type != BT_DATA_SVC_DATA16) { + return true; /* Continue parsing to next AD data type */ + } + + if (data->data_len < sizeof(uuid_val)) { + return true; /* Continue parsing to next AD data type */ + } + + /* We are looking for the CAS service data */ + uuid_val = sys_get_le16(data->data); + uuid = BT_UUID_DECLARE_16(uuid_val); + if (bt_uuid_cmp(uuid, BT_UUID_CAS) != 0) { + return true; /* Continue parsing to next AD data type */ + } + + bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); + printk("Device found: %s\n", addr_str); + + printk("Stopping scan\n"); + if (bt_le_scan_stop()) { + FAIL("Could not stop scan"); + return false; + } + + err = bt_conn_le_create( + addr, BT_CONN_LE_CREATE_CONN, + BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, BT_GAP_INIT_CONN_INT_MIN, 0, 400), + &connected_conns[connected_conn_cnt]); + if (err != 0) { + FAIL("Could not connect to peer: %d", err); + } + + return false; /* Stop parsing */ +} + +static void scan_recv_cb(const struct bt_le_scan_recv_info *info, struct net_buf_simple *buf) +{ + struct bt_conn *conn; + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, info->addr); + if (conn != NULL) { + /* Already connected to this device */ + bt_conn_unref(conn); + return; + } + + /* Check for connectable, extended advertising */ + if (((info->adv_props & BT_GAP_ADV_PROP_EXT_ADV) != 0) && + ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE)) != 0) { + /* Check for TMAS support in advertising data */ + bt_data_parse(buf, check_audio_support_and_connect_cb, (void *)info->addr); + } +} + static void init(void) { + static struct bt_le_scan_cb scan_callbacks = { + .recv = scan_recv_cb, + }; int err; err = bt_enable(NULL); @@ -378,6 +446,11 @@ static void init(void) } bt_gatt_cb_register(&gatt_callbacks); + err = bt_le_scan_cb_register(&scan_callbacks); + if (err != 0) { + FAIL("Failed to register scan callbacks (err %d)\n", err); + return; + } err = bt_bap_unicast_client_register_cb(&unicast_client_cbs); if (err != 0) { @@ -404,56 +477,13 @@ static void init(void) } } -static void cap_device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - struct bt_conn *conn; - int err; - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr); - if (conn != NULL) { - /* Already connected to this device */ - bt_conn_unref(conn); - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - /* connect only to devices in close proximity */ - if (rssi < -70) { - FAIL("RSSI too low"); - return; - } - - printk("Stopping scan\n"); - if (bt_le_scan_stop()) { - FAIL("Could not stop scan"); - return; - } - - err = bt_conn_le_create( - addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, BT_GAP_INIT_CONN_INT_MIN, 0, 400), - &connected_conns[connected_conn_cnt]); - if (err) { - FAIL("Could not connect to peer: %d", err); - } -} - static void scan_and_connect(void) { int err; UNSET_FLAG(flag_connected); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, cap_device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/common.h b/tests/bsim/bluetooth/audio/src/common.h index 76020b8529d1b..1febed2f2ddf4 100644 --- a/tests/bsim/bluetooth/audio/src/common.h +++ b/tests/bsim/bluetooth/audio/src/common.h @@ -29,6 +29,7 @@ #include #include +#include "bstests.h" #include "bs_types.h" #include "bs_tracing.h" @@ -88,7 +89,7 @@ static const uint8_t mock_iso_data[] = { (void)k_sleep(K_MSEC(1)); \ } - +extern enum bst_result_t bst_result; #define FAIL(...) \ do { \ bst_result = Failed; \ @@ -106,7 +107,7 @@ static const uint8_t mock_iso_data[] = { #define PA_SYNC_INTERVAL_TO_TIMEOUT_RATIO 20 /* Set the timeout relative to interval */ #define PA_SYNC_SKIP 5 -#define PBP_STREAMS_TO_SEND 2 +#define PBP_STREAMS_TO_SEND 2 extern struct bt_le_scan_cb common_scan_cb; extern const struct bt_data ad[AD_SIZE]; @@ -133,7 +134,6 @@ struct audio_test_stream { struct bt_cap_stream stream; uint16_t seq_num; - bool tx_active; size_t tx_cnt; uint16_t tx_sdu_size; diff --git a/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c b/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c index c50f5104f0ddf..e0f00dcdca944 100644 --- a/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c +++ b/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c @@ -34,6 +34,7 @@ #include #include +#include "bap_stream_tx.h" #include "bstests.h" #include "common.h" #include "bap_common.h" @@ -179,52 +180,6 @@ const struct named_lc3_preset *gmap_get_named_preset(bool is_unicast, enum bt_au return NULL; } -static void stream_sent_cb(struct bt_bap_stream *bap_stream) -{ - struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(bap_stream); - struct bt_cap_stream *cap_stream = cap_stream_from_audio_test_stream(test_stream); - struct net_buf *buf; - int ret; - - if (!test_stream->tx_active) { - return; - } - - if ((test_stream->tx_cnt % 100U) == 0U) { - printk("[%zu]: Stream %p sent with seq_num %u\n", test_stream->tx_cnt, cap_stream, - test_stream->seq_num); - } - - if (test_stream->tx_sdu_size > CONFIG_BT_ISO_TX_MTU) { - FAIL("Invalid SDU %u for the MTU: %d", test_stream->tx_sdu_size, - CONFIG_BT_ISO_TX_MTU); - return; - } - - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (buf == NULL) { - printk("Could not allocate buffer when sending on %p\n", bap_stream); - return; - } - - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, mock_iso_data, test_stream->tx_sdu_size); - ret = bt_cap_stream_send(cap_stream, buf, test_stream->seq_num++); - if (ret < 0) { - /* This will end broadcasting on this stream. */ - net_buf_unref(buf); - - /* Only fail if tx is active (may fail if we are disabling the stream) */ - if (test_stream->tx_active) { - FAIL("Unable to broadcast data on %p: %d\n", cap_stream, ret); - } - - return; - } - - test_stream->tx_cnt++; -} - static void stream_configured_cb(struct bt_bap_stream *stream, const struct bt_bap_qos_cfg_pref *pref) { @@ -248,6 +203,17 @@ static void stream_enabled_cb(struct bt_bap_stream *stream) static void stream_started_cb(struct bt_bap_stream *stream) { printk("Started stream %p\n", stream); + + if (stream_is_tx(stream)) { + int err; + + err = stream_tx_register(stream); + if (err != 0) { + FAIL("Failed to register stream %p for TX: %d\n", stream, err); + return; + } + } + k_sem_give(&sem_stream_started); } @@ -264,6 +230,17 @@ static void stream_disabled_cb(struct bt_bap_stream *stream) static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason) { printk("Stream %p stopped with reason 0x%02X\n", stream, reason); + + if (stream_is_tx(stream)) { + int err; + + err = stream_tx_unregister(stream); + if (err != 0) { + FAIL("Failed to unregister stream %p for TX: %d\n", stream, err); + return; + } + } + k_sem_give(&sem_stream_stopped); } @@ -281,7 +258,7 @@ static struct bt_bap_stream_ops stream_ops = { .disabled = stream_disabled_cb, .stopped = stream_stopped_cb, .released = stream_released_cb, - .sent = stream_sent_cb, + .sent = stream_tx_sent_cb, }; static void cap_discovery_complete_cb(struct bt_conn *conn, int err, @@ -474,6 +451,9 @@ static void init(void) return; } + printk("Bluetooth initialized\n"); + stream_tx_init(); + bt_gatt_cb_register(&gatt_callbacks); err = bt_bap_unicast_client_register_cb(&unicast_client_cbs); @@ -1154,10 +1134,6 @@ static void broadcast_audio_stop(struct bt_cap_broadcast_source *broadcast_sourc printk("Stopping broadcast source\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_streams); i++) { - broadcast_streams[i].tx_active = false; - } - err = bt_cap_initiator_broadcast_audio_stop(broadcast_source); if (err != 0) { FAIL("Failed to stop broadcast source: %d\n", err); @@ -1258,18 +1234,6 @@ static int test_gmap_ugg_broadcast_ac(const struct gmap_broadcast_ac_param *para k_sem_take(&sem_stream_started, K_FOREVER); } - /* Initialize sending */ - printk("Starting sending\n"); - for (size_t i = 0U; i < param->stream_cnt; i++) { - struct audio_test_stream *test_stream = &broadcast_streams[i]; - - test_stream->tx_active = true; - - for (unsigned int j = 0U; j < ISO_ENQUEUE_COUNT; j++) { - stream_sent_cb(bap_stream_from_audio_test_stream(test_stream)); - } - } - /* Wait for other devices to have received what they wanted */ backchannel_sync_wait_any(); diff --git a/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c b/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c index 86df90cc38671..12f85ad0dc708 100644 --- a/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c +++ b/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c @@ -24,6 +24,7 @@ #include #include +#include "bap_stream_tx.h" #include "bstests.h" #include "common.h" @@ -55,7 +56,7 @@ static uint8_t bis_codec_data[] = { BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_FREQ, BT_BYTES_LIST_LE16(BT_AUDIO_CODEC_CFG_FREQ_48KHZ))}; -static struct bt_cap_stream broadcast_source_stream; +static struct audio_test_stream broadcast_source_stream; static struct bt_cap_stream *broadcast_stream; static struct bt_cap_initiator_broadcast_stream_param stream_params; @@ -74,52 +75,32 @@ static struct bt_le_ext_adv *adv; static void started_cb(struct bt_bap_stream *stream) { + int err; + printk("Stream %p started\n", stream); + + err = stream_tx_register(stream); + if (err != 0) { + FAIL("Failed to register stream %p for TX: %d\n", stream, err); + return; + } + k_sem_give(&sem_started); } static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason) { - printk("Stream %p stopped with reason 0x%02X\n", stream, reason); - k_sem_give(&sem_stopped); -} - -static void sent_cb(struct bt_bap_stream *stream) -{ - static uint8_t mock_data[CONFIG_BT_ISO_TX_MTU]; - static bool mock_data_initialized; - static uint32_t seq_num; - struct net_buf *buf; - int ret; - - if (broadcast_preset_48_2_1.qos.sdu > CONFIG_BT_ISO_TX_MTU) { - printk("Invalid SDU %u for the MTU: %d", - broadcast_preset_48_2_1.qos.sdu, CONFIG_BT_ISO_TX_MTU); - return; - } + int err; - if (!mock_data_initialized) { - for (size_t i = 0U; i < ARRAY_SIZE(mock_data); i++) { - /* Initialize mock data */ - mock_data[i] = (uint8_t)i; - } - mock_data_initialized = true; - } + printk("Stream %p stopped with reason 0x%02X\n", stream, reason); - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (buf == NULL) { - printk("Could not allocate buffer when sending on %p\n", stream); + err = stream_tx_unregister(stream); + if (err != 0) { + FAIL("Failed to unregister stream %p for TX: %d\n", stream, err); return; } - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, mock_data, broadcast_preset_48_2_1.qos.sdu); - ret = bt_bap_stream_send(stream, buf, seq_num++); - if (ret < 0) { - /* This will end broadcasting on this stream. */ - net_buf_unref(buf); - return; - } + k_sem_give(&sem_stopped); } static int setup_extended_adv_data(struct bt_cap_broadcast_source *source, @@ -278,7 +259,7 @@ static int stop_extended_adv(struct bt_le_ext_adv *adv) static struct bt_bap_stream_ops broadcast_stream_ops = { .started = started_cb, .stopped = stopped_cb, - .sent = sent_cb + .sent = stream_tx_sent_cb, }; static void test_main(void) @@ -293,10 +274,13 @@ static void test_main(void) return; } - broadcast_stream = &broadcast_source_stream; + printk("Bluetooth initialized\n"); + stream_tx_init(); + + broadcast_stream = &broadcast_source_stream.stream; bt_bap_stream_cb_register(&broadcast_stream->bap_stream, &broadcast_stream_ops); - stream_params.stream = &broadcast_source_stream; + stream_params.stream = broadcast_stream; stream_params.data_len = ARRAY_SIZE(bis_codec_data); stream_params.data = bis_codec_data; @@ -346,11 +330,6 @@ static void test_main(void) k_sem_take(&sem_started, SEM_TIMEOUT); - /* Initialize sending */ - for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { - sent_cb(&broadcast_stream->bap_stream); - } - /* Wait for other devices to let us know when we can stop the source */ printk("Waiting for signal from receiver to stop\n"); backchannel_sync_wait_any(); diff --git a/tests/bsim/bluetooth/audio/sysbuild.cmake b/tests/bsim/bluetooth/audio/sysbuild.cmake index 1b8d10c8db30c..5dfd594349c19 100644 --- a/tests/bsim/bluetooth/audio/sysbuild.cmake +++ b/tests/bsim/bluetooth/audio/sysbuild.cmake @@ -18,6 +18,11 @@ if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) CACHE INTERNAL "" ) + set(${NET_APP}_EXTRA_CONF_FILE + ${APP_DIR}/overlay-nrf5340_cpunet_iso-bt_ll_sw_split.conf + CACHE INTERNAL "" + ) + native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) endif() diff --git a/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_ac_12.sh b/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_ac_12.sh index 607d6837699a2..b7fc2721d623a 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_ac_12.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_ac_12.sh @@ -51,19 +51,19 @@ Execute_AC_12 48_5_1 Execute_AC_12 48_6_1 # High reliability -# Execute_AC_12 8_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 8_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 16_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 16_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 24_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 24_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 32_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 32_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 441_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 441_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 48_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 48_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 48_3_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 48_4_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 48_5_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_12 48_6_2 # BT_ISO_FLAGS_ERROR +Execute_AC_12 8_1_2 +Execute_AC_12 8_2_2 +Execute_AC_12 16_1_2 +Execute_AC_12 16_2_2 +Execute_AC_12 24_1_2 +Execute_AC_12 24_2_2 +Execute_AC_12 32_1_2 +Execute_AC_12 32_2_2 +# Execute_AC_12 441_1_2 # BT_ISO_FLAGS_LOST +# Execute_AC_12 441_2_2 # BT_ISO_FLAGS_LOST +Execute_AC_12 48_1_2 +Execute_AC_12 48_2_2 +Execute_AC_12 48_3_2 +Execute_AC_12 48_4_2 +Execute_AC_12 48_5_2 +Execute_AC_12 48_6_2 diff --git a/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_ac_14.sh b/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_ac_14.sh index 0ac6ed685fb30..1b5484a42acc3 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_ac_14.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_ac_14.sh @@ -41,9 +41,7 @@ Execute_AC_14 24_1_1 Execute_AC_14 24_2_1 Execute_AC_14 32_1_1 Execute_AC_14 32_2_1 -# ASSERTION FAIL [err == ((isoal_status_t) 0x00) || err == ((isoal_status_t) 0x04)] -# @ WEST_TOPDIR/zephyr/subsys/bluetooth/controller/hci/hci_driver.c:513 -# Execute_AC_14 441_1_1 +Execute_AC_14 441_1_1 # ASSERTION FAIL [err == ((isoal_status_t) 0x00) || err == ((isoal_status_t) 0x04)] # @ WEST_TOPDIR/zephyr/subsys/bluetooth/controller/hci/hci_driver.c:513 # Execute_AC_14 441_2_1 @@ -55,19 +53,19 @@ Execute_AC_14 48_5_1 Execute_AC_14 48_6_1 # High reliability -# Execute_AC_14 8_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 8_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 16_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 16_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 24_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 24_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 32_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 32_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 441_1_2 # BT_ISO_FLAGS_ERROR +Execute_AC_14 8_1_2 +Execute_AC_14 8_2_2 +Execute_AC_14 16_1_2 +Execute_AC_14 16_2_2 +Execute_AC_14 24_1_2 +Execute_AC_14 24_2_2 +Execute_AC_14 32_1_2 +Execute_AC_14 32_2_2 +# Execute_AC_14 441_1_2 # BT_ISO_FLAGS_LOST # Execute_AC_14 441_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 48_1_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 48_2_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 48_3_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 48_4_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 48_5_2 # BT_ISO_FLAGS_ERROR -# Execute_AC_14 48_6_2 # BT_ISO_FLAGS_ERROR +Execute_AC_14 48_1_2 +Execute_AC_14 48_2_2 +Execute_AC_14 48_3_2 +Execute_AC_14 48_4_2 +# Execute_AC_14 48_5_2 # BT_ISO_FLAGS_ERROR +# Execute_AC_14 48_6_2 # BT_ISO_FLAGS_ERROR diff --git a/tests/bsim/bluetooth/audio_samples/bap_broadcast_sink/compile.sh b/tests/bsim/bluetooth/audio_samples/bap_broadcast_sink/compile.sh index 8ed8895934ad1..474307e7c1234 100755 --- a/tests/bsim/bluetooth/audio_samples/bap_broadcast_sink/compile.sh +++ b/tests/bsim/bluetooth/audio_samples/bap_broadcast_sink/compile.sh @@ -10,9 +10,13 @@ set -ue source ${ZEPHYR_BASE}/tests/bsim/compile.source if [ "${BOARD_TS}" == "nrf5340bsim_nrf5340_cpuapp" ]; then - app=samples/bluetooth/bap_broadcast_source sysbuild=1 compile + app=samples/bluetooth/bap_broadcast_source sysbuild=1 \ + conf_overlay=${ZEPHYR_BASE}/samples/bluetooth/bap_broadcast_source/boards/${BOARD_TS}.conf \ + exe_name=bs_${BOARD_TS}_${app}_prj_conf \ + compile app=tests/bsim/bluetooth/audio_samples/bap_broadcast_sink sysbuild=1 \ conf_file=${ZEPHYR_BASE}/samples/bluetooth/bap_broadcast_sink/prj.conf \ + conf_overlay=${ZEPHYR_BASE}/samples/bluetooth/bap_broadcast_sink/boards/${BOARD_TS}.conf \ exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile else app=samples/bluetooth/bap_broadcast_source conf_overlay=overlay-bt_ll_sw_split.conf \ diff --git a/tests/bsim/bluetooth/audio_samples/bap_unicast_client/boards/nrf5340bsim_nrf5340_cpuapp.conf b/tests/bsim/bluetooth/audio_samples/bap_unicast_client/boards/nrf5340bsim_nrf5340_cpuapp.conf index f1624acbc199f..6dbc974ee3d61 100644 --- a/tests/bsim/bluetooth/audio_samples/bap_unicast_client/boards/nrf5340bsim_nrf5340_cpuapp.conf +++ b/tests/bsim/bluetooth/audio_samples/bap_unicast_client/boards/nrf5340bsim_nrf5340_cpuapp.conf @@ -9,4 +9,5 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_SEND_ECC_EMULATION=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bsim/bluetooth/host/gatt/caching/psa_overlay.conf b/tests/bsim/bluetooth/host/gatt/caching/psa_overlay.conf index 7086f66d96d52..9e3c2e8461de7 100644 --- a/tests/bsim/bluetooth/host/gatt/caching/psa_overlay.conf +++ b/tests/bsim/bluetooth/host/gatt/caching/psa_overlay.conf @@ -1,7 +1,5 @@ -CONFIG_BT_USE_PSA_API=y CONFIG_MBEDTLS=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y CONFIG_PSA_CRYPTO_ENABLE_ALL=y CONFIG_ENTROPY_GENERATOR=y -CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y diff --git a/tests/bsim/bluetooth/ll/bis/prj.conf b/tests/bsim/bluetooth/ll/bis/prj.conf index afa1f5958614c..39890e8c35082 100644 --- a/tests/bsim/bluetooth/ll/bis/prj.conf +++ b/tests/bsim/bluetooth/ll/bis/prj.conf @@ -24,3 +24,5 @@ CONFIG_BT_CTLR_TEST=y CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_ACL_RX_SIZE=255 + +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bsim/bluetooth/ll/cis/overlay-acl_group.conf b/tests/bsim/bluetooth/ll/cis/overlay-acl_group.conf index 0d6a6d052c27e..f81c52b2a0ba6 100644 --- a/tests/bsim/bluetooth/ll/cis/overlay-acl_group.conf +++ b/tests/bsim/bluetooth/ll/cis/overlay-acl_group.conf @@ -4,3 +4,4 @@ CONFIG_BT_MAX_CONN=4 CONFIG_BT_ISO_MAX_CHAN=4 CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 CONFIG_BT_CTLR_CENTRAL_SPACING=0 +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bsim/bluetooth/ll/conn/prj_split_hci_uart.conf b/tests/bsim/bluetooth/ll/conn/prj_split_hci_uart.conf index 4c39731af6a42..35e01bd6ffd73 100644 --- a/tests/bsim/bluetooth/ll/conn/prj_split_hci_uart.conf +++ b/tests/bsim/bluetooth/ll/conn/prj_split_hci_uart.conf @@ -15,3 +15,5 @@ CONFIG_BT_L2CAP_TX_BUF_COUNT=6 CONFIG_BT_HCI=y CONFIG_BT_CTLR=n + +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bsim/bluetooth/ll/conn/prj_split_privacy.conf b/tests/bsim/bluetooth/ll/conn/prj_split_privacy.conf index 7c490964fbed0..54e1fec2451ea 100644 --- a/tests/bsim/bluetooth/ll/conn/prj_split_privacy.conf +++ b/tests/bsim/bluetooth/ll/conn/prj_split_privacy.conf @@ -12,3 +12,4 @@ CONFIG_BT_GATT_CLIENT=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_DEVICE_NAME="bsim_test_split" CONFIG_BT_L2CAP_TX_BUF_COUNT=6 +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/bsim/bluetooth/ll/conn/psa_overlay.conf b/tests/bsim/bluetooth/ll/conn/psa_overlay.conf index 7086f66d96d52..9e3c2e8461de7 100644 --- a/tests/bsim/bluetooth/ll/conn/psa_overlay.conf +++ b/tests/bsim/bluetooth/ll/conn/psa_overlay.conf @@ -1,7 +1,5 @@ -CONFIG_BT_USE_PSA_API=y CONFIG_MBEDTLS=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y CONFIG_PSA_CRYPTO_ENABLE_ALL=y CONFIG_ENTROPY_GENERATOR=y -CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y diff --git a/tests/bsim/bluetooth/ll/edtt/gatt_test_app/prj_llcp.conf b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/prj_llcp.conf index 1fdcd1a770f6e..cf1e71513c9d1 100644 --- a/tests/bsim/bluetooth/ll/edtt/gatt_test_app/prj_llcp.conf +++ b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/prj_llcp.conf @@ -24,3 +24,5 @@ CONFIG_BT_CTLR_RX_BUFFERS=3 # To make DEVICE Name writable... CONFIG_BT_DEVICE_NAME_DYNAMIC=y + +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=32 diff --git a/tests/bsim/bluetooth/mesh/overlay_psa.conf b/tests/bsim/bluetooth/mesh/overlay_psa.conf index 764d8cb6ea494..97629adc43f73 100644 --- a/tests/bsim/bluetooth/mesh/overlay_psa.conf +++ b/tests/bsim/bluetooth/mesh/overlay_psa.conf @@ -1,5 +1,5 @@ -# Enable PSA as a crypto backend in host -CONFIG_BT_USE_PSA_API=y +# Increase the number of key slots in PSA Crypto core +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=64 # Enable mbedTLS PSA as a crypto backend CONFIG_BT_MESH_USES_MBEDTLS_PSA=y diff --git a/tests/bsim/bluetooth/mesh/prj.conf b/tests/bsim/bluetooth/mesh/prj.conf index 156b12496758f..a1d7f46a4b060 100644 --- a/tests/bsim/bluetooth/mesh/prj.conf +++ b/tests/bsim/bluetooth/mesh/prj.conf @@ -73,3 +73,5 @@ CONFIG_BT_TESTING=y # Needed for RPR tests due to huge amount of retransmitted messages CONFIG_BT_MESH_MSG_CACHE_SIZE=64 + +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=64 diff --git a/tests/bsim/bluetooth/mesh/src/test_access.c b/tests/bsim/bluetooth/mesh/src/test_access.c index 6967aa6d71c11..f2efd8a2bc551 100644 --- a/tests/bsim/bluetooth/mesh/src/test_access.c +++ b/tests/bsim/bluetooth/mesh/src/test_access.c @@ -812,7 +812,7 @@ static void tx_transmit(bool delayable) } /* Let the receiver hit the first semaphore. */ - k_sleep(K_SECONDS(1)); + k_sleep(K_SECONDS(2)); } PASS(); diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index c7fed00485a17..f4057ebc7b74e 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -15,10 +15,6 @@ #if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA #include -#elif defined CONFIG_BT_MESH_USES_TINYCRYPT -#include -#include -#include #else #error "Unknown crypto library has been chosen" #endif @@ -435,7 +431,6 @@ static void oob_auth_set(int test_step) prov.input_actions = oob_auth_test_vector[test_step].input_actions; } -#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA static void generate_oob_key_pair(void) { psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT; @@ -470,12 +465,6 @@ static void generate_oob_key_pair(void) memcpy(public_key_be, public_key_repr + 1, 64); } -#elif defined CONFIG_BT_MESH_USES_TINYCRYPT -static void generate_oob_key_pair(void) -{ - ASSERT_TRUE(uECC_make_key(public_key_be, private_key_be, uECC_secp256r1())); -} -#endif static void oob_device(bool use_oob_pk) { diff --git a/tests/bsim/bluetooth/samples/central_hr_peripheral_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf b/tests/bsim/bluetooth/samples/central_hr_peripheral_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf index 4d2c3afd09ecc..00e2fd2436073 100644 --- a/tests/bsim/bluetooth/samples/central_hr_peripheral_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf +++ b/tests/bsim/bluetooth/samples/central_hr_peripheral_hr/boards/nrf5340bsim_nrf5340_cpuapp.conf @@ -1 +1,2 @@ CONFIG_BT_BUF_ACL_RX_SIZE=255 +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/crypto/mbedtls_psa/prj.conf b/tests/crypto/mbedtls_psa/prj.conf index 0f4585d6b49d3..54dd833011b1f 100644 --- a/tests/crypto/mbedtls_psa/prj.conf +++ b/tests/crypto/mbedtls_psa/prj.conf @@ -3,4 +3,3 @@ CONFIG_ZTEST=y CONFIG_MBEDTLS=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y -CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y diff --git a/tests/crypto/mbedtls_psa/testcase.yaml b/tests/crypto/mbedtls_psa/testcase.yaml index 6b96e8ff5f6fa..af9a0b7600260 100644 --- a/tests/crypto/mbedtls_psa/testcase.yaml +++ b/tests/crypto/mbedtls_psa/testcase.yaml @@ -11,8 +11,6 @@ # - no TF-M enabled devices because we assume that the TF-M implementation # of PSA crypto is working fine on the platforms that support TF-M. # - platform should be testable by the CI. -# - enable CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG in order to reduce as much -# as possible usage of legacy modules in Mbed TLS. # - pick 1 platform which supports entropy driver and 1 which does not. The # latter case will allow to test # CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG. @@ -34,8 +32,11 @@ tests: # Pick a platform which does not have an entropy driver. In this case we # enable the timer random generator because it's always available on all # platforms. + # Explicitly select CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG because this is + # not "automatically selected" when there is CSPRNG available. integration_platforms: - qemu_x86 extra_configs: + - CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y - CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG=y - CONFIG_TEST_RANDOM_GENERATOR=y diff --git a/tests/crypto/secp256r1/mbedtls.conf b/tests/crypto/secp256r1/mbedtls.conf index dd8231a21ca54..bbc2eb0e65638 100644 --- a/tests/crypto/secp256r1/mbedtls.conf +++ b/tests/crypto/secp256r1/mbedtls.conf @@ -1,7 +1,8 @@ CONFIG_MBEDTLS=y -CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED=y +CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS=y +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=2 CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT=y CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE=y diff --git a/tests/crypto/secp256r1/p256-m_raw.conf b/tests/crypto/secp256r1/p256-m_raw.conf index 801a31df91a86..5ac706ef29bf6 100644 --- a/tests/crypto/secp256r1/p256-m_raw.conf +++ b/tests/crypto/secp256r1/p256-m_raw.conf @@ -1,5 +1,4 @@ CONFIG_MBEDTLS=y -CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED=y CONFIG_MBEDTLS_PSA_P256M_DRIVER_RAW=y diff --git a/tests/modules/uoscore/prj.conf b/tests/modules/uoscore/prj.conf index f661156dbc1d6..d86ae838b21d3 100644 --- a/tests/modules/uoscore/prj.conf +++ b/tests/modules/uoscore/prj.conf @@ -13,7 +13,6 @@ CONFIG_MBEDTLS=y CONFIG_MBEDTLS_ENABLE_HEAP=y CONFIG_MBEDTLS_HEAP_SIZE=2048 CONFIG_MBEDTLS_ENTROPY_C=y -CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR=y # PSA Crypto options diff --git a/tests/net/socket/tls_configurations/prj.conf b/tests/net/socket/tls_configurations/prj.conf index 93a8c0f8b1230..23842f6a64149 100644 --- a/tests/net/socket/tls_configurations/prj.conf +++ b/tests/net/socket/tls_configurations/prj.conf @@ -28,7 +28,6 @@ CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2048 CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y # Build the PSA Crypto core so that the TLS stack uses the PSA crypto API. CONFIG_MBEDTLS_PSA_CRYPTO_C=y -CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y CONFIG_ENTROPY_GENERATOR=y # Disable some Kconfigs that are implied by CONFIG_NET_SOCKETS_SOCKOPT_TLS. diff --git a/tests/subsys/jwt/testcase.yaml b/tests/subsys/jwt/testcase.yaml index f439e9aea9e1c..8744d51bbd03b 100644 --- a/tests/subsys/jwt/testcase.yaml +++ b/tests/subsys/jwt/testcase.yaml @@ -12,6 +12,9 @@ tests: libraries.encoding.jwt.ecdsa.psa: extra_configs: - CONFIG_JWT_SIGN_ECDSA_PSA=y + # Explicitly select CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG because this + # is not automatically selected on platforms that do not have a CSPRNG + # source. - CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y - CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG=y libraries.encoding.jwt.rsa.legacy: @@ -21,5 +24,8 @@ tests: libraries.encoding.jwt.rsa.psa: extra_configs: - CONFIG_JWT_SIGN_RSA_PSA=y + # Explicitly select CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG because this + # is not automatically selected on platforms that do not have a CSPRNG + # source. - CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y - CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG=y diff --git a/tests/subsys/secure_storage/psa/crypto/overlay-secure_storage.conf b/tests/subsys/secure_storage/psa/crypto/overlay-secure_storage.conf index 84d933c2332ba..063c04fd2b5e7 100644 --- a/tests/subsys/secure_storage/psa/crypto/overlay-secure_storage.conf +++ b/tests/subsys/secure_storage/psa/crypto/overlay-secure_storage.conf @@ -4,7 +4,6 @@ CONFIG_MAIN_STACK_SIZE=2048 CONFIG_MBEDTLS=y CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TIMER_RANDOM_GENERATOR=y -CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y CONFIG_SECURE_STORAGE=y diff --git a/tests/subsys/secure_storage/psa/its/overlay-default_transform.conf b/tests/subsys/secure_storage/psa/its/overlay-default_transform.conf index 52751db59b622..2f49f5d6593aa 100644 --- a/tests/subsys/secure_storage/psa/its/overlay-default_transform.conf +++ b/tests/subsys/secure_storage/psa/its/overlay-default_transform.conf @@ -1,7 +1,6 @@ CONFIG_MBEDTLS=y CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TIMER_RANDOM_GENERATOR=y -CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y # SETTINGS_MAX_VAL_LEN (256) - flags (1) - CONFIG_SECURE_STORAGE_ITS_TRANSFORM_OUTPUT_OVERHEAD (28) diff --git a/tests/subsys/storage/flash_map/overlay-psa.conf b/tests/subsys/storage/flash_map/overlay-psa.conf index 4b5dcfd9af67d..381d89286d496 100644 --- a/tests/subsys/storage/flash_map/overlay-psa.conf +++ b/tests/subsys/storage/flash_map/overlay-psa.conf @@ -1,3 +1,5 @@ CONFIG_FLASH_AREA_CHECK_INTEGRITY_PSA=y CONFIG_MBEDTLS=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y + +CONFIG_TEST_RANDOM_GENERATOR=y diff --git a/west.yml b/west.yml index 87657ebf6df36..9dd1f0aa6f9a9 100644 --- a/west.yml +++ b/west.yml @@ -280,7 +280,7 @@ manifest: revision: 2b498e6f36d6b82ae1da12c8b7742e318624ecf5 path: modules/lib/gui/lvgl - name: mbedtls - revision: a78176c6ff0733ba08018cba4447bd3f20de7978 + revision: pull/64/head path: modules/crypto/mbedtls groups: - crypto