diff mbox series

[Bluez,v2] input: disconnect intr channel before ctrl channel

Message ID 20200609225813.Bluez.v2.1.I1952bb847ed07631095daf37fe281a49ccf864d0@changeid (mailing list archive)
State Accepted, archived
Headers show
Series [Bluez,v2] input: disconnect intr channel before ctrl channel | expand

Commit Message

Archie Pusaka June 9, 2020, 2:58 p.m. UTC
From: Archie Pusaka <apusaka@chromium.org>

According to bluetooth HID Profile spec Ver 1.0, section 7.2.2, A
host or device shall always complete the disconnection of the
interrupt channel before disconnecting the control channel.
However, the current implementation disconnects them both
simultaneously.

This patch postpone the disconnection of control channel to the
callback of interrupt watch, which shall be called upon receiving
interrupt channel disconnection response.
---

Changes in v2:
-change socket shut mode to SHUT_WR

 profiles/input/device.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Archie Pusaka June 9, 2020, 3:03 p.m. UTC | #1
Hi Luiz,

Sorry, I didn't realize sooner that the version which I sent earlier
as v1 is different than the one in my local repo. This is the correct
version.

Thanks,
Archie


On Tue, 9 Jun 2020 at 22:58, Archie Pusaka <apusaka@google.com> wrote:
>
> From: Archie Pusaka <apusaka@chromium.org>
>
> According to bluetooth HID Profile spec Ver 1.0, section 7.2.2, A
> host or device shall always complete the disconnection of the
> interrupt channel before disconnecting the control channel.
> However, the current implementation disconnects them both
> simultaneously.
>
> This patch postpone the disconnection of control channel to the
> callback of interrupt watch, which shall be called upon receiving
> interrupt channel disconnection response.
> ---
>
> Changes in v2:
> -change socket shut mode to SHUT_WR
>
>  profiles/input/device.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/profiles/input/device.c b/profiles/input/device.c
> index d89da2d7c..e2ea459fe 100644
> --- a/profiles/input/device.c
> +++ b/profiles/input/device.c
> @@ -1026,14 +1026,19 @@ static bool is_connected(struct input_device *idev)
>
>  static int connection_disconnect(struct input_device *idev, uint32_t flags)
>  {
> +       int sock;
> +
>         if (!is_connected(idev))
>                 return -ENOTCONN;
>
> -       /* Standard HID disconnect */
> -       if (idev->intr_io)
> -               g_io_channel_shutdown(idev->intr_io, TRUE, NULL);
> -       if (idev->ctrl_io)
> -               g_io_channel_shutdown(idev->ctrl_io, TRUE, NULL);
> +       /* Standard HID disconnect
> +        * Intr channel must be disconnected before ctrl channel, so only
> +        * disconnect intr here, ctrl is disconnected in intr_watch_cb.
> +        */
> +       if (idev->intr_io) {
> +               sock = g_io_channel_unix_get_fd(idev->intr_io);
> +               shutdown(sock, SHUT_WR);
> +       }
>
>         if (idev->uhid)
>                 return 0;
> --
> 2.27.0.278.ge193c7cf3a9-goog
>
Luiz Augusto von Dentz June 10, 2020, 8:22 p.m. UTC | #2
Hi Archie,

On Tue, Jun 9, 2020 at 8:03 AM Archie Pusaka <apusaka@google.com> wrote:
>
> Hi Luiz,
>
> Sorry, I didn't realize sooner that the version which I sent earlier
> as v1 is different than the one in my local repo. This is the correct
> version.
>
> Thanks,
> Archie
>
>
> On Tue, 9 Jun 2020 at 22:58, Archie Pusaka <apusaka@google.com> wrote:
> >
> > From: Archie Pusaka <apusaka@chromium.org>
> >
> > According to bluetooth HID Profile spec Ver 1.0, section 7.2.2, A
> > host or device shall always complete the disconnection of the
> > interrupt channel before disconnecting the control channel.
> > However, the current implementation disconnects them both
> > simultaneously.
> >
> > This patch postpone the disconnection of control channel to the
> > callback of interrupt watch, which shall be called upon receiving
> > interrupt channel disconnection response.
> > ---
> >
> > Changes in v2:
> > -change socket shut mode to SHUT_WR
> >
> >  profiles/input/device.c | 15 ++++++++++-----
> >  1 file changed, 10 insertions(+), 5 deletions(-)
> >
> > diff --git a/profiles/input/device.c b/profiles/input/device.c
> > index d89da2d7c..e2ea459fe 100644
> > --- a/profiles/input/device.c
> > +++ b/profiles/input/device.c
> > @@ -1026,14 +1026,19 @@ static bool is_connected(struct input_device *idev)
> >
> >  static int connection_disconnect(struct input_device *idev, uint32_t flags)
> >  {
> > +       int sock;
> > +
> >         if (!is_connected(idev))
> >                 return -ENOTCONN;
> >
> > -       /* Standard HID disconnect */
> > -       if (idev->intr_io)
> > -               g_io_channel_shutdown(idev->intr_io, TRUE, NULL);
> > -       if (idev->ctrl_io)
> > -               g_io_channel_shutdown(idev->ctrl_io, TRUE, NULL);
> > +       /* Standard HID disconnect
> > +        * Intr channel must be disconnected before ctrl channel, so only
> > +        * disconnect intr here, ctrl is disconnected in intr_watch_cb.
> > +        */
> > +       if (idev->intr_io) {
> > +               sock = g_io_channel_unix_get_fd(idev->intr_io);
> > +               shutdown(sock, SHUT_WR);
> > +       }
> >
> >         if (idev->uhid)
> >                 return 0;
> > --
> > 2.27.0.278.ge193c7cf3a9-goog
> >

Applied, thanks.
diff mbox series

Patch

diff --git a/profiles/input/device.c b/profiles/input/device.c
index d89da2d7c..e2ea459fe 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -1026,14 +1026,19 @@  static bool is_connected(struct input_device *idev)
 
 static int connection_disconnect(struct input_device *idev, uint32_t flags)
 {
+	int sock;
+
 	if (!is_connected(idev))
 		return -ENOTCONN;
 
-	/* Standard HID disconnect */
-	if (idev->intr_io)
-		g_io_channel_shutdown(idev->intr_io, TRUE, NULL);
-	if (idev->ctrl_io)
-		g_io_channel_shutdown(idev->ctrl_io, TRUE, NULL);
+	/* Standard HID disconnect
+	 * Intr channel must be disconnected before ctrl channel, so only
+	 * disconnect intr here, ctrl is disconnected in intr_watch_cb.
+	 */
+	if (idev->intr_io) {
+		sock = g_io_channel_unix_get_fd(idev->intr_io);
+		shutdown(sock, SHUT_WR);
+	}
 
 	if (idev->uhid)
 		return 0;