From patchwork Sat Nov 20 15:29:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 516969 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 15DE8C433F5 for ; Sat, 20 Nov 2021 15:29:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231390AbhKTPc6 (ORCPT ); Sat, 20 Nov 2021 10:32:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbhKTPc6 (ORCPT ); Sat, 20 Nov 2021 10:32:58 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB890C061574 for ; Sat, 20 Nov 2021 07:29:54 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id lj10-20020a17090b344a00b001a653d07ad8so8559332pjb.3 for ; Sat, 20 Nov 2021 07:29:54 -0800 (PST) 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=CYpmfPbN3C/XAnsKeNyp26vn7Ku9902if6kiPcHTnMA=; b=laFLdRc24VNgngtSgCx1BZGvpOkmcudjOBDl4DMu2aTmKNYpl706EjrvwP0fFOTH/8 23YgPRyg0WTF8SApYM5Nl/HuQHguqBnBzftDU/g/wJnr3f0hZ16mpVXk32k8eMlcVY7K xY59qDTS3blyo6EqB1pVapuVftZQ9ZT4IEFC/3l+iKtWSnlf7q510Bb9q8Tunh2exoCW Z6YebxUYubiRp39HFQwt5HJhbpf6g4y3/nrkGPT0K3xu5O378imcY3C/5aTw33fISKuO zQ5jFB8RunucWao3TLNPK+VLeK4ScVUqMRZJyCSLlGioRV6zVwsiIwIA+MwAgxsZb4A4 xqXw== 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=CYpmfPbN3C/XAnsKeNyp26vn7Ku9902if6kiPcHTnMA=; b=ogOQKHtBO81S4eFiBBrcjKjNRmfb8FTxtrjlzfW6szKoBYT1WC8tu26vcbt/NLz4IS 5LqHYCEH2juYF6NZr0+JDK4fVkQx8Lf4llooAKiPvUlfqogy6+dJi/Ivz0qtThhjAjxt V+IN3TGop96D/d6QBzEomLc6VUHPfytFmzLBi8FxucOZKD3m58/dow9jpEAx1Xv97hZQ z7jEpTgk2Vbak/RqdBq0yTUiCYwpcp5biNUUlgKd2OWMjym7VmQf7y3T7u4uch300VHS /ZBZ6pUpGpa0R5shtF+yL6+5QQ/rFG6c5z4Tm0X1lrhXnf6rSb3pe5Fo7USUX/ZxMaQi hBnQ== X-Gm-Message-State: AOAM530hPIrQ1Q05MkDuwN5ViHffQNyg1FP4uyY5H9FvvQSWDXNDs01C enWCGa083YRlek5F2yjuY1JQD7djG+reOA== X-Google-Smtp-Source: ABdhPJwUY0pSz5rpdjZoj8hR7cz/xueqe/jDsfk8JbhAUoBBzgeRP5+A7/qOT8DrDWRaljAZn5MPF3q47sqUCw== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:8437:70f3:c03b:1c71]) (user=mmandlik job=sendgmr) by 2002:a65:50c6:: with SMTP id s6mr23074422pgp.352.1637422194400; Sat, 20 Nov 2021 07:29:54 -0800 (PST) Date: Sat, 20 Nov 2021 07:29:36 -0800 Message-Id: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [BlueZ PATCH v6 1/6] doc: Introduce the Adv Monitor Device Found/Lost events From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Manish Mandlik , Miao-chen Chou Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch introduces two new MGMT events MGMT_EV_ADV_MONITOR_DEVICE_FOUND and MGMT_EV_ADV_MONITOR_DEVICE_LOST to indicate that the controller has started/stopped tracking a particular device matching one of the already added Advertisement Monitor. If the controller offloading support is not available, MGMT_EV_ADV_MONITOR_DEVICE_FOUND event is also used to report all advertisements to perform software based filtering whenever we are not active scanning. Reviewed-by: Miao-chen Chou --- Hello Bt-Maintainers, Bluetooth Advertisement Monitor API was introduced to support background scanning and proximity detection based on the application specified RSSI thresholds and content filters on LE advertisement packets. To optimize the power consumption, the API offloads the content filtering and RSSI tracking to the controller if the controller offloading support is available. However, this monitoring is not completely offloaded as the bluetoothd also handles RSSI thresholds and timeouts in order to fulfill high/low thresholds/timeouts filtering with D-bus clients. There is further room to achieve better power optimization by supporting the controller event HCI_VS_MSFT_LE_Monitor_Device_Event to fulfill true monitor offloading. This is currently not supported as it was originally desired to minimize the changes to the MGMT interface and reuse the existing MGMT_EV_DEVICE_FOUND event to pass advertisements to the bluetoothd and let bluetoothd handle the RSSI thresholds and timeouts in order to fulfill the D-bus API requirements for the client. This patch series introduces MGMT events MGMT_EV_ADV_MONITOR_DEVICE_FOUND and MGMT_EV_ADV_MONITOR_DEVICE_LOST to indicate that the controller has started/stopped monitoring a particular device. Please let me know what you think about this or if you have any further questions. Thanks, Manish. (no changes since v5) Changes in v5: - Update the Adv Monitor Device Found event to include fields from the existing Device Found event. Changes in v4: - Add Advertisement Monitor Device Found event, make Address_Type 0 as reserved. Changes in v3: - Discard changes to the Device Found event and notify bluetoothd only when the controller stops monitoring the device via new Device Lost event. Changes in v2: - Instead of creating a new 'Device Tracking' event, add a flag 'Device Tracked' in the existing 'Device Found' event and add a new 'Device Lost' event to indicate that the controller has stopped tracking that device. doc/mgmt-api.txt | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt index 97d33e30a..8e7b5ef70 100644 --- a/doc/mgmt-api.txt +++ b/doc/mgmt-api.txt @@ -4910,3 +4910,63 @@ Controller Resume Event Address_Type. Otherwise, Address and Address_Type will both be zero. This event will be sent to all management sockets. + + +Advertisement Monitor Device Found Event +======================================== + + Event code: 0x002f + Controller Index: + Event Parameters: Monitor_Handle (2 Octets) + Address (6 Octets) + Address_Type (1 Octet) + RSSI (1 Octet) + Flags (4 Octets) + AD_Data_Length (2 Octets) + AD_Data (0-65535 Octets) + + This event indicates that the controller has started tracking a device + matching an Advertisement Monitor with handle Monitor_Handle. + + Monitor_Handle 0 indicates that we are not active scanning and this + is a subsequent advertisement report for already matched Advertisement + Monitor or the controller offloading support is not available so need + to report all advertisements for software based filtering. + + The address of the device being tracked will be shared in Address and + Address_Type. + + Possible values for the Address_Type parameter: + 0 Reserved (not in use) + 1 LE Public + 2 LE Random + + For the RSSI field a value of 127 indicates that the RSSI is + not available. That can happen with Bluetooth 1.1 and earlier + controllers or with bad radio conditions. + + This event will be sent to all management sockets. + + +Advertisement Monitor Device Lost Event +======================================= + + Event code: 0x0030 + Controller Index: + Event Parameters: Monitor_Handle (2 Octets) + Address (6 Octets) + Address_Type (1 Octet) + + This event indicates that the controller has stopped tracking a device + that was being tracked by an Advertisement Monitor with the handle + Monitor_Handle. + + The address of the device being tracked will be shared in Address and + Address_Type. + + Possible values for the Address_Type parameter: + 0 Reserved (not in use) + 1 LE Public + 2 LE Random + + This event will be sent to all management sockets. From patchwork Sat Nov 20 15:29:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 518218 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 04061C433EF for ; Sat, 20 Nov 2021 15:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234428AbhKTPdA (ORCPT ); Sat, 20 Nov 2021 10:33:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbhKTPdA (ORCPT ); Sat, 20 Nov 2021 10:33:00 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B39C061574 for ; Sat, 20 Nov 2021 07:29:57 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id q19-20020a056a00151300b004a4ca777976so696423pfu.19 for ; Sat, 20 Nov 2021 07:29:57 -0800 (PST) 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=f6zYR9MAYsS0039Eqvpfb2Rwm7MPpeLd6nNVycQISeQ=; b=pE0DUh6TPtbXYhSKVRGbXRr1v+E2953Plpa4no+jCLMGbz9z7vHc58RErlz914sAS5 6Ad+JRfq+lQPnaT2/JC5sJiVLenr7n3BD7kMpmqmolzVa9Rk0b6TB/I1WOWhQ5DD1HD2 dHemqGbJ1ueFe3FxoenThqP+zgsIlhBM0lyj+zhwBTWqougf8l6z1WfNX9JfsezUSafk jE+/NLlD43ItH8Ov49frkxUWBIlDhs3I4m0dzjIr0mf/CD+kuz/zUNCzXdXXb0jaMK9R jk7HLIX4/63pEQV018XLqpZyeEhRFwaU9TzTeV4mHMI5RYekoqlTJizyxlkrEWAdEJbi XvAA== 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=f6zYR9MAYsS0039Eqvpfb2Rwm7MPpeLd6nNVycQISeQ=; b=fuf71tUey1N/6k4SrTynz9sk6qix54iMZWjEWHDtqy4WP8zqulVPD8Qt3GWkeg/f2w hlqVW1Tn0hCr99qFlSK+sY3STpy+kmQIhsZioWz/iTvODyjqO0GGS5XT9vuxb5v1UHj/ orSNOhITb5vH5eKC9lGjmF3SHB50z099l5i9O5Oegw84I3vcoZPTIDUFptQz+3Tu8/c2 Mpb9NItqn53jzxnxSCntZc/4je/RmzBnbYlvlvw36R4vMDVLq3tjePljJnSrhqSs+G/e wongUn/R/zbO1AVIn2ZErsvnRRWfKspxnvid0OnEPBfmfVNRiJEmz6gmd041u5zOEeEo eSjg== X-Gm-Message-State: AOAM531zQkovcuHVzLUznr9aASYvspvJKewWf2ingudbFttKFKSqw7RL Ovc8ceIKVUMTXS/SdMYYUN3F0ps95uxGew== X-Google-Smtp-Source: ABdhPJx7krLnsVhMhPmRUOGulF1eG4p3sjyJNCKFXheqpUr0sS/Tcp8VCLW3bIDkXXZgtWBQpcCDw4aBvBJ4pg== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:8437:70f3:c03b:1c71]) (user=mmandlik job=sendgmr) by 2002:aa7:99cf:0:b0:49f:9d3c:ac0f with SMTP id v15-20020aa799cf000000b0049f9d3cac0fmr73053611pfi.39.1637422196566; Sat, 20 Nov 2021 07:29:56 -0800 (PST) Date: Sat, 20 Nov 2021 07:29:37 -0800 In-Reply-To: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211120072449.BlueZ.v6.2.Ied4afb8c4c882e573f4a23670fc060cbc3e319c9@changeid> Mime-Version: 1.0 References: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [BlueZ PATCH v6 2/6] lib: Add definitions of the Adv Monitor Device Found/Lost events From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Manish Mandlik , Miao-chen Chou Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch adds definitions of the new Advertisement Monitor Device Found and Device Lost events to indicate that the controller has started/stopped tracking a particular device. Reviewed-by: Miao-chen Chou --- (no changes since v5) Changes in v5: - Update the Adv Monitor Device Found event to include fields from the existing Device Found event. Changes in v4: - Add Advertisement Monitor Device Found event. Changes in v3: - Discard changes to the Device Found event and notify bluetoothd only when the controller stops monitoring the device via new Device Lost event. Changes in v2: - Instead of creating a new 'Device Tracking' event, add a flag 'Device Tracked' in the existing 'Device Found' event and add a new 'Device Lost' event to indicate that the controller has stopped tracking that device. lib/mgmt.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/mgmt.h b/lib/mgmt.h index 0d1678f01..3bc35bc7c 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -1014,6 +1014,22 @@ struct mgmt_ev_controller_resume { uint8_t wake_reason; } __packed; +#define MGMT_EV_ADV_MONITOR_DEVICE_FOUND 0x002f +struct mgmt_ev_adv_monitor_device_found { + uint16_t monitor_handle; + struct mgmt_addr_info addr; + int8_t rssi; + uint32_t flags; + uint16_t ad_data_len; + uint8_t ad_data[0]; +} __packed; + +#define MGMT_EV_ADV_MONITOR_DEVICE_LOST 0x0030 +struct mgmt_ev_adv_monitor_device_lost { + uint16_t monitor_handle; + struct mgmt_addr_info addr; +} __packed; + static const char *mgmt_op[] = { "<0x0000>", "Read Version", @@ -1152,6 +1168,8 @@ static const char *mgmt_ev[] = { "Advertisement Monitor Removed", "Controller Suspend", "Controller Resume", + "Advertisement Monitor Device Found", /* 0x002f */ + "Advertisement Monitor Device Lost", }; static const char *mgmt_status[] = { From patchwork Sat Nov 20 15:29:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 516968 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 1AF6BC433F5 for ; Sat, 20 Nov 2021 15:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234461AbhKTPdE (ORCPT ); Sat, 20 Nov 2021 10:33:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234510AbhKTPdC (ORCPT ); Sat, 20 Nov 2021 10:33:02 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD1F7C061574 for ; Sat, 20 Nov 2021 07:29:58 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id n6-20020a17090a670600b001a9647fd1aaso8553433pjj.1 for ; Sat, 20 Nov 2021 07:29:58 -0800 (PST) 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=smKACWAoQoueNUR+pRVMh86fOTRKhFr4+ViV3tZpMak=; b=qeeDoBhibimiFQn42Dta7qLsDA3aNqx/Wizn9xCKSuMigXNhW/qNHJGwB3xWftyki9 Hp/2ti4Dm9twEXenFNgNNe7rZeWwZus9kvJKpEwniblGl3exfSy/1Y9bA7CWpkzo5LFG v1ePrH7ngxBPkJUsnaBZka1vyu4cuO4y9kh6OoDduByRxuZi+2J8nEo4h2QzoIJxzd3N ce1/xr6N/vScpsB3MQxxBuMH7SdNwb8iyVQqUg91MmdraOHaF+EZr7EbfWCbMmlraj5w ftC9JzApzz2GNuSq6Se1FQ8PN5YJDPnjPfYN1ZvFrtdAtoz1KTsrp9PdOXO26QCrhvb2 6zww== 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=smKACWAoQoueNUR+pRVMh86fOTRKhFr4+ViV3tZpMak=; b=wHZXD9E1cOQ3x0RpAl/ASASX7mIPeh8WV35dpsBc1J6v4MeJWEPsiLNvjjGMJTdTU4 9A7BWuOOHA4PNT8RH0cNY+H1Jno/oyIzICGYVp8T0g43XzxzSQQbYb0xoUFim4as7UW1 89t8CfxmD6pz74bI+JOHdYzQHSqUIgXx6wu124F6BX9C0aucl+ICaxPV3ufgvf4g1g+k ewSBCcGOKY+LhRjS8s0xgSGYhCmVICiz1EGMArEDwCjYFbqPP4EBGFrNdD99URL9A7cs dvIk/mo5M6af5OaqFgQyRqMLNGEIt1vo3e1IfVsbIuiSliuFMrcPIi1NfPxOny5zVaP2 FypQ== X-Gm-Message-State: AOAM533nO8Uo0JMx30L401WnvLWGAJCvOgEZNxpZ/13itY7+hpWDirMO zrFIlo2uAbY53f+8TWcDz9nXH0YVPcGxQQ== X-Google-Smtp-Source: ABdhPJyVi3qpYhgNnFsyrhA5YwEHyeYt5gtkxfemsomipYpCgq7EBnWCQEp6f8igvI+D8mQx8UJoTGFNubqLCw== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:8437:70f3:c03b:1c71]) (user=mmandlik job=sendgmr) by 2002:aa7:84d7:0:b0:49f:aa6d:8745 with SMTP id x23-20020aa784d7000000b0049faa6d8745mr71923623pfn.50.1637422198336; Sat, 20 Nov 2021 07:29:58 -0800 (PST) Date: Sat, 20 Nov 2021 07:29:38 -0800 In-Reply-To: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211120072449.BlueZ.v6.3.I68039747acc3c63f758278452889d6ed2bfff065@changeid> Mime-Version: 1.0 References: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [BlueZ PATCH v6 3/6] adv_monitor: Receive the Device Found/Lost events From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Manish Mandlik , Miao-chen Chou Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch registers callback functions to receive the Advertisement Monitor Device Found and Device Lost events. It also disables software based filtering whenever controller offloading support is available. Test performed: - Verified by logs that the MSFT Monitor Device is received from the controller and the bluetoothd is notified whenever the controller starts/stops monitoring a device. Reviewed-by: Miao-chen Chou --- Changes in v6: - Removed unused variable 'handle'. Changes in v5: - Update the Adv Monitor Device Found event to include fields from the existing Device Found event and update the device object. - Disable the software based filtering whenever controller offloading is available. Changes in v4: - Add Advertisement Monitor Device Found event. Changes in v3: - Fix indentation of the adv_monitor_device_lost_callback() name and it's arguments. Changes in v2: - Update function name adv_monitor_tracking_callback() to adv_monitor_device_lost_callback() as it will receive only Device Lost event. src/adapter.c | 47 ++++++++++++++----------- src/adapter.h | 8 +++++ src/adv_monitor.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++ src/adv_monitor.h | 2 ++ 4 files changed, 127 insertions(+), 20 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index d0d38621b..42463a3c1 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -6984,12 +6984,13 @@ static bool device_is_discoverable(struct btd_adapter *adapter, return discoverable; } -static void update_found_devices(struct btd_adapter *adapter, +void btd_adapter_update_found_device(struct btd_adapter *adapter, const bdaddr_t *bdaddr, uint8_t bdaddr_type, int8_t rssi, bool confirm, bool legacy, bool not_connectable, - const uint8_t *data, uint8_t data_len) + const uint8_t *data, uint8_t data_len, + bool monitoring) { struct btd_device *dev; struct bt_ad *ad = NULL; @@ -6999,20 +7000,24 @@ static void update_found_devices(struct btd_adapter *adapter, bool duplicate = false; struct queue *matched_monitors = NULL; - if (bdaddr_type != BDADDR_BREDR) - ad = bt_ad_new_with_data(data_len, data); + if (!btd_adv_monitor_offload_supported(adapter->adv_monitor_manager)) { + if (bdaddr_type != BDADDR_BREDR) + ad = bt_ad_new_with_data(data_len, data); - /* During the background scanning, update the device only when the data - * match at least one Adv monitor - */ - if (ad) { - matched_monitors = btd_adv_monitor_content_filter( - adapter->adv_monitor_manager, ad); - bt_ad_unref(ad); - ad = NULL; + /* During the background scanning, update the device only when + * the data match at least one Adv monitor + */ + if (ad) { + matched_monitors = btd_adv_monitor_content_filter( + adapter->adv_monitor_manager, + ad); + bt_ad_unref(ad); + ad = NULL; + monitoring = matched_monitors ? true : false; + } } - if (!adapter->discovering && !matched_monitors) + if (!adapter->discovering && !monitoring) return; memset(&eir_data, 0, sizeof(eir_data)); @@ -7025,7 +7030,7 @@ static void update_found_devices(struct btd_adapter *adapter, dev = btd_adapter_find_device(adapter, bdaddr, bdaddr_type); if (!dev) { - if (!discoverable && !matched_monitors) { + if (!discoverable && !monitoring) { eir_data_free(&eir_data); return; } @@ -7064,7 +7069,7 @@ static void update_found_devices(struct btd_adapter *adapter, */ if (!btd_device_is_connected(dev) && (device_is_temporary(dev) && !adapter->discovery_list) && - !matched_monitors) { + !monitoring) { eir_data_free(&eir_data); return; } @@ -7072,7 +7077,7 @@ static void update_found_devices(struct btd_adapter *adapter, /* If there is no matched Adv monitors, don't continue if not * discoverable or if active discovery filter don't match. */ - if (!matched_monitors && (!discoverable || + if (!monitoring && (!discoverable || (adapter->filtered_discovery && !is_filter_match( adapter->discovery_list, &eir_data, rssi)))) { eir_data_free(&eir_data); @@ -7202,6 +7207,7 @@ static void device_found_callback(uint16_t index, uint16_t length, bool confirm_name; bool legacy; char addr[18]; + bool not_connectable; if (length < sizeof(*ev)) { btd_error(adapter->dev_id, @@ -7230,11 +7236,12 @@ static void device_found_callback(uint16_t index, uint16_t length, confirm_name = (flags & MGMT_DEV_FOUND_CONFIRM_NAME); legacy = (flags & MGMT_DEV_FOUND_LEGACY_PAIRING); + not_connectable = (flags & MGMT_DEV_FOUND_NOT_CONNECTABLE); - update_found_devices(adapter, &ev->addr.bdaddr, ev->addr.type, - ev->rssi, confirm_name, legacy, - flags & MGMT_DEV_FOUND_NOT_CONNECTABLE, - eir, eir_len); + btd_adapter_update_found_device(adapter, &ev->addr.bdaddr, + ev->addr.type, ev->rssi, confirm_name, + legacy, not_connectable, eir, eir_len, + false); } struct agent *adapter_get_agent(struct btd_adapter *adapter) diff --git a/src/adapter.h b/src/adapter.h index db3c17f23..cd0d037af 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -87,6 +87,14 @@ struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter, struct btd_device *btd_adapter_find_device_by_path(struct btd_adapter *adapter, const char *path); +void btd_adapter_update_found_device(struct btd_adapter *adapter, + const bdaddr_t *bdaddr, + uint8_t bdaddr_type, int8_t rssi, + bool confirm, bool legacy, + bool not_connectable, + const uint8_t *data, uint8_t data_len, + bool monitored); + const char *adapter_get_path(struct btd_adapter *adapter); const bdaddr_t *btd_adapter_get_address(struct btd_adapter *adapter); uint8_t btd_adapter_get_address_type(struct btd_adapter *adapter); diff --git a/src/adv_monitor.c b/src/adv_monitor.c index a3b33188b..ca8aa976c 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -1531,6 +1531,77 @@ static void adv_monitor_removed_callback(uint16_t index, uint16_t length, ev->monitor_handle); } +/* Processes Adv Monitor Device Found event from kernel */ +static void adv_monitor_device_found_callback(uint16_t index, uint16_t length, + const void *param, + void *user_data) +{ + const struct mgmt_ev_adv_monitor_device_found *ev = param; + struct btd_adv_monitor_manager *manager = user_data; + const uint16_t adapter_id = manager->adapter_id; + struct btd_adapter *adapter = manager->adapter; + const uint8_t *ad_data = NULL; + uint16_t ad_data_len; + uint32_t flags; + bool confirm_name; + bool legacy; + char addr[18]; + bool not_connectable; + + if (length < sizeof(*ev)) { + btd_error(adapter_id, + "Too short Adv Monitor Device Found event"); + return; + } + + ad_data_len = btohs(ev->ad_data_len); + if (length != sizeof(*ev) + ad_data_len) { + btd_error(adapter_id, + "Wrong size of Adv Monitor Device Found event"); + return; + } + + if (ad_data_len > 0) + ad_data = ev->ad_data; + + flags = btohl(ev->flags); + + ba2str(&ev->addr.bdaddr, addr); + DBG("hci%u addr %s, rssi %d flags 0x%04x ad_data_len %u", + index, addr, ev->rssi, flags, ad_data_len); + + confirm_name = (flags & MGMT_DEV_FOUND_CONFIRM_NAME); + legacy = (flags & MGMT_DEV_FOUND_LEGACY_PAIRING); + not_connectable = (flags & MGMT_DEV_FOUND_NOT_CONNECTABLE); + + btd_adapter_update_found_device(adapter, &ev->addr.bdaddr, + ev->addr.type, ev->rssi, confirm_name, + legacy, not_connectable, ad_data, + ad_data_len, true); +} + +/* Processes Adv Monitor Device Lost event from kernel */ +static void adv_monitor_device_lost_callback(uint16_t index, uint16_t length, + const void *param, + void *user_data) +{ + struct btd_adv_monitor_manager *manager = user_data; + const struct mgmt_ev_adv_monitor_device_lost *ev = param; + uint16_t handle = le16_to_cpu(ev->monitor_handle); + const uint16_t adapter_id = manager->adapter_id; + char addr[18]; + + if (length < sizeof(*ev)) { + btd_error(adapter_id, + "Wrong size of Adv Monitor Device Lost event"); + return; + } + + ba2str(&ev->addr.bdaddr, addr); + DBG("Adv Monitor with handle 0x%04x stopped tracking the device %s", + handle, addr); +} + /* Allocates a manager object */ static struct btd_adv_monitor_manager *manager_new( struct btd_adapter *adapter, @@ -1555,6 +1626,14 @@ static struct btd_adv_monitor_manager *manager_new( manager->adapter_id, adv_monitor_removed_callback, manager, NULL); + mgmt_register(manager->mgmt, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, + manager->adapter_id, adv_monitor_device_found_callback, + manager, NULL); + + mgmt_register(manager->mgmt, MGMT_EV_ADV_MONITOR_DEVICE_LOST, + manager->adapter_id, adv_monitor_device_lost_callback, + manager, NULL); + return manager; } @@ -1666,6 +1745,17 @@ void btd_adv_monitor_manager_destroy(struct btd_adv_monitor_manager *manager) manager_destroy(manager); } +bool btd_adv_monitor_offload_supported(struct btd_adv_monitor_manager *manager) +{ + if (!manager) { + error("Manager is NULL, get offload support failed"); + return false; + } + + return !!(manager->enabled_features & + MGMT_ADV_MONITOR_FEATURE_MASK_OR_PATTERNS); +} + /* Processes the content matching based pattern(s) of a monitor */ static void adv_match_per_monitor(void *data, void *user_data) { diff --git a/src/adv_monitor.h b/src/adv_monitor.h index d9cb9ccbb..bed6572d0 100644 --- a/src/adv_monitor.h +++ b/src/adv_monitor.h @@ -27,6 +27,8 @@ struct btd_adv_monitor_manager *btd_adv_monitor_manager_create( struct mgmt *mgmt); void btd_adv_monitor_manager_destroy(struct btd_adv_monitor_manager *manager); +bool btd_adv_monitor_offload_supported(struct btd_adv_monitor_manager *manager); + struct queue *btd_adv_monitor_content_filter( struct btd_adv_monitor_manager *manager, struct bt_ad *ad); From patchwork Sat Nov 20 15:29:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 518217 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 A26DDC433EF for ; Sat, 20 Nov 2021 15:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236254AbhKTPdF (ORCPT ); Sat, 20 Nov 2021 10:33:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237027AbhKTPdE (ORCPT ); Sat, 20 Nov 2021 10:33:04 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D9E8C061574 for ; Sat, 20 Nov 2021 07:30:01 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id v32-20020a05622a18a000b002b04d0d410dso8947534qtc.11 for ; Sat, 20 Nov 2021 07:30:01 -0800 (PST) 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=ZRxuidxB40H/T2WQ7bK2a/emOFuJ6J+zg0ZcDF0pEew=; b=ZLIHqI4iqVcaCd2vjgWSj6QGyH1mJ6BjPuZriK04QuFOozTD2sCtPaBm7mXjeKkpVI Mf7ed4LKkniBHjVhcE+2NPU+CVIvPD9SdVKPFWr5Bos3Ko0LZoN/Yn25Ohe7MCCnBh3I NEmdstQ1qzpZwE30oH5lQoIPx81RnERoiLJdPJHd4Jw1OI69Q2dfW577f9Tl7Y/q+4b7 OFwrbr1HtoQ+gmlQJNV9P/cFT79AV60njiP3zlsquBRKrKCIttYLANfb72fpH4j2DwMB v5cxsFMSb65fXsGAgrOXCUYaXOs9kUK88uFk8zXE4OXTMvOb83x75wgUQ62ROKtOTnG1 kxuQ== 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=ZRxuidxB40H/T2WQ7bK2a/emOFuJ6J+zg0ZcDF0pEew=; b=p69cPRaO7DgIiZPrimMDJtJWR79BpKHJjCBP3IZJLD2asVTs00zfvcm1l8heMXEtlV sI1Qi2Ka5sHhSIuoPAbMxG2bdSzHrws0+csS1+Cyx+BWs/qUH8I1goRjkkiU+gWVoH6K 77Z4WpGJ+EA6u9cgsSEPdrzrE3LJz8eJ3ZcG76D7YjBhVcpZW9vCnTHJBTV7zQMnmu2V KJtPTgku8mp4EWICW6B3Aqi4wqoH/jC4kAt7tBOIOO2rnyCN22n3Hp1mUZchnutLw3Lz /Wq9KphBNAbFx8nIilyeWye49kn8ko+EIrEKWvuAWia1dniU2EZZZcJBnlrjMZPxiGJ1 synQ== X-Gm-Message-State: AOAM531QrbsqS8fbm0VPnRR4ktGd/nUY3FtvYUpqa1r+PNRmEvfsDuBl HrUtBTCbYFPK+N4ljjSfu9uwsFaemXGaWQ== X-Google-Smtp-Source: ABdhPJxG/uP9Si6D9pqu7mLSInGUhg54egFKFqwIX8rZPdXvqq9ALE6OoaX+RPv9LadFoI4Fs21B/c6GHt/Zvw== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:8437:70f3:c03b:1c71]) (user=mmandlik job=sendgmr) by 2002:a05:622a:1115:: with SMTP id e21mr15376830qty.315.1637422200216; Sat, 20 Nov 2021 07:30:00 -0800 (PST) Date: Sat, 20 Nov 2021 07:29:39 -0800 In-Reply-To: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211120072449.BlueZ.v6.4.If3927b0228004494a5eb09d9226370119ddf4d8b@changeid> Mime-Version: 1.0 References: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [BlueZ PATCH v6 4/6] adv_monitor: Invoke DeviceFound/Lost on tracked monitors From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Manish Mandlik , Miao-chen Chou Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch delivers DeviceFound/DeviceLost events to apps over D-Bus whenever controller starts/stops tracking a device. Tests performed: - Add a monitor and verify that DeviceFound/DeviceLost events are received whenever controller starts/stops monitoring. - Verify from logs that only one Adv Report is received from the controller when Sampling_Period is set to 0xFF and the DeviceFound/DeviceLost functionality still works as intended. - Verify that DeviceFound/DeviceLost is reported appropriately even when the Active Scanning is in progress. - Verify that the reconnection also works properly with and without any active Advertisement Monitor. Reviewed-by: Miao-chen Chou --- Changes in v6: - Moved the definition of 'handle' variable to this patch Changes in v5: - Add this new patch in series to deliver DeviceFound/Lost to apps src/adv_monitor.c | 104 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 8 deletions(-) diff --git a/src/adv_monitor.c b/src/adv_monitor.c index ca8aa976c..27d5f3308 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -174,6 +174,11 @@ struct adv_rssi_filter_info { int8_t rssi; }; +struct monitored_device_info { + uint16_t monitor_handle; /* Kernel Monitor Handle */ + struct btd_device *device; +}; + static void monitor_device_free(void *data); static void adv_monitor_filter_rssi(struct adv_monitor *monitor, struct btd_device *device, int8_t rssi); @@ -1531,6 +1536,39 @@ static void adv_monitor_removed_callback(uint16_t index, uint16_t length, ev->monitor_handle); } +/* Includes found/lost device's object path into the dbus message */ +static void report_device_state_setup(DBusMessageIter *iter, void *user_data) +{ + const char *path = device_get_path(user_data); + + dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); +} + +/* Invokes DeviceFound on the matched monitor */ +static void notify_device_found_per_monitor(void *data, void *user_data) +{ + struct adv_monitor *monitor = data; + struct monitored_device_info *info = user_data; + + if (monitor->merged_pattern->monitor_handle == info->monitor_handle) { + DBG("Calling DeviceFound() on Adv Monitor of owner %s " + "at path %s", monitor->app->owner, monitor->path); + + g_dbus_proxy_method_call(monitor->proxy, "DeviceFound", + report_device_state_setup, NULL, + info->device, NULL); + } +} + +/* Checks all monitors for match in the app to invoke DeviceFound */ +static void notify_device_found_per_app(void *data, void *user_data) +{ + struct adv_monitor_app *app = data; + + queue_foreach(app->monitors, notify_device_found_per_monitor, + user_data); +} + /* Processes Adv Monitor Device Found event from kernel */ static void adv_monitor_device_found_callback(uint16_t index, uint16_t length, const void *param, @@ -1540,6 +1578,8 @@ static void adv_monitor_device_found_callback(uint16_t index, uint16_t length, struct btd_adv_monitor_manager *manager = user_data; const uint16_t adapter_id = manager->adapter_id; struct btd_adapter *adapter = manager->adapter; + uint16_t handle = le16_to_cpu(ev->monitor_handle); + struct monitored_device_info info; const uint8_t *ad_data = NULL; uint16_t ad_data_len; uint32_t flags; @@ -1578,6 +1618,49 @@ static void adv_monitor_device_found_callback(uint16_t index, uint16_t length, ev->addr.type, ev->rssi, confirm_name, legacy, not_connectable, ad_data, ad_data_len, true); + + if (handle) { + DBG("Adv Monitor with handle 0x%04x started tracking " + "the device %s", handle, addr); + + info.device = btd_adapter_find_device(adapter, &ev->addr.bdaddr, + ev->addr.type); + if (!info.device) { + btd_error(adapter_id, "Device object not found for %s", + addr); + return; + } + + /* Check for matched monitor in all apps */ + info.monitor_handle = handle; + queue_foreach(manager->apps, notify_device_found_per_app, + &info); + } +} + +/* Invokes DeviceLost on the matched monitor */ +static void notify_device_lost_per_monitor(void *data, void *user_data) +{ + struct adv_monitor *monitor = data; + struct monitored_device_info *info = user_data; + + if (monitor->merged_pattern->monitor_handle == info->monitor_handle) { + DBG("Calling DeviceLost() on Adv Monitor of owner %s " + "at path %s", monitor->app->owner, monitor->path); + + g_dbus_proxy_method_call(monitor->proxy, "DeviceLost", + report_device_state_setup, NULL, + info->device, NULL); + } +} + +/* Checks all monitors for match in the app to invoke DeviceLost */ +static void notify_device_lost_per_app(void *data, void *user_data) +{ + struct adv_monitor_app *app = data; + + queue_foreach(app->monitors, notify_device_lost_per_monitor, + user_data); } /* Processes Adv Monitor Device Lost event from kernel */ @@ -1589,6 +1672,8 @@ static void adv_monitor_device_lost_callback(uint16_t index, uint16_t length, const struct mgmt_ev_adv_monitor_device_lost *ev = param; uint16_t handle = le16_to_cpu(ev->monitor_handle); const uint16_t adapter_id = manager->adapter_id; + struct btd_adapter *adapter = manager->adapter; + struct monitored_device_info info; char addr[18]; if (length < sizeof(*ev)) { @@ -1600,6 +1685,17 @@ static void adv_monitor_device_lost_callback(uint16_t index, uint16_t length, ba2str(&ev->addr.bdaddr, addr); DBG("Adv Monitor with handle 0x%04x stopped tracking the device %s", handle, addr); + + info.device = btd_adapter_find_device(adapter, &ev->addr.bdaddr, + ev->addr.type); + if (!info.device) { + btd_error(adapter_id, "Device object not found for %s", addr); + return; + } + + /* Check for matched monitor in all apps */ + info.monitor_handle = handle; + queue_foreach(manager->apps, notify_device_lost_per_app, &info); } /* Allocates a manager object */ @@ -1961,14 +2057,6 @@ static struct adv_monitor_device *monitor_device_create( return dev; } -/* Includes found/lost device's object path into the dbus message */ -static void report_device_state_setup(DBusMessageIter *iter, void *user_data) -{ - const char *path = device_get_path(user_data); - - dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); -} - /* Handles a situation where the device goes offline/out-of-range */ static bool handle_device_lost_timeout(gpointer user_data) { From patchwork Sat Nov 20 15:29:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 516967 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 1E7E4C433FE for ; Sat, 20 Nov 2021 15:30:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237479AbhKTPdG (ORCPT ); Sat, 20 Nov 2021 10:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237027AbhKTPdG (ORCPT ); Sat, 20 Nov 2021 10:33:06 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC9F0C061574 for ; Sat, 20 Nov 2021 07:30:02 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id e4-20020a170902b78400b00143c2e300ddso5793873pls.17 for ; Sat, 20 Nov 2021 07:30:02 -0800 (PST) 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=jmpCJe5TKrx6C8LTBNW6hibZhG79HzwFdwgGf0nOh30=; b=J7l3Vuu/5S2YbzMd60qnM+r+LR8kQz1pFZ/jgU1QwNyk51lFf4c+7Mm13YrHF1dJeb jGE0+rZdw+r9zD4Mq2gpE8NPCqJqPa2RZWjlJCAyu8gjiQ/G3SnKZvM2srvDefoHVGnv 06pGdip7wX3UfrIKNFKffyhxy8621lW2bKxtQm1Hta+RoY2xYbi7TpWkNT1exgFdS31G ieb+QONseSBsZEBx5XB8EC8W0M8cWvkT8zxVonoL9t2xdu2qzUWHtHIS20bgTj65Vv7X WtoNmSGEXBMNcQy0FQ+f86FO6Lr6aFpEGaG21N9dGAyTf+GZMKl7GJo5ZdeALpCAmx4Q 0eyw== 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=jmpCJe5TKrx6C8LTBNW6hibZhG79HzwFdwgGf0nOh30=; b=CoJ9Cx7IS5tsiGMXAuRNfWRVvaCLW5kTTGyliri4C4zNdBehz/SeRIXXAxah31cGIC aJk5hDUfQVNyGrshFS/Ww+j6NI4sfPpRB8kLKAxVQHH3DT0FJQfMLkkVlzRSgaXYbehz z/4hAB0Lzf4JhInJNQtTzpjGjMYCoS/YDT8z85/reBqa+9ET1kRwDqegylzRI7UZrvte HDZNvOyl5l7+Um9D0GlFkOoOfTvshC5684qrcDFtnaHdfveyKNxfHyszl9uC31nMgHDu FKahGPLJ6YQCezb6QctgrLNwcvK4nj28pW4B7G0rF6PL7TLJ8GO6Z6OuIVP4HOOMWxe0 J+rg== X-Gm-Message-State: AOAM532cEGUv0r4WPGFw/QWANt11WvskNTQqL23RchrsqrmWzK8uiQWM 3cMcoj3PlXSu+QTf0hOHBfnwsg/2/reSPA== X-Google-Smtp-Source: ABdhPJwkCCBgaEsdMATrkJG159LAtlQTbqXc6UZu0ih+wrzsR8up25SJIsKLzEQkl3Vvao8klxbSZ+PJGBj9mw== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:8437:70f3:c03b:1c71]) (user=mmandlik job=sendgmr) by 2002:a17:902:d114:b0:142:3934:be82 with SMTP id w20-20020a170902d11400b001423934be82mr87809355plw.40.1637422202328; Sat, 20 Nov 2021 07:30:02 -0800 (PST) Date: Sat, 20 Nov 2021 07:29:40 -0800 In-Reply-To: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211120072449.BlueZ.v6.5.Ib85d2d946d853ea8c879dc922ad8e47587d3c603@changeid> Mime-Version: 1.0 References: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [BlueZ PATCH v6 5/6] adv_monitor: Change sampling period to uint16_t From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Manish Mandlik , Archie Pusaka , Miao-chen Chou Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org In the Advertisement Monitor API, RSSISamplingPeriod is an unsigned value. Change sampling_period variable to uint16_t in the code. More info: doc/advertisement-monitor-api.txt Reviewed-by: Archie Pusaka Reviewed-by: Miao-chen Chou --- (no changes since v5) Changes in v5: - New patch in the series. Update 'sampling_period' data type to the correct type. src/adv_monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adv_monitor.c b/src/adv_monitor.c index 27d5f3308..bf7f2bed3 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -772,7 +772,7 @@ static bool parse_rssi_and_timeout(struct adv_monitor *monitor, int16_t l_rssi = ADV_MONITOR_UNSET_RSSI; uint16_t h_rssi_timeout = ADV_MONITOR_UNSET_TIMEOUT; uint16_t l_rssi_timeout = ADV_MONITOR_UNSET_TIMEOUT; - int16_t sampling_period = ADV_MONITOR_UNSET_SAMPLING_PERIOD; + uint16_t sampling_period = ADV_MONITOR_UNSET_SAMPLING_PERIOD; uint16_t adapter_id = monitor->app->manager->adapter_id; /* Extract RSSIHighThreshold */ From patchwork Sat Nov 20 15:29:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 518216 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 7841DC433EF for ; Sat, 20 Nov 2021 15:30:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbhKTPdK (ORCPT ); Sat, 20 Nov 2021 10:33:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237462AbhKTPdI (ORCPT ); Sat, 20 Nov 2021 10:33:08 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFB5FC061748 for ; Sat, 20 Nov 2021 07:30:04 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id l10-20020a17090a4d4a00b001a6f817f57eso6200550pjh.3 for ; Sat, 20 Nov 2021 07:30:04 -0800 (PST) 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=17tQDHDQUht1fmHeg8bl5FT/hN7QDbl//pQvYVh8C8E=; b=ZNSi3z2/YiTkOmVzIENDjW5bIf2BtqaV7lT+GxzBL4zDQUOo7lzVyKYAffXqK2nPUU uU+cHaZGfzcTuKEZRd+9o70sLdAii6wrHS8k4krW1myZO3P2jwIN/Dd+6Lri6OfxALAj uVeE1KQL0YuT8xjmFn1RqE1z6TcqMwhr2e9Ua7NgVs1F4RzjK5AzFM7Eo8Wt41mkHgyE GYoj8vD3sxK7dT4CYL5TrH8X9r4E+qc39BxBuP1RZ/jfHP4HA5OgDl59sNaMibWMnVpC 7JlwJCsIXAOPHNGiNuI6H5vG5cxsqtGnbJygpik/iHGEF9Fj1VyIHeFLkOhHLEHwJ8z0 zbOA== 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=17tQDHDQUht1fmHeg8bl5FT/hN7QDbl//pQvYVh8C8E=; b=x0hj5FEQjOGLJpFvUCCFe4ux5MJDo4seqZvHNyokx0hpJACEAw2DifIb0Mcd3VYJFB PKBU6SCTRuuVMh0hZS5+LYah2wHzOk9abM39e5s+VU/pfuuCmajVENCOvPgH5CclYwqJ gbfiOhpLCIp/uazVy8yrHiC64vUGtlBFCZ54CZkHdZTKnnAJ8E14wvFBLtE0hS0owuJQ ckk5yQhPfDDKusZcYzg/Ah7Rld3Rkwoz9R1f0DA7pY4wcmJJhHiBhrHzyjm6d5Ciu0Ar 8R17qEE/j7S5E1pnl1UjwF79DtExnbq/Z20/lWzUXeaNp7bcguDvDcqBsmQhOnbbt1oe zVGg== X-Gm-Message-State: AOAM530GaHl+o1g+NjuA5OjVLvhSe6Ciet7lpHVycU+wekrlHd0ql1// jcCsmzFeAe4729KXCYuQZooetTM2TBtzYg== X-Google-Smtp-Source: ABdhPJzGqTF0xRBi4njm+F8IcsKFt61jH7R+I9m1ApoIx8mfmBFbVkzMXZtJblLTkkpU8V2bNYXYEHfao5MqDg== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:8437:70f3:c03b:1c71]) (user=mmandlik job=sendgmr) by 2002:a17:90b:1e0c:: with SMTP id pg12mr11234526pjb.135.1637422204262; Sat, 20 Nov 2021 07:30:04 -0800 (PST) Date: Sat, 20 Nov 2021 07:29:41 -0800 In-Reply-To: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211120072449.BlueZ.v6.6.I363090b80e59a3cda134c9bd2df0b3bca2cb527b@changeid> Mime-Version: 1.0 References: <20211120072449.BlueZ.v6.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [BlueZ PATCH v6 6/6] core: Update default advmon Sampling_Period to 0xFF From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Manish Mandlik , Miao-chen Chou Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Update default Advertisemet Monitor Sampling_Period to 0xFF. It indicates that controller will report only one advertisement per monitoring period for a device. This will help reduce the power consumption drastically. Reviewed-by: Miao-chen Chou --- Changes in v6: - Update information about the value range and units. - Update commented entry to use the default value Changes in v5: - New patch in the series. Update default Sampling_Period to 0xFF. src/main.c | 2 +- src/main.conf | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 5ca8d5644..1f852fdf6 100644 --- a/src/main.c +++ b/src/main.c @@ -932,7 +932,7 @@ static void init_defaults(void) btd_opts.avdtp.session_mode = BT_IO_MODE_BASIC; btd_opts.avdtp.stream_mode = BT_IO_MODE_BASIC; - btd_opts.advmon.rssi_sampling_period = 0; + btd_opts.advmon.rssi_sampling_period = 0xFF; } static void log_handler(const gchar *log_domain, GLogLevelFlags log_level, diff --git a/src/main.conf b/src/main.conf index e05291d8e..17795a847 100644 --- a/src/main.conf +++ b/src/main.conf @@ -260,5 +260,9 @@ [AdvMon] # Default RSSI Sampling Period. This is used when a client registers an # advertisement monitor and leaves the RSSISamplingPeriod unset. -# Default: 0 -#RSSISamplingPeriod=0 +# Possible values: +# 0x00 Report all advertisements +# N = 0xXX Report advertisements every N x 100 msec (range: 0x01 to 0xFE) +# 0xFF Report only one advertisement per device during monitoring period +# Default: 0xFF +#RSSISamplingPeriod=0xFF