Skip to content

Commit 1a11d1b

Browse files
Thalleycarlescufi
authored andcommitted
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 <[email protected]>
1 parent a56cbed commit 1a11d1b

File tree

2 files changed

+75
-82
lines changed

2 files changed

+75
-82
lines changed

subsys/bluetooth/host/iso.c

Lines changed: 74 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
#define LOG_MODULE_NAME bt_iso
2525
#include "common/log.h"
2626

27-
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_BROADCAST)
28-
NET_BUF_POOL_FIXED_DEFINE(iso_tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT,
29-
BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), NULL);
30-
#endif /* CONFIG_BT_ISO_UNICAST || CONFIG_BT_ISO_BROADCAST */
27+
#define iso_chan(_iso) ((_iso)->iso.chan);
3128

3229
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_SYNC_RECEIVER)
3330
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,
3633
static struct bt_iso_recv_info iso_info_data[CONFIG_BT_ISO_RX_BUF_COUNT];
3734
#define iso_info(buf) (&iso_info_data[net_buf_id(buf)])
3835
#endif /* CONFIG_BT_ISO_UNICAST || CONFIG_BT_ISO_SYNC_RECEIVER */
39-
#define iso_chan(_iso) ((_iso)->iso.chan);
4036

4137
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_BROADCAST)
38+
NET_BUF_POOL_FIXED_DEFINE(iso_tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT,
39+
BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), NULL);
40+
4241
#if CONFIG_BT_ISO_TX_FRAG_COUNT > 0
4342
NET_BUF_POOL_FIXED_DEFINE(iso_frag_pool, CONFIG_BT_ISO_TX_FRAG_COUNT,
4443
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);
6160
/* Prototype */
6261
int hci_le_remove_cig(uint8_t cig_id);
6362

64-
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_SYNC_RECEIVER)
65-
struct net_buf *bt_iso_get_rx(k_timeout_t timeout)
66-
{
67-
struct net_buf *buf = net_buf_alloc(&iso_rx_pool, timeout);
68-
69-
if (buf) {
70-
net_buf_reserve(buf, BT_BUF_RESERVE);
71-
bt_buf_set_type(buf, BT_BUF_ISO_IN);
72-
}
73-
74-
return buf;
75-
}
76-
#endif /* CONFIG_BT_ISO_UNICAST || CONFIG_BT_ISO_SYNC_RECEIVER */
77-
7863
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_BROADCASTER)
7964
static void bt_iso_send_cb(struct bt_conn *iso, void *user_data)
8065
{
@@ -542,6 +527,18 @@ void bt_iso_chan_set_state(struct bt_iso_chan *chan, uint8_t state)
542527
#endif /* CONFIG_BT_DEBUG_ISO */
543528

544529
#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_SYNC_RECEIVER)
530+
struct net_buf *bt_iso_get_rx(k_timeout_t timeout)
531+
{
532+
struct net_buf *buf = net_buf_alloc(&iso_rx_pool, timeout);
533+
534+
if (buf) {
535+
net_buf_reserve(buf, BT_BUF_RESERVE);
536+
bt_buf_set_type(buf, BT_BUF_ISO_IN);
537+
}
538+
539+
return buf;
540+
}
541+
545542
void bt_iso_recv(struct bt_conn *iso, struct net_buf *buf, uint8_t flags)
546543
{
547544
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
16651662

16661663
return err;
16671664
}
1665+
1666+
void hci_le_big_complete(struct net_buf *buf)
1667+
{
1668+
struct bt_hci_evt_le_big_complete *evt = (void *)buf->data;
1669+
struct bt_iso_big *big;
1670+
1671+
if (evt->big_handle >= ARRAY_SIZE(bigs)) {
1672+
BT_WARN("Invalid BIG handle");
1673+
1674+
big = big_lookup_flag(BT_BIG_PENDING);
1675+
if (big) {
1676+
big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED);
1677+
cleanup_big(big);
1678+
}
1679+
1680+
return;
1681+
}
1682+
1683+
big = lookup_big_by_handle(evt->big_handle);
1684+
atomic_clear_bit(big->flags, BT_BIG_PENDING);
1685+
1686+
BT_DBG("BIG[%u] %p completed, status %u", big->handle, big, evt->status);
1687+
1688+
if (evt->status || evt->num_bis != big->num_bis) {
1689+
if (evt->status == BT_HCI_ERR_SUCCESS && evt->num_bis != big->num_bis) {
1690+
BT_ERR("Invalid number of BIS created, was %u expected %u",
1691+
evt->num_bis, big->num_bis);
1692+
}
1693+
big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED);
1694+
cleanup_big(big);
1695+
return;
1696+
}
1697+
1698+
for (int i = 0; i < big->num_bis; i++) {
1699+
struct bt_iso_chan *bis = big->bis[i];
1700+
1701+
bis->iso->handle = sys_le16_to_cpu(evt->handle[i]);
1702+
bt_conn_set_state(bis->iso, BT_CONN_CONNECTED);
1703+
}
1704+
}
1705+
1706+
void hci_le_big_terminate(struct net_buf *buf)
1707+
{
1708+
struct bt_hci_evt_le_big_terminate *evt = (void *)buf->data;
1709+
struct bt_iso_big *big;
1710+
1711+
if (evt->big_handle >= ARRAY_SIZE(bigs)) {
1712+
BT_WARN("Invalid BIG handle");
1713+
return;
1714+
}
1715+
1716+
big = lookup_big_by_handle(evt->big_handle);
1717+
1718+
BT_DBG("BIG[%u] %p terminated", big->handle, big);
1719+
1720+
big_disconnect(big, evt->reason);
1721+
cleanup_big(big);
1722+
}
16681723
#endif /* CONFIG_BT_ISO_BROADCASTER */
16691724

