From 34b6b3d9eb33787443af4bdb7fd18ab642c56cd4 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 30 Aug 2024 10:22:38 +0200 Subject: [PATCH] Bluetooth: Controller: Support FAKE_ENTROPY_NATIVE_POSIX Add support for use of FAKE_ENTROPY_NATIVE_POSIX as entropy driver for the Controller on BOARD_NRF54L15BSIM. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/Kconfig | 33 ++++++++++++++++++- .../bluetooth/controller/Kconfig.ll_sw_split | 7 +++- .../controller/ll_sw/nordic/lll/lll.c | 32 +++++++++--------- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index f512293968a..f6aaba31fab 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -6,7 +6,11 @@ # The following symbols are enabled depending if the controller actually # supports the respective features. +config BT_CTLR_ENTROPY_SUPPORT + bool + config BT_CTLR_CRYPTO_SUPPORT + depends on BT_CTLR_ENTROPY_SUPPORT bool config BT_CTLR_LE_ENC_SUPPORT @@ -147,15 +151,42 @@ config BT_CTLR_HCI comment "BLE Controller configuration" +config BT_CTLR_ENTROPY + bool "Random number generation in Controller" + depends on BT_CTLR_ENTROPY_SUPPORT + select ENTROPY_GENERATOR + default y + help + Use random number generation provided by the Controller. + + Bluetooth Core Specification mandates a use of random number generator + compliant with FIPS PUB 140-2. + + This option allows for Controller implementation that do not use true + random number generation and hence making the implementation as + experimental. + + Controller implementations can provide custom bare-metal random number + implementation without any support in Zephyr driver, i.e. there is no + ENTROPY_HAS_DRIVER enabled. + config BT_CTLR_CRYPTO bool "Crypto functions in Controller" depends on BT_CTLR_CRYPTO_SUPPORT - select ENTROPY_GENERATOR default y help Use random number generation and AES encryption support functions provided by the controller. + Support for HCI LE Rand and HCI LE Encrypt commands are mandatory + by Bluetooth Core Specification. + + In an Application/Host and Controller split (using a HCI transport) or + combined builds for single CPU SoCs, applications can use its own + FIPS-197 compliant cryptographic implementations. In this case the + Controller cryptographic implementations can be disabled to save flash + and RAM usage. + config BT_CTLR_HCI_VS_BUILD_INFO string "Zephyr HCI VS Build Info string" default "" diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 111f62272af..e6d32e8251b 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -11,8 +11,11 @@ config BT_LLL_VENDOR_NORDIC depends on !$(dt_nodelabel_enabled,timer0) depends on !$(dt_nodelabel_enabled,rtc0) - select ENTROPY_NRF5_RNG if BT_CTLR_CRYPTO + select BT_CTLR_ENTROPY_SUPPORT if !SOC_COMPATIBLE_NRF54LX || BOARD_NRF54L15BSIM + select FAKE_ENTROPY_NATIVE_POSIX if BT_CTLR_ENTROPY && BOARD_NRF54L15BSIM + select ENTROPY_NRF5_RNG if BT_CTLR_ENTROPY && !SOC_COMPATIBLE_NRF54LX select ENTROPY_NRF5_BIAS_CORRECTION if ENTROPY_NRF5_RNG + select EXPERIMENTAL if !ENTROPY_HAS_DRIVER || FAKE_ENTROPY_NATIVE_POSIX select BT_HAS_HCI_VS select BT_CTLR_CRYPTO_SUPPORT if !SOC_COMPATIBLE_NRF54LX @@ -69,7 +72,9 @@ config BT_LLL_VENDOR_NORDIC config BT_LLL_VENDOR_OPENISA bool "Use OpenISA LLL" depends on SOC_OPENISA_RV32M1 + select BT_HAS_HCI_VS + select BT_CTLR_ENTROPY_SUPPORT select BT_CTLR_CRYPTO_SUPPORT select BT_CTLR_LE_ENC_SUPPORT if BT_CTLR_CRYPTO_SUPPORT && \ !BT_CTLR_DATA_LENGTH_CLEAR diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index ec2ad2896f5..2572bac35e5 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -58,9 +58,9 @@ static struct { } event; /* Entropy device */ -#if defined(CONFIG_ENTROPY_NRF5_RNG) +#if defined(CONFIG_ENTROPY_HAS_DRIVER) static const struct device *const dev_entropy = DEVICE_DT_GET(DT_NODELABEL(rng)); -#endif /* CONFIG_ENTROPY_NRF5_RNG */ +#endif /* CONFIG_ENTROPY_HAS_DRIVER */ static int init_reset(void); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) @@ -179,12 +179,12 @@ int lll_init(void) { int err; -#if defined(CONFIG_ENTROPY_NRF5_RNG) +#if defined(CONFIG_ENTROPY_HAS_DRIVER) /* Get reference to entropy device */ if (!device_is_ready(dev_entropy)) { return -ENODEV; } -#endif /* CONFIG_ENTROPY_NRF5_RNG */ +#endif /* CONFIG_ENTROPY_HAS_DRIVER */ /* Initialise LLL internals */ event.curr.abort_cb = NULL; @@ -327,54 +327,54 @@ int lll_deinit(void) int lll_csrand_get(void *buf, size_t len) { -#if defined(CONFIG_ENTROPY_NRF5_RNG) +#if defined(CONFIG_ENTROPY_HAS_DRIVER) return entropy_get_entropy(dev_entropy, buf, len); -#else +#else /* !CONFIG_ENTROPY_HAS_DRIVER */ /* FIXME: No suitable entropy device available yet. * It is required by Controller to use random numbers. * Hence, return uninitialized buf contents, for now. */ return 0; -#endif +#endif /* !CONFIG_ENTROPY_HAS_DRIVER */ } int lll_csrand_isr_get(void *buf, size_t len) { -#if defined(CONFIG_ENTROPY_NRF5_RNG) +#if defined(CONFIG_ENTROPY_HAS_DRIVER) return entropy_get_entropy_isr(dev_entropy, buf, len, 0); -#else +#else /* !CONFIG_ENTROPY_HAS_DRIVER */ /* FIXME: No suitable entropy device available yet. * It is required by Controller to use random numbers. * Hence, return uninitialized buf contents, for now. */ return 0; -#endif +#endif /* !CONFIG_ENTROPY_HAS_DRIVER */ } int lll_rand_get(void *buf, size_t len) { -#if defined(CONFIG_ENTROPY_NRF5_RNG) +#if defined(CONFIG_ENTROPY_HAS_DRIVER) return entropy_get_entropy(dev_entropy, buf, len); -#else +#else /* !CONFIG_ENTROPY_HAS_DRIVER */ /* FIXME: No suitable entropy device available yet. * It is required by Controller to use random numbers. * Hence, return uninitialized buf contents, for now. */ return 0; -#endif +#endif /* !CONFIG_ENTROPY_HAS_DRIVER */ } int lll_rand_isr_get(void *buf, size_t len) { -#if defined(CONFIG_ENTROPY_NRF5_RNG) +#if defined(CONFIG_ENTROPY_HAS_DRIVER) return entropy_get_entropy_isr(dev_entropy, buf, len, 0); -#else +#else /* !CONFIG_ENTROPY_HAS_DRIVER */ /* FIXME: No suitable entropy device available yet. * It is required by Controller to use random numbers. * Hence, return uninitialized buf contents, for now. */ return 0; -#endif +#endif /* !CONFIG_ENTROPY_HAS_DRIVER */ } int lll_reset(void)