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;