Sync with Tizen 2.4(v1.1.38)
[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 *d;
489         DIR *dir;
490
491         dir = opendir(CONNMAN_STORAGE);
492         if (dir == NULL) {
493                 ERR("Cannot open dir %s", CONNMAN_STORAGE);
494                 return NULL;
495         }
496
497         while ((d = readdir(dir))) {
498                 if (g_strcmp0(d->d_name, ".") == 0 || g_strcmp0(d->d_name, "..") == 0 ||
499                                 strncmp(d->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
500                         continue;
501                 }
502                 gchar *config_id = g_strdup(d->d_name + WIFI_PREFIX_LENGTH);
503                 list = g_slist_append(list, g_strdup(config_id));
504                 g_free(config_id);
505         }
506         closedir(dir);
507
508         return list;
509 }
510
511 gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id)
512 {
513         gboolean ret = FALSE;
514         gchar *val = NULL;
515
516         if ((service_profile == NULL) || (config_id == NULL)) {
517                 ERR("Invalid parameter");
518                 return FALSE;
519         }
520
521         ret = __get_config_id(service_profile, &val);
522         *config_id = g_strdup(val);
523         g_free(val);
524
525         return ret;
526 }
527
528 gboolean wifi_config_remove_configuration(const gchar *config_id)
529 {
530         gboolean ret = FALSE;
531
532         ret = _remove_configuration(config_id);
533
534         return ret;
535 }
536
537 // dbus method
538 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context)
539 {
540         guint i = 0;
541         GSList *config_ids = NULL;
542         guint length;
543         gchar **result = NULL;
544
545         g_return_val_if_fail(wifi != NULL, FALSE);
546
547         config_ids = _get_list();
548         if (config_ids == NULL) {
549                 netconfig_error_no_profile(context);
550                 ERR("Fail to get config list");
551                 return FALSE;
552         }
553
554         length = g_slist_length(config_ids);
555         result = g_new0(gchar *, length + 1);
556         for (i = 0; i < length; i++) {
557                 gchar *config_id = g_slist_nth_data(config_ids, i);
558                 result[i] = g_strdup(config_id);
559         }
560
561         config_ids = g_slist_nth(config_ids, 0);
562         g_slist_free_full(config_ids, g_free);
563
564         wifi_complete_get_config_ids(wifi, context, (const gchar * const*)result);
565         return TRUE;
566 }
567
568 gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context,
569                 const gchar *config_id)
570 {
571         gboolean ret = FALSE;
572         GVariantBuilder *b = NULL;
573         struct wifi_config *conf = NULL;
574
575         g_return_val_if_fail(wifi != NULL, FALSE);
576
577         conf = g_new0(struct wifi_config, 1);
578
579         ret = _load_configuration(config_id, conf);
580         if (ret != TRUE) {
581                 g_free(conf);
582                 ERR("Fail to _load_configuration");
583                 netconfig_error_no_profile(context);
584                 return FALSE;
585         }
586
587         b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
588         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
589         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
590         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
591         if (conf->proxy_address != NULL) {
592                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
593                 g_free(conf->proxy_address);
594         } else {
595                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
596         }
597         if (conf->last_error != NULL) {
598                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
599                 g_free(conf->last_error);
600         } else {
601                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
602         }
603
604         g_free(conf->name);
605         g_free(conf->security_type);
606         g_free(conf->is_hidden);
607         g_free(conf);
608
609         wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b));
610         g_variant_builder_unref(b);
611         return TRUE;
612 }
613
614 gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
615                 const gchar *config_id, GVariant *configuration)
616 {
617         gboolean ret = FALSE;
618         struct wifi_config *conf = NULL;
619         GKeyFile *keyfile = NULL;
620         GVariantIter *iter;
621         GVariant *value;
622         gchar *field;
623         gchar *group_name = NULL;
624
625         if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
626                 ERR("Invalid parameter");
627                 netconfig_error_invalid_parameter(context);
628                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed");
629                 return FALSE;
630         }
631
632         ERR("save_configuration [%s]", config_id);
633
634         conf = g_new0(struct wifi_config, 1);
635
636         g_variant_get(configuration, "a{sv}", &iter);
637         while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
638                 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
639                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
640                                 conf->name = g_strdup(g_variant_get_string(value, NULL));
641                                 ERR("name [%s]", conf->name);
642                         } else {
643                                 conf->name = NULL;
644                         }
645                 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
646                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
647                                 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
648                                 ERR("ssid [%s]", conf->ssid);
649                         } else {
650                                 conf->ssid = NULL;
651                         }
652                 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
653                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
654                                 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
655                                 ERR("passphrase []");
656                         } else {
657                                 conf->passphrase = NULL;
658                         }
659                 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
660                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
661                                 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
662                                 ERR("is_hidden [%s]", conf->is_hidden);
663                         } else {
664                                 conf->is_hidden = NULL;
665                         }
666                 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
667                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
668                                 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
669                                 ERR("proxy_address [%s]", conf->proxy_address);
670                         } else {
671                                 conf->proxy_address = NULL;
672                         }
673                 }
674         }
675         conf->favorite = TRUE;
676         conf->autoconnect = TRUE;
677
678         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
679         if (ret != TRUE) {
680                 ERR("Fail to get_wifi_config_group_name");
681                 return FALSE;
682         }
683
684         keyfile = g_key_file_new();
685         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
686         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
687
688         if (conf->passphrase != NULL)
689                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
690
691         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
692         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
693
694         // Optional field
695         if (conf->proxy_address != NULL) {
696                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
697                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
698         }
699
700         if (conf->is_hidden != NULL) {
701                 gboolean hidden = FALSE;
702                 if (g_strcmp0(conf->is_hidden, "TRUE") == 0) {
703                         hidden = TRUE;
704                 }
705                 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
706         }
707
708         ret = _save_configuration(config_id, keyfile);
709         if (ret == TRUE) {
710                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Succeed");
711                 wifi_complete_save_configuration(wifi, context);
712         } else {
713                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed");
714                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
715         }
716
717         g_key_file_free(keyfile);
718         g_free(conf->name);
719         g_free(conf->ssid);
720         g_free(conf->passphrase);
721         g_free(conf->is_hidden);
722         g_free(conf->proxy_address);
723         g_free(conf);
724
725         g_variant_iter_free(iter);
726
727         return ret;
728 }
729
730 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
731                 const gchar *config_id)
732 {
733         gboolean ret = FALSE;
734         GVariantBuilder *b = NULL;
735         struct wifi_config *conf = NULL;
736
737         g_return_val_if_fail(wifi != NULL, FALSE);
738
739         conf = g_new0(struct wifi_config, 1);
740         conf->eap_config = g_new0(struct wifi_eap_config, 1);
741
742         ret = _load_configuration(config_id, conf);
743         if (ret != TRUE) {
744                 g_free(conf->eap_config);
745                 g_free(conf);
746                 ERR("Fail to _load_configuration");
747                 netconfig_error_no_profile(context);
748                 return FALSE;
749         }
750
751         b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
752         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
753         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
754         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
755         if (conf->proxy_address != NULL) {
756                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
757                 g_free(conf->proxy_address);
758         } else {
759                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
760         }
761         if (conf->last_error != NULL) {
762                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
763                 g_free(conf->last_error);
764         } else {
765                 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
766         }
767         if (conf->eap_config != NULL) {
768                 if (conf->eap_config->anonymous_identity != NULL) {
769                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
770                 } else {
771                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
772                 }
773                 if (conf->eap_config->ca_cert != NULL) {
774                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
775                 } else {
776                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
777                 }
778                 if (conf->eap_config->client_cert != NULL) {
779                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
780                 } else {
781                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
782                 }
783                 if (conf->eap_config->private_key != NULL) {
784                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
785                 } else {
786                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
787                 }
788                 if (conf->eap_config->identity != NULL) {
789                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
790                 } else {
791                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
792                 }
793                 if (conf->eap_config->eap_type != NULL) {
794                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
795                 } else {
796                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
797                 }
798                 if (conf->eap_config->eap_auth_type != NULL) {
799                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
800                 } else {
801                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
802                 }
803                 if (conf->eap_config->subject_match != NULL) {
804                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
805                 } else {
806                         g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
807                 }
808         }
809
810         __free_wifi_configuration(conf);
811
812         wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
813         g_variant_builder_unref(b);
814         return TRUE;
815 }
816
817 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
818                 const gchar *config_id, GVariant *configuration)
819 {
820         gboolean ret = FALSE;
821         struct wifi_config *conf = NULL;
822         GKeyFile *keyfile = NULL;
823         GVariantIter *iter;
824         GVariant *value;
825         gchar *field;
826         gchar *group_name = NULL;
827
828         if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
829                 ERR("Invalid parameter");
830                 netconfig_error_invalid_parameter(context);
831                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed");
832                 return FALSE;
833         }
834
835         INFO("save [%s]", config_id);
836
837         conf = g_new0(struct wifi_config, 1);
838         conf->eap_config = g_new0(struct wifi_eap_config, 1);
839
840         g_variant_get(configuration, "a{sv}", &iter);
841         while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
842                 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
843                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
844                                 conf->name = g_strdup(g_variant_get_string(value, NULL));
845                                 ERR("name [%s]", conf->name);
846                         } else {
847                                 conf->name = NULL;
848                         }
849                 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
850                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
851                                 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
852                                 ERR("ssid [%s]", conf->ssid);
853                         } else {
854                                 conf->ssid = NULL;
855                         }
856                 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
857                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
858                                 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
859                                 ERR("passphrase [%s]", conf->passphrase);
860                         } else {
861                                 conf->passphrase = NULL;
862                         }
863                 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
864                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
865                                 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
866                                 ERR("is_hidden [%s]", conf->is_hidden);
867                         } else {
868                                 conf->is_hidden = NULL;
869                         }
870                 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
871                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
872                                 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
873                                 ERR("proxy_address [%s]", conf->proxy_address);
874                         } else {
875                                 conf->proxy_address = NULL;
876                         }
877                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
878                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
879                                 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
880                                 ERR("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
881                         } else {
882                                 conf->eap_config->anonymous_identity = NULL;
883                         }
884                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
885                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
886                                 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
887                                 ERR("ca_cert [%s]", conf->eap_config->ca_cert);
888                         } else {
889                                 conf->eap_config->ca_cert = NULL;
890                         }
891                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
892                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
893                                 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
894                                 ERR("client_cert [%s]", conf->eap_config->client_cert);
895                         } else {
896                                 conf->eap_config->client_cert = NULL;
897                         }
898                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
899                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
900                                 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
901                                 ERR("private_key [%s]", conf->eap_config->private_key);
902                         } else {
903                                 conf->eap_config->private_key = NULL;
904                         }
905                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
906                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
907                                 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
908                                 ERR("identity [%s]", conf->eap_config->identity);
909                         } else {
910                                 conf->eap_config->identity = NULL;
911                         }
912                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
913                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
914                                 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
915                                 ERR("eap_type [%s]", conf->eap_config->eap_type);
916                         } else {
917                                 conf->eap_config->eap_type = NULL;
918                         }
919                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
920                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
921                                 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
922                                 ERR("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
923                         } else {
924                                 conf->eap_config->eap_auth_type = NULL;
925                         }
926                 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
927                         if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
928                                 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
929                                 ERR("subject_match [%s]", conf->eap_config->subject_match);
930                         } else {
931                                 conf->eap_config->subject_match = NULL;
932                         }
933                 }
934         }
935         conf->favorite = TRUE;
936         conf->autoconnect = TRUE;
937
938         ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
939         if (ret != TRUE) {
940                 __free_wifi_configuration(conf);
941                 ERR("Fail to get_wifi_config_group_name");
942                 return FALSE;
943         }
944
945         keyfile = g_key_file_new();
946         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
947         g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
948
949         if (conf->passphrase != NULL)
950                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
951
952         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
953         g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
954
955         // Optional field
956         if (conf->proxy_address != NULL) {
957                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
958                 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
959         }
960
961         if (conf->is_hidden != NULL) {
962                 gboolean hidden = FALSE;
963                 if (g_strcmp0(conf->is_hidden, "TRUE") == 0) {
964                         hidden = TRUE;
965                 }
966                 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
967         }
968
969         ret = _save_configuration(config_id, keyfile);
970         if (ret == TRUE) {
971                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Succeed");
972                 wifi_complete_save_eap_configuration(wifi, context);
973         } else {
974                 SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed");
975                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
976         }
977
978         g_key_file_free(keyfile);
979         __free_wifi_configuration(conf);
980
981         g_variant_iter_free(iter);
982
983         return ret;
984 }
985
986 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
987 {
988         gboolean ret = FALSE;
989
990         if ((wifi == NULL) || (config_id == NULL)) {
991                 ERR("Invalid parameter");
992                 netconfig_error_invalid_parameter(context);
993                 return FALSE;
994         }
995
996         ret = _remove_configuration(config_id);
997         if (ret != TRUE) {
998                 // no configuration or error
999                 ERR("No [%s] configuration", config_id);
1000                 netconfig_error_no_profile(context);
1001                 return FALSE;
1002         }
1003
1004         wifi_complete_remove_configuration(wifi, context);
1005         return ret;
1006 }
1007
1008 // config field key / value
1009 /*
1010  * [wifi_macaddress_config_id]
1011  * Name=name (mandatory)
1012  * SSID=SSID (mandatory)
1013  * Frequency=2462 (X)
1014  * Favorite=true (X)
1015  * AutoConnect=true (Default true)
1016  * Modified=2015-03-20 (X)
1017  * IPv4.method=manual (O)
1018  * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1019  * IPv6.method=auto (X)
1020  * IPv6.privacy=disabled (X)
1021  * IPv4.netmask_prefixlen=24 (X)
1022  * IPv4.local_address=192.0.0.1 (O)
1023  * IPv4.gateway=192.0.0.1 (O ? X ?)
1024  * Nameservers=192.168.43.22; (O)
1025  * Proxy.Method=manual (O)
1026  * Proxy.Servers=trst.com:8888; (O)
1027  */
1028 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1029                 const gchar *config_id, const gchar *key, const gchar *value)
1030 {
1031         gboolean ret = FALSE;
1032         gchar *keyfile_key = NULL;
1033
1034         g_return_val_if_fail(wifi != NULL, FALSE);
1035         g_return_val_if_fail(config_id != NULL, FALSE);
1036         g_return_val_if_fail(key != NULL, FALSE);
1037
1038         DBG("Key[%s] Value[%d]", key, value);
1039
1040         if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1041                 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1042                 if (!ret) {
1043                         ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1044                         netconfig_error_invalid_parameter(context);
1045                         return FALSE;
1046                 }
1047                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1048         } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1049                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1050         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1051                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1052         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1053                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1054         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1055                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1056         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1057                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1058         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1059                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1060         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1061                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1062         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1063                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1064         } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1065                 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1066         } else {
1067                 ERR("Not supported key[%s]", key);
1068                 netconfig_error_invalid_parameter(context);
1069                 return FALSE;
1070         }
1071
1072         ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1073         if (!ret) {
1074                 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1075                 ret = FALSE;
1076         }
1077
1078         if (keyfile_key != NULL)
1079                 g_free(keyfile_key);
1080
1081         wifi_complete_set_config_field(wifi,context);
1082         return ret;
1083 }
1084
1085 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1086 {
1087         gboolean ret = FALSE;
1088         gchar *passphrase = NULL;
1089
1090         if ((wifi == NULL) || (config_id == NULL)) {
1091                 ERR("Invalid parameter");
1092                 netconfig_error_invalid_parameter(context);
1093                 return FALSE;
1094         }
1095
1096         ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1097         if (!ret) {
1098                 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1099                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1100                 return FALSE;
1101         }
1102
1103         wifi_complete_get_config_passphrase(wifi, context, passphrase);
1104         g_free(passphrase);
1105
1106         return ret;
1107 }