summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-01-27 19:31:23 +0100
committerThomas Haller <thaller@redhat.com>2020-02-10 19:11:50 +0100
commit05ff735ec00aa32c6c7b3b2f80606a4e1cb06f95 (patch)
tree7e44a99d309942c82aa71500ae0bdb5383d21a5a
parent837e71a374b479833e4baf5844011109d9724da1 (diff)
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.
-rw-r--r--src/devices/wifi/nm-wifi-utils.c19
-rw-r--r--src/devices/wifi/nm-wifi-utils.h2
-rw-r--r--src/nm-core-utils.c21
-rw-r--r--src/nm-core-utils.h4
4 files changed, 25 insertions, 21 deletions
diff --git a/src/devices/wifi/nm-wifi-utils.c b/src/devices/wifi/nm-wifi-utils.c
index 7cb5f85bd..0903dc8bb 100644
--- a/src/devices/wifi/nm-wifi-utils.c
+++ b/src/devices/wifi/nm-wifi-utils.c
@@ -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)
{
diff --git a/src/devices/wifi/nm-wifi-utils.h b/src/devices/wifi/nm-wifi-utils.h
index 982080b90..505baa84b 100644
--- a/src/devices/wifi/nm-wifi-utils.h
+++ b/src/devices/wifi/nm-wifi-utils.h
@@ -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,
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index 54c3ee629..eccb5f7b1 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -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"),
diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h
index fbb798757..ca3e7dbf3 100644
--- a/src/nm-core-utils.h
+++ b/src/nm-core-utils.h
@@ -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"