Skip to content

Commit 9d0fb5e

Browse files
Vudentznashif
authored andcommitted
Bluetooth: ISO: Remove channel direction
Channel direction was actually a source of confusion since the spec does actually define the data path direction from controller point of view meaning input actually means transmit and output receive, also direction can be configured with different QoS settings. To make these APIs less confusing and allow QoS to be configured independently they are now split into RX (receiving) and TX (transmission) settings including its data path. Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 0eb4bfe commit 9d0fb5e

File tree

3 files changed

+143
-90
lines changed

3 files changed

+143
-90
lines changed

include/bluetooth/iso.h

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,33 @@ struct bt_iso_chan {
6060
struct bt_iso_chan_ops *ops;
6161
/** Channel QoS reference */
6262
struct bt_iso_chan_qos *qos;
63-
/** Channel data path reference*/
64-
struct bt_iso_chan_path *path;
6563
sys_snode_t node;
6664
uint8_t state;
6765
bt_security_t required_sec_level;
6866
};
6967

70-
/** @brief Audio QoS direction */
71-
enum {
72-
BT_ISO_CHAN_QOS_IN,
73-
BT_ISO_CHAN_QOS_OUT,
74-
BT_ISO_CHAN_QOS_INOUT
68+
/** @brief ISO Channel IO QoS structure. */
69+
struct bt_iso_chan_io_qos {
70+
/** Channel interval in us. Value range 0x0000FF - 0x0FFFFFF. */
71+
uint32_t interval;
72+
/** Channel Latency in ms. Value range 0x0005 - 0x0FA0. */
73+
uint16_t latency;
74+
/** Channel SDU. Value range 0x0000 - 0x0FFF. */
75+
uint16_t sdu;
76+
/** Channel PHY - See BT_GAP_LE_PHY for values.
77+
* Setting BT_GAP_LE_PHY_NONE is invalid.
78+
*/
79+
uint8_t phy;
80+
/** Channel Retransmission Number. Value range 0x00 - 0x0F. */
81+
uint8_t rtn;
82+
/** Channel data path reference.
83+
* Setting to NULL default to HCI data path.
84+
*/
85+
struct bt_iso_chan_path *path;
7586
};
7687

7788
/** @brief ISO Channel QoS structure. */
7889
struct bt_iso_chan_qos {
79-
/** @brief Channel direction
80-
*
81-
* Possible values: BT_ISO_CHAN_QOS_IN, BT_ISO_CHAN_QOS_OUT or
82-
* BT_ISO_CHAN_QOS_INOUT. Shall be BT_ISO_CHAN_QOS_IN for broadcast
83-
* transmitting, and BT_ISO_CHAN_QOS_OUT for broadcast receiver.
84-
*/
85-
uint8_t dir;
86-
/** Channel interval in us. Value range 0x0000FF - 0x0FFFFFF. */
87-
uint32_t interval;
8890
/** @brief Channel peripherals sleep clock accuracy Only for CIS
8991
*
9092
* Shall be worst case sleep clock accuracy of all the peripherals.
@@ -95,14 +97,14 @@ struct bt_iso_chan_qos {
9597
uint8_t packing;
9698
/** Channel framing mode. 0 for unframed, 1 for framed. */
9799
uint8_t framing;
98-
/** Channel Latency in ms. Value range 0x0005 - 0x0FA0. */
99-
uint16_t latency;
100-
/** Channel SDU. Value range 0x0000 0 0x0FFF. */
101-
uint8_t sdu;
102-
/** Channel PHY - See BT_GAP_LE_PHY for values. Shall not be BT_GAP_LE_PHY_NONE. */
103-
uint8_t phy;
104-
/** Channel Retransmission Number. Value range 0x00 - 0x0F. */
105-
uint8_t rtn;
100+
/** Channel Receiving QoS:
101+
* Setting NULL disables data path BT_HCI_DATAPATH_DIR_CTLR_TO_HOST
102+
*/
103+
struct bt_iso_chan_io_qos *rx;
104+
/** Channel Transmission QoS:
105+
* Setting NULL disables data path BT_HCI_DATAPATH_DIR_HOST_TO_CTRL
106+
*/
107+
struct bt_iso_chan_io_qos *tx;
106108
};
107109

108110
/** @brief ISO Channel Data Path structure. */
@@ -123,7 +125,6 @@ struct bt_iso_chan_path {
123125
uint8_t cc[0];
124126
};
125127

126-
127128
/** Opaque type representing an Broadcast Isochronous Group (BIG). */
128129
struct bt_iso_big;
129130

subsys/bluetooth/host/iso.c

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -395,40 +395,48 @@ static struct net_buf *hci_le_set_cig_params(struct bt_iso_create_param *param)
395395
memset(req, 0, sizeof(*req));
396396

397397
req->cig_id = param->conns[0]->iso.cig_id;
398-
sys_put_le24(param->chans[0]->qos->interval, req->m_interval);
399-
sys_put_le24(param->chans[0]->qos->interval, req->s_interval);
398+
sys_put_le24(param->chans[0]->qos->tx->interval, req->m_interval);
399+
sys_put_le24(param->chans[0]->qos->rx->interval, req->s_interval);
400400
req->sca = param->chans[0]->qos->sca;
401401
req->packing = param->chans[0]->qos->packing;
402402
req->framing = param->chans[0]->qos->framing;
403-
req->m_latency = sys_cpu_to_le16(param->chans[0]->qos->latency);
404-
req->s_latency = sys_cpu_to_le16(param->chans[0]->qos->latency);
403+
req->m_latency = sys_cpu_to_le16(param->chans[0]->qos->tx->latency);
404+
req->s_latency = sys_cpu_to_le16(param->chans[0]->qos->rx->latency);
405405
req->num_cis = param->num_conns;
406406

407407
/* Program the cis parameters */
408408
for (i = 0; i < param->num_conns; i++) {
409+
struct bt_iso_chan_qos *qos = param->chans[i]->qos;
410+
409411
cis = net_buf_add(buf, sizeof(*cis));
410412

411413
memset(cis, 0, sizeof(*cis));
412414

413415
cis->cis_id = param->conns[i]->iso.cis_id;
414416

415-
switch (param->chans[i]->qos->dir) {
416-
case BT_ISO_CHAN_QOS_IN:
417-
cis->s_sdu = param->chans[i]->qos->sdu;
418-
break;
419-
case BT_ISO_CHAN_QOS_OUT:
420-
cis->m_sdu = param->chans[i]->qos->sdu;
421-
break;
422-
case BT_ISO_CHAN_QOS_INOUT:
423-
cis->m_sdu = param->chans[i]->qos->sdu;
424-
cis->s_sdu = param->chans[i]->qos->sdu;
425-
break;
417+
if (!qos->tx && !qos->rx) {
418+
BT_ERR("Both TX and RX QoS are disabled");
419+
net_buf_unref(buf);
420+
return NULL;
426421
}
427422

428-
cis->m_phy = param->chans[i]->qos->phy;
429-
cis->s_phy = param->chans[i]->qos->phy;
430-
cis->m_rtn = param->chans[i]->qos->rtn;
431-
cis->s_rtn = param->chans[i]->qos->rtn;
423+
if (!qos->tx) {
424+
/* Use RX PHY if TX is not set (disabled) */
425+
cis->m_phy = qos->rx->phy;
426+
} else {
427+
cis->m_sdu = sys_cpu_to_le16(qos->tx->sdu);
428+
cis->m_phy = qos->tx->phy;
429+
cis->m_rtn = qos->tx->rtn;
430+
}
431+
432+
if (!qos->rx) {
433+
/* Use TX PHY if RX is not set (disabled) */
434+
cis->s_phy = qos->tx->phy;
435+
} else {
436+
cis->s_sdu = sys_cpu_to_le16(qos->rx->sdu);
437+
cis->s_phy = qos->rx->phy;
438+
cis->s_rtn = qos->rx->rtn;
439+
}
432440
}
433441

434442
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_CIG_PARAMS, buf, &rsp);
@@ -702,24 +710,15 @@ static int bt_iso_setup_data_path(struct bt_conn *conn)
702710
return -EINVAL;
703711
}
704712

