Skip to content

Conversation

seankyer
Copy link
Member

@seankyer seankyer commented Sep 6, 2025

Add alert notification service (ANS) to Bluetooth subsystem and accompanying sample.

Based on spec described in https://www.bluetooth.com/specifications/specs/alert-notification-service-1-0/ with bitfields taken from https://btprodspecificationrefs.blob.core.windows.net/gatt-specification-supplement/GATT_Specification_Supplement.pdf.

To interact with this sample, download a BLE app like ADI Attach or nRF connect. Once you subscribe to the unread alert and new alert notification characteristics, you need to send a "write" to the Alert Notification Control Point characteristic to enable the categories you would like to be notified on.

In the basic example you would send: [0,0] and [1,0] to the control point and once you have subscribed to notifications you will then start receiving the messages. Further commands are explained in https://btprodspecificationrefs.blob.core.windows.net/gatt-specification-supplement/GATT_Specification_Supplement.pdf section 3.12.

It is the responsibility of the app to interpret whatever a 'new notification' or 'unread notification' is and use the APIs to update them accordingly. The service must save the most recent value for each enabled category in case the control point sends the 'immediate' request, which relays the most up to date values for the specified category.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the Alert Notification Service (ANS) for Bluetooth subsystem, enabling devices to send alert notifications to connected BLE clients. The implementation follows the Bluetooth ANS 1.0 specification and includes support for both new alert and unread alert notifications across multiple categories.

  • Implements complete ANS service with support for 10 alert categories (simple alert, email, news, call, etc.)
  • Adds configurable category support through Kconfig options for both new and unread alert types
  • Includes a sample application demonstrating ANS usage with periodic alert notifications

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
subsys/bluetooth/services/ans.c Core ANS service implementation with GATT characteristics and API functions
subsys/bluetooth/services/Kconfig.ans Configuration options for enabling specific alert categories
subsys/bluetooth/services/Kconfig Integration of ANS Kconfig into main services menu
subsys/bluetooth/services/CMakeLists.txt Build system integration for ANS service
samples/bluetooth/peripheral_ans/src/main.c Sample application demonstrating ANS usage
samples/bluetooth/peripheral_ans/sample.yaml Test configuration for sample application
samples/bluetooth/peripheral_ans/prj.conf Project configuration for sample
samples/bluetooth/peripheral_ans/README.rst Documentation for sample usage
samples/bluetooth/peripheral_ans/CMakeLists.txt Build configuration for sample
include/zephyr/bluetooth/services/ans.h Public API header for ANS service
include/zephyr/bluetooth/att.h Addition of BT_ATT_ERR_CMD_NOT_SUP error code

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR - It's overall good quality, and most of my comments are related some potential missing features or Zephyr specific formatting or coding guidelines

@zephyrbot zephyrbot added the Release Notes To be mentioned in the release notes label Sep 6, 2025
@zephyrbot zephyrbot requested a review from cfriedt September 6, 2025 20:16
@seankyer seankyer force-pushed the feat/bt-ans branch 2 times, most recently from ff12748 to 47ddfac Compare September 6, 2025 20:58
@seankyer
Copy link
Member Author

seankyer commented Sep 6, 2025

Thanks for the review. I replied to a few comments and applied your suggestions.

I also refactored the transmit functions since they got too nested.

Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things that I think needs to be fixed :)

@seankyer seankyer force-pushed the feat/bt-ans branch 4 times, most recently from 9d85235 to 2b3c021 Compare September 27, 2025 19:23
Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments, but otherwise LGTM.

Please also have a look at the issues reported by Sonar

}
k_sleep(K_SECONDS(1));

ret = bt_ans_set_unread_count(NULL, BT_ANS_CAT_SIMPLE_ALERT, ++num_unread);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_unread can overflow here, can't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this and #95578 (comment) it will overflow and loop back around to 0 (essentially restarting the sample). I thought this was fine for the sample. I'll add a comment to the static declaration of the variables however stating this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's fine to overflow, but ideally we explicitly state this to avoid any confusion :)

@Thalley Thalley requested a review from Copilot September 29, 2025 08:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@seankyer seankyer force-pushed the feat/bt-ans branch 2 times, most recently from 7afa20c to 728b1e5 Compare September 30, 2025 10:28
Thalley
Thalley previously approved these changes Sep 30, 2025
Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good for now - The spec itself is too unclear about how to handle multiple connections, so that part is still somewhat unclear in the implementation as well.

It would have been nice with some testing of this service, but that would also require a client implementation

@Thalley
Copy link
Contributor

Thalley commented Sep 30, 2025

CI issue not related to this PR; see #96787

@seankyer
Copy link
Member Author

Just rebased

@seankyer
Copy link
Member Author

seankyer commented Oct 1, 2025

@jhedberg or @alwa-nordic could you review when you have a chance? Thanks

@jhedberg jhedberg assigned Thalley and unassigned jhedberg and alwa-nordic Oct 14, 2025
Comment on lines +7 to +8
menuconfig BT_ANS
bool "GATT Alert Notification Service"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add " [EXPERIMENTAL]" to the end of the description to align with select EXPERIMENTAL

Comment on lines +52 to +76
menu "Unread Alert Categories"

config BT_ANS_UNALRT_CAT_SIMPLE_ALERT
bool "Support Simple Alert"

config BT_ANS_UNALRT_CAT_EMAIL
bool "Support Email"

config BT_ANS_UNALRT_CAT_NEWS
bool "Support News"

config BT_ANS_UNALRT_CAT_CALL
bool "Support Call"

config BT_ANS_UNALRT_CAT_MISSED_CALL
bool "Support Missed Call"

config BT_ANS_UNALRT_CAT_SMS_MMS
bool "Support SMS/MMS"

config BT_ANS_UNALRT_CAT_VOICE_MAIL
bool "Support Voice Mail"

config BT_ANS_UNALRT_CAT_SCHEDULE
bool "Support Schedule"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels slightly overkill to have Kconfig options for these. Did you consider having the app provide them when initializing ANS? I suppose one core reason may be that our stack-internal services don't (generally?) public exposed initialization APIs, so as soon as you need some parametrization you end up having to do this through Kconfig even though Kconfig might not otherwise be the most intuitive tool for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we did discuss it here: #95578 (comment).
To recap, I do agree, but I think since the service requires that at least one topic be enabled at all times, that it may warrant the use of the Kconfig to initially set the bitmaps.

Add alert notification service (ANS) to Bluetooth
subsystem and accompanying sample.

Signed-off-by: Sean Kyer <[email protected]>
Add Alert Notification Service (ANS) and enabling Kconfig
to 4.3 release notes.

Signed-off-by: Sean Kyer <[email protected]>
@seankyer
Copy link
Member Author

@Thalley @kartben @jhedberg I pushed updates based on the recent feedback, please re-up/re-review when you get the chance. Thanks you.

@seankyer seankyer requested a review from Thalley October 19, 2025 10:32
Copy link

Copy link
Contributor

@kartben kartben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for docs / sample, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth area: Samples Samples Release Notes To be mentioned in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants