diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index bbff26b535..e4a048e3d3 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -608,7 +608,9 @@ static int characteristic_access_cb(uint16_t conn_handle, uint16_t value_handle, return BLE_ATT_ERR_ATTR_NOT_FOUND; } - os_mbuf_append(ctxt->om, entry->data, entry->data_len); + if (os_mbuf_append(ctxt->om, entry->data, entry->data_len)) { + return BLE_ATT_ERR_INSUFFICIENT_RES; + } return 0; case BLE_GATT_ACCESS_OP_WRITE_CHR: @@ -625,6 +627,8 @@ static int characteristic_access_cb(uint16_t conn_handle, uint16_t value_handle, entry->data_len = MIN(entry->data_alloc, OS_MBUF_PKTLEN(ctxt->om) + offset); os_mbuf_copydata(ctxt->om, 0, entry->data_len - offset, entry->data + offset); + // TODO: Consider failing with BLE_ATT_ERR_INSUFFICIENT_RES if the buffer is full. + mp_bluetooth_gatts_on_write(conn_handle, value_handle); return 0;