705-
in_path.path = chan->path ? chan->path : &path;
706-
out_path.path = chan->path ? chan->path : &path;
713+
in_path.path = chan->qos->tx->path ? chan->qos->tx->path : &path;
714+
out_path.path = chan->qos->rx->path ? chan->qos->rx->path : &path;
707715

708-
switch (chan->qos->dir) {
709-
case BT_ISO_CHAN_QOS_IN:
710-
in_path.pid = in_path.path->pid;
711-
out_path.pid = BT_ISO_DATA_PATH_DISABLED;
712-
break;
713-
case BT_ISO_CHAN_QOS_OUT:
716+
if (!chan->qos->tx) {
714717
in_path.pid = BT_ISO_DATA_PATH_DISABLED;
715-
out_path.pid = out_path.path->pid;
716-
break;
717-
case BT_ISO_CHAN_QOS_INOUT:
718-
in_path.pid = in_path.path->pid;
719-
out_path.pid = out_path.path->pid;
720-
break;
721-
default:
722-
return -EINVAL;
718+
}
719+
720+
if (!chan->qos->rx) {
721+
out_path.pid = BT_ISO_DATA_PATH_DISABLED;
723722
}
724723

725724
err = hci_le_setup_iso_data_path(conn, &in_path);
@@ -1242,8 +1241,7 @@ static int big_init_bis(struct bt_iso_big *big, bool broadcaster)
12421241
return -EALREADY;
12431242
}
12441243

