linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez PATCH v1 1/2] device: add device_remove_bonding function
@ 2020-06-10 15:05 Archie Pusaka
  2020-06-10 15:05 ` [Bluez PATCH v1 2/2] input: Remove bonding info when receiving virtual cable unplug Archie Pusaka
  2020-06-10 15:38 ` [Bluez,v1,1/2] device: add device_remove_bonding function bluez.test.bot
  0 siblings, 2 replies; 4+ messages in thread
From: Archie Pusaka @ 2020-06-10 15:05 UTC (permalink / raw)
  To: linux-bluetooth, Luiz Augusto von Dentz; +Cc: Archie Pusaka

From: Archie Pusaka <apusaka@chromium.org>

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 | 25 +++++++++++++++----------
 src/device.h |  1 +
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/device.c b/src/device.c
index 7b0eb256e..9fb0e018c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4162,6 +4162,17 @@ 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;
+
+	btd_adapter_remove_bonding(device->adapter, &device->bdaddr,
+							bdaddr_type);
+}
+
 static void device_remove_stored(struct btd_device *device)
 {
 	char device_addr[18];
@@ -4170,17 +4181,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 06b100499..907c7c5c4 100644
--- a/src/device.h
+++ b/src/device.h
@@ -49,6 +49,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.27.0.278.ge193c7cf3a9-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Bluez PATCH v1 2/2] input: Remove bonding info when receiving virtual cable unplug
  2020-06-10 15:05 [Bluez PATCH v1 1/2] device: add device_remove_bonding function Archie Pusaka
@ 2020-06-10 15:05 ` Archie Pusaka
  2020-06-10 18:18   ` Luiz Augusto von Dentz
  2020-06-10 15:38 ` [Bluez,v1,1/2] device: add device_remove_bonding function bluez.test.bot
  1 sibling, 1 reply; 4+ messages in thread
From: Archie Pusaka @ 2020-06-10 15:05 UTC (permalink / raw)
  To: linux-bluetooth, Luiz Augusto von Dentz; +Cc: Archie Pusaka

From: Archie Pusaka <apusaka@chromium.org>

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".
---

 profiles/input/device.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index d89da2d7c..45d86b6cb 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -88,6 +88,7 @@ struct input_device {
 	uint8_t			report_req_pending;
 	guint			report_req_timer;
 	uint32_t		report_rsp_id;
+	bool			unbond_on_disconnect;
 };
 
 static int idle_timeout = 0;
@@ -148,6 +149,14 @@ static void input_device_free(struct input_device *idev)
 	g_free(idev);
 }
 
+static void invalidate_bonding(struct input_device *idev)
+{
+	device_remove_bonding(device_get_adapter(idev->device),
+				btd_device_get_bdaddr_type(idev->device));
+
+	idev->unbond_on_disconnect = false;
+}
+
 static bool hidp_send_message(GIOChannel *chan, uint8_t hdr,
 					const uint8_t *data, size_t size)
 {
@@ -188,6 +197,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->unbond_on_disconnect = true;
+
 	return hidp_send_message(idev->ctrl_io, hdr, data, size);
 }
 
@@ -342,6 +354,9 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
 	/* Enter the auto-reconnect mode if needed */
 	input_device_enter_reconnect_mode(idev);
 
+	if (!idev->ctrl_io && idev->unbond_on_disconnect)
+		invalidate_bonding(idev);
+
 	return FALSE;
 }
 
@@ -406,7 +421,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,
@@ -530,6 +545,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->unbond_on_disconnect)
+		invalidate_bonding(idev);
+
 	return FALSE;
 }
 
@@ -1035,6 +1053,9 @@ static int connection_disconnect(struct input_device *idev, uint32_t flags)
 	if (idev->ctrl_io)
 		g_io_channel_shutdown(idev->ctrl_io, TRUE, NULL);
 
+	if (flags & (1 << HIDP_VIRTUAL_CABLE_UNPLUG))
+		idev->unbond_on_disconnect = true;
+
 	if (idev->uhid)
 		return 0;
 	else
-- 
2.27.0.278.ge193c7cf3a9-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [Bluez,v1,1/2] device: add device_remove_bonding function
  2020-06-10 15:05 [Bluez PATCH v1 1/2] device: add device_remove_bonding function Archie Pusaka
  2020-06-10 15:05 ` [Bluez PATCH v1 2/2] input: Remove bonding info when receiving virtual cable unplug Archie Pusaka
