adapter: Add btd_adapter_find_device_by_fd
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 14 Apr 2022 00:17:01 +0000 (17:17 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
This adds btd_adapter_find_device_by_fd that lookup a device by a fd
socket destination address.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c
src/adapter.h

index 97e8512..daac434 100644 (file)
@@ -1908,6 +1908,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;
index 628d02d..635632d 100644 (file)
@@ -162,6 +162,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);
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 void btd_adapter_update_found_device(struct btd_adapter *adapter,