16701725
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)
17631818
return err;
17641819
}
17651820

1766-
#if defined(CONFIG_BT_ISO_BROADCASTER)
1767-
void hci_le_big_complete(struct net_buf *buf)
1768-
{
1769-
struct bt_hci_evt_le_big_complete *evt = (void *)buf->data;
1770-
struct bt_iso_big *big;
1771-
1772-
if (evt->big_handle >= ARRAY_SIZE(bigs)) {
1773-
BT_WARN("Invalid BIG handle");
1774-
1775-
big = big_lookup_flag(BT_BIG_PENDING);
1776-
if (big) {
1777-
big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED);
1778-
cleanup_big(big);
1779-
}
1780-
1781-
return;
1782-
}
1783-
1784-
big = lookup_big_by_handle(evt->big_handle);
1785-
atomic_clear_bit(big->flags, BT_BIG_PENDING);
1786-
1787-
BT_DBG("BIG[%u] %p completed, status %u", big->handle, big, evt->status);
1788-
1789-
if (evt->status || evt->num_bis != big->num_bis) {
1790-
if (evt->status == BT_HCI_ERR_SUCCESS && evt->num_bis != big->num_bis) {
1791-
BT_ERR("Invalid number of BIS created, was %u expected %u",
1792-
evt->num_bis, big->num_bis);
1793-
}
1794-
big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED);
1795-
cleanup_big(big);
1796-
return;
1797-
}
1798-
1799-
for (int i = 0; i < big->num_bis; i++) {
1800-
struct bt_iso_chan *bis = big->bis[i];
1801-
1802-
bis->iso->handle = sys_le16_to_cpu(evt->handle[i]);
1803-
bt_conn_set_state(bis->iso, BT_CONN_CONNECTED);
1804-
}
1805-
}
1806-
1807-
void hci_le_big_terminate(struct net_buf *buf)
1808-
{
1809-
struct bt_hci_evt_le_big_terminate *evt = (void *)buf->data;
1810-
struct bt_iso_big *big;
1811-
1812-
if (evt->big_handle >= ARRAY_SIZE(bigs)) {
1813-
BT_WARN("Invalid BIG handle");
1814-
return;
1815-
}
1816-
1817-
big = lookup_big_by_handle(evt->big_handle);
1818-
1819-
BT_DBG("BIG[%u] %p terminated", big->handle, big);
1820-
1821-
big_disconnect(big, evt->reason);
1822-
cleanup_big(big);
1823-
}
1824-
#endif /* CONFIG_BT_ISO_BROADCASTER */
1825-
18261821
#if defined(CONFIG_BT_ISO_SYNC_RECEIVER)
18271822
void hci_le_big_sync_established(struct net_buf *buf)
18281823
{

subsys/bluetooth/shell/iso.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(iso_cmds,
538538
#if defined(CONFIG_BT_ISO_BROADCASTER)
539539
SHELL_CMD_ARG(create-big, NULL, "Create a BIG as a broadcaster [enc <broadcast code>]",
540540
cmd_big_create, 1, 2),
541+
SHELL_CMD_ARG(broadcast, NULL, "Broadcast on ISO channels", cmd_broadcast, 1, 1),
541542
#endif /* CONFIG_BT_ISO_BROADCASTER */
542543
#if defined(CONFIG_BT_ISO_SYNC_RECEIVER)
543544
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,
546547
#if defined(CONFIG_BT_ISO_BROADCAST)
547548
SHELL_CMD_ARG(term-big, NULL, "Terminate a BIG", cmd_big_term, 1, 0),
548549
#endif /* CONFIG_BT_ISO_BROADCAST */
549-
#if defined(CONFIG_BT_ISO_BROADCASTER)
550-
SHELL_CMD_ARG(broadcast, NULL, "Broadcast on ISO channels", cmd_broadcast, 1, 1),
551-
#endif /* CONFIG_BT_ISO_BROADCASTER */
552550
SHELL_SUBCMD_SET_END
553551
);
554552

0 commit comments

Comments
 (0)