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