diff options
author | Sven Gothel <[email protected]> | 2020-05-31 05:21:54 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-31 05:21:54 +0200 |
commit | 7850f58d81c2262cc52baa72cf05de7e24a73588 (patch) | |
tree | f318a9ccab0cb269a7c57c14e177152b8af94b26 /src/direct_bt/HCIComm.cpp | |
parent | dc43013a6df42ca425386520cbc40065ba1c3a43 (diff) |
Differentiate disconnect w/ IO-Error, i.e. DBTDevice shall not issue HCI nor Mgmt disconnect (device gone)
It has shown that the extreme 6-9s delay in forced disconnect (device shutdown)
is caused by the HCI and Mgmt disconnect command. Both fail, always.
Hence, in case of a GATT send error or short read-reply timeout (ringbuffer.getBlocking(500ms))
we can cleanup the device w/o explicit disconnect command.
+++
The usual disconnect signal from a device forced shutdown is as follows:
L2CAP send or GATT read-reply -> Device -> HCI(1) + Mgmt(2)
(1) HCI disconnect skipped if IO-Error
(2) Mgmt disconnect skipped if IO-Error, but sends DISCONNECT event
+++
Mgmt and GATTHandler also differentiate timeouts,
lenghthly 3s for the ringbuffer read w/o any impact and 1s (mgmt) or 500ms (gatt) for command replies
on the user thread.
This leads to fast DISCONNECT events for the user and actual device cleanup.
Subsequent connection works w/o issues.
If using HCI connect via discovery (not whitelist),
the turnaround time from forced disconnect to next connect is below 1s.
However, using whitelist, the subsequent connect after the forced disconnect
consumes 'a few seconds' and hence is seemingly not suitable for a responsive system (???).
The latter is true with or without Mgmt disconnect attempts!
Misc:
- L2CAPComm disconnect: Show potention pthread_kill error
- HCIComm send_req/send: Refine ERR_PRINT, remove unsused case HCI_EV_REMOTE_NAME
Diffstat (limited to 'src/direct_bt/HCIComm.cpp')
-rw-r--r-- | src/direct_bt/HCIComm.cpp | 27 |
1 files changed, 2 insertions, 25 deletions
diff --git a/src/direct_bt/HCIComm.cpp b/src/direct_bt/HCIComm.cpp index d82bba5e..0a2b2618 100644 --- a/src/direct_bt/HCIComm.cpp +++ b/src/direct_bt/HCIComm.cpp @@ -370,7 +370,7 @@ HCIErrorCode HCIComm::send_req(const uint16_t opcode, const void *command, const #else while ((n = poll(&p, 1, _timeoutMS)) < 0) { #endif - ERR_PRINT("hci_send_req: poll"); + ERR_PRINT("HCIComm::send_req(dev_id %d, channel %d): poll: res %d", dev_id, channel, n); if (errno == EAGAIN || errno == EINTR) { continue; } @@ -392,7 +392,7 @@ HCIErrorCode HCIComm::send_req(const uint16_t opcode, const void *command, const int len; while ((len = ::read(_dd, buf, sizeof(buf))) < 0) { - ERR_PRINT("hci_send_req: read: res %d", len); + ERR_PRINT("HCIComm::send_req(dev_id %d, channel %d): read: res %d", dev_id, channel, len); if (errno == EAGAIN || errno == EINTR) { continue; } @@ -456,29 +456,6 @@ HCIErrorCode HCIComm::send_req(const uint16_t opcode, const void *command, const rlen, bytesHexString((uint8_t*)ptr, 0, rlen, false /* lsbFirst */, true /* leading0X */).c_str()); goto done; } - case HCI_EV_REMOTE_NAME: { - DBG_PRINT("hci_send_req: HCI_EV_REMOTE_NAME: event 0x%X (equal %d), exp_event 0x%X, r-len %d/%d", - hdr->evt, exp_event, (hdr->evt == exp_event), response_len, len); - - if (hdr->evt != exp_event) { - continue; // next packet - } - - const hci_ev_remote_name *rn = static_cast<const hci_ev_remote_name *>(static_cast<const void *>( ptr )); - const hci_cp_remote_name_req *cp = static_cast<const hci_cp_remote_name_req *>(command); - - if ( rn->bdaddr != cp->bdaddr ) { - DBG_PRINT("hci_send_req: HCI_EV_REMOTE_NAME: address mismatch: cmd %s != req %s", - cp->bdaddr.toString().c_str(), rn->bdaddr.toString().c_str()); - continue; // next packet - } - - const int rlen = MIN(len, response_len); - memcpy(response, ptr, rlen); - DBG_PRINT("hci_send_req: HCI_EV_REMOTE_NAME: copied %d bytes: %s", - rlen, bytesHexString((uint8_t*)ptr, 0, rlen, false /* lsbFirst */, true /* leading0X */).c_str()); - goto done; - } case HCI_EV_LE_META: { const hci_ev_le_meta *me = static_cast<const hci_ev_le_meta *>(static_cast<const void *>( ptr )); |