device: add device_remove_bonding function
authorArchie Pusaka <apusaka@chromium.org>
Thu, 16 Jul 2020 18:04:32 +0000 (02:04 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:50 +0000 (14:30 +0530)
This patch splits the "bonding removal" function in device.c,
because we need to remove bonding information when receiving
"virtual cable unplug" in HID profile.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/device.c
src/device.h

index d314823..f5fce16 100644 (file)
@@ -6297,6 +6297,20 @@ static void delete_folder_tree(const char *dirname)
        rmdir(dirname);
 }
 
+void device_remove_bonding(struct btd_device *device, uint8_t bdaddr_type)
+{
+       if (bdaddr_type == BDADDR_BREDR)
+               device->bredr_state.bonded = false;
+       else
+               device->le_state.bonded = false;
+
+       if (!device->bredr_state.bonded && !device->le_state.bonded)
+               btd_device_set_temporary(device, true);
+
+       btd_adapter_remove_bonding(device->adapter, &device->bdaddr,
+                                                       bdaddr_type);
+}
+
 static void device_remove_stored(struct btd_device *device)
 {
        char device_addr[18];
@@ -6305,17 +6319,11 @@ static void device_remove_stored(struct btd_device *device)
        char *data;
        gsize length = 0;
 
-       if (device->bredr_state.bonded) {
-               device->bredr_state.bonded = false;
-               btd_adapter_remove_bonding(device->adapter, &device->bdaddr,
-                                                               BDADDR_BREDR);
-       }
+       if (device->bredr_state.bonded)
+               device_remove_bonding(device, BDADDR_BREDR);
 
-       if (device->le_state.bonded) {
-               device->le_state.bonded = false;
-               btd_adapter_remove_bonding(device->adapter, &device->bdaddr,
-                                                       device->bdaddr_type);
-       }
+       if (device->le_state.bonded)
+               device_remove_bonding(device, device->bdaddr_type);
 
        device->bredr_state.paired = false;
        device->le_state.paired = false;
index 909e7f1..5927da8 100644 (file)
@@ -56,6 +56,7 @@ uint16_t btd_device_get_vendor(struct btd_device *device);
 uint16_t btd_device_get_vendor_src(struct btd_device *device);
 uint16_t btd_device_get_product(struct btd_device *device);
 uint16_t btd_device_get_version(struct btd_device *device);
+void device_remove_bonding(struct btd_device *device, uint8_t bdaddr_type);
 void device_remove(struct btd_device *device, gboolean remove_stored);
 int device_address_cmp(gconstpointer a, gconstpointer b);
 int device_bdaddr_cmp(gconstpointer a, gconstpointer b);