From 90871a5e98a2ceb28a391fba59d8ea926e1569ea Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Tue, 13 Sep 2016 16:49:44 +0200 Subject: [PATCH] Bluetooth: Controller: Implement LE_RAND command The LE_RAND HCI command was not filling in the rand array with 8 random numbers as required by the spec. Please note that the while() loop inside the command's implementation can take up to hundreds of ms to execute. Jira: ZEP-726 Change-Id: If27ff861ee5fa7842cd469e99d5bfa8ac47ac2fa Signed-off-by: Carles Cufi --- drivers/bluetooth/controller/hci/hci.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/controller/hci/hci.c b/drivers/bluetooth/controller/hci/hci.c index 8f502270865..7c9ce5ba745 100644 --- a/drivers/bluetooth/controller/hci/hci.c +++ b/drivers/bluetooth/controller/hci/hci.c @@ -25,6 +25,8 @@ #include "defines.h" #include "ticker.h" #include "mem.h" +#include "rand.h" +#include "cpu.h" #include "ecb.h" #include "ccm.h" #include "radio.h" @@ -554,13 +556,19 @@ static void le_encrypt(uint8_t *cp, struct bt_hci_evt_hdr *evt) static void le_rand(uint8_t *cp, struct bt_hci_evt_hdr *evt) { struct bt_hci_rp_le_rand *rp = HCI_CC_RP(evt); + uint8_t count = sizeof(rp->rand); evt->evt = BT_HCI_EVT_CMD_COMPLETE; evt->len = HCI_CC_LEN(*rp); rp->status = 0x00; - /** TODO fill rand */ + while (count) { + count = rand_get(count, rp->rand); + if (count) { + cpu_sleep(); + } + } } static void le_start_encryption(uint8_t *cp, struct bt_hci_evt_hdr *evt)