Revert "Fix compile error which is specific for GCC 6.2"
[platform/core/connectivity/net-config.git] / src / wifi-config.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <sys/types.h>
23 #include <dirent.h>
24 #include <sys/stat.h>
25 #include <glib.h>
26 #include <unistd.h>
27
28 #include <vconf.h>
29
30 #include "log.h"
31 #include "util.h"
32 #include "neterror.h"
33 #include "wifi-config.h"
34
35 #define CONNMAN_STORAGE         "/var/lib/connman"
36
37 #define WIFI_SECURITY_NONE              "none"
38 #define WIFI_SECURITY_WEP               "wep"
39 #define WIFI_SECURITY_WPA_PSK   "psk"
40 #define WIFI_SECURITY_EAP               "ieee8021x"
41
42 #define WIFI_CONFIG_PREFIX      "wifi_"
43 #define MAC_ADDRESS_LENGTH              12
44 #define WIFI_PREFIX_LENGTH              MAC_ADDRESS_LENGTH + 6  /* wifi_485a3f2f506a_ */
45 #define PROFILE_PREFIX_LENGTH   WIFI_PREFIX_LENGTH + 21 /* /net/connman/service/wifi_485a3f2f506a_ */
46
47 #define WIFI_MAC_ADD_LENGTH             17
48 #define WIFI_MAC_ADD_PATH               "/sys/class/net/wlan0/address"
49
50 struct wifi_eap_config {
51         gchar *anonymous_identity;
52         gchar *ca_cert;
53         gchar *client_cert;
54         gchar *private_key;
55         gchar *identity;
56         gchar *eap_type;
57         gchar *eap_auth_type;
58         gchar *subject_match;
59 };
60
61 struct wifi_config {
62         gchar *name;
63         gchar *ssid;
64         gchar *passphrase;
65         gchar *security_type;
66         gboolean favorite;
67         gboolean autoconnect;
68         gchar *is_hidden;
69         gchar *proxy_address;
70         struct wifi_eap_config *eap_config;
71         gchar *last_error;
72 };
73
74 static void __free_wifi_configuration(struct wifi_config *conf)
75 {
76         if (conf == NULL)
77                 return;
78
79         g_free(conf->name);
80         g_free(conf->ssid);
81         g_free(conf->passphrase);
82         g_free(conf->security_type);
83         g_free(conf->is_hidden);
84         g_free(conf->proxy_address);
85         g_free(conf->last_error);
86         if (conf->eap_config) {
87                 g_free(conf->eap_config->anonymous_identity);
88                 g_free(conf->eap_config->ca_cert);
89                 g_free(conf->eap_config->client_cert);
90                 g_free(conf->eap_config->private_key);
91                 g_free(conf->eap_config->identity);
92                 g_free(conf->eap_config->eap_type);
93                 g_free(conf->eap_config->eap_auth_type);
94                 g_free(conf->eap_config->subject_match);
95                 g_free(conf->eap_config);
96         }
97         g_free(conf);
98 }
99
100 static gboolean __get_mac_address(gchar **mac_address)
101 {
102         gchar *tmp_mac = NULL;
103         gchar *tmp = NULL;
104         gchar mac[13] = { 0, };
105         gint i = 0, j = 0;
106 #if defined TIZEN_TV
107         FILE *fp = NULL;
108         char buf[WIFI_MAC_ADD_LENGTH + 1];
109         if (0 == access(WIFI_MAC_ADD_PATH, F_OK))
110                 fp = fopen(WIFI_MAC_ADD_PATH, "r");
111
112         if (fp == NULL) {
113                 ERR("Failed to open file %s\n", WIFI_MAC_ADD_PATH);
114                 *mac_address = NULL;
115                 return FALSE;
116         }
117
118         if (fgets(buf, sizeof(buf), fp) == NULL) {
119                 ERR("Failed to get MAC info from %s\n", WIFI_MAC_ADD_PATH);
120                 *mac_address = NULL;
121                 fclose(fp);
122                 return FALSE;
123         }
124         tmp_mac = (char *)g_try_malloc0(WIFI_MAC_ADD_LENGTH + 1);
125         if (tmp_mac == NULL) {
126                 ERR("malloc() failed");
127                 *mac_address = NULL;
128                 fclose(fp);
129                 return FALSE;
130         }
131         g_strlcpy(tmp_mac, buf, WIFI_MAC_ADD_LENGTH + 1);
132         fclose(fp);
133 #else
134         tmp_mac = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
135         if (tmp_mac == NULL) {
136                 ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed");
137                 *mac_address = NULL;
138                 return FALSE;
139         }
140 #endif
141         tmp = g_ascii_strdown(tmp_mac, (gssize)strlen(tmp_mac));
142         g_free(tmp_mac);
143         while (tmp && tmp[i]) {
144                 if (tmp[i] != ':')
145                         mac[j++] = tmp[i];
146                 i++;
147         }
148         mac[12] = '\0';
149         *mac_address = g_strdup(mac);
150
151         return TRUE;
152 }
153
154 static gboolean __get_group_name(const gchar *prefix, const gchar *config_id, gchar **group_name)
155 {
156         gchar *mac_address = NULL;
157         gchar *g_name = NULL;
158         gboolean ret = FALSE;
159
160         ret = __get_mac_address(&mac_address);
161         if ((ret != TRUE) || (strlen(mac_address) == 0)) {
162                 ERR("Cannot get WIFI MAC address");
163                 return FALSE;
164         }
165
166         g_name = g_strdup_printf("%s%s_%s", prefix, mac_address, config_id);
167         if (g_name == NULL) {
168                 g_free(mac_address);
169                 return FALSE;
170         }
171
172         *group_name = g_strdup(g_name);
173
174         g_free(mac_address);
175         g_free(g_name);
176
177         return TRUE;
178 }
179
180 static gboolean __get_security_type(const gchar *config_id, gchar **type)
181 {
182         if (g_str_has_suffix(config_id, WIFI_SECURITY_NONE) == TRUE) {
183                 *type = g_strdup(WIFI_SECURITY_NONE);
184         } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WEP) == TRUE) {
185                 *type = g_strdup(WIFI_SECURITY_WEP);
186         } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WPA_PSK) == TRUE) {
187                 *type = g_strdup(WIFI_SECURITY_WPA_PSK);
188         } else if (g_str_has_suffix(config_id, WIFI_SECURITY_EAP) == TRUE) {
189                 *type = g_strdup(WIFI_SECURITY_EAP);
190         } else {
191                 *type = NULL;
192                 return FALSE;
193         }
194
195         return TRUE;
196 }
197
198 static gboolean __get_config_id(const gchar *profile, gchar **config_id)
199 {
200         *config_id = g_strdup(profile + PROFILE_PREFIX_LENGTH);
201         if (*config_id == NULL) {
202                 ERR("OOM");
203                 return FALSE;
204         }
205
206         return TRUE;
207 }
208
209
210 static GKeyFile *__get_configuration_keyfile(const gchar *group_name)
211 {
212         GKeyFile *keyfile = NULL;
213         gchar *path;
214
215         path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
216
217         keyfile = netconfig_keyfile_load(path);
218         if (keyfile == NULL) {
219                 ERR("keyfile[%s] is NULL", path);
220         }
221
222         g_free(path);
223
224         return keyfile;
225 }
226
227 static gboolean __remove_file(const gchar *pathname, const gchar *filename)
228 {
229         gboolean ret = FALSE;
230         gchar *path;
231
232         path = g_strdup_printf("%s/%s", pathname, filename);
233         if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) {
234                 ret = TRUE;
235         } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) {
236                 unlink(path);
237                 ret = TRUE;
238         }
239
240         g_free(path);
241         return ret;
242 }
243
244 static gboolean __remove_configuration(const gchar *pathname)
245 {
246         int ret = 0;
247
248         if (__remove_file(pathname, "settings") != TRUE) {
249                 ERR("Cannot remove [%s/settings]", pathname);
250                 return FALSE;
251         }
252         if (__remove_file(pathname, "data") != TRUE) {
253                 ERR("Cannot remove [%s/data]", pathname);
254                 return FALSE;
255         }
256
257         ret = rmdir(pathname);
258         if (ret == -1) {
259                 ERR("Cannot remove [%s]", pathname);
260                 return FALSE;
261         }
262
263         return TRUE;
264 }
265
266 static gboolean _load_configuration(const gchar *config_id, struct wifi_config *config)
267 {
268         GKeyFile *keyfile;
269         gchar *group_name;
270         gboolean hidden = FALSE;
271         gboolean ret = FALSE;
272
273         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
274         if (ret != TRUE) {
275                 ERR("Fail to get_wifi_config_group_name");
276                 return FALSE;
277         }
278
279         keyfile = __get_configuration_keyfile(group_name);
280         if (keyfile == NULL) {
281                 ERR("Fail to __get_configuration_keyfile[%s]", group_name);
282                 g_free(group_name);
283                 return FALSE;
284         }
285
286         config->name = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
287         DBG("name [%s]", config->name);
288
289         ret = __get_security_type(config_id, &config->security_type);
290         if (ret != TRUE) {
291                 ERR("Fail to _get_security_type");
292                 g_key_file_free(keyfile);
293                 g_free(group_name);
294                 return FALSE;
295         }
296         DBG("security_type [%s]", config->security_type);
297
298         config->proxy_address = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
299         if (config->proxy_address)
300                 DBG("proxy_address [%s]", config->proxy_address);
301
302         hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
303         if (hidden)
304                 config->is_hidden = g_strdup("TRUE");
305         else
306                 config->is_hidden = g_strdup("FALSE");
307         DBG("is_hidden [%s]", config->is_hidden);
308
309         if (g_strcmp0(config->security_type, WIFI_SECURITY_EAP) == 0) {
310                 config->eap_config->anonymous_identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
311                 config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
312                 config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
313                 config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
314                 config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
315                 config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
316                 config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
317                 config->eap_config->subject_match = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
318
319                 if (config->eap_config->anonymous_identity)
320                         DBG("anonymous_identity [%s]", config->eap_config->anonymous_identity);
321                 if (config->eap_config->ca_cert)
322                         DBG("ca_cert [%s]", config->eap_config->ca_cert);
323                 if (config->eap_config->client_cert)
324                         DBG("client_cert [%s]", config->eap_config->client_cert);
325                 if (config->eap_config->private_key)
326                         DBG("private_key [%s]", config->eap_config->private_key);
327                 if (config->eap_config->identity)
328                         DBG("identity [%s]", config->eap_config->identity);
329                 if (config->eap_config->eap_type)
330                         DBG("eap_type [%s]", config->eap_config->eap_type);
331                 if (config->eap_config->eap_auth_type)
332                         DBG("eap_auth_type [%s]", config->eap_config->eap_auth_type);
333                 if (config->eap_config->subject_match)
334                         DBG("subject_match [%s]", config->eap_config->subject_match);
335         }
336
337         config->last_error = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
338         if (config->last_error)
339                 DBG("last_error [%s]", config->last_error);
340
341         g_key_file_free(keyfile);
342         g_free(group_name);
343
344         return TRUE;
345 }
346
347 static gboolean _save_configuration(const gchar *config_id, GKeyFile *keyfile)
348 {
349         gchar *dir;
350         gchar *path;
351         gchar *group_name;
352         gboolean ret = FALSE;
353
354         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
355         if (ret != TRUE) {
356                 ERR("Fail to get_wifi_config_group_name");
357                 return FALSE;
358         }
359
360         dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
361         if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
362                 if (__remove_configuration(dir) != TRUE) {
363                         ERR("[%s] is existed, but cannot remove", dir);
364                         g_free(group_name);
365                         g_free(dir);
366                         return FALSE;
367                 }
368         }
369
370         if (mkdir(dir, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) < 0) {
371                 ERR("Cannot mkdir %s", dir);
372                 g_free(group_name);
373                 g_free(dir);
374                 return FALSE;
375         }
376
377         path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
378         netconfig_keyfile_save(keyfile, path);
379         g_free(group_name);
380         g_free(dir);
381         g_free(path);
382
383         return TRUE;
384 }
385
386 static gboolean _remove_configuration(const gchar *config_id)
387 {
388         gboolean ret = FALSE;
389         gchar *dir;
390         gchar *group_name;
391
392         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
393         if (ret != TRUE) {
394                 ERR("Fail to get_wifi_config_group_name");
395                 return FALSE;
396         }
397
398         dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
399         if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
400                 if (__remove_configuration(dir) != TRUE) {
401                         ERR("[%s] is existed, but cannot remove", dir);
402                         ret = FALSE;
403                 }
404                 INFO("Success to remove [%s]", dir);
405                 ret = TRUE;
406         } else {
407                 ERR("[%s] is not existed", dir);
408                 ret = FALSE;
409         }
410
411         g_free(group_name);
412         g_free(dir);
413
414         return ret;
415 }
416
417
418 static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar *value)
419 {
420         gboolean ret = TRUE;
421         GKeyFile *keyfile;
422         gchar *group_name;
423
424         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
425         if (ret != TRUE) {
426                 ERR("Fail to get_wifi_config_group_name");
427                 return FALSE;
428         }
429         DBG("group_name %s", group_name);
430
431         keyfile = __get_configuration_keyfile(group_name);
432         if (keyfile == NULL) {
433                 ERR("Fail to __get_configuration_keyfile");
434                 return FALSE;
435         }
436
437         if (g_strcmp0(key, WIFI_CONFIG_PROXY_METHOD) == 0) {
438                 g_key_file_set_string(keyfile, group_name, key, value);
439         } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
440                 g_key_file_set_string(keyfile, group_name, key, value);
441         } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
442                 gboolean hidden = FALSE;
443                 if (g_strcmp0(value, "TRUE") == 0)
444                         hidden = TRUE;
445                 g_key_file_set_boolean(keyfile, group_name, key, hidden);
446         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
447                 g_key_file_set_string(keyfile, group_name, key, value);
448         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
449                 g_key_file_set_string(keyfile, group_name, key, value);
450         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
451                 g_key_file_set_string(keyfile, group_name, key, value);
452         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
453                 g_key_file_set_string(keyfile, group_name, key, value);
454         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
455                 g_key_file_set_string(keyfile, group_name, key, value);
456         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
457                 g_key_file_set_string(keyfile, group_name, key, value);
458         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
459                 g_key_file_set_string(keyfile, group_name, key, value);
460         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
461                 g_key_file_set_string(keyfile, group_name, key, value);
462         } else {
463                 ERR("key[%s] is not supported", key);
464                 ret = FALSE;
465         }
466
467         _save_configuration(config_id, keyfile);
468
469         g_key_file_free(keyfile);
470         g_free(group_name);
471
472         return ret;
473 }
474
475 static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **value)
476 {
477         GKeyFile *keyfile;
478         gchar *group_name;
479         gchar *val = NULL;
480         gboolean hidden = FALSE;
481         gboolean ret = FALSE;
482
483         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
484         if (ret != TRUE) {
485                 ERR("Fail to get_wifi_config_group_name");
486                 return FALSE;
487         }
488         DBG("group_name %s", group_name);
489
490         keyfile = __get_configuration_keyfile(group_name);
491         if (keyfile == NULL) {
492                 ERR("Fail to __get_configuration_keyfile");
493                 return FALSE;
494         }
495
496         if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) {
497                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
498         } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) {
499                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL);
500         } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
501                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
502         } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
503                 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
504                 if (hidden)
505                         val = g_strdup("TRUE");
506                 else
507                         val = g_strdup("FALSE");
508         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
509                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
510         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
511                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
512         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
513                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
514         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
515                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
516         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
517                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
518         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
519                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
520         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
521                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
522         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
523                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
524         } else if (g_strcmp0(key, WIFI_CONFIG_FAILURE) == 0) {
525                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
526         } else {
527                 ERR("Invalid key[%s]", key);
528                 val = g_strdup("NOTSUPPORTED");
529         }
530
531         *value = g_strdup(val);
532         g_free(val);
533
534         g_key_file_free(keyfile);
535         g_free(group_name);
536
537         return TRUE;
538 }
539
540 static GSList *_get_list(void)
541 {
542         GSList *list = NULL;
543         struct dirent ent_struct;
544         struct dirent *dp = NULL;
545         DIR *dir;
546
547         dir = opendir(CONNMAN_STORAGE);
548         if (dir == NULL) {
549                 ERR("Cannot open dir %s", CONNMAN_STORAGE);
550                 return NULL;
551         }
552
553         while ((readdir_r(dir, &ent_struct, &dp) == 0) && dp) {
554                 if (g_strcmp0(dp->d_name, ".") == 0 || g_strcmp0(dp->d_name, "..") == 0 ||
555                                 strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
556                         continue;
557                 }
558                 gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH);
559                 list = g_slist_append(list, g_strdup(config_id));
560                 g_free(config_id);
561         }
562         closedir(dir);
563
564         return list;
565 }
566
567 gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id)
568 {
569         gboolean ret = FALSE;
570         gchar *val = NULL;
571
572         if ((service_profile == NULL) || (config_id == NULL)) {
573                 ERR("Invalid parameter");
574                 return FALSE;
575         }
576
577         ret = __get_config_id(service_profile, &val);
578         *config_id = g_strdup(val);
579         g_free(val);
580
581         return ret;
582 }
583
584 gboolean wifi_config_remove_configuration(const gchar *config_id)
585 {
586         gboolean ret = FALSE;
587
588         ret = _remove_configuration(config_id);
589
590         return ret;
591 }
592
593 /* dbus method */
594 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context)
595 {
596         guint i = 0;
597         GSList *config_ids = NULL;
598         guint length;
599         gchar **result = NULL;
600
601         g_return_val_if_fail(wifi != NULL, FALSE);
602
603         config_ids = _get_list();
604         if (config_ids == NULL) {
605                 netconfig_error_no_profile(context);
606                 ERR("Fail to get config list");
607                 return FALSE;
608         }
609
610         length = g_slist_length(config_ids);
611         result = g_new0(gchar *, length + 1);
612         for (i = 0; i < length; i++) {
613                 gchar *config_id = g_slist_nth_data(config_ids, i);
614                 result[i] = g_strdup(config_id);
615         }
616
617         config_ids = g_slist_nth(config_ids, 0);
618         g_slist_free_full(config_ids, g_free);
619
620         wifi_complete_get_config_ids(wifi, context, (const gchar * const *)result);
621
622         for (i = 0; i < length; i++)
623                 if (result[i])
624                         g_free(result[i]);
625
626         if (result)
627                 g_free(result);
628
629         return TRUE;
630 }
631
632 gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context,
633                 const gchar *config_id)
634 {
635         gboolean ret = FALSE;
636         GVariantBuilder *b = NULL;
637         struct wifi_config *conf = NULL;
638
639         g_return_val_if_fail(wifi != NULL, FALSE);
640
641         conf = g_new0(struct wifi_config, 1);
642
643         ret = _load_configuration(config_id, conf);
644         if (ret != TRUE) {
645                 g_free(conf);
646                 ERR("Fail to _load_configuration");
647                 netconfig_error_no_profile(context);
648                 return FALSE;
649         }
650
651         b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
652         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
653         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
654         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
655
656         if (conf->proxy_address != NULL)
657                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
658         else
659                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
660
661         if (conf->last_error != NULL)
662                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
663         else
664                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
665
666         g_free(conf->proxy_address);
667         g_free(conf->last_error);
668         g_free(conf->name);
669         g_free(conf->security_type);
670         g_free(conf->is_hidden);
671         g_free(conf);
672
673         wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b));
674         g_variant_builder_unref(b);
675         return TRUE;
676 }
677
678 gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
679                 const gchar *config_id, GVariant *configuration)
680 {
681         gboolean ret = FALSE;
682         struct wifi_config *conf = NULL;
683         GKeyFile *keyfile = NULL;
684         GVariantIter *iter;
685         GVariant *value;
686         gchar *field;
687         gchar *group_name = NULL;
688
689         if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
690                 ERR("Invalid parameter");
691                 netconfig_error_invalid_parameter(context);
692                 return FALSE;
693         }
694
695         conf = g_new0(struct wifi_config, 1);
696
697         g_variant_get(configuration, "a{sv}", &iter);
698         while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
699                 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
700                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
701                                 conf->name = g_strdup(g_variant_get_string(value, NULL));
702                                 DBG("name [%s]", conf->name);
703                         } else {
704                                 conf->name = NULL;
705                         }
706                 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
707                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
708                                 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
709                                 DBG("ssid [%s]", conf->ssid);
710                         } else {
711                                 conf->ssid = NULL;
712                         }
713                 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
714                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
715                                 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
716                                 DBG("passphrase []");
717                         } else {
718                                 conf->passphrase = NULL;
719                         }
720                 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
721                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
722                                 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
723                                 DBG("is_hidden [%s]", conf->is_hidden);
724                         } else {
725                                 conf->is_hidden = NULL;
726                         }
727                 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
728                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
729                                 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
730                                 DBG("proxy_address [%s]", conf->proxy_address);
731                         } else {
732                                 conf->proxy_address = NULL;
733                         }
734                 }
735         }
736         conf->favorite = TRUE;
737         conf->autoconnect = TRUE;
738
739         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
740         if (ret != TRUE) {
741                 ERR("Fail to get_wifi_config_group_name");
742                 return FALSE;
743         }
744
745         keyfile = g_key_file_new();
746         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
747         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
748
749         if (conf->passphrase != NULL)
750                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
751
752         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
753         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
754
755         /* Optional field */
756         if (conf->proxy_address != NULL) {
757                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
758                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
759         }
760
761         if (conf->is_hidden != NULL) {
762                 gboolean hidden = FALSE;
763                 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
764                         hidden = TRUE;
765                 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
766         }
767
768         ret = _save_configuration(config_id, keyfile);
769         if (ret == TRUE) {
770                 INFO("Success to save configuration [%s]", config_id);
771                 wifi_complete_save_configuration(wifi, context);
772         } else {
773                 INFO("Fail to save configuration [%s]", config_id);
774                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
775         }
776
777         g_key_file_free(keyfile);
778         g_free(conf->name);
779         g_free(conf->ssid);
780         g_free(conf->passphrase);
781         g_free(conf->is_hidden);
782         g_free(conf->proxy_address);
783         g_free(conf);
784
785         g_variant_iter_free(iter);
786
787         return ret;
788 }
789
790 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
791                 const gchar *config_id)
792 {
793         gboolean ret = FALSE;
794         GVariantBuilder *b = NULL;
795         struct wifi_config *conf = NULL;
796
797         g_return_val_if_fail(wifi != NULL, FALSE);
798
799         conf = g_new0(struct wifi_config, 1);
800         conf->eap_config = g_new0(struct wifi_eap_config, 1);
801
802         ret = _load_configuration(config_id, conf);
803         if (ret != TRUE) {
804                 g_free(conf->eap_config);
805                 g_free(conf);
806                 ERR("Fail to _load_configuration");
807                 netconfig_error_no_profile(context);
808                 return FALSE;
809         }
810
811         b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
812         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
813         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
814         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
815         if (conf->proxy_address != NULL)
816                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
817         else
818                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
819
820         if (conf->last_error != NULL)
821                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
822         else
823                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
824
825         if (conf->eap_config != NULL) {
826                 if (conf->eap_config->anonymous_identity != NULL)
827                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
828                 else
829                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
830
831                 if (conf->eap_config->ca_cert != NULL)
832                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
833                 else
834                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
835
836                 if (conf->eap_config->client_cert != NULL)
837                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
838                 else
839                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
840
841                 if (conf->eap_config->private_key != NULL)
842                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
843                 else
844                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
845
846                 if (conf->eap_config->identity != NULL)
847                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
848                 else
849                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
850
851                 if (conf->eap_config->eap_type != NULL)
852                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
853                 else
854                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
855
856                 if (conf->eap_config->eap_auth_type != NULL)
857                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
858                 else
859                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
860
861                 if (conf->eap_config->subject_match != NULL)
862                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
863                 else
864                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
865         }
866
867         __free_wifi_configuration(conf);
868
869         wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
870         g_variant_builder_unref(b);
871         return TRUE;
872 }
873
874 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
875                 const gchar *config_id, GVariant *configuration)
876 {
877         gboolean ret = FALSE;
878         struct wifi_config *conf = NULL;
879         GKeyFile *keyfile = NULL;
880         GVariantIter *iter;
881         GVariant *value;
882         gchar *field;
883         gchar *group_name = NULL;
884
885         if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
886                 ERR("Invalid parameter");
887                 netconfig_error_invalid_parameter(context);
888                 return FALSE;
889         }
890
891         conf = g_new0(struct wifi_config, 1);
892         conf->eap_config = g_new0(struct wifi_eap_config, 1);
893
894         g_variant_get(configuration, "a{sv}", &iter);
895         while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
896                 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
897                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
898                                 conf->name = g_strdup(g_variant_get_string(value, NULL));
899                                 DBG("name [%s]", conf->name);
900                         } else {
901                                 conf->name = NULL;
902                         }
903                 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
904                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
905                                 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
906                                 DBG("ssid [%s]", conf->ssid);
907                         } else {
908                                 conf->ssid = NULL;
909                         }
910                 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
911                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
912                                 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
913                                 DBG("passphrase [%s]", conf->passphrase);
914                         } else {
915                                 conf->passphrase = NULL;
916                         }
917                 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
918                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
919                                 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
920                                 DBG("is_hidden [%s]", conf->is_hidden);
921                         } else {
922                                 conf->is_hidden = NULL;
923                         }
924                 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
925                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
926                                 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
927                                 DBG("proxy_address [%s]", conf->proxy_address);
928                         } else {
929                                 conf->proxy_address = NULL;
930                         }
931                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
932                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
933                                 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
934                                 DBG("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
935                         } else {
936                                 conf->eap_config->anonymous_identity = NULL;
937                         }
938                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
939                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
940                                 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
941                                 DBG("ca_cert [%s]", conf->eap_config->ca_cert);
942                         } else {
943                                 conf->eap_config->ca_cert = NULL;
944                         }
945                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
946                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
947                                 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
948                                 DBG("client_cert [%s]", conf->eap_config->client_cert);
949                         } else {
950                                 conf->eap_config->client_cert = NULL;
951                         }
952                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
953                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
954                                 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
955                                 DBG("private_key [%s]", conf->eap_config->private_key);
956                         } else {
957                                 conf->eap_config->private_key = NULL;
958                         }
959                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
960                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
961                                 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
962                                 DBG("identity [%s]", conf->eap_config->identity);
963                         } else {
964                                 conf->eap_config->identity = NULL;
965                         }
966                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
967                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
968                                 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
969                                 DBG("eap_type [%s]", conf->eap_config->eap_type);
970                         } else {
971                                 conf->eap_config->eap_type = NULL;
972                         }
973                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
974                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
975                                 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
976                                 DBG("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
977                         } else {
978                                 conf->eap_config->eap_auth_type = NULL;
979                         }
980                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
981                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
982                                 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
983                                 DBG("subject_match [%s]", conf->eap_config->subject_match);
984                         } else {
985                                 conf->eap_config->subject_match = NULL;
986                         }
987                 }
988         }
989         conf->favorite = TRUE;
990         conf->autoconnect = TRUE;
991
992         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
993         if (ret != TRUE) {
994                 __free_wifi_configuration(conf);
995                 ERR("Fail to get_wifi_config_group_name");
996                 return FALSE;
997         }
998
999         keyfile = g_key_file_new();
1000         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1001         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1002
1003         if (conf->passphrase != NULL)
1004                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1005
1006         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1007         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1008
1009         /* Optional field */
1010         if (conf->proxy_address != NULL) {
1011                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1012                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1013         }
1014
1015         if (conf->is_hidden != NULL) {
1016                 gboolean hidden = FALSE;
1017                 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1018                         hidden = TRUE;
1019                 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1020         }
1021
1022         if (conf->eap_config->anonymous_identity != NULL)
1023                 g_key_file_set_string(keyfile, group_name,
1024                         WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, conf->eap_config->anonymous_identity);
1025
1026         if (conf->eap_config->ca_cert != NULL)
1027                 g_key_file_set_string(keyfile, group_name,
1028                         WIFI_CONFIG_EAP_CACERT, conf->eap_config->ca_cert);
1029
1030         if (conf->eap_config->client_cert != NULL)
1031                 g_key_file_set_string(keyfile, group_name,
1032                         WIFI_CONFIG_EAP_CLIENTCERT, conf->eap_config->client_cert);
1033
1034         if (conf->eap_config->private_key != NULL)
1035                 g_key_file_set_string(keyfile, group_name,
1036                         WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
1037
1038         if (conf->eap_config->identity != NULL)
1039                 g_key_file_set_string(keyfile, group_name,
1040                         WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);
1041
1042         if (conf->eap_config->eap_type != NULL)
1043                 g_key_file_set_string(keyfile, group_name,
1044                         WIFI_CONFIG_EAP_TYPE, conf->eap_config->eap_type);
1045
1046         if (conf->eap_config->eap_auth_type != NULL)
1047                 g_key_file_set_string(keyfile, group_name,
1048                         WIFI_CONFIG_EAP_AUTH_TYPE, conf->eap_config->eap_auth_type);
1049
1050         if (conf->eap_config->subject_match != NULL)
1051                 g_key_file_set_string(keyfile, group_name,
1052                         WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match);
1053
1054         ret = _save_configuration(config_id, keyfile);
1055         if (ret == TRUE) {
1056                 INFO("Success to save eap configuration [%s]", config_id);
1057                 wifi_complete_save_eap_configuration(wifi, context);
1058         } else {
1059                 INFO("Fail to save eap configuration [%s]", config_id);
1060                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1061         }
1062
1063         g_key_file_free(keyfile);
1064         __free_wifi_configuration(conf);
1065
1066         g_variant_iter_free(iter);
1067
1068         return ret;
1069 }
1070
1071 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1072 {
1073         gboolean ret = FALSE;
1074
1075         if ((wifi == NULL) || (config_id == NULL)) {
1076                 ERR("Invalid parameter");
1077                 netconfig_error_invalid_parameter(context);
1078                 return FALSE;
1079         }
1080
1081         ret = _remove_configuration(config_id);
1082         if (ret != TRUE) {
1083                 /* no configuration or error */
1084                 ERR("No [%s] configuration", config_id);
1085                 netconfig_error_no_profile(context);
1086                 return FALSE;
1087         }
1088
1089         wifi_complete_remove_configuration(wifi, context);
1090         return ret;
1091 }
1092
1093 /* config field key / value */
1094 /*
1095  * [wifi_macaddress_config_id]
1096  * Name=name (mandatory)
1097  * SSID=SSID (mandatory)
1098  * Frequency=2462 (X)
1099  * Favorite=true (X)
1100  * AutoConnect=true (Default true)
1101  * Modified=2015-03-20 (X)
1102  * IPv4.method=manual (O)
1103  * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1104  * IPv6.method=auto (X)
1105  * IPv6.privacy=disabled (X)
1106  * IPv4.netmask_prefixlen=24 (X)
1107  * IPv4.local_address=192.0.0.1 (O)
1108  * IPv4.gateway=192.0.0.1 (O ? X ?)
1109  * Nameservers=192.168.43.22; (O)
1110  * Proxy.Method=manual (O)
1111  * Proxy.Servers=trst.com:8888; (O)
1112  */
1113 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1114                 const gchar *config_id, const gchar *key, const gchar *value)
1115 {
1116         gboolean ret = FALSE;
1117         gchar *keyfile_key = NULL;
1118
1119         g_return_val_if_fail(wifi != NULL, FALSE);
1120         g_return_val_if_fail(config_id != NULL, FALSE);
1121         g_return_val_if_fail(key != NULL, FALSE);
1122
1123         DBG("Key[%s] Value[%d]", key, value);
1124
1125         if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1126                 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1127                 if (!ret) {
1128                         ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1129                         netconfig_error_invalid_parameter(context);
1130                         return FALSE;
1131                 }
1132                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1133         } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1134                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1135         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1136                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1137         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1138                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1139         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1140                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1141         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1142                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1143         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1144                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1145         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1146                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1147         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1148                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1149         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1150                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1151         } else {
1152                 ERR("Not supported key[%s]", key);
1153                 netconfig_error_invalid_parameter(context);
1154                 return FALSE;
1155         }
1156
1157         ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1158         if (!ret) {
1159                 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1160                 ret = FALSE;
1161         }
1162
1163         if (keyfile_key != NULL)
1164                 g_free(keyfile_key);
1165
1166         wifi_complete_set_config_field(wifi, context);
1167         return ret;
1168 }
1169
1170 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1171 {
1172         gboolean ret = FALSE;
1173         gchar *passphrase = NULL;
1174
1175         if ((wifi == NULL) || (config_id == NULL)) {
1176                 ERR("Invalid parameter");
1177                 netconfig_error_invalid_parameter(context);
1178                 return FALSE;
1179         }
1180
1181         ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1182         if (!ret) {
1183                 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1184                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1185                 return FALSE;
1186         }
1187
1188         wifi_complete_get_config_passphrase(wifi, context, passphrase);
1189         g_free(passphrase);
1190
1191         return ret;
1192 }