Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3119652pxv; Sun, 27 Jun 2021 19:40:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPMBAovtJC55gpNE/0PTSzQ4Toaj8GrmeFFD1YmbqQHihKfOmOXTqm/vJ/4cIWiGAvbokc X-Received: by 2002:a05:6e02:dc9:: with SMTP id l9mr587296ilj.282.1624848051396; Sun, 27 Jun 2021 19:40:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624848051; cv=none; d=google.com; s=arc-20160816; b=XBjJ7uB7U8orgCh9ZCLh58J0l9TXkZJlUfjb0CqWADsY72Pj/qb1T2nW9NxKw5QTTG FHh/HDNWB4tjlY4JZEqD+B8cUfUSts0KU4TCqy9UwH4qQZu+9yRCNvYdrUOBfHpjY0E6 S4MPjr/OFA4QkVEiLfVeESeZ+r77l6496HrAOgROUCZF/WPpMIFwmO5sZpRa8OMQKF0w aYGW+tlwjV+AjiGmr5/cSXA9WHHd90jgoC5QjlQbavR3DcWdgQJJSjWHD7HCkzdEfYtj tzG6wQom9eibhaq6q1Mxjl/qtrQSUxUcWH0s+SvQsN5kEghQi/c1LiLnWo3ZCR24f2EU HT8w== 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=MwMqaF6KHjKax+s/NmkxoLDiKUl97GggGRlOq0iov10=; b=IO0E1rVlBUwXFUu1vc8md5vsUjf8vqG6jvbnxT3CiW1u21EzDJ4tIUWc3ZgYQuWf35 7SwHBba9Q6aMfK0Lms/a3p9bT76TfabErtgwQ+3SbY+GPY3+yQCVtmipkHT7LtxLOKpM rxbAD5yaArmGCUpzHsovkNbFRzdMmdhJ19yKMAxTKSqmM+SxuRPhzfkeIkz4XCyfQf8N WSBqBZl+sCa1Lm+x9Jrs86NgOgo/LvQwmOR0vzuSOzMBtZ8SA2MEPRqtZpc3HFkQhI5z hR9lVIrPsefACQ+NypJSC4luc41d3nJteXT3ZsNyJ16bS1gEQOKbGwp1323NRPSejvZC kSXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="OCHYf6/P"; 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 r4si18643694ilb.18.2021.06.27.19.40.16; Sun, 27 Jun 2021 19:40:51 -0700 (PDT) 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=20161025 header.b="OCHYf6/P"; 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 S231978AbhF1Cjq (ORCPT + 99 others); Sun, 27 Jun 2021 22:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231678AbhF1Cjq (ORCPT ); Sun, 27 Jun 2021 22:39:46 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45DEFC061574 for ; Sun, 27 Jun 2021 19:37:18 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id u12-20020a17090abb0cb029016ee12ec9a1so10169003pjr.3 for ; Sun, 27 Jun 2021 19:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=MwMqaF6KHjKax+s/NmkxoLDiKUl97GggGRlOq0iov10=; b=OCHYf6/PKaQnZnPn+VhqK1lHwCuadWuye44gQyd1xmcDoO2Je9MyapuCv3F81t8JJO JzRTjv355PK8Ayap8OizgkbcozPFBby2YtVVhRY1/c3oCMHlDZ3NRySZdllxwRzKSxlB uf1fisO2Ta2GcFAgoqVmcin6E3Ztl1sFdzMohsemh2ac/u88KDHnFhTPXFw3H6A0bWjy McyOAEEV92BWW6iJK2Z3zYGdndHXsQ9zHmX+qdRlh5OKkWBiPEU2sNPxZynSmy+Ac5Ou 4aAyBwH9/f5MM4qbhaUaA7pAlKjLlApiSZ+49+t6zY2O2O6ILUxFsvX7116ZEjx8t11U IIbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=MwMqaF6KHjKax+s/NmkxoLDiKUl97GggGRlOq0iov10=; b=gGWEuNlezJqczmhbFVFrIUrzpNa/n4v2WisqX/n5HLPUrTZVxl7HYn1/yigDPgnsqJ OYYQ3VgFZQ+s0KWriX54cvFPfHiRc/svVdoj1D9LV6KsrVhmczg2+qryjx1SWDhlVnPR Tsg1pHqNna3nQZokg08QDdnutRPv4hJcniP/Xzzl4jZMOe2+OPGqBskd6ovaupG9IQlv cFMGfY4JVmr+SeMy981csIIM2/x7X9rtsLLn2/s4HFPV4uqiIk+w4VuuaWqsVVsR46YJ ANbmElnepKm/Jv+ker0a3QoWbodU63utOSAVDBk/kJn75dlMLdnQUzYXfIVJ6W8+PPXB DPHw== X-Gm-Message-State: AOAM531MNSWIeJAIjIpGWXkrQ8vJI86uVUd1CnEmAtrU/0FsHS7FRTPh fPA/abwm2r8kh9XX2AfA4jbC49ZrYEcjS2VNglXkVbgclKTzH7pvacPzwVMmgsLsL6n71J7nkRh X0FTcZSeumuXrQXNDEoQiyw9hRNBsU0iYFnjpsXLEbAwl8+OHMJIYYNF9J/P7gOaTZIzwvBPJtl 3AgoNLaHaPxvw= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:1cb9:1290:1b4b:4db2]) (user=howardchung job=sendgmr) by 2002:a62:9242:0:b029:300:6fb1:38b7 with SMTP id o63-20020a6292420000b02903006fb138b7mr22221948pfd.80.1624847837600; Sun, 27 Jun 2021 19:37:17 -0700 (PDT) Date: Mon, 28 Jun 2021 10:37:12 +0800 Message-Id: <20210628103655.Bluez.v1.1.I5dc587c2fe4bf2e49927513cd711d353510c12fc@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [Bluez PATCH v1] src/adv_monitor: Remove checking in device lost timeout From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, Yun-Hao Chung , apusaka@chromium.org, mcchou@chromium.org, mmandlik@chromium.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Yun-Hao Chung The time check in device lost timeout could cause DeviceLost never being reported because of the following reasons: 1. Timer created in timeout_add_seconds, which calls g_timeout_add_seconds_full internally, can be fired one second earlier than |timeout| seconds. 2. When handle_device_lost_timeout is invoked early, time diff between |curr_time| and |last_seen| could be less than |low_rssi_timeout|. In this case, since handle_device_lost always returns FALSE, the timer will be removed, but DeviceLost has not been reported yet. 3. If we never receives any advertisement from that peer since then, DeviceLost will never be reported. We can remove the checking in handle_device_lost_time because we restart or remove the timer whenever an advertisement is recevied. Reviewed-by: apusaka@chromium.org Reviewed-by: mcchou@chromium.org Reviewed-by: mmandlik@chromium.org --- src/adv_monitor.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/adv_monitor.c b/src/adv_monitor.c index 17f1777eb1da..715ac5904b9a 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -1884,31 +1884,16 @@ static bool handle_device_lost_timeout(gpointer user_data) { struct adv_monitor_device *dev = user_data; struct adv_monitor *monitor = dev->monitor; - time_t curr_time = time(NULL); - DBG("Device Lost timeout triggered for device %p " - "for the Adv Monitor at path %s", dev->device, monitor->path); + DBG("Device Lost timeout triggered for device %p. Calling DeviceLost() " + "on Adv Monitor of owner %s at path %s", dev->device, + monitor->app->owner, monitor->path); + g_dbus_proxy_method_call(monitor->proxy, "DeviceLost", + report_device_state_setup, + NULL, dev->device, NULL); dev->lost_timer = 0; - if (dev->found && dev->last_seen) { - /* We were tracking for the Low RSSI filter. Check if there is - * any Adv received after the timeout function is invoked. - * If not, report the Device Lost event. - */ - if (difftime(curr_time, dev->last_seen) >= - monitor->rssi.low_rssi_timeout) { - dev->found = false; - - DBG("Calling DeviceLost() on Adv Monitor of owner %s " - "at path %s", monitor->app->owner, monitor->path); - - g_dbus_proxy_method_call(monitor->proxy, "DeviceLost", - report_device_state_setup, - NULL, dev->device, NULL); - } - } - return FALSE; } -- 2.32.0.93.g670b81a890-goog