Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1472791pxb; Thu, 14 Apr 2022 07:02:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEJoL3d2SmhhbGAlDyB+nctW83tD0xSFqH7Pxq5scLnAugKEBT2xUdLRaTLmYrrwkxv4+R X-Received: by 2002:a17:907:9958:b0:6e7:f67a:a1e7 with SMTP id kl24-20020a170907995800b006e7f67aa1e7mr2410689ejc.400.1649944954478; Thu, 14 Apr 2022 07:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649944954; cv=none; d=google.com; s=arc-20160816; b=PmrrBoz7Toxx0ScAQ3AgrBHUMzCypynE4H3tEdgJFOoD2LyhRz8TRi6QzgUblAMYCi 5ig1xstbRxJK543yoZP3/rYetxxT9wasUXkJph3ZBv9WiyIkWeUGKUSfZynhTAZKoIie UqkBEWKKhyPgEWYqDqyfCmVAu0OyeJezdNlTfzsc+Kl1OCVexXW4BKEMx9gSyNW7Lz8X WaFiDUOjlonn9kkFTeXSlgHOzzkkNjpnx8tLN9jilKjOXO/jSAKlmaBhl2QC7ZkXUifg wR36T+oRGxQNKyv10qRqg59zLLAdv3xZZ30iLjIw+DkXbr1ImvRnJzgChdsJHXIixo9/ I3hA== 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=0lBl5MKCkM7Tt+RyKRaq77MJ8KNp3O7zGBlqRNQca14=; b=SGPCLFPw4XjeNzVp7koMLcmUTJiuEmyd9FB6GipG9oV2V7wlzxy+mTEllRNF+w7mpq f5ZkeDv41arCuKQI38ggd1iUaNrL6rZghNg9g3ich0MZaPdFiVbwVHJyCuQN8F9dMxCR hJgEnciypHuWsZ/Ns+ohd18gwjG5pDA/t9ll1vF0Gl7W/93uWwuloHbvAa4os678zxRj svdwjD1Y+6ydJihLAEbffPpjxeBWVDRXkSD06DpUaUA94EHOqxIM1NQ6DHo++k7NT3FY GIcZKXCr7uWp5BRHTUIqk8VwWTOUn4aBHFoXhySbMEUjAUnmM5ojH7HpR58djWSKNxlV ruwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=A7+mMeLU; 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 ne25-20020a1709077b9900b006e8416a2d33si2664119ejc.454.2022.04.14.07.01.57; Thu, 14 Apr 2022 07:02:34 -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=A7+mMeLU; 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 S237910AbiDMU5u (ORCPT + 99 others); Wed, 13 Apr 2022 16:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238721AbiDMU5b (ORCPT ); Wed, 13 Apr 2022 16:57:31 -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 6719D71EEB for ; Wed, 13 Apr 2022 13:55:09 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2ec0490dc1bso26718477b3.5 for ; Wed, 13 Apr 2022 13:55:09 -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=0lBl5MKCkM7Tt+RyKRaq77MJ8KNp3O7zGBlqRNQca14=; b=A7+mMeLUdwcNR3VngEVpWmqNg2t3FS7xPQz3tJysUu/3lHjgEQq7v9/bh65U4pG/Ub ZKy5QjNvEQIN7axzQpIV499GR+zfZC7OziBxRqi0OTXkMBD4HEODv5Zw0425OncVK63Z poQgPsCv/IMWWaL0d2hm71964Y0knVlK35oiosdw0Y4somMYmbT3QEry2IiMFeJEAN07 6VxqbDzRW8Y0nsEW7G/Op758k713/T+ZdVl+hoJd2cIg2dju3QlTlXhrESlG92S7tk3s UZnxWbcFQQG9kbjxq1w6OkkYVdoB7HYs3kMl4iErRdcJ9FKXij6x3zGdIjhxrFsiGzqf RzAw== 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=0lBl5MKCkM7Tt+RyKRaq77MJ8KNp3O7zGBlqRNQca14=; b=6ObiTzoZE4IkLRqqY4/GOceNbateTnON3NdU7bcX4FM9i1+fNcaV+Fwsg/vMPqeyaU W6b3pthKvBenGKFmCEn08Im11mPjb6MnBvW2LVt3900a2k16owaipdOdsUSuNFoHqgrY IDOaWWIUmT5tMv4qfPDB+ML4nDYztSLHmZSoQwqU53CHgnXRTi0SBZZoZ1tPsVFpMzpX UbO/CHmOaSBhlcW8spH1XsFmsPzi5K0/BKOfvNv73Zfy4+SGG8ECqvHt2gbYnzaT/46d NXCssNPEz8Gb804fiNcYQXisqvZxK6Y1w8dpfJykQxWL+QQ8HxztEsU/uL6DJlCbqmPy qZNQ== X-Gm-Message-State: AOAM533Ut2nURlCLho/T+c7OERZWzX/X8WRvXQzcEU0/+N8x6NY3+vhO CklLtNLvyHOP8nlxoBKuwXmalyimv7vnVA== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:2620:46aa:79ff:778d]) (user=mmandlik job=sendgmr) by 2002:a25:ced1:0:b0:640:df7f:398 with SMTP id x200-20020a25ced1000000b00640df7f0398mr696044ybe.162.1649883308663; Wed, 13 Apr 2022 13:55:08 -0700 (PDT) Date: Wed, 13 Apr 2022 13:54:46 -0700 In-Reply-To: <20220413135223.BlueZ.v2.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220413135223.BlueZ.v2.6.Idb90bd382a52c8c0bc6fb5d936a9d5e5afac1fb5@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 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.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 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 --- (no changes since v1) 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 c01f8b154..d88e1bbbb 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.36.0.rc0.470.gd361397f0d-goog