diff --git a/src/adapter.c b/src/adapter.c
index bb49a1e..85ddfc1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
static void set_device_privacy_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
+ struct btd_device *dev = user_data;
const struct mgmt_rp_set_device_flags *rp = param;
if (status != MGMT_STATUS_SUCCESS) {
error("Too small Set Device Flags complete event: %d", length);
return;
}
+
+ btd_device_flags_changed(dev, btd_device_get_supported_flags(dev),
+ btd_device_get_pending_flags(dev));
}
static void add_device_complete(uint8_t status, uint16_t length,
adapter_set_device_flags(adapter, dev, flags |
DEVICE_FLAG_DEVICE_PRIVACY,
set_device_privacy_complete,
- NULL);
+ dev);
}
}
}
{
struct mgmt_cp_set_device_flags cp;
uint32_t supported = btd_device_get_supported_flags(device);
+ uint32_t pending = btd_device_get_pending_flags(device);
const bdaddr_t *bdaddr;
uint8_t bdaddr_type;
(supported | flags) != supported)
return;
+ /* Check if changing flags are pending */
+ if (flags == (flags & pending))
+ return;
+
+ /* Set Device Privacy Mode if it has not set the flag yet. */
+ if (btd_opts.device_privacy && !(flags & DEVICE_FLAG_DEVICE_PRIVACY))
+ flags |= DEVICE_FLAG_DEVICE_PRIVACY & supported & ~pending;
+
bdaddr = device_get_address(device);
bdaddr_type = btd_device_get_bdaddr_type(device);
cp.addr.type = bdaddr_type;
cp.current_flags = cpu_to_le32(flags);
- mgmt_send(adapter->mgmt, MGMT_OP_SET_DEVICE_FLAGS, adapter->dev_id,
- sizeof(cp), &cp, func, user_data, NULL);
+ if (mgmt_send(adapter->mgmt, MGMT_OP_SET_DEVICE_FLAGS, adapter->dev_id,
+ sizeof(cp), &cp, func, user_data, NULL))
+ btd_device_set_pending_flags(device, flags);
}
static void device_flags_changed_callback(uint16_t index, uint16_t length,
diff --git a/src/device.c b/src/device.c
index 097b1fb..a1dc075 100644
--- a/src/device.c
+++ b/src/device.c
GDBusPendingPropertySet wake_id;
uint32_t supported_flags;
+ uint32_t pending_flags;
uint32_t current_flags;
GSList *svc_callbacks;
GSList *eir_uuids;
return;
}
- device_set_wake_allowed_complete(dev);
+ btd_device_flags_changed(dev, dev->supported_flags, dev->pending_flags);
}
void device_set_wake_allowed(struct btd_device *device, bool wake_allowed,
return dev->supported_flags;
}
+void btd_device_set_pending_flags(struct btd_device *dev, uint32_t flags)
+{
+ if (!dev)
+ return;
+
+ dev->pending_flags = flags;
+}
+
+uint32_t btd_device_get_pending_flags(struct btd_device *dev)
+{
+ if (!dev)
+ return 0;
+
+ return dev->pending_flags;
+}
+
/* This event is sent immediately after add device on all mgmt sockets.
* Afterwards, it is only sent to mgmt sockets other than the one which called
* set_device_flags.
dev->supported_flags = supported_flags;
dev->current_flags = current_flags;
+ dev->pending_flags = 0;
if (!changed_flags)
return;
diff --git a/src/device.h b/src/device.h
index 0794f92..3742f60 100644
--- a/src/device.h
+++ b/src/device.h
uint32_t btd_device_get_current_flags(struct btd_device *dev);
uint32_t btd_device_get_supported_flags(struct btd_device *dev);
+uint32_t btd_device_get_pending_flags(struct btd_device *dev);
+void btd_device_set_pending_flags(struct btd_device *dev, uint32_t flags);
void btd_device_flags_changed(struct btd_device *dev, uint32_t supported_flags,
uint32_t current_flags);