]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
Bluetooth: L2CAP: Fix using wrong mode
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 8 Dec 2021 23:35:48 +0000 (15:35 -0800)
committerPaolo Pisati <paolo.pisati@canonical.com>
Fri, 28 Jan 2022 09:59:39 +0000 (10:59 +0100)
BugLink: https://bugs.launchpad.net/bugs/1959376
[ Upstream commit 30d57722732d9736554f85f75f9d7ad5402d192e ]

If user has a set to use SOCK_STREAM the socket would default to
L2CAP_MODE_ERTM which later needs to be adjusted if the destination
address is LE which doesn't support such mode.

Fixes: 15f02b9105625 ("Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
net/bluetooth/l2cap_sock.c

index 4574c5cb1b596e80f2613280ef51bdb82f590167..251017c69ab7ffad7a8f120e5ff4c865203fde6f 100644 (file)
@@ -161,7 +161,11 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
                break;
        }
 
-       if (chan->psm && bdaddr_type_is_le(chan->src_type))
+       /* Use L2CAP_MODE_LE_FLOWCTL (CoC) in case of LE address and
+        * L2CAP_MODE_EXT_FLOWCTL (ECRED) has not been set.
+        */
+       if (chan->psm && bdaddr_type_is_le(chan->src_type) &&
+           chan->mode != L2CAP_MODE_EXT_FLOWCTL)
                chan->mode = L2CAP_MODE_LE_FLOWCTL;
 
        chan->state = BT_BOUND;
@@ -255,7 +259,11 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
                        return -EINVAL;
        }
 
-       if (chan->psm && bdaddr_type_is_le(chan->src_type) && !chan->mode)
+       /* Use L2CAP_MODE_LE_FLOWCTL (CoC) in case of LE address and
+        * L2CAP_MODE_EXT_FLOWCTL (ECRED) has not been set.
+        */
+       if (chan->psm && bdaddr_type_is_le(chan->src_type) &&
+           chan->mode != L2CAP_MODE_EXT_FLOWCTL)
                chan->mode = L2CAP_MODE_LE_FLOWCTL;
 
        l2cap_sock_init_pid(sk);