Skip to content
Permalink
Browse files

bluetooth: controller: Moved ull_entropy_get to LLL

Moved and renamed ull_entropy_get to lll_entropy_get, placed under
vendor specific ll_sw. This is needed for SW implemented entropy,
to allow vendor implementation of faster, less secure random number
generator for randomizing ADV timing.

Signed-off-by: Morten Priess <mtpr@oticon.com>
  • Loading branch information...
mtpr-ot authored and aescolar committed Jun 19, 2019
1 parent 13b4c17 commit 14537fee9d703344c9b5d9d7fa8095dffc336899
@@ -7,6 +7,7 @@
#include <errno.h>
#include <zephyr/types.h>
#include <device.h>
#include <entropy.h>
#include <clock_control.h>
#include <drivers/clock_control/nrf_clock_control.h>

@@ -40,6 +41,9 @@ static struct {
struct device *clk_hf;
} lll;

/* Entropy device */
static struct device *dev_entropy;

static int init_reset(void);
static int prepare(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb,
lll_prepare_cb_t prepare_cb, int prio,
@@ -108,6 +112,12 @@ int lll_init(void)
struct device *clk_k32;
int err;

/* Get reference to entropy device */
dev_entropy = device_get_binding(CONFIG_ENTROPY_NAME);
if (!dev_entropy) {
return -ENODEV;
}

/* Initialise LLL internals */
event.curr.abort_cb = NULL;

@@ -150,6 +160,11 @@ int lll_init(void)
return 0;
}

u8_t lll_entropy_get(u8_t len, void *rand)
{
return entropy_get_entropy_isr(dev_entropy, rand, len, 0);
}

int lll_reset(void)
{
int err;
@@ -14,3 +14,4 @@ u32_t lll_evt_offset_get(struct evt_hdr *evt);
u32_t lll_preempt_calc(struct evt_hdr *evt, u8_t ticker_id,
u32_t ticks_at_event);
void lll_chan_set(u32_t chan);
u8_t lll_entropy_get(u8_t len, void *rand);
@@ -119,10 +119,9 @@ static struct k_sem sem_ticker_api_cb;
/* Semaphore to wakeup thread on Rx-ed objects */
static struct k_sem *sem_recv;

/* Entropy device */
static struct device *dev_entropy;

/* Declare prepare-event FIFO: mfifo_prep: Queue of struct node_rx_event_done */
/* Declare prepare-event FIFO: mfifo_prep.
* Queue of struct node_rx_event_done
*/
static MFIFO_DEFINE(prep, sizeof(struct lll_event), EVENT_PIPELINE_MAX);

/* Declare done-event FIFO: mfifo_done.
@@ -225,11 +224,6 @@ int ll_init(struct k_sem *sem_rx)

/* Store the semaphore to be used to wakeup Thread context */
sem_recv = sem_rx;
/* Get reference to entropy device */
dev_entropy = device_get_binding(CONFIG_ENTROPY_NAME);
if (!dev_entropy) {
return -ENODEV;
}

/* Initialize counter */
/* TODO: Bind and use counter driver? */
@@ -1123,11 +1117,6 @@ void *ull_event_done(void *param)
return evdone;
}

u8_t ull_entropy_get(u8_t len, void *rand)
{
return entropy_get_entropy_isr(dev_entropy, rand, len, 0);
}

static inline int init_reset(void)
{
memq_link_t *link;
@@ -28,6 +28,7 @@
#include "lll_adv.h"
#include "lll_scan.h"
#include "lll_conn.h"
#include "lll_internal.h"
#include "lll_filter.h"

#include "ull_adv_types.h"
@@ -1016,7 +1017,7 @@ static void ticker_cb(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
u32_t random_delay;
u32_t ret;

ull_entropy_get(sizeof(random_delay), &random_delay);
lll_entropy_get(sizeof(random_delay), &random_delay);
random_delay %= HAL_TICKER_US_TO_TICKS(10000);
random_delay += 1;

@@ -37,4 +37,3 @@ void *ull_update_mark(void *param);
void *ull_update_unmark(void *param);
void *ull_update_mark_get(void);
int ull_disable(void *param);
u8_t ull_entropy_get(u8_t len, void *rand);

1 comment on commit 14537fe

@George-Stefan

This comment has been minimized.

Copy link

commented on 14537fe Jun 20, 2019

entropy_get_entropy_isr() is still used in ull_conn.c.
Why not replacing it from there as well?

Please sign in to comment.
You can’t perform that action at this time.