Skip to content

Commit 087812a

Browse files
Yang Ligregkh
authored andcommitted
Bluetooth: Add PA_LINK to distinguish BIG sync and PA sync connections
[ Upstream commit a7bcffc ] Currently, BIS_LINK is used for both BIG sync and PA sync connections, which makes it impossible to distinguish them when searching for a PA sync connection. Adding PA_LINK will make the distinction clearer and simplify future extensions for PA-related features. Signed-off-by: Yang Li <yang.li@amlogic.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Stable-dep-of: 9d4b01a ("Bluetooth: hci_core: Fix not accounting for BIS/CIS/PA links separately") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a33d563 commit 087812a

File tree

8 files changed

+46
-30
lines changed

8 files changed

+46
-30
lines changed

include/net/bluetooth/hci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ enum {
562562
#define LE_LINK 0x80
563563
#define CIS_LINK 0x82
564564
#define BIS_LINK 0x83
565+
#define PA_LINK 0x84
565566
#define INVALID_LINK 0xff
566567

567568
/* LMP features */

include/net/bluetooth/hci_core.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
10151015
break;
10161016
case CIS_LINK:
10171017
case BIS_LINK:
1018+
case PA_LINK:
10181019
h->iso_num++;
10191020
break;
10201021
}
@@ -1042,6 +1043,7 @@ static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
10421043
break;
10431044
case CIS_LINK:
10441045
case BIS_LINK:
1046+
case PA_LINK:
10451047
h->iso_num--;
10461048
break;
10471049
}
@@ -1060,6 +1062,7 @@ static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
10601062
return h->sco_num;
10611063
case CIS_LINK:
10621064
case BIS_LINK:
1065+
case PA_LINK:
10631066
return h->iso_num;
10641067
default:
10651068
return 0;
@@ -1142,7 +1145,7 @@ hci_conn_hash_lookup_create_pa_sync(struct hci_dev *hdev)
11421145
rcu_read_lock();
11431146