1245-
if (!bis->qos ||
1246-
bis->qos->dir != (broadcaster ? BT_ISO_CHAN_QOS_IN : BT_ISO_CHAN_QOS_OUT)) {
1244+
if (!bis->qos || (!bis->qos->tx && broadcaster)) {
12471245
BT_DBG("BIS QOS was invalid");
12481246
return -EINVAL;
12491247
}
@@ -1286,11 +1284,11 @@ static int hci_le_create_big(struct bt_le_ext_adv *padv, struct bt_iso_big *big,
12861284
req->big_handle = big->handle;
12871285
req->adv_handle = padv->handle;
12881286
req->num_bis = big->num_bis;
1289-
sys_put_le24(qos->interval, req->sdu_interval);
1290-
req->max_sdu = sys_cpu_to_le16(qos->sdu);
1291-
req->max_latency = sys_cpu_to_le16(qos->latency);
1292-
req->rtn = qos->rtn;
1293-
req->phy = qos->phy;
1287+
sys_put_le24(qos->tx->interval, req->sdu_interval);
1288+
req->max_sdu = sys_cpu_to_le16(qos->tx->sdu);
1289+
req->max_latency = sys_cpu_to_le16(qos->tx->latency);
1290+
req->rtn = qos->tx->rtn;
1291+
req->phy = qos->tx->phy;
12941292
req->packing = qos->packing;
12951293
req->framing = qos->framing;
12961294
req->encryption = param->encryption;
@@ -1428,7 +1426,7 @@ int bt_iso_big_terminate(struct bt_iso_big *big)
14281426
}
14291427

14301428
/* They all have the same QOS dir so we can just check the first */
1431-
broadcaster = big->bis[0]->qos->dir == BT_ISO_CHAN_QOS_IN;
1429+
broadcaster = big->bis[0]->qos->tx ? true : false;
14321430

14331431
if (broadcaster) {
14341432
err = hci_le_terminate_big(big);

0 commit comments

Comments
 (0)