Skip to content

Commit 3580adf

Browse files
committed
Implement bt_gatt_cb_unregister method for sys_slist_find_and_remove.
New API bt_gatt_cb_unregister, use _SAFE iteration for callback list. Signed-off-by: Zhijie Zhong <zhongzhijie1@xiaomi.com>
1 parent 8b2c75a commit 3580adf

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

doc/releases/release-notes-4.4.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ Deprecated APIs and options
5656
New APIs and options
5757
====================
5858

59+
* Bluetooth
60+
61+
* Host
62+
63+
* :c:func:`bt_gatt_cb_unregister` Added an API to unregister GATT callback handlers.
64+
5965
..
6066
Link to new APIs here, in a group if you think it's necessary, no need to get
6167
fancy just list the link, that should contain the documentation. If you feel

include/zephyr/bluetooth/gatt.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,17 @@ static inline const char *bt_gatt_err_to_str(int gatt_err)
622622
*/
623623
void bt_gatt_cb_register(struct bt_gatt_cb *cb);
624624

625+
/** @brief Unregister GATT callbacks.
626+
*
627+
* Unregister callbacks for monitoring the state of GATT. The callback
628+
* struct should be one that was previously registered.
629+
*
630+
* @param cb Callback struct.
631+
*
632+
* @return 0 in case of success or negative value in case of error.
633+
*/
634+
int bt_gatt_cb_unregister(struct bt_gatt_cb *cb);
635+
625636
/** @brief Register GATT authorization callbacks.
626637
*
627638
* Register callbacks to perform application-specific authorization of GATT

subsys/bluetooth/host/gatt.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,19 @@ void bt_gatt_cb_register(struct bt_gatt_cb *cb)
16281628
sys_slist_append(&callback_list, &cb->node);
16291629
}
16301630

1631+
int bt_gatt_cb_unregister(struct bt_gatt_cb *cb)
1632+
{
1633+
if (cb == NULL) {
1634+
return -EINVAL;
1635+
}
1636+
1637+
if (!sys_slist_find_and_remove(&callback_list, &cb->node)) {
1638+
return -ENOENT;
1639+
}
1640+
1641+
return 0;
1642+
}
1643+
16311644
#if defined(CONFIG_BT_GATT_DYNAMIC_DB)
16321645
static void db_changed(void)
16331646
{
@@ -6023,9 +6036,9 @@ void bt_gatt_connected(struct bt_conn *conn)
60236036

60246037
void bt_gatt_att_max_mtu_changed(struct bt_conn *conn, uint16_t tx, uint16_t rx)
60256038
{
6026-
struct bt_gatt_cb *cb;
6039+
struct bt_gatt_cb *cb, *tmp;
60276040

6028-
SYS_SLIST_FOR_EACH_CONTAINER(&callback_list, cb, node) {
6041+
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&callback_list, cb, tmp, node) {
60296042
if (cb->att_mtu_updated) {
60306043
cb->att_mtu_updated(conn, tx, rx);
60316044
}

0 commit comments

Comments
 (0)