@@ -1364,6 +1364,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;
@@ -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,
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(+)