Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2269836pxp; Mon, 21 Mar 2022 15:28:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+QtplpB+X8T/2LMsHGwpPb88YJvYyi1kgNEAl4LxwZJa2tLRk6zgDWAnoe/n6ZKiiSVQ3 X-Received: by 2002:a63:5b4b:0:b0:382:9344:7224 with SMTP id l11-20020a635b4b000000b0038293447224mr3738932pgm.28.1647901694992; Mon, 21 Mar 2022 15:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647901694; cv=none; d=google.com; s=arc-20160816; b=xvrI09h9qS8m0dMPSgUePdylubWz2nf6+ui+nmKw9tYbj8IVuj1H4/eoUh+Bw2u7r5 UY97/GA/TDkJZLRGsfTEGetpkp3BmUAJILXVnKp+qiMdZ2BGLBn7GI4NZ5EfaZ4jhjXS Y9aCBQag10J+CrLUnMrznrG/so1ciknPuf1T+nz523JGtiI+ARpcg34Oz607T/VVvq0B y/AE55H8Lc8W07i9bxssQTiXGKSHN1T5CukWQjuz6/Q3Cd6m7dtBI3Hy0UqOpCqz5Gfi 0dcDpGd9b+aiaWWE8IsjU+15TexKUeztmP4QOpb64rJmsPDSi5qm4IRBLIWFCM3+2E+3 bm7g== 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=odBF3cajz4i7C33x4dHnygWlrAUv00Xw9OFqKIfJfoo=; b=J3pWVlhBrFQmiylolSq6WBceqAlQVoc/xUDM2NTdbVKd4lPVbQ9wJ9KiU2R/bFql0q Mh3MNxDsLmRvPxrKc8+YtWYO3jnkTVPw3S4mhjOMN3H6zkFG6LrMaY0lUbXcG5kfuwE7 rvL1NX7JuW1fuZmLHoEvmpf0CFsLenVSoAwywR+TvAYQ/ZTo954HyWZoYTc4AKN1I0Xt 7mC9pQVqcaLbY2XgqBeoia1tZ0pN7AFr28pusQtOyLTOGhSIv1H1/8noDPqn16H0LdRM a+YKqCFdlxi+NE7TGy0/0YuNfQBrcammxtcUEY0ka4lU6TxbsJ5Lldro/DFx1arjBxBA drMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=W8q6N9Ek; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k9-20020a170902694900b00153b2d1658bsi10987041plt.403.2022.03.21.15.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:28:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=W8q6N9Ek; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EDB613A6269; Mon, 21 Mar 2022 14:42:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343988AbiCUBis (ORCPT + 99 others); Sun, 20 Mar 2022 21:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343971AbiCUBiq (ORCPT ); Sun, 20 Mar 2022 21:38:46 -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 2AACE17C437 for ; Sun, 20 Mar 2022 18:37:21 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2e5d456d198so69619757b3.23 for ; Sun, 20 Mar 2022 18:37:21 -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=odBF3cajz4i7C33x4dHnygWlrAUv00Xw9OFqKIfJfoo=; b=W8q6N9EkQqviChZaxi/Zk4YgBWeZXnwAgrLZJYeMc0fuRhIfOyEZQNfSz7MAhAUNFp sx5TJBmBaNfOMyM9DCXoRv6N+RLofd3YOJ72/oJJbfwBKYMeimSg6XgYT5/5l/XILdEl JB/wx/5p5f9GtXuYyvNK2cMjIYsv6wSAA+YokgI8P7ItVIo2EQ4jeIUeb6tPnpVT/K8B C7BV75C8u46yvEufL1k4Hll9i5J1q1tY4uu8u1qBwNkoFqSOCSeQHaskx4JdjjInRTlo 2OVoCbtzOxXkXRLO5Nvg7c6s7ARAcnHPJFNj3NgL1DWpStmp44z4pb4wEmnlCffFTI9R PJqA== 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=odBF3cajz4i7C33x4dHnygWlrAUv00Xw9OFqKIfJfoo=; b=d1Mx7F8vuFQ717txo2z5u9e60gwU6V5WOZ56oNzuKzPMejmWhcy6kLidmBlu1wqP9M YIA44zyV102pXYiuy0tw1E3+V0MFx+HRW8Vgfoku3d34cZhLrzYPUw/KkoMejLBt2zlm coY1JLBwdqbXo55vfaFK6oaSWpiZUa6T08YVIJJ5XQ3WX5eJwxqBnRKVcahWBQIgtNFt xgiJPf9sVOsy80UAmX3Ch7A6LaKy/r91PKrJLsGCuc8vZOb+mNt2AsGma6WqrYNE39yK a/gCgo0Hi+CnlvyCtQEvtjPI4tWi/uyuXr0FL3uDsa59G0xMgXKcqbMTCL2cj7cgDn2a 9Vig== X-Gm-Message-State: AOAM532OlsaBub7eu+/xtDvYG/KYt9VE68kgxHF0sofL8dlRw9Z/mFd+ MKh/vUuGfBDtNt2OkO25SHM/F66twTtgLw== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a0d:d7c3:0:b0:2e5:8fc6:ed98 with SMTP id z186-20020a0dd7c3000000b002e58fc6ed98mr21743104ywd.206.1647826640389; Sun, 20 Mar 2022 18:37:20 -0700 (PDT) Date: Sun, 20 Mar 2022 18:37:00 -0700 In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220320183445.BlueZ.6.Idb90bd382a52c8c0bc6fb5d936a9d5e5afac1fb5@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 6/9] adv_monitor: Do not merge monitors with non-overlapping RSSI 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.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Merging two monitors with different RSSI thresholds is not possible if their RSSI ranges do not overlap. Example: Monitor 1: -40 -80 Result: Merge with updated RSSI Monitor 2: -60 -100 thresholds -60 -100 Monitor 1: -40 -100 Result: Merge with updated RSSI Monitor 2: -60 -80 thresholds -60 -100 Monitor 1: -40 -60 Result: Do not merge Monitor 2: -80 -100 Reviewed-by: Miao-chen Chou --- src/adv_monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/src/adv_monitor.c b/src/adv_monitor.c index 77b8ea10d..85231557e 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -251,6 +251,46 @@ static void merged_pattern_free(void *data) free(merged_pattern); } +/* Checks if merging monitors with different RSSI Thresh is possible or not */ +static bool merge_is_possible( + struct adv_monitor_merged_pattern *existing_pattern, + struct adv_monitor *monitor) +{ + const struct queue_entry *q_entry; + struct adv_monitor *q_data; + + /* Merging two monitors with different RSSI thresholds is not possible + * if their RSSI ranges do not overlap. + */ + + q_entry = queue_get_entries(existing_pattern->monitors); + + while (q_entry) { + q_data = q_entry->data; + + if (q_data->rssi.low_rssi >= monitor->rssi.high_rssi || + monitor->rssi.low_rssi >= q_data->rssi.high_rssi) + goto fail; + + q_entry = q_entry->next; + } + + return true; + +fail: + monitor->state = MONITOR_STATE_FAILED; + merged_pattern_free(monitor->merged_pattern); + monitor->merged_pattern = NULL; + + btd_error(monitor->app->manager->adapter_id, + "Adv Monitor at path %s is in conflict with " + "an existing Adv Monitor at path %s", + g_dbus_proxy_get_path(monitor->proxy), + g_dbus_proxy_get_path(q_data->proxy)); + + return false; +} + /* Returns the smaller of the two integers |a| and |b| which is not equal to the * |unset| value. If both are unset, return unset. */ @@ -291,14 +331,9 @@ static void merge_rssi(const struct rssi_parameters *a, */ merged->high_rssi_timeout = 0; - /* Sampling period is not implemented yet in userspace. There is no - * good value if the two values are different, so just choose 0 for - * always reporting, to avoid missing packets. - */ - if (a->sampling_period != b->sampling_period) - merged->sampling_period = 0; - else - merged->sampling_period = a->sampling_period; + merged->sampling_period = get_smaller_not_unset(a->sampling_period, + b->sampling_period, + ADV_MONITOR_UNSET_SAMPLING_PERIOD); } /* Two merged_pattern are considered equal if all the following are true: @@ -1249,6 +1284,13 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) monitor->merged_pattern); merged_pattern_add(monitor->merged_pattern); } else { + if (!merge_is_possible(existing_pattern, monitor)) { + monitor_destroy(monitor); + DBG("Adv Monitor at path %s released due to existing " + "monitor", path); + return; + } + /* Since there is a matching pattern, abandon the one we have */ merged_pattern_free(monitor->merged_pattern); monitor->merged_pattern = existing_pattern; -- 2.35.1.894.gb6a874cedc-goog