@@ -909,11 +909,37 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
909909{
910910 struct hci_conn * conn ;
911911
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+
912938 bt_dev_dbg (hdev , "dst %pMR handle 0x%4.4x" , dst , handle );
913939
914940 conn = kzalloc (sizeof (* conn ), GFP_KERNEL );
915941 if (!conn )
916- return NULL ;
942+ return ERR_PTR ( - ENOMEM ) ;
917943
918944 bacpy (& conn -> dst , dst );
919945 bacpy (& conn -> src , & hdev -> bdaddr );
@@ -944,10 +970,12 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
944970 switch (type ) {
945971 case ACL_LINK :
946972 conn -> pkt_type = hdev -> pkt_type & ACL_PTYPE_MASK ;
973+ conn -> mtu = hdev -> acl_mtu ;
947974 break ;
948975 case LE_LINK :
949976 /* conn->src should reflect the local identity address */
950977 hci_copy_identity_address (hdev , & conn -> src , & conn -> src_type );
978+ conn -> mtu = hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
951979 break ;
952980 case ISO_LINK :
953981 /* 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,
959987 else if (conn -> role == HCI_ROLE_MASTER )
960988 conn -> cleanup = cis_cleanup ;
961989
990+ conn -> mtu = hdev -> iso_mtu ? hdev -> iso_mtu :
991+ hdev -> le_mtu ? hdev -> le_mtu : hdev -> acl_mtu ;
962992 break ;
963993 case SCO_LINK :
964994 if (lmp_esco_capable (hdev ))
965995 conn -> pkt_type = (hdev -> esco_type & SCO_ESCO_MASK ) |
966996 (hdev -> esco_type & EDR_ESCO_MASK );
967997 else
968998 conn -> pkt_type = hdev -> pkt_type & SCO_PTYPE_MASK ;
999+
1000+ conn -> mtu = hdev -> sco_mtu ;
9691001 break ;
9701002 case ESCO_LINK :
9711003 conn -> pkt_type = hdev -> esco_type & ~EDR_ESCO_MASK ;
1004+ conn -> mtu = hdev -> sco_mtu ;
9721005 break ;
9731006 }
9741007
@@ -1011,7 +1044,7 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
10111044
10121045 handle = hci_conn_hash_alloc_unset (hdev );
10131046 if (unlikely (handle < 0 ))
1014- return NULL ;
1047+ return ERR_PTR ( - ECONNREFUSED ) ;
10151048
10161049 return hci_conn_add (hdev , type , dst , role , handle );
10171050}
@@ -1317,8 +1350,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
13171350 bacpy (& conn -> dst , dst );
13181351 } else {
13191352 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 ;
13221355 hci_conn_hold (conn );
13231356 conn -> pending_sec_level = sec_level ;
13241357 }
@@ -1494,8 +1527,8 @@ static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
14941527 return ERR_PTR (- EADDRINUSE );
14951528
14961529 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 ;
14991532
15001533 conn -> state = BT_CONNECT ;
15011534
@@ -1538,8 +1571,8 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
15381571 BT_DBG ("requesting refresh of dst_addr" );
15391572
15401573 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 ;
15431576
15441577 if (hci_explicit_conn_params_set (hdev , dst , dst_type ) < 0 ) {
15451578 hci_conn_del (conn );
@@ -1586,8 +1619,8 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
15861619 acl = hci_conn_hash_lookup_ba (hdev , ACL_LINK , dst );
15871620 if (!acl ) {
15881621 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 ;
15911624 }
15921625
15931626 hci_conn_hold (acl );
@@ -1655,9 +1688,9 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
16551688 sco = hci_conn_hash_lookup_ba (hdev , type , dst );
16561689 if (!sco ) {
16571690 sco = hci_conn_add_unset (hdev , type , dst , HCI_ROLE_MASTER );
1658- if (! sco ) {
1691+ if (IS_ERR ( sco ) ) {
16591692 hci_conn_drop (acl );
1660- return ERR_PTR ( - ENOMEM ) ;
1693+ return sco ;
16611694 }
16621695 }
16631696
@@ -1847,8 +1880,8 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
18471880 qos -> ucast .cis );
18481881 if (!cis ) {
18491882 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 ;
18521885 cis -> cleanup = cis_cleanup ;
18531886 cis -> dst_type = dst_type ;
18541887 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,
19832016 struct bt_iso_io_qos * qos , __u8 phy )
19842017{
19852018 /* 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 ;
19942021
19952022 /* Use the same PHY as ACL if set to any */
19962023 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,
20712098 return ERR_PTR (- EBUSY );
20722099
20732100 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 ;
20762103
20772104 conn -> iso_qos = * qos ;
20782105 conn -> state = BT_LISTEN ;
0 commit comments