Skip to content

Commit 9fa7a11

Browse files
Thalleyrick1082
authored andcommitted
[nrf fromtree] Bluetooth: BAP: Fix issue with setting invalid iso data path
BAP would always set up the ISO data path in both directions, even for unidirectional CIS. This meant that in the unconfigured direction, the data path configuration data would all be 0, which causes issues on some controllers. The new refactored approach implemented by this commit will always ensure that the data path is setup correctly, and that we only set the data path in one direction for unidirectional CIS. The unset path will use the default ISO path of HCI and transparant format, which should always be allowed by a controller. This is building on the requirement in BAP that all streams in a unicast group shall be QoS configured at the same time. This ensures that before any streams in the CIG has been connected, they have all been configured. Signed-off-by: Emil Gydesen <[email protected]> (cherry picked from commit aef39f6) Signed-off-by: Jui-Chou Chung <[email protected]>
1 parent 827bb38 commit 9fa7a11

8 files changed

+46
-52
lines changed

subsys/bluetooth/audio/ascs.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -1820,11 +1820,7 @@ static int ase_stream_qos(struct bt_bap_stream *stream, struct bt_audio_codec_qo
18201820
* we have the ISO <-> EP coupling completed (due to setting
18211821
* the CIS ID in the QoS procedure).
18221822
*/
1823-
if (ep->dir == BT_AUDIO_DIR_SINK) {
1824-
bt_audio_codec_cfg_to_iso_path(&ep->iso->rx.path, stream->codec_cfg);
1825-
} else {
1826-
bt_audio_codec_cfg_to_iso_path(&ep->iso->tx.path, stream->codec_cfg);
1827-
}
1823+
bt_bap_iso_configure_data_path(ep, stream->codec_cfg);
18281824

18291825
ep->cig_id = cig_id;
18301826
ep->cis_id = cis_id;

subsys/bluetooth/audio/bap_broadcast_sink.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ static int bt_bap_broadcast_sink_setup_stream(struct bt_bap_broadcast_sink *sink
764764
bt_bap_iso_bind_ep(iso, ep);
765765

766766
bt_audio_codec_qos_to_iso_qos(iso->chan.qos->rx, &sink->codec_qos);
767-
bt_audio_codec_cfg_to_iso_path(iso->chan.qos->rx->path, codec_cfg);
767+
bt_bap_iso_configure_data_path(ep, codec_cfg);
768768

769769
bt_bap_iso_unref(iso);
770770

subsys/bluetooth/audio/bap_broadcast_source.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static int broadcast_source_setup_stream(uint8_t index, struct bt_bap_stream *st
288288
bt_bap_iso_bind_ep(iso, ep);
289289

290290
bt_audio_codec_qos_to_iso_qos(iso->chan.qos->tx, qos);
291-
bt_audio_codec_cfg_to_iso_path(iso->chan.qos->tx->path, codec_cfg);
291+
bt_bap_iso_configure_data_path(ep, codec_cfg);
292292
#if defined(CONFIG_BT_ISO_TEST_PARAMS)
293293
iso->chan.qos->num_subevents = qos->num_subevents;
294294
#endif /* CONFIG_BT_ISO_TEST_PARAMS */
@@ -878,7 +878,7 @@ int bt_bap_broadcast_source_reconfig(struct bt_bap_broadcast_source *source,
878878

879879
iso_qos = stream->ep->iso->chan.qos->tx;
880880
bt_bap_stream_attach(NULL, stream, stream->ep, codec_cfg);
881-
bt_audio_codec_cfg_to_iso_path(iso_qos->path, codec_cfg);
881+
bt_bap_iso_configure_data_path(stream->ep, codec_cfg);
882882
}
883883
}
884884

subsys/bluetooth/audio/bap_iso.c

+39-9
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,12 @@ void bt_bap_iso_init(struct bt_bap_iso *iso, struct bt_iso_chan_ops *ops)
129129
iso->chan.ops = ops;
130130
iso->chan.qos = &iso->qos;
131131

132-
/* Setup points for both Tx and Rx
132+
/* Setup the QoS for both Tx and Rx
133133
* This is due to the limitation in the ISO API where pointers like
134-
* the `qos->tx` shall be initialized before the CIS is connected if
135-
* ever want to use it for TX, and ditto for RX. They cannot be
136-
* initialized after the CIS has been connected
134+
* the `qos->tx` shall be initialized before the CIS is created
137135
*/
138136
iso->chan.qos->rx = &iso->rx.qos;
139-
iso->chan.qos->rx->path = &iso->rx.path;
140-
iso->chan.qos->rx->path->cc = iso->rx.cc;
141-
142137
iso->chan.qos->tx = &iso->tx.qos;
143-
iso->chan.qos->tx->path = &iso->tx.path;
144-
iso->chan.qos->tx->path->cc = iso->tx.cc;
145138
}
146139

147140
static struct bt_bap_iso_dir *bap_iso_get_iso_dir(bool unicast_client, struct bt_bap_iso *iso,
@@ -164,6 +157,43 @@ static struct bt_bap_iso_dir *bap_iso_get_iso_dir(bool unicast_client, struct bt
164157
}
165158
}
166159

160+
void bt_bap_iso_configure_data_path(struct bt_bap_ep *ep, struct bt_audio_codec_cfg *codec_cfg)
161+
{
162+
struct bt_bap_iso *bap_iso = ep->iso;
163+
struct bt_iso_chan_qos *qos = bap_iso->chan.qos;
164+
const bool is_unicast_client =
165+
IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && bt_bap_ep_is_unicast_client(ep);
166+
struct bt_bap_iso_dir *iso_dir = bap_iso_get_iso_dir(is_unicast_client, bap_iso, ep->dir);
167+
struct bt_iso_chan_path *path = &iso_dir->path;
168+
169+
/* Setup the data path objects */
170+
if (iso_dir == &bap_iso->rx) {
171+
qos->rx->path = path;
172+
} else {
173+
qos->tx->path = path;
174+
}
175+
176+
/* Configure the data path to either use the controller for transcoding, or set the path to
177+
* be transparant to indicate that the transcoding happens somewhere else
178+
*/
179+
path->pid = codec_cfg->path_id;
180+
181+
if (codec_cfg->ctlr_transcode) {
182+
path->format = codec_cfg->id;
183+
path->cid = codec_cfg->cid;
184+
path->vid = codec_cfg->vid;
185+
path->delay = 0;
186+
path->cc_len = codec_cfg->data_len;
187+
path->cc = codec_cfg->data;
188+
} else {
189+
path->format = BT_HCI_CODING_FORMAT_TRANSPARENT;
190+
path->cid = 0;
191+
path->vid = 0;
192+
path->delay = 0;
193+
path->cc_len = 0;
194+
path->cc = NULL;
195+
}
196+
}
167197
static bool is_unicast_client_ep(struct bt_bap_ep *ep)
168198
{
169199
return IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && bt_bap_ep_is_unicast_client(ep);

subsys/bluetooth/audio/bap_iso.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void bt_bap_iso_foreach(bt_bap_iso_func_t func, void *user_data);
4141
struct bt_bap_iso *bt_bap_iso_find(bt_bap_iso_func_t func, void *user_data);
4242
void bt_bap_iso_init(struct bt_bap_iso *iso, struct bt_iso_chan_ops *ops);
4343
void bt_bap_iso_bind_ep(struct bt_bap_iso *iso, struct bt_bap_ep *ep);
44+
void bt_bap_iso_configure_data_path(struct bt_bap_ep *ep, struct bt_audio_codec_cfg *codec_cfg);
4445
void bt_bap_iso_unbind_ep(struct bt_bap_iso *iso, struct bt_bap_ep *ep);
4546
struct bt_bap_ep *bt_bap_iso_get_ep(bool unicast_client, struct bt_bap_iso *iso,
4647
enum bt_audio_dir dir);

subsys/bluetooth/audio/bap_stream.c

-22
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,6 @@
3131

3232
LOG_MODULE_REGISTER(bt_bap_stream, CONFIG_BT_BAP_STREAM_LOG_LEVEL);
3333

34-
void bt_audio_codec_cfg_to_iso_path(struct bt_iso_chan_path *path,
35-
struct bt_audio_codec_cfg *codec_cfg)
36-
{
37-
path->pid = codec_cfg->path_id;
38-
39-
if (codec_cfg->ctlr_transcode) {
40-
path->format = codec_cfg->id;
41-
path->cid = codec_cfg->cid;
42-
path->vid = codec_cfg->vid;
43-
path->delay = 0;
44-
path->cc_len = codec_cfg->data_len;
45-
path->cc = codec_cfg->data;
46-
} else {
47-
path->format = BT_HCI_CODING_FORMAT_TRANSPARENT;
48-
path->cid = 0;
49-
path->vid = 0;
50-
path->delay = 0;
51-
path->cc_len = 0;
52-
path->cc = NULL;
53-
}
54-
}
55-
5634
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT) || defined(CONFIG_BT_BAP_BROADCAST_SOURCE) || \
5735
defined(CONFIG_BT_BAP_BROADCAST_SINK)
5836
void bt_audio_codec_qos_to_iso_qos(struct bt_iso_chan_io_qos *io,

subsys/bluetooth/audio/bap_stream.h

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ void bt_bap_stream_reset(struct bt_bap_stream *stream);
1717
void bt_bap_stream_attach(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep,
1818
struct bt_audio_codec_cfg *codec_cfg);
1919

20-
void bt_audio_codec_cfg_to_iso_path(struct bt_iso_chan_path *path,
21-
struct bt_audio_codec_cfg *codec_cfg);
2220
void bt_audio_codec_qos_to_iso_qos(struct bt_iso_chan_io_qos *io,
2321
const struct bt_audio_codec_qos *codec_qos);
2422

subsys/bluetooth/audio/bap_unicast_client.c

+2-11
Original file line numberDiff line numberDiff line change
@@ -774,17 +774,8 @@ static void unicast_client_ep_qos_state(struct bt_bap_ep *ep, struct net_buf_sim
774774
* we have the ISO <-> EP coupling completed (due to setting
775775
* the CIS ID in the QoS procedure).
776776
*/
777-
if (ep->dir == BT_AUDIO_DIR_SOURCE) {
778-
/* If the endpoint is a source, then we need to
779-
* configure our RX parameters
780-
*/
781-
bt_audio_codec_cfg_to_iso_path(&ep->iso->rx.path, stream->codec_cfg);
782-
} else {
783-
/* If the endpoint is a sink, then we need to
784-
* configure our TX parameters
785-
*/
786-
bt_audio_codec_cfg_to_iso_path(&ep->iso->tx.path, stream->codec_cfg);
787-
}
777+
778+
bt_bap_iso_configure_data_path(ep, stream->codec_cfg);
788779
}
789780

790781
/* Notify upper layer */

0 commit comments

Comments
 (0)