From 37be50d6793eaf6cfbc72b7dd69e3d57b468db2c Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 3 Nov 2021 17:26:30 -0700 Subject: adapter: Set Device Privacy Mode This adds support for setting Device Privacy flag when enabled in main.conf via Privacy = device,limited-device. --- src/device.c | 58 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 15 deletions(-) (limited to 'src/device.c') diff --git a/src/device.c b/src/device.c index 1b4dae685..6b398bd39 100644 --- a/src/device.c +++ b/src/device.c @@ -1403,9 +1403,45 @@ void device_set_wake_override(struct btd_device *device, bool wake_override) } } +static void device_set_wake_allowed_complete(struct btd_device *device) +{ + if (device->wake_id != -1U) { + g_dbus_pending_property_success(device->wake_id); + device->wake_id = -1U; + } + + device->wake_allowed = device->pending_wake_allowed; + g_dbus_emit_property_changed(dbus_conn, device->path, + DEVICE_INTERFACE, "WakeAllowed"); + + store_device_info(device); +} + +static void set_wake_allowed_complete(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + const struct mgmt_rp_set_device_flags *rp = param; + struct btd_device *dev = user_data; + + if (status != MGMT_STATUS_SUCCESS) { + error("Set device flags return status: %s", + mgmt_errstr(status)); + return; + } + + if (length < sizeof(*rp)) { + error("Too small Set Device Flags complete event: %d", length); + return; + } + + device_set_wake_allowed_complete(dev); +} + void device_set_wake_allowed(struct btd_device *device, bool wake_allowed, GDBusPendingPropertySet id) { + uint32_t flags; + /* Pending and current value are the same unless there is a change in * progress. Only update wake allowed if pending value doesn't match the * new value. @@ -1415,25 +1451,17 @@ void device_set_wake_allowed(struct btd_device *device, bool wake_allowed, device->wake_id = id; device->pending_wake_allowed = wake_allowed; - adapter_set_device_wakeable(device_get_adapter(device), device, - wake_allowed); -} -void device_set_wake_allowed_complete(struct btd_device *device) -{ - if (device->wake_id != -1U) { - g_dbus_pending_property_success(device->wake_id); - device->wake_id = -1U; - } - - device->wake_allowed = device->pending_wake_allowed; - g_dbus_emit_property_changed(dbus_conn, device->path, - DEVICE_INTERFACE, "WakeAllowed"); + flags = device->current_flags; + if (wake_allowed) + flags |= DEVICE_FLAG_REMOTE_WAKEUP; + else + flags &= ~DEVICE_FLAG_REMOTE_WAKEUP; - store_device_info(device); + adapter_set_device_flags(device->adapter, device, flags, + set_wake_allowed_complete, device); } - static gboolean dev_property_get_wake_allowed(const GDBusPropertyTable *property, DBusMessageIter *iter, void *data) -- cgit v1.2.1