@ 2020-06-10 15:38 ` bluez.test.bot
  1 sibling, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2020-06-10 15:38 UTC (permalink / raw)
  To: linux-bluetooth, apusaka

[-- Attachment #1: Type: text/plain, Size: 1515 bytes --]


This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While we are preparing for reviewing the patches, we found the following
issue/warning.

Test Result:
checkbuild Failed

Outputs:
ar: `u' modifier ignored since `D' is the default (see `U')
ar: `u' modifier ignored since `D' is the default (see `U')
ar: `u' modifier ignored since `D' is the default (see `U')
ar: `u' modifier ignored since `D' is the default (see `U')
ar: `u' modifier ignored since `D' is the default (see `U')
profiles/input/device.c: In function ‘invalidate_bonding’:
profiles/input/device.c:154:24: error: passing argument 1 of ‘device_remove_bonding’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  154 |  device_remove_bonding(device_get_adapter(idev->device),
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                        |
      |                        struct btd_adapter *
In file included from profiles/input/device.c:48:
./src/device.h:52:47: note: expected ‘struct btd_device *’ but argument is of type ‘struct btd_adapter *’
   52 | void device_remove_bonding(struct btd_device *device, uint8_t bdaddr_type);
      |                            ~~~~~~~~~~~~~~~~~~~^~~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:8579: profiles/input/bluetoothd-device.o] Error 1
make: *** [Makefile:4010: all] Error 2



---
Regards,
Linux Bluetooth

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bluez PATCH v1 2/2] input: Remove bonding info when receiving virtual cable unplug
  2020-06-10 15:05 ` [Bluez PATCH v1 2/2] input: Remove bonding info when receiving virtual cable unplug Archie Pusaka
@ 2020-06-10 18:18   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2020-06-10 18:18 UTC (permalink / raw)
  To: Archie Pusaka; +Cc: linux-bluetooth, Archie Pusaka

Hi Archie,

On Wed, Jun 10, 2020 at 8:06 AM Archie Pusaka <apusaka@google.com> wrote:
>
> From: Archie Pusaka <apusaka@chromium.org>
>
> 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".
> ---
>
>  profiles/input/device.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/profiles/input/device.c b/profiles/input/device.c
> index d89da2d7c..45d86b6cb 100644
> --- a/profiles/input/device.c
> +++ b/profiles/input/device.c
> @@ -88,6 +88,7 @@ struct input_device {
>         uint8_t                 report_req_pending;
>         guint                   report_req_timer;
>         uint32_t                report_rsp_id;
> +       bool                    unbond_on_disconnect;

Either name it cable_unplug or have a flag with one bit field reserved
to indicate cable unplugged case.

>  };
>
>  static int idle_timeout = 0;
> @@ -148,6 +149,14 @@ static void input_device_free(struct input_device *idev)
>         g_free(idev);
>  }
>
> +static void invalidate_bonding(struct input_device *idev)
> +{
> +       device_remove_bonding(device_get_adapter(idev->device),
> +                               btd_device_get_bdaddr_type(idev->device));
> +
> +       idev->unbond_on_disconnect = false;
> +}
> +
>  static bool hidp_send_message(GIOChannel *chan, uint8_t hdr,
>                                         const uint8_t *data, size_t size)
>  {
> @@ -188,6 +197,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->unbond_on_disconnect = true;
> +
>         return hidp_send_message(idev->ctrl_io, hdr, data, size);
>  }
>
> @@ -342,6 +354,9 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
>         /* Enter the auto-reconnect mode if needed */
>         input_device_enter_reconnect_mode(idev);
>
> +       if (!idev->ctrl_io && idev->unbond_on_disconnect)
> +               invalidate_bonding(idev);
> +
>         return FALSE;
>  }
>
> @@ -406,7 +421,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,
> @@ -530,6 +545,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->unbond_on_disconnect)
> +               invalidate_bonding(idev);
> +
>         return FALSE;
>  }
>
> @@ -1035,6 +1053,9 @@ static int connection_disconnect(struct input_device *idev, uint32_t flags)
>         if (idev->ctrl_io)
>                 g_io_channel_shutdown(idev->ctrl_io, TRUE, NULL);
>
> +       if (flags & (1 << HIDP_VIRTUAL_CABLE_UNPLUG))
> +               idev->unbond_on_disconnect = true;
> +
>         if (idev->uhid)
>                 return 0;
>         else
> --
> 2.27.0.278.ge193c7cf3a9-goog
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-10 18:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-10 15:05 [Bluez PATCH v1 1/2] device: add device_remove_bonding function Archie Pusaka
2020-06-10 15:05 ` [Bluez PATCH v1 2/2] input: Remove bonding info when receiving virtual cable unplug Archie Pusaka
2020-06-10 18:18   ` Luiz Augusto von Dentz
2020-06-10 15:38 ` [Bluez,v1,1/2] device: add device_remove_bonding function bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).