11441147
list_for_each_entry_rcu(c, &h->list, list) {
1145-
if (c->type != BIS_LINK)
1148+
if (c->type != PA_LINK)
11461149
continue;
11471150

11481151
if (!test_bit(HCI_CONN_CREATE_PA_SYNC, &c->flags))
@@ -1337,7 +1340,7 @@ hci_conn_hash_lookup_big_sync_pend(struct hci_dev *hdev,
13371340
rcu_read_lock();
13381341

13391342
list_for_each_entry_rcu(c, &h->list, list) {
1340-
if (c->type != BIS_LINK)
1343+
if (c->type != PA_LINK)
13411344
continue;
13421345

13431346
if (handle == c->iso_qos.bcast.big && num_bis == c->num_bis) {
@@ -1407,7 +1410,7 @@ hci_conn_hash_lookup_pa_sync_handle(struct hci_dev *hdev, __u16 sync_handle)
14071410
rcu_read_lock();
14081411

14091412
list_for_each_entry_rcu(c, &h->list, list) {
1410-
if (c->type != BIS_LINK)
1413+
if (c->type != PA_LINK)
14111414
continue;
14121415

14131416
/* Ignore the listen hcon, we are looking
@@ -2038,6 +2041,7 @@ static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
20382041

20392042
case CIS_LINK:
20402043
case BIS_LINK:
2044+
case PA_LINK:
20412045
return iso_connect_ind(hdev, bdaddr, flags);
20422046

20432047
default:

net/bluetooth/hci_conn.c

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

788788
if (test_and_clear_bit(HCI_CONN_PA_SYNC, &conn->flags)) {
789-
hci_conn_hash_list_flag(hdev, find_bis, BIS_LINK,
789+
hci_conn_hash_list_flag(hdev, find_bis, PA_LINK,
790790
HCI_CONN_PA_SYNC, d);
791791

792792
if (!d->count)
@@ -915,6 +915,7 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t
915915
break;
916916
case CIS_LINK:
917917
case BIS_LINK:
918+
case PA_LINK:
918919
if (hdev->iso_mtu)
919920
/* Dedicated ISO Buffer exists */
920921
break;
@@ -980,6 +981,7 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t
980981
break;
981982
case CIS_LINK:
982983
case BIS_LINK:
984+
case PA_LINK:
983985
/* conn->src should reflect the local identity address */
984986
hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
985987

@@ -1034,7 +1036,6 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t
10341036
}
10351037

10361038
hci_conn_init_sysfs(conn);
1037-
10381039
return conn;
10391040
}
10401041

@@ -1078,6 +1079,7 @@ static void hci_conn_cleanup_child(struct hci_conn *conn, u8 reason)
10781079
break;
10791080
case CIS_LINK:
10801081
case BIS_LINK:
1082+
case PA_LINK:
10811083
if ((conn->state != BT_CONNECTED &&
10821084
!test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) ||
10831085
test_bit(HCI_CONN_BIG_CREATED, &conn->flags))
@@ -1153,7 +1155,8 @@ void hci_conn_del(struct hci_conn *conn)
11531155
} else {
11541156
/* Unacked ISO frames */
11551157
if (conn->type == CIS_LINK ||
1156-
conn->type == BIS_LINK) {
1158+
conn->type == BIS_LINK ||
1159+
conn->type == PA_LINK) {
11571160
if (hdev->iso_pkts)
11581161
hdev->iso_cnt += conn->sent;
11591162
else if (hdev->le_pkts)
@@ -2082,7 +2085,7 @@ struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
20822085

20832086
bt_dev_dbg(hdev, "dst %pMR type %d sid %d", dst, dst_type, sid);
20842087

2085-
conn = hci_conn_add_unset(hdev, BIS_LINK, dst, HCI_ROLE_SLAVE);
2088+
conn = hci_conn_add_unset(hdev, PA_LINK, dst, HCI_ROLE_SLAVE);
20862089
if (IS_ERR(conn))
20872090
return conn;
20882091

@@ -2247,7 +2250,7 @@ struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
22472250
* the start periodic advertising and create BIG commands have
22482251
* been queued
22492252
*/
2250-
hci_conn_hash_list_state(hdev, bis_mark_per_adv, BIS_LINK,
2253+
hci_conn_hash_list_state(hdev, bis_mark_per_adv, PA_LINK,
22512254
BT_BOUND, &data);
22522255

22532256
/* Queue start periodic advertising and create BIG */
@@ -2981,6 +2984,7 @@ void hci_conn_tx_queue(struct hci_conn *conn, struct sk_buff *skb)
29812984
switch (conn->type) {
29822985
case CIS_LINK:
29832986
case BIS_LINK:
2987+
case PA_LINK:
29842988
case ACL_LINK:
29852989
case LE_LINK:
29862990
break;

net/bluetooth/hci_core.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,12 +2938,14 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)
29382938
case HCI_ACLDATA_PKT:
29392939
/* Detect if ISO packet has been sent as ACL */
29402940
if (hci_conn_num(hdev, CIS_LINK) ||
2941-
hci_conn_num(hdev, BIS_LINK)) {
2941+
hci_conn_num(hdev, BIS_LINK) ||
2942+
hci_conn_num(hdev, PA_LINK)) {
29422943
__u16 handle = __le16_to_cpu(hci_acl_hdr(skb)->handle);
29432944
__u8 type;
29442945

29452946
type = hci_conn_lookup_type(hdev, hci_handle(handle));
2946-
if (type == CIS_LINK || type == BIS_LINK)
2947+
if (type == CIS_LINK || type == BIS_LINK ||
2948+
type == PA_LINK)
29472949
hci_skb_pkt_type(skb) = HCI_ISODATA_PKT;
29482950
}
29492951
break;
@@ -3398,6 +3400,7 @@ static inline void hci_quote_sent(struct hci_conn *conn, int num, int *quote)
33983400
break;
33993401
case CIS_LINK:
34003402
case BIS_LINK:
3403+
case PA_LINK:
34013404
cnt = hdev->iso_mtu ? hdev->iso_cnt :
34023405
hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt;
34033406
break;
@@ -3411,7 +3414,7 @@ static inline void hci_quote_sent(struct hci_conn *conn, int num, int *quote)
34113414
}
34123415

34133416
static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type,
3414-
__u8 type2, int *quote)
3417+
int *quote)
34153418
{
34163419
struct hci_conn_hash *h = &hdev->conn_hash;
34173420
struct hci_conn *conn = NULL, *c;
@@ -3423,7 +3426,7 @@ static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type,
34233426
rcu_read_lock();
34243427

34253428
list_for_each_entry_rcu(c, &h->list, list) {
3426-
if ((c->type != type && c->type != type2) ||
3429+
if (c->type != type ||
34273430
skb_queue_empty(&c->data_q))
34283431
continue;
34293432

@@ -3627,7 +3630,7 @@ static void hci_sched_sco(struct hci_dev *hdev, __u8 type)
36273630
else
36283631
cnt = &hdev->sco_cnt;
36293632

3630-
while (*cnt && (conn = hci_low_sent(hdev, type, type, &quote))) {
3633+
while (*cnt && (conn = hci_low_sent(hdev, type, &quote))) {
36313634
while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
36323635
BT_DBG("skb %p len %d", skb, skb->len);
36333636
hci_send_conn_frame(hdev, conn, skb);
@@ -3746,23 +3749,21 @@ static void hci_sched_le(struct hci_dev *hdev)
37463749
hci_prio_recalculate(hdev, LE_LINK);
37473750
}
37483751

3749-
/* Schedule CIS */
3750-
static void hci_sched_iso(struct hci_dev *hdev)
3752+
/* Schedule iso */
3753+
static void hci_sched_iso(struct hci_dev *hdev, __u8 type)
37513754
{
37523755
struct hci_conn *conn;
37533756
struct sk_buff *skb;
37543757
int quote, *cnt;
37553758

37563759
BT_DBG("%s", hdev->name);
37573760

3758-
if (!hci_conn_num(hdev, CIS_LINK) &&
3759-
!hci_conn_num(hdev, BIS_LINK))
3761+
if (!hci_conn_num(hdev, type))
37603762
return;
37613763

37623764
cnt = hdev->iso_pkts ? &hdev->iso_cnt :
37633765
hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt;
3764-
while (*cnt && (conn = hci_low_sent(hdev, CIS_LINK, BIS_LINK,
3765-
&quote))) {
3766+
while (*cnt && (conn = hci_low_sent(hdev, type, &quote))) {
37663767
while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
37673768
BT_DBG("skb %p len %d", skb, skb->len);
37683769
hci_send_conn_frame(hdev, conn, skb);
@@ -3787,7 +3788,9 @@ static void hci_tx_work(struct work_struct *work)
37873788
/* Schedule queues and send stuff to HCI driver */
37883789
hci_sched_sco(hdev, SCO_LINK);
37893790
hci_sched_sco(hdev, ESCO_LINK);
3790-
hci_sched_iso(hdev);
3791+
hci_sched_iso(hdev, CIS_LINK);
3792+
hci_sched_iso(hdev, BIS_LINK);
3793+
hci_sched_iso(hdev, PA_LINK);
37913794
hci_sched_acl(hdev);
37923795
hci_sched_le(hdev);
37933796
}

net/bluetooth/hci_event.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,6 +4432,7 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data,
44324432

44334433
case CIS_LINK:
44344434
case BIS_LINK:
4435+
case PA_LINK:
44354436
if (hdev->iso_pkts) {
44364437
hdev->iso_cnt += count;
44374438
if (hdev->iso_cnt > hdev->iso_pkts)
@@ -6381,7 +6382,7 @@ static void hci_le_pa_sync_estabilished_evt(struct hci_dev *hdev, void *data,
63816382
conn->sync_handle = le16_to_cpu(ev->handle);
63826383
conn->sid = HCI_SID_INVALID;
63836384

6384-
mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, BIS_LINK,
6385+
mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, PA_LINK,
63856386
&flags);
63866387
if (!(mask & HCI_LM_ACCEPT)) {
63876388
hci_le_pa_term_sync(hdev, ev->handle);
@@ -6392,7 +6393,7 @@ static void hci_le_pa_sync_estabilished_evt(struct hci_dev *hdev, void *data,
63926393
goto unlock;
63936394

63946395
/* Add connection to indicate PA sync event */
6395-
pa_sync = hci_conn_add_unset(hdev, BIS_LINK, BDADDR_ANY,
6396+
pa_sync = hci_conn_add_unset(hdev, PA_LINK, BDADDR_ANY,
63966397
HCI_ROLE_SLAVE);
63976398

63986399
if (IS_ERR(pa_sync))
@@ -6423,7 +6424,7 @@ static void hci_le_per_adv_report_evt(struct hci_dev *hdev, void *data,
64236424

64246425
hci_dev_lock(hdev);
64256426

6426-
mask |= hci_proto_connect_ind(hdev, BDADDR_ANY, BIS_LINK, &flags);
6427+
mask |= hci_proto_connect_ind(hdev, BDADDR_ANY, PA_LINK, &flags);
64276428
if (!(mask & HCI_LM_ACCEPT))
64286429
goto unlock;
64296430

net/bluetooth/hci_sync.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,7 +2929,7 @@ static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type,
29292929
if (sent) {
29302930
struct hci_conn *conn;
29312931

2932-
conn = hci_conn_hash_lookup_ba(hdev, BIS_LINK,
2932+
conn = hci_conn_hash_lookup_ba(hdev, PA_LINK,
29332933
&sent->bdaddr);
29342934
if (conn) {
29352935
struct bt_iso_qos *qos = &conn->iso_qos;
@@ -5493,7 +5493,7 @@ static int hci_disconnect_sync(struct hci_dev *hdev, struct hci_conn *conn,
54935493
{
54945494
struct hci_cp_disconnect cp;
54955495

5496-
if (conn->type == BIS_LINK) {
5496+
if (conn->type == BIS_LINK || conn->type == PA_LINK) {
54975497
/* This is a BIS connection, hci_conn_del will
54985498
* do the necessary cleanup.
54995499
*/
@@ -5562,7 +5562,7 @@ static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn,
55625562
return HCI_ERROR_LOCAL_HOST_TERM;
55635563
}
55645564

5565-
if (conn->type == BIS_LINK) {
5565+
if (conn->type == BIS_LINK || conn->type == PA_LINK) {
55665566
/* There is no way to cancel a BIS without terminating the BIG
55675567
* which is done later on connection cleanup.
55685568
*/
@@ -5627,7 +5627,7 @@ static int hci_reject_conn_sync(struct hci_dev *hdev, struct hci_conn *conn,
56275627
if (conn->type == CIS_LINK)
56285628
return hci_le_reject_cis_sync(hdev, conn, reason);
56295629

5630-
if (conn->type == BIS_LINK)
5630+
if (conn->type == BIS_LINK || conn->type == PA_LINK)
56315631
return -EINVAL;
56325632

56335633
if (conn->type == SCO_LINK || conn->type == ESCO_LINK)
@@ -6992,7 +6992,7 @@ static void create_pa_complete(struct hci_dev *hdev, void *data, int err)
69926992
goto unlock;
69936993

69946994
/* Add connection to indicate PA sync error */
6995-
pa_sync = hci_conn_add_unset(hdev, BIS_LINK, BDADDR_ANY,
6995+
pa_sync = hci_conn_add_unset(hdev, PA_LINK, BDADDR_ANY,
69966996
HCI_ROLE_SLAVE);
69976997

69986998
if (IS_ERR(pa_sync))

net/bluetooth/iso.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,8 @@ int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
22262226

22272227
static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
22282228
{
2229-
if (hcon->type != CIS_LINK && hcon->type != BIS_LINK) {
2229+
if (hcon->type != CIS_LINK && hcon->type != BIS_LINK &&
2230+
hcon->type != PA_LINK) {
22302231
if (hcon->type != LE_LINK)
22312232
return;
22322233

@@ -2267,7 +2268,8 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
22672268

22682269
static void iso_disconn_cfm(struct hci_conn *hcon, __u8 reason)
22692270
{
2270-
if (hcon->type != CIS_LINK && hcon->type != BIS_LINK)
2271+
if (hcon->type != CIS_LINK && hcon->type != BIS_LINK &&
2272+
hcon->type != PA_LINK)
22712273
return;
22722274

22732275
BT_DBG("hcon %p reason %d", hcon, reason);

net/bluetooth/mgmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3237,6 +3237,7 @@ static u8 link_to_bdaddr(u8 link_type, u8 addr_type)
32373237
switch (link_type) {
32383238
case CIS_LINK:
32393239
case BIS_LINK:
3240+
case PA_LINK:
32403241
case LE_LINK:
32413242
switch (addr_type) {
32423243
case ADDR_LE_DEV_PUBLIC:

0 commit comments

Comments
 (0)