Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3349844pxp; Tue, 22 Mar 2022 18:11:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3R1Vv6umQAL0A9iNe4zlBd2hY/EH9ePNOGs2AbcCFmBcWG0FJ2sBU3RBZthOJEadsvHPE X-Received: by 2002:a05:6a00:3018:b0:4fa:d533:45e5 with SMTP id ay24-20020a056a00301800b004fad53345e5mr1661136pfb.13.1647997887241; Tue, 22 Mar 2022 18:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647997887; cv=none; d=google.com; s=arc-20160816; b=WhEAUHmE7FRlfX9hmrn9tqZBHQ448vjtmrurGbsaj092nTGAZnL+fFuL4j3oVgUw7r ZNUHZuv85TQnEpxqPTuHS9oilxjOQ6y5Oy95+85a9NILapDOjrAvjXIKGmvyCthZmAO1 fDcKpEmZwVRZGqnLX9rRFE9kRS6pu2rW5xeTt231C4klI+B8b1St/mBe61Cm+Kc9vU66 y0ivVKgz4kv6lIYgJAGfi6T3+xd/+GE0GFfnVaI3aYkCdWNDWHOk/wTZ72VyTAptAjXa gir6LYJzPYuTmUsRWoMYCl+fx8/8qkJZbV2JjI/f+PXuVnn3kcEzwh5e8Q1AmARJUs0A N9ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/Ql1UW7kb+dY7XxMygQ/ftVXYkoUpGIDtsnaZmElvcs=; b=Ng3Xgj4Xun8g//IagJySwmEzpgMGVXjCVDAlqYqKaibM40yA+hZq6H7UMbPCYCKLBU Ow1kHSCZRob/4bi83doa0AlNsxrOtNOBD/xEzKyepT/If/7IsCr8bgCWHxxv2YDhTaDD 1bmY2eBQBLyqaOFhqSEfiPQy4KAssqdKrNHsh7ZuO5s2mXqaCRlvK9+CjE8UrW2Zfpof 5V/OMULExrQjpTCdJkli8bjiO6TKP6ZS5hdTstHRyn6wpYMa09XWsdQr6FH/n4gVlkRL b3HIa6y/G1b6FOGgopXk1xW3EJSEE4jPwBu3jfVnCmOYKCkIbEK1GULrD/HPZQOaY0zc nAUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="G/HoWEXn"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a63ad0e000000b00381b0bd5852si17774288pgf.399.2022.03.22.18.10.54; Tue, 22 Mar 2022 18:11:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="G/HoWEXn"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234571AbiCVVgx (ORCPT + 99 others); Tue, 22 Mar 2022 17:36:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235678AbiCVVgw (ORCPT ); Tue, 22 Mar 2022 17:36:52 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C57F2238 for ; Tue, 22 Mar 2022 14:35:23 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id j2so36179868ybu.0 for ; Tue, 22 Mar 2022 14:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/Ql1UW7kb+dY7XxMygQ/ftVXYkoUpGIDtsnaZmElvcs=; b=G/HoWEXnGQXEtf2yKNtEnsXWg5R6NcckddVQlavJk03JI53mzDbEfCw7Jy6mbBY0kE 8slO03n5IyG/88V9eP2QrD9pdEwwM6eeQFxioXfEiP61YimxPYtNpy6dF/rlrhNMKGxw vjqZeYWdYJ0Q83zkrJGmoCTN1M3IBDVveB1a/doaSd46+bsnhZS7FDrCraSlNHeW9e4I dP2x3ia4Hm91mBZXEtB5pjEIXJWZ4EyusQwUxIcNTbvM24rtGfz+4cKjYZE/B3o8UrCh qWiXN9HWZ6YZWYryLtm7GbMRpn4QN8XCg3hnXQNBqwx61dg8vW/Doglfxltw+Qr0JQNo pfpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/Ql1UW7kb+dY7XxMygQ/ftVXYkoUpGIDtsnaZmElvcs=; b=o1MKoMUGSquMRZBsTRhkWLwsx8Z2B/533Da/6cBtUYhOaypIQpOh1AIvQMiRPGWD8f ErLTDUlG9qWRiC4Csyo4ubh4JWUp/Xx0VXZctk+WIncEGKqT+wAPMQxO0EKYbeae6nis 4MTuGQ+twFIpXChXok+773I3/siE8RTYERtCS77sjCvgFiIKYwwKolr5MQbSr8our/S1 8M+aqCVqcU15nc9lcznB8W39KZNfT7AryAbn/yDkRWAr92GCVclgpop9QDoTa9pp3nA8 oB3sFvYt7azZOLk1rWw5zlpWlA2iyeff8iAsFWdRuU0+kuIPaJrJKK+grw6+EduvpmT7 Nauw== X-Gm-Message-State: AOAM532lWGP0IHDxuleXa+V+KuyhDcVmO076jwisy8NWDAwNIoci6ZCE wdyZw7eYBAaC5kVrMiBRJaf7hc2p3Ex4syFLWiqcUR2FMZE= X-Received: by 2002:a25:9742:0:b0:61d:9526:ebc3 with SMTP id h2-20020a259742000000b0061d9526ebc3mr28600427ybo.578.1647984922795; Tue, 22 Mar 2022 14:35:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Luiz Augusto von Dentz Date: Tue, 22 Mar 2022 14:35:11 -0700 Message-ID: Subject: Re: GATT issue, possible bluez bug? To: Adam Pigg Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Adam, On Tue, Mar 22, 2022 at 3:40 AM Adam Pigg wrote: > > Hi Luiz > > > On Tue, 22 Mar 2022 at 07:55, Adam Pigg wrote: > > > > Hi Luiz > > > > On Tue, 22 Mar 2022 at 00:44, Luiz Augusto von Dentz > > wrote: > > > > > > Hi Adam, > > > > > > On Mon, Mar 21, 2022 at 4:03 PM Adam Pigg wrote: > > > > > > > > Hi > > > > > > > > A bit of background, I write a linux desktop/mobile app called > > > > Amazfish which interfaces with several watches over BLE using their > > > > GATT services. To do this, I use the bluez dbus api (technically a > > > > thin wrapper around it I wrote called qble > > > > https://github.com/piggz/qble) > > > > > > > > All has been good so far, I support several generations of > > > > Huami/Amazfit watches, as well as the open source Pinetime and > > > > Bangle.js. For the Amazfit watches, i have implementations for older > > > > devies such as the Bip, and newer ones such as the GTS. > > > > > > > > Much of the reverse engineering comes from the Android Gadget Bridge > > > > project, which supports many more devices. > > > > > > > > My community of users donated to buy me a newer device called a GTR2, > > > > which, according to the GB devs uses the same protocol as the slightly > > > > older GTS, and the packet captures I have from Android would support > > > > this. > > > > > > > > But this is where my trouble starts with Bluez, my existing > > > > implementation doesnt work at all. Normally, after a connection, I > > > > would wait for the ServicesResolved signal, which happens pretty fast > > > > on all other devices, but on the GTR2, it takes about 30 seconds, by > > > > which time, the watch has disconnected. (i get a disconnected signal > > > > immediately after the ServicesResolved signal) > > > > > > > > To rule out my code, I have tried several things: > > > > Gatttool > > > > With gattool, i can connect, get the services, enable a notification, > > > > write a value and get the expected results seemingly fine > > > > > > > > Python-gatt (using the bluez dbus api) > > > > Im unable to iterate the services, like my app, it takes 30 seconds to > > > > get the signal and then swiftly disconnects > > > > > > > > Gattlib (https://github.com/labapart/gattlib) > > > > Gattlib is interesting as it appears to have "borrowed" much of its > > > > code directly from bluez. When built against the system bluez, if the > > > > version is > 5.42, it will use the dbus api. When I do this, again im > > > > unable to list services on the watch. However, if I edit the build to > > > > force it to use its internal gatt implementation, which appears to be > > > > the same one used by gatttool, then, it IS able to interrogate the > > > > watch. > > > > > > > > I have attached 3 files > > > > 1. test python program which should print services, and associated btmon > > > > 2. btmon output while using gatttool > > > > 3. btmon output running gattlib discover example > > > > > > > > Note, other than discovery, I havnt been able to get gattlib to > > > > read/write/notify! > > > > > > > > It seems as though I may be triggering a bug in the bluez dbus api? > > > > Can anyone suggest anything? > > > > > > What version are you using? I would first try with the latest to see > > > if that something already fixed. > > > > > > > > Im using 5.63 already, which is the latest tag (on opensuse tumbleweed) > > > > I'll also try bluetoothctl and attach logs using that, though I > > suspect it will behave the same as the python library and my own > > library. > > > > Attached is the output of btmon while using bluetoothctl > > bluetoothctl behaves the same as my lib and python, it is unable to > list services, and after a while, emits the ServicesResolved and > disconnected messages at the same time. Im sure it should be able to > list the services immediately after connect just like gatttool can. Looks like there is multiple rounds of MTU Exchange, not sure if that is actually a problem but the spec does say it shall only be sent once per client: BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 3, Part F page 1424: This request shall only be sent once during a connection by the client. There is also no response to frame #30: < ACL Data TX: Handle 3585 flags 0x00 dlen 7 #30 [hci0] 26.641557 ATT: Read Request (0x0a) len 2 Handle: 0x0018 So after 30 seconds (ATT timeout) without receiving any response it disconnects: < HCI Command: Disconnect (0x01|0x0006) plen 3 #48 [hci0] 58.673128 Handle: 3585 Reason: Remote User Terminated Connection (0x13) > Thanks > > > > > -- > > > Luiz Augusto von Dentz -- Luiz Augusto von Dentz