network-functions.pl: Improve wifi_get_link_quality

iwconfig doesn't return values for "Link Quality" if the interface
is disconnected, causing a division by zero error. If there are odd
values, the resulting percentage may contain many decimal places.

This patch makes wifi_get_link_quality return zero instead of failing
and rounds the percentage to a more meaningful integer.

Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
This commit is contained in:
Leo-Andres Hofmann
2021-07-23 13:09:42 +02:00
committed by Arne Fitzenreiter
parent f4858c925c
commit 6dd084c22d

View File

@@ -403,7 +403,11 @@ sub wifi_get_link_quality($) {
my ($cur, $max) = $status =~ /Link Quality=(\d+)\/(\d+)/;
return $cur * 100 / $max;
if($max > 0) {
return sprintf('%.0f', ($cur * 100) / $max);
}
return 0;
}
sub wifi_get_signal_level($) {