Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1581999pxp; Sun, 20 Mar 2022 23:20:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4UutotiNNVXa1OhcxGflDfi1a9DfQ9zhEbdnxfmVm9Jzlr1+xio+LpBRUP9KJPpCvIcSk X-Received: by 2002:aa7:c748:0:b0:418:f0fb:83a1 with SMTP id c8-20020aa7c748000000b00418f0fb83a1mr21242183eds.350.1647843620878; Sun, 20 Mar 2022 23:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647843620; cv=none; d=google.com; s=arc-20160816; b=dxUUY+BeyhEdWj1BblKPwh4xMhRkv41psVwsU7t0ks3Z0p7EPNDCqZawX1HvTKjRVw SG8R+NMoU8rn7+XjHeSWdgdUqQad3yyI3ENVPTTiiDN+5Jv7baEcx0KE7NF6wtlsUkUb qP0qtxANemN8K27S7/zFX+H/0nne3E8X591ofl377YmbbBIt9V4oqAKgOXKNwyYHDmQm KleLjEMGiA85UZtomUoHzlzLjmIdZsgOYFMn1uAVxn1b+MZDexiWyTIsWaHhBsJd/fh+ n8bFagkA/dFYvUICzJrwAbTG8r7r/mbSSh3hbDeUS0uVUtTkTrcckU8CEkdp75I7kxwb 4P9w== 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=eCqYJR6Vta2NjxcLrsGvMmxUCWwhAPgPhCQWWuHd4Y4=; b=Vqc7vpceH6Z3As6727KBHW9lyrqILAFwzRgt7qSAqEecwl+i5g2ayW0W+E8zUrJrN+ iHJzSYADQEJ+bBR30TxvT6ItsYWxxBIOd7tvMmj5ihrTsMkGywH0bvWXeoVQ30ONAzYV bc+DVweCL0GpK1H+cqTtuHp+uWG5eShT6y8Otr+cung6xrF5aMCC7/R/iRspY2DTwD+t jJ6W8/xV0oG33FnjGeguVygv5l5VQ3ZLKulphcqj11onmy1IO9fKrY1sgkaMfkeVC9w8 610mL0FcPos7W0hvbaWWLdUwJCqU5yTaWgOTGZDTzdDQ9awyxEGKTOatl7GS2KEgPYU1 PpHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kz0Uc6pZ; 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 24-20020a170906005800b006df76385c19si6983870ejg.185.2022.03.20.23.19.41; Sun, 20 Mar 2022 23:20:20 -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=kz0Uc6pZ; 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 S244224AbiCUBil (ORCPT + 99 others); Sun, 20 Mar 2022 21:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343988AbiCUBik (ORCPT ); Sun, 20 Mar 2022 21:38:40 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C97E0DD97D for ; Sun, 20 Mar 2022 18:37:15 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2dc1ce31261so114074767b3.6 for ; Sun, 20 Mar 2022 18:37:15 -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=eCqYJR6Vta2NjxcLrsGvMmxUCWwhAPgPhCQWWuHd4Y4=; b=kz0Uc6pZ7z4oLTmSdIDcAxIKp1pbbb8D5r/MwgpHRds1vvkua53D+Tapa9acxdG7eo tY1J4TK9mgLoMW7YdmNAARBLQ+cmmUnwsfQGR5Orzljogr+cqAW8NdfgldrJ+t4d/54d B7U+Yrf01aUwh720VEnGdyxfzHlA5L+RUlOewVehAcyum7v1FIXvbh5rsAFKnDfZJRpu 88Kx7yAQoYkWssLF6STLKYjxHG8kf9xlHyvGXPsph0fbcg9VxSYznuAFr/80p+Ca+r// cEkLeRE6TXo4JlGsJI73qX65krYTK5X/DUCqP9tnO0Tkai3zCaft9BEwqlQM18SBm2SC sXyw== 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=eCqYJR6Vta2NjxcLrsGvMmxUCWwhAPgPhCQWWuHd4Y4=; b=MfedlTa5e2AX8Ybop2WxvcCP0qPmLLBviSf9h4wEn9gEqlGxoGQrhN33tdbHSXN+B9 vLJnVKJwnhJqU9NChBjYyqM7S+PXy4853NF9GVfm09bOfhcTRd6dOlHYcIa93Pc0hBVJ Qs8XNcC2guHC+7DjPrw0pq4iZgxrsEmu598Hfvi4PUgw5o/2pG47h7rn9kqP5b6vyyaY 6nyMw9ZuDc0CmyBGyluskkfAa0Zp3ZaAulCZ5JtZQr6SWnKYn1iUe68li0D4pEXmBYuZ 7IzNKwTE1eEH28pRKJKc0uheoCBDFQAGYXrpzJ91d+CwsVVVmeXdbZDtdLFRVlLMs2x5 FPrg== X-Gm-Message-State: AOAM530BpGjhvrsBwX97ZPhdz1ki5h7UpwgvCw5Qy1wKsOZvSN35T4s8 1u6Q8SL9V7XURfNWSvaeuKN3xBlAFFinqQ== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a25:d684:0:b0:633:68be:a431 with SMTP id n126-20020a25d684000000b0063368bea431mr19728582ybg.555.1647826635086; Sun, 20 Mar 2022 18:37:15 -0700 (PDT) Date: Sun, 20 Mar 2022 18:36:58 -0700 In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220320183445.BlueZ.4.I81b6c0f613e08fe2cabd5c6b16ed68c2116e359d@changeid> Mime-Version: 1.0 References: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog Subject: [BlueZ PATCH 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 --- 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 35d9bc9c8..77b8ea10d 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.35.1.894.gb6a874cedc-goog