751c3b534c7704fd34d6cae69be7bf406b54e649
[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[i]) {
143                 if (tmp[i] != ':') {
144                         mac[j++] = tmp[i];
145                 }
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                 g_free(path);
221         }
222
223         return keyfile;
224 }
225
226 static gboolean __remove_file(const gchar *pathname, const gchar *filename)
227 {
228         gboolean ret = FALSE;
229         gchar *path;
230
231         path = g_strdup_printf("%s/%s", pathname, filename);
232         if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) {
233                 ret = TRUE;
234         } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) {
235                 unlink(path);
236                 ret = TRUE;
237         }
238
239         g_free(path);
240         return ret;
241 }
242
243 static gboolean __remove_configuration(const gchar *pathname)
244 {
245         int ret = 0;
246
247         if (__remove_file(pathname, "settings") != TRUE) {
248                 ERR("Cannot remove [%s/settings]", pathname);
249                 return FALSE;
250         }
251         if (__remove_file(pathname, "data") != TRUE) {
252                 ERR("Cannot remove [%s/data]", pathname);
253                 return FALSE;
254         }
255
256         ret = rmdir(pathname);
257         if (ret == -1) {
258                 ERR("Cannot remove [%s]", pathname);
259                 return FALSE;
260         }
261
262         return TRUE;
263 }
264
265 static gboolean _load_configuration(const gchar *config_id, struct wifi_config *config)
266 {
267         GKeyFile *keyfile;
268         gchar *group_name;
269         gboolean hidden = FALSE;
270         gboolean ret = FALSE;
271
272         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
273         if (ret != TRUE) {
274                 ERR("Fail to get_wifi_config_group_name");
275                 return FALSE;
276         }
277
278         keyfile = __get_configuration_keyfile(group_name);
279         if (keyfile == NULL) {
280                 ERR("Fail to __get_configuration_keyfile[%s]", group_name);
281                 g_free(group_name);
282                 return FALSE;
283         }
284
285         config->name = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
286         ret = __get_security_type(config_id, &config->security_type);
287         if (ret != TRUE) {
288                 ERR("Fail to _get_security_type");
289                 g_key_file_free(keyfile);
290                 g_free(group_name);
291                 return FALSE;
292         }
293         config->proxy_address = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
294         hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
295         if (hidden) {
296                 config->is_hidden = g_strdup("TRUE");
297         } else {
298                 config->is_hidden = g_strdup("FALSE");
299         }
300
301         if (g_strcmp0(config->security_type, WIFI_SECURITY_EAP) == 0) {
302                 config->eap_config->anonymous_identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
303                 config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
304                 config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
305                 config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
306                 config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
307                 config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
308                 config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
309                 config->eap_config->subject_match = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
310         }
311
312         config->last_error = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
313
314         g_key_file_free(keyfile);
315         g_free(group_name);
316
317         return TRUE;
318 }
319
320 static gboolean _save_configuration(const gchar *config_id, GKeyFile *keyfile)
321 {
322         gchar *dir;
323         gchar *path;
324         gchar *group_name;
325         gboolean ret = FALSE;
326
327         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
328         if (ret != TRUE) {
329                 ERR("Fail to get_wifi_config_group_name");
330                 return FALSE;
331         }
332
333         dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
334         if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
335                 if (__remove_configuration(dir) != TRUE) {
336                         ERR("[%s] is existed, but cannot remove", dir);
337                         g_free(group_name);
338                         g_free(dir);
339                         return FALSE;
340                 }
341         }
342
343         if (mkdir(dir, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) < 0) {
344                 ERR("Cannot mkdir %s", dir);
345                 g_free(group_name);
346                 g_free(dir);
347                 return FALSE;
348         }
349
350         path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
351         netconfig_keyfile_save(keyfile, path);
352         g_free(group_name);
353         g_free(dir);
354         g_free(path);
355
356         return TRUE;
357 }
358
359 static gboolean _remove_configuration(const gchar *config_id)
360 {
361         gboolean ret = FALSE;
362         gchar *dir;
363         gchar *group_name;
364
365         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
366         if (ret != TRUE) {
367                 ERR("Fail to get_wifi_config_group_name");
368                 return FALSE;
369         }
370
371         dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
372         if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
373                 if (__remove_configuration(dir) != TRUE) {
374                         ERR("[%s] is existed, but cannot remove", dir);
375                         ret = FALSE;
376                 }
377                 INFO("Success to remove [%s]", dir);
378                 ret = TRUE;
379         } else {
380                 ERR("[%s] is not existed", dir);
381                 ret = FALSE;
382         }
383
384         g_free(group_name);
385         g_free(dir);
386
387         return ret;
388 }
389
390
391 static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar *value)
392 {
393         gboolean ret = TRUE;
394         GKeyFile *keyfile;
395         gchar *group_name;
396
397         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
398         if (ret != TRUE) {
399                 ERR("Fail to get_wifi_config_group_name");
400                 return FALSE;
401         }
402         DBG("group_name %s", group_name);
403
404         keyfile = __get_configuration_keyfile(group_name);
405         if (keyfile == NULL) {
406                 ERR("Fail to __get_configuration_keyfile");
407                 return FALSE;
408         }
409
410         if (g_strcmp0(key, WIFI_CONFIG_PROXY_METHOD) == 0) {
411                 g_key_file_set_string(keyfile, group_name, key, value);
412         }else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
413                 g_key_file_set_string(keyfile, group_name, key, value);
414         } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
415                 gboolean hidden = FALSE;
416                 if (g_strcmp0(value, "TRUE") == 0) {
417                         hidden = TRUE;
418                 }
419                 g_key_file_set_boolean(keyfile, group_name, key, hidden);
420         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
421                 g_key_file_set_string(keyfile, group_name, key, value);
422         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
423                 g_key_file_set_string(keyfile, group_name, key, value);
424         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
425                 g_key_file_set_string(keyfile, group_name, key, value);
426         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
427                 g_key_file_set_string(keyfile, group_name, key, value);
428         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
429                 g_key_file_set_string(keyfile, group_name, key, value);
430         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
431                 g_key_file_set_string(keyfile, group_name, key, value);
432         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
433                 g_key_file_set_string(keyfile, group_name, key, value);
434         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
435                 g_key_file_set_string(keyfile, group_name, key, value);
436         } else {
437                 ERR("key[%s] is not supported", key);
438                 ret = FALSE;
439         }
440
441         _save_configuration(config_id, keyfile);
442
443         g_key_file_free(keyfile);
444         g_free(group_name);
445
446         return ret;
447 }
448
449 static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **value)
450 {
451         GKeyFile *keyfile;
452         gchar *group_name;
453         gchar *val = NULL;
454         gboolean hidden = FALSE;
455         gboolean ret = FALSE;
456
457         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
458         if (ret != TRUE) {
459                 ERR("Fail to get_wifi_config_group_name");
460                 return FALSE;
461         }
462         DBG("group_name %s", group_name);
463
464         keyfile = __get_configuration_keyfile(group_name);
465         if (keyfile == NULL) {
466                 ERR("Fail to __get_configuration_keyfile");
467                 return FALSE;
468         }
469
470         if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) {
471                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
472         } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) {
473                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL);
474         } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
475                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
476         } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
477                 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
478                 if (hidden) {
479                         val = g_strdup("TRUE");
480                 } else {
481                         val = g_strdup("FALSE");
482                 }
483         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
484                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
485         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
486                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
487         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
488                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
489         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
490                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
491         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
492                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
493         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
494                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
495         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
496                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
497         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
498                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
499         } else if (g_strcmp0(key, WIFI_CONFIG_FAILURE) == 0) {
500                 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
501         } else {
502                 ERR("Invalid key[%s]", key);
503                 val = g_strdup("NOTSUPPORTED");
504         }
505
506         *value = g_strdup(val);
507         g_free(val);
508
509         g_key_file_free(keyfile);
510         g_free(group_name);
511
512         return TRUE;
513 }
514
515 static GSList *_get_list(void)
516 {
517         GSList *list = NULL;
518         struct dirent ent_struct;
519         struct dirent *dp = NULL;
520         DIR *dir;
521
522         dir = opendir(CONNMAN_STORAGE);
523         if (dir == NULL) {
524                 ERR("Cannot open dir %s", CONNMAN_STORAGE);
525                 return NULL;
526         }
527
528         while ((readdir_r(dir, &ent_struct, &dp) == 0) && dp) {
529                 if (g_strcmp0(dp->d_name, ".") == 0 || g_strcmp0(dp->d_name, "..") == 0 ||
530                                 strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
531                         continue;
532                 }
533                 gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH);
534                 list = g_slist_append(list, g_strdup(config_id));
535                 g_free(config_id);
536         }
537         closedir(dir);
538
539         return list;
540 }
541
542 gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id)
543 {
544         gboolean ret = FALSE;
545         gchar *val = NULL;
546
547         if ((service_profile == NULL) || (config_id == NULL)) {
548                 ERR("Invalid parameter");
549                 return FALSE;
550         }
551
552         ret = __get_config_id(service_profile, &val);
553         *config_id = g_strdup(val);
554         g_free(val);
555
556         return ret;
557 }
558
559 gboolean wifi_config_remove_configuration(const gchar *config_id)
560 {
561         gboolean ret = FALSE;
562
563         ret = _remove_configuration(config_id);
564
565         return ret;
566 }
567
568 // dbus method
569 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context)
570 {
571         guint i = 0;
572         GSList *config_ids = NULL;
573         guint length;
574         gchar **result = NULL;
575
576         g_return_val_if_fail(wifi != NULL, FALSE);
577
578         config_ids = _get_list();
579         if (config_ids == NULL) {
580                 netconfig_error_no_profile(context);
581                 ERR("Fail to get config list");
582                 return FALSE;
583         }
584
585         length = g_slist_length(config_ids);
586         result = g_new0(gchar *, length + 1);
587         for (i = 0; i < length; i++) {
588                 gchar *config_id = g_slist_nth_data(config_ids, i);
589                 result[i] = g_strdup(config_id);
590         }
591
592         config_ids = g_slist_nth(config_ids, 0);
593         g_slist_free_full(config_ids, g_free);
594
595         wifi_complete_get_config_ids(wifi, context, (const gchar * const*)result);
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                 }
740                 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
741         }
742
743         ret = _save_configuration(config_id, keyfile);
744         if (ret == TRUE) {
745                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Succeed");
746                 wifi_complete_save_configuration(wifi, context);
747         } else {
748                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed");
749                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
750         }
751
752         g_key_file_free(keyfile);
753         g_free(conf->name);
754         g_free(conf->ssid);
755         g_free(conf->passphrase);
756         g_free(conf->is_hidden);
757         g_free(conf->proxy_address);
758         g_free(conf);
759
760         g_variant_iter_free(iter);
761
762         return ret;
763 }
764
765 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
766                 const gchar *config_id)
767 {
768         gboolean ret = FALSE;
769         GVariantBuilder *b = NULL;
770         struct wifi_config *conf = NULL;
771
772         g_return_val_if_fail(wifi != NULL, FALSE);
773
774         conf = g_new0(struct wifi_config, 1);
775         conf->eap_config = g_new0(struct wifi_eap_config, 1);
776
777         ret = _load_configuration(config_id, conf);
778         if (ret != TRUE) {
779                 g_free(conf->eap_config);
780                 g_free(conf);
781                 ERR("Fail to _load_configuration");
782                 netconfig_error_no_profile(context);
783                 return FALSE;
784         }
785
786         b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
787         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
788         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
789         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
790         if (conf->proxy_address != NULL) {
791                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
792                 g_free(conf->proxy_address);
793         } else {
794                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
795         }
796         if (conf->last_error != NULL) {
797                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
798                 g_free(conf->last_error);
799         } else {
800                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
801         }
802         if (conf->eap_config != NULL) {
803                 if (conf->eap_config->anonymous_identity != NULL) {
804                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
805                 } else {
806                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
807                 }
808                 if (conf->eap_config->ca_cert != NULL) {
809                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
810                 } else {
811                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
812                 }
813                 if (conf->eap_config->client_cert != NULL) {
814                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
815                 } else {
816                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
817                 }
818                 if (conf->eap_config->private_key != NULL) {
819                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
820                 } else {
821                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
822                 }
823                 if (conf->eap_config->identity != NULL) {
824                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
825                 } else {
826                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
827                 }
828                 if (conf->eap_config->eap_type != NULL) {
829                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
830                 } else {
831                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
832                 }
833                 if (conf->eap_config->eap_auth_type != NULL) {
834                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
835                 } else {
836                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
837                 }
838                 if (conf->eap_config->subject_match != NULL) {
839                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
840                 } else {
841                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
842                 }
843         }
844
845         __free_wifi_configuration(conf);
846
847         wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
848         g_variant_builder_unref(b);
849         return TRUE;
850 }
851
852 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
853                 const gchar *config_id, GVariant *configuration)
854 {
855         gboolean ret = FALSE;
856         struct wifi_config *conf = NULL;
857         GKeyFile *keyfile = NULL;
858         GVariantIter *iter;
859         GVariant *value;
860         gchar *field;
861         gchar *group_name = NULL;
862
863         if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
864                 ERR("Invalid parameter");
865                 netconfig_error_invalid_parameter(context);
866                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed");
867                 return FALSE;
868         }
869
870         INFO("save [%s]", config_id);
871
872         conf = g_new0(struct wifi_config, 1);
873         conf->eap_config = g_new0(struct wifi_eap_config, 1);
874
875         g_variant_get(configuration, "a{sv}", &iter);
876         while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
877                 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
878                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
879                                 conf->name = g_strdup(g_variant_get_string(value, NULL));
880                                 ERR("name [%s]", conf->name);
881                         } else {
882                                 conf->name = NULL;
883                         }
884                 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
885                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
886                                 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
887                                 ERR("ssid [%s]", conf->ssid);
888                         } else {
889                                 conf->ssid = NULL;
890                         }
891                 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
892                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
893                                 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
894                                 ERR("passphrase [%s]", conf->passphrase);
895                         } else {
896                                 conf->passphrase = NULL;
897                         }
898                 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
899                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
900                                 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
901                                 ERR("is_hidden [%s]", conf->is_hidden);
902                         } else {
903                                 conf->is_hidden = NULL;
904                         }
905                 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
906                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
907                                 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
908                                 ERR("proxy_address [%s]", conf->proxy_address);
909                         } else {
910                                 conf->proxy_address = NULL;
911                         }
912                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
913                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
914                                 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
915                                 ERR("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
916                         } else {
917                                 conf->eap_config->anonymous_identity = NULL;
918                         }
919                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
920                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
921                                 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
922                                 ERR("ca_cert [%s]", conf->eap_config->ca_cert);
923                         } else {
924                                 conf->eap_config->ca_cert = NULL;
925                         }
926                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
927                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
928                                 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
929                                 ERR("client_cert [%s]", conf->eap_config->client_cert);
930                         } else {
931                                 conf->eap_config->client_cert = NULL;
932                         }
933                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
934                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
935                                 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
936                                 ERR("private_key [%s]", conf->eap_config->private_key);
937                         } else {
938                                 conf->eap_config->private_key = NULL;
939                         }
940                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
941                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
942                                 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
943                                 ERR("identity [%s]", conf->eap_config->identity);
944                         } else {
945                                 conf->eap_config->identity = NULL;
946                         }
947                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
948                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
949                                 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
950                                 ERR("eap_type [%s]", conf->eap_config->eap_type);
951                         } else {
952                                 conf->eap_config->eap_type = NULL;
953                         }
954                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
955                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
956                                 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
957                                 ERR("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
958                         } else {
959                                 conf->eap_config->eap_auth_type = NULL;
960                         }
961                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
962                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
963                                 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
964                                 ERR("subject_match [%s]", conf->eap_config->subject_match);
965                         } else {
966                                 conf->eap_config->subject_match = NULL;
967                         }
968                 }
969         }
970         conf->favorite = TRUE;
971         conf->autoconnect = TRUE;
972
973         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
974         if (ret != TRUE) {
975                 __free_wifi_configuration(conf);
976                 ERR("Fail to get_wifi_config_group_name");
977                 return FALSE;
978         }
979
980         keyfile = g_key_file_new();
981         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
982         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
983
984         if (conf->passphrase != NULL)
985                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
986
987         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
988         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
989
990         // Optional field
991         if (conf->proxy_address != NULL) {
992                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
993                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
994         }
995
996         if (conf->is_hidden != NULL) {
997                 gboolean hidden = FALSE;
998                 if (g_strcmp0(conf->is_hidden, "TRUE") == 0) {
999                         hidden = TRUE;
1000                 }
1001                 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1002         }
1003
1004         ret = _save_configuration(config_id, keyfile);
1005         if (ret == TRUE) {
1006                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Succeed");
1007                 wifi_complete_save_eap_configuration(wifi, context);
1008         } else {
1009                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed");
1010                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1011         }
1012
1013         g_key_file_free(keyfile);
1014         __free_wifi_configuration(conf);
1015
1016         g_variant_iter_free(iter);
1017
1018         return ret;
1019 }
1020
1021 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1022 {
1023         gboolean ret = FALSE;
1024
1025         if ((wifi == NULL) || (config_id == NULL)) {
1026                 ERR("Invalid parameter");
1027                 netconfig_error_invalid_parameter(context);
1028                 return FALSE;
1029         }
1030
1031         ret = _remove_configuration(config_id);
1032         if (ret != TRUE) {
1033                 // no configuration or error
1034                 ERR("No [%s] configuration", config_id);
1035                 netconfig_error_no_profile(context);
1036                 return FALSE;
1037         }
1038
1039         wifi_complete_remove_configuration(wifi, context);
1040         return ret;
1041 }
1042
1043 // config field key / value
1044 /*
1045  * [wifi_macaddress_config_id]
1046  * Name=name (mandatory)
1047  * SSID=SSID (mandatory)
1048  * Frequency=2462 (X)
1049  * Favorite=true (X)
1050  * AutoConnect=true (Default true)
1051  * Modified=2015-03-20 (X)
1052  * IPv4.method=manual (O)
1053  * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1054  * IPv6.method=auto (X)
1055  * IPv6.privacy=disabled (X)
1056  * IPv4.netmask_prefixlen=24 (X)
1057  * IPv4.local_address=192.0.0.1 (O)
1058  * IPv4.gateway=192.0.0.1 (O ? X ?)
1059  * Nameservers=192.168.43.22; (O)
1060  * Proxy.Method=manual (O)
1061  * Proxy.Servers=trst.com:8888; (O)
1062  */
1063 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1064                 const gchar *config_id, const gchar *key, const gchar *value)
1065 {
1066         gboolean ret = FALSE;
1067         gchar *keyfile_key = NULL;
1068
1069         g_return_val_if_fail(wifi != NULL, FALSE);
1070         g_return_val_if_fail(config_id != NULL, FALSE);
1071         g_return_val_if_fail(key != NULL, FALSE);
1072
1073         DBG("Key[%s] Value[%d]", key, value);
1074
1075         if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1076                 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1077                 if (!ret) {
1078                         ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1079                         netconfig_error_invalid_parameter(context);
1080                         return FALSE;
1081                 }
1082                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1083         } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1084                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1085         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1086                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1087         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1088                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1089         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1090                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1091         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1092                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1093         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1094                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1095         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1096                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1097         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1098                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1099         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1100                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1101         } else {
1102                 ERR("Not supported key[%s]", key);
1103                 netconfig_error_invalid_parameter(context);
1104                 return FALSE;
1105         }
1106
1107         ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1108         if (!ret) {
1109                 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1110                 ret = FALSE;
1111         }
1112
1113         if (keyfile_key != NULL)
1114                 g_free(keyfile_key);
1115
1116         wifi_complete_set_config_field(wifi,context);
1117         return ret;
1118 }
1119
1120 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1121 {
1122         gboolean ret = FALSE;
1123         gchar *passphrase = NULL;
1124
1125         if ((wifi == NULL) || (config_id == NULL)) {
1126                 ERR("Invalid parameter");
1127                 netconfig_error_invalid_parameter(context);
1128                 return FALSE;
1129         }
1130
1131         ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1132         if (!ret) {
1133                 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1134                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1135                 return FALSE;
1136         }
1137
1138         wifi_complete_get_config_passphrase(wifi, context, passphrase);
1139         g_free(passphrase);
1140
1141         return ret;
1142 }