Skip to content

Commit 1027b0e

Browse files
anchaojhedberg
authored andcommitted
Bluetooth: host: add support for unregister scanner callback
This is a pairing function with bt_le_scan_cb_register() to used for remove the scanner callback from callback list. Signed-off-by: chao an <[email protected]>
1 parent bc7e86b commit 1027b0e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

include/bluetooth/bluetooth.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,15 @@ int bt_le_scan_stop(void);
17141714
*/
17151715
void bt_le_scan_cb_register(struct bt_le_scan_cb *cb);
17161716

1717+
/**
1718+
* @brief Unregister scanner packet callbacks.
1719+
*
1720+
* Remove the callback structure from the list of scanner callbacks.
1721+
*
1722+
* @param cb Callback struct. Must point to memory that remains valid.
1723+
*/
1724+
void bt_le_scan_cb_unregister(struct bt_le_scan_cb *cb);
1725+
17171726
/**
17181727
* @brief Add device (LE) to whitelist.
17191728
*

subsys/bluetooth/host/hci_core.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4301,7 +4301,7 @@ static uint8_t get_adv_props(uint8_t evt_type)
43014301
static void le_adv_recv(bt_addr_le_t *addr, struct bt_le_scan_recv_info *info,
43024302
struct net_buf *buf, uint8_t len)
43034303
{
4304-
struct bt_le_scan_cb *listener;
4304+
struct bt_le_scan_cb *listener, *next;
43054305
struct net_buf_simple_state state;
43064306
bt_addr_le_t id_addr;
43074307

@@ -4339,8 +4339,7 @@ static void le_adv_recv(bt_addr_le_t *addr, struct bt_le_scan_recv_info *info,
43394339
net_buf_simple_restore(&buf->b, &state);
43404340
}
43414341

4342-
4343-
SYS_SLIST_FOR_EACH_CONTAINER(&scan_cbs, listener, node) {
4342+
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&scan_cbs, listener, next, node) {
43444343
if (listener->recv) {
43454344
net_buf_simple_save(&buf->b, &state);
43464345

@@ -4359,7 +4358,7 @@ static void le_adv_recv(bt_addr_le_t *addr, struct bt_le_scan_recv_info *info,
43594358
#if defined(CONFIG_BT_EXT_ADV)
43604359
static void le_scan_timeout(struct net_buf *buf)
43614360
{
4362-
struct bt_le_scan_cb *listener;
4361+
struct bt_le_scan_cb *listener, *next;
43634362

43644363
atomic_clear_bit(bt_dev.flags, BT_DEV_SCANNING);
43654364
atomic_clear_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN);
@@ -4371,7 +4370,7 @@ static void le_scan_timeout(struct net_buf *buf)
43714370
pending_id_keys_update();
43724371
#endif
43734372

4374-
SYS_SLIST_FOR_EACH_CONTAINER(&scan_cbs, listener, node) {
4373+
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&scan_cbs, listener, next, node) {
43754374
if (listener->timeout) {
43764375
listener->timeout();
43774376
}
@@ -8996,6 +8995,11 @@ void bt_le_scan_cb_register(struct bt_le_scan_cb *cb)
89968995
{
89978996
sys_slist_append(&scan_cbs, &cb->node);
89988997
}
8998+
8999+
void bt_le_scan_cb_unregister(struct bt_le_scan_cb *cb)
9000+
{
9001+
sys_slist_find_and_remove(&scan_cbs, &cb->node);
9002+
}
89999003
#endif /* CONFIG_BT_OBSERVER */
90009004

90019005
#if defined(CONFIG_BT_WHITELIST)

0 commit comments

Comments
 (0)