Skip to content

Commit 2320556

Browse files
pvVudentz
authored andcommitted
Bluetooth: separate CIS_LINK and BIS_LINK link types
Use separate link type id for unicast and broadcast ISO connections. These connection types are handled with separate HCI commands, socket API is different, and hci_conn has union fields that are different in the two cases, so they shall not be mixed up. Currently in most places it is attempted to distinguish ucast by bacmp(&c->dst, BDADDR_ANY) but it is wrong as dst is set for bcast sink hci_conn in iso_conn_ready(). Additionally checking sync_handle might be OK, but depends on details of bcast conn configuration flow. To avoid complicating it, use separate link types. Fixes: f764a6c ("Bluetooth: ISO: Add broadcast support") Signed-off-by: Pauli Virtanen <pav@iki.fi> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 5bd5c71 commit 2320556

File tree

8 files changed

+89
-74
lines changed

8 files changed

+89
-74
lines changed

include/net/bluetooth/hci.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ enum {
558558
#define ESCO_LINK 0x02
559559
/* Low Energy links do not have defined link type. Use invented one */
560560
#define LE_LINK 0x80
561-
#define ISO_LINK 0x82
561+
#define CIS_LINK 0x82
562+
#define BIS_LINK 0x83
562563
#define INVALID_LINK 0xff
563564

564565
/* LMP features */

include/net/bluetooth/hci_core.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,8 @@ static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
999999
case ESCO_LINK:
10001000
h->sco_num++;
10011001
break;
1002-
case ISO_LINK:
1002+
case CIS_LINK:
1003+
case BIS_LINK:
10031004
h->iso_num++;
10041005
break;
10051006
}
@@ -1025,7 +1026,8 @@ static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
10251026
case ESCO_LINK:
10261027
h->sco_num--;
10271028
break;
1028-
case ISO_LINK:
1029+
case CIS_LINK:
1030+
case BIS_LINK:
10291031
h->iso_num--;
10301032
break;
10311033
}
@@ -1042,7 +1044,8 @@ static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
10421044
case SCO_LINK:
10431045
case ESCO_LINK:
10441046
return h->sco_num;
1045-
case ISO_LINK:
1047+
case CIS_LINK:
1048+
case BIS_LINK:
10461049
return h->iso_num;
10471050
default:
10481051
return 0;
@@ -1103,7 +1106,7 @@ static inline struct hci_conn *hci_conn_hash_lookup_bis(struct hci_dev *hdev,
11031106
rcu_read_lock();
11041107

11051108
list_for_each_entry_rcu(c, &h->list, list) {
1106-
if (bacmp(&c->dst, ba) || c->type != ISO_LINK)
1109+
if (bacmp(&c->dst, ba) || c->type != BIS_LINK)
11071110
continue;
11081111

11091112
if (c->iso_qos.bcast.bis == bis) {
@@ -1125,7 +1128,7 @@ hci_conn_hash_lookup_create_pa_sync(struct hci_dev *hdev)
11251128
rcu_read_lock();
11261129

11271130
list_for_each_entry_rcu(c, &h->list, list) {
1128-
if (c->type != ISO_LINK)
1131+
if (c->type != BIS_LINK)
11291132
continue;
11301133

11311134
if (!test_bit(HCI_CONN_CREATE_PA_SYNC, &c->flags))
@@ -1151,8 +1154,8 @@ hci_conn_hash_lookup_per_adv_bis(struct hci_dev *hdev,
11511154
rcu_read_lock();
11521155

11531156
list_for_each_entry_rcu(c, &h->list, list) {
1154-
if (bacmp(&c->dst, ba) || c->type != ISO_LINK ||
1155-
!test_bit(HCI_CONN_PER_ADV, &c->flags))
1157+
if (bacmp(&c->dst, ba) || c->type != BIS_LINK ||
1158+
!test_bit(HCI_CONN_PER_ADV, &c->flags))
11561159
continue;
11571160

11581161
if (c->iso_qos.bcast.big == big &&
@@ -1241,7 +1244,7 @@ static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
12411244
rcu_read_lock();
12421245

12431246
list_for_each_entry_rcu(c, &h->list, list) {
1244-
if (c->type != ISO_LINK || !bacmp(&c->dst, BDADDR_ANY))
1247+
if (c->type != CIS_LINK)
12451248
continue;
12461249

12471250
/* Match CIG ID if set */
@@ -1273,7 +1276,7 @@ static inline struct hci_conn *hci_conn_hash_lookup_cig(struct hci_dev *hdev,
12731276
rcu_read_lock();
12741277

12751278
list_for_each_entry_rcu(c, &h->list, list) {
1276-
if (c->type != ISO_LINK || !bacmp(&c->dst, BDADDR_ANY))
1279+
if (c->type != CIS_LINK)
12771280
continue;
12781281

12791282
if (handle == c->iso_qos.ucast.cig) {
@@ -1296,17 +1299,7 @@ static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,
12961299
rcu_read_lock();
12971300

12981301
list_for_each_entry_rcu(c, &h->list, list) {
1299-
if (c->type != ISO_LINK)
1300-
continue;
1301-
1302-
/* An ISO_LINK hcon with BDADDR_ANY as destination
1303-
* address is a Broadcast connection. A Broadcast
1304-
* slave connection is associated with a PA train,
1305-
* so the sync_handle can be used to differentiate
1306-
* from unicast.
1307-
*/
1308-
if (bacmp(&c->dst, BDADDR_ANY) &&
1309-
c->sync_handle == HCI_SYNC_HANDLE_INVALID)
1302+
if (c->type != BIS_LINK)
13101303
continue;
13111304

13121305
if (handle == c->iso_qos.bcast.big) {
@@ -1330,7 +1323,7 @@ hci_conn_hash_lookup_big_sync_pend(struct hci_dev *hdev,
13301323
rcu_read_lock();
13311324

13321325
list_for_each_entry_rcu(c, &h->list, list) {
1333-
if (c->type != ISO_LINK)
1326+
if (c->type != BIS_LINK)
13341327
continue;
13351328

13361329
if (handle == c->iso_qos.bcast.big && num_bis == c->num_bis) {
@@ -1353,8 +1346,8 @@ hci_conn_hash_lookup_big_state(struct hci_dev *hdev, __u8 handle, __u16 state)
13531346
rcu_read_lock();
13541347

13551348
list_for_each_entry_rcu(c, &h->list, list) {
1356-
if (bacmp(&c->dst, BDADDR_ANY) || c->type != ISO_LINK ||
1357-
c->state != state)
1349+
if (c->type != BIS_LINK || bacmp(&c->dst, BDADDR_ANY) ||
1350+
c->state != state)
13581351
continue;
13591352

13601353
if (handle == c->iso_qos.bcast.big) {
@@ -1377,8 +1370,8 @@ hci_conn_hash_lookup_pa_sync_big_handle(struct hci_dev *hdev, __u8 big)
13771370
rcu_read_lock();
13781371

13791372
list_for_each_entry_rcu(c, &h->list, list) {
1380-
if (c->type != ISO_LINK ||
1381-
!test_bit(HCI_CONN_PA_SYNC, &c->flags))
1373+
if (c->type != BIS_LINK ||
1374+
!test_bit(HCI_CONN_PA_SYNC, &c->flags))
13821375
continue;
13831376

13841377
if (c->iso_qos.bcast.big == big) {
@@ -1400,7 +1393,7 @@ hci_conn_hash_lookup_pa_sync_handle(struct hci_dev *hdev, __u16 sync_handle)
14001393
rcu_read_lock();
14011394

14021395
list_for_each_entry_rcu(c, &h->list, list) {
1403-
if (c->type != ISO_LINK)
1396+
if (c->type != BIS_LINK)
14041397
continue;
14051398

14061399
/* Ignore the listen hcon, we are looking
@@ -2015,7 +2008,8 @@ static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
20152008
case ESCO_LINK:
20162009
return sco_connect_ind(hdev, bdaddr, flags);
20172010

2018-
case ISO_LINK:
2011+
case CIS_LINK:
2012+
case BIS_LINK:
20192013
return iso_connect_ind(hdev, bdaddr, flags);
20202014

20212015
default:

net/bluetooth/hci_conn.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct hci_conn *c
785785
d->sync_handle = conn->sync_handle;
786786

787787
if (test_and_clear_bit(HCI_CONN_PA_SYNC, &conn->flags)) {
788-
hci_conn_hash_list_flag(hdev, find_bis, ISO_LINK,
788+
hci_conn_hash_list_flag(hdev, find_bis, BIS_LINK,
789789
HCI_CONN_PA_SYNC, d);
790790

791791
if (!d->count)
@@ -795,7 +795,7 @@ static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct hci_conn *c
795795
}
796796

797797
if (test_and_clear_bit(HCI_CONN_BIG_SYNC, &conn->flags)) {
798-
hci_conn_hash_list_flag(hdev, find_bis, ISO_LINK,
798+
hci_conn_hash_list_flag(hdev, find_bis, BIS_LINK,
799799
HCI_CONN_BIG_SYNC, d);
800800

801801
if (!d->count)
@@ -885,9 +885,11 @@ static void cis_cleanup(struct hci_conn *conn)
885885
/* Check if ISO connection is a CIS and remove CIG if there are
886886
* no other connections using it.
887887
*/
888-
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK, BT_BOUND, &d);
889-
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK, BT_CONNECT, &d);
890-
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK, BT_CONNECTED, &d);
888+
hci_conn_hash_list_state(hdev, find_cis, CIS_LINK, BT_BOUND, &d);
889+
hci_conn_hash_list_state(hdev, find_cis, CIS_LINK, BT_CONNECT,
890+
&d);
891+
hci_conn_hash_list_state(hdev, find_cis, CIS_LINK, BT_CONNECTED,
892+
&d);
891893
if (d.count)
892894
return;
893895

@@ -910,7 +912,8 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t
910912
if (!hdev->acl_mtu)
911913
return ERR_PTR(-ECONNREFUSED);
912914
break;
913-
case ISO_LINK:
915+
case CIS_LINK:
916+
case BIS_LINK:
914917
if (hdev->iso_mtu)
915918
/* Dedicated ISO Buffer exists */
916919
break;
@@ -974,7 +977,8 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t
974977
hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
975978
conn->mtu = hdev->le_mtu ? hdev->le_mtu : hdev->acl_mtu;
976979
break;
977-
case ISO_LINK:
980+
case CIS_LINK:
981+
case BIS_LINK:
978982
/* conn->src should reflect the local identity address */
979983
hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
980984

@@ -1071,7 +1075,8 @@ static void hci_conn_cleanup_child(struct hci_conn *conn, u8 reason)
10711075
if (HCI_CONN_HANDLE_UNSET(conn->handle))
10721076
hci_conn_failed(conn, reason);
10731077
break;
1074-
case ISO_LINK:
1078+
case CIS_LINK:
1079+
case BIS_LINK:
10751080
if ((conn->state != BT_CONNECTED &&
10761081
!test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) ||
10771082
test_bit(HCI_CONN_BIG_CREATED, &conn->flags))
@@ -1146,7 +1151,8 @@ void hci_conn_del(struct hci_conn *conn)
11461151
hdev->acl_cnt += conn->sent;
11471152
} else {
11481153
/* Unacked ISO frames */
1149-
if (conn->type == ISO_LINK) {
1154+
if (conn->type == CIS_LINK ||
1155+
conn->type == BIS_LINK) {
11501156
if (hdev->iso_pkts)
11511157
hdev->iso_cnt += conn->sent;
11521158
else if (hdev->le_pkts)
@@ -1532,7 +1538,7 @@ static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
15321538
memcmp(conn->le_per_adv_data, base, base_len)))
15331539
return ERR_PTR(-EADDRINUSE);
15341540

1535-
conn = hci_conn_add_unset(hdev, ISO_LINK, dst, HCI_ROLE_MASTER);
1541+
conn = hci_conn_add_unset(hdev, BIS_LINK, dst, HCI_ROLE_MASTER);
15361542
if (IS_ERR(conn))
15371543
return conn;
15381544

@@ -1740,7 +1746,7 @@ static int hci_le_create_big(struct hci_conn *conn, struct bt_iso_qos *qos)
17401746
data.count = 0;
17411747

17421748
/* Create a BIS for each bound connection */
1743-
hci_conn_hash_list_state(hdev, bis_list, ISO_LINK,
1749+
hci_conn_hash_list_state(hdev, bis_list, BIS_LINK,
17441750
BT_BOUND, &data);
17451751

17461752
cp.handle = qos->bcast.big;
@@ -1829,12 +1835,12 @@ static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos)
18291835
for (data.cig = 0x00; data.cig < 0xf0; data.cig++) {
18301836
data.count = 0;
18311837

1832-
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK,
1838+
hci_conn_hash_list_state(hdev, find_cis, CIS_LINK,
18331839
BT_CONNECT, &data);
18341840
if (data.count)
18351841
continue;
18361842

1837-
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK,
1843+
hci_conn_hash_list_state(hdev, find_cis, CIS_LINK,
18381844
BT_CONNECTED, &data);
18391845
if (!data.count)
18401846
break;
@@ -1884,7 +1890,8 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
18841890
cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type, qos->ucast.cig,
18851891
qos->ucast.cis);
18861892
if (!cis) {
1887-
cis = hci_conn_add_unset(hdev, ISO_LINK, dst, HCI_ROLE_MASTER);
1893+
cis = hci_conn_add_unset(hdev, CIS_LINK, dst,
1894+
HCI_ROLE_MASTER);
18881895
if (IS_ERR(cis))
18891896
return cis;
18901897
cis->cleanup = cis_cleanup;
@@ -1976,7 +1983,7 @@ bool hci_iso_setup_path(struct hci_conn *conn)
19761983

19771984
int hci_conn_check_create_cis(struct hci_conn *conn)
19781985
{
1979-
if (conn->type != ISO_LINK || !bacmp(&conn->dst, BDADDR_ANY))
1986+
if (conn->type != CIS_LINK)
19801987
return -EINVAL;
19811988

19821989
if (!conn->parent || conn->parent->state != BT_CONNECTED ||
@@ -2072,7 +2079,7 @@ struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
20722079

20732080
bt_dev_dbg(hdev, "dst %pMR type %d sid %d", dst, dst_type, sid);
20742081

2075-
conn = hci_conn_add_unset(hdev, ISO_LINK, dst, HCI_ROLE_SLAVE);
2082+
conn = hci_conn_add_unset(hdev, BIS_LINK, dst, HCI_ROLE_SLAVE);
20762083
if (IS_ERR(conn))
20772084
return conn;
20782085

@@ -2221,7 +2228,7 @@ struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
22212228
* the start periodic advertising and create BIG commands have
22222229
* been queued
22232230
*/
2224-
hci_conn_hash_list_state(hdev, bis_mark_per_adv, ISO_LINK,
2231+
hci_conn_hash_list_state(hdev, bis_mark_per_adv, BIS_LINK,
22252232
BT_BOUND, &data);
22262233

22272234
/* Queue start periodic advertising and create BIG */
@@ -2953,7 +2960,8 @@ void hci_conn_tx_queue(struct hci_conn *conn, struct sk_buff *skb)
29532960
* TODO: SCO support without flowctl (needs to be done in drivers)
29542961
*/
29552962
switch (conn->type) {
2956-
case ISO_LINK:
2963+
case CIS_LINK:
2964+
case BIS_LINK:
29572965
case ACL_LINK:
29582966
case LE_LINK:
29592967
break;

net/bluetooth/hci_core.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,12 +2898,13 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)
28982898
break;
28992899
case HCI_ACLDATA_PKT:
29002900
/* Detect if ISO packet has been sent as ACL */
2901-
if (hci_conn_num(hdev, ISO_LINK)) {
2901+
if (hci_conn_num(hdev, CIS_LINK) ||
2902+
hci_conn_num(hdev, BIS_LINK)) {
29022903
__u16 handle = __le16_to_cpu(hci_acl_hdr(skb)->handle);
29032904
__u8 type;
29042905

29052906
type = hci_conn_lookup_type(hdev, hci_handle(handle));
2906-
if (type == ISO_LINK)
2907+
if (type == CIS_LINK || type == BIS_LINK)
29072908
hci_skb_pkt_type(skb) = HCI_ISODATA_PKT;
29082909
}
29092910
break;
@@ -3356,7 +3357,8 @@ static inline void hci_quote_sent(struct hci_conn *conn, int num, int *quote)
33563357
case LE_LINK:
33573358
cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt;
33583359
break;
3359-
case ISO_LINK:
3360+
case CIS_LINK:
3361+
case BIS_LINK:
33603362
cnt = hdev->iso_mtu ? hdev->iso_cnt :
33613363
hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt;
33623364
break;
@@ -3370,7 +3372,7 @@ static inline void hci_quote_sent(struct hci_conn *conn, int num, int *quote)
33703372
}
33713373

33723374
static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type,
3373-
int *quote)
3375+
__u8 type2, int *quote)
33743376
{
33753377
struct hci_conn_hash *h = &hdev->conn_hash;
33763378
struct hci_conn *conn = NULL, *c;
@@ -3382,7 +3384,8 @@ static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type,
33823384
rcu_read_lock();
33833385

33843386
list_for_each_entry_rcu(c, &h->list, list) {
3385-
if (c->type != type || skb_queue_empty(&c->data_q))
3387+
if ((c->type != type && c->type != type2) ||
3388+
skb_queue_empty(&c->data_q))
33863389
continue;
33873390

33883391
if (c->state != BT_CONNECTED && c->state != BT_CONFIG)
@@ -3590,7 +3593,7 @@ static void hci_sched_sco(struct hci_dev *hdev, __u8 type)
35903593
else
35913594
cnt = &hdev->sco_cnt;
35923595

3593-
while (*cnt && (conn = hci_low_sent(hdev, type, &quote))) {
3596+
while (*cnt && (conn = hci_low_sent(hdev, type, type, &quote))) {
35943597
while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
35953598
BT_DBG("skb %p len %d", skb, skb->len);
35963599
hci_send_conn_frame(hdev, conn, skb);
@@ -3718,12 +3721,14 @@ static void hci_sched_iso(struct hci_dev *hdev)
37183721

37193722
BT_DBG("%s", hdev->name);
37203723

3721-
if (!hci_conn_num(hdev, ISO_LINK))
3724+
if (!hci_conn_num(hdev, CIS_LINK) &&
3725+
!hci_conn_num(hdev, BIS_LINK))
37223726
return;
37233727

37243728
cnt = hdev->iso_pkts ? &hdev->iso_cnt :
37253729
hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt;
3726-
while (*cnt && (conn = hci_low_sent(hdev, ISO_LINK, &quote))) {
3730+
while (*cnt && (conn = hci_low_sent(hdev, CIS_LINK, BIS_LINK,
3731+
&quote))) {
37273732
while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
37283733
BT_DBG("skb %p len %d", skb, skb->len);
37293734
hci_send_conn_frame(hdev, conn, skb);

0 commit comments

Comments
 (0)