Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1822395pxp; Mon, 21 Mar 2022 06:01:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyyo4EZ7pW5T6RstWKlLQUXvtv9TUYLAFFLILREkkiyiiRy2rqkGPp3sDwAK5XQwTivLrK X-Received: by 2002:a05:6402:524c:b0:419:4d8c:e959 with SMTP id t12-20020a056402524c00b004194d8ce959mr1726815edd.398.1647867674451; Mon, 21 Mar 2022 06:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647867674; cv=none; d=google.com; s=arc-20160816; b=Kdpf1lYAhZL65CZvm8CcasHgIQqmrr/WFem5gasmJULQmmFb67nGmHCD0Wz76kNk+9 CmVf/GLXsekRn3baqOu1G18NSfssyGY1pHl5rtocLcP7a+E9cwTQdIEdqb1evyhW2p2l kCoCK0w3uUDpqcNYcMvjwG539b1bscrj8YsggzXlK6aKx81hH7UEZBp2MAo4vx+U+Gga Ecw9FOao15ccoaKmeOJ0UWTQHt5LAYgr0pG+JCwUbUoUpUWN+yguB0T75E56wB2i22Qh 2jyEVpIvqwSGjbk97LwBlRDOxPOSF0IOInd2hHwitzdkA4phICdj5iTQ/FiS8cnUDEBI oIYw== 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=gh24cwy+hhvqTY6yTcGM/Wqmblsr/GhZPwqYp8ln8eg=; b=JpPPBx8cl297id8+jgungX5km4zO8kYbGFMqZVJV5ZeMousHg9fqh+KZrnyWDYOF2J vQK4EKOpJ+oMNt+72tV0p3Bz2aUjccpLe5nFL3aDje6C3f8s73EXVWZytiRncMf0yb21 tNIgTSkLA+FaonV2SJEXSeuAH6fOyAfofzPQ24yAJbM0KnfaZ3nPkpVc+x/3kFsWRZAC ExB/PGD48o7JgBlg6pTtXE9AOYVu8/v8yc7mzYD0TaXuLBiEK2aZRNxBnW7YrO7iP9Qr geteEx7spSfbsiDFofBfy2YVEZ7pnO9NYxM+oCWc2pJuY+EP/sXGKU5621t3xQwwM57K 80SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=V8qDSeI6; 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 c9-20020a1709063f0900b006dff4dd30f9si4267900ejj.862.2022.03.21.06.00.06; Mon, 21 Mar 2022 06:01:14 -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=V8qDSeI6; 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 S242511AbiCUBif (ORCPT + 99 others); Sun, 20 Mar 2022 21:38:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239687AbiCUBie (ORCPT ); Sun, 20 Mar 2022 21:38:34 -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 AAEF8DD971 for ; Sun, 20 Mar 2022 18:37:10 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d726bd83a2so114617437b3.20 for ; Sun, 20 Mar 2022 18:37:10 -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=gh24cwy+hhvqTY6yTcGM/Wqmblsr/GhZPwqYp8ln8eg=; b=V8qDSeI6DY3pOvq1KclyWn1njbsum7PTYm6R2wnEsg64bDTgyUVVqYbCi8vfzPVRGN hYQvfukAr0qj/LcWTRIzJar/7K9oh101LJd7O9/+Tv21kt43HNRpAQY/xP0TJDFxF3J4 7hEjfv59o4sDn0ndVVT8qmj/CrxGj7T75jvDMd6tCerPyTIBfi35cEq2I+ySLuWjG5li Rr2Aa2L9+Rell5p4xt8vnJG+QQMqnV+Dws+PvPlCBkik7CoC3NxAajaJ5SRxHfGp/Byv W96hzsxLPAPb5UdEHzwimmLac7ITE8BMvvpV1ptSBir08/Pk4gbt/o7zuaznWD/aZXbe Ruiw== 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=gh24cwy+hhvqTY6yTcGM/Wqmblsr/GhZPwqYp8ln8eg=; b=r6u8XkX8MI7zwMRodV457dz7GU7mIAjpwst27pEsfopq6wSYhCXuq6SXSF9L5jPoty j9av3CF8ZjJjxC7bCCuTY8ZC4oNul16/oesdI7/jo6nvupPxoyYnsYcZ3Ub3xhilqsT9 BUv7f/D/syAnYjngOLwu9ZTpKvC2gLtJDFs1d82IrR8SMq0L3W16SL3bGIGNBV77fjkn XwTTgAMtbnHoDKz9FrfVF7TWB4cy3kR6rZJQGk8JqZVgqV8BmXCgFVZQMRzq4HP8kYxD mFthNu1Gkodu770YxmE7+MDGDj1Nag6HdSxzz0zyefA4hgVatCiyQej2COxIoYMx8/WO wdkg== X-Gm-Message-State: AOAM530LRxhRw0R1OPhxEIY6Wlr3pjtCJvwoQiNeesBZm8UBlaUlfV2C 5VqhnRQnPtik7Bk9NzX8Ql/bXzDNfuYvCQ== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a81:1182:0:b0:2dc:4e58:da41 with SMTP id 124-20020a811182000000b002dc4e58da41mr21588794ywr.268.1647826629894; Sun, 20 Mar 2022 18:37:09 -0700 (PDT) Date: Sun, 20 Mar 2022 18:36:56 -0700 In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220320183445.BlueZ.2.Ie337efd4e92e6cbbf47503c29b67384327d91c73@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 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 --- 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.35.1.894.gb6a874cedc-goog