Bluetooth: Remove bt_read_static_addr() "hack"

This function was used to shortcut HCI for combined host + controller
builds. It doesn't provide much value and adds complexity to the HCI
driver interface, so just remove it. This means vendor-specific HCI
commands is now the only way for the host to access the same
information.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
This commit is contained in:
Johan Hedberg 2024-05-10 15:57:50 +03:00 committed by Anas Nashif
commit 484fe3f06c
4 changed files with 39 additions and 59 deletions

View file

@ -52,15 +52,6 @@ enum {
*/
int bt_recv(struct net_buf *buf);
/** @brief Read static addresses from the controller.
*
* @param addrs Random static address and Identity Root (IR) array.
* @param size Size of array.
*
* @return Number of addresses read.
*/
uint8_t bt_read_static_addr(struct bt_hci_vs_static_addr addrs[], uint8_t size);
/** Possible values for the 'bus' member of the bt_hci_driver struct */
enum bt_hci_driver_bus {
BT_HCI_DRIVER_BUS_VIRTUAL = 0,

View file

@ -4788,16 +4788,6 @@ static int controller_cmd_handle(uint16_t ocf, struct net_buf *cmd,
return 0;
}
/* If Zephyr VS HCI commands are not enabled provide this functionality directly
*/
#if !defined(CONFIG_BT_HCI_VS)
uint8_t bt_read_static_addr(struct bt_hci_vs_static_addr addrs[], uint8_t size)
{
return hci_vendor_read_static_addr(addrs, size);
}
#endif /* !defined(CONFIG_BT_HCI_VS) */
#if defined(CONFIG_BT_HCI_VS)
static void vs_read_version_info(struct net_buf *buf, struct net_buf **evt)
{

View file

@ -1589,9 +1589,9 @@ int bt_setup_public_id_addr(void)
return id_create(BT_ID_DEFAULT, &addr, irk);
}
#if defined(CONFIG_BT_HCI_VS)
uint8_t bt_read_static_addr(struct bt_hci_vs_static_addr addrs[], uint8_t size)
static uint8_t vs_read_static_addr(struct bt_hci_vs_static_addr addrs[], uint8_t size)
{
#if defined(CONFIG_BT_HCI_VS)
struct bt_hci_rp_vs_read_static_addrs *rp;
struct net_buf *rsp;
int err, i;
@ -1637,59 +1637,58 @@ uint8_t bt_read_static_addr(struct bt_hci_vs_static_addr addrs[], uint8_t size)
}
return cnt;
#else
return 0;
#endif
}
#endif /* CONFIG_BT_HCI_VS */
int bt_setup_random_id_addr(void)
{
#if defined(CONFIG_BT_HCI_VS) || defined(CONFIG_BT_CTLR)
/* Only read the addresses if the user has not already configured one or
* more identities (!bt_dev.id_count).
*/
if (!bt_dev.id_count) {
if (IS_ENABLED(CONFIG_BT_HCI_VS) && !bt_dev.id_count) {
struct bt_hci_vs_static_addr addrs[CONFIG_BT_ID_MAX];
bt_dev.id_count = bt_read_static_addr(addrs, CONFIG_BT_ID_MAX);
bt_dev.id_count = vs_read_static_addr(addrs, CONFIG_BT_ID_MAX);
if (bt_dev.id_count) {
for (uint8_t i = 0; i < bt_dev.id_count; i++) {
int err;
bt_addr_le_t addr;
uint8_t *irk = NULL;
#if defined(CONFIG_BT_PRIVACY)
uint8_t ir_irk[16];
for (uint8_t i = 0; i < bt_dev.id_count; i++) {
int err;
bt_addr_le_t addr;
uint8_t *irk = NULL;
uint8_t ir_irk[16];
if (!IS_ENABLED(CONFIG_BT_PRIVACY_RANDOMIZE_IR)) {
if (!bt_smp_irk_get(addrs[i].ir, ir_irk)) {
irk = ir_irk;
}
}
#endif /* CONFIG_BT_PRIVACY */
/* If true, `id_create` will randomize the IRK. */
if (!irk && IS_ENABLED(CONFIG_BT_PRIVACY)) {
/* `id_create` will not store the id when called before
* BT_DEV_READY. But since part of the id will be
* randomized, it needs to be stored.
*/
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
atomic_set_bit(bt_dev.flags, BT_DEV_STORE_ID);
}
}
bt_addr_copy(&addr.a, &addrs[i].bdaddr);
addr.type = BT_ADDR_LE_RANDOM;
err = id_create(i, &addr, irk);
if (err) {
return err;
if (IS_ENABLED(CONFIG_BT_PRIVACY) &&
!IS_ENABLED(CONFIG_BT_PRIVACY_RANDOMIZE_IR)) {
if (!bt_smp_irk_get(addrs[i].ir, ir_irk)) {
irk = ir_irk;
}
}
/* If true, `id_create` will randomize the IRK. */
if (!irk && IS_ENABLED(CONFIG_BT_PRIVACY)) {
/* `id_create` will not store the id when called before
* BT_DEV_READY. But since part of the id will be
* randomized, it needs to be stored.
*/
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
atomic_set_bit(bt_dev.flags, BT_DEV_STORE_ID);
}
}
bt_addr_copy(&addr.a, &addrs[i].bdaddr);
addr.type = BT_ADDR_LE_RANDOM;
err = id_create(i, &addr, irk);
if (err) {
return err;
}
}
if (bt_dev.id_count > 0) {
return 0;
}
}
#endif /* defined(CONFIG_BT_HCI_VS) || defined(CONFIG_BT_CTLR) */
if (IS_ENABLED(CONFIG_BT_PRIVACY) && IS_ENABLED(CONFIG_BT_SETTINGS)) {
atomic_set_bit(bt_dev.flags, BT_DEV_STORE_ID);

View file

@ -50,7 +50,7 @@ ZTEST_SUITE(bt_setup_random_id_addr_bt_settings_enabled, NULL, NULL, tc_setup, N
* Test reading controller static random address fails and no attempt to store settings.
*
* Constraints:
* - bt_read_static_addr() returns zero
* - vs_read_static_addr() returns zero
*
* Expected behaviour:
* - ID count is set to 0 and bt_setup_random_id_addr() returns a negative error code
@ -60,7 +60,7 @@ ZTEST(bt_setup_random_id_addr_bt_settings_enabled, test_bt_read_static_addr_retu
{
int err;
/* This will force bt_read_static_addr() to fail */
/* This will force vs_read_static_addr() to fail */
bt_hci_cmd_send_sync_fake.return_val = 1;
err = bt_setup_random_id_addr();