Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp669944ybt; Wed, 8 Jul 2020 08:54:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxbu6ts7hagDQpLSIhVjylqTyY7T7uDe6kBdie7YJMr7dPT4smYTkZQUi5qG/08gpjr3iu X-Received: by 2002:a17:906:87c8:: with SMTP id zb8mr51475079ejb.35.1594223640809; Wed, 08 Jul 2020 08:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594223640; cv=none; d=google.com; s=arc-20160816; b=MPr1iLYdBxKMYivsG/+wl0t9EWP7cCtcY8eK8faUwq3g9lVnpvyyGE+XBaVUzxvZU4 u7YHcblErgx0HaAaMlvAmg6rdfJMmi6SNZxvb2uZttqLELqks+ri4iysTvVfCFQIxjme CCmEZAcTTgsLGG4MU4EHtKV6gMuWKcY3s++pO+O3NY7Y8xpruk0xdRTneJczMJVdqr6n m9VOgNspC6bE3yFFIzdidOXzVmaAUsGf/jRybiOcNvSGbMe6km+/BChhEelDgW02LQqX lD1NifJCEIEvZRHuGIkRrcLgI9Ds4r1/+r//o6Qx19mCeIh2hEibW7N4BMXwO1Uyhi4S Qwuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=3Rhw7BD+8GQYrmfzt2oYwuMMnAaDzpl0AiN3h3ecb1s=; b=itgRuV0hJfWlS7CibMDE1QOMt+8mFX1Yk6wSiknHRiJb5KLeQgSMMcrX4v65hZpycC O51UN/g+eFpi+v5nvk1NJAp7EoSf+UZFcdgCNgmWMNKMD33gUouSa3JJuwdsvYI/5CGB T18JNWbqgcSWlvestFUFqoaa3w/XhSkJqxcJAX/IvjhdQtN1LTL++MA+z3QccAKSEavb HvVKR2o5z9WObS7dvVz24PpYtszH11/Xufx3/MCV9gnSFuy04Iq9Rv3fSnAqq8FCjGYG QxmbFwlWI0tyX6vpfZbqUtbWxERF6/roSdoVxA6LsA68KYJhMhWUmcM6b1qmMmGn6x9E rXKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=n6etBYEN; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 90si231226edk.460.2020.07.08.08.53.16; Wed, 08 Jul 2020 08:54:00 -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=@gmail.com header.s=20161025 header.b=n6etBYEN; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730048AbgGHPxN (ORCPT + 99 others); Wed, 8 Jul 2020 11:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729022AbgGHPxN (ORCPT ); Wed, 8 Jul 2020 11:53:13 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FE61C061A0B for ; Wed, 8 Jul 2020 08:53:13 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id mn17so1394035pjb.4 for ; Wed, 08 Jul 2020 08:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3Rhw7BD+8GQYrmfzt2oYwuMMnAaDzpl0AiN3h3ecb1s=; b=n6etBYEN0g1HSageAUZbTww+qJrrsdPyEgON1OnzgBjLdR+5EDF5RqGyVC9t88JAdA BHPdLhAFCqx8JQqHyMvK9f2gReOFiyDNEu13EifQI7LN2guI9aLA4TnxapDiuLMhfw11 2NkN2R7TlnL0IblcvCnnwx1fnHHZilkwx2QAyza8ZKHPZaxyXg+DEWhvCz0/Vu5BdGpA 5mYoLpg5ixTGBKhsHgMOdgUC6ZUTGym19gRqpL44Lf7R2KxBIgJlhrnScLQfDP6G2pXX xm/UlRiilVoZIzv8pBEED3SUoCmOQPDB1I78Vr3vOk67fwPlxKeuug88L9PWR83Mk7EL zcrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3Rhw7BD+8GQYrmfzt2oYwuMMnAaDzpl0AiN3h3ecb1s=; b=m169Xp/bHEmadog4I/7rTAfGMu2WDdrpHeJobp+WCKMAiXErLyjFUQytx8dUy+mnfu 4H95OrOHLXMTsvmtk8pFURB6z+kfbmwg/n3r5Ko8XBVJZHurPMXSo7A6C1Ori7qx/Gvj e7WB32i+y7YuQlJDqr4C2te/zssyxg5KIdrctY5xJkD+9yS+Pk5Igj38VYNC/PF02D5V DE+VvrsvDz98+D0SOHLGOsKoohisdB0PsqdV7LaTAhftbm3Ay29OSyysO3UeQD6SFpwE QhskZf4Pe2O8Y6tJ2S7W9dvCPgAB+f6NMwzqLtPN+/htI5cqzhHYJXdHj+1q7Ty5V5Nk FrgA== X-Gm-Message-State: AOAM530bikkWA1tfMmUW5mEOAH7irzj9kzX++9KpR8Eyw8jTZhYSJwCn kV7NrHRslVCD1Js5hd3vRc8kJ7P0mpz/KyXV4Z3Xcqkw X-Received: by 2002:a17:90b:3683:: with SMTP id mj3mr10262945pjb.91.1594223592841; Wed, 08 Jul 2020 08:53:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrey Batyiev Date: Wed, 8 Jul 2020 18:53:00 +0300 Message-ID: Subject: Re: Temporary device removal during discovery To: Bastien Nocera Cc: linux-bluetooth Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Bastien, everyone, I've made a patch to the bluez, so the temporary devices are routinely purged based on their last_seen attribute. What do you think about such solution? Thanks, Andrey diff --git a/src/adapter.c b/src/adapter.c index 529002b02..101b03633 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -88,6 +88,7 @@ #define CONN_SCAN_TIMEOUT (3) #define IDLE_DISCOV_TIMEOUT (5) +#define TEMP_DEV_REAPER_INTERVAL (30) #define TEMP_DEV_TIMEOUT (3 * 60) #define BONDING_TIMEOUT (2 * 60) @@ -1491,18 +1492,18 @@ static gboolean remove_temp_devices(gpointer user_data) DBG("%s", adapter->path); - adapter->temp_devices_timeout = 0; - for (l = adapter->devices; l != NULL; l = next) { struct btd_device *dev = l->data; next = g_slist_next(l); - if (device_is_temporary(dev) && !btd_device_is_connected(dev)) + if (device_is_temporary(dev) && + !btd_device_is_connected(dev) && + device_last_seen_delta(dev) > TEMP_DEV_TIMEOUT) btd_adapter_remove_device(adapter, dev); } - return FALSE; + return TRUE; } static void discovery_cleanup(struct btd_adapter *adapter) @@ -1516,11 +1517,6 @@ static void discovery_cleanup(struct btd_adapter *adapter) adapter->discovery_idle_timeout = 0; } - if (adapter->temp_devices_timeout > 0) { - g_source_remove(adapter->temp_devices_timeout); - adapter->temp_devices_timeout = 0; - } - g_slist_free_full(adapter->discovery_found, invalidate_rssi_and_tx_power); adapter->discovery_found = NULL; @@ -1536,9 +1532,6 @@ static void discovery_cleanup(struct btd_adapter *adapter) if (device_is_temporary(dev) && !device_is_connectable(dev)) btd_adapter_remove_device(adapter, dev); } - - adapter->temp_devices_timeout = g_timeout_add_seconds(TEMP_DEV_TIMEOUT, - remove_temp_devices, adapter); } static void discovery_free(void *user_data) @@ -2405,7 +2398,7 @@ static bool parse_pathloss(DBusMessageIter *value, return true; } -static bool parse_transport(DBusMessageIter *value, +static bool parse_transport(DBusMessageIter *value, struct discovery_filter *filter) { char *transport_str; @@ -5362,6 +5355,11 @@ static void adapter_free(gpointer user_data) adapter->passive_scan_timeout = 0; } + if (adapter->temp_devices_timeout > 0) { + g_source_remove(adapter->temp_devices_timeout); + adapter->temp_devices_timeout = 0; + } + if (adapter->load_ltks_timeout > 0) g_source_remove(adapter->load_ltks_timeout); @@ -6343,6 +6341,9 @@ static struct btd_adapter *btd_adapter_new(uint16_t index) adapter->auths = g_queue_new(); + adapter->temp_devices_timeout = g_timeout_add_seconds(TEMP_DEV_REAPER_INTERVAL, + remove_temp_devices, adapter); + return btd_adapter_ref(adapter); } diff --git a/src/device.c b/src/device.c index 0deee2707..cebbabab2 100644 --- a/src/device.c +++ b/src/device.c @@ -4240,6 +4240,15 @@ void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type) device->le_seen = time(NULL); } +time_t device_last_seen_delta(struct btd_device *device) +{ + const time_t now = time(NULL); + const time_t bredr_time = now - device->bredr_seen; + const time_t le_time = now - device->le_seen; + + return bredr_time < le_time ? bredr_time : le_time; +} + /* It is possible that we have two device objects for the same device in * case it has first been discovered over BR/EDR and has a private * address when discovered over LE for the first time. In such a case we diff --git a/src/device.h b/src/device.h index cb8d884e8..75fd3ec60 100644 --- a/src/device.h +++ b/src/device.h @@ -44,6 +44,7 @@ void device_update_addr(struct btd_device *device, const bdaddr_t *bdaddr, void device_set_bredr_support(struct btd_device *device); void device_set_le_support(struct btd_device *device, uint8_t bdaddr_type); void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type); +time_t device_last_seen_delta(struct btd_device *device); void device_merge_duplicate(struct btd_device *dev, struct btd_device *dup); uint32_t btd_device_get_class(struct btd_device *device); uint16_t btd_device_get_vendor(struct btd_device *device);