From 41fce7212a904f03359f4c142d0351151503fe8e Mon Sep 17 00:00:00 2001 From: 94xhn <87560781+94xhn@users.noreply.github.com> Date: Sun, 12 Jul 2026 22:07:17 +0800 Subject: [PATCH] services/ans: Fix category 0 skipped by immediate-notify-all command The Alert Notification Service control point handler for BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE and BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE loops over all supported categories when the peer writes cat_id == 0xff ("all categories"): for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) { if ((ble_svc_ans_new_alert_cat >> i) & 0x01) { ble_svc_ans_new_alert_notify(i, NULL); } } The loop condition `i > 0` stops before `i` reaches 0, so category ID 0 (BLE_SVC_ANS_CAT_ID_SIMPLE_ALERT, "Simple Alert") is never notified by this path, even when it is enabled and has a pending alert. If Simple Alert is the only category the peer has enabled, a 0xff immediate-notify request results in zero notifications being sent. Change the bound to `i >= 0` so category 0 is included, matching the same fix in both the new-alert and unread-alert-status branches. Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com> --- nimble/host/services/ans/src/ble_svc_ans.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nimble/host/services/ans/src/ble_svc_ans.c b/nimble/host/services/ans/src/ble_svc_ans.c index edaf7f3c12..eb6e26099f 100644 --- a/nimble/host/services/ans/src/ble_svc_ans.c +++ b/nimble/host/services/ans/src/ble_svc_ans.c @@ -247,7 +247,7 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle, case BLE_SVC_ANS_CMD_NOT_NEW_ALERT_IMMEDIATE: if (cat_id == 0xff) { /* If cat_id is 0xff, notify on all enabled categories */ - for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) { + for (i = BLE_SVC_ANS_CAT_NUM - 1; i >= 0; --i) { if ((ble_svc_ans_new_alert_cat >> i) & 0x01) { ble_svc_ans_new_alert_notify(i, NULL); } @@ -259,7 +259,7 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle, case BLE_SVC_ANS_CMD_NOT_UNR_ALERT_IMMEDIATE: if (cat_id == 0xff) { /* If cat_id is 0xff, notify on all enabled categories */ - for (i = BLE_SVC_ANS_CAT_NUM - 1; i > 0; --i) { + for (i = BLE_SVC_ANS_CAT_NUM - 1; i >= 0; --i) { if ((ble_svc_ans_unr_alert_cat >> i) & 0x01) { ble_svc_ans_unr_alert_notify(i); }