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