Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/4] btio: Add BT_IO_PHY option
Date: Tue, 18 Feb 2020 16:36:10 -0800	[thread overview]
Message-ID: <20200219003612.14599-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20200219003612.14599-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds BT_IO_PHY option which can be used to read the underline
packet types/PHY in use by the link layer.
---
 btio/btio.c | 37 ++++++++++++++++++++++++++++++++++++-
 btio/btio.h |  1 +
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/btio/btio.c b/btio/btio.c
index af2276db9..db37b99da 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -881,6 +881,7 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
 		case BT_IO_OPT_DEST_CHANNEL:
 		case BT_IO_OPT_HANDLE:
 		case BT_IO_OPT_CLASS:
+		case BT_IO_OPT_PHY:
 		default:
 			g_set_error(err, BT_IO_ERROR, EINVAL,
 					"Unknown option %d", opt);
@@ -968,6 +969,17 @@ static int get_priority(int sock, uint32_t *prio)
 	return 0;
 }
 
+static int get_phy(int sock, uint32_t *phy)
+{
+	socklen_t len;
+
+	len = sizeof(*phy);
+	if (getsockopt(sock, SOL_BLUETOOTH, BT_PHY, phy, &len) < 0)
+		return -errno;
+
+	return 0;
+}
+
 static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
 								va_list args)
 {
@@ -979,7 +991,7 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
 	uint16_t handle = 0;
 	socklen_t len;
 	gboolean flushable = FALSE, have_dst = FALSE;
-	uint32_t priority;
+	uint32_t priority, phy;
 
 	if (!get_src(sock, &src, sizeof(src), err))
 		return FALSE;
@@ -1147,6 +1159,13 @@ parse_opts:
 			}
 			*(va_arg(args, uint32_t *)) = priority;
 			break;
+		case BT_IO_OPT_PHY:
+			if (get_phy(sock, &phy) < 0) {
+				ERROR_FAILED(err, "get_phy", errno);
+				return FALSE;
+			}
+			*(va_arg(args, uint32_t *)) = phy;
+			break;
 		case BT_IO_OPT_INVALID:
 		case BT_IO_OPT_SOURCE_TYPE:
 		case BT_IO_OPT_CHANNEL:
@@ -1194,6 +1213,7 @@ static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1,
 	socklen_t len;
 	uint8_t dev_class[3];
 	uint16_t handle = 0;
+	uint32_t phy;
 
 	if (!get_src(sock, &src, sizeof(src), err))
 		return FALSE;
@@ -1287,6 +1307,13 @@ static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1,
 			}
 			memcpy(va_arg(args, uint8_t *), dev_class, 3);
 			break;
+		case BT_IO_OPT_PHY:
+			if (get_phy(sock, &phy) < 0) {
+				ERROR_FAILED(err, "get_phy", errno);
+				return FALSE;
+			}
+			*(va_arg(args, uint32_t *)) = phy;
+			break;
 		case BT_IO_OPT_SOURCE_TYPE:
 		case BT_IO_OPT_DEST_TYPE:
 		case BT_IO_OPT_KEY_SIZE:
@@ -1338,6 +1365,7 @@ static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args)
 	socklen_t len;
 	uint8_t dev_class[3];
 	uint16_t handle = 0;
+	uint32_t phy;
 
 	len = sizeof(sco_opt);
 	memset(&sco_opt, 0, len);
@@ -1385,6 +1413,13 @@ static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args)
 			}
 			memcpy(va_arg(args, uint8_t *), dev_class, 3);
 			break;
+		case BT_IO_OPT_PHY:
+			if (get_phy(sock, &phy) < 0) {
+				ERROR_FAILED(err, "get_phy", errno);
+				return FALSE;
+			}
+			*(va_arg(args, uint32_t *)) = phy;
+			break;
 		case BT_IO_OPT_SOURCE_TYPE:
 		case BT_IO_OPT_DEST_TYPE:
 		case BT_IO_OPT_DEFER_TIMEOUT:
diff --git a/btio/btio.h b/btio/btio.h
index 2dce9f0c1..41a017acb 100644
--- a/btio/btio.h
+++ b/btio/btio.h
@@ -56,6 +56,7 @@ typedef enum {
 	BT_IO_OPT_FLUSHABLE,
 	BT_IO_OPT_PRIORITY,
 	BT_IO_OPT_VOICE,
+	BT_IO_OPT_PHY,
 } BtIOOption;
 
 typedef enum {
-- 
2.21.1


  reply	other threads:[~2020-02-19  0:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19  0:36 [PATCH BlueZ 1/4] lib: Add definition to BT_PHY Luiz Augusto von Dentz
2020-02-19  0:36 ` Luiz Augusto von Dentz [this message]
2020-02-19  0:36 ` [PATCH BlueZ 3/4] l2test: Add support " Luiz Augusto von Dentz
2020-02-19  0:36 ` [PATCH BlueZ 4/4] avdtp: Enable MTU auto tunning Luiz Augusto von Dentz
2020-02-19 21:55 ` [PATCH BlueZ 1/4] lib: Add definition to BT_PHY Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200219003612.14599-2-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox