Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp36743pxb; Thu, 13 Jan 2022 01:11:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLilutUzm4OT4YBTPiWqitkY6glR5HgHg2SXZ6O2cCn69bqh4eUwcYtFDS4CoRbAOFXyzk X-Received: by 2002:a17:903:11cd:b0:149:bf70:2031 with SMTP id q13-20020a17090311cd00b00149bf702031mr3713896plh.40.1642065102783; Thu, 13 Jan 2022 01:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642065102; cv=none; d=google.com; s=arc-20160816; b=bHOM4f0kj9fgJus2aNw70ZLqPz7H17vxji9jYtp31FKJHvRaDKI9YbS83eSw+3lgfM CbKMVPeKbkhZeGPagDa85WGUO5+xk2hs36aKhsHMj7ktv8BhzRmAOH3M8WlUYyhRvWoS DWMAb1pXcKdk1zurSJPlYPgiBKA7I+y+7YjIOm3n9pC4dTuy1tkTa3p3kkWIL6N6R9E/ 3FS7m+94jQZ8ESDRWOSW1cOHIcc6UocYOhF60dd/ymTdUCsPnbMXQfA0YyzGNlUHunRB Bgj3qZHlKjnlo3is0lskbq4I06Bj93uBmBD+juBC+R9alLWzxB1ZJUjOY7/hKOHehjd9 Q6qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=iMhwf3Iu+brQUPQFN1+cibRAb8MViFV1vimei4pqOmU=; b=FsPeHzOFfq7NA7y8mzc/uXSGz2KxbrUalXG1QDLdzVSATtHmhYVFca1j94q18zjuEu EzcQaXEW+PZkI9iglDqqjDBZRAB7GNni19aNZOwKAEIkPZ7itabAbec6s0Aoe96AiC6v mi8k6IVkPzm2BCjadSVdmmQ97CqHqFvKNN4yhpqnIZRw3K5Vp5IxmR9456l1BjkgxZR5 WOwgb3kPt8d8w4pj8HQALyqqyl1Ix7Bwgz6HvthRvzx2GE1JZaGyfOt+xvUvMnEWYB9k IGfLuRGeNB1mKB+rm+kYcI3QHvKzSHVHvQWOOBSCnJG1GrcUkTDSgtoBm+WbZqPecJo4 xEjA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r19si1139460plr.18.2022.01.13.01.11.25; Thu, 13 Jan 2022 01:11:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230257AbiAMHFC convert rfc822-to-8bit (ORCPT + 99 others); Thu, 13 Jan 2022 02:05:02 -0500 Received: from coyote.holtmann.net ([212.227.132.17]:39367 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbiAMHFC (ORCPT ); Thu, 13 Jan 2022 02:05:02 -0500 Received: from smtpclient.apple (p4fefca45.dip0.t-ipconnect.de [79.239.202.69]) by mail.holtmann.org (Postfix) with ESMTPSA id BADDFCECF2; Thu, 13 Jan 2022 08:05:00 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Subject: Re: [Bluez PATCH] device: Fix device can't be scanned for 5 mins after reboot From: Marcel Holtmann In-Reply-To: <20220113141533.Bluez.1.Iad485a29772515142eefb1b120d5eb5e101d82f6@changeid> Date: Thu, 13 Jan 2022 08:05:00 +0100 Cc: linux-bluetooth , Luiz Augusto von Dentz , CrosBT Upstreaming , Archie Pusaka , Shuo-Peng Liao Content-Transfer-Encoding: 8BIT Message-Id: <2413B80E-E93D-49F1-849D-BAA899BAF832@holtmann.org> References: <20220113141533.Bluez.1.Iad485a29772515142eefb1b120d5eb5e101d82f6@changeid> To: Archie Pusaka X-Mailer: Apple Mail (2.3693.40.0.1.81) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Archie, > 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 CL fixes it by always allowing RNR when failed_time = 0. > > Reviewed-by: Shuo-Peng Liao > --- > > src/device.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/src/device.c b/src/device.c > index f2447c478e..16b1ed5bd3 100644 > --- a/src/device.c > +++ b/src/device.c > @@ -4487,10 +4487,15 @@ 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. > + /* Allow name request for any of these cases: > + * (1) failed_time is empty (0). Meaning no prior failure. > + * (2) now < failed_time. Meaning the clock has somehow turned back, > + * possibly because of system restart. Allow just to be safe. > + * (3) 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 || > + return device->name_resolve_failed_time == 0 || > + now.tv_sec < device->name_resolve_failed_time || > now.tv_sec >= device->name_resolve_failed_time + > btd_opts.name_request_retry_delay; > } I have the feeling this becomes complex and hard to follow. I appreciate the comment above, but just for thoughts, would it be better to do something like this: /* failed_time is empty (0). Meaning no prior failure. */ if (device->name_..failed_time == 0) return true; .. return false; Regards Marcel