From 7400a89196d1ac2fc2d14108a64ffa9f00e92a66 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Fri, 26 Jun 2026 20:23:28 +0800 Subject: [PATCH] fix(ble/bluedroid): preserve ATT error on prepare write completion Skip prepare-write echo validation when the GATT stack reports a non-success status. ATT Error Response carries no prepare-write echo body (rsp_len=0), so the check incorrectly overwrote errors such as GATT_INSUF_AUTHENTICATION (0x05) with GATT_INVALID_PDU (0x04). (cherry picked from commit d5b9350d0fa2b74ea8810874163e972663d45fb2) Co-authored-by: zhanghaipeng --- components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c index 1b17e58622a..2fcf2bdcb8e 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c @@ -1486,8 +1486,9 @@ void bta_gattc_write_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data) ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_PREP_WRITE_EVT, (tBTA_GATTC *)&cb_data); return; } - /* Rsp value is one ATT chunk (<= MTU-5), not necessarily full api_write.len. */ - { + /* Rsp value is one ATT chunk (<= MTU-5), not necessarily full api_write.len. + * Only validate echo on success; ATT Error Response has no prepare-write body. */ + if (p_data->status == BTA_GATT_OK) { UINT16 rsp_len = p_data->p_cmpl->att_value.len; UINT16 req_len = p_clcb->p_q_cmd->api_write.len; tGATT_VALUE *a = &p_data->p_cmpl->att_value;