@@ -904,11 +904,37 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
904
904
{
905
905
struct hci_conn * conn ;
906
906
907
+ switch (type ) {
908
+ case ACL_LINK :
909
+ if (!hdev -> acl_mtu )
910
+ return ERR_PTR (- ECONNREFUSED );
911
+ break ;
912
+ case ISO_LINK :
913
+ if (hdev -> iso_mtu )
914
+ /* Dedicated ISO Buffer exists */
915
+ break ;
916
+ fallthrough ;
917
+ case LE_LINK :
918
+ if (hdev -> le_mtu && hdev -> le_mtu < HCI_MIN_LE_MTU )
919
+ return ERR_PTR (- ECONNREFUSED );
920
+ if (!hdev -> le_mtu && hdev -> acl_mtu < HCI_MIN_LE_MTU )
921
+ return ERR_PTR (- ECONNREFUSED );
922
+ break ;
923
+ case SCO_LINK :
924
+ case ESCO_LINK :
925
+ if (!hdev -> sco_pkts )
926
+ /* Controller does not support SCO or eSCO over HCI */
927
+ return ERR_PTR (- ECONNREFUSED );
928
+ break ;
929
+ default :
930
+ return ERR_PTR (- ECONNREFUSED );
931
+ }
932
+
907
933
bt_dev_dbg (hdev , "dst %pMR handle 0x%4.4x" , dst , handle );
908
934
909
935
conn = kzalloc (sizeof (* conn ), GFP_KERNEL );
910
936
if (!conn )
911
- return NULL ;
937
+ return ERR_PTR ( - ENOMEM ) ;
912
938
913
939
bacpy (& conn -> dst , dst );
914
940
bacpy (& conn -> src , & hdev -> bdaddr );
@@ -939,10 +965,12 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
939
965
switch (type ) {
940
966
case ACL_LINK :
941
967
conn -> pkt_type = hdev -> pkt_type & ACL_PTYPE_MASK ;
968
+ conn -> mtu = hdev -> acl_mtu ;
942
969
break ;
943
970
case LE_LINK :
944
971
/* conn->src should reflect the local identity address */
945
972
hci_copy_identity_address (hdev , & conn -> src , & conn -> src_type );
973
+ conn -> mtu = hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
946
974
break ;
947
975
case ISO_LINK :
948
976
/* conn->src should reflect the local identity address */
@@ -954,16 +982,21 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
954
982
else if (conn -> role == HCI_ROLE_MASTER )
955
983
conn -> cleanup = cis_cleanup ;
956
984
985
+ conn -> mtu = hdev -> iso_mtu ? hdev -> iso_mtu :
986
+ hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
957
987
break ;
958
988
case SCO_LINK :
959
989
if (lmp_esco_capable (hdev ))
960
990
conn -> pkt_type = (hdev -> esco_type & SCO_ESCO_MASK ) |
961
991
(hdev -> esco_type & EDR_ESCO_MASK );
962
992
else
963
993
conn -> pkt_type = hdev -> pkt_type & SCO_PTYPE_MASK ;
994
+
995
+ conn -> mtu = hdev -> sco_mtu ;
964
996
break ;
965
997
case ESCO_LINK :
966
998
conn -> pkt_type = hdev -> esco_type & ~EDR_ESCO_MASK ;
999
+ conn -> mtu = hdev -> sco_mtu ;
967
1000
break ;
968
1001
}
969
1002
@@ -1006,7 +1039,7 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
1006
1039
1007
1040
handle = hci_conn_hash_alloc_unset (hdev );
1008
1041
if (unlikely (handle < 0 ))
1009
- return NULL ;
1042
+ return ERR_PTR ( - ECONNREFUSED ) ;
1010
1043
1011
1044
return hci_conn_add (hdev , type , dst , role , handle );
1012
1045
}
@@ -1312,8 +1345,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1312
1345
bacpy (& conn -> dst , dst );
1313
1346
} else {
1314
1347
conn = hci_conn_add_unset (hdev , LE_LINK , dst , role );
1315
- if (! conn )
1316
- return ERR_PTR ( - ENOMEM ) ;
1348
+ if (IS_ERR ( conn ) )
1349
+ return conn ;
1317
1350
hci_conn_hold (conn );
1318
1351
conn -> pending_sec_level = sec_level ;
1319
1352
}
@@ -1489,8 +1522,8 @@ static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
1489
1522
return ERR_PTR (- EADDRINUSE );
1490
1523
1491
1524
conn = hci_conn_add_unset (hdev , ISO_LINK , dst , HCI_ROLE_MASTER );
1492
- if (! conn )
1493
- return ERR_PTR ( - ENOMEM ) ;
1525
+ if (IS_ERR ( conn ) )
1526
+ return conn ;
1494
1527
1495
1528
conn -> state = BT_CONNECT ;
1496
1529
@@ -1533,8 +1566,8 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
1533
1566
BT_DBG ("requesting refresh of dst_addr" );
1534
1567
1535
1568
conn = hci_conn_add_unset (hdev , LE_LINK , dst , HCI_ROLE_MASTER );
1536
- if (! conn )
1537
- return ERR_PTR ( - ENOMEM ) ;
1569
+ if (IS_ERR ( conn ) )
1570
+ return conn ;
1538
1571
1539
1572
if (hci_explicit_conn_params_set (hdev , dst , dst_type ) < 0 ) {
1540
1573
hci_conn_del (conn );
@@ -1581,8 +1614,8 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
1581
1614
acl = hci_conn_hash_lookup_ba (hdev , ACL_LINK , dst );
1582
1615
if (!acl ) {
1583
1616
acl = hci_conn_add_unset (hdev , ACL_LINK , dst , HCI_ROLE_MASTER );
1584
- if (! acl )
1585
- return ERR_PTR ( - ENOMEM ) ;
1617
+ if (IS_ERR ( acl ) )
1618
+ return acl ;
1586
1619
}
1587
1620
1588
1621
hci_conn_hold (acl );
@@ -1650,9 +1683,9 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1650
1683
sco = hci_conn_hash_lookup_ba (hdev , type , dst );
1651
1684
if (!sco ) {
1652
1685
sco = hci_conn_add_unset (hdev , type , dst , HCI_ROLE_MASTER );
1653
- if (! sco ) {
1686
+ if (IS_ERR ( sco ) ) {
1654
1687
hci_conn_drop (acl );
1655
- return ERR_PTR ( - ENOMEM ) ;
1688
+ return sco ;
1656
1689
}
1657
1690
}
1658
1691
@@ -1841,8 +1874,8 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
1841
1874
qos -> ucast .cis );
1842
1875
if (!cis ) {
1843
1876
cis = hci_conn_add_unset (hdev , ISO_LINK , dst , HCI_ROLE_MASTER );
1844
- if (! cis )
1845
- return ERR_PTR ( - ENOMEM ) ;
1877
+ if (IS_ERR ( cis ) )
1878
+ return cis ;
1846
1879
cis -> cleanup = cis_cleanup ;
1847
1880
cis -> dst_type = dst_type ;
1848
1881
cis -> iso_qos .ucast .cig = BT_ISO_QOS_CIG_UNSET ;
@@ -1977,14 +2010,8 @@ static void hci_iso_qos_setup(struct hci_dev *hdev, struct hci_conn *conn,
1977
2010
struct bt_iso_io_qos * qos , __u8 phy )
1978
2011
{
1979
2012
/* Only set MTU if PHY is enabled */
1980
- if (!qos -> sdu && qos -> phy ) {
1981
- if (hdev -> iso_mtu > 0 )
1982
- qos -> sdu = hdev -> iso_mtu ;
1983
- else if (hdev -> le_mtu > 0 )
1984
- qos -> sdu = hdev -> le_mtu ;
1985
- else
1986
- qos -> sdu = hdev -> acl_mtu ;
1987
- }
2013
+ if (!qos -> sdu && qos -> phy )
2014
+ qos -> sdu = conn -> mtu ;
1988
2015
1989
2016
/* Use the same PHY as ACL if set to any */
1990
2017
if (qos -> phy == BT_ISO_PHY_ANY )
@@ -2065,8 +2092,8 @@ struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
2065
2092
return ERR_PTR (- EBUSY );
2066
2093
2067
2094
conn = hci_conn_add_unset (hdev , ISO_LINK , dst , HCI_ROLE_SLAVE );
2068
- if (! conn )
2069
- return ERR_PTR ( - ENOMEM ) ;
2095
+ if (IS_ERR ( conn ) )
2096
+ return conn ;
2070
2097
2071
2098
conn -> iso_qos = * qos ;
2072
2099
conn -> state = BT_LISTEN ;
0 commit comments