Bluetooth: Move PRNG initialization a bit later in HCI init

Move the PRNG initialization after reading local supported commands,
so that we don't send HCI_LE_Rand if the controller doesn't support it
(we still need to fail the init however). The patch also removes a few
unnecessary #ifdefs related to crypto.h.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-06-27 08:45:01 +03:00 committed by Johan Hedberg
commit 8f9c305a15
2 changed files with 15 additions and 14 deletions

View file

@ -66,6 +66,11 @@ int prng_init(void)
struct net_buf *rsp;
int ret;
/* Check first that HCI_LE_Rand is supported */
if (!(bt_dev.supported_commands[27] & BIT(7))) {
return -ENOTSUP;
}
ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_RAND, NULL, &rsp);
if (ret) {
return ret;

View file

@ -39,10 +39,7 @@
#include "conn_internal.h"
#include "l2cap_internal.h"
#include "smp.h"
#if defined(CONFIG_BLUETOOTH_HOST_CRYPTO)
#include "crypto.h"
#endif
/* Peripheral timeout to initialize Connection Parameter Update procedure */
#define CONN_UPDATE_TIMEOUT K_SECONDS(5)
@ -3172,17 +3169,6 @@ static int common_init(void)
hci_reset_complete(rsp);
net_buf_unref(rsp);
#if defined(CONFIG_BLUETOOTH_HOST_CRYPTO)
/*
* initialize PRNG right after reset so that it is safe to use it later
* on in initialization process
*/
err = prng_init();
if (err) {
return err;
}
#endif
/* Read Local Supported Features */
err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_LOCAL_FEATURES, NULL, &rsp);
if (err) {
@ -3217,6 +3203,16 @@ static int common_init(void)
read_supported_commands_complete(rsp);
net_buf_unref(rsp);
if (IS_ENABLED(CONFIG_BLUETOOTH_HOST_CRYPTO)) {
/* Initialize the PRNG so that it is safe to use it later
* on in the initialization process.
*/
err = prng_init();
if (err) {
return err;
}
}
#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
err = set_flow_control();
if (err) {