Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp146349pxb; Thu, 13 Jan 2022 03:59:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4U1bRdEgKayceF+nOFxuA/dyw2eMCvvHHiHx5/5crKOspSp3Hhjbxr9vVmGPStSNjH0Rf X-Received: by 2002:a05:6402:2926:: with SMTP id ee38mr3809732edb.213.1642075156478; Thu, 13 Jan 2022 03:59:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642075156; cv=none; d=google.com; s=arc-20160816; b=OA4vI41h1FIe8V5aPfi1BUhthh8Hgk10lBPgG25NGo8cO6aPbpzcxd5d8m1Z2j67gB c/BlrngPv92mQLNOJbam+0eCxK/bMxX2a/WFK4dBNfvQI1ILSLY9lYzhUFrp7r6om/td mKy4FtdNHkpWpUY6ANKenZ8BFsPNrvRE2rT0x8PN1/lnjXxyYMEckD/r7Tfjzi7vmnnn 1WbQCcpl9J3jf8HcX0VkaU3FKVRf5AanIFvvF/8RUsj6j9mPT6uxMdI6uH5u9sREnrlE 5/W8ZdEQMoLF4i91ZdHOc/tpOhGyQfFFMR+1DhLh+AO7cKEAuQuIGrhwIU0H8Msnu+7u Ondg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=lqg7D1vpwzpCQfKueX7qq7B6zdY7SHtCugzwSsPGXCM=; b=dbjzNOD+ur1caBe09iv+3VE92uNjsPCkxUsFFHWKk3n4xlr70LsWwAcDQca9FIOh9Y LNUX8kKzQDCttSCcdI/iTu18t8BHf6PE6d4IPg3nlCMgJBlV5uiGv5r8tB5GL6eKC4ki JKAhCSQoTNbHZ/3jkcWEx+iN2nnCF198ZjanVi9oJEI+8KsDHafGbvl++gboyKYv43n3 2J44ythKG9SKoFL0pPJ2yL0DgLd0kGV048LFizaEiXZ4RpSMN51bok9rN6eQODXlK03/ QMc3gAyDpznnTectzH7Wi6qi1ZsAYB9cHF95LsAU6pNzAJbR7f5wMOVdOetC4ewuIjey SpEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=G0SohyWs; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id oz24si1177864ejb.754.2022.01.13.03.58.06; Thu, 13 Jan 2022 03:59:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=G0SohyWs; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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 S232786AbiAMHrM (ORCPT + 99 others); Thu, 13 Jan 2022 02:47:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232791AbiAMHrM (ORCPT ); Thu, 13 Jan 2022 02:47:12 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C112C06173F for ; Wed, 12 Jan 2022 23:47:11 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id s19-20020a170902b19300b00149a463ad43so5308581plr.1 for ; Wed, 12 Jan 2022 23:47:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=lqg7D1vpwzpCQfKueX7qq7B6zdY7SHtCugzwSsPGXCM=; b=G0SohyWslUnm1mbCcGj4Ecpzca3PjKN/hf6QRip0KpRLPMgVNBiT12qbotvli2vfoC 149k5KodkeEUk/aAnFQsWda2gK4DznDwP+xu7/OfcT//F0L6SzxmAGohflgK3IVWiK37 zG246b9Fy0suNO02LmlIrSxq1XC9e2YsWwRGcLktTLexO6rjKCQY6qQLTatqHnObJV0y 8gFTUcVp3T2maLE0kCySQckZTTPme0uLqfkJNU30A+YsdfzAhYMjp9DkDhx1CWEEfh9r oIg9H0k5wzjmvg9JdfGIz3B2pAm+LABBPi4EPNIUcZzLtiTcDqrejoWY9UFOdTQTPiTl LxfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=lqg7D1vpwzpCQfKueX7qq7B6zdY7SHtCugzwSsPGXCM=; b=wVs3xODD5EMN3eYqZbl9uHndiEhr+PX7h2fZLHfI9ZS3BwJwdfzaaDLl3Kj//S9uwd nSmxlM81WOc9Xldvg90O3L9o7VIy19EMDhBX4tW82IMSP3hqJpu/tplsGx5NQTkc5Ssb VucQTGfVtZ+e6RwUVxlSfEqZ4BJ1P5ctHn+3mrH6jRj+dE7gSOMv/wprtpnhrAca0HMG FHoKgaAYaxb4jYwVVFcpjZG01KcNA0DI3Fa8cQWWuOotBCh0fq/djv9Ix/9/PMIYs3DN X0Ks5csPNhmr5zh3cH8s/hSFH7BoprZWg74BpNeR7wwUtLz3fb7ni8cpNlBf4B60ITjc SeYQ== X-Gm-Message-State: AOAM531IOFQ4eqNVj34bG6fLHXJoLdx0uxm3SZrh8CEbmlaYFX11cFAC xsGq4ezQPFxo7SgWZyjMFaArmGwmcqFkjGIGFfXUKGCVCHGXvMihoO/bHmOTa4dLvD0OBvlMBgr CSyoHlqUo7sXfU7TikeY0oYu4owJsdYBRhn59yGRJGZ0/jHTDuLOezhDTsVSgWu0Vhk6C9y+0tD Mz X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:8245:76ed:a5b3:7f11]) (user=apusaka job=sendgmr) by 2002:a63:7a54:: with SMTP id j20mr2819718pgn.294.1642060030869; Wed, 12 Jan 2022 23:47:10 -0800 (PST) Date: Thu, 13 Jan 2022 15:46:52 +0800 Message-Id: <20220113154626.Bluez.v2.1.Iad485a29772515142eefb1b120d5eb5e101d82f6@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.1.575.g55b058a8bb-goog Subject: [Bluez PATCH v2] device: Fix device can't be scanned for 5 mins after reboot From: Archie Pusaka To: linux-bluetooth , Luiz Augusto von Dentz , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Archie Pusaka After the patches which limit the attempts of doing remote name resolving, there's an issue which prevents BlueZ to RNR new devices for 5 minutes after reboot. It's caused by failed_time is init to 0, and is then treated as the timestamp when the device failed RNR. However, actually there is no failure yet. This patch fixes it by always allowing RNR when failed_time = 0. --- Changes in v2: * Separate the one big if into multiple smaller ifs for clarity src/device.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/device.c b/src/device.c index f2447c478e..6d29eb8966 100644 --- a/src/device.c +++ b/src/device.c @@ -4487,12 +4487,24 @@ bool device_is_name_resolve_allowed(struct btd_device *device) clock_gettime(CLOCK_MONOTONIC, &now); - /* If now < failed_time, it means the clock has somehow turned back, - * possibly because of system restart. Allow name request in this case. + /* failed_time is empty (0), meaning no prior failure. */ + if (device->name_resolve_failed_time == 0) + return true; + + /* now < failed_time, meaning the clock has somehow turned back, + * possibly because of system restart. Allow just to be safe. + */ + if (now.tv_sec < device->name_resolve_failed_time) + return true; + + /* now >= failed_time + name_request_retry_delay, meaning the + * period of not sending name request is over. */ - return now.tv_sec < device->name_resolve_failed_time || - now.tv_sec >= device->name_resolve_failed_time + - btd_opts.name_request_retry_delay; + if (now.tv_sec >= device->name_resolve_failed_time + + btd_opts.name_request_retry_delay) + return true; + + return false; } void device_name_resolve_fail(struct btd_device *device) -- 2.34.1.575.g55b058a8bb-goog