Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1965645rwd; Fri, 2 Jun 2023 02:51:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4z6+l4ZaO8nY+14kaKAFf266Br5im8w4+5hapzJKz+ksiZB4ntxVn9NCRgQMEBUg1V/iQp X-Received: by 2002:a05:6a00:2488:b0:643:980:65b with SMTP id c8-20020a056a00248800b006430980065bmr14398773pfv.2.1685699499287; Fri, 02 Jun 2023 02:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685699499; cv=none; d=google.com; s=arc-20160816; b=tftdU8t8byFMJXFPgAXWC+4sXugGL93JOI3Q3lN+iV9OM5PP7+QpdXkno/Jivr7CZf PquB/tU9Nzr2E7BgowTwNluAJEG2r+hFJv5sgoU/eJ4+D+lxOOK8EO3j/6Pbs1zopegA KXcbuezGZQNeAs2V63p3tZQw+QTE4jayJpMYEX+xrWszg3YVU3g5+IKd+oJsUnrcJlSH bsMdECZGo8gsRAF5qME5df/I9mSYY+zZ2bb8GkE0aqXpOhDEZUAI6xyACb0k7VjsvAy0 fyPTYwNwYFSuABJo6VK4KibmYNtuw7/IskRYAAi5CHNKhBV/c1hgDe7QhLB2uRYYiBzw LCcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:date:message-id:subject:mime-version :content-transfer-encoding:from:dkim-signature; bh=h0lt0mtX5Af0bz+uQwtronJyLa7qinDTnPxE5AHba4Y=; b=x8D13aBHNsEiR4rOt4q1pRJb5Fa0wczyB3C0SEGVrUl1s3Ckz43mUZ6YPuiH6RH3bJ c89JTix7ZHU63bwKI/HOMNlW25zrh2el8bcfcEvIZXjB4jClAw/dNZot2l5a+jtUWVg1 Rwmg2XonoMMoRMhSgxixGZAsfbGFnyRsLMO3LndSXheBbEIEoycUrfe80xTIiv2rdMin T1K9PYXk6JCyrEQ95mYxc/siM/HoFmSV+JUKu/eauqt9C4yvUTUo/oNOSV6EDdtS0snQ a2oAkSYhYQzOQE6bvJgybzlknQs9kOkQWNmvM2lqrkbcL0qpVSaJK/fMazDHGfMcGg6x LarA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@athom.nl header.s=google header.b=C1IyYmDf; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n28-20020a63721c000000b0052c9e45cb3fsi765274pgc.384.2023.06.02.02.51.17; Fri, 02 Jun 2023 02:51:39 -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=@athom.nl header.s=google header.b=C1IyYmDf; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234560AbjFBJqJ (ORCPT + 99 others); Fri, 2 Jun 2023 05:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234582AbjFBJqI (ORCPT ); Fri, 2 Jun 2023 05:46:08 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C22134 for ; Fri, 2 Jun 2023 02:46:06 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9745c5fed21so115462766b.3 for ; Fri, 02 Jun 2023 02:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=athom.nl; s=google; t=1685699164; x=1688291164; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=h0lt0mtX5Af0bz+uQwtronJyLa7qinDTnPxE5AHba4Y=; b=C1IyYmDf9hOQ0bDNH9kjv9Z5gc46t0e7HtrDhl/UlA1A2TeXNxAN6Zw9Bk9BpzFR3O YBKVnmgB8vdyWoB603fdiX7VCVrbSuurtLGPzjFAOaPpKTLUuy+rY+lbBW/4UEr2+5hz bi+57u6XH26Zn7kexVS9IG1FGOa/VeG8F6CHw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685699164; x=1688291164; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h0lt0mtX5Af0bz+uQwtronJyLa7qinDTnPxE5AHba4Y=; b=PR0/cZipMyOSoOY7dvRL/qyNM3Mcy8aIg9xC39SAQ1GRUDTb5Ir8EPHIzYnOhLIzZi nMVSUx+EOQESgwNsiO9oeqnsADfk9XYX6eW39uKZDjOSYz6HdoAkakAcn5rGL8FfKG3C ON6TINWaaiScjkZZMoqB8hh1JXIJvlLW/RsaEbk3oqA7EKTbIjvepmnS86oCj9CsipD2 kIF6fOqOgU8sS3lDDELb+DiqXW0TdxZjJiyH6hcHrqdzaog3o6u79A9/GQYzG1P5fQtW cs+xVomWuSlTPHHKFD6s3h7kul61QMDRWi8EOyyiBDAeQAOLhA09WxHIHUvBwxq3NYmB g1oA== X-Gm-Message-State: AC+VfDxVTTihREa3pkqDF2GIeEwiN5nkr5+4ILeNEZZCqIMA2C38/Cmm Tfx21n5ej6RTqPhkdx+YAGPUVq8w4//Sej++rGzWKN4u X-Received: by 2002:a17:907:9718:b0:96a:90bb:a2d3 with SMTP id jg24-20020a170907971800b0096a90bba2d3mr9715654ejc.71.1685699164210; Fri, 02 Jun 2023 02:46:04 -0700 (PDT) Received: from smtpclient.apple ([37.153.225.197]) by smtp.gmail.com with ESMTPSA id rk9-20020a170907214900b0096f8c4b1911sm545987ejb.130.2023.06.02.02.46.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2023 02:46:03 -0700 (PDT) From: Herman Meerlo Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) Subject: Intermittent Not connectable devices reported Message-Id: <76E1E367-BAF0-41A8-A292-7E002B213D8A@athom.nl> Date: Fri, 2 Jun 2023 11:45:53 +0200 To: linux-bluetooth@vger.kernel.org X-Mailer: Apple Mail (2.3731.500.231) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 I'm working on a Raspberry Pi device that performs periodic BLE = discovery and tries to connect to multiple devices. Most of the times = this goes fine but especially in BLE heavy environments every now and = then it fails because it says that the device is not found. I have been = debugging this issue for a few weeks now and it comes down to this: =E2=80=A2 Connect to DBus to start the discovery =E2=80=A2 Devices are found, interfacesAdded callbacks are made, = everything looks fine =E2=80=A2 Stop discovery =E2=80=A2 Directly some devices are removed by the interfacesRemoved = callback =E2=80=A2 My code does not get the device it searches for -> unhappy = user What happens under the hood is that DBus removes all devices from it's = cache that have been indicated by Bluez as being Not connectable. I.e. = there is no use in keeping them around, you can't connect to them = anyway. But... this is not true for the device I'm looking for. It is = marked as Not connectable incorrectly. So to chase down the problem I create a btmon dump which shows indeed = that the device is reported to be Not connectable after having received = a SCAN_RSP: > HCI Event: LE Meta Event (0x3e) plen 38 #73 [hci0] 34.359921 LE Advertising Report (0x02) Num reports: 1 Event type: Scan response - SCAN_RSP (0x04) Address type: Public (0x00) Address: F4:B8:5E:64:02:55 (Texas Instruments) Data length: 26 Name (complete): BeeWi SmartLite Peripheral Conn. Interval: 0x0028 - 0x0050 TX power: 0 dBm RSSI: -42 dBm (0xd6) @ MGMT Event: Device Found (0x0012) plen 40 {0x0001} [hci0] 34.360057 LE Address: F4:B8:5E:64:02:55 (Texas Instruments) RSSI: -42 dBm (0xd6) Flags: 0x00000004 Not Connectable Data length: 26 Name (complete): BeeWi SmartLite Peripheral Conn. Interval: 0x0028 - 0x0050 TX power: 0 dBm But all ADV_IND PDU's before that clearly indicate that the device is = connectable, it is only after this SCAN_RSP that it is reported as Not = connectable: > HCI Event: LE Meta Event (0x3e) plen 27 #46 [hci0] 34.152817 LE Advertising Report (0x02) Num reports: 1 Event type: Connectable undirected - ADV_IND (0x00) Address type: Public (0x00) Address: F4:B8:5E:64:02:55 (Texas Instruments) Data length: 15 Flags: 0x06 LE General Discoverable Mode BR/EDR Not Supported Company: Texas Instruments Inc. (13) Data: 06030108b0e408f7 RSSI: -43 dBm (0xd5) @ MGMT Event: Device Found (0x0012) plen 31 {0x0001} [hci0] 34.152905 LE Address: 44:6E:FF:00:0D:65 (Resolvable) RSSI: -74 dBm (0xb6) Flags: 0x00000000 Data length: 17 Flags: 0x1a LE General Discoverable Mode Simultaneous LE and BR/EDR (Controller) Simultaneous LE and BR/EDR (Host) TX power: 9 dBm Company: Apple, Inc. (76) Type: Unknown (16) Data: 01188898dc > HCI Event: LE Meta Event (0x3e) plen 41 #47 [hci0] 34.156958 LE Advertising Report (0x02) Num reports: 1 Event type: Connectable undirected - ADV_IND (0x00) Address type: Random (0x01) Address: FA:BD:8D:12:26:BF (Static) Data length: 29 Name (short): P mesh Flags: 0x04 BR/EDR Not Supported 128-bit Service UUIDs (partial): 1 entry Vendor specific RSSI: -47 dBm (0xd1) @ MGMT Event: Device Found (0x0012) plen 29 {0x0001} [hci0] 34.157030 LE Address: F4:B8:5E:64:02:55 (Texas Instruments) RSSI: -43 dBm (0xd5) Flags: 0x00000000 Data length: 15 Flags: 0x06 LE General Discoverable Mode BR/EDR Not Supported Company: Texas Instruments Inc. (13) Data: 06030108b0e408f7 So I am heavily doubting whether the Linux kernel code has a bug in = handling the SCAN_RSP. Please look at this part of the kernel:=20 = https://github.com/torvalds/linux/blob/48b1320a674e1ff5de2fad8606bee38f724= 594dc/net/bluetooth/hci_event.c#L6326 It sets the NOT CONNECTABLE flag by default for a SCAN_RSP and will = overwrite it with any flags it has received with a previous ADV_IND. But = it does not seem to take into account that in BLE heavy environments the = previous ADV_IND might be of a totally different device. So every now = and then it will enter the first path where it will just report the = device with a NOT_CONNECTABLE flag. Or am I missing something here?=