@@ -909,11 +909,37 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
909
909
{
910
910
struct hci_conn * conn ;
911
911
912
+ switch (type ) {
913
+ case ACL_LINK :
914
+ if (!hdev -> acl_mtu )
915
+ return ERR_PTR (- ECONNREFUSED );
916
+ break ;
917
+ case ISO_LINK :
918
+ if (hdev -> iso_mtu )
919
+ /* Dedicated ISO Buffer exists */
920
+ break ;
921
+ fallthrough ;
922
+ case LE_LINK :
923
+ if (hdev -> le_mtu && hdev -> le_mtu < HCI_MIN_LE_MTU )
924
+ return ERR_PTR (- ECONNREFUSED );
925
+ if (!hdev -> le_mtu && hdev -> acl_mtu < HCI_MIN_LE_MTU )
926
+ return ERR_PTR (- ECONNREFUSED );
927
+ break ;
928
+ case SCO_LINK :
929
+ case ESCO_LINK :
930
+ if (!hdev -> sco_pkts )
931
+ /* Controller does not support SCO or eSCO over HCI */
932
+ return ERR_PTR (- ECONNREFUSED );
933
+ break ;
934
+ default :
935
+ return ERR_PTR (- ECONNREFUSED );
936
+ }
937
+
912
938
bt_dev_dbg (hdev , "dst %pMR handle 0x%4.4x" , dst , handle );
913
939
914
940
conn = kzalloc (sizeof (* conn ), GFP_KERNEL );
915
941
if (!conn )
916
- return NULL ;
942
+ return ERR_PTR ( - ENOMEM ) ;
917
943
918
944
bacpy (& conn -> dst , dst );
919
945
bacpy (& conn -> src , & hdev -> bdaddr );
@@ -944,10 +970,12 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
944
970
switch (type ) {
945
971
case ACL_LINK :
946
972
conn -> pkt_type = hdev -> pkt_type & ACL_PTYPE_MASK ;
973
+ conn -> mtu = hdev -> acl_mtu ;
947
974
break ;
948
975
case LE_LINK :
949
976
/* conn->src should reflect the local identity address */
950
977
hci_copy_identity_address (hdev , & conn -> src , & conn -> src_type );
978
+ conn -> mtu = hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
951
979
break ;
952
980
case ISO_LINK :
953
981
/* conn->src should reflect the local identity address */
@@ -959,16 +987,21 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
959
987
else if (conn -> role == HCI_ROLE_MASTER )
960
988
conn -> cleanup = cis_cleanup ;
961
989
990
+ conn -> mtu = hdev -> iso_mtu ? hdev -> iso_mtu :
991
+ hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
962
992
break ;
963
993
case SCO_LINK :
964
994
if (lmp_esco_capable (hdev ))
965
995
conn -> pkt_type = (hdev -> esco_type & SCO_ESCO_MASK ) |
966
996
(hdev -> esco_type & EDR_ESCO_MASK );
967
997
else
968
998
conn -> pkt_type = hdev -> pkt_type & SCO_PTYPE_MASK ;
999
+
1000
+ conn -> mtu = hdev -> sco_mtu ;
969
1001
break ;
970
1002
case ESCO_LINK :
971
1003
conn -> pkt_type = hdev -> esco_type & ~EDR_ESCO_MASK ;
1004
+ conn -> mtu = hdev -> sco_mtu ;
972
1005
break ;
973
1006
}
974
1007
@@ -1011,7 +1044,7 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
1011
1044
1012
1045
handle = hci_conn_hash_alloc_unset (hdev );
1013
1046
if (unlikely (handle < 0 ))
1014
- return NULL ;
1047
+ return ERR_PTR ( - ECONNREFUSED ) ;
1015
1048
1016
1049
return hci_conn_add (hdev , type , dst , role , handle );
1017
1050
}
@@ -1317,8 +1350,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1317
1350
bacpy (& conn -> dst , dst );
1318
1351
} else {
1319
1352
conn = hci_conn_add_unset (hdev , LE_LINK , dst , role );
1320
- if (! conn )
1321
- return ERR_PTR ( - ENOMEM ) ;
1353
+ if (IS_ERR ( conn ) )
1354
+ return conn ;
1322
1355
hci_conn_hold (conn );
1323
1356
conn -> pending_sec_level = sec_level ;
1324
1357
}
@@ -1494,8 +1527,8 @@ static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
1494
1527
return ERR_PTR (- EADDRINUSE );
1495
1528
1496
1529
conn = hci_conn_add_unset (hdev , ISO_LINK , dst , HCI_ROLE_MASTER );
1497
- if (! conn )
1498
- return ERR_PTR ( - ENOMEM ) ;
1530
+ if (IS_ERR ( conn ) )
1531
+ return conn ;
1499
1532
1500
1533
conn -> state = BT_CONNECT ;
1501
1534
@@ -1538,8 +1571,8 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
1538
1571
BT_DBG ("requesting refresh of dst_addr" );
1539
1572
1540
1573
conn = hci_conn_add_unset (hdev , LE_LINK , dst , HCI_ROLE_MASTER );
1541
- if (! conn )
1542
- return ERR_PTR ( - ENOMEM ) ;
1574
+ if (IS_ERR ( conn ) )
1575
+ return conn ;
1543
1576
1544
1577
if (hci_explicit_conn_params_set (hdev , dst , dst_type ) < 0 ) {
1545
1578
hci_conn_del (conn );
@@ -1586,8 +1619,8 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
1586
1619
acl = hci_conn_hash_lookup_ba (hdev , ACL_LINK , dst );
1587
1620
if (!acl ) {
1588
1621
acl = hci_conn_add_unset (hdev , ACL_LINK , dst , HCI_ROLE_MASTER );
1589
- if (! acl )
1590
- return ERR_PTR ( - ENOMEM ) ;
1622
+ if (IS_ERR ( acl ) )
1623
+ return acl ;
1591
1624
}
1592
1625
1593
1626
hci_conn_hold (acl );
@@ -1655,9 +1688,9 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1655
1688
sco = hci_conn_hash_lookup_ba (hdev , type , dst );
1656
1689
if (!sco ) {
1657
1690
sco = hci_conn_add_unset (hdev , type , dst , HCI_ROLE_MASTER );
1658
- if (! sco ) {
1691
+ if (IS_ERR ( sco ) ) {
1659
1692
hci_conn_drop (acl );
1660
- return ERR_PTR ( - ENOMEM ) ;
1693
+ return sco ;
1661
1694
}
1662
1695
}
1663
1696
@@ -1847,8 +1880,8 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
1847
1880
qos -> ucast .cis );
1848
1881
if (!cis ) {
1849
1882
cis = hci_conn_add_unset (hdev , ISO_LINK , dst , HCI_ROLE_MASTER );
1850
- if (! cis )
1851
- return ERR_PTR ( - ENOMEM ) ;
1883
+ if (IS_ERR ( cis ) )
1884
+ return cis ;
1852
1885
cis -> cleanup = cis_cleanup ;
1853
1886
cis -> dst_type = dst_type ;
1854
1887
cis -> iso_qos .ucast .cig = BT_ISO_QOS_CIG_UNSET ;
@@ -1983,14 +2016,8 @@ static void hci_iso_qos_setup(struct hci_dev *hdev, struct hci_conn *conn,
1983
2016
struct bt_iso_io_qos * qos , __u8 phy )
1984
2017
{
1985
2018
/* Only set MTU if PHY is enabled */
1986
- if (!qos -> sdu && qos -> phy ) {
1987
- if (hdev -> iso_mtu > 0 )
1988
- qos -> sdu = hdev -> iso_mtu ;
1989
- else if (hdev -> le_mtu > 0 )
1990
- qos -> sdu = hdev -> le_mtu ;
1991
- else
1992
- qos -> sdu = hdev -> acl_mtu ;
1993
- }
2019
+ if (!qos -> sdu && qos -> phy )
2020
+ qos -> sdu = conn -> mtu ;
1994
2021
1995
2022
/* Use the same PHY as ACL if set to any */
1996
2023
if (qos -> phy == BT_ISO_PHY_ANY )
@@ -2071,8 +2098,8 @@ struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
2071
2098
return ERR_PTR (- EBUSY );
2072
2099
2073
2100
conn = hci_conn_add_unset (hdev , ISO_LINK , dst , HCI_ROLE_SLAVE );
2074
- if (! conn )
2075
- return ERR_PTR ( - ENOMEM ) ;
2101
+ if (IS_ERR ( conn ) )
2102
+ return conn ;
2076
2103
2077
2104
conn -> iso_qos = * qos ;
2078
2105
conn -> state = BT_LISTEN ;
0 commit comments