Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp4212560ybh; Tue, 17 Mar 2020 14:32:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtlpptKejdmVAS0X8Egfsg0EqDwlb1P7ihexEN0Qgk8oBtPbzDDKWKFvVfS8dmAgHUndUr0 X-Received: by 2002:aca:b1d5:: with SMTP id a204mr760640oif.82.1584480740563; Tue, 17 Mar 2020 14:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584480740; cv=none; d=google.com; s=arc-20160816; b=zJthTk00wwkwFMcZzDAqc9fAKXcGAYnhQeje9/gBUz2jobLNgr/6rqN5+l8xw3azvL nLLcHLbIao73KozMXaDxxsZhM3mDorTqqnDnVCCgIUv++r0Y5x5j8he4MDo7vKEdgGBe XS0Vhtki16fFizHuU/g9hTABQ/9Mnb2BeEE/pSvg7YZOj8DFaEsLklsc/UdOCdCoC7Yw beEl9QP6Wjg9/uSbvsGENnYDsWlj+AW6TSljIw6SmHPzUQJtF/aLy+AeUG2IgF4pgbn0 z+pPRi2pUT89KAVFDBLRdMuHjGjFsgnRXN5bb7dBEDw6U43yU+gU0FpVbhCqr1GXnkzX 01sw== 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=RPvFEGqI9mQfsI11OXNvHEax6/EWC7cYKUYPPbuRuNc=; b=06bYGeu+O/pkjKbu2adrbocFdbzRuXd2AVr5MVsJKMkOSYtdPw2/TKy/nbTbsl/fOe PGC3C8vtigy5uIXhAYxCVm1BgX+PbNXD/Y47ifeBf+M0BJSUrc5QgmYRnOd17NGnAl8D Jlcpzb85zWP+K/4axKwV+b+jsoTsesRMOWJAvPp+Wn+mtvFpAQiIFyeQRMAeoraPPo0I HtvnPHWXp9r6+qfXF8vfIyrePRZK/JPtnBhSTyvjYfUkoGbgNqyO6zaLqDGqGIUU4jSE XecjUsjYOm3pAz3a0TeToZAb48L8B6YpdxpEW1TLcJQmXiHQApUmzl9AouzJRMbulpQG NpSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G3cjS5SQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 103si2515138otv.23.2020.03.17.14.31.48; Tue, 17 Mar 2020 14:32:20 -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=@gmail.com header.s=20161025 header.b=G3cjS5SQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbgCQVbY (ORCPT + 99 others); Tue, 17 Mar 2020 17:31:24 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:34004 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726494AbgCQVbY (ORCPT ); Tue, 17 Mar 2020 17:31:24 -0400 Received: by mail-ot1-f67.google.com with SMTP id j16so23342939otl.1 for ; Tue, 17 Mar 2020 14:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RPvFEGqI9mQfsI11OXNvHEax6/EWC7cYKUYPPbuRuNc=; b=G3cjS5SQyh+SIE9K+C2ZISwdXjUafqtw835Q1wkiVVhkmfM2uVxybVugh+1Jp4Bhxt dn1xXTvFPQb/kg6XIPST/RG7J+Mbidivx5iV1tx25vER9gDW9/KvQmilaz7L4U8bFBUQ Kx623N1BCsuHJ688zbh6Oca+cuFHyZXMcH5V3Jr4uaQXYtkl+LB1Zdtyd68nbCu4m1vW h9X4iRqZ25krCp27O4SUat0yFHA0x6qN/Ugn68g+qTfH7SfVWsGfzxF4H7xD2dEpYKMW lgA5DLZOEuTY63Z8NZuZaFziA2w8WHC38wqyu9aSiA2KXPwgVi9IDcSqwpEOPPoJEKN8 28ww== 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=RPvFEGqI9mQfsI11OXNvHEax6/EWC7cYKUYPPbuRuNc=; b=a8F0iVKOznS1aOHD1fMGdudV5NgmrHDmkHldG/n/ZBVBe4uNkI2o3nPzwbxOceFCwL HwdwFDEr/GKSSt/GyZvG8C8rXM6vrJK+a/1H3cEr+WtnS+2pzn6NM3bovP2po29vC1hQ 4svyZKsgLmK3Jewm/ZHjTyIek1DIyafxrj4ESWzSXmzwtkAdH58x1mhcQkwU2v7W/Eb1 HytYIaQ44XPrC921Dm3cwHTm8iz+h/TVtxfWO1gbMgAMF8LHDYRsvvUZuT2ibS+GyL+T bFFBdcW0052OOsYIfLxRWK+DkkgZU65mY7/F6KljfA/H5t8Rr0cw9GoVRCjmjlDJhXlS vcAw== X-Gm-Message-State: ANhLgQ3uVvtaTx4YRdVl/21A1sElf5qi6PC9JXnBb8R/T5iR0JorPMlS FWMpuYgonXJiKdnK4YnMEfqkC2OhMBQsJtcFz81Raw== X-Received: by 2002:a9d:3f4b:: with SMTP id m69mr1103353otc.146.1584480683699; Tue, 17 Mar 2020 14:31:23 -0700 (PDT) MIME-Version: 1.0 References: <20200316123914.Bluez.v1.1.I2c83372de789a015c1ee506690bb795ee0b0b0d9@changeid> In-Reply-To: From: Luiz Augusto von Dentz Date: Tue, 17 Mar 2020 14:31:11 -0700 Message-ID: Subject: Re: [Bluez PATCH v1] input: disconnect intr channel before ctrl channel To: Archie Pusaka 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 Archie, On Mon, Mar 16, 2020 at 11:53 PM Archie Pusaka wrote: > > 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? I see, we shutdown the socket immediately since the socket API itself don't seem to have a concept of disconnect syscall not sure if other values could be passed to shutdown second parameter to indicate we want to actually wait it to be disconnected. > 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 -- Luiz Augusto von Dentz