From bd066867e4295a56f79049723d40d96c87f28a51 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 13 Jun 2016 10:58:26 +0300 Subject: [PATCH] Revert "Bluetooth: Remove LE Rand workaround for mynewt firmware" The current documentation points to MyNewt 0.9 which doesn't have the necessary fix, so revert the workaround until the next release of MyNewt is out. A minor change to the original patch is that we also have a delay in prng_init() which seems to be needed since this is now called earlier during the HCI init sequence. This reverts commit d75acb44c3bbfac340519f7a4f2799ae2b4aaed5. Change-Id: Ic4919e01bddbfaca477825c3f7fdcb549c8d10ec Signed-off-by: Johan Hedberg --- net/bluetooth/hci_core.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 979f3479df2..d2e0dc46643 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2111,6 +2111,20 @@ static void hci_cmd_status(struct net_buf *buf) } } +static inline void mynewt_rand_delay(void) +{ +#if defined(CONFIG_BOARD_ARDUINO_101) + /* FIXME: Temporary hack for MyNewt HCI firmware which + * crashes if it receives too rapid LE_Rand commands. + */ + if (sys_execution_context_type_get() == NANO_CTX_FIBER) { + fiber_sleep(MSEC(30)); + } else { + task_sleep(MSEC(30)); + } +#endif +} + static int prng_reseed(struct tc_hmac_prng_struct *h) { uint8_t seed[32]; @@ -2121,6 +2135,11 @@ static int prng_reseed(struct tc_hmac_prng_struct *h) struct bt_hci_rp_le_rand *rp; struct net_buf *rsp; + /* FIXME: Temporary hack for MyNewt HCI firmware which + * crashes if it receives too rapid LE_Rand commands. + */ + mynewt_rand_delay(); + ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_RAND, NULL, &rsp); if (ret) { return ret; @@ -2150,6 +2169,11 @@ static int prng_init(struct tc_hmac_prng_struct *h) struct net_buf *rsp; int ret; + /* FIXME: Temporary hack for MyNewt HCI firmware which + * crashes if it receives too rapid LE_Rand commands. + */ + mynewt_rand_delay(); + ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_RAND, NULL, &rsp); if (ret) { return ret;