Skip to content

Commit

Permalink
Bluetooth: Controller: Support FAKE_ENTROPY_NATIVE_POSIX
Browse files Browse the repository at this point in the history
Add support for use of FAKE_ENTROPY_NATIVE_POSIX as entropy
driver for the Controller on BOARD_NRF54L15BSIM.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
  • Loading branch information
cvinayak authored and nashif committed Sep 6, 2024
1 parent 7e35800 commit 34b6b3d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
33 changes: 32 additions & 1 deletion subsys/bluetooth/controller/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ""
Expand Down
7 changes: 6 additions & 1 deletion subsys/bluetooth/controller/Kconfig.ll_sw_split
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 34b6b3d

Please sign in to comment.