From bfbb71b763378df7620381f5b98fc60573feb5aa Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 23 Nov 2010 00:02:46 -0600 Subject: [PATCH] wifi: update signal quality calculation for new supplicant interface --- src/nm-device-wifi.c | 40 ---------------------------------------- src/nm-wifi-ap.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index 3644ccfc4c..a2b3b4c1e2 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -2140,44 +2140,6 @@ cull_scan_list (NMDeviceWifi *self) removed, total); } -#define SET_QUALITY_MEMBER(qual_item, lc_member, uc_member) \ - if (lc_member != -1) { \ - qual_item.lc_member = lc_member; \ - qual_item.updated |= IW_QUAL_##uc_member##_UPDATED; \ - } else { \ - qual_item.updated |= IW_QUAL_##uc_member##_INVALID; \ - } - -static void -set_ap_strength_from_properties (NMDeviceWifi *self, - NMAccessPoint *ap, - GHashTable *properties) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - int qual, level, noise; - struct iw_quality quality; - GValue *value; - gint8 strength; - - value = (GValue *) g_hash_table_lookup (properties, "quality"); - qual = value ? g_value_get_int (value) : -1; - - value = (GValue *) g_hash_table_lookup (properties, "level"); - level = value ? g_value_get_int (value) : -1; - - value = (GValue *) g_hash_table_lookup (properties, "noise"); - noise = value ? g_value_get_int (value) : -1; - - /* Calculate and set the AP's signal quality */ - memset (&quality, 0, sizeof (struct iw_quality)); - SET_QUALITY_MEMBER (quality, qual, QUAL); - SET_QUALITY_MEMBER (quality, level, LEVEL); - SET_QUALITY_MEMBER (quality, noise, NOISE); - - strength = wireless_qual_to_percent (&quality, &priv->max_qual); - nm_ap_set_strength (ap, strength); -} - static void supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, GHashTable *properties, @@ -2197,8 +2159,6 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, ap = nm_ap_new_from_properties (properties); if (ap) { - set_ap_strength_from_properties (self, ap, properties); - nm_ap_print_self (ap, "AP: "); /* Add the AP to the device's AP list */ diff --git a/src/nm-wifi-ap.c b/src/nm-wifi-ap.c index 642b6d978e..4438118729 100644 --- a/src/nm-wifi-ap.c +++ b/src/nm-wifi-ap.c @@ -22,6 +22,7 @@ #include "wireless-helper.h" #include +#include #include "nm-wifi-ap.h" #include "NetworkManagerUtils.h" @@ -495,6 +496,19 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data) if (!strcmp (key, "Frequency")) nm_ap_set_freq (ap, val); + } else if (G_VALUE_HOLDS_INT (variant)) { + gint val = g_value_get_int (variant); + + if (!strcmp (key, "Signal")) { + if (val < 0) { + /* Rough conversion: best = -40, worst = -100 */ + val = abs (CLAMP (val, -100, -40) + 40); + val = 100 - (int) ((100.0 * (double) val) / 60.0); + } else + val /= 100; + + nm_ap_set_strength (ap, val); + } } else if (G_VALUE_HOLDS_STRING (variant)) { const char *val = g_value_get_string (variant);