Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3447083ybh; Mon, 16 Mar 2020 23:53:39 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuzMdvGgAH0fXMhvpSiFlLivOA2NIMcOcqqtRL4DAFiWzBvQ5PzNG9KqVbCiwTnAScGGhJx X-Received: by 2002:aca:75d5:: with SMTP id q204mr2483087oic.9.1584428019460; Mon, 16 Mar 2020 23:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584428019; cv=none; d=google.com; s=arc-20160816; b=zke4S9GW21MeCLS99QIkYgtwzz8+eKagXlTjYcbrfIIx8TYtLsmWIufY4b4apKYtZj OuNNPTQTECXcZ/mg9Ns2tGqokJsjUdphcY9eMNFRvfzKQN78D7y0edDBt1lzU3ejlMSg M9VaalHZEKlvS+UGx8ysiJX/ophsUJYGIzZCgjmda6yBgC+jPnWxY3ziJJLxZlM/Jl81 GtNp/6HbyA/fqWckz4QQhrXtkFefcwvDTuHH7rU9jPAGq6SNDIwcCwAvLjXNZkvE65o5 b2UYmBijVvcMyhT8pn1kOZ5NLAiGWY8qMZRlfI2kNaaprIS7DVCmSZhzRtZkcV0PG0Cr 8tQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=DQJFThQABfvaCXGRaom/ZTc/xTYIP6obwBzxYLhhNQ0=; b=GdcdWxxdEwM7CkbHiW+zuoJ5rpdVeSS82LnvL9tTFJnBPUIIOzdGO8KBhvAJbmGWJw BMRYgyJI0KSwjhU0rwKpBWGeEeVK1LpbxvV3AYKAKAHPBDHa376bEQ0JrtLo4ISgU8DI fNJtXkvi2Wvmrhf2IeAwpNdLLG2D6DmTdAwmb4mZ0rm4wNpSXpRAlN7riBKmV+8jaIFI eGtQBLAbZgqn5hslTwUrenKI+zMpHDZqTHcK8Nf94QXExjtPNFxCnzFSROt9h/5fwk6U tjTOsF7c1C2EQDcwxjvAUClcxdYTvqywCRP4jx/hUx9BYENevd6Jlzh6jkrMTFxmcUfA 4kLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=I0WfZGFo; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p25si285991ota.143.2020.03.16.23.53.10; Mon, 16 Mar 2020 23:53:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=I0WfZGFo; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725868AbgCQGxI (ORCPT + 99 others); Tue, 17 Mar 2020 02:53:08 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37804 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbgCQGxI (ORCPT ); Tue, 17 Mar 2020 02:53:08 -0400 Received: by mail-wm1-f66.google.com with SMTP id a141so20601930wme.2 for ; Mon, 16 Mar 2020 23:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DQJFThQABfvaCXGRaom/ZTc/xTYIP6obwBzxYLhhNQ0=; b=I0WfZGFoApAUjGvD6N6OPpsoRlcuYsIKcHG9jN0rQjwYCpKonPhs4M2+9cFR1igT0m qXiZjQtDUQAl8zNm9x0gfsVlt524WRYGNp4ONWKIjeuoikmftO+7HvxRR1MmEzh/+4lr 5+jixtrqoK1SZWqm2zypUkXlxAoXPPz7wjJAVKNZ4odpnLLG4UZfLCX5j7bWFpDqltOM +09t4pDOTE4y6AEJal4c7qhmMDB5s8j4eBEjA2Y9yhyb8WHjBr/cA8IceAv1EODm303h Hx2GOmN2oEczjJzzzWPVQuwHAiF2oDvhOwzgtqSTBBpkOFv4T9Dvi56PIQJGd1icOwPV xUhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DQJFThQABfvaCXGRaom/ZTc/xTYIP6obwBzxYLhhNQ0=; b=cd+8yIYOELFtNxUPBJ0dLKqEKAkU8Q02vzztDqee4KjXMTVjz8uhqzlCDNvyMSwf4G ZRYQv7m/cTc+A4hz/tvkwJlBitr8067xg6LWlFs8lLjZWZcms4m8dKbyFlpyMmCebRoI t/xMzpa/F/JTEgOhwpa/Lpq43vTT/z2p0HDy6bzlkXpVHz7Cx4GzFfszXt+x5hncQ1j/ eUN2vfXJN9kVhq4M0e9iFW7MGAK+/LvJmkQ/6ysAFJwPXJbzG0Zua6C3txudBWTi+at4 9dpFPC3tNDMXsIksQlt5ke54wl5unwNKcDL4MhPboeX5TbJbNc+CSW+arbzj7G0DLi23 RhVA== X-Gm-Message-State: ANhLgQ0tF8T7b0ac/Gu+9Tc0gNeUqE0rjrJAn4IOAvLltMVdIQP2PJrT sehS2e7ueUAxNGc28X3r27ALdfNeIjz4FX+cWuiadE6xvSZFhQ== X-Received: by 2002:a7b:c391:: with SMTP id s17mr3491567wmj.55.1584427985365; Mon, 16 Mar 2020 23:53:05 -0700 (PDT) MIME-Version: 1.0 References: <20200316123914.Bluez.v1.1.I2c83372de789a015c1ee506690bb795ee0b0b0d9@changeid> In-Reply-To: From: Archie Pusaka Date: Tue, 17 Mar 2020 14:52:54 +0800 Message-ID: Subject: Re: [Bluez PATCH v1] input: disconnect intr channel before ctrl channel To: Luiz Augusto von Dentz Cc: linux-bluetooth Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, Luckily you asked, because I found out that actually the patch didn't wait for the disconnection response for any case. It does delay the disconnection of the ctrl channel slightly though, but that doesn't guarantee a proper order of disconnection. Therefore, as of now, this patch is not fixing anything. Digging more into this matter, I found out by removing this condition (sk->sk_shutdown == SHUTDOWN_MASK) in [1], it makes intr_watch_cb() called after truly receiving the interrupt disconnection response. However, I haven't checked whether removal of such condition will break other things. Do you have any suggestions? With this patch and removal of that condition, I confirm that it works with situations where the device is being removed and/or just being disconnected. It also works with virtual cable unplug when UHID is used. * Virtual cable unplug has another problem which doesn't adhere to the specs, but it is unrelated to disconnection. [1] https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/af_bluetooth.c#n470 Thanks, Archie On Tue, 17 Mar 2020 at 04:58, Luiz Augusto von Dentz wrote: > > Hi Archie, > > On Sun, Mar 15, 2020 at 9:40 PM Archie Pusaka wrote: > > > > From: Archie Pusaka > > > > 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. > > --- > > > > 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 8ada1b4ff..8ef3714c9 100644 > > --- a/profiles/input/device.c > > +++ b/profiles/input/device.c > > @@ -1010,14 +1010,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_RDWR); > > + } > > > > if (idev->uhid) > > return 0; > > -- > > 2.25.1.481.gfbce0eb801-goog > > Just to confirm, have you checked if this works with both situation > where the device is being removed or just being disconnected, > specially the case of HIDP_CTRL_VIRTUAL_CABLE_UNPLUG which perhaps was > not working before as well since we disconnect the ctrl channel before > transmitting it. > > -- > Luiz Augusto von Dentz