public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v3 01/11] adapter: Add btd_adapter_find_device_by_fd
Date: Fri, 26 Aug 2022 17:05:30 -0700	[thread overview]
Message-ID: <20220827000540.113414-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20220827000540.113414-1-luiz.dentz@gmail.com>

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

This adds btd_adapter_find_device_by_fd that lookup a device by a fd
socket destination address.
---
 src/adapter.c | 33 +++++++++++++++++++++++++++++++++
 src/adapter.h |  1 +
 2 files changed, 34 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index b453e86a03c1..51b099daefdf 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1383,6 +1383,39 @@ struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter,
 	return adapter_create_device(adapter, addr, addr_type);
 }
 
+struct btd_device *btd_adapter_find_device_by_fd(int fd)
+{
+	bdaddr_t src, dst;
+	uint8_t dst_type;
+	GIOChannel *io = NULL;
+	GError *gerr = NULL;
+	struct btd_adapter *adapter;
+
+	io = g_io_channel_unix_new(fd);
+	if (!io)
+		return NULL;
+
+	bt_io_get(io, &gerr,
+			BT_IO_OPT_SOURCE_BDADDR, &src,
+			BT_IO_OPT_DEST_BDADDR, &dst,
+			BT_IO_OPT_DEST_TYPE, &dst_type,
+			BT_IO_OPT_INVALID);
+	if (gerr) {
+		error("bt_io_get: %s", gerr->message);
+		g_error_free(gerr);
+		g_io_channel_unref(io);
+		return NULL;
+	}
+
+	g_io_channel_unref(io);
+
+	adapter = adapter_find(&src);
+	if (!adapter)
+		return NULL;
+
+	return btd_adapter_find_device(adapter, &dst, dst_type);
+}
+
 sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter)
 {
 	return adapter->services;
diff --git a/src/adapter.h b/src/adapter.h
index b09044edda70..f38f473b79d7 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -86,6 +86,7 @@ struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter,
 							uint8_t dst_type);
 struct btd_device *btd_adapter_find_device_by_path(struct btd_adapter *adapter,
 						   const char *path);
+struct btd_device *btd_adapter_find_device_by_fd(int fd);
 
 void btd_adapter_update_found_device(struct btd_adapter *adapter,
 					const bdaddr_t *bdaddr,
-- 
2.37.2


  reply	other threads:[~2022-08-27  0:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-27  0:05 [PATCH v3 00/11] Initial BAP support Luiz Augusto von Dentz
2022-08-27  0:05 ` Luiz Augusto von Dentz [this message]
2022-08-27  3:53   ` bluez.test.bot
2022-08-27  0:05 ` [PATCH v3 02/11] lib/uuid: Add PACS/ASCS UUIDs Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 03/11] shared/bap: Add initial code for handling BAP Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 04/11] profiles: Add initial code for bap plugin Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 05/11] shared: Add definition for LC3 codec Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 06/11] media-api: Add SelectProperties Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 07/11] test/simple-endpoint: Add support for LC3 endpoints Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 08/11] client/player: Add support for PACS endpoints Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 09/11] client/player: Use QoS interval on transport.send Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 10/11] profiles: Allow linked transport to release the fd Luiz Augusto von Dentz
2022-08-27  0:05 ` [PATCH v3 11/11] profiles: Update transport Links property on state change to QoS Luiz Augusto von Dentz
2022-08-29 19:50 ` [PATCH v3 00/11] Initial BAP support patchwork-bot+bluetooth

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=20220827000540.113414-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