[PATCH BlueZ 2/4] btio: Add BT_IO_PHY option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux