Bluetooth: ISO: Move some broadcast iso code to better group functionality
Better group code specific for e.g. ISO broadcaster and ISO sync receiver. No code has been changed. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
a56cbed603
commit
1a11d1bd25
@ -24,10 +24,7 @@
|
||||
#define LOG_MODULE_NAME bt_iso
|
||||
#include "common/log.h"
|
||||
|
||||
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_BROADCAST)
|
||||
NET_BUF_POOL_FIXED_DEFINE(iso_tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT,
|
||||
BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), NULL);
|
||||
#endif /* CONFIG_BT_ISO_UNICAST || CONFIG_BT_ISO_BROADCAST */
|
||||
#define iso_chan(_iso) ((_iso)->iso.chan);
|
||||
|
||||
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_SYNC_RECEIVER)
|
||||
NET_BUF_POOL_FIXED_DEFINE(iso_rx_pool, CONFIG_BT_ISO_RX_BUF_COUNT,
|
||||
@ -36,9 +33,11 @@ NET_BUF_POOL_FIXED_DEFINE(iso_rx_pool, CONFIG_BT_ISO_RX_BUF_COUNT,
|
||||
static struct bt_iso_recv_info iso_info_data[CONFIG_BT_ISO_RX_BUF_COUNT];
|
||||
#define iso_info(buf) (&iso_info_data[net_buf_id(buf)])
|
||||
#endif /* CONFIG_BT_ISO_UNICAST || CONFIG_BT_ISO_SYNC_RECEIVER */
|
||||
#define iso_chan(_iso) ((_iso)->iso.chan);
|
||||
|
||||
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_BROADCAST)
|
||||
NET_BUF_POOL_FIXED_DEFINE(iso_tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT,
|
||||
BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), NULL);
|
||||
|
||||
#if CONFIG_BT_ISO_TX_FRAG_COUNT > 0
|
||||
NET_BUF_POOL_FIXED_DEFINE(iso_frag_pool, CONFIG_BT_ISO_TX_FRAG_COUNT,
|
||||
BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), NULL);
|
||||
@ -61,20 +60,6 @@ static struct bt_iso_big *lookup_big_by_handle(uint8_t big_handle);
|
||||
/* Prototype */
|
||||
int hci_le_remove_cig(uint8_t cig_id);
|
||||
|
||||
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_SYNC_RECEIVER)
|
||||
struct net_buf *bt_iso_get_rx(k_timeout_t timeout)
|
||||
{
|
||||
struct net_buf *buf = net_buf_alloc(&iso_rx_pool, timeout);
|
||||
|
||||
if (buf) {
|
||||
net_buf_reserve(buf, BT_BUF_RESERVE);
|
||||
bt_buf_set_type(buf, BT_BUF_ISO_IN);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
#endif /* CONFIG_BT_ISO_UNICAST || CONFIG_BT_ISO_SYNC_RECEIVER */
|
||||
|
||||
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_BROADCASTER)
|
||||
static void bt_iso_send_cb(struct bt_conn *iso, void *user_data)
|
||||
{
|
||||
@ -542,6 +527,18 @@ void bt_iso_chan_set_state(struct bt_iso_chan *chan, uint8_t state)
|
||||
#endif /* CONFIG_BT_DEBUG_ISO */
|
||||
|
||||
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_SYNC_RECEIVER)
|
||||
struct net_buf *bt_iso_get_rx(k_timeout_t timeout)
|
||||
{
|
||||
struct net_buf *buf = net_buf_alloc(&iso_rx_pool, timeout);
|
||||
|
||||
if (buf) {
|
||||
net_buf_reserve(buf, BT_BUF_RESERVE);
|
||||
bt_buf_set_type(buf, BT_BUF_ISO_IN);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void bt_iso_recv(struct bt_conn *iso, struct net_buf *buf, uint8_t flags)
|
||||
{
|
||||
struct bt_hci_iso_data_hdr *hdr;
|
||||
@ -1665,6 +1662,64 @@ int bt_iso_big_create(struct bt_le_ext_adv *padv, struct bt_iso_big_create_param
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void hci_le_big_complete(struct net_buf *buf)
|
||||
{
|
||||
struct bt_hci_evt_le_big_complete *evt = (void *)buf->data;
|
||||
struct bt_iso_big *big;
|
||||
|
||||
if (evt->big_handle >= ARRAY_SIZE(bigs)) {
|
||||
BT_WARN("Invalid BIG handle");
|
||||
|
||||
big = big_lookup_flag(BT_BIG_PENDING);
|
||||
if (big) {
|
||||
big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED);
|
||||
cleanup_big(big);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
big = lookup_big_by_handle(evt->big_handle);
|
||||
atomic_clear_bit(big->flags, BT_BIG_PENDING);
|
||||
|
||||
BT_DBG("BIG[%u] %p completed, status %u", big->handle, big, evt->status);
|
||||
|
||||
if (evt->status || evt->num_bis != big->num_bis) {
|
||||
if (evt->status == BT_HCI_ERR_SUCCESS && evt->num_bis != big->num_bis) {
|
||||
BT_ERR("Invalid number of BIS created, was %u expected %u",
|
||||
evt->num_bis, big->num_bis);
|
||||
}
|
||||
big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED);
|
||||
cleanup_big(big);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < big->num_bis; i++) {
|
||||
struct bt_iso_chan *bis = big->bis[i];
|
||||
|
||||
bis->iso->handle = sys_le16_to_cpu(evt->handle[i]);
|
||||
bt_conn_set_state(bis->iso, BT_CONN_CONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
void hci_le_big_terminate(struct net_buf *buf)
|
||||
{
|
||||
struct bt_hci_evt_le_big_terminate *evt = (void *)buf->data;
|
||||
struct bt_iso_big *big;
|
||||
|
||||
if (evt->big_handle >= ARRAY_SIZE(bigs)) {
|
||||
BT_WARN("Invalid BIG handle");
|
||||
return;
|
||||
}
|
||||
|
||||
big = lookup_big_by_handle(evt->big_handle);
|
||||
|
||||
BT_DBG("BIG[%u] %p terminated", big->handle, big);
|
||||
|
||||
big_disconnect(big, evt->reason);
|
||||
cleanup_big(big);
|
||||
}
|
||||
#endif /* CONFIG_BT_ISO_BROADCASTER */
|
||||
|
||||
static int hci_le_terminate_big(struct bt_iso_big *big)
|
||||
@ -1763,66 +1818,6 @@ int bt_iso_big_terminate(struct bt_iso_big *big)
|
||||
return err;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_ISO_BROADCASTER)
|
||||
void hci_le_big_complete(struct net_buf *buf)
|
||||
{
|
||||
struct bt_hci_evt_le_big_complete *evt = (void *)buf->data;
|
||||
struct bt_iso_big *big;
|
||||
|
||||
if (evt->big_handle >= ARRAY_SIZE(bigs)) {
|
||||
BT_WARN("Invalid BIG handle");
|
||||
|
||||
big = big_lookup_flag(BT_BIG_PENDING);
|
||||
if (big) {
|
||||
big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED);
|
||||
cleanup_big(big);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
big = lookup_big_by_handle(evt->big_handle);
|
||||
atomic_clear_bit(big->flags, BT_BIG_PENDING);
|
||||
|
||||
BT_DBG("BIG[%u] %p completed, status %u", big->handle, big, evt->status);
|
||||
|
||||
if (evt->status || evt->num_bis != big->num_bis) {
|
||||
if (evt->status == BT_HCI_ERR_SUCCESS && evt->num_bis != big->num_bis) {
|
||||
BT_ERR("Invalid number of BIS created, was %u expected %u",
|
||||
evt->num_bis, big->num_bis);
|
||||
}
|
||||
big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED);
|
||||
cleanup_big(big);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < big->num_bis; i++) {
|
||||
struct bt_iso_chan *bis = big->bis[i];
|
||||
|
||||
bis->iso->handle = sys_le16_to_cpu(evt->handle[i]);
|
||||
bt_conn_set_state(bis->iso, BT_CONN_CONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
void hci_le_big_terminate(struct net_buf *buf)
|
||||
{
|
||||
struct bt_hci_evt_le_big_terminate *evt = (void *)buf->data;
|
||||
struct bt_iso_big *big;
|
||||
|
||||
if (evt->big_handle >= ARRAY_SIZE(bigs)) {
|
||||
BT_WARN("Invalid BIG handle");
|
||||
return;
|
||||
}
|
||||
|
||||
big = lookup_big_by_handle(evt->big_handle);
|
||||
|
||||
BT_DBG("BIG[%u] %p terminated", big->handle, big);
|
||||
|
||||
big_disconnect(big, evt->reason);
|
||||
cleanup_big(big);
|
||||
}
|
||||
#endif /* CONFIG_BT_ISO_BROADCASTER */
|
||||
|
||||
#if defined(CONFIG_BT_ISO_SYNC_RECEIVER)
|
||||
void hci_le_big_sync_established(struct net_buf *buf)
|
||||
{
|
||||
|
||||
@ -538,6 +538,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(iso_cmds,
|
||||
#if defined(CONFIG_BT_ISO_BROADCASTER)
|
||||
SHELL_CMD_ARG(create-big, NULL, "Create a BIG as a broadcaster [enc <broadcast code>]",
|
||||
cmd_big_create, 1, 2),
|
||||
SHELL_CMD_ARG(broadcast, NULL, "Broadcast on ISO channels", cmd_broadcast, 1, 1),
|
||||
#endif /* CONFIG_BT_ISO_BROADCASTER */
|
||||
#if defined(CONFIG_BT_ISO_SYNC_RECEIVER)
|
||||
SHELL_CMD_ARG(sync-big, NULL, "Synchronize to a BIG as a receiver <BIS bitfield> [mse] "
|
||||
@ -546,9 +547,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(iso_cmds,
|
||||
#if defined(CONFIG_BT_ISO_BROADCAST)
|
||||
SHELL_CMD_ARG(term-big, NULL, "Terminate a BIG", cmd_big_term, 1, 0),
|
||||
#endif /* CONFIG_BT_ISO_BROADCAST */
|
||||
#if defined(CONFIG_BT_ISO_BROADCASTER)
|
||||
SHELL_CMD_ARG(broadcast, NULL, "Broadcast on ISO channels", cmd_broadcast, 1, 1),
|
||||
#endif /* CONFIG_BT_ISO_BROADCASTER */
|
||||
SHELL_SUBCMD_SET_END
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user