From 32f03a42c78e2aada7da070ca09a2df35ea9f5b9 Mon Sep 17 00:00:00 2001 From: Vinayak Chettimada Date: Wed, 15 Mar 2017 09:06:07 +0100 Subject: [PATCH] Bluetooth: controller: Move bt_rand into separate file Move crypto related interface provided by the software-based Controller bt_rand into separate file, crypto.c. Change-id: I9998a43fe45799b479969ca195f324199418b8c2 Signed-off-by: Vinayak Chettimada --- subsys/bluetooth/controller/ll_sw/Makefile | 1 + subsys/bluetooth/controller/ll_sw/crypto.c | 25 ++++++++++++++++++++++ subsys/bluetooth/controller/ll_sw/ll.c | 16 -------------- 3 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 subsys/bluetooth/controller/ll_sw/crypto.c diff --git a/subsys/bluetooth/controller/ll_sw/Makefile b/subsys/bluetooth/controller/ll_sw/Makefile index c60465a75cc..00f29c77488 100644 --- a/subsys/bluetooth/controller/ll_sw/Makefile +++ b/subsys/bluetooth/controller/ll_sw/Makefile @@ -2,3 +2,4 @@ ccflags-$(CONFIG_BLUETOOTH_LL_SW) += -I$(srctree)/subsys/bluetooth/controller/in ccflags-$(CONFIG_BLUETOOTH_LL_SW) += -I$(srctree)/subsys/bluetooth/controller obj-$(CONFIG_BLUETOOTH_LL_SW) += ctrl.o obj-$(CONFIG_BLUETOOTH_LL_SW) += ll.o +obj-$(CONFIG_BLUETOOTH_LL_SW) += crypto.o diff --git a/subsys/bluetooth/controller/ll_sw/crypto.c b/subsys/bluetooth/controller/ll_sw/crypto.c new file mode 100644 index 00000000000..3fdb1617c21 --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/crypto.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016-2017 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "hal/cpu.h" +#include "hal/rand.h" + +K_MUTEX_DEFINE(mutex_rand); + +int bt_rand(void *buf, size_t len) +{ + while (len) { + k_mutex_lock(&mutex_rand, K_FOREVER); + len = rand_get(len, buf); + k_mutex_unlock(&mutex_rand); + if (len) { + cpu_sleep(); + } + } + + return 0; +} diff --git a/subsys/bluetooth/controller/ll_sw/ll.c b/subsys/bluetooth/controller/ll_sw/ll.c index 9deacc891b0..df304a193cc 100644 --- a/subsys/bluetooth/controller/ll_sw/ll.c +++ b/subsys/bluetooth/controller/ll_sw/ll.c @@ -46,8 +46,6 @@ static uint8_t MALIGN(4) _ticker_user_ops[RADIO_TICKER_USER_OPS] [TICKER_USER_OP_T_SIZE]; static uint8_t MALIGN(4) _radio[LL_MEM_TOTAL]; -K_MUTEX_DEFINE(mutex_rand); - static struct k_sem *sem_recv; static struct { @@ -74,20 +72,6 @@ static struct { uint8_t filter_policy:1; } _ll_scan_params; -int bt_rand(void *buf, size_t len) -{ - while (len) { - k_mutex_lock(&mutex_rand, K_FOREVER); - len = rand_get(len, buf); - k_mutex_unlock(&mutex_rand); - if (len) { - cpu_sleep(); - } - } - - return 0; -} - void mayfly_enable_cb(uint8_t caller_id, uint8_t callee_id, uint8_t enable) { (void)caller_id;