5 * Copyright (C) 2007 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <arpa/inet.h>
33 #define GROUP_CONFIG "Config"
35 int __connman_iface_load(struct connman_iface *iface)
38 gchar *pathname, *str;
40 DBG("iface %p", iface);
42 if (iface->identifier == NULL)
45 pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
50 keyfile = g_key_file_new();
52 if (g_key_file_load_from_file(keyfile, pathname, 0, NULL) == FALSE)
55 if (g_key_file_has_group(keyfile, GROUP_CONFIG) == FALSE)
58 str = g_key_file_get_string(keyfile, GROUP_CONFIG, "Policy", NULL);
60 iface->policy = __connman_iface_string2policy(str);
64 str = g_key_file_get_string(keyfile, GROUP_CONFIG, "Network", NULL);
66 g_free(iface->network.essid);
67 iface->network.essid = str;
68 if (iface->driver->set_network)
69 iface->driver->set_network(iface, str);
71 str = g_key_file_get_string(keyfile, iface->network.essid,
74 g_free(iface->network.psk);
75 iface->network.psk = str;
76 if (iface->driver->set_passphrase)
77 iface->driver->set_passphrase(iface, str);
82 g_key_file_free(keyfile);
89 static void do_update(GKeyFile *keyfile, struct connman_iface *iface)
93 DBG("iface %p", iface);
95 str = __connman_iface_policy2string(iface->policy);
96 g_key_file_set_string(keyfile, GROUP_CONFIG, "Policy", str);
98 if (iface->network.essid != NULL) {
99 g_key_file_set_string(keyfile, GROUP_CONFIG,
100 "Network", iface->network.essid);
102 g_key_file_remove_key(keyfile, GROUP_CONFIG, "Network", NULL);
104 if (iface->network.essid != NULL)
105 g_key_file_set_string(keyfile, iface->network.essid,
106 "PSK", iface->network.psk);
109 int __connman_iface_store(struct connman_iface *iface)
112 gchar *pathname, *data = NULL;
115 DBG("iface %p", iface);
117 if (iface->identifier == NULL)
120 pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
122 if (pathname == NULL)
125 keyfile = g_key_file_new();
127 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
131 if (g_key_file_load_from_data(keyfile, data, length,
132 G_KEY_FILE_KEEP_COMMENTS, NULL) == FALSE)
139 do_update(keyfile, iface);
141 data = g_key_file_to_data(keyfile, &length, NULL);
143 g_file_set_contents(pathname, data, length, NULL);
148 g_key_file_free(keyfile);