diff --git a/include/zephyr/bluetooth/audio/audio.h b/include/zephyr/bluetooth/audio/audio.h index cc722f44e32..c8d74688ed8 100644 --- a/include/zephyr/bluetooth/audio/audio.h +++ b/include/zephyr/bluetooth/audio/audio.h @@ -1935,7 +1935,7 @@ int bt_audio_stream_release(struct bt_audio_stream *stream); * @return Bytes sent in case of success or negative value in case of error. */ int bt_audio_stream_send(struct bt_audio_stream *stream, struct net_buf *buf, - uint32_t seq_num, uint32_t ts); + uint16_t seq_num, uint32_t ts); /** @brief Parameter struct for the unicast group functions * diff --git a/include/zephyr/bluetooth/iso.h b/include/zephyr/bluetooth/iso.h index f39e3c72c21..fb9963e31fb 100644 --- a/include/zephyr/bluetooth/iso.h +++ b/include/zephyr/bluetooth/iso.h @@ -677,7 +677,7 @@ int bt_iso_chan_disconnect(struct bt_iso_chan *chan); * @return Bytes sent in case of success or negative value in case of error. */ int bt_iso_chan_send(struct bt_iso_chan *chan, struct net_buf *buf, - uint32_t seq_num, uint32_t ts); + uint16_t seq_num, uint32_t ts); struct bt_iso_unicast_tx_info { /** The transport latency in us */ diff --git a/samples/bluetooth/broadcast_audio_source/src/main.c b/samples/bluetooth/broadcast_audio_source/src/main.c index ece1d0ef9d2..b5529b494b4 100644 --- a/samples/bluetooth/broadcast_audio_source/src/main.c +++ b/samples/bluetooth/broadcast_audio_source/src/main.c @@ -27,7 +27,7 @@ NET_BUF_POOL_FIXED_DEFINE(tx_pool, TOTAL_BUF_NEEDED, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); static uint8_t mock_data[CONFIG_BT_ISO_TX_MTU]; -static uint32_t seq_num; +static uint16_t seq_num; static bool stopping; static K_SEM_DEFINE(sem_started, 0U, ARRAY_SIZE(streams)); diff --git a/samples/bluetooth/central_iso/src/main.c b/samples/bluetooth/central_iso/src/main.c index d33e3fa9a21..336ff918150 100644 --- a/samples/bluetooth/central_iso/src/main.c +++ b/samples/bluetooth/central_iso/src/main.c @@ -24,7 +24,7 @@ static void start_scan(void); static struct bt_conn *default_conn; static struct k_work_delayable iso_send_work; static struct bt_iso_chan iso_chan; -static uint32_t seq_num; +static uint16_t seq_num; static uint32_t interval_us = 10U * USEC_PER_MSEC; /* 10 ms */ NET_BUF_POOL_FIXED_DEFINE(tx_pool, 1, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); diff --git a/samples/bluetooth/hap_ha/src/bap_unicast_sr.c b/samples/bluetooth/hap_ha/src/bap_unicast_sr.c index 4bc4163dce4..0def2418c45 100644 --- a/samples/bluetooth/hap_ha/src/bap_unicast_sr.c +++ b/samples/bluetooth/hap_ha/src/bap_unicast_sr.c @@ -31,14 +31,14 @@ static struct k_work_delayable audio_send_work; static struct bt_audio_stream streams[CONFIG_BT_ASCS_ASE_SNK_COUNT + CONFIG_BT_ASCS_ASE_SRC_COUNT]; static struct bt_audio_source { struct bt_audio_stream *stream; - uint32_t seq_num; + uint16_t seq_num; } source_streams[CONFIG_BT_ASCS_ASE_SRC_COUNT]; static size_t configured_source_stream_count; static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0x02, 10, 20000, 40000, 20000, 40000); -static uint32_t get_and_incr_seq_num(const struct bt_audio_stream *stream) +static uint16_t get_and_incr_seq_num(const struct bt_audio_stream *stream) { for (size_t i = 0U; i < configured_source_stream_count; i++) { if (stream == source_streams[i].stream) { diff --git a/samples/bluetooth/iso_broadcast/src/main.c b/samples/bluetooth/iso_broadcast/src/main.c index 711aeb39aaf..2e177b8099c 100644 --- a/samples/bluetooth/iso_broadcast/src/main.c +++ b/samples/bluetooth/iso_broadcast/src/main.c @@ -21,7 +21,7 @@ static K_SEM_DEFINE(sem_big_term, 0, BIS_ISO_CHAN_COUNT); #define INITIAL_TIMEOUT_COUNTER (BIG_TERMINATE_TIMEOUT_US / BIG_SDU_INTERVAL_US) -static uint32_t seq_num; +static uint16_t seq_num; static void iso_connected(struct bt_iso_chan *chan) { diff --git a/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c b/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c index 216dacfff37..cf35d78e30b 100644 --- a/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c +++ b/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c @@ -36,7 +36,7 @@ static uint8_t connected_bis; static struct bt_iso_chan bis_iso_chans[CONFIG_BT_ISO_MAX_CHAN]; static struct bt_iso_chan *bis[CONFIG_BT_ISO_MAX_CHAN]; /* We use a single seq_num for all the BIS as they share the same SDU interval */ -static uint32_t seq_num; +static uint16_t seq_num; static struct bt_iso_big_create_param big_create_param = { .num_bis = DEFAULT_BIS_COUNT, .bis_channels = bis, diff --git a/samples/bluetooth/iso_connected_benchmark/src/main.c b/samples/bluetooth/iso_connected_benchmark/src/main.c index 7d6b370f9c8..a3382efbe6f 100644 --- a/samples/bluetooth/iso_connected_benchmark/src/main.c +++ b/samples/bluetooth/iso_connected_benchmark/src/main.c @@ -52,7 +52,7 @@ struct iso_chan_work { struct bt_iso_chan chan; struct k_work_delayable send_work; struct bt_iso_info info; - uint32_t seq_num; + uint16_t seq_num; } iso_chans[CONFIG_BT_ISO_MAX_CHAN]; static enum benchmark_role role; diff --git a/samples/bluetooth/unicast_audio_client/src/main.c b/samples/bluetooth/unicast_audio_client/src/main.c index 267dd608c41..00c91ef5b1c 100644 --- a/samples/bluetooth/unicast_audio_client/src/main.c +++ b/samples/bluetooth/unicast_audio_client/src/main.c @@ -23,7 +23,7 @@ static struct bt_audio_unicast_group *unicast_group; static struct bt_codec *remote_codec_capabilities[CONFIG_BT_AUDIO_UNICAST_CLIENT_PAC_COUNT]; static struct bt_audio_sink { struct bt_audio_ep *ep; - uint32_t seq_num; + uint16_t seq_num; } sinks[CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT]; static struct bt_audio_ep *sources[CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SRC_COUNT]; NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT, @@ -55,7 +55,7 @@ static K_SEM_DEFINE(sem_stream_qos, 0, 1); static K_SEM_DEFINE(sem_stream_enabled, 0, 1); static K_SEM_DEFINE(sem_stream_started, 0, 1); -static uint32_t get_and_incr_seq_num(const struct bt_audio_stream *stream) +static uint16_t get_and_incr_seq_num(const struct bt_audio_stream *stream) { for (size_t i = 0U; i < configured_sink_stream_count; i++) { if (stream->ep == sinks[i].ep) { diff --git a/samples/bluetooth/unicast_audio_server/src/main.c b/samples/bluetooth/unicast_audio_server/src/main.c index f0681087e98..daaa64d415e 100644 --- a/samples/bluetooth/unicast_audio_server/src/main.c +++ b/samples/bluetooth/unicast_audio_server/src/main.c @@ -41,7 +41,7 @@ static struct k_work_delayable audio_send_work; static struct bt_audio_stream streams[CONFIG_BT_ASCS_ASE_SNK_COUNT + CONFIG_BT_ASCS_ASE_SRC_COUNT]; static struct bt_audio_source { struct bt_audio_stream *stream; - uint32_t seq_num; + uint16_t seq_num; uint16_t max_sdu; size_t len_to_send; } source_streams[CONFIG_BT_ASCS_ASE_SRC_COUNT]; @@ -69,7 +69,7 @@ static const struct bt_data ad[] = { BT_DATA(BT_DATA_SVC_DATA16, unicast_server_addata, ARRAY_SIZE(unicast_server_addata)), }; -static uint32_t get_and_incr_seq_num(const struct bt_audio_stream *stream) +static uint16_t get_and_incr_seq_num(const struct bt_audio_stream *stream) { for (size_t i = 0U; i < configured_source_stream_count; i++) { if (stream == source_streams[i].stream) { diff --git a/subsys/bluetooth/audio/stream.c b/subsys/bluetooth/audio/stream.c index 3a4bff0e88a..83de6119164 100644 --- a/subsys/bluetooth/audio/stream.c +++ b/subsys/bluetooth/audio/stream.c @@ -89,7 +89,7 @@ void bt_audio_stream_attach(struct bt_conn *conn, #if defined(CONFIG_BT_AUDIO_UNICAST) || defined(CONFIG_BT_AUDIO_BROADCAST_SOURCE) int bt_audio_stream_send(struct bt_audio_stream *stream, struct net_buf *buf, - uint32_t seq_num, uint32_t ts) + uint16_t seq_num, uint32_t ts) { struct bt_audio_ep *ep; diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index d304b59c7b4..60ac2577bc1 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -125,16 +125,6 @@ struct bt_conn_iso { uint8_t bis_id; }; -#if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_BROADCASTER) - /** @brief 16-bit sequence number that shall be incremented per SDU interval - * - * Stored as 32-bit to handle wrapping: Only once the value has - * become greater than 0xFFFF will values less than the - * current are allowed again. - */ - uint32_t seq_num; -#endif /* CONFIG_BT_ISO_UNICAST) || CONFIG_BT_ISO_BROADCASTER */ - /** Stored information about the ISO stream */ struct bt_iso_info info; }; diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index b6fbfcd8bfd..b288d8add43 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -741,7 +741,7 @@ static uint16_t iso_chan_max_data_len(const struct bt_iso_chan *chan, } int bt_iso_chan_send(struct bt_iso_chan *chan, struct net_buf *buf, - uint32_t seq_num, uint32_t ts) + uint16_t seq_num, uint32_t ts) { uint16_t max_data_len; struct bt_conn *iso_conn; @@ -778,19 +778,6 @@ int bt_iso_chan_send(struct bt_iso_chan *chan, struct net_buf *buf, return -EMSGSIZE; } - /* Once the stored seq_num reaches the maximum value sendable to the - * controller (BT_ISO_MAX_SEQ_NUM) we will allow the application to wrap - * it. This ensures that up to 2^32-1 SDUs can be sent without wrapping - * the sequence number which should provide ample room to handle - * applications that does not send an SDU every interval. - */ - if (seq_num <= iso_conn->iso.seq_num && - iso_conn->iso.seq_num < BT_ISO_MAX_SEQ_NUM) { - BT_DBG("Invalid seq_num %u - Shall be > than %u", - seq_num, iso_conn->iso.seq_num); - return -EINVAL; - } - max_data_len = iso_chan_max_data_len(chan, ts); if (buf->len > max_data_len) { BT_DBG("Cannot send %u octets, maximum %u", @@ -798,13 +785,11 @@ int bt_iso_chan_send(struct bt_iso_chan *chan, struct net_buf *buf, return -EMSGSIZE; } - iso_conn->iso.seq_num = seq_num; - if (ts == BT_ISO_TIMESTAMP_NONE) { struct bt_hci_iso_data_hdr *hdr; hdr = net_buf_push(buf, sizeof(*hdr)); - hdr->sn = sys_cpu_to_le16((uint16_t)seq_num); + hdr->sn = sys_cpu_to_le16(seq_num); hdr->slen = sys_cpu_to_le16(bt_iso_pkt_len_pack(net_buf_frags_len(buf) - sizeof(*hdr), BT_ISO_DATA_VALID)); @@ -813,7 +798,7 @@ int bt_iso_chan_send(struct bt_iso_chan *chan, struct net_buf *buf, hdr = net_buf_push(buf, sizeof(*hdr)); hdr->ts = ts; - hdr->data.sn = sys_cpu_to_le16((uint16_t)seq_num); + hdr->data.sn = sys_cpu_to_le16(seq_num); hdr->data.slen = sys_cpu_to_le16(bt_iso_pkt_len_pack(net_buf_frags_len(buf) - sizeof(*hdr), BT_ISO_DATA_VALID)); @@ -990,9 +975,6 @@ void hci_le_cis_established(struct net_buf *buf) __ASSERT(chan != NULL && chan->qos != NULL, "Invalid ISO chan"); - /* Reset sequence number */ - iso->iso.seq_num = BT_ISO_MAX_SEQ_NUM; - tx = chan->qos->tx; rx = chan->qos->rx; @@ -2465,8 +2447,6 @@ void hci_le_big_complete(struct net_buf *buf) const uint16_t handle = evt->handle[i++]; struct bt_conn *iso_conn = bis->iso; - /* Reset sequence number */ - iso_conn->iso.seq_num = BT_ISO_MAX_SEQ_NUM; iso_conn->handle = sys_le16_to_cpu(handle); store_bis_broadcaster_info(evt, &iso_conn->iso.info); bt_conn_set_state(iso_conn, BT_CONN_CONNECTED); diff --git a/subsys/bluetooth/host/iso_internal.h b/subsys/bluetooth/host/iso_internal.h index 51214c1a0a3..604c4f5ebfd 100644 --- a/subsys/bluetooth/host/iso_internal.h +++ b/subsys/bluetooth/host/iso_internal.h @@ -11,8 +11,6 @@ #include -#define BT_ISO_MAX_SEQ_NUM 0xFFFF - struct iso_data { /** BT_BUF_ISO_IN */ uint8_t type; diff --git a/subsys/bluetooth/shell/audio.c b/subsys/bluetooth/shell/audio.c index 5a9ae28c2e8..a2fa3292dd5 100644 --- a/subsys/bluetooth/shell/audio.c +++ b/subsys/bluetooth/shell/audio.c @@ -61,7 +61,7 @@ static struct bt_audio_stream broadcast_sink_streams[BROADCAST_SNK_STREAM_CNT]; static struct bt_audio_broadcast_sink *default_sink; #endif /* CONFIG_BT_AUDIO_BROADCAST_SINK */ static struct bt_audio_stream *default_stream; -static uint32_t seq_num; +static uint16_t seq_num; static bool connecting; struct named_lc3_preset { @@ -145,7 +145,7 @@ static struct named_lc3_preset lc3_broadcast_presets[] = { static struct named_lc3_preset *default_preset = &lc3_unicast_presets[3]; static bool initialized; -static uint32_t get_next_seq_num(uint32_t interval_us) +static uint16_t get_next_seq_num(uint32_t interval_us) { static int64_t last_ticks; int64_t uptime_ticks, delta_ticks; @@ -164,7 +164,7 @@ static uint32_t get_next_seq_num(uint32_t interval_us) seq_num_incr = delta_us / interval_us; next_seq_num = (seq_num_incr + seq_num); - return (uint32_t)next_seq_num; + return (uint16_t)next_seq_num; } #if defined(CONFIG_LIBLC3) diff --git a/tests/bluetooth/bsim_bt/bsim_test_iso/src/main.c b/tests/bluetooth/bsim_bt/bsim_test_iso/src/main.c index 281e2767d1c..dacd293da06 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_iso/src/main.c +++ b/tests/bluetooth/bsim_bt/bsim_test_iso/src/main.c @@ -86,7 +86,7 @@ static struct bt_iso_chan bis_iso_chan = { #define BIS_ISO_CHAN_COUNT 1 static struct bt_iso_chan *bis_channels[BIS_ISO_CHAN_COUNT] = { &bis_iso_chan }; -static uint32_t seq_num; +static uint16_t seq_num; NET_BUF_POOL_FIXED_DEFINE(bis_tx_pool, BIS_ISO_CHAN_COUNT, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL);