@@ -904,11 +904,37 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
904904{
905905 struct hci_conn * conn ;
906906
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+
907933 bt_dev_dbg (hdev , "dst %pMR handle 0x%4.4x" , dst , handle );
908934
909935 conn = kzalloc (sizeof (* conn ), GFP_KERNEL );
910936 if (!conn )
911- return NULL ;
937+ return ERR_PTR ( - ENOMEM ) ;
912938
913939 bacpy (& conn -> dst , dst );
914940 bacpy (& conn -> src , & hdev -> bdaddr );
@@ -939,10 +965,12 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
939965 switch (type ) {
940966 case ACL_LINK :
941967 conn -> pkt_type = hdev -> pkt_type & ACL_PTYPE_MASK ;
968+ conn -> mtu = hdev -> acl_mtu ;
942969 break ;
943970 case LE_LINK :
944971 /* conn->src should reflect the local identity address */
945972 hci_copy_identity_address (hdev , & conn -> src , & conn -> src_type );
973+ conn -> mtu = hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
946974 break ;
947975 case ISO_LINK :
948976 /* 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,
954982 else if (conn -> role == HCI_ROLE_MASTER )
955983 conn -> cleanup = cis_cleanup ;
956984
985+ conn -> mtu = hdev -> iso_mtu ? hdev -> iso_mtu :
986+ hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
957987 break ;
958988 case SCO_LINK :
959989 if (lmp_esco_capable (hdev ))
960990 conn -> pkt_type = (hdev -> esco_type & SCO_ESCO_MASK ) |
961991 (hdev -> esco_type & EDR_ESCO_MASK );
962992 else
963993 conn -> pkt_type = hdev -> pkt_type & SCO_PTYPE_MASK ;
994+
995+ conn -> mtu = hdev -> sco_mtu ;
964996 break ;
965997 case ESCO_LINK :
966998 conn -> pkt_type = hdev -> esco_type & ~EDR_ESCO_MASK ;
999+ conn -> mtu = hdev -> sco_mtu ;
9671000 break ;
9681001 }
9691002
@@ -1006,7 +1039,7 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
10061039
10071040 handle = hci_conn_hash_alloc_unset (hdev );
10081041 if (unlikely (handle < 0 ))
1009- return NULL ;
1042+ return ERR_PTR ( - ECONNREFUSED ) ;
10101043
10111044 return hci_conn_add (hdev , type , dst , role , handle );
10121045}
@@ -1312,8 +1345,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
13121345 bacpy (& conn -> dst , dst );
13131346 } else {
13141347 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 ;
13171350 hci_conn_hold (conn );
13181351 conn -> pending_sec_level = sec_level ;
13191352 }
@@ -1489,8 +1522,8 @@ static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
14891522 return ERR_PTR (- EADDRINUSE );
14901523
14911524 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 ;
14941527
14951528 conn -> state = BT_CONNECT ;
14961529
@@ -1533,8 +1566,8 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
15331566 BT_DBG ("requesting refresh of dst_addr" );
15341567
15351568 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 ;
15381571
15391572 if (hci_explicit_conn_params_set (hdev , dst , dst_type ) < 0 ) {
15401573 hci_conn_del (conn );
@@ -1581,8 +1614,8 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
15811614 acl = hci_conn_hash_lookup_ba (hdev , ACL_LINK , dst );
15821615 if (!acl ) {
15831616 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 ;
15861619 }
15871620
15881621 hci_conn_hold (acl );
@@ -1650,9 +1683,9 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
16501683 sco = hci_conn_hash_lookup_ba (hdev , type , dst );
16511684 if (!sco ) {
16521685 sco = hci_conn_add_unset (hdev , type , dst , HCI_ROLE_MASTER );
1653- if (! sco ) {
1686+ if (IS_ERR ( sco ) ) {
16541687 hci_conn_drop (acl );
1655- return ERR_PTR ( - ENOMEM ) ;
1688+ return sco ;
16561689 }
16571690 }
16581691
@@ -1841,8 +1874,8 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
18411874 qos -> ucast .cis );
18421875 if (!cis ) {
18431876 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 ;
18461879 cis -> cleanup = cis_cleanup ;
18471880 cis -> dst_type = dst_type ;
18481881 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,
19772010 struct bt_iso_io_qos * qos , __u8 phy )
19782011{
19792012 /* 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 ;
19882015
19892016 /* Use the same PHY as ACL if set to any */
19902017 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,
20652092 return ERR_PTR (- EBUSY );
20662093
20672094 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 ;
20702097
20712098 conn -> iso_qos = * qos ;
20722099 conn -> state = BT_LISTEN ;
0 commit comments