Bluetooth: Don't update random address unnecessarily

If the wanted address is already programmed to the controller there's
no need to send a HCI command to change it.

Change-Id: Ib73d09cc5b20cd6820e603f0828f000f8310a89e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-04-04 20:56:45 +03:00
commit 499b44201b

View file

@ -387,6 +387,11 @@ static int set_random_address(const bt_addr_t *addr)
{
struct net_buf *buf;
/* Do nothing if we already have the right address */
if (!bt_addr_cmp(addr, &bt_dev.random_addr.a)) {
return 0;
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(*addr));
if (!buf) {
return -ENOBUFS;
@ -476,6 +481,13 @@ static int hci_le_create_conn(const struct bt_conn *conn)
struct net_buf *buf;
struct bt_hci_cp_le_create_conn *cp;
if (conn->le.init_addr.type == BT_ADDR_LE_RANDOM &&
bt_addr_le_cmp(&conn->le.init_addr, &bt_dev.random_addr)) {
if (set_random_address(&conn->le.init_addr.a)) {
return -EIO;
}
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_CREATE_CONN, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
@ -488,12 +500,6 @@ static int hci_le_create_conn(const struct bt_conn *conn)
cp->scan_interval = sys_cpu_to_le16(BT_GAP_SCAN_FAST_INTERVAL);
cp->scan_window = cp->scan_interval;
if (conn->le.init_addr.type == BT_ADDR_LE_RANDOM) {
if (set_random_address(&conn->le.init_addr.a)) {
return -EIO;
}
}
bt_addr_le_copy(&cp->peer_addr, &conn->le.resp_addr);
cp->own_addr_type = conn->le.init_addr.type;
cp->conn_interval_min = sys_cpu_to_le16(conn->le.interval_min);