Bluetooth: hci_conn: Fix CIS connection dst_type handling
authorPauli Virtanen <pav@iki.fi>
Tue, 11 Oct 2022 19:25:33 +0000 (22:25 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 2 Nov 2022 21:15:33 +0000 (14:15 -0700)
hci_connect_cis and iso_connect_cis call hci_bind_cis inconsistently
with dst_type being either ISO socket address type or the HCI type, but
these values cannot be mixed like this. Fix this by using only the HCI
type.

CIS connection dst_type was also not initialized in hci_bind_cis, even
though it is used in hci_conn_hash_lookup_cis to find existing
connections.  Set the value in hci_bind_cis, so that existing CIS
connections are found e.g. when doing deferred socket connections, also
when dst_type is not 0 (ADDR_LE_DEV_PUBLIC).

Fixes: 26afbd826ee3 ("Bluetooth: Add initial implementation of CIS connections")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/hci_conn.c
net/bluetooth/iso.c

index 7a59c44..1176bad 100644 (file)
@@ -1761,6 +1761,7 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
                if (!cis)
                        return ERR_PTR(-ENOMEM);
                cis->cleanup = cis_cleanup;
+               cis->dst_type = dst_type;
        }
 
        if (cis->state == BT_CONNECTED)
@@ -2140,12 +2141,6 @@ struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
        struct hci_conn *le;
        struct hci_conn *cis;
 
-       /* Convert from ISO socket address type to HCI address type  */
-       if (dst_type == BDADDR_LE_PUBLIC)
-               dst_type = ADDR_LE_DEV_PUBLIC;
-       else
-               dst_type = ADDR_LE_DEV_RANDOM;
-
        if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
                le = hci_connect_le(hdev, dst, dst_type, false,
                                    BT_SECURITY_LOW,
index 613039b..f825857 100644 (file)
@@ -235,6 +235,14 @@ static int iso_chan_add(struct iso_conn *conn, struct sock *sk,
        return err;
 }
 
+static inline u8 le_addr_type(u8 bdaddr_type)
+{
+       if (bdaddr_type == BDADDR_LE_PUBLIC)
+               return ADDR_LE_DEV_PUBLIC;
+       else
+               return ADDR_LE_DEV_RANDOM;
+}
+
 static int iso_connect_bis(struct sock *sk)
 {
        struct iso_conn *conn;
@@ -328,14 +336,16 @@ static int iso_connect_cis(struct sock *sk)
        /* Just bind if DEFER_SETUP has been set */
        if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
                hcon = hci_bind_cis(hdev, &iso_pi(sk)->dst,
-                                   iso_pi(sk)->dst_type, &iso_pi(sk)->qos);
+                                   le_addr_type(iso_pi(sk)->dst_type),
+                                   &iso_pi(sk)->qos);
                if (IS_ERR(hcon)) {
                        err = PTR_ERR(hcon);
                        goto done;
                }
        } else {
                hcon = hci_connect_cis(hdev, &iso_pi(sk)->dst,
-                                      iso_pi(sk)->dst_type, &iso_pi(sk)->qos);
+                                      le_addr_type(iso_pi(sk)->dst_type),
+                                      &iso_pi(sk)->qos);
                if (IS_ERR(hcon)) {
                        err = PTR_ERR(hcon);
                        goto done;