Skip to content

Commit 99f9e74

Browse files
committed
Bugfix - Characteristic onRead callback not called.
Fixes detection of the original read request vs a followup read for characteristic values greater than MTU - 3.
1 parent 62180ab commit 99f9e74

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/NimBLEServer.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,10 @@ int NimBLEServer::handleGattEvent(uint16_t connHandle, uint16_t attrHandle, ble_
620620
switch (ctxt->op) {
621621
case BLE_GATT_ACCESS_OP_READ_DSC:
622622
case BLE_GATT_ACCESS_OP_READ_CHR: {
623-
// Don't call readEvent if this is an internal read (handle is NONE)
624-
if (connHandle != BLE_HS_CONN_HANDLE_NONE) {
625-
// If the packet header is only 8 bytes then this is a follow up of a long read
626-
// so we don't want to call the onRead() callback again.
627-
if (ctxt->om->om_pkthdr_len > 8 || val.size() <= (ble_att_mtu(connHandle) - 3)) {
628-
pAtt->readEvent(peerInfo);
629-
}
623+
// Don't call readEvent if the buffer len is 0 (this is a follow up to a previous read),
624+
// or if this is an internal read (handle is NONE)
625+
if (ctxt->om->om_len > 0 && connHandle != BLE_HS_CONN_HANDLE_NONE) {
626+
pAtt->readEvent(peerInfo);
630627
}
631628

632629
ble_npl_hw_enter_critical();

0 commit comments

Comments
 (0)