From 83d5b9c3c210327ec91caec78ee2a4c065acdb36 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 18 Feb 2020 11:41:29 -0800 Subject: [PATCH] btio: Add BT_IO_PHY option This adds BT_IO_PHY option which can be used to read the underline packet types/PHY in use by the link layer. Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- 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 969cd3a..a3da4b6 100755 --- 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 2dce9f0..41a017a 100755 --- 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.7.4