Bluetooth: Fix bt_conn_lookup*
bt_conn_lookup shall work both with identity address or initial destination address as bt_conn may change the destination address with the identity address. Change-Id: Ibdd19ec453c3307eb6db188196b7e57a2260b526 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
a4b6b2417d
commit
ae213a2ea8
2 changed files with 20 additions and 2 deletions
|
@ -1204,6 +1204,21 @@ struct bt_conn *bt_conn_lookup_handle(uint16_t handle)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bt_conn_addr_le_cmp(const struct bt_conn *conn, const bt_addr_le_t *peer)
|
||||||
|
{
|
||||||
|
/* Check against conn dst address as it may be the identity address */
|
||||||
|
if (!bt_addr_le_cmp(peer, &conn->le.dst)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check against initial connection address */
|
||||||
|
if (conn->role == BT_HCI_ROLE_MASTER) {
|
||||||
|
return bt_addr_le_cmp(peer, &conn->le.resp_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bt_addr_le_cmp(peer, &conn->le.init_addr);
|
||||||
|
}
|
||||||
|
|
||||||
struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer)
|
struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -1217,7 +1232,7 @@ struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bt_addr_le_cmp(peer, &conns[i].le.dst)) {
|
if (!bt_conn_addr_le_cmp(&conns[i], peer)) {
|
||||||
return bt_conn_ref(&conns[i]);
|
return bt_conn_ref(&conns[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1239,7 +1254,7 @@ struct bt_conn *bt_conn_lookup_state_le(const bt_addr_le_t *peer,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peer && bt_addr_le_cmp(peer, &conns[i].le.dst)) {
|
if (peer && bt_conn_addr_le_cmp(&conns[i], peer)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,9 @@ void bt_conn_disconnect_all(void);
|
||||||
/* Look up an existing connection */
|
/* Look up an existing connection */
|
||||||
struct bt_conn *bt_conn_lookup_handle(uint16_t handle);
|
struct bt_conn *bt_conn_lookup_handle(uint16_t handle);
|
||||||
|
|
||||||
|
/* Compare an address with bt_conn destination address */
|
||||||
|
int bt_conn_addr_le_cmp(const struct bt_conn *conn, const bt_addr_le_t *peer);
|
||||||
|
|
||||||
/* Look up a connection state. For BT_ADDR_LE_ANY, returns the first connection
|
/* Look up a connection state. For BT_ADDR_LE_ANY, returns the first connection
|
||||||
* with the specific state
|
* with the specific state
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue