diff mbox series

[BlueZ,3/3] device: Try to set the wake_allowed property only for bonded devices

Message ID 20250325172846.139431-4-ludovico.denittis@collabora.com (mailing list archive)
State New
Headers show
Series Fix wake_allowed reported error and not being set after pairing | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

Ludovico de Nittis March 25, 2025, 5:28 p.m. UTC
When the function `device_set_wake_support()` is called, we don't have
the guarantees for the device to be already bonded.

For example, that function gets called by `hog_probe()`, that is also
triggered when bluez scans for new devices. In that instance, we don't
want to try setting the `wake_allowed` property, because those devices
are only in range of the host and are not connected, paired or bonded
yet.

This fixes the following Bluez error when we scan for new devices and a
new hog or hid is in range:
```
src/device.c:set_wake_allowed_complete() Set device flags return status:
Invalid Parameters
```

Additionally, because that initial `device_set_allowed()` call can fail,
this commit fixes the issue of hog and hid devices that, after the first
pairing, were unexpectedly showing `WakeAllowed: no`. And it required a
reboot to let that property be set to the expected `WakeAllowed: yes` by
default.
---
 src/device.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/src/device.c b/src/device.c
index 474ec5763..727b668af 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1526,10 +1526,13 @@  void device_set_wake_support(struct btd_device *device, bool wake_support)
 	if (device->wake_override == WAKE_FLAG_DEFAULT)
 		device_set_wake_override(device, wake_support);
 
-	/* Set wake_allowed according to the override value. */
-	device_set_wake_allowed(device,
-				device->wake_override == WAKE_FLAG_ENABLED,
-				-1U);
+	/* Set wake_allowed according to the override value.
+	 * Limit this to bonded device to avoid trying to set it
+	 * to new devices that are simply in range. */
+	if (device_is_bonded(device, device->bdaddr_type))
+		device_set_wake_allowed(device,
+					device->wake_override == WAKE_FLAG_ENABLED,
+					-1U);
 }
 
 static bool device_get_wake_allowed(struct btd_device *device)
@@ -6561,6 +6564,10 @@  void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type,
 
 	device_auth_req_free(device);
 
+	/* Enable the wake_allowed property if required */
+	if (device->wake_override == WAKE_FLAG_ENABLED)
+		device_set_wake_allowed(device, true, -1U);
+
 	/* If we're already paired nothing more is needed */
 	if (state->paired)
 		return;