Bugfix - Characteristic onRead callback not called.

Fixes detection of the original read request vs a followup read for characteristic values greater than MTU - 3.
This commit is contained in:
h2zero
2025-03-14 10:57:55 -06:00
parent 723cdf0a66
commit 9ce2eec0cb

View File

@ -620,13 +620,10 @@ int NimBLEServer::handleGattEvent(uint16_t connHandle, uint16_t attrHandle, ble_
switch (ctxt->op) { switch (ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_DSC: case BLE_GATT_ACCESS_OP_READ_DSC:
case BLE_GATT_ACCESS_OP_READ_CHR: { case BLE_GATT_ACCESS_OP_READ_CHR: {
// Don't call readEvent if this is an internal read (handle is NONE) // Don't call readEvent if the buffer len is 0 (this is a follow up to a previous read),
if (connHandle != BLE_HS_CONN_HANDLE_NONE) { // or if this is an internal read (handle is NONE)
// If the packet header is only 8 bytes then this is a follow up of a long read if (ctxt->om->om_len > 0 && connHandle != BLE_HS_CONN_HANDLE_NONE) {
// so we don't want to call the onRead() callback again. pAtt->readEvent(peerInfo);
if (ctxt->om->om_pkthdr_len > 8 || val.size() <= (ble_att_mtu(connHandle) - 3)) {
pAtt->readEvent(peerInfo);
}
} }
ble_npl_hw_enter_critical(); ble_npl_hw_enter_critical();