[PATCH v4 02/14] Bluetooth: Support reading of codecs supported over l2cap socket
From: Kiran K <hidden>
Date: 2021-11-19 08:15:00
Subsystem:
bluetooth subsystem, the rest · Maintainers:
Marcel Holtmann, Luiz Augusto von Dentz, Linus Torvalds
Codecs supported for A2DP offload use case are returned over l2cap socket. Add BT_CODEC option to getsockopt to return the codecs. Signed-off-by: Kiran K <redacted> Reviewed-by: Chethan T N <redacted> Reviewed-by: Srivatsa Ravishankar <redacted> --- include/net/bluetooth/hci.h | 2 ++ net/bluetooth/l2cap_sock.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 84db6b275231..e52fd2f1e046 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h@@ -332,6 +332,7 @@ enum { HCI_FORCE_NO_MITM, HCI_QUALITY_REPORT, HCI_OFFLOAD_CODECS_ENABLED, + HCI_MSFT_A2DP_OFFLOAD_CODECS_ENABLED, __HCI_NUM_FLAGS, };
@@ -2667,6 +2668,7 @@ static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb) #define hci_iso_data_flags(h) ((h) >> 14) /* codec transport types */ +#define HCI_TRANSPORT_ACL 0x00 #define HCI_TRANSPORT_SCO_ESCO 0x01 /* le24 support */
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 4574c5cb1b59..3c293d6bd04b 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c@@ -36,6 +36,7 @@ #include <net/bluetooth/l2cap.h> #include "smp.h" +#include "hci_codec.h" static struct bt_sock_list l2cap_sk_list = { .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock)
@@ -568,6 +569,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, struct bt_power pwr; u32 phys; int len, mode, err = 0; + struct hci_dev *hdev; BT_DBG("sk %p", sk);
@@ -704,6 +706,25 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, err = -EFAULT; break; + case BT_CODEC: + hdev = hci_get_route(BDADDR_ANY, &chan->src, BDADDR_BREDR); + if (!hdev) { + err = -EBADFD; + break; + } + + if (!hci_dev_test_flag(hdev, + HCI_MSFT_A2DP_OFFLOAD_CODECS_ENABLED)) { + hci_dev_put(hdev); + err = -EOPNOTSUPP; + break; + } + + err = hci_get_supported_codecs(hdev, HCI_TRANSPORT_ACL, optval, + optlen, len); + hci_dev_put(hdev); + break; + default: err = -ENOPROTOOPT; break;
--
2.17.1