Bluetooth: ISO: Change ISO seq_num to 16-bit
The sequence number is by the core spec defined as 16-bit. We had implemented a workaround for the wrapping of the sequence number, which required the type to be larger than 16-bit (32-bit). However, since the definition of the sequence number, and the use of, is poorly defined by the core spec, we are reverting this workaround and reducing the sequence number to 16-bit again. This way it is more in line with the core spec, as well as more intuitive given the other uses for the sequence number. This change moves the responsibility of using the right value to the upper layers, as the stack can and will no longer provide any guarantees. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
78809549ee
commit
31bf99cbd2
@ -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
|
||||
*
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -11,8 +11,6 @@
|
||||
|
||||
#include <zephyr/bluetooth/iso.h>
|
||||
|
||||
#define BT_ISO_MAX_SEQ_NUM 0xFFFF
|
||||
|
||||
struct iso_data {
|
||||
/** BT_BUF_ISO_IN */
|
||||
uint8_t type;
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user