From: Samuel Ortiz Date: Thu, 3 Jun 2010 17:55:23 +0000 (+0200) Subject: wifi routine to fetch the saved SSIDs from the active profile X-Git-Tag: 2.0_alpha~2720 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ea39185a68f23f3c902d8c167f79ef81416a99ce;p=framework%2Fconnectivity%2Fconnman.git wifi routine to fetch the saved SSIDs from the active profile --- diff --git a/include/wifi.h b/include/wifi.h index d5dceef..c90e312 100644 --- a/include/wifi.h +++ b/include/wifi.h @@ -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 diff --git a/src/wifi.c b/src/wifi.c index bca1e60..a663f17 100644 --- a/src/wifi.c +++ b/src/wifi.c @@ -23,6 +23,9 @@ #include #endif +#include +#include + #include #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; +}