From patchwork Wed Nov 17 19:14:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12625239 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D86DC433EF for ; Wed, 17 Nov 2021 19:15:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE1FB61BB6 for ; Wed, 17 Nov 2021 19:15:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240405AbhKQTSD (ORCPT ); Wed, 17 Nov 2021 14:18:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233430AbhKQTSC (ORCPT ); Wed, 17 Nov 2021 14:18:02 -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 17CBCC061570 for ; Wed, 17 Nov 2021 11:15:04 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id bf17-20020a17090b0b1100b001a634dbd737so3610214pjb.9 for ; Wed, 17 Nov 2021 11:15:04 -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=VrXRhTozwaNZW5A6W1CImE5Asu5J3ezcqXz+ALKAH50=; b=YXHLvZrghlfDgXvwQ3urfQglCs2TLNuX/5oztqH9wuufiLGx0XhfL5WGbph2DMip8o 2hW2XBZxasIlA87qxrc5xNJ7yL9HUbv/qrVmabz7Tf2VNYBtvFxQ17c/ckcn8ED2E3kH n829FJ45jjBWrVZyAGEjuC/EC8lIyfPZIUfuMyiGQ5S2mRPA9L2r90yju+VWuphdLBY0 ga07eJMvUzG0VuPAPzaaWwQRR13j3ZZYaxRauzwSx23kb/roDTmd2/WO0OBjc2/TDGF9 3DlvSwjV/Uf9E57WoLtdQjU+KmPMqCLkuGGm+FyjjEWjdaNTbck0W27nazjKkSCkYFsA ofJw== 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=VrXRhTozwaNZW5A6W1CImE5Asu5J3ezcqXz+ALKAH50=; b=Btjn3+AA9fz703MDMuTkb6b9/aTw8wWNrbxR9UpbFDc4470C5vxqrT/vpMpHvlCpKl TrSEgEcst/5XQ+bLhdbVqXH8yNyJ70PaKgKuBq9gx23tEPQnvy9vp9MB/2qJr/5aiEMh i0e3VuoEAuu4FoDYt8SMRN+UXJz5a2e+p2h9E703JqxzdXWO7LjxhAu+37znOllBlXK2 nSdAIoEcvMTZ8Dr4yrGtay+F67pqO7zRjhdzkqRP3c8bnQs8EyR/Tow/WIGeEELBio5M LOnDfWpp41fUUitOLsHKZNZ1O1meUWcZodOLgDM3fJnWZfLpOPbPylmQtPjc0xelYTYo vi9w== X-Gm-Message-State: AOAM532P1javavZYc7cjcyJBG4okePJ8d2OyvSIucZZLNQRDlk/Gs92r PajGkqNXfWYSFVYSZIhF7cU/L3UW1KQ8/Q== X-Google-Smtp-Source: ABdhPJxsR439g3s9f8qCGSQqfqXCwlzcVIhyGVo6+PZLtZ/prb5Fb6mp3i3sWbXAMrP8DEwgXV9fJQgcU+h3mg== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:b1b3:555c:d0fb:8921]) (user=mmandlik job=sendgmr) by 2002:a17:902:7797:b0:143:88c3:7ff1 with SMTP id o23-20020a170902779700b0014388c37ff1mr57582250pll.22.1637176503549; Wed, 17 Nov 2021 11:15:03 -0800 (PST) Date: Wed, 17 Nov 2021 11:14:45 -0800 Message-Id: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog Subject: [BlueZ PATCH v5 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. 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 Wed Nov 17 19:14:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12625241 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49387C433EF for ; Wed, 17 Nov 2021 19:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35E0561B6F for ; Wed, 17 Nov 2021 19:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240410AbhKQTSF (ORCPT ); Wed, 17 Nov 2021 14:18:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233430AbhKQTSF (ORCPT ); Wed, 17 Nov 2021 14:18:05 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AB1EC061570 for ; Wed, 17 Nov 2021 11:15:06 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id r7-20020a63ce47000000b002a5cadd2f25so1575763pgi.9 for ; Wed, 17 Nov 2021 11:15:06 -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=FWr/lcz6NN501LpemE5CKmCae255JbWooF2tV8RjfYo=; b=e6cvfalaKZ/xeZM1JRjbmOMDaPLxlU83+4zsbJNNdAyceEhYBAa4vzq3uNPqngZ1s/ mp4Ox72RfgL66kQaMoBVY9Q+bPz7mq2xsuujbEQOw5ErdJYL9YcOjGGxq9BXrB34LaYC TChvUlUDVwmPk5T5PjvW1FR77RmFy2K0W6aLEF9qDXCsjtriFVsWxK/Rc5tV8e3UZZS9 MRMo8ACGHr2fapuxjfhaSyl7WsgEIprusYj6w4aYutdhdTJvyP/oeHHlzPv4iHv67FcC U94BfMfMWWnxaPBh7/AXb7UY1YuKdez/OftyqnHbJg1PFfaX+Vp+dFGli17NeitufCAQ RzRA== 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=FWr/lcz6NN501LpemE5CKmCae255JbWooF2tV8RjfYo=; b=jirDIhcghdUgnCPUs7JKbwQospqDmgYxREAKh02xNvc7LBqb1wVItt/ukuonVcINyP 2449xSENHGAXvrJezqmcIFBquRUGSfCsxe0Oj3OEY9vAc1XwrqBGTfqf5/M2AF/ap0hq /yyY2pC2jZ04/LUdohqqtRcxVRNcb2VLPBkwwm1d/aIOia+tYU0j7SWeqXICYnoga8Hx Cfovi+H5BJOsNZaLP+Gfa2fqYQfQOe/iRTafD4ib07ZpohmKaAgs97I+QhWcybcUsjl5 Rgsxbx5zVSnRrw6QPdI0V57ZU8lC5DPkWy9Hvq73iqEdWPbCbCAN5geV+Th9rAEL7MsY Q4UA== X-Gm-Message-State: AOAM5301r8UJGmv5JbPPe0Zll1GwA5QOOpWR7REtzvibjir9oZUgheBI 4Voa4QfXwAJt2r8JQChfjI/O4qG6JxMRew== X-Google-Smtp-Source: ABdhPJzoiIE9hBFHp6xk/1piAT7YhO1a4tiV3gEdrtv70yJcLhfwD9UeHXuGapO32jJXCSeWO+WJ4K4ETZ+GMg== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:b1b3:555c:d0fb:8921]) (user=mmandlik job=sendgmr) by 2002:aa7:9438:0:b0:4a2:c941:9ac4 with SMTP id y24-20020aa79438000000b004a2c9419ac4mr23578867pfo.12.1637176505742; Wed, 17 Nov 2021 11:15:05 -0800 (PST) Date: Wed, 17 Nov 2021 11:14:46 -0800 In-Reply-To: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211117110627.BlueZ.v5.2.Ied4afb8c4c882e573f4a23670fc060cbc3e319c9@changeid> Mime-Version: 1.0 References: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog Subject: [BlueZ PATCH v5 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 --- 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 Wed Nov 17 19:14:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12625243 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27CF1C433F5 for ; Wed, 17 Nov 2021 19:15:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 110EC61BB6 for ; Wed, 17 Nov 2021 19:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240412AbhKQTSJ (ORCPT ); Wed, 17 Nov 2021 14:18:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240414AbhKQTSH (ORCPT ); Wed, 17 Nov 2021 14:18:07 -0500 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 9A9D0C061570 for ; Wed, 17 Nov 2021 11:15:08 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id y3-20020a25ad03000000b005e52103ed80so5469206ybi.19 for ; Wed, 17 Nov 2021 11:15:08 -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=gos2naxGKWfULEQNzy8c4dBRogK6Y5j4KagBjXSK2y0=; b=r73WZaSipY23x+CmBZiwUm2ctUvuB8p2c/eCLCPRJubN6xlAj1GMG2w+pjG3nNaPUg NU4wBYbc1Z2KDUriY4+/l7JalYhN20gAmvP2jwkubzHKLXJCH4c2aLixNxxm01c8WAjS zGOB2HT/gk8iTvDd+A0uOIZUrzTHteelwMPfz5sNg3l2DW6ilj3w5r4hYUcxuIvHHYGN 7RmLwQY1IqZnDJCVq76wqYt1mk0gv/BrCRHRFFqHTceYtnnPgUvMtmzYdEqmlswGG1Ca ULS83l0J+a7i8IiL9qnjzGeJVvBvenQReN3fLRprl4DCOIVyTbAwehWLU0YRGsnvVH+z JKZQ== 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=gos2naxGKWfULEQNzy8c4dBRogK6Y5j4KagBjXSK2y0=; b=BFoa1Fo1lVAtYJ9MVeNpFQlEfiqR63aNQNn5+8AwusnU1OojLSJHE/IHduMeqw3D+O zT+AiwynktDjW4WjUBbde/g9R6EMtAinA0uF+cXbGMiY/W7GuUHdsEDP2gQBJRiBo4qx euQyASDESPmvQxLQRjVq37PMYG2ytq/8Sr8Y8mRgyjSMlWZmpMImM4o2SyhOjsHj4fn6 4AYiyim5ea1fMRSMo5r+vqvneXNDzbrE+vPBrxWcMbSKxJxGNaHT7FxrjC1Vr5OPU10j 6kxh/dh3kp/fIjaZKJrK3NNTYDvjEvKXP1qCr3LXy2nC9HYVOYHsxLwhD7vosMiUfOAG oamg== X-Gm-Message-State: AOAM530h04bOfhw4553bix15lSuZU/xk7krPaWeIh4FXHI/Qx4ZOAd+V NOCDsKAHzfupK3qcBs99+a2zCBOv3QZ4ZQ== X-Google-Smtp-Source: ABdhPJz1AEvx2C+k22ZIiz+K2ysnww+VPTyENTe4pM8LWUArrV4IBuLH5sjIIQR70gCMONHjU9RM5VaIRvNBkQ== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:b1b3:555c:d0fb:8921]) (user=mmandlik job=sendgmr) by 2002:a25:104:: with SMTP id 4mr19657447ybb.27.1637176507835; Wed, 17 Nov 2021 11:15:07 -0800 (PST) Date: Wed, 17 Nov 2021 11:14:47 -0800 In-Reply-To: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211117110627.BlueZ.v5.3.I68039747acc3c63f758278452889d6ed2bfff065@changeid> Mime-Version: 1.0 References: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog Subject: [BlueZ PATCH v5 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 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 | 91 +++++++++++++++++++++++++++++++++++++++++++++++ src/adv_monitor.h | 2 ++ 4 files changed, 128 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..e5bdfb6ef 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -1531,6 +1531,78 @@ 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; + uint16_t handle = le16_to_cpu(ev->monitor_handle); + 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 +1627,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 +1746,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 Wed Nov 17 19:14:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12625245 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 834D3C433FE for ; Wed, 17 Nov 2021 19:15:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DAC761B04 for ; Wed, 17 Nov 2021 19:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240417AbhKQTSJ (ORCPT ); Wed, 17 Nov 2021 14:18:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240419AbhKQTSI (ORCPT ); Wed, 17 Nov 2021 14:18:08 -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 25D95C061570 for ; Wed, 17 Nov 2021 11:15:10 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id e9-20020a170902ed8900b00143a3f40299so1607553plj.20 for ; Wed, 17 Nov 2021 11:15:10 -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=fik3+aUxkJOy7w+csONhe1xUYP5DVD9aKI/SS7545MU=; b=KF3/W8rPei0uW0CEwYkt+tDxoGVeiWKE3iGzxl59j43LCZgqWiIPS+l/Wlg0d6iE0d UFZGqaOEY0nMylzv1BBscK9guZ2rWipucVbdOV/uR0lsvhOMjYSWq+DMrkPDgYA7y4Dr xtAYpCy7X9XVOgry1wi6sTefXRYZZohU3Q1HjQSvGkIg7twsqCvN3/IJplD+Wm60Tr7v XeKQYYj8SPiQKYJCzQ2+GsYKJgbVCpLqHRkXIvjJkzV1uQE9NSApANAiDv9SmrVKOCD8 zZU+As3zDD9DsOkHHdJ4FtaC59ehQ+yC5Mnk+sEg5PvhN+CEFgJ8FtIVoYIqID1HvA7T S7Ew== 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=fik3+aUxkJOy7w+csONhe1xUYP5DVD9aKI/SS7545MU=; b=yNVNX2YYJdgemC3iI/nHzaqcMmVYtfKeyWPjxjfr975ILMU8YpU7jyKqyT12kZDKVR z75N0bQxOUgrkeZyVuqBU0BERfsBj5oPyj3yag0WKgvKvvEvMmujVvxqAZBhzFOxjq4p 30OI1PNCHlcxCnfjG2uxdie6lQnsZbCcLHE2QDT49d5Ri3m4OhCpnfJpHv7aHTbAc8KU QkWpagrFqdfuipPVf3mk7X0+YLc4vMANXlb4iNO9z7bOCsZ2aKZRSKI01sDDUw+GW0Gm m/qHS9WusqtYVQwlyPjuLtiyXQ1FPcrCTenyx6COIq2P5fL3AfFSL1HoAWoyYLRbEqiJ 0r5g== X-Gm-Message-State: AOAM531VhXM51zD9ukQ+9tAGh/Y415/LhKlPPgn4LMe8knvgRIhzgaJG GjoOqKSE9oiHuyFBOxCfH5lnssRfJjgoeA== X-Google-Smtp-Source: ABdhPJwGeJNldwXus6T+5MK7SmdumQFLiiWc4jtfYi0YtqBfuPve0JJUv2Hwe/yD2ApLf/Qfasy5XV85zO3lwA== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:b1b3:555c:d0fb:8921]) (user=mmandlik job=sendgmr) by 2002:a63:5813:: with SMTP id m19mr6780980pgb.441.1637176509679; Wed, 17 Nov 2021 11:15:09 -0800 (PST) Date: Wed, 17 Nov 2021 11:14:48 -0800 In-Reply-To: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211117110627.BlueZ.v5.4.If3927b0228004494a5eb09d9226370119ddf4d8b@changeid> Mime-Version: 1.0 References: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog Subject: [BlueZ PATCH v5 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 v5: - Add this new patch in series to deliver DeviceFound/Lost to apps src/adv_monitor.c | 103 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 8 deletions(-) diff --git a/src/adv_monitor.c b/src/adv_monitor.c index e5bdfb6ef..1a8397259 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, @@ -1548,6 +1586,7 @@ static void adv_monitor_device_found_callback(uint16_t index, uint16_t length, bool legacy; char addr[18]; bool not_connectable; + struct monitored_device_info info; if (length < sizeof(*ev)) { btd_error(adapter_id, @@ -1579,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 */ @@ -1590,7 +1672,9 @@ 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; char addr[18]; + struct monitored_device_info info; if (length < sizeof(*ev)) { btd_error(adapter_id, @@ -1601,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 */ @@ -1962,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 Wed Nov 17 19:14:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12625247 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78BD9C4332F for ; Wed, 17 Nov 2021 19:15:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 621E861B6F for ; Wed, 17 Nov 2021 19:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240423AbhKQTSL (ORCPT ); Wed, 17 Nov 2021 14:18:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240420AbhKQTSK (ORCPT ); Wed, 17 Nov 2021 14:18:10 -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 3EA08C061766 for ; Wed, 17 Nov 2021 11:15:12 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id p24-20020a170902a41800b001438d6c7d71so1630428plq.7 for ; Wed, 17 Nov 2021 11:15:12 -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=caF73V05VAN5SrnvUb/tr/Mu5EsXFnwrIedVE9l5TzA=; b=Yekdrs8naalFBDFLp/FQys6wcES2NK8B8uNSpGYBpVphyAyxai3Tr+RebOizZE1btx 2fRSEN3pCq/h56cGEVoA8J2ddK2qfsFtt2LF5F4eFcshHzmqDDNKxHV6gvZl1gnu+cbo ujKferdNYWeSMdbUue/ISserLL+6X9yE8J/exlqTfWbFf4so8zbNaWTkvLfPshVivAPh 78xF0X9xBeWE/b215zGgKf/owqbGiCUy+r7/ll1+s1888D37vjYcwfHStSEEZRWx0vyJ 0eP+Ja5cDcyPvLrUR1apdMWBRAqCASU4uQ5o98ANSuO7KeRTmBZAhvmT4LVDFZz7f05C a+oQ== 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=caF73V05VAN5SrnvUb/tr/Mu5EsXFnwrIedVE9l5TzA=; b=7t3bAQzAlZm0jzYRoUp1YEMIDIoNGjPKUMYRDrU8d8aKP3nMEQ47YOXyy0uY4SfvWH ifX1ZBnOaJnPAeJaBYAPyXKCuMFOzK7WihpGtHjKjhIGtjYhGbRWf8SUUplsRYB5r6VC Nvt3NWoipHP+Oq27kb48FpajLvpx0zZCDjQPxDkTbksvlEQXgDQ7fh2l79TIYMIL22Cb P8cF35su9v4hfv1KvRai0ODwXNpIKL3zntX/4AuPAWdGJ+Q6ZoT1WojWtbxSWgbwXFlc cIY35TrEbZVRarSJijnN5QlkJfM8RAfwM0M5MkU14ikqZGrreApeciD55mqL9sGQNEU6 q3Vg== X-Gm-Message-State: AOAM531Mt9K6V11PRsAxFUL17QEm9+uCp6MBO6HQ1KGE4+83LDwKQ0Tp knxtwQezLTKW4/K7PJnx/fUMCIPdMx8ONQ== X-Google-Smtp-Source: ABdhPJxvID29vJHyN8qT9tZgOY2pujjv/zZEawePXXSGYu3QNceR3gybZSlm4FWsffZNkMfQ6Xl8MobrMvxFOQ== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:b1b3:555c:d0fb:8921]) (user=mmandlik job=sendgmr) by 2002:a17:90a:cb98:: with SMTP id a24mr2507596pju.153.1637176511809; Wed, 17 Nov 2021 11:15:11 -0800 (PST) Date: Wed, 17 Nov 2021 11:14:49 -0800 In-Reply-To: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211117110627.BlueZ.v5.5.Ib85d2d946d853ea8c879dc922ad8e47587d3c603@changeid> Mime-Version: 1.0 References: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog Subject: [BlueZ PATCH v5 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 --- 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 1a8397259..fbb5277dc 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 Wed Nov 17 19:14:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 12625249 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64F9BC433F5 for ; Wed, 17 Nov 2021 19:15:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DC1961BCF for ; Wed, 17 Nov 2021 19:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240422AbhKQTSN (ORCPT ); Wed, 17 Nov 2021 14:18:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240420AbhKQTSN (ORCPT ); Wed, 17 Nov 2021 14:18:13 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D1F5C061570 for ; Wed, 17 Nov 2021 11:15:14 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id s8-20020a63af48000000b002e6c10ac245so1562129pgo.21 for ; Wed, 17 Nov 2021 11:15:14 -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=NrI132Th5kjg0DS+zwQPNWwLlybgHpWaafBqwEcowOA=; b=ovr94Sh2PeWXRkDdjddqon9cmpesRJXR294JtYA/fTidlB1mFrTkbc4o9YGTOyLGav chSn8DzlUXYqAdnUkSUG6pbFylvwdXuKhpB9W1rq+NBMjJbw6HbAeWaN8ZhX0ngMCtsu zGdY8ci+RDrEAd8YpeNCFDIIBm/dGM4QWYC5XfXYqdBA2uXi0M84LqV/q48VPSyf+6nU I18cL6Caf2Tl8MPkdCsjEi8kBQAg3U/+EMWQUO1GhQLbhEsZTyECWTbGHpv6pSzFCgDg pz/1eWd/aJu8wcw63uUcnaTwv9BgXnC7ZwB4Xb31HPelLWQOw913Evtqn4zTspfNI8+D eOYA== 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=NrI132Th5kjg0DS+zwQPNWwLlybgHpWaafBqwEcowOA=; b=DEChGSapikUDMjie8BWdmpQi9y0x1kTit1jzwl2ZFAtH/sUzoc/LV9jEWnuBhelvkl s0itN4AH8QgKtvTtWia3MJ6kfBOPsp2HuP2V3T+1O5RsOnAXEoxBIcf3ZGoH6KbCd4E9 O7mNo+nXn2SBFE9Tu4xm/SfiC2kC2ciHyuvLSAgWn7sniGjcU6VjZ8t4BQsjrwi1/SZy 4GhOJ1oIc8cRPE1Gowl1aLNLbkOy/EhzcUFYZF5ZoDl5PwOe1TYMhnQ9MXQPggJMhcCk +GOMMzTu7dXZWZgy1UP+RGv5ClxRPm2RMvCEA9F0zQ3EXKM83jWOQ/XeE84hCQawo3Oq LbDQ== X-Gm-Message-State: AOAM531E806Vbna+VzRXDW7Df/4PLyBlZy2TIJVvdh3tBvkOV4FKmUPq nge3UsmNokQtbcv81S349BnbJ01x6a3nvw== X-Google-Smtp-Source: ABdhPJwVMpwu8ph7QnjICT44FHC6rrxuh0usmd1Qwf+vThgvZWdMLdeiw/pLPAMUpuzoh9wpId+VvjL5Nw5axg== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:b1b3:555c:d0fb:8921]) (user=mmandlik job=sendgmr) by 2002:a17:903:4053:b0:143:6d84:984c with SMTP id n19-20020a170903405300b001436d84984cmr59080794pla.37.1637176514154; Wed, 17 Nov 2021 11:15:14 -0800 (PST) Date: Wed, 17 Nov 2021 11:14:50 -0800 In-Reply-To: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> Message-Id: <20211117110627.BlueZ.v5.6.I363090b80e59a3cda134c9bd2df0b3bca2cb527b@changeid> Mime-Version: 1.0 References: <20211117110627.BlueZ.v5.1.I7f6bdb9282c1e12ffc6c662674678f2b1cb69182@changeid> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog Subject: [BlueZ PATCH v5 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 v5: - New patch in the series. Update default Sampling_Period to 0xFF. src/main.c | 2 +- src/main.conf | 2 +- 2 files changed, 2 insertions(+), 2 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..e49259453 100644 --- a/src/main.conf +++ b/src/main.conf @@ -260,5 +260,5 @@ [AdvMon] # Default RSSI Sampling Period. This is used when a client registers an # advertisement monitor and leaves the RSSISamplingPeriod unset. -# Default: 0 +# Default: 0xFF (Report only one Adv per device during the monitoring period) #RSSISamplingPeriod=0