connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iwd: Use same signal strength calculation as wpa_supplicant
@ 2022-02-15 10:19 Jonathan Liu
  2022-02-21  8:24 ` Daniel Wagner
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Liu @ 2022-02-15 10:19 UTC (permalink / raw)
  To: connman; +Cc: Jonathan Liu

Fixes the signal strength reported by connman being lower when using iwd
compared to wpa_supplicant.

In the wifi plugin for wpa_supplicant, the signal strength is calculated
as follows:
strength = 120 + g_supplicant_network_get_signal(supplicant_network);
if (strength > 100)
    strength = 100;

The g_supplicant_network_get_signal() function returns the signal
strength in dBm. This means the signal strength calculation in connman
for wpa_supplicant treats -20 dBm or higher as 100% signal strength.

The iwd plugin is changed to use the same calculation but as iwd returns
returns the signal strength as 100 * dBm, it needs to be divided by 100
to get the same dBm value as wpa_supplicant.
---
 plugins/iwd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index ac3d1e17..2a245fe2 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -1128,7 +1128,9 @@ static unsigned char calculate_strength(int strength)
 	 * ConnMan expects it in the range from 100 (strongest) to 0
 	 * (weakest).
 	 */
-	res = (unsigned char)((strength + 10000) / 100);
+	res = (unsigned char)(120 + strength / 100);
+	if (res > 100)
+		res = 100;
 
 	return res;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iwd: Use same signal strength calculation as wpa_supplicant
  2022-02-15 10:19 [PATCH v2] iwd: Use same signal strength calculation as wpa_supplicant Jonathan Liu
@ 2022-02-21  8:24 ` Daniel Wagner
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Wagner @ 2022-02-21  8:24 UTC (permalink / raw)
  To: Jonathan Liu; +Cc: connman

Hi,

On Tue, Feb 15, 2022 at 09:19:40PM +1100, Jonathan Liu wrote:
> Fixes the signal strength reported by connman being lower when using iwd
> compared to wpa_supplicant.
> 
> In the wifi plugin for wpa_supplicant, the signal strength is calculated
> as follows:
> strength = 120 + g_supplicant_network_get_signal(supplicant_network);
> if (strength > 100)
>     strength = 100;
> 
> The g_supplicant_network_get_signal() function returns the signal
> strength in dBm. This means the signal strength calculation in connman
> for wpa_supplicant treats -20 dBm or higher as 100% signal strength.
> 
> The iwd plugin is changed to use the same calculation but as iwd returns
> returns the signal strength as 100 * dBm, it needs to be divided by 100
> to get the same dBm value as wpa_supplicant.

Patch applied.

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-21  8:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 10:19 [PATCH v2] iwd: Use same signal strength calculation as wpa_supplicant Jonathan Liu
2022-02-21  8:24 ` Daniel Wagner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).