From 56a14cc7205788a2ee9ed8168d58254eb200bbb4 Mon Sep 17 00:00:00 2001 From: Nicolas Escande Date: Tue, 8 Mar 2022 11:22:18 +0100 Subject: [PATCH] DFS: Don't let cac_time_left_seconds overflow There can be some discrepancy between the theorical dfs cac end (as computed with the cac duration and cac start) and the actual cac end as reported by the driver. During that window, the value of remaining time outputed by the status command on the socket control interface will display an overflowed, invalid value. To mitigate this lets compute the remaining time as signed and display it only when positive, otherwise defaulting it to 0. Status command shows something like that when polling every seconds: state=DFS cac_time_seconds=60 cac_time_left_seconds=1 ... state=DFS cac_time_seconds=60 cac_time_left_seconds=0 ... state=DFS cac_time_seconds=60 cac_time_left_seconds=4294967294 ... state=DFS cac_time_seconds=60 cac_time_left_seconds=4294967293 ... state=DFS cac_time_seconds=60 cac_time_left_seconds=4294967292 ... state=ENABLED cac_time_seconds=60 cac_time_left_seconds=N/A Signed-off-by: Nicolas Escande --- src/ap/ctrl_iface_ap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ap/ctrl_iface_ap.c b/src/ap/ctrl_iface_ap.c index 1d8fb8246..9e9eadd2f 100644 --- a/src/ap/ctrl_iface_ap.c +++ b/src/ap/ctrl_iface_ap.c @@ -724,15 +724,15 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf, } else { /* CAC started and CAC time set - calculate remaining time */ struct os_reltime now; - unsigned int left_time; + long left_time; os_reltime_age(&iface->dfs_cac_start, &now); - left_time = iface->dfs_cac_ms / 1000 - now.sec; + left_time = (long) iface->dfs_cac_ms / 1000 - now.sec; ret = os_snprintf(buf + len, buflen - len, "cac_time_seconds=%u\n" - "cac_time_left_seconds=%u\n", + "cac_time_left_seconds=%lu\n", iface->dfs_cac_ms / 1000, - left_time); + left_time > 0 ? left_time : 0); } if (os_snprintf_error(buflen - len, ret)) return len; -- 2.47.2