Skip to content

Commit

Permalink
Softdevice_controller: remove RNG from the SoftDevice Controller
Browse files Browse the repository at this point in the history
The application is responsible for providing the SoftDevice Controller
with random number generating functions.

Signed-off-by: Bernhard Wimmer <[email protected]>
  • Loading branch information
bewi-nordic authored and joerchan committed Mar 8, 2021
1 parent e64f0dd commit 20ad8a5
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 188 deletions.
1 change: 0 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Kconfig* @tejlmand
/.known-issues/ @carlescufi
# All subfolders
/drivers/ @anangl
/drivers/bt_ll_softdevice/ @anangl @rugeGerritsen
/dts/ @anangl
/ext/ @carlescufi
/include/ @anangl @rlubos @pizi-nordic
Expand Down
1 change: 0 additions & 1 deletion drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

add_subdirectory_ifdef(CONFIG_SENSOR sensor)
add_subdirectory_ifdef(CONFIG_NETWORKING net)
add_subdirectory_ifdef(CONFIG_BT_LL_SOFTDEVICE bt_ll_softdevice)
add_subdirectory_ifdef(CONFIG_MPSL mpsl)
add_subdirectory(hw_cc310)
add_subdirectory(entropy)
Expand Down
4 changes: 0 additions & 4 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ rsource "sensor/Kconfig"
rsource "gps/Kconfig"
rsource "serial/Kconfig"

if BT_LL_SOFTDEVICE
rsource "bt_ll_softdevice/Kconfig"
endif

if MPSL
rsource "mpsl/Kconfig"
endif
Expand Down
7 changes: 0 additions & 7 deletions drivers/bt_ll_softdevice/CMakeLists.txt

This file was deleted.

7 changes: 0 additions & 7 deletions drivers/bt_ll_softdevice/Kconfig

This file was deleted.

7 changes: 0 additions & 7 deletions drivers/bt_ll_softdevice/entropy/CMakeLists.txt

This file was deleted.

27 changes: 0 additions & 27 deletions drivers/bt_ll_softdevice/entropy/Kconfig

This file was deleted.

133 changes: 0 additions & 133 deletions drivers/bt_ll_softdevice/entropy/entropy_ll_softdevice.c

This file was deleted.

48 changes: 48 additions & 0 deletions subsys/bluetooth/controller/hci_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <drivers/entropy.h>
#include <drivers/bluetooth/hci_driver.h>
#include <bluetooth/controller.h>
#include <bluetooth/hci_vs.h>
Expand All @@ -13,8 +14,10 @@
#include <soc.h>
#include <sys/byteorder.h>
#include <stdbool.h>
#include <sys/__assert.h>

#include <sdc.h>
#include <sdc_soc.h>
#include <sdc_hci.h>
#include <sdc_hci_vs.h>
#include "multithreading_lock.h"
Expand Down Expand Up @@ -372,6 +375,33 @@ void host_signal(void)
k_sem_give(&sem_recv);
}


static const struct device *entropy_source;

static uint8_t rand_prio_low_vector_get(uint8_t *p_buff, uint8_t length)
{
int ret = entropy_get_entropy_isr(entropy_source, p_buff, length, 0);

__ASSERT(ret >= 0, "The entropy source returned an error in the low priority context");
return ret >= 0 ? ret : 0;
}

static uint8_t rand_prio_high_vector_get(uint8_t *p_buff, uint8_t length)
{
int ret = entropy_get_entropy_isr(entropy_source, p_buff, length, 0);

__ASSERT(ret >= 0, "The entropy source returned an error in the high priority context");
return ret >= 0 ? ret : 0;
}

static void rand_prio_low_vector_get_blocking(uint8_t *p_buff, uint8_t length)
{
int err = entropy_get_entropy(entropy_source, p_buff, length);

__ASSERT(err == 0, "The entropy source returned an error in a blocking call");
(void) err;
}

static int hci_driver_open(void)
{
BT_DBG("Open");
Expand Down Expand Up @@ -447,6 +477,24 @@ static int hci_driver_open(void)
return -ENOMEM;
}

entropy_source = device_get_binding(DT_LABEL(DT_NODELABEL(rng)));
if (!entropy_source) {
BT_ERR("An entropy source is required");
return -ENODEV;
}

sdc_rand_source_t rand_functions = {
.rand_prio_low_get = rand_prio_low_vector_get,
.rand_prio_high_get = rand_prio_high_vector_get,
.rand_poll = rand_prio_low_vector_get_blocking
};

err = sdc_rand_source_register(&rand_functions);
if (err) {
BT_ERR("Failed to register rand source (%d)", err);
return -EINVAL;
}

if (IS_ENABLED(CONFIG_BT_BROADCASTER)) {
if (IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT)) {
err = sdc_support_ext_adv();
Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ manifest:
- name: nrfxlib
repo-path: sdk-nrfxlib
path: nrfxlib
revision: bdb5abc20b7d80b9444823d4189357168584038e
revision: 46efc8f14e8f0e9d07ea00d6d62e7b013d46965a
- name: trusted-firmware-m
repo-path: sdk-trusted-firmware-m
path: modules/tee/tfm
Expand Down

0 comments on commit 20ad8a5

Please sign in to comment.