From: taesub kim Date: Fri, 26 May 2017 08:29:03 +0000 (+0900) Subject: Modified way of update rssi value X-Git-Tag: accepted/tizen/unified/20170703.064321^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fnet-config.git;a=commitdiff_plain;h=5857d1ff5a0f530b8345740c1f6e69a616859ca4 Modified way of update rssi value Change-Id: I8b06ff9d4fc35a43685f7f75d3c9245d3ccca0eb Signed-off-by: Taesub Kim --- diff --git a/src/wifi-indicator.c b/src/wifi-indicator.c index 36cf86e..3ad9b8e 100755 --- a/src/wifi-indicator.c +++ b/src/wifi-indicator.c @@ -66,91 +66,49 @@ int netconfig_wifi_get_rssi(void) static int __netconfig_wifi_update_and_get_rssi(void) { - FILE *fp; - char buf[512]; - char *p_ifname = NULL, *p_entry = NULL; + const char *if_path = NULL; + GVariant *message = NULL; + GVariant *value = NULL; + gchar *key; + GVariantIter *iter; + GVariant *variant; + gint32 key_value; int rssi_dbm = VCONFKEY_WIFI_SNR_MIN; - fp = fopen(NETCONFIG_PROCWIRELESS, "r"); - if (fp == NULL) { - ERR("Failed to open %s", NETCONFIG_PROCWIRELESS); - return rssi_dbm; + if_path = netconfig_wifi_get_supplicant_interface(); + if (if_path == NULL) { + ERR("Fail to get wpa_supplicant DBus path"); + return 0; } - /* skip the first and second line */ - if (fgets(buf, sizeof(buf), fp) == NULL || - fgets(buf, sizeof(buf), fp) == NULL) - goto endline; - - while (fgets(buf, sizeof(buf), fp)) { - unsigned int status = 0; - int link = 0; - int noise = 0; - /* No need to read */ - /* - unsigned long nwid, crypt, frag, retry, misc, missed; - */ - - p_ifname = buf; - while (*p_ifname == ' ') p_ifname++; - p_entry = strchr(p_ifname, ':'); - if (p_entry == NULL) - goto endline; - *p_entry++ = '\0'; - - if (g_strcmp0(p_ifname, WIFI_IFNAME) != 0) - continue; - - /* read wireless status */ - char *saveptr; - p_entry = strtok_r(p_entry, " .", &saveptr); - - /* status "%x" */ - if (p_entry != NULL) - status = (int)strtol(p_entry, NULL, 16); - - p_entry = strtok_r(NULL, " .", &saveptr); - - /* Quality link "%d" */ - if (p_entry != NULL) - link = (int)strtol(p_entry, NULL, 10); - - p_entry = strtok_r(NULL, " .", &saveptr); - - /* Quality level "%d" */ - if (p_entry != NULL) - rssi_dbm = (int)strtol(p_entry, NULL, 10); - - p_entry = strtok_r(NULL, " .", &saveptr); - - /* Quality noise "%d" */ - if (p_entry != NULL) - noise = (int)strtol(p_entry, NULL, 10); - - DBG("status(%x) link(%d) rssi_dbm(%d) noise(%d)", - status, link, rssi_dbm, noise); - - /* No need to read */ - /* - p_entry = strtok(NULL, " ."); // Discarded nwid "%lu" - sscanf(p_entry, "%lu", &nwid); - p_entry = strtok(NULL, " ."); // Discarded crypt "%lu" - sscanf(p_entry, "%lu", &crypt); - p_entry = strtok(NULL, " ."); // Discarded frag "%lu" - sscanf(p_entry, "%lu", &frag); - p_entry = strtok(NULL, " ."); // Discarded retry "%lu" - sscanf(p_entry, "%lu", &retry); - p_entry = strtok(NULL, " ."); // Discarded misc "%lu" - sscanf(p_entry, "%lu", &misc); - p_entry = strtok(NULL, " ."); // Discarded missed "%lu" - sscanf(p_entry, "%lu", &missed); - */ + message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE, if_path, + SUPPLICANT_INTERFACE ".Interface", "SignalPoll", NULL); + if (message == NULL) { + ERR("Fail to get SignalPoll from wpa_supplicant"); + return 0; + } - break; + g_variant_get(message, "(v)", &value); + + g_variant_get(value, "a{sv}", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) { + key_value = g_variant_get_int32(variant); + + if (g_strcmp0(key, "rssi") == 0) { + rssi_dbm = (int)key_value; + DBG("Currently signal dbm value [%d]", rssi_dbm); + g_variant_unref(variant); + g_free(key); + break; + } } -endline: - fclose(fp); + if (iter) + g_variant_iter_free(iter); + + if (value) + g_variant_unref(value); + netconfig_wifi_rssi = rssi_dbm; return rssi_dbm; diff --git a/src/wifi-power.c b/src/wifi-power.c index b6b9bab..c0236c7 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -247,6 +247,7 @@ static int _remove_driver_and_supplicant(void) { int err = 0; + INFO("remove driver and supplicant"); if (wifi_firmware_recovery_mode != TRUE && netconfig_wifi_is_wps_enabled() == TRUE) { DBG("Wi-Fi WPS mode"); @@ -263,6 +264,9 @@ static int _remove_driver_and_supplicant(void) wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_OFF); + // reset service state + wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); + if (wifi_firmware_recovery_mode == TRUE) { if (wifi_power_on() < 0) ERR("Failed to recover Wi-Fi firmware");