diff mbox series

[v1,2/7] Bluetooth: Support reading of codecs supported over l2cap socket

Message ID 20211008135853.8604-2-kiran.k@intel.com (mailing list archive)
State Superseded
Headers show
Series [v1,1/7] Bluetooth: Refactor code to read supported codecs in getsockopt | expand

Checks

Context Check Description
tedd_an/checkpatch fail [v1,2/7] Bluetooth: Support reading of codecs supported over l2cap socket\ERROR:GERRIT_CHANGE_ID: Remove Gerrit Change-Id's before submitting upstream #57: Change-Id: I1592f3bb1167771bfb2cb9114438e473ea372c90 total: 1 errors, 0 warnings, 0 checks, 39 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/12545459.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/gitlint success Gitlint PASS

Commit Message

K, Kiran Oct. 8, 2021, 1:58 p.m. UTC
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 <kiran.k@intel.com>
Change-Id: I1592f3bb1167771bfb2cb9114438e473ea372c90
---
 include/net/bluetooth/hci.h |  1 +
 net/bluetooth/l2cap_sock.c  | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 63065bc01b76..451d491f7f68 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -2666,6 +2666,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 160c016a5dfb..06f8ea681972 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)
@@ -549,6 +550,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);
 
@@ -685,6 +687,18 @@  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;
+		}
+
+		err = hci_get_supported_codecs(hdev, HCI_TRANSPORT_ACL, optval,
+					       optlen, len);
+		hci_dev_put(hdev);
+		break;
+
 	default:
 		err = -ENOPROTOOPT;
 		break;