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 <[email protected]>
---
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: <controller_id>
+ 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: <controller_id>
+ 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.
--
2.34.0.rc1.387.gb447b232ab-goog
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 <[email protected]>
---
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[] = {
--
2.34.0.rc1.387.gb447b232ab-goog
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 <[email protected]>
---
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);
--
2.34.0.rc1.387.gb447b232ab-goog
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 <[email protected]>
---
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)
{
--
2.34.0.rc1.387.gb447b232ab-goog
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 <[email protected]>
Reviewed-by: Miao-chen Chou <[email protected]>
---
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 */
--
2.34.0.rc1.387.gb447b232ab-goog
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 <[email protected]>
---
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
--
2.34.0.rc1.387.gb447b232ab-goog
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=581841
---Test result---
Test Summary:
CheckPatch PASS 2.89 seconds
GitLint PASS 1.83 seconds
Prep - Setup ELL PASS 43.79 seconds
Build - Prep PASS 0.23 seconds
Build - Configure PASS 8.02 seconds
Build - Make PASS 192.03 seconds
Make Check PASS 9.33 seconds
Make Distcheck PASS 227.33 seconds
Build w/ext ELL - Configure PASS 8.32 seconds
Build w/ext ELL - Make PASS 181.16 seconds
---
Regards,
Linux Bluetooth
Hi Manish,
On Wed, Nov 17, 2021 at 11:15 AM Manish Mandlik <[email protected]> wrote:
>
> 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 <[email protected]>
> ---
>
> 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
While at it it would be good to explain what is the unit used here,
also it is common practice to have the default on the commented entry.
> --
> 2.34.0.rc1.387.gb447b232ab-goog
>
--
Luiz Augusto von Dentz
Hi Manish,
On Wed, Nov 17, 2021 at 11:15 AM Manish Mandlik <[email protected]> wrote:
>
> 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 <[email protected]>
> ---
>
> 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);
Make sure each patch don't break the build:
src/adv_monitor.c: In function ‘adv_monitor_device_found_callback’:
src/adv_monitor.c:1541:18: error: unused variable ‘handle’
[-Werror=unused-variable]
1541 | 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);
> --
> 2.34.0.rc1.387.gb447b232ab-goog
>
--
Luiz Augusto von Dentz
Hi Manish,
On Fri, Nov 19, 2021 at 11:06 AM Manish Mandlik <[email protected]> wrote:
>
> Hi Luiz,
>
>
> On Wed, Nov 17, 2021 at 4:09 PM Luiz Augusto von Dentz <[email protected]> wrote:
>>
>> Hi Manish,
>>
>> On Wed, Nov 17, 2021 at 11:15 AM Manish Mandlik <[email protected]> wrote:
>> >
>> > 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 <[email protected]>
>> > ---
>> >
>> > 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
>>
>> While at it it would be good to explain what is the unit used here,
>> also it is common practice to have the default on the commented entry.
>
> Ack. I'll update this in the next revision.
>
>>
>>
>> > --
>> > 2.34.0.rc1.387.gb447b232ab-goog
>> >
>>
>>
>> --
>> Luiz Augusto von Dentz
>
>
> Can you please review the other patches as well and let me know if they look good? I'll send all the required changes in the next revision together.
Other patches look good.
--
Luiz Augusto von Dentz