input: Remove bonding info when receiving virtual cable unplug
authorArchie Pusaka <apusaka@chromium.org>
Thu, 16 Jul 2020 18:04:33 +0000 (02:04 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:50 +0000 (14:30 +0530)
From Bluetooth HID Profile 1.1 Spec: If a Virtual Cable is
unplugged via a HID control Virtual Unplug command, then both the
Bluetooth HID device and Bluetooth HID Host shall destroy or
invalidate all Bluetooth bonding and Virtual Cable information
that was previously stored in persistent memory for the respective
Virtually Cabled devices and hosts.

This patch removes the bonding information upon receiving and/or
sending a "virtual cable unplug".

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

index 2870bea..f31b336 100644 (file)
@@ -87,6 +87,7 @@ struct input_device {
        uint8_t                 report_req_pending;
        guint                   report_req_timer;
        uint32_t                report_rsp_id;
+       bool                    virtual_cable_unplug;
 #ifdef TIZEN_BT_HID_DEVICE_ENABLE
        char *role;
 #endif
@@ -161,6 +162,14 @@ static void input_device_free(struct input_device *idev)
        g_free(idev);
 }
 
+static void virtual_cable_unplug(struct input_device *idev)
+{
+       device_remove_bonding(idev->device,
+                               btd_device_get_bdaddr_type(idev->device));
+
+       idev->virtual_cable_unplug = false;
+}
+
 static bool hidp_send_message(GIOChannel *chan, uint8_t hdr,
                                        const uint8_t *data, size_t size)
 {
@@ -201,6 +210,9 @@ static bool hidp_send_message(GIOChannel *chan, uint8_t hdr,
 static bool hidp_send_ctrl_message(struct input_device *idev, uint8_t hdr,
                                        const uint8_t *data, size_t size)
 {
+       if (hdr == (HIDP_TRANS_HID_CONTROL | HIDP_CTRL_VIRTUAL_CABLE_UNPLUG))
+               idev->virtual_cable_unplug = true;
+
        return hidp_send_message(idev->ctrl_io, hdr, data, size);
 }
 
@@ -361,6 +373,10 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
 #else
        input_device_enter_reconnect_mode(idev);
 #endif
+
+       if (!idev->ctrl_io && idev->virtual_cable_unplug)
+               virtual_cable_unplug(idev);
+
        return FALSE;
 }
 
@@ -425,7 +441,7 @@ static void hidp_recv_ctrl_hid_control(struct input_device *idev, uint8_t param)
        DBG("");
 
        if (param == HIDP_CTRL_VIRTUAL_CABLE_UNPLUG)
-               connection_disconnect(idev, 0);
+               connection_disconnect(idev, (1 << HIDP_VIRTUAL_CABLE_UNPLUG));
 }
 
 static void hidp_recv_ctrl_data(struct input_device *idev, uint8_t param,
@@ -549,6 +565,9 @@ static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
        if (idev->intr_io && !(cond & G_IO_NVAL))
                g_io_channel_shutdown(idev->intr_io, TRUE, NULL);
 
+       if (!idev->intr_io && idev->virtual_cable_unplug)
+               virtual_cable_unplug(idev);
+
        return FALSE;
 }
 
@@ -1073,6 +1092,10 @@ static int connection_disconnect(struct input_device *idev, uint32_t flags)
        if (idev->role != NULL)
                btd_service_disconnecting_complete(idev->service, 0);
 #endif
+
+       if (flags & (1 << HIDP_VIRTUAL_CABLE_UNPLUG))
+               idev->virtual_cable_unplug = true;
+
        if (idev->uhid)
                return 0;
        else