@@ -330,8 +330,11 @@ static void hci_add_sco(struct hci_conn *conn, __u16 handle)
330
330
static bool find_next_esco_param (struct hci_conn * conn ,
331
331
const struct sco_param * esco_param , int size )
332
332
{
333
+ if (!conn -> parent )
334
+ return false;
335
+
333
336
for (; conn -> attempt <= size ; conn -> attempt ++ ) {
334
- if (lmp_esco_2m_capable (conn -> link ) ||
337
+ if (lmp_esco_2m_capable (conn -> parent ) ||
335
338
(esco_param [conn -> attempt - 1 ].pkt_type & ESCO_2EV3 ))
336
339
break ;
337
340
BT_DBG ("hcon %p skipped attempt %d, eSCO 2M not supported" ,
@@ -461,7 +464,7 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
461
464
break ;
462
465
463
466
case BT_CODEC_CVSD :
464
- if (lmp_esco_capable (conn -> link )) {
467
+ if (conn -> parent && lmp_esco_capable (conn -> parent )) {
465
468
if (!find_next_esco_param (conn , esco_param_cvsd ,
466
469
ARRAY_SIZE (esco_param_cvsd )))
467
470
return - EINVAL ;
@@ -531,7 +534,7 @@ static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle)
531
534
param = & esco_param_msbc [conn -> attempt - 1 ];
532
535
break ;
533
536
case SCO_AIRMODE_CVSD :
534
- if (lmp_esco_capable (conn -> link )) {
537
+ if (conn -> parent && lmp_esco_capable (conn -> parent )) {
535
538
if (!find_next_esco_param (conn , esco_param_cvsd ,
536
539
ARRAY_SIZE (esco_param_cvsd )))
537
540
return false;
@@ -637,21 +640,22 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
637
640
/* Device _must_ be locked */
638
641
void hci_sco_setup (struct hci_conn * conn , __u8 status )
639
642
{
640
- struct hci_conn * sco = conn -> link ;
643
+ struct hci_link * link ;
641
644
642
- if (!sco )
645
+ link = list_first_entry_or_null (& conn -> link_list , struct hci_link , list );
646
+ if (!link || !link -> conn )
643
647
return ;
644
648
645
649
BT_DBG ("hcon %p" , conn );
646
650
647
651
if (!status ) {
648
652
if (lmp_esco_capable (conn -> hdev ))
649
- hci_setup_sync (sco , conn -> handle );
653
+ hci_setup_sync (link -> conn , conn -> handle );
650
654
else
651
- hci_add_sco (sco , conn -> handle );
655
+ hci_add_sco (link -> conn , conn -> handle );
652
656
} else {
653
- hci_connect_cfm (sco , status );
654
- hci_conn_del (sco );
657
+ hci_connect_cfm (link -> conn , status );
658
+ hci_conn_del (link -> conn );
655
659
}
656
660
}
657
661
@@ -1042,6 +1046,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
1042
1046
skb_queue_head_init (& conn -> data_q );
1043
1047
1044
1048
INIT_LIST_HEAD (& conn -> chan_list );
1049
+ INIT_LIST_HEAD (& conn -> link_list );
1045
1050
1046
1051
INIT_DELAYED_WORK (& conn -> disc_work , hci_conn_timeout );
1047
1052
INIT_DELAYED_WORK (& conn -> auto_accept_work , hci_conn_auto_accept );
@@ -1069,15 +1074,39 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
1069
1074
return conn ;
1070
1075
}
1071
1076
1072
- static bool hci_conn_unlink (struct hci_conn * conn )
1077
+ static void hci_conn_unlink (struct hci_conn * conn )
1073
1078
{
1079
+ struct hci_dev * hdev = conn -> hdev ;
1080
+
1081
+ bt_dev_dbg (hdev , "hcon %p" , conn );
1082
+
1083
+ if (!conn -> parent ) {
1084
+ struct hci_link * link , * t ;
1085
+
1086
+ list_for_each_entry_safe (link , t , & conn -> link_list , list )
1087
+ hci_conn_unlink (link -> conn );
1088
+
1089
+ return ;
1090
+ }
1091
+
1074
1092
if (!conn -> link )
1075
- return false;
1093
+ return ;
1094
+
1095
+ hci_conn_put (conn -> parent );
1096
+ conn -> parent = NULL ;
1076
1097
1077
- conn -> link -> link = NULL ;
1098
+ list_del_rcu (& conn -> link -> list );
1099
+ synchronize_rcu ();
1100
+
1101
+ kfree (conn -> link );
1078
1102
conn -> link = NULL ;
1079
1103
1080
- return true;
1104
+ /* Due to race, SCO connection might be not established
1105
+ * yet at this point. Delete it now, otherwise it is
1106
+ * possible for it to be stuck and can't be deleted.
1107
+ */
1108
+ if (conn -> handle == HCI_CONN_HANDLE_UNSET )
1109
+ hci_conn_del (conn );
1081
1110
}
1082
1111
1083
1112
int hci_conn_del (struct hci_conn * conn )
@@ -1091,18 +1120,7 @@ int hci_conn_del(struct hci_conn *conn)
1091
1120
cancel_delayed_work_sync (& conn -> idle_work );
1092
1121
1093
1122
if (conn -> type == ACL_LINK ) {
1094
- struct hci_conn * link = conn -> link ;
1095
-
1096
- if (link ) {
1097
- hci_conn_unlink (conn );
1098
- /* Due to race, SCO connection might be not established
1099
- * yet at this point. Delete it now, otherwise it is
1100
- * possible for it to be stuck and can't be deleted.
1101
- */
1102
- if (link -> handle == HCI_CONN_HANDLE_UNSET )
1103
- hci_conn_del (link );
1104
- }
1105
-
1123
+ hci_conn_unlink (conn );
1106
1124
/* Unacked frames */
1107
1125
hdev -> acl_cnt += conn -> sent ;
1108
1126
} else if (conn -> type == LE_LINK ) {
@@ -1113,7 +1131,7 @@ int hci_conn_del(struct hci_conn *conn)
1113
1131
else
1114
1132
hdev -> acl_cnt += conn -> sent ;
1115
1133
} else {
1116
- struct hci_conn * acl = conn -> link ;
1134
+ struct hci_conn * acl = conn -> parent ;
1117
1135
1118
1136
if (acl ) {
1119
1137
hci_conn_unlink (conn );
@@ -1600,11 +1618,40 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
1600
1618
return acl ;
1601
1619
}
1602
1620
1621
+ static struct hci_link * hci_conn_link (struct hci_conn * parent ,
1622
+ struct hci_conn * conn )
1623
+ {
1624
+ struct hci_dev * hdev = parent -> hdev ;
1625
+ struct hci_link * link ;
1626
+
1627
+ bt_dev_dbg (hdev , "parent %p hcon %p" , parent , conn );
1628
+
1629
+ if (conn -> link )
1630
+ return conn -> link ;
1631
+
1632
+ if (conn -> parent )
1633
+ return NULL ;
1634
+
1635
+ link = kzalloc (sizeof (* link ), GFP_KERNEL );
1636
+ if (!link )
1637
+ return NULL ;
1638
+
1639
+ link -> conn = hci_conn_hold (conn );
1640
+ conn -> link = link ;
1641
+ conn -> parent = hci_conn_get (parent );
1642
+
1643
+ /* Use list_add_tail_rcu append to the list */
1644
+ list_add_tail_rcu (& link -> list , & parent -> link_list );
1645
+
1646
+ return link ;
1647
+ }
1648
+
1603
1649
struct hci_conn * hci_connect_sco (struct hci_dev * hdev , int type , bdaddr_t * dst ,
1604
1650
__u16 setting , struct bt_codec * codec )
1605
1651
{
1606
1652
struct hci_conn * acl ;
1607
1653
struct hci_conn * sco ;
1654
+ struct hci_link * link ;
1608
1655
1609
1656
acl = hci_connect_acl (hdev , dst , BT_SECURITY_LOW , HCI_AT_NO_BONDING ,
1610
1657
CONN_REASON_SCO_CONNECT );
@@ -1620,10 +1667,12 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1620
1667
}
1621
1668
}
1622
1669
1623
- acl -> link = sco ;
1624
- sco -> link = acl ;
1625
-
1626
- hci_conn_hold (sco );
1670
+ link = hci_conn_link (acl , sco );
1671
+ if (!link ) {
1672
+ hci_conn_drop (acl );
1673
+ hci_conn_drop (sco );
1674
+ return NULL ;
1675
+ }
1627
1676
1628
1677
sco -> setting = setting ;
1629
1678
sco -> codec = * codec ;
@@ -1890,7 +1939,7 @@ static int hci_create_cis_sync(struct hci_dev *hdev, void *data)
1890
1939
u8 cig ;
1891
1940
1892
1941
memset (& cmd , 0 , sizeof (cmd ));
1893
- cmd .cis [0 ].acl_handle = cpu_to_le16 (conn -> link -> handle );
1942
+ cmd .cis [0 ].acl_handle = cpu_to_le16 (conn -> parent -> handle );
1894
1943
cmd .cis [0 ].cis_handle = cpu_to_le16 (conn -> handle );
1895
1944
cmd .cp .num_cis ++ ;
1896
1945
cig = conn -> iso_qos .ucast .cig ;
@@ -1903,11 +1952,12 @@ static int hci_create_cis_sync(struct hci_dev *hdev, void *data)
1903
1952
struct hci_cis * cis = & cmd .cis [cmd .cp .num_cis ];
1904
1953
1905
1954
if (conn == data || conn -> type != ISO_LINK ||
1906
- conn -> state == BT_CONNECTED || conn -> iso_qos .ucast .cig != cig )
1955
+ conn -> state == BT_CONNECTED ||
1956
+ conn -> iso_qos .ucast .cig != cig )
1907
1957
continue ;
1908
1958
1909
1959
/* Check if all CIS(s) belonging to a CIG are ready */
1910
- if (!conn -> link || conn -> link -> state != BT_CONNECTED ||
1960
+ if (!conn -> parent || conn -> parent -> state != BT_CONNECTED ||
1911
1961
conn -> state != BT_CONNECT ) {
1912
1962
cmd .cp .num_cis = 0 ;
1913
1963
break ;
@@ -1924,7 +1974,7 @@ static int hci_create_cis_sync(struct hci_dev *hdev, void *data)
1924
1974
* command have been generated, the Controller shall return the
1925
1975
* error code Command Disallowed (0x0C).
1926
1976
*/
1927
- cis -> acl_handle = cpu_to_le16 (conn -> link -> handle );
1977
+ cis -> acl_handle = cpu_to_le16 (conn -> parent -> handle );
1928
1978
cis -> cis_handle = cpu_to_le16 (conn -> handle );
1929
1979
cmd .cp .num_cis ++ ;
1930
1980
}
@@ -1943,15 +1993,33 @@ static int hci_create_cis_sync(struct hci_dev *hdev, void *data)
1943
1993
int hci_le_create_cis (struct hci_conn * conn )
1944
1994
{
1945
1995
struct hci_conn * cis ;
1996
+ struct hci_link * link , * t ;
1946
1997
struct hci_dev * hdev = conn -> hdev ;
1947
1998
int err ;
1948
1999
2000
+ bt_dev_dbg (hdev , "hcon %p" , conn );
2001
+
1949
2002
switch (conn -> type ) {
1950
2003
case LE_LINK :
1951
- if (! conn -> link || conn -> state != BT_CONNECTED )
2004
+ if (conn -> state != BT_CONNECTED || list_empty ( & conn -> link_list ) )
1952
2005
return - EINVAL ;
1953
- cis = conn -> link ;
1954
- break ;
2006
+
2007
+ cis = NULL ;
2008
+
2009
+ /* hci_conn_link uses list_add_tail_rcu so the list is in
2010
+ * the same order as the connections are requested.
2011
+ */
2012
+ list_for_each_entry_safe (link , t , & conn -> link_list , list ) {
2013
+ if (link -> conn -> state == BT_BOUND ) {
2014
+ err = hci_le_create_cis (link -> conn );
2015
+ if (err )
2016
+ return err ;
2017
+
2018
+ cis = link -> conn ;
2019
+ }
2020
+ }
2021
+
2022
+ return cis ? 0 : - EINVAL ;
1955
2023
case ISO_LINK :
1956
2024
cis = conn ;
1957
2025
break ;
@@ -2172,6 +2240,7 @@ struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
2172
2240
{
2173
2241
struct hci_conn * le ;
2174
2242
struct hci_conn * cis ;
2243
+ struct hci_link * link ;
2175
2244
2176
2245
if (hci_dev_test_flag (hdev , HCI_ADVERTISING ))
2177
2246
le = hci_connect_le (hdev , dst , dst_type , false,
@@ -2197,16 +2266,18 @@ struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
2197
2266
return cis ;
2198
2267
}
2199
2268
2200
- le -> link = cis ;
2201
- cis -> link = le ;
2202
-
2203
- hci_conn_hold (cis );
2269
+ link = hci_conn_link (le , cis );
2270
+ if (!link ) {
2271
+ hci_conn_drop (le );
2272
+ hci_conn_drop (cis );
2273
+ return NULL ;
2274
+ }
2204
2275
2205
2276
/* If LE is already connected and CIS handle is already set proceed to
2206
2277
* Create CIS immediately.
2207
2278
*/
2208
2279
if (le -> state == BT_CONNECTED && cis -> handle != HCI_CONN_HANDLE_UNSET )
2209
- hci_le_create_cis (le );
2280
+ hci_le_create_cis (cis );
2210
2281
2211
2282
return cis ;
2212
2283
}
0 commit comments