wifi routine to fetch the saved SSIDs from the active profile
authorSamuel Ortiz <sameo@linux.intel.com>
Thu, 3 Jun 2010 17:55:23 +0000 (19:55 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 4 Jun 2010 22:33:48 +0000 (00:33 +0200)
include/wifi.h
src/wifi.c

index d5dceef..c90e312 100644 (file)
@@ -31,6 +31,8 @@ char *connman_wifi_build_group_name(const unsigned char *ssid,
                                                        const char *mode,
                                                        const char *security);
 
+char **connman_wifi_load_ssid(void);
+
 #ifdef __cplusplus
 }
 #endif
index bca1e60..a663f17 100644 (file)
@@ -23,6 +23,9 @@
 #include <config.h>
 #endif
 
+#include <stdio.h>
+#include <string.h>
+
 #include <glib.h>
 
 #include "connman.h"
@@ -48,3 +51,45 @@ char *connman_wifi_build_group_name(const unsigned char *ssid,
 
        return g_string_free(str, FALSE);
 }
+
+char **connman_wifi_load_ssid(void)
+{
+       GKeyFile *key_file;
+       const char * profile;
+       gchar **groups, *group;
+       gsize num_groups;
+       char **hex_ssids;
+       int i, j;
+
+       profile = __connman_profile_active_ident();
+
+       key_file = __connman_storage_open_profile(profile);
+       if (key_file == NULL)
+               return NULL;
+
+       groups = g_key_file_get_groups(key_file, &num_groups);
+       if (groups == NULL) {
+               hex_ssids = NULL;
+               goto done;
+       }
+
+       hex_ssids = g_try_malloc0(sizeof(*hex_ssids) * num_groups);
+
+       for (i = 0, j = 0; groups[i]; i++) {
+               gchar *hex_ssid;
+
+               group = groups[i];
+
+               hex_ssid = g_key_file_get_string(key_file, group,
+                                                       "SSID", NULL);
+               if (hex_ssid == NULL)
+                       continue;
+
+               hex_ssids[j++] = hex_ssid;
+       }
+
+done:
+       __connman_storage_close_profile(profile, key_file, FALSE);
+
+       return hex_ssids;
+}