summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorArchie Pusaka <apusaka@chromium.org>2022-01-13 15:46:52 +0800
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-01-13 13:34:53 -0800
commit7a8d1be9755f39ca2d3060b4ba9f9ce58c83c0ed (patch)
treeb128e893d5efcf96525b0c38779e5ce62119bc1e /src/device.c
parent33d13bbc5703185ab3f15e4429df324987f3f225 (diff)
downloadbluez-7a8d1be9755f39ca2d3060b4ba9f9ce58c83c0ed.tar.gz
device: Fix device can't be scanned for 5 mins after reboot
After the patches which limit the attempts of doing remote name resolving, there's an issue which prevents BlueZ to RNR new devices for 5 minutes after reboot. It's caused by failed_time is init to 0, and is then treated as the timestamp when the device failed RNR. However, actually there is no failure yet. This patch fixes it by always allowing RNR when failed_time = 0.
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/device.c b/src/device.c
index f2447c478..6d29eb896 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4487,12 +4487,24 @@ bool device_is_name_resolve_allowed(struct btd_device *device)
clock_gettime(CLOCK_MONOTONIC, &now);
- /* If now < failed_time, it means the clock has somehow turned back,
- * possibly because of system restart. Allow name request in this case.
+ /* failed_time is empty (0), meaning no prior failure. */
+ if (device->name_resolve_failed_time == 0)
+ return true;
+
+ /* now < failed_time, meaning the clock has somehow turned back,
+ * possibly because of system restart. Allow just to be safe.
+ */
+ if (now.tv_sec < device->name_resolve_failed_time)
+ return true;
+
+ /* now >= failed_time + name_request_retry_delay, meaning the
+ * period of not sending name request is over.
*/
- return now.tv_sec < device->name_resolve_failed_time ||
- now.tv_sec >= device->name_resolve_failed_time +
- btd_opts.name_request_retry_delay;
+ if (now.tv_sec >= device->name_resolve_failed_time +
+ btd_opts.name_request_retry_delay)
+ return true;
+
+ return false;
}
void device_name_resolve_fail(struct btd_device *device)