Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp918079pxb; Wed, 13 Apr 2022 15:41:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUrPSmp1nKC0aTgynWvaaf9P8k7p/KaiAKLI1w4qdasvuASEMDHj2G2sl+VpdErUaXr5y5 X-Received: by 2002:a17:907:868b:b0:6e8:d819:6938 with SMTP id qa11-20020a170907868b00b006e8d8196938mr2045919ejc.651.1649889710675; Wed, 13 Apr 2022 15:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649889710; cv=none; d=google.com; s=arc-20160816; b=bpP48LGFeb6f6uYlV72oBVJd62WkEQMpcR8CQKo/7bXM2bgCHbZEEH/goZp5tUFOra 5Y1eRStvv4lIl6MzpFHayluenME3+uNUxgfwDYbC/p0jB9sPVaPtQN8GWRLx4+UYOc5u UysloOfE2dv+jMotlq9HtQyIhyQ5LtXmTgcIoLSSZlHPSI7Sb3W51KucXfGOBT2s5R35 kn9xrxIbLZ+DAXWhDMpWQvEuHtWjYrpJHzJh/Yy5JdwiqT/q/7/GaF8DFZnyzuRuIAE4 miSOhdTpzWVUJK48VzlaGag/xgmdOWvANsu6kbpAKwCJt56X8nV8v4nUJiPnxtE4RHgU 56Lg== 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:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=5QHuP0OaOqm2MvcLs33y6b/W3BiqwZkboBia8uB9AUA=; b=AcYLXnDAvmt/u1HTGEc7k7Vo1M7DtiaDO6nVV+QAX1SZEf4KIlR9bH9RRZvAOwLXlm 3Ld1AI3/wKhfK4/KXHt4OJ3RFi+QKLvn5XGNqBIL7q8NAzFGA980XkLi9IYJXByBXLcu MqCIsuFPHGt8OBETIpx3pOa4pkbImPDMe9uPt06N5lx1qos0whGexEfQw8Ucml6Ei7sb sAurSbtnpuMjiiIrzbr/inxSEtws1d3br0jTHOQbiJtRBOlvf+/47Bwv/GxXYO3aGxqV lekFYg6vQ07PjAIbpzYBW2tDTjma7oK+e87QlANyP4iOTdROoK82E2vl7YqKDvucrJoK Xt0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=h3q3T3AM; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kd17-20020a17090798d100b006e873306c2dsi860687ejc.225.2022.04.13.15.41.09; Wed, 13 Apr 2022 15:41:50 -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=@google.com header.s=20210112 header.b=h3q3T3AM; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238091AbiDMU51 (ORCPT + 99 others); Wed, 13 Apr 2022 16:57:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237910AbiDMU50 (ORCPT ); Wed, 13 Apr 2022 16:57:26 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 350A853718 for ; Wed, 13 Apr 2022 13:55:04 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2e642be1a51so25990967b3.21 for ; Wed, 13 Apr 2022 13:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=5QHuP0OaOqm2MvcLs33y6b/W3BiqwZkboBia8uB9AUA=; b=h3q3T3AM+ajBi5C/WQRDPdSFRViPIbkpjE1kaEFHChNiTGShVpCvuXk28+rd0tbRwd OH8HcSh86JZ7WfqF3tTx7HZwyhnPNsWY7AT5JqRyEFSeTRFEOEUU5UKm/TpFYL73IG9G jH6MMztu/POxny81xOHMY6VFG9WDdsMF3UQi0de5KIKlI5m7nQNcLykaFvdAk0RtHj6f KvVWKmeO2j5OYww4uLy9FeFuwhcPA68Kl1WSyp2As2f20f4YfgSYnOSqZe6oGPag/7O+ 36oBUGtdJwkl0nQ13CAArl78zmfyRbpNIfYeCS3o2fwtyjMxOgGD0mJbyKAfI+4RKNTJ kvcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=5QHuP0OaOqm2MvcLs33y6b/W3BiqwZkboBia8uB9AUA=; b=yFN0mi8AcUWa3D4iQ5ORL5aJsbS/NGYee4fx0QZMr2sNJqeGgDx8pFEJ0E6dPtOnSW XroeMt1/2kLBifAegFxkxSHiHJWyQvvYIoQatq+0in+WIfNnycGM9+7+lvpjZTpcGs7K oBUp+LLKPJ5KdGeuSh4bju0HmEcfJsFScj/4aBeWOTbziXnEHYzGDFo946jH2cKZrKvj HUuhBah3CWi6xi79C7pVU2sn67m20YB2swYcuKSF3wqxPeUKqIz8BlQxFQp8w8ONTo6Y e9UBbFlovrP94LNp3gS4gTkh0gpATpeyVZsbtJEUOhjj0gWYfAK0ZqNV5+9bPFvVq9PM WpDQ== X-Gm-Message-State: AOAM530wndcEXHxi0efLEwJix6uEGNMh8eJdOpYkx3ofYRvYmZKZVUTx 82yz8NqkMDQC53fgATAid8SHn1DwrsQxqQ== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:2620:46aa:79ff:778d]) (user=mmandlik job=sendgmr) by 2002:a5b:78f:0:b0:63d:936b:1a4 with SMTP id b15-20020a5b078f000000b0063d936b01a4mr687187ybq.29.1649883303495; Wed, 13 Apr 2022 13:55:03 -0700 (PDT) Date: Wed, 13 Apr 2022 13:54:44 -0700 In-Reply-To: <20220413135223.BlueZ.v2.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220413135223.BlueZ.v2.4.I81b6c0f613e08fe2cabd5c6b16ed68c2116e359d@changeid> Mime-Version: 1.0 References: <20220413135223.BlueZ.v2.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [BlueZ PATCH v2 4/9] adv_monitor: Do not remove the device while monitoring From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Manish Mandlik , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 Bluetoothd clears temporary devices if they are not seen for 30 seconds. When controller offloading is enabled and SamplingPeriod is set to 0xFF, the controller sends only one advertisement report per device during the monitoring period. In such a case, don't remove the temporary devices if they are being monitored. Reviewed-by: Miao-chen Chou --- (no changes since v1) src/adv_monitor.c | 4 ++++ src/device.c | 22 +++++++++++++++++++++- src/device.h | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/adv_monitor.c b/src/adv_monitor.c index 18ce839e9..c01f8b154 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -1663,6 +1663,8 @@ static void adv_monitor_device_found_callback(uint16_t index, uint16_t length, return; } + btd_device_set_monitored(info.device, true); + /* Check for matched monitor in all apps */ info.monitor_handle = handle; queue_foreach(manager->apps, notify_device_found_per_app, @@ -1745,6 +1747,8 @@ static void adv_monitor_device_lost_callback(uint16_t index, uint16_t length, /* Check for matched monitor in all apps */ info.monitor_handle = handle; queue_foreach(manager->apps, notify_device_lost_per_app, &info); + + btd_device_set_monitored(info.device, false); } /* Allocates a manager object */ diff --git a/src/device.c b/src/device.c index 3992f9a0c..00d0cc2fb 100644 --- a/src/device.c +++ b/src/device.c @@ -218,6 +218,7 @@ struct btd_device { GSList *services; /* List of btd_service */ GSList *pending; /* Pending services */ GSList *watches; /* List of disconnect_data */ + bool monitored; /* Tracked by Adv Monitor */ bool temporary; bool connectable; unsigned int disconn_timer; @@ -3206,11 +3207,30 @@ static bool device_disappeared(gpointer user_data) dev->temporary_timer = 0; - btd_adapter_remove_device(dev->adapter, dev); + /* Do not remove the device if it is being tracked by an Advertisement + * Monitor. It will be removed when the Advertisement Monitor stops + * tracking that device. + */ + if (!dev->monitored) + btd_adapter_remove_device(dev->adapter, dev); return FALSE; } +void btd_device_set_monitored(struct btd_device *device, bool monitored) +{ + if (!device) + return; + + device->monitored = monitored; + + /* If the device is not being monitored and the temporary_timer has + * already expired, it indicates that the device can be removed. + */ + if (!monitored && device->temporary && !device->temporary_timer) + device_disappeared(device); +} + static void set_temporary_timer(struct btd_device *dev, unsigned int timeout) { clear_temporary_timer(dev); diff --git a/src/device.h b/src/device.h index 071576d6b..0a4103747 100644 --- a/src/device.h +++ b/src/device.h @@ -87,6 +87,7 @@ bool device_is_connectable(struct btd_device *device); bool device_is_paired(struct btd_device *device, uint8_t bdaddr_type); bool device_is_bonded(struct btd_device *device, uint8_t bdaddr_type); gboolean device_is_trusted(struct btd_device *device); +void btd_device_set_monitored(struct btd_device *device, bool monitored); void device_set_paired(struct btd_device *dev, uint8_t bdaddr_type); void device_set_unpaired(struct btd_device *dev, uint8_t bdaddr_type); void btd_device_set_temporary(struct btd_device *device, bool temporary); -- 2.36.0.rc0.470.gd361397f0d-goog