From patchwork Mon Mar 21 01:36:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85106C433F5 for ; Mon, 21 Mar 2022 01:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242456AbiCUBid (ORCPT ); Sun, 20 Mar 2022 21:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239687AbiCUBic (ORCPT ); Sun, 20 Mar 2022 21:38:32 -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 499E9DD971 for ; Sun, 20 Mar 2022 18:37:08 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id x9-20020a5b0809000000b00631d9edfb96so10943178ybp.22 for ; Sun, 20 Mar 2022 18:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=HzBVKHokxfG6S7lseDnOBheRWh/dqD/0K8SGlgy6lu8=; b=MAlcl39Vv4u8uf8wfbbLX0A/Sp4Hn0QNrmFa5ud3t81gVl8UKLSLLMHFHtShD9UmOW /Lp3TxraGWAkCKzrKs9JuUt5pgrFGlRkqLFznTcaYzeJHzDr1MSX55TK8S4CCaImxbO/ rQs8hMyiUieHe2RJeWgkqkGdhJDEqltznzAH7N5Gq2qdjnrW3fwMZoUqpuChDxeKnib+ ZvOFx6cpU5ujl7eo8dmfm0/JlqB+pxtGWjBlV6ZPLdUlNy4Fw0uKoIeo2zB9DNdoYoUR NxJl3d50A+bpisKNxGjHuKktPIFq9pg0SnVJwrIpetYjqFXXAK5y2PHcBJaaHhzoY7vl j9fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=HzBVKHokxfG6S7lseDnOBheRWh/dqD/0K8SGlgy6lu8=; b=M3ps0z6vSHAIOsHhPhVQhe8iFhshQzrqIgetPuREHFtEWIwE9TWtbn2UqHPTP2A3yp IgbYSzJlbXvv7T4S2JreLnRXnxWXeA0LeGSWM65IqIEAhzaMVPlTh7d9K66try/5aM16 3odUPBd+DI0cvx030tpoKk4UGs3pY96P0uXpvrmg0NsPgkK2XqzTAw2BCk8a9sxcpZ1/ qWSa80zDRHDxj907FcPByBHfbScs7DrCMI4ibLULs42EIMJsr/HO195x0LbaKsVJavX3 s3yrkz5Dy5g5brmbm6LRTS+QDfZM21Zrz0o4edf7VvvRnyqmeO641jf2nMlyAgPun32d a8ag== X-Gm-Message-State: AOAM533JxppR9ax03Hqa1rJSgRKMTluEYR0wqrjlUyVwCJ6lrrC5R7J3 J1QEsGwRFI5vS1PdGgE/VJxw75IT1gxMDw== X-Google-Smtp-Source: ABdhPJxa5H0XEYgb5c5UnmltAGYrG6sR1a0KRcIRWEZVx3v4ybsizLypNLg1kt1CyWVlWLu45RLXZdOMjTg/iA== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a25:cac5:0:b0:629:3595:a4bd with SMTP id a188-20020a25cac5000000b006293595a4bdmr20111758ybg.304.1647826627547; Sun, 20 Mar 2022 18:37:07 -0700 (PDT) Date: Sun, 20 Mar 2022 18:36:55 -0700 Message-Id: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog Subject: [BlueZ PATCH 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering 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 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Controller offloading does not support High RSSI Timeout. Disable High RSSI Timeout for SW based filtering as well to provide a consistent behavior between SW based and controller based monitoring. Reviewed-by: Miao-chen Chou --- doc/advertisement-monitor-api.txt | 5 +++++ src/adv_monitor.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/doc/advertisement-monitor-api.txt b/doc/advertisement-monitor-api.txt index 9189f2cce..942d44b2f 100644 --- a/doc/advertisement-monitor-api.txt +++ b/doc/advertisement-monitor-api.txt @@ -79,6 +79,11 @@ Properties string Type [read-only] in-range (found). Valid range is 1 to 300 (seconds), while 0 indicates unset. + NOTE: Controller offloading does not support High RSSI + Timeout. So, to provide a consistent behavior between + SW based and controller based monitoring, this property + has been disabled and deprecated. + Uint16 RSSISamplingPeriod [read-only, optional] Grouping rules on how to propagate the received diff --git a/src/adv_monitor.c b/src/adv_monitor.c index 33f4d9619..a1778248f 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -860,6 +860,12 @@ static bool parse_rssi_and_timeout(struct adv_monitor *monitor, monitor->rssi.low_rssi_timeout = l_rssi_timeout; monitor->rssi.sampling_period = sampling_period; + /* Controller offloading does not support High RSSI Timeout. Disable + * High RSSI Timeout for SW based filtering to provide a consistent + * behavior between SW based and controller based monitoring. + */ + monitor->rssi.high_rssi_timeout = ADV_MONITOR_UNSET_TIMEOUT; + done: DBG("Adv Monitor at %s initiated with high RSSI threshold %d, high " "RSSI threshold timeout %d, low RSSI threshold %d, low RSSI " From patchwork Mon Mar 21 01:36:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786734 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D022C433F5 for ; Mon, 21 Mar 2022 01:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243814AbiCUBif (ORCPT ); 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-Google-Smtp-Source: ABdhPJzR03d1BmWhedO56PFRQHMn5FVHjd/CBdF5e6NvSvm0FWZA5BgpOd4CgNRV18d4ipl7VlROR8/LH5JrDg== 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 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); From patchwork Mon Mar 21 01:36:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42DD0C433EF for ; Mon, 21 Mar 2022 01:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244605AbiCUBii (ORCPT ); Sun, 20 Mar 2022 21:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244224AbiCUBih (ORCPT ); Sun, 20 Mar 2022 21:38:37 -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 8EF7DDD97C for ; Sun, 20 Mar 2022 18:37:13 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2e62857e0d2so15123267b3.14 for ; Sun, 20 Mar 2022 18:37:13 -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=uLPcmR4K6QwbWhmkn/cTqz/cPCrfSkt7khr1jCpbRs0=; b=ly6XuN0pDqdkZaJ9yeM+zvnu8PRlOFNeXixNmFxAJ992SmfXVxJ4T/6WWlnGH46/Ah INwSaZiEkuXKjch6wrbU0vE7qKN0FMQZ5Zv6jtB3jW+JFBcbgWMbbWEsDRagH3EiipmK XPa9DSG5pG3orYP0C+Q15h7yjV+FINL3OQvJ9tH+WoONfW/kf/DxXWaVQI4NWJfBAX1Z p/IFXmphlA5j5MhsG0uO8rbTXr2L9nrfS2PRy0SxbYfUPCXlrg1Lm3fASSOSnLOp7KRD L6kJn73PW+HHfsc8EINqhdJF45JN+uD1/BjFmfbqjj7t/vhvUU8Gfmjr7ElCwrUxNzPz ABuw== 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=uLPcmR4K6QwbWhmkn/cTqz/cPCrfSkt7khr1jCpbRs0=; b=BBJ29aIpkxSnOwodfyH6wl4IbtAcaLHTKvh+FdL/93y6u7VqXJtNu8Aub5W3NY96i4 7Lb/2SsoT6RINYFove+AZKJW01QgkUjHNiFMykWvbKmuAIm/4uQT7AJrEc1BNv3iVCfb 1wZ4b08ulX/SCbH6Ttb+PCQfKw+auJSDF3sZyyisrUnBtkokpSFHRCERUYDRdj9vyiLb T1HWxz0WGu8inzxzTZSbe+gKm38eDZRuVUWl2AtGY8ivddbRifOimO0NVz8DqwM726qD 2v+qTfK2T/dju5+/MWzOjrc8Pv1t3BaYZ20DlVnTpjrR/g91X6AzGrVMRO9h83BncnaN UtQw== X-Gm-Message-State: AOAM5332Pd7l9VWu3F9ciL64MatRn2TGdtIQLRsSuDKnxTzXdLwTO+fR SMAWkgpF0NuEWH328zd5myXXxQRtxMI6rA== X-Google-Smtp-Source: ABdhPJxk1wPMuV6Wx4tC8zsSiqQ106ZbFVmes2t7GZrW92nyTQT79KNi/lYuZxGPlh6sc7ajJKFhFM6W1wFkrQ== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a81:1458:0:b0:2e5:fa20:3531 with SMTP id 85-20020a811458000000b002e5fa203531mr9455347ywu.387.1647826632782; Sun, 20 Mar 2022 18:37:12 -0700 (PDT) Date: Sun, 20 Mar 2022 18:36:57 -0700 In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220320183445.BlueZ.3.Icb5e0b991a133d9b8a91a23f1c9b2ca41e151a27@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 3/9] adv_monitor: Clear tracked devices on resume 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 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Clear any tracked devices on system resume. Matched devices will be found again if they are in range after resume. Reviewed-by: Miao-chen Chou --- src/adapter.c | 1 + src/adv_monitor.c | 19 +++++++++++++++++++ src/adv_monitor.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index 97ce26f8e..2ae8a9ae9 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -9183,6 +9183,7 @@ static void controller_resume_callback(uint16_t index, uint16_t length, info("Controller resume with wake event 0x%x", ev->wake_reason); controller_resume_notify(adapter); + btd_adv_monitor_resume(adapter->adv_monitor_manager); } static void device_blocked_callback(uint16_t index, uint16_t length, diff --git a/src/adv_monitor.c b/src/adv_monitor.c index a7763df10..35d9bc9c8 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -2248,6 +2248,7 @@ static void clear_device_lost_timer(void *data, void *user_data) if (dev->lost_timer) { timeout_remove(dev->lost_timer); dev->lost_timer = 0; + dev->found = false; monitor = dev->monitor; @@ -2289,3 +2290,21 @@ void btd_adv_monitor_power_down(struct btd_adv_monitor_manager *manager) /* Clear any running DeviceLost timers in case of power down */ queue_foreach(manager->apps, clear_lost_timers_from_app, NULL); } + +/* Handles wake from system suspend scenario */ +void btd_adv_monitor_resume(struct btd_adv_monitor_manager *manager) +{ + if (!manager) { + error("Unexpected NULL btd_adv_monitor_manager object upon " + "system resume"); + return; + } + + /* Clear any tracked devices on system resume. Matched devices will be + * found again if they are in range after resume. (No need to do this if + * the controller based monitoring is supported as the kernel clears all + * monitored devices on resume. + */ + if (!btd_adv_monitor_offload_supported(manager)) + queue_foreach(manager->apps, clear_lost_timers_from_app, NULL); +} diff --git a/src/adv_monitor.h b/src/adv_monitor.h index c6bb8a68a..3b5b1200a 100644 --- a/src/adv_monitor.h +++ b/src/adv_monitor.h @@ -42,4 +42,6 @@ void btd_adv_monitor_device_remove(struct btd_adv_monitor_manager *manager, void btd_adv_monitor_power_down(struct btd_adv_monitor_manager *manager); +void btd_adv_monitor_resume(struct btd_adv_monitor_manager *manager); + #endif /* __ADV_MONITOR_H */ From patchwork Mon Mar 21 01:36:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBFFEC433F5 for ; Mon, 21 Mar 2022 01:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344020AbiCUBin (ORCPT ); Sun, 20 Mar 2022 21:38:43 -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-Google-Smtp-Source: ABdhPJwlVva+cXpU8GCm3W74m4FHHVElpESBgCFqe5Al87O5c4+HbNbu7wvt5hP1rN6okuaKF5NjxdBvR4BmRw== 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 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); From patchwork Mon Mar 21 01:36:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 679D6C433EF for ; Mon, 21 Mar 2022 01:37:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344011AbiCUBis (ORCPT ); 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 S1344022AbiCUBin (ORCPT ); Sun, 20 Mar 2022 21:38:43 -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 97ECADD97A for ; Sun, 20 Mar 2022 18:37:18 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id z15-20020a25bb0f000000b00613388c7d99so11069572ybg.8 for ; Sun, 20 Mar 2022 18:37:18 -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=YXq71nLjntbIYjgifO6/WWT8gp5pZBjfe99X73obMew=; b=VAA1ZDAvMSYm2jMxo+arQfNPGcQMlrSCd/DN6HGS5AtgWAo5tr+et0iw7iLf5LOGEp 9lyj1o1oyDDihvMaeNtyuHxv1ZL5nYXgxP2B4bNbFUzlxKEhk+TE8Ff4snVbg28zk2aj IbjJ3taYFoDHwTKc4ZD9PjGKOPBuE6f0vjGFZPMFXx4BsbVaBFta1V6MkWmd0mpk+iJu tmSU+AZ5DBMI3Z96NuFs/XV6EdrMf4Wk4DPAmIpwiXCPDqa28260Ho3cAHMarNEuj79s GWuIYXJzqUiIbZ2O/kaKUwwgWb2OmNAVayVf8775QQna83eW023yTqIt980p/7TaxsrY DGyg== 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=YXq71nLjntbIYjgifO6/WWT8gp5pZBjfe99X73obMew=; b=WXQvafaXoJjG+2JJpHURR+T1cAAl8D+0slvA+NkmkDtWE10Zd9Ly3Qsdezj1AVTAEP vU/Ic3LNWGoWQynzrwco5pn+aEgWSKa4+mC5H0D0x8VRp2q2Tx52yZi39CKhpA901AE3 RNguh4ONn+GnrNm5md8U8fVch147ZcpK1ZK0DqD1YVMlTximX12zE2IwvQjPGDoUCpPX Vn2mGRV6ysrkE1YZ5EqBPR1kxiQjG5Q67kZcgGzt7ws4UQcrJ8IVK+ZxuM5oPebZSXT+ 8/dScM5f9bKqlKFGGTmIktLy2ZoA1vExLwrFXsdMAV9HuzahEsd4Wm3zA445kFSXbeZj gUkQ== X-Gm-Message-State: AOAM532Nlc1rTFi2HVOtIkZtCThp3Z9LWUBKxRhwlJ30t0wSa5/EfbHS ncRFNafbKFDavZcLQIAPltuR38fLtGO9JA== X-Google-Smtp-Source: ABdhPJwKYKmJ+O3Mbb2iOijDa4A8txzq0voseRw2rnD+dh7nO1Uzrp4Objnjjv1A05NdeeLU7UnXZrZDJ6L3PQ== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a81:493:0:b0:2e5:a1de:9f1a with SMTP id 141-20020a810493000000b002e5a1de9f1amr22477282ywe.88.1647826637817; Sun, 20 Mar 2022 18:37:17 -0700 (PDT) Date: Sun, 20 Mar 2022 18:36:59 -0700 In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220320183445.BlueZ.5.I53ad1b66c8f8a65e5950354cd20417d812ad9c72@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 5/9] monitor: Display AdvMonitor DeviceFound/Lost events 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 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Display information about MGMT_EV_ADV_MONITOR_DEVICE_FOUND and MGMT_EV_ADV_MONITOR_DEVICE_LOST events in the btmon output. Reviewed-by: Miao-chen Chou --- monitor/packet.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/monitor/packet.c b/monitor/packet.c index b7431b57d..6f615f7ba 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -14103,6 +14103,31 @@ static void mgmt_device_found_evt(const void *data, uint16_t size) print_eir(data + 14, size - 14, false); } +static void mgmt_adv_monitor_device_found_evt(const void *data, uint16_t size) +{ + uint16_t handle = get_le16(data); + uint8_t address_type = get_u8(data + 8); + int8_t rssi = get_s8(data + 9); + uint32_t flags = get_le32(data + 10); + uint16_t data_len = get_le16(data + 14); + + print_field("Handle: %u", handle); + mgmt_print_address(data + 2, address_type); + print_rssi(rssi); + mgmt_print_device_flags(flags); + print_field("Data length: %u", data_len); + print_eir(data + 16, size - 16, false); +} + +static void mgmt_adv_monitor_device_lost_evt(const void *data, uint16_t size) +{ + uint16_t handle = get_le16(data); + uint8_t address_type = get_u8(data + 8); + + print_field("Handle: %u", handle); + mgmt_print_address(data + 2, address_type); +} + static void mgmt_discovering_evt(const void *data, uint16_t size) { uint8_t type = get_u8(data); @@ -14414,6 +14439,10 @@ static const struct mgmt_data mgmt_event_table[] = { mgmt_controller_suspend_evt, 1, true }, { 0x002e, "Controller Resumed", mgmt_controller_resume_evt, 8, true }, + { 0x002f, "Adv Monitor Device Found", + mgmt_adv_monitor_device_found_evt, 16, false }, + { 0x0030, "Adv Monitor Device Lost", + mgmt_adv_monitor_device_lost_evt, 9, true }, { } }; From patchwork Mon Mar 21 01:37:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786738 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C52E3C433FE for ; Mon, 21 Mar 2022 01:37:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344015AbiCUBis (ORCPT ); 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-Google-Smtp-Source: ABdhPJylH7FYNdX5N6Zj7hZbR0Hj+qCPsALpWPT3096Dzbi/A4d9p60g41YsrM6hwQRPIbFVc7Lkvgke0J+P+A== 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 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; From patchwork Mon Mar 21 01:37:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8452DC433F5 for ; Mon, 21 Mar 2022 01:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344021AbiCUBit (ORCPT ); Sun, 20 Mar 2022 21:38:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242906AbiCUBis (ORCPT ); Sun, 20 Mar 2022 21:38:48 -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 B2A6DDD97A for ; Sun, 20 Mar 2022 18:37:23 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id y32-20020a25ad20000000b006339fb8e18cso8411417ybi.9 for ; Sun, 20 Mar 2022 18:37:23 -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=GXP6gytR/IH82JZglBDkMhSpMbMKKcfVk1giEr7fMLQ=; b=DH8mL8UPdPtPw/c+mZHBfeLAFMHKvyn92DMnEKnsIUeCF8pudXxyrgCgfA7L6odn9t EMaEIu4ECHCWGkm49IJ/BT4cuinyF9TB5/rc6aC4JUO3tdfU9Jr3sCpswxAi67Q2gdWk wCqwp70kyxUOzzcwmVgCkFmXQ4qFE7DvCRpGVWuMeyPO+KgPUExH0Aup+mbRM+dr7bmK qxi3ybBNwlhZYTQwLQMRKlUCWJcouDRpM2XxroAA9kX5LCRhe6nIZlZkLz0wj2ksx/Qo 822a1Q3PKowPreuSe8nGYOu3PafCVnZZMFPTBo33e+aiQaqPMyush21w8AVzfBTH6ExM P1cw== 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=GXP6gytR/IH82JZglBDkMhSpMbMKKcfVk1giEr7fMLQ=; b=hJXHOIyiHoxynFvdtyZQeYhRBddTWy/g1uqfbEHBSy7DsdthghyG/XkgQS9FJgTO8k AXPgfpjo3QQgMAhHwSnGyBPETjbGLwAkue6fk6VasBcVamgIk3bJFRGW707pmqOlNach PW6PWrDlML79UQU+y8Qj2KsmAn6uovoyv1uVAdOFN+Gm27PasbOaZ7+8JXijc67Z/hud fArYVv+N8kegtEj7OwbVsrmqvHfxjrsZdZuJM9A4RC2oaOsnARYUMNMOWqlQiNrFqjdx YDLTSDKp/B1HNSor4SX5a3bHJw9hiE3OU4N6GDjBGcwNspEOFGKbygn3566h9taTrbLa 0RUQ== X-Gm-Message-State: AOAM530otvCA6+npQ6Rn4VoOHMEM/LxmVQNYyakrofRQD9KHanfytalZ lbnl6m0EnAfqopZ68hDDZlsQAMfxUAc25Q== X-Google-Smtp-Source: ABdhPJzMqOWGU8GbqSvdcoCvBq9DPyMmoluoHTUzGlOZmdfbLeRmRNFtV+Lm6ypYPRoLLuVhThy10mjEcd6trA== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a25:5d0d:0:b0:633:25c8:380 with SMTP id r13-20020a255d0d000000b0063325c80380mr19732725ybb.167.1647826642982; Sun, 20 Mar 2022 18:37:22 -0700 (PDT) Date: Sun, 20 Mar 2022 18:37:01 -0700 In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220320183445.BlueZ.7.I668ef2477efd8fcdd9c44975c5f7b9f32af966ca@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 7/9] adv_monitor: Add the monitor Release reason 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 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Adv Monitor is released for various reasons. For example, incorrect RSSI parameters, incorrect monitor type, non-overlapping RSSI thresholds, etc. Return this release reason along with the Release event for the better visibility to clients. Reviewed-by: Miao-chen Chou --- doc/advertisement-monitor-api.txt | 12 ++++++- src/adv_monitor.c | 56 ++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/doc/advertisement-monitor-api.txt b/doc/advertisement-monitor-api.txt index 942d44b2f..fcbd9c5c2 100644 --- a/doc/advertisement-monitor-api.txt +++ b/doc/advertisement-monitor-api.txt @@ -17,12 +17,22 @@ Service org.bluez Interface org.bluez.AdvertisementMonitor1 [experimental] Object path freely definable -Methods void Release() [noreply] +Methods void Release(Int8 reason) [noreply] This gets called as a signal for a client to perform clean-up when (1)a monitor cannot be activated after it was exposed or (2)a monitor has been deactivated. + Possible reasons: 0 Unknown reason + 1 Invalid monitor type + 2 Invalid RSSI parameter(s) + 3 Invalid pattern(s) + 4 Monitor already exists + 5 Kernel failed to add monitor + 6 Kernel failed to remove monitor + 7 Monitor removed by kernel + 8 App unregistered/destroyed + void Activate() [noreply] After a monitor was exposed, this gets called as a diff --git a/src/adv_monitor.c b/src/adv_monitor.c index 85231557e..6ee3736d2 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -90,6 +90,18 @@ enum monitor_state { MONITOR_STATE_RELEASED, /* Dbus Object removed by app */ }; +enum monitor_release_reason { + REASON_UNKNOWN, + REASON_INVALID_TYPE, + REASON_INVALID_RSSI_PARAMS, + REASON_INVALID_PATTERNS, + REASON_ALREADY_EXISTS, + REASON_FAILED_TO_ADD, + REASON_FAILED_TO_REMOVE, + REASON_REMOVED_BY_KERNEL, + REASON_APP_DESTROYED, +}; + enum merged_pattern_state { MERGED_PATTERN_STATE_ADDING, /* Adding pattern to kernel */ MERGED_PATTERN_STATE_REMOVING, /* Removing pattern from kernel */ @@ -113,6 +125,7 @@ struct adv_monitor { char *path; enum monitor_state state; /* MONITOR_STATE_* */ + enum monitor_release_reason release_reason; struct rssi_parameters rssi; /* RSSI parameter for this monitor */ struct adv_monitor_merged_pattern *merged_pattern; @@ -137,6 +150,7 @@ struct adv_monitor_merged_pattern { struct queue *patterns; /* List of bt_ad_pattern objects */ enum merged_pattern_state current_state; /* MERGED_PATTERN_STATE_* */ enum merged_pattern_state next_state; /* MERGED_PATTERN_STATE_* */ + enum monitor_release_reason release_reason; }; /* Some data like last_seen, timer/timeout values need to be maintained @@ -541,6 +555,18 @@ static void monitor_free(struct adv_monitor *monitor) free(monitor); } +/* Includes monitor release reason into the dbus message */ +static void report_release_reason_setup(DBusMessageIter *iter, void *user_data) +{ + const struct adv_monitor *monitor = user_data; + int8_t release_reason = REASON_UNKNOWN; + + if (monitor) + release_reason = monitor->release_reason; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &release_reason); +} + /* Calls Release() method of the remote Adv Monitor */ static void monitor_release(struct adv_monitor *monitor) { @@ -560,8 +586,9 @@ static void monitor_release(struct adv_monitor *monitor) DBG("Calling Release() on Adv Monitor of owner %s at path %s", monitor->app->owner, monitor->path); - g_dbus_proxy_method_call(monitor->proxy, "Release", NULL, NULL, NULL, - NULL); + g_dbus_proxy_method_call(monitor->proxy, "Release", + report_release_reason_setup, NULL, + monitor, NULL); } /* Removes monitor from the merged_pattern. This would result in removing it @@ -635,13 +662,20 @@ static void monitor_destroy(void *data) static void app_destroy(void *data) { struct adv_monitor_app *app = data; + const struct queue_entry *e; if (!app) return; DBG("Destroy Adv Monitor app %s at path %s", app->owner, app->path); - queue_destroy(app->monitors, monitor_destroy); + for (e = queue_get_entries(app->monitors); e; e = e->next) { + struct adv_monitor *m = e->data; + + m->release_reason = REASON_APP_DESTROYED; + monitor_destroy(m); + } + queue_destroy(app->monitors, NULL); if (app->reg) { app_reply_msg(app, btd_error_failed(app->reg, @@ -793,6 +827,7 @@ static bool parse_monitor_type(struct adv_monitor *monitor, const char *path) } failed: + monitor->release_reason = REASON_INVALID_TYPE; btd_error(adapter_id, "Invalid argument of property Type of the Adv Monitor " "at path %s", path); @@ -919,6 +954,7 @@ done: return true; failed: + monitor->release_reason = REASON_INVALID_RSSI_PARAMS; btd_error(adapter_id, "Invalid argument of RSSI thresholds and timeouts " "of the Adv Monitor at path %s", @@ -1005,6 +1041,7 @@ static bool parse_patterns(struct adv_monitor *monitor, const char *path) return true; failed: + monitor->release_reason = REASON_INVALID_PATTERNS; btd_error(adapter_id, "Invalid argument of property Patterns of the " "Adv Monitor at path %s", path); @@ -1053,6 +1090,7 @@ static void merged_pattern_destroy_monitors( struct adv_monitor *monitor = e->data; monitor->merged_pattern = NULL; + monitor->release_reason = merged_pattern->release_reason; monitor_destroy(monitor); } } @@ -1086,6 +1124,7 @@ static void remove_adv_monitor_cb(uint8_t status, uint16_t length, return; fail: + merged_pattern->release_reason = REASON_FAILED_TO_REMOVE; merged_pattern_destroy_monitors(merged_pattern); merged_pattern_free(merged_pattern); } @@ -1142,6 +1181,7 @@ static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length, return; fail: + merged_pattern->release_reason = REASON_FAILED_TO_ADD; merged_pattern_destroy_monitors(merged_pattern); merged_pattern_free(merged_pattern); } @@ -1285,6 +1325,7 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) merged_pattern_add(monitor->merged_pattern); } else { if (!merge_is_possible(existing_pattern, monitor)) { + monitor->release_reason = REASON_ALREADY_EXISTS; monitor_destroy(monitor); DBG("Adv Monitor at path %s released due to existing " "monitor", path); @@ -1551,6 +1592,7 @@ static void remove_merged_pattern(void *data, void *user_data) { struct adv_monitor_merged_pattern *merged_pattern = data; uint16_t *handle = user_data; + const struct queue_entry *e; if (!handle) return; @@ -1562,8 +1604,14 @@ static void remove_merged_pattern(void *data, void *user_data) DBG("Adv monitor with handle:0x%04x removed by kernel", merged_pattern->monitor_handle); + for (e = queue_get_entries(merged_pattern->monitors); e; e = e->next) { + struct adv_monitor *m = e->data; + + m->release_reason = REASON_REMOVED_BY_KERNEL; + monitor_destroy(m); + } queue_foreach(merged_pattern->monitors, monitor_state_removed, NULL); - queue_destroy(merged_pattern->monitors, monitor_destroy); + queue_destroy(merged_pattern->monitors, NULL); merged_pattern_free(merged_pattern); } From patchwork Mon Mar 21 01:37:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56052C433FE for ; Mon, 21 Mar 2022 01:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344023AbiCUBiu (ORCPT ); Sun, 20 Mar 2022 21:38:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344018AbiCUBiu (ORCPT ); Sun, 20 Mar 2022 21:38:50 -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 320E4DD97C for ; Sun, 20 Mar 2022 18:37:26 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id l19-20020a252513000000b00629235aacb2so11055218ybl.13 for ; Sun, 20 Mar 2022 18:37:26 -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=2nmhRNWH/fk87U5vGxnIXXLDZ1M4aQ9tVgpNuh+z2ZU=; b=cbDc6t1hC258uMQYWKSs/Q3hfTrdNwU5pBdSqrrppW+R0sMYf/7lLcw/GoVcriBIyV WkC9jUsN2jvZqn+5vDjuEvOgi+NYcNWgWc2VmdvaUeaieyl7i7DW9XsIfEyXdxbFm9MA IB3lMbNxPSgVFDRx1NyWoVvzx1k0VEbsiQ4+VCFj0Gy83ssL6Ep5ir6tgiy3GKPOsAUg A/nVYNWh5EPu0aNyzKeZueWcf7hhtsqkQ3eUmwiR7+VkJ7L2LN0n+kyUanPdDl0u1tZF SZjdq0uAMKRDVX4B1xUbkK3g9ogN56IeMQMpOm3QFL2XE+WEGyeeUmdHwRY6diPvQHc1 f6Yg== 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=2nmhRNWH/fk87U5vGxnIXXLDZ1M4aQ9tVgpNuh+z2ZU=; b=mkLd8ggyE6+UaMbrzV6/YlwC8Aq1GmwzQkDO+90myWW1DzU4qSPX+j8eqop0JtbRI7 K6yyq7nyMCOecD7wWtFFKCPJREBCAzYrHiNmOaYGShtEH8RqOUGo1tN8m6irkEaEltAo HbIxuqhbyysXcCeuV0umtZqCPVKPJp0ZsgGPy6hpYoXy0VWeG+UJEI6UXS7qF56bsINu 7nzw4SNotmgu454i4wsSTeg7/yD2oA53n18udQqDV0a/JLzCwMM7h71zU4MAi5miSB2T E6qxnL24eyKDW/gS4T9AdUcZdKSMw8zT8y3xBSz4a7m7+d7TOxsxYIC3VLfwerpOG6qt u84A== X-Gm-Message-State: AOAM533CoclZByKdr10m129AfWctxYBY3i02tvdmgAdwHBLjQafKwCDo y/Wu7WUZ94yx+UcWiJ1vgIqLNeer3iFXjw== X-Google-Smtp-Source: ABdhPJwNyWCteB7/2R5ghO6byrYkMho+qgGEqRcBF/pCn4PcHqmDgUI0XTds/oWhNE+4b7wYvcVoVBX4KU3oow== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a5b:689:0:b0:61d:9014:bbbe with SMTP id j9-20020a5b0689000000b0061d9014bbbemr20476564ybq.34.1647826645451; Sun, 20 Mar 2022 18:37:25 -0700 (PDT) Date: Sun, 20 Mar 2022 18:37:02 -0700 In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220320183445.BlueZ.8.Ia97a9544495c94781c0391c0ec5a01273a278d18@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 8/9] client: Display the AdvMonitor Release reason 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 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Bluetoothd returns the release reason when a monitor is released. Read the release reason received as part of the Release event and print it using the bluetoothctl. Reviewed-by: Miao-chen Chou --- client/adv_monitor.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/adv_monitor.c b/client/adv_monitor.c index 792379fc4..6ee9d2b42 100644 --- a/client/adv_monitor.c +++ b/client/adv_monitor.c @@ -72,9 +72,13 @@ static DBusMessage *release_adv_monitor(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct adv_monitor *adv_monitor = user_data; + int8_t release_reason; - bt_shell_printf("Advertisement monitor %d released\n", - adv_monitor->idx); + dbus_message_get_args(msg, NULL, DBUS_TYPE_BYTE, &release_reason, + DBUS_TYPE_INVALID); + bt_shell_printf("Advertisement monitor %d released (reason: %d)\n", + adv_monitor->idx, + release_reason); remove_adv_monitor(adv_monitor, conn); return dbus_message_new_method_return(msg); @@ -117,7 +121,8 @@ static DBusMessage *device_lost_adv_monitor(DBusConnection *conn, } static const GDBusMethodTable adv_monitor_methods[] = { - { GDBUS_ASYNC_METHOD("Release", NULL, NULL, release_adv_monitor) }, + { GDBUS_ASYNC_METHOD("Release", GDBUS_ARGS({"reason", "y"}), + NULL, release_adv_monitor) }, { GDBUS_ASYNC_METHOD("Activate", NULL, NULL, activate_adv_monitor) }, { GDBUS_ASYNC_METHOD("DeviceFound", GDBUS_ARGS({ "device", "o" }), NULL, device_found_adv_monitor) }, From patchwork Mon Mar 21 01:37:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12786741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DC67C433EF for ; Mon, 21 Mar 2022 01:37:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344024AbiCUBix (ORCPT ); Sun, 20 Mar 2022 21:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344018AbiCUBiw (ORCPT ); Sun, 20 Mar 2022 21:38:52 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28C2DE901 for ; Sun, 20 Mar 2022 18:37:28 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id y32-20020a25ad20000000b006339fb8e18cso8411474ybi.9 for ; Sun, 20 Mar 2022 18:37:28 -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=iEjX0ROiUQFHfIqhoycGS7Ir4vAwahHJTq/EAslgS8I=; b=prYrO57GUhr+K+Ou6koSz/P2JmwDT/cR2h/7eipGfP2TzIbkLYu9gGSE3QmnvLZ189 orMZgRk782d686iKQ2hKCu30uFAQwr6hFxKanFmFgKyH0kNdNg7TM8OZmwB0N6wU0nv4 fkRI8j+P47YMNFJKN1YwaR7sBoLQyXN+FxR1WlXHsVj8hpHIOcq3iB4QFiK09wexDh63 xBmoIRkNDOGkR69uID7ibuZOLh80IP/KhJpI/6GHzp/JnpDWIzJYQLpFaQ3AIqpRSZqh zckn9j09oKzrcjI2hp2UY8QqxoKRdYkf4ONhEU22ki1KTpbWbMAMhtxuVvvKQPksmtf/ USuA== 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=iEjX0ROiUQFHfIqhoycGS7Ir4vAwahHJTq/EAslgS8I=; b=xygQFQbqMBxvs/2HviIomqDduYHH8BEI9uoskzCM01oHvLoIN0KMI0OFUdjqzGyjXE HTJF80gmv7Iu0Y6Fqd+OXwKFnylY+LUJXTxFPD8i8Vu8QiXS2ENEFvGuiRDqLTeqQpHe vQz1kzcw+PxPNYLG6RNQRu3CjxanAkpAOxCn0XTWITPI1F9iYV9PyPNTbl8WW4GForbR a5G/BWR/SehA7ZvclkMvDxXfkLL4X3UohD8KnBoH7Z6sderfmq4+tK0Dg3zPTdvK8+vp n270fxRyE4fWlPtjNJdwdb5bz6IxNZF8Fk4+SNIckEcg1fEGLGmWFMbJDdThdyK5vovT CvpQ== X-Gm-Message-State: AOAM531bgdVuabKyoTGtClDk/Hh4zEPjd+Pfk/ijKx6TuMagJ8ap1+rA 12+AW5AIkyZDGIvomvSXywOXQM7OGsnaww== X-Google-Smtp-Source: ABdhPJwjf8gLXMo3hNZ1SpaS10P/uXI+V4s36o54PZ4BFhKri9C8QvrbdXYdKP6C920UJQ7pbZEssP0DA42hTg== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:e0cb:81c1:7b8f:ab9f]) (user=mmandlik job=sendgmr) by 2002:a81:53c6:0:b0:2d0:e6df:adb6 with SMTP id h189-20020a8153c6000000b002d0e6dfadb6mr22178978ywb.483.1647826647887; Sun, 20 Mar 2022 18:37:27 -0700 (PDT) Date: Sun, 20 Mar 2022 18:37:03 -0700 In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> Message-Id: <20220320183445.BlueZ.9.I6c034497f366eccbb78925ad107ce957f81d97b1@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 9/9] test: Display the AdvMonitor Release reason 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 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Bluetoothd returns the release reason when a monitor is released. Read the release reason received as part of the Release event and print it using the example python app. Reviewed-by: Miao-chen Chou --- test/example-adv-monitor | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/example-adv-monitor b/test/example-adv-monitor index a405fc7b0..b01114c6b 100644 --- a/test/example-adv-monitor +++ b/test/example-adv-monitor @@ -117,10 +117,11 @@ class AdvMonitor(dbus.service.Object): @dbus.service.method(ADV_MONITOR_IFACE, - in_signature='', + in_signature='y', out_signature='') - def Release(self): - print('{}: Monitor Released'.format(self.path)) + def Release(self, reason): + print('{}: Monitor Released (reason: {})'.format(self.path, + format(reason, 'd'))) @dbus.service.method(ADV_MONITOR_IFACE, @@ -352,7 +353,10 @@ def test(bus, mainloop, advmon_mgr, app_id): # Run until user hits the 'Enter' key. If any peer device is advertising # during this time, DeviceFound() should get triggered for monitors # matching the advertisements. - raw_input('Press "Enter" key to quit...\n') + try: + raw_input('Press "Enter" key to quit...\n') # python2 + except: + input('Press "Enter" key to quit...\n') # python3 # Remove a monitor. DeviceFound() for this monitor should not get # triggered any more.