Bluetooth: Ignore completed packets events for unknown connections

Some controllers are broken in that they may send a completed packets
event after a disconnection has already occurred and the handle is
invalid:

> HCI Event: Disconnect Complete (0x05) plen 4
        Status: Success (0x00)
        Handle: 64
        Reason: Remote User Terminated Connection (0x13)
< HCI Command: LE Set Advert.. (0x08|0x000a) plen 1
        Advertising: Enabled (0x01)
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Advertise Enable (0x08|0x000a) ncmd 1
        Status: Success (0x00)
> HCI Event: Number of Completed Pa.. (0x13) plen 5
        Num handles: 1
        Handle: 64
        Count: 1

Since the disconnection code already takes care of updating the
le_pkts_sem semaphore appropriately there is no need to do anything
for this kind of events (except log a warning of a misbehaving
controller).

Change-Id: I67b35aa50f7297d6bcdeeeab62f1f1d224b1a372
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-09-17 11:22:00 +03:00 committed by Anas Nashif
commit 6f580e363b

View file

@ -488,19 +488,21 @@ static void hci_num_completed_packets(struct bt_buf *buf)
BT_DBG("handle %u count %u\n", handle, count);
conn = bt_conn_lookup_handle(handle);
if (conn) {
if (conn->pending_pkts >= count) {
conn->pending_pkts -= count;
} else {
BT_ERR("completed packets mismatch: %u > %u\n",
count, conn->pending_pkts);
conn->pending_pkts = 0;
}
bt_conn_put(conn);
} else {
BT_ERR("No matching connection for handle %u", handle);
if (!conn) {
BT_ERR("No connection for handle %u\n", handle);
continue;
}
if (conn->pending_pkts >= count) {
conn->pending_pkts -= count;
} else {
BT_ERR("completed packets mismatch: %u > %u\n",
count, conn->pending_pkts);
conn->pending_pkts = 0;
}
bt_conn_put(conn);
while (count--) {
nano_fiber_sem_give(&bt_dev.le_pkts_sem);
}