wifi: move nm_wifi_utils_level_to_quality() to "src/nm-core-utils.h"

It will be used outside of Wi-Fi device plugin. Namely, NMSupplicantInterface
needs to convert the signal strength from supplicant to percent.
This commit is contained in:
Thomas Haller 2020-01-27 19:31:23 +01:00
parent 837e71a374
commit 05ff735ec0
4 changed files with 25 additions and 21 deletions

View file

@ -786,25 +786,6 @@ nm_wifi_utils_complete_connection (GBytes *ap_ssid,
return TRUE;
}
guint32
nm_wifi_utils_level_to_quality (int val)
{
if (val < 0) {
/* Assume dBm already; rough conversion: best = -40, worst = -100 */
val = abs (CLAMP (val, -100, -40) + 40); /* normalize to 0 */
val = 100 - (int) ((100.0 * (double) val) / 60.0);
} else if (val > 110 && val < 256) {
/* assume old-style WEXT 8-bit unsigned signal level */
val -= 256; /* subtract 256 to convert to dBm */
val = abs (CLAMP (val, -100, -40) + 40); /* normalize to 0 */
val = 100 - (int) ((100.0 * (double) val) / 60.0);
} else {
/* Assume signal is a "quality" percentage */
}
return CLAMP (val, 0, 100);
}
gboolean
nm_wifi_utils_is_manf_default_ssid (GBytes *ssid)
{

View file

@ -30,8 +30,6 @@ gboolean nm_wifi_utils_complete_connection (GBytes *ssid,
gboolean lock_bssid,
GError **error);
guint32 nm_wifi_utils_level_to_quality (int val);
gboolean nm_wifi_utils_is_manf_default_ssid (GBytes *ssid);
NMIwdNetworkSecurity nm_wifi_connection_get_iwd_security (NMConnection *connection,

View file

@ -4073,6 +4073,27 @@ nm_utils_strdict_to_variant (GHashTable *options)
/*****************************************************************************/
guint8
nm_wifi_utils_level_to_quality (int val)
{
if (val < 0) {
/* Assume dBm already; rough conversion: best = -40, worst = -100 */
val = abs (CLAMP (val, -100, -40) + 40); /* normalize to 0 */
val = 100 - (int) ((100.0 * (double) val) / 60.0);
} else if (val > 110 && val < 256) {
/* assume old-style WEXT 8-bit unsigned signal level */
val -= 256; /* subtract 256 to convert to dBm */
val = abs (CLAMP (val, -100, -40) + 40); /* normalize to 0 */
val = 100 - (int) ((100.0 * (double) val) / 60.0);
} else {
/* Assume signal is a "quality" percentage */
}
return CLAMP (val, 0, 100);
}
/*****************************************************************************/
NM_UTILS_ENUM2STR_DEFINE (nm_icmpv6_router_pref_to_string, NMIcmpv6RouterPref,
NM_UTILS_ENUM2STR (NM_ICMPV6_ROUTER_PREF_LOW, "low"),
NM_UTILS_ENUM2STR (NM_ICMPV6_ROUTER_PREF_MEDIUM, "medium"),

View file

@ -473,6 +473,10 @@ const char *nm_utils_parse_dns_domain (const char *domain, gboolean *is_routing)
/*****************************************************************************/
guint8 nm_wifi_utils_level_to_quality (int val);
/*****************************************************************************/
#define NM_VPN_ROUTE_METRIC_DEFAULT 50
#define NM_UTILS_ERROR_MSG_REQ_AUTH_FAILED "Unable to authenticate the request"