From c7907994920aa8cea9e2d80fa6d4dd36ff6fe99b Mon Sep 17 00:00:00 2001 From: Shuai Wang Date: Fri, 26 Jun 2026 09:56:12 +0800 Subject: [PATCH] fix(nimble): initialize return value in LED characteristic access callback When the NimBLE stack called this callback for a GATT Write Request, the uninitialized stack value was interpreted as a non-zero GATT error code, causing the stack to send BLE_ATT_ERR_UNLIKELY (0x0E) back to the client. --- .../ble_get_started/nimble/NimBLE_GATT_Server/README.md | 5 +---- .../nimble/NimBLE_GATT_Server/main/src/gatt_svc.c | 5 +---- .../nimble/NimBLE_Security/main/src/gatt_svc.c | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server/README.md b/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server/README.md index 9be317a527c..37442fa97f0 100644 --- a/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server/README.md +++ b/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server/README.md @@ -169,9 +169,6 @@ The characteristic is binded with `led_chr_access` callback function, in which t ``` C static int led_chr_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { - /* Local variables */ - int rc; - /* Handle access events */ /* Note: LED characteristic is write only */ switch (ctxt->op) { @@ -203,7 +200,7 @@ static int led_chr_access(uint16_t conn_handle, uint16_t attr_handle, } else { goto error; } - return rc; + return 0; } goto error; diff --git a/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server/main/src/gatt_svc.c b/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server/main/src/gatt_svc.c index 4e521e348b5..bf03d4023f4 100644 --- a/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server/main/src/gatt_svc.c +++ b/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server/main/src/gatt_svc.c @@ -114,9 +114,6 @@ error: static int led_chr_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { - /* Local variables */ - int rc = 0; - /* Handle access events */ /* Note: LED characteristic is write only */ switch (ctxt->op) { @@ -148,7 +145,7 @@ static int led_chr_access(uint16_t conn_handle, uint16_t attr_handle, } else { goto error; } - return rc; + return 0; } goto error; diff --git a/examples/bluetooth/ble_get_started/nimble/NimBLE_Security/main/src/gatt_svc.c b/examples/bluetooth/ble_get_started/nimble/NimBLE_Security/main/src/gatt_svc.c index d819be8e5be..726a4f2bb60 100644 --- a/examples/bluetooth/ble_get_started/nimble/NimBLE_Security/main/src/gatt_svc.c +++ b/examples/bluetooth/ble_get_started/nimble/NimBLE_Security/main/src/gatt_svc.c @@ -117,9 +117,6 @@ error: static int led_chr_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { - /* Local variables */ - int rc = 0; - /* Handle access events */ /* Note: LED characteristic is write only */ switch (ctxt->op) { @@ -151,7 +148,7 @@ static int led_chr_access(uint16_t conn_handle, uint16_t attr_handle, } else { goto error; } - return rc; + return 0; } goto error;