Bluetooth: Fix bt_conn_lookup_addr_le and bt_conn_lookup_handle

bt_conn_lookup_addr_le shouldn't look for the state of the connection.
bt_conn_lookup_handle should return bt_conn only if there is a handle
so if connection is in state BT_CONN_CONNECTED or BT_CONN_DISCONNECT.

Change-Id: Id88361990913d17bdaffc686e5aa3edaeaaecc0a
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
This commit is contained in:
Mariusz Skamra 2015-06-24 14:39:14 +02:00 committed by Anas Nashif
commit 606c3701ab
3 changed files with 11 additions and 11 deletions

View file

@ -330,7 +330,11 @@ struct bt_conn *bt_conn_lookup_handle(uint16_t handle)
int i;
for (i = 0; i < ARRAY_SIZE(conns); i++) {
if (conns[i].state != BT_CONN_CONNECTED) {
switch (conns[i].state) {
case BT_CONN_CONNECTED:
case BT_CONN_DISCONNECT:
break;
default:
continue;
}
@ -347,10 +351,6 @@ struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer)
int i;
for (i = 0; i < ARRAY_SIZE(conns); i++) {
if (conns[i].state != BT_CONN_CONNECTED) {
continue;
}
if (!bt_addr_le_cmp(peer, &conns[i].dst)) {
return bt_conn_get(&conns[i]);
}

View file

@ -334,7 +334,7 @@ static uint8_t notify_cb(const struct bt_gatt_attr *attr, void *user_data)
}
conn = bt_conn_lookup_addr_le(&ccc->cfg[i].peer);
if (!conn) {
if (!conn || conn->state != BT_CONN_CONNECTED) {
continue;
}
@ -440,7 +440,7 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, void *user_data)
/* Skip if there is another peer connected */
tmp = bt_conn_lookup_addr_le(&ccc->cfg[i].peer);
if (tmp) {
if (tmp && tmp->state == BT_CONN_CONNECTED) {
bt_conn_put(tmp);
return BT_GATT_ITER_CONTINUE;
}

View file

@ -253,7 +253,7 @@ static void hci_acl(struct bt_buf *buf)
}
conn = bt_conn_lookup_handle(buf->acl.handle);
if (!conn) {
if (!conn || conn->state != BT_CONN_CONNECTED) {
BT_ERR("Unable to find conn for handle %u\n", buf->acl.handle);
bt_buf_put(buf);
return;
@ -392,7 +392,7 @@ static void hci_encrypt_change(struct bt_buf *buf)
}
conn = bt_conn_lookup_handle(handle);
if (!conn) {
if (!conn || conn->state != BT_CONN_CONNECTED) {
BT_ERR("Unable to look up conn with handle %u\n", handle);
return;
}
@ -540,7 +540,7 @@ static void hci_encrypt_key_refresh_complete(struct bt_buf *buf)
}
conn = bt_conn_lookup_handle(handle);
if (!conn) {
if (!conn || conn->state != BT_CONN_CONNECTED) {
BT_ERR("Unable to look up conn with handle %u\n", handle);
return;
}
@ -653,7 +653,7 @@ static void le_ltk_request(struct bt_buf *buf)
BT_DBG("handle %u\n", handle);
conn = bt_conn_lookup_handle(handle);
if (!conn) {
if (!conn || conn->state != BT_CONN_CONNECTED) {
BT_ERR("Unable to lookup conn for handle %u\n", handle);
return;
}