Skip to content

Commit e8bcb29

Browse files
Thalleykartben
authored andcommitted
Bluetooth: ISO: Add BIG callbacks
Add callbacks that is called for the entire BIG. The BIG state is from an HCI perspective a single state change that we previously only propagated as a state change for each channel. However it may be simpler for applications and higher layers to use BIG changes to trigger their behavior. Signed-off-by: Emil Gydesen <[email protected]>
1 parent b3ffaf4 commit e8bcb29

File tree

2 files changed

+88
-0
lines changed
  • include/zephyr/bluetooth
  • subsys/bluetooth/host

2 files changed

+88
-0
lines changed

include/zephyr/bluetooth/iso.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <zephyr/sys/atomic.h>
3535
#include <zephyr/sys/slist.h>
3636
#include <zephyr/sys/util_macro.h>
37+
#include <zephyr/sys/slist.h>
3738

3839
#ifdef __cplusplus
3940
extern "C" {
@@ -1102,6 +1103,42 @@ int bt_iso_chan_get_info(const struct bt_iso_chan *chan, struct bt_iso_info *inf
11021103
*/
11031104
int bt_iso_chan_get_tx_sync(const struct bt_iso_chan *chan, struct bt_iso_tx_info *info);
11041105

1106+
/**
1107+
* @brief Struct to hold the Broadcast Isochronous Group callbacks
1108+
*
1109+
* These can be registered for usage with bt_iso_big_register_cb().
1110+
*/
1111+
struct bt_iso_big_cb {
1112+
/**
1113+
* @brief The BIG has started and all of the streams are ready for data
1114+
*
1115+
* @param big The started BIG
1116+
*/
1117+
void (*started)(struct bt_iso_big *big);
1118+
1119+
/**
1120+
* @brief The BIG has stopped and none of the streams are ready for data
1121+
*
1122+
* @param big The stopped BIG
1123+
* @param reason The reason why the BIG stopped (see the BT_HCI_ERR_* values)
1124+
*/
1125+
void (*stopped)(struct bt_iso_big *big, uint8_t reason);
1126+
1127+
/** @internal Internally used field for list handling */
1128+
sys_snode_t _node;
1129+
};
1130+
1131+
/**
1132+
* @brief Registers callbacks for Broadcast Sources
1133+
*
1134+
* @param cb Pointer to the callback structure.
1135+
*
1136+
* @retval 0 on success
1137+
* @retval -EINVAL if @p cb is NULL
1138+
* @retval -EEXIST if @p cb is already registered
1139+
*/
1140+
int bt_iso_big_register_cb(struct bt_iso_big_cb *cb);
1141+
11051142
/**
11061143
* @brief Creates a BIG as a broadcaster
11071144
*

subsys/bluetooth/host/iso.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,6 +2525,8 @@ int bt_iso_chan_connect(const struct bt_iso_connect_param *param, size_t count)
25252525
#endif /* CONFIG_BT_ISO_UNICAST */
25262526

25272527
#if defined(CONFIG_BT_ISO_BROADCAST)
2528+
static sys_slist_t iso_big_cbs = SYS_SLIST_STATIC_INIT(&iso_big_cbs);
2529+
25282530
static struct bt_iso_big *lookup_big_by_handle(uint8_t big_handle)
25292531
{
25302532
return &bigs[big_handle];
@@ -2587,6 +2589,16 @@ static void big_disconnect(struct bt_iso_big *big, uint8_t reason)
25872589

25882590
bt_iso_chan_disconnected(bis, reason);
25892591
}
2592+
2593+
if (!sys_slist_is_empty(&iso_big_cbs)) {
2594+
struct bt_iso_big_cb *listener;
2595+
2596+
SYS_SLIST_FOR_EACH_CONTAINER(&iso_big_cbs, listener, _node) {
2597+
if (listener->stopped != NULL) {
2598+
listener->stopped(big, reason);
2599+
}
2600+
}
2601+
}
25902602
}
25912603

25922604
static int big_init_bis(struct bt_iso_big *big, struct bt_iso_chan **bis_channels, uint8_t num_bis,
@@ -2617,6 +2629,25 @@ static int big_init_bis(struct bt_iso_big *big, struct bt_iso_chan **bis_channel
26172629
return 0;
26182630
}
26192631

2632+
int bt_iso_big_register_cb(struct bt_iso_big_cb *cb)
2633+
{
2634+
CHECKIF(cb == NULL) {
2635+
LOG_DBG("cb is NULL");
2636+
2637+
return -EINVAL;
2638+
}
2639+
2640+
if (sys_slist_find(&iso_big_cbs, &cb->_node, NULL)) {
2641+
LOG_DBG("cb %p is already registered", cb);
2642+
2643+
return -EEXIST;
2644+
}
2645+
2646+
sys_slist_append(&iso_big_cbs, &cb->_node);
2647+
2648+
return 0;
2649+
}
2650+
26202651
#if defined(CONFIG_BT_ISO_BROADCASTER)
26212652
static int hci_le_create_big(struct bt_le_ext_adv *padv, struct bt_iso_big *big,
26222653
struct bt_iso_big_create_param *param)
@@ -3006,6 +3037,16 @@ void hci_le_big_complete(struct net_buf *buf)
30063037
store_bis_broadcaster_info(evt, &iso_conn->iso.info);
30073038
bt_conn_set_state(iso_conn, BT_CONN_CONNECTED);
30083039
}
3040+
3041+
if (!sys_slist_is_empty(&iso_big_cbs)) {
3042+
struct bt_iso_big_cb *listener;
3043+
3044+
SYS_SLIST_FOR_EACH_CONTAINER(&iso_big_cbs, listener, _node) {
3045+
if (listener->started != NULL) {
3046+
listener->started(big);
3047+
}
3048+
}
3049+
}
30093050
}
30103051

30113052
void hci_le_big_terminate(struct net_buf *buf)
@@ -3186,6 +3227,16 @@ void hci_le_big_sync_established(struct net_buf *buf)
31863227
store_bis_sync_receiver_info(evt, &iso_conn->iso.info);
31873228
bt_conn_set_state(iso_conn, BT_CONN_CONNECTED);
31883229
}
3230+
3231+
if (!sys_slist_is_empty(&iso_big_cbs)) {
3232+
struct bt_iso_big_cb *listener;
3233+
3234+
SYS_SLIST_FOR_EACH_CONTAINER(&iso_big_cbs, listener, _node) {
3235+
if (listener->started != NULL) {
3236+
listener->started(big);
3237+
}
3238+
}
3239+
}
31893240
}
31903241

31913242
void hci_le_big_sync_lost(struct net_buf *buf)

0 commit comments

Comments
 (0)