From cfe249a5c3420b7a5d0863dac92b75a209745144 Mon Sep 17 00:00:00 2001 From: Archie Pusaka Date: Fri, 17 Jul 2020 02:04:32 +0800 Subject: [PATCH] device: add device_remove_bonding function 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. --- src/device.c | 28 ++++++++++++++++++---------- src/device.h | 1 + 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/device.c b/src/device.c index 2237a7670..bb8e07e8f 100644 --- a/src/device.c +++ b/src/device.c @@ -4364,6 +4364,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]; @@ -4372,17 +4386,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; diff --git a/src/device.h b/src/device.h index cb8d884e8..956fec1ae 100644 --- a/src/device.h +++ b/src/device.h @@ -50,6 +50,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); -- 2.47.3