|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Sean Kyer |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_ANS_H_ |
| 8 | +#define ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_ANS_H_ |
| 9 | + |
| 10 | +/** |
| 11 | + * @brief Alert Notification Service (ANS) |
| 12 | + * @defgroup bt_ans Alert Notification Service (ANS) |
| 13 | + * |
| 14 | + * @since 4.3 |
| 15 | + * @version 0.1.0 |
| 16 | + * |
| 17 | + * @ingroup bluetooth |
| 18 | + * @{ |
| 19 | + */ |
| 20 | + |
| 21 | +#include <stdint.h> |
| 22 | + |
| 23 | +#ifdef __cplusplus |
| 24 | +extern "C" { |
| 25 | +#endif |
| 26 | + |
| 27 | +/** |
| 28 | + * @brief Command not supported error code |
| 29 | + */ |
| 30 | +#define BT_ANS_ERR_CMD_NOT_SUP 0xa0 |
| 31 | + |
| 32 | +/** |
| 33 | + * @brief ANS max text string size in octets |
| 34 | + * |
| 35 | + * This is the max string size in octets to be saved in a New Alert. Text longer than the max is |
| 36 | + * truncated. |
| 37 | + * |
| 38 | + * section 3.165 of |
| 39 | + * https://btprodspecificationrefs.blob.core.windows.net/gatt-specification-supplement/GATT_Specification_Supplement.pdf |
| 40 | + * |
| 41 | + */ |
| 42 | +#define BT_ANS_MAX_TEXT_STR_SIZE 18 |
| 43 | + |
| 44 | +/** |
| 45 | + * @brief ANS Category ID Enum |
| 46 | + * |
| 47 | + * Enumeration for whether the category is supported. |
| 48 | + */ |
| 49 | +enum bt_ans_cat { |
| 50 | + BT_ANS_CAT_SIMPLE_ALERT, /**< Simple alerts (general notifications). */ |
| 51 | + BT_ANS_CAT_EMAIL, /**< Email messages. */ |
| 52 | + BT_ANS_CAT_NEWS, /**< News updates. */ |
| 53 | + BT_ANS_CAT_CALL, /**< Incoming call alerts. */ |
| 54 | + BT_ANS_CAT_MISSED_CALL, /**< Missed call alerts. */ |
| 55 | + BT_ANS_CAT_SMS_MMS, /**< SMS/MMS text messages. */ |
| 56 | + BT_ANS_CAT_VOICE_MAIL, /**< Voicemail notifications. */ |
| 57 | + BT_ANS_CAT_SCHEDULE, /**< Calendar or schedule alerts. */ |
| 58 | + BT_ANS_CAT_HIGH_PRI_ALERT, /**< High-priority alerts. */ |
| 59 | + BT_ANS_CAT_INSTANT_MESSAGE, /**< Instant messaging alerts. */ |
| 60 | + |
| 61 | + BT_ANS_CAT_NUM, /**< Marker for the number of categories. */ |
| 62 | + |
| 63 | + /* 10–15 reserved for future use */ |
| 64 | +}; |
| 65 | + |
| 66 | +/** |
| 67 | + * @brief Set the support for a given new alert category |
| 68 | + * |
| 69 | + * @param mask The bitmask of supported categories |
| 70 | + * |
| 71 | + * @return 0 on success |
| 72 | + * @return negative error codes on failure |
| 73 | + */ |
| 74 | +int bt_ans_set_new_alert_support_category(uint16_t mask); |
| 75 | + |
| 76 | +/** |
| 77 | + * @brief Set the support for a given unread new alert category |
| 78 | + * |
| 79 | + * @param mask The bitmask of supported categories |
| 80 | + * |
| 81 | + * @return 0 on success |
| 82 | + * @return negative error codes on failure |
| 83 | + */ |
| 84 | +int bt_ans_set_unread_support_category(uint16_t mask); |
| 85 | + |
| 86 | +/** |
| 87 | + * @brief Send a new alert to remote devices |
| 88 | + * |
| 89 | + * The new alert is transmitted to the remote devices if notifications are enabled. Each category |
| 90 | + * will save the latest call to this function in case an immediate replay is requested via the ANS |
| 91 | + * control point. |
| 92 | + * |
| 93 | + * @note This function waits on a Mutex with @ref K_FOREVER to ensure atomic updates to notification |
| 94 | + * structs. To avoid deadlocks, do not call this function in BT RX or System Workqueue threads. |
| 95 | + * |
| 96 | + * @param conn The connection object to send the alert to |
| 97 | + * @param category The category the notification is for |
| 98 | + * @param num_new Number of new alerts since last alert |
| 99 | + * @param text Text brief of alert, null terminated |
| 100 | + * |
| 101 | + * @return 0 on success |
| 102 | + * @return negative error codes on failure |
| 103 | + */ |
| 104 | +int bt_ans_notify_new_alert(struct bt_conn *conn, enum bt_ans_cat category, uint8_t num_new, |
| 105 | + const char *text); |
| 106 | + |
| 107 | +/** |
| 108 | + * @brief Set the total unread count for a given category |
| 109 | + * |
| 110 | + * The unread count is transmitted to the remote devices if notifications are enabled. Each category |
| 111 | + * will save the latest call to this function in case an immediate replay is requested via the ANS |
| 112 | + * control point. |
| 113 | + * |
| 114 | + * @note This function waits on a Mutex with @ref K_FOREVER to ensure atomic updates to notification |
| 115 | + * structs. To avoid deadlocks, do not call this function in BT RX or System Workqueue threads. |
| 116 | + * |
| 117 | + * @param conn The connection object to send the alert to |
| 118 | + * @param category The category the unread count is for |
| 119 | + * @param unread Total number of unread alerts |
| 120 | + * |
| 121 | + * @return 0 on success |
| 122 | + * @return negative error codes on failure |
| 123 | + */ |
| 124 | +int bt_ans_set_unread_count(struct bt_conn *conn, enum bt_ans_cat category, uint8_t unread); |
| 125 | + |
| 126 | +#ifdef __cplusplus |
| 127 | +} |
| 128 | +#endif |
| 129 | + |
| 130 | +/** |
| 131 | + * @} |
| 132 | + */ |
| 133 | + |
| 134 | +#endif /* ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_BT_ANS_H_ */ |
0 commit comments