@@ -939,11 +939,37 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
939939{
940940 struct hci_conn * conn ;
941941
942+ switch (type ) {
943+ case ACL_LINK :
944+ if (!hdev -> acl_mtu )
945+ return ERR_PTR (- ECONNREFUSED );
946+ break ;
947+ case ISO_LINK :
948+ if (hdev -> iso_mtu )
949+ /* Dedicated ISO Buffer exists */
950+ break ;
951+ fallthrough ;
952+ case LE_LINK :
953+ if (hdev -> le_mtu && hdev -> le_mtu < HCI_MIN_LE_MTU )
954+ return ERR_PTR (- ECONNREFUSED );
955+ if (!hdev -> le_mtu && hdev -> acl_mtu < HCI_MIN_LE_MTU )
956+ return ERR_PTR (- ECONNREFUSED );
957+ break ;
958+ case SCO_LINK :
959+ case ESCO_LINK :
960+ if (!hdev -> sco_pkts )
961+ /* Controller does not support SCO or eSCO over HCI */
962+ return ERR_PTR (- ECONNREFUSED );
963+ break ;
964+ default :
965+ return ERR_PTR (- ECONNREFUSED );
966+ }
967+
942968 bt_dev_dbg (hdev , "dst %pMR handle 0x%4.4x" , dst , handle );
943969
944970 conn = kzalloc (sizeof (* conn ), GFP_KERNEL );
945971 if (!conn )
946- return NULL ;
972+ return ERR_PTR ( - ENOMEM ) ;
947973
948974 bacpy (& conn -> dst , dst );
949975 bacpy (& conn -> src , & hdev -> bdaddr );
@@ -974,10 +1000,12 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
9741000 switch (type ) {
9751001 case ACL_LINK :
9761002 conn -> pkt_type = hdev -> pkt_type & ACL_PTYPE_MASK ;
1003+ conn -> mtu = hdev -> acl_mtu ;
9771004 break ;
9781005 case LE_LINK :
9791006 /* conn->src should reflect the local identity address */
9801007 hci_copy_identity_address (hdev , & conn -> src , & conn -> src_type );
1008+ conn -> mtu = hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
9811009 break ;
9821010 case ISO_LINK :
9831011 /* conn->src should reflect the local identity address */
@@ -989,16 +1017,21 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
9891017 else if (conn -> role == HCI_ROLE_MASTER )
9901018 conn -> cleanup = cis_cleanup ;
9911019
1020+ conn -> mtu = hdev -> iso_mtu ? hdev -> iso_mtu :
1021+ hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
9921022 break ;
9931023 case SCO_LINK :
9941024 if (lmp_esco_capable (hdev ))
9951025 conn -> pkt_type = (hdev -> esco_type & SCO_ESCO_MASK ) |
9961026 (hdev -> esco_type & EDR_ESCO_MASK );
9971027 else
9981028 conn -> pkt_type = hdev -> pkt_type & SCO_PTYPE_MASK ;
1029+
1030+ conn -> mtu = hdev -> sco_mtu ;
9991031 break ;
10001032 case ESCO_LINK :
10011033 conn -> pkt_type = hdev -> esco_type & ~EDR_ESCO_MASK ;
1034+ conn -> mtu = hdev -> sco_mtu ;
10021035 break ;
10031036 }
10041037
@@ -1041,7 +1074,7 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
10411074
10421075 handle = hci_conn_hash_alloc_unset (hdev );
10431076 if (unlikely (handle < 0 ))
1044- return NULL ;
1077+ return ERR_PTR ( - ECONNREFUSED ) ;
10451078
10461079 return hci_conn_add (hdev , type , dst , role , handle );
10471080}
@@ -1384,8 +1417,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
13841417 bacpy (& conn -> dst , dst );
13851418 } else {
13861419 conn = hci_conn_add_unset (hdev , LE_LINK , dst , role );
1387- if (! conn )
1388- return ERR_PTR ( - ENOMEM ) ;
1420+ if (IS_ERR ( conn ) )
1421+ return conn ;
13891422 hci_conn_hold (conn );
13901423 conn -> pending_sec_level = sec_level ;
13911424 }
@@ -1549,8 +1582,8 @@ static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
15491582 return ERR_PTR (- EADDRINUSE );
15501583
15511584 conn = hci_conn_add_unset (hdev , ISO_LINK , dst , HCI_ROLE_MASTER );
1552- if (! conn )
1553- return ERR_PTR ( - ENOMEM ) ;
1585+ if (IS_ERR ( conn ) )
1586+ return conn ;
15541587
15551588 conn -> state = BT_CONNECT ;
15561589
@@ -1593,8 +1626,8 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
15931626 BT_DBG ("requesting refresh of dst_addr" );
15941627
15951628 conn = hci_conn_add_unset (hdev , LE_LINK , dst , HCI_ROLE_MASTER );
1596- if (! conn )
1597- return ERR_PTR ( - ENOMEM ) ;
1629+ if (IS_ERR ( conn ) )
1630+ return conn ;
15981631
15991632 if (hci_explicit_conn_params_set (hdev , dst , dst_type ) < 0 ) {
16001633 hci_conn_del (conn );
@@ -1641,8 +1674,8 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
16411674 acl = hci_conn_hash_lookup_ba (hdev , ACL_LINK , dst );
16421675 if (!acl ) {
16431676 acl = hci_conn_add_unset (hdev , ACL_LINK , dst , HCI_ROLE_MASTER );
1644- if (! acl )
1645- return ERR_PTR ( - ENOMEM ) ;
1677+ if (IS_ERR ( acl ) )
1678+ return acl ;
16461679 }
16471680
16481681 hci_conn_hold (acl );
@@ -1701,9 +1734,9 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
17011734 sco = hci_conn_hash_lookup_ba (hdev , type , dst );
17021735 if (!sco ) {
17031736 sco = hci_conn_add_unset (hdev , type , dst , HCI_ROLE_MASTER );
1704- if (! sco ) {
1737+ if (IS_ERR ( sco ) ) {
17051738 hci_conn_drop (acl );
1706- return ERR_PTR ( - ENOMEM ) ;
1739+ return sco ;
17071740 }
17081741 }
17091742
@@ -1893,8 +1926,8 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
18931926 qos -> ucast .cis );
18941927 if (!cis ) {
18951928 cis = hci_conn_add_unset (hdev , ISO_LINK , dst , HCI_ROLE_MASTER );
1896- if (! cis )
1897- return ERR_PTR ( - ENOMEM ) ;
1929+ if (IS_ERR ( cis ) )
1930+ return cis ;
18981931 cis -> cleanup = cis_cleanup ;
18991932 cis -> dst_type = dst_type ;
19001933 cis -> iso_qos .ucast .cig = BT_ISO_QOS_CIG_UNSET ;
@@ -2029,14 +2062,8 @@ static void hci_iso_qos_setup(struct hci_dev *hdev, struct hci_conn *conn,
20292062 struct bt_iso_io_qos * qos , __u8 phy )
20302063{
20312064 /* Only set MTU if PHY is enabled */
2032- if (!qos -> sdu && qos -> phy ) {
2033- if (hdev -> iso_mtu > 0 )
2034- qos -> sdu = hdev -> iso_mtu ;
2035- else if (hdev -> le_mtu > 0 )
2036- qos -> sdu = hdev -> le_mtu ;
2037- else
2038- qos -> sdu = hdev -> acl_mtu ;
2039- }
2065+ if (!qos -> sdu && qos -> phy )
2066+ qos -> sdu = conn -> mtu ;
20402067
20412068 /* Use the same PHY as ACL if set to any */
20422069 if (qos -> phy == BT_ISO_PHY_ANY )
0 commit comments