fix(nimble): Send Prepare Write Request before Execute Write in write long with zero-length data

This commit is contained in:
Shreeyash Bhakare
2026-09-11 14:51:31 +05:30
parent c409049a82
commit 71a1fd7bfd
+34
View File
@@ -4901,6 +4901,21 @@ ble_gattc_write_long_tx(struct ble_gattc_proc *proc)
proc->write_long.attr.offset);
if (write_len <= 0) {
if (proc->write_long.attr.offset == 0 &&
OS_MBUF_PKTLEN(proc->write_long.attr.om) == 0) {
proc->write_long.length = 0;
om = ble_hs_mbuf_att_pkt();
if (om == NULL) {
rc = BLE_HS_ENOMEM;
goto done;
}
rc = ble_att_clt_tx_prep_write(proc->conn_handle, proc->cid,
proc->write_long.attr.handle,
proc->write_long.attr.offset,
om);
om = NULL;
goto done;
}
rc = ble_att_clt_tx_exec_write(proc->conn_handle, proc->cid,
BLE_ATT_EXEC_WRITE_F_EXECUTE);
goto done;
@@ -5009,6 +5024,25 @@ ble_gattc_write_long_rx_prep(struct ble_gattc_proc *proc,
if (proc->write_long.attr.offset >=
OS_MBUF_PKTLEN(proc->write_long.attr.om)) {
if (OS_MBUF_PKTLEN(proc->write_long.attr.om) == 0 &&
proc->write_long.attr.offset == 0 &&
proc->write_long.length == 0) {
if (handle != proc->write_long.attr.handle) {
rc = BLE_HS_EBADDATA;
goto err;
}
if (offset != proc->write_long.attr.offset) {
rc = BLE_HS_EBADDATA;
goto err;
}
rc = ble_att_clt_tx_exec_write(proc->conn_handle, proc->cid,
BLE_ATT_EXEC_WRITE_F_EXECUTE);
if (rc != 0) {
goto err;
}
return 0;
}
/* Expecting a prepare write response, not an execute write
* response.
*/