Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp860555pxb; Wed, 13 Apr 2022 14:13:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+hNKoYUDdgt1QcCrrK2LWf7hcd1/C9sdIM7fYd/UWkDznz6Z1xTV1ogoax6m8SsnHGSim X-Received: by 2002:a05:6a00:14ca:b0:4fb:5d3e:5f77 with SMTP id w10-20020a056a0014ca00b004fb5d3e5f77mr698107pfu.34.1649884436359; Wed, 13 Apr 2022 14:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649884436; cv=none; d=google.com; s=arc-20160816; b=N/gwwyWH1gaHMu8KCK79Sthhg+jf17w7Mxig4i58cHMCkNpBYrXoor4dJpFqeLaat8 NdmUEEPEr2j15eV191sPeduT8d5IzuEzzdIVrApoeMU2/hCrIZBhZjpYeM8WHROfTOxd y7L+tdaHBZP2MN1QzxuRePIvWD0QFhPqFCGkJahROxMd75cH1uku73SwWAouwol1cWmi 6uPR6GhFu/0tV9BGE1SPGZ8AdnXuVcKdrYpBeLu+JBagHmwn4t7CGb1HyydP4ZT1fhXM nJWxWq2y5rJHGev4b1ITNVFkkxExcX7YEzwTUbwTZ4/ZujWHoyJoFr4SuXHHa4KgvN8r RqqA== 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=NFvbHB/8fDYayZz14ZUldq7zRC0WFipDioxr1FFGnc8=; b=w9iM0UGIAlnx/rTtEumSHRPvNOb3EeQR8DGmc65HEiUOZMqcp1F9jRcDiqXXRdOTQq f+mJXu8bmxXcw8h3a9xCXXB6H0gp7eHuDHY7ict4Bx5Vhd5gqT/rOZTU44lX3IXK/Psr W3RVTC77fz57/Gvf3j0x9nWdFW8S6xvopyxZRpzORjsROP48EAIE0fivc/15yAk5E9lV tbAHYOi2HnqYrtojlG0a5zyk5DEHRWgksGVGJr7GtbcvFw3qJT9AVif/ovY8ycv+ATJ4 c6bo/wzGtBcpm4bd638OLjCqpohh7uBRUdyHBFtSZIZh//4ZN8cKmlthaVthawYKryjO jx6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JXmR7tv9; 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 78-20020a630051000000b0039db6053613si2420018pga.483.2022.04.13.14.13.20; Wed, 13 Apr 2022 14:13:56 -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=JXmR7tv9; 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 S237726AbiDMU5W (ORCPT + 99 others); Wed, 13 Apr 2022 16:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237910AbiDMU5V (ORCPT ); Wed, 13 Apr 2022 16:57:21 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59FD367D37 for ; Wed, 13 Apr 2022 13:54:59 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b12-20020a056902030c00b0061d720e274aso2644246ybs.20 for ; Wed, 13 Apr 2022 13:54:59 -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=NFvbHB/8fDYayZz14ZUldq7zRC0WFipDioxr1FFGnc8=; b=JXmR7tv9dLzUL1FVQOJ37L20K9fHt6LSyBAAiUKF0/sskbZKmLouTTS0VuhV5XhF7R /Rd7q3GT7gzh5T6A5VQ0izaFLVfCh6nL1pU6LbjiiWcqOWjs6Z1YUl6zvMgxA2aF5ZiB p8p3HsMumKCbqw7OZF23Mx5wH7iNjU0sI+e+YXBpxWk6PnsL4P9W9Kw+q3L+exgjNpTx eZNFpl9D9NB3KCA3dwcPJrFFPvPFGmd9kzl5/C9Y/wIUTk/nblzzc3CjSYL001Qa7gs9 Y4h1DpXnvBfbDvbnnhDVq2uDO+b3CfaLALCEOCNF2D6pK3VTwsn+TncC9W+6qlvE4IB+ ckiA== 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=NFvbHB/8fDYayZz14ZUldq7zRC0WFipDioxr1FFGnc8=; b=XmxtY7qVqRgIimHjqFR8MHrFUdeWmisBz2FnaQXRcI0urkK64Iaz0ZE17hL0IVnwzd RFu95BR4EFblVGNboFKHmCI6n7y+aW6z5Mv7rJqAJqqbIGuKnb/c3m/Q9uhGLhwXtn23 VOKqJafWsEQDVB+OLveMHXiAU4YXvaHiSqJzzz9N3ZpLQyp8QEMUb7SBQstFOaCBp3Z2 aPaI5hQ4tWJaF2QHIbbXm1nq5SzbfNs6EpjLzp7CKMlkqwBubBLnYeiHqQ5uopob++o4 gO01KELlpq2UXhR11C8rrf8TTLQQDLcklch6GyGLdvFEOU8Nc8Vbmy3PFJpYVD5Tm427 VE0Q== X-Gm-Message-State: AOAM531IdWevbrEB4z6RtEBJGsFBia/lPU3dGYEeNoBWMTVhYjMggyjl bfkH7EvkvhD2sA9YRlRE7nOe21Sm/aUpvg== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:2620:46aa:79ff:778d]) (user=mmandlik job=sendgmr) by 2002:a25:8c01:0:b0:634:712d:3def with SMTP id k1-20020a258c01000000b00634712d3defmr643817ybl.343.1649883298631; Wed, 13 Apr 2022 13:54:58 -0700 (PDT) Date: Wed, 13 Apr 2022 13:54:42 -0700 In-Reply-To: <20220413135223.BlueZ.v2.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220413135223.BlueZ.v2.2.Ie337efd4e92e6cbbf47503c29b67384327d91c73@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 2/9] adv_monitor: Don't send DeviceFound for already found devices 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 When monitors with same patterns are merged, BlueZ removes the existing monitor from the kernel and re-registers it with updated/merged RSSI parameters. The controller then triggers a new Device Found event for the device that matches the updated monitor. Don't notify the D-Bus client again with another DeviceFound for that device. Reviewed-by: Miao-chen Chou --- (no changes since v1) src/adv_monitor.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/adv_monitor.c b/src/adv_monitor.c index a1778248f..a7763df10 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -188,6 +188,11 @@ static void merged_pattern_send_add( static void merged_pattern_send_remove( struct adv_monitor_merged_pattern *merged_pattern); +static bool monitor_device_match(const void *a, const void *b); +static struct adv_monitor_device *monitor_device_create( + struct adv_monitor *monitor, + struct btd_device *device); + const struct adv_monitor_type { enum monitor_type type; const char *name; @@ -1555,8 +1560,26 @@ static void notify_device_found_per_monitor(void *data, void *user_data) { struct adv_monitor *monitor = data; struct monitored_device_info *info = user_data; + struct adv_monitor_device *dev = NULL; + uint16_t adapter_id = monitor->app->manager->adapter_id; if (monitor->merged_pattern->monitor_handle == info->monitor_handle) { + dev = queue_find(monitor->devices, monitor_device_match, + info->device); + if (!dev) { + dev = monitor_device_create(monitor, info->device); + if (!dev) { + btd_error(adapter_id, "Failed to create " + "Adv Monitor device object."); + return; + } + } + + if (dev->found) + return; + + dev->found = true; + DBG("Calling DeviceFound() on Adv Monitor of owner %s " "at path %s", monitor->app->owner, monitor->path); @@ -1652,8 +1675,25 @@ static void notify_device_lost_per_monitor(void *data, void *user_data) { struct adv_monitor *monitor = data; struct monitored_device_info *info = user_data; + struct adv_monitor_device *dev = NULL; + uint16_t adapter_id = monitor->app->manager->adapter_id; if (monitor->merged_pattern->monitor_handle == info->monitor_handle) { + dev = queue_find(monitor->devices, monitor_device_match, + info->device); + if (!dev) { + btd_error(adapter_id, "Adv Monitor device object " + "not found."); + return; + } + + if (!dev->found) { + btd_error(adapter_id, "Device not tracked."); + return; + } + + dev->found = false; + DBG("Calling DeviceLost() on Adv Monitor of owner %s " "at path %s", monitor->app->owner, monitor->path); -- 2.36.0.rc0.470.gd361397f0d-goog