2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <sys/types.h>
34 #include "wifi-config.h"
35 #include "netsupplicant.h"
37 #define CONNMAN_STORAGE "/var/lib/connman"
39 #define WIFI_SECURITY_NONE "none"
40 #define WIFI_SECURITY_WEP "wep"
41 #define WIFI_SECURITY_WPA_PSK "psk"
42 #define WIFI_SECURITY_EAP "ieee8021x"
44 #define WIFI_CONFIG_PREFIX "wifi_"
45 #define MAC_ADDRESS_LENGTH 12
46 #define WIFI_PREFIX_LENGTH MAC_ADDRESS_LENGTH + 6 /* wifi_485a3f2f506a_ */
47 #define PROFILE_PREFIX_LENGTH WIFI_PREFIX_LENGTH + 21 /* /net/connman/service/wifi_485a3f2f506a_ */
49 #define WIFI_MAC_ADD_LENGTH 17
50 #define WIFI_MAC_ADD_PATH "/sys/class/net/wlan0/address"
52 struct wifi_eap_config {
53 gchar *anonymous_identity;
72 struct wifi_eap_config *eap_config;
76 static void __free_wifi_configuration(struct wifi_config *conf)
83 g_free(conf->passphrase);
84 g_free(conf->security_type);
85 g_free(conf->is_hidden);
86 g_free(conf->proxy_address);
87 g_free(conf->last_error);
88 if (conf->eap_config) {
89 g_free(conf->eap_config->anonymous_identity);
90 g_free(conf->eap_config->ca_cert);
91 g_free(conf->eap_config->client_cert);
92 g_free(conf->eap_config->private_key);
93 g_free(conf->eap_config->identity);
94 g_free(conf->eap_config->eap_type);
95 g_free(conf->eap_config->eap_auth_type);
96 g_free(conf->eap_config->subject_match);
97 g_free(conf->eap_config);
102 static gboolean __get_mac_address(gchar **mac_address)
104 gchar *tmp_mac = NULL;
106 gchar mac[13] = { 0, };
111 char buf[WIFI_MAC_ADD_LENGTH + 1];
112 if (0 == access(WIFI_MAC_ADD_PATH, F_OK))
113 fp = fopen(WIFI_MAC_ADD_PATH, "r");
116 ERR("Failed to open file %s\n", WIFI_MAC_ADD_PATH);
121 if (fgets(buf, sizeof(buf), fp) == NULL) {
122 ERR("Failed to get MAC info from %s\n", WIFI_MAC_ADD_PATH);
127 tmp_mac = (gchar *)malloc(WIFI_MAC_ADD_LENGTH + 1);
128 if (tmp_mac == NULL) {
129 ERR("malloc() failed");
134 memset(tmp_mac, 0, WIFI_MAC_ADD_LENGTH + 1);
135 g_strlcpy(tmp_mac, buf, WIFI_MAC_ADD_LENGTH + 1);
138 tmp_mac = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
139 if (tmp_mac == NULL) {
140 ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed");
145 tmp = g_ascii_strdown(tmp_mac, (gssize)strlen(tmp_mac));
147 while (tmp && tmp[i]) {
153 *mac_address = g_strdup(mac);
158 static gboolean __get_group_name(const gchar *prefix, const gchar *config_id, gchar **group_name)
160 gchar *mac_address = NULL;
161 gchar *g_name = NULL;
162 gboolean ret = FALSE;
164 ret = __get_mac_address(&mac_address);
165 if ((ret != TRUE) || (strlen(mac_address) == 0)) {
166 ERR("Cannot get WIFI MAC address");
170 g_name = g_strdup_printf("%s%s_%s", prefix, mac_address, config_id);
171 if (g_name == NULL) {
176 *group_name = g_strdup(g_name);
184 static gboolean __get_security_type(const gchar *config_id, gchar **type)
186 if (g_str_has_suffix(config_id, WIFI_SECURITY_NONE) == TRUE) {
187 *type = g_strdup(WIFI_SECURITY_NONE);
188 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WEP) == TRUE) {
189 *type = g_strdup(WIFI_SECURITY_WEP);
190 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WPA_PSK) == TRUE) {
191 *type = g_strdup(WIFI_SECURITY_WPA_PSK);
192 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_EAP) == TRUE) {
193 *type = g_strdup(WIFI_SECURITY_EAP);
202 static gboolean __get_config_id(const gchar *profile, gchar **config_id)
204 *config_id = g_strdup(profile + PROFILE_PREFIX_LENGTH);
205 if (*config_id == NULL) {
214 static GKeyFile *__get_configuration_keyfile(const gchar *group_name)
216 GKeyFile *keyfile = NULL;
219 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
221 keyfile = netconfig_keyfile_load(path);
223 ERR("keyfile[%s] is NULL", path);
230 static gboolean __remove_file(const gchar *pathname, const gchar *filename)
232 gboolean ret = FALSE;
235 path = g_strdup_printf("%s/%s", pathname, filename);
236 if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) {
238 } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) {
247 static gboolean __remove_configuration(const gchar *pathname)
251 if (__remove_file(pathname, "settings") != TRUE) {
252 ERR("Cannot remove [%s/settings]", pathname);
255 if (__remove_file(pathname, "data") != TRUE) {
256 ERR("Cannot remove [%s/data]", pathname);
260 ret = rmdir(pathname);
262 ERR("Cannot remove [%s]", pathname);
269 static gboolean _load_configuration(const gchar *config_id, struct wifi_config *config)
273 gboolean hidden = FALSE;
274 gboolean ret = FALSE;
276 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
278 ERR("Fail to get_wifi_config_group_name");
282 keyfile = __get_configuration_keyfile(group_name);
283 if (keyfile == NULL) {
284 ERR("Fail to __get_configuration_keyfile[%s]", group_name);
289 config->name = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
290 DBG("name [%s]", config->name);
292 __get_security_type(config_id, &config->security_type);
293 if (config->security_type == NULL) {
294 ERR("Fail to _get_security_type");
295 g_key_file_free(keyfile);
299 DBG("security_type [%s]", config->security_type);
301 config->proxy_address = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
302 if (config->proxy_address)
303 DBG("proxy_address [%s]", config->proxy_address);
305 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
307 config->is_hidden = g_strdup("TRUE");
309 config->is_hidden = g_strdup("FALSE");
310 DBG("is_hidden [%s]", config->is_hidden);
312 if (g_strcmp0(config->security_type, WIFI_SECURITY_EAP) == 0) {
313 config->eap_config->anonymous_identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
314 config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
315 config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
316 config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
317 config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
318 config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
319 config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
320 config->eap_config->subject_match = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
322 if (config->eap_config->anonymous_identity)
323 DBG("anonymous_identity [%s]", config->eap_config->anonymous_identity);
324 if (config->eap_config->ca_cert)
325 DBG("ca_cert [%s]", config->eap_config->ca_cert);
326 if (config->eap_config->client_cert)
327 DBG("client_cert [%s]", config->eap_config->client_cert);
328 if (config->eap_config->private_key)
329 DBG("private_key [%s]", config->eap_config->private_key);
330 if (config->eap_config->identity)
331 DBG("identity [%s]", config->eap_config->identity);
332 if (config->eap_config->eap_type)
333 DBG("eap_type [%s]", config->eap_config->eap_type);
334 if (config->eap_config->eap_auth_type)
335 DBG("eap_auth_type [%s]", config->eap_config->eap_auth_type);
336 if (config->eap_config->subject_match)
337 DBG("subject_match [%s]", config->eap_config->subject_match);
340 config->last_error = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
341 if (config->last_error)
342 DBG("last_error [%s]", config->last_error);
344 g_key_file_free(keyfile);
350 static gboolean _save_configuration(const gchar *config_id, GKeyFile *keyfile)
355 gboolean ret = FALSE;
357 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
359 ERR("Fail to get_wifi_config_group_name");
363 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
364 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
365 if (__remove_configuration(dir) != TRUE) {
366 ERR("[%s] is existed, but cannot remove", dir);
373 if (mkdir(dir, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) < 0) {
374 ERR("Cannot mkdir %s", dir);
380 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
381 netconfig_keyfile_save(keyfile, path);
389 static gboolean _remove_configuration(const gchar *config_id)
391 gboolean ret = FALSE;
395 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
397 ERR("Fail to get_wifi_config_group_name");
401 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
402 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
403 if (__remove_configuration(dir) != TRUE) {
404 ERR("[%s] is existed, but cannot remove", dir);
407 INFO("Success to remove [%s]", dir);
410 ERR("[%s] is not existed", dir);
421 static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar *value)
427 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
429 ERR("Fail to get_wifi_config_group_name");
432 DBG("group_name %s", group_name);
434 keyfile = __get_configuration_keyfile(group_name);
435 if (keyfile == NULL) {
436 ERR("Fail to __get_configuration_keyfile");
441 if (g_strcmp0(key, WIFI_CONFIG_PROXY_METHOD) == 0) {
442 g_key_file_set_string(keyfile, group_name, key, value);
443 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
444 g_key_file_set_string(keyfile, group_name, key, value);
445 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
446 gboolean hidden = FALSE;
447 if (g_strcmp0(value, "TRUE") == 0)
449 g_key_file_set_boolean(keyfile, group_name, key, hidden);
450 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
451 g_key_file_set_string(keyfile, group_name, key, value);
452 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
453 g_key_file_set_string(keyfile, group_name, key, value);
454 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
455 g_key_file_set_string(keyfile, group_name, key, value);
456 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
457 g_key_file_set_string(keyfile, group_name, key, value);
458 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
459 g_key_file_set_string(keyfile, group_name, key, value);
460 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
461 g_key_file_set_string(keyfile, group_name, key, value);
462 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
463 g_key_file_set_string(keyfile, group_name, key, value);
464 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
465 g_key_file_set_string(keyfile, group_name, key, value);
467 ERR("key[%s] is not supported", key);
471 _save_configuration(config_id, keyfile);
473 g_key_file_free(keyfile);
479 static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **value)
484 gboolean hidden = FALSE;
485 gboolean ret = FALSE;
487 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
489 ERR("Fail to get_wifi_config_group_name");
492 DBG("group_name %s", group_name);
494 keyfile = __get_configuration_keyfile(group_name);
495 if (keyfile == NULL) {
496 ERR("Fail to __get_configuration_keyfile");
501 if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) {
502 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
503 } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) {
504 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL);
505 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
506 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
507 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
508 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
510 val = g_strdup("TRUE");
512 val = g_strdup("FALSE");
513 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
514 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
515 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
516 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
517 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
518 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
519 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
520 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
521 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
522 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
523 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
524 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
525 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
526 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
527 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
528 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
529 } else if (g_strcmp0(key, WIFI_CONFIG_FAILURE) == 0) {
530 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
532 ERR("Invalid key[%s]", key);
533 val = g_strdup("NOTSUPPORTED");
536 *value = g_strdup(val);
539 g_key_file_free(keyfile);
545 static GSList *_get_list(void)
548 struct dirent *dp = NULL;
551 dir = opendir(CONNMAN_STORAGE);
553 ERR("Cannot open dir %s", CONNMAN_STORAGE);
557 while ((dp = readdir(dir)) != NULL) {
558 if (g_strcmp0(dp->d_name, ".") == 0 || g_strcmp0(dp->d_name, "..") == 0 ||
559 strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
562 gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH);
563 list = g_slist_append(list, g_strdup(config_id));
571 gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id)
573 gboolean ret = FALSE;
576 if ((service_profile == NULL) || (config_id == NULL)) {
577 ERR("Invalid parameter");
581 ret = __get_config_id(service_profile, &val);
582 *config_id = g_strdup(val);
588 gboolean wifi_config_remove_configuration(const gchar *config_id)
590 gboolean ret = FALSE;
592 ret = _remove_configuration(config_id);
597 static int __netconfig_hex_char_to_num(char c)
599 if (c >= '0' && c <= '9')
602 if (c >= 'a' && c <= 'f')
605 if (c >= 'A' && c <= 'F')
611 static int __netconfig_hex_to_byte(const char *hex)
615 a = __netconfig_hex_char_to_num(*hex++);
619 b = __netconfig_hex_char_to_num(*hex++);
626 static int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len)
630 const char *ipos = hex;
631 unsigned char *opos = buf;
633 for (i = 0; i < len; i++) {
634 a = __netconfig_hex_to_byte(ipos);
645 static int __netconfig_byte_to_txt(const unsigned char *src, char **dst, int src_len)
652 ERR("Invalid parameter.");
656 *dst = (char *) g_try_malloc0((2*src_len)+1);
658 ERR("failed to allocate memory to buffer.");
664 for (i = 0; i < src_len; i++) {
665 snprintf(buf, 3, "%02x", src[i]);
673 static int __netconfig_unpack_ay_malloc(unsigned char **dst, GVariantIter *iter)
675 GVariantIter *iter_copy = NULL;
678 unsigned char *tmp_dst = NULL;
680 if (!dst || *dst || !iter) {
681 ERR("Invalid parameter");
685 iter_copy = g_variant_iter_copy(iter);
687 while (g_variant_iter_loop(iter, "y", &tmp))
689 g_variant_iter_free(iter);
691 tmp_dst = (unsigned char *)g_try_malloc0(length + 1);
693 ERR("failed to allocate memory");
698 while (g_variant_iter_loop(iter_copy, "y", &tmp_dst[length]))
700 g_variant_iter_free(iter_copy);
706 tmp_dst[length] = '\0';
710 DBG("Length [%d]", length);
714 gboolean _add_vsie(int frame_id, const char* vsie)
716 GVariant *params = NULL;
717 GVariant *message = NULL;
718 GVariantBuilder *bytearray_builder = NULL;
723 unsigned char *bytearray = NULL;
724 size_t bytearray_len = 0;
726 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
727 DBG("Invalid parameter, frame-id: %d", frame_id);
731 vsie_len = strlen(vsie);
733 DBG("vsie length is zero");
737 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
739 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
740 if (bytearray == NULL) {
741 DBG("Failed to allocate memory to bytearray");
745 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
746 DBG("invalid vsie string");
751 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
752 for (i = 0; i < bytearray_len; i++)
753 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
755 params = g_variant_new("(iay)", frame_id, bytearray_builder);
756 g_variant_builder_unref(bytearray_builder);
758 if_path = netconfig_wifi_get_supplicant_interface();
760 if (if_path == NULL) {
761 ERR("Fail to get wpa_supplicant DBus path");
766 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
767 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemAdd", params);
770 if (message == NULL) {
771 ERR("Failed to send command to wpa_supplicant");
776 DBG("Succeeded to add vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
782 gboolean _get_vsie(int frame_id, char **vsie)
784 GVariant *params = NULL;
785 GVariant *message = NULL;
788 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
789 DBG("Invalid parameter, frame-id: %d", frame_id);
793 if_path = netconfig_wifi_get_supplicant_interface();
794 if (if_path == NULL) {
795 ERR("Fail to get wpa_supplicant DBus path");
799 params = g_variant_new("(i)", frame_id);
801 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
802 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemGet", params);
805 if (message == NULL) {
806 ERR("Failed to send command to wpa_supplicant");
809 GVariantIter *iter = NULL;
810 unsigned char *vsie_bytes = NULL;
814 g_variant_get(message, "(ay)", &iter);
816 ERR("vsie is not present");
820 vsie_len = __netconfig_unpack_ay_malloc(&vsie_bytes, iter);
821 if (vsie_bytes == NULL) {
822 ERR("vsie_bytes not allocated");
826 ret = __netconfig_byte_to_txt(vsie_bytes, vsie, vsie_len);
829 ERR("vsie not allocated.");
836 ERR("Succeeded to get vsie: Frame ID[%d], VSIE[%s]", frame_id, *vsie);
842 gboolean _remove_vsie(int frame_id, const char *vsie)
844 GVariant *params = NULL;
845 GVariant *message = NULL;
846 GVariantBuilder *bytearray_builder = NULL;
851 unsigned char *bytearray = NULL;
852 size_t bytearray_len = 0;
854 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
855 DBG("Invalid parameter, frame-id: %d", frame_id);
859 vsie_len = strlen(vsie);
861 DBG("vsie length is zero");
865 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
867 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
868 if (bytearray == NULL) {
869 DBG("Failed to allocate memory to bytearray");
873 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
874 DBG("invalid vsie string");
879 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
880 for (i = 0; i < bytearray_len; i++)
881 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
883 params = g_variant_new("(iay)", frame_id, bytearray_builder);
884 g_variant_builder_unref(bytearray_builder);
886 if_path = netconfig_wifi_get_supplicant_interface();
887 if (if_path == NULL) {
888 ERR("Fail to get wpa_supplicant DBus path");
893 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
894 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemRem", params);
897 if (message == NULL) {
898 ERR("Failed to send command to wpa_supplicant");
903 DBG("Succeeded to remove vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
910 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context)
913 GSList *config_ids = NULL;
915 gchar **result = NULL;
917 g_return_val_if_fail(wifi != NULL, FALSE);
919 config_ids = _get_list();
920 if (config_ids == NULL) {
921 ERR("Fail to get config list");
922 netconfig_error_no_profile(context);
926 length = g_slist_length(config_ids);
927 result = g_new0(gchar *, length + 1);
928 for (i = 0; i < length; i++) {
929 gchar *config_id = g_slist_nth_data(config_ids, i);
930 result[i] = g_strdup(config_id);
933 config_ids = g_slist_nth(config_ids, 0);
934 g_slist_free_full(config_ids, g_free);
936 wifi_complete_get_config_ids(wifi, context, (const gchar * const *)result);
938 for (i = 0; i < length; i++)
948 gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context,
949 const gchar *config_id)
951 gboolean ret = FALSE;
952 GVariantBuilder *b = NULL;
953 struct wifi_config *conf = NULL;
955 g_return_val_if_fail(wifi != NULL, FALSE);
957 conf = g_new0(struct wifi_config, 1);
959 ret = _load_configuration(config_id, conf);
962 ERR("Fail to _load_configuration");
963 netconfig_error_no_profile(context);
967 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
968 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
969 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
970 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
972 if (conf->proxy_address != NULL)
973 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
975 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
977 if (conf->last_error != NULL)
978 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
980 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
982 g_free(conf->proxy_address);
983 g_free(conf->last_error);
985 g_free(conf->security_type);
986 g_free(conf->is_hidden);
989 wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b));
990 g_variant_builder_unref(b);
994 gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
995 const gchar *config_id, GVariant *configuration)
997 gboolean ret = FALSE;
998 struct wifi_config *conf = NULL;
999 GKeyFile *keyfile = NULL;
1003 gchar *group_name = NULL;
1005 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1006 ERR("Invalid parameter");
1007 netconfig_error_invalid_parameter(context);
1011 conf = g_new0(struct wifi_config, 1);
1013 g_variant_get(configuration, "a{sv}", &iter);
1014 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1015 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1016 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1017 conf->name = g_strdup(g_variant_get_string(value, NULL));
1018 DBG("name [%s]", conf->name);
1022 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1023 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1024 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1025 DBG("ssid [%s]", conf->ssid);
1029 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1030 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1031 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1032 DBG("passphrase []");
1034 conf->passphrase = NULL;
1036 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1037 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1038 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1039 DBG("is_hidden [%s]", conf->is_hidden);
1041 conf->is_hidden = NULL;
1043 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1044 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1045 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1046 DBG("proxy_address [%s]", conf->proxy_address);
1048 conf->proxy_address = NULL;
1052 conf->favorite = TRUE;
1053 conf->autoconnect = TRUE;
1055 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1059 g_free(conf->passphrase);
1060 g_free(conf->is_hidden);
1061 g_free(conf->proxy_address);
1063 ERR("Fail to get_wifi_config_group_name");
1067 keyfile = g_key_file_new();
1068 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1069 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1071 if (conf->passphrase != NULL)
1072 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1074 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1075 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1077 /* Optional field */
1078 if (conf->proxy_address != NULL) {
1079 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1080 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1083 if (conf->is_hidden != NULL) {
1084 gboolean hidden = FALSE;
1085 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1087 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1090 ret = _save_configuration(config_id, keyfile);
1092 INFO("Success to save configuration [%s]", config_id);
1093 wifi_complete_save_configuration(wifi, context);
1095 INFO("Fail to save configuration [%s]", config_id);
1096 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
1099 g_key_file_free(keyfile);
1103 g_free(conf->passphrase);
1104 g_free(conf->is_hidden);
1105 g_free(conf->proxy_address);
1108 g_variant_iter_free(iter);
1113 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1114 const gchar *config_id)
1116 gboolean ret = FALSE;
1117 GVariantBuilder *b = NULL;
1118 struct wifi_config *conf = NULL;
1120 g_return_val_if_fail(wifi != NULL, FALSE);
1122 conf = g_new0(struct wifi_config, 1);
1123 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1125 ret = _load_configuration(config_id, conf);
1127 g_free(conf->eap_config);
1129 ERR("Fail to _load_configuration");
1130 netconfig_error_no_profile(context);
1134 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1135 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
1136 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
1137 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
1138 if (conf->proxy_address != NULL)
1139 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
1141 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
1143 if (conf->last_error != NULL)
1144 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
1146 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
1148 if (conf->eap_config != NULL) {
1149 if (conf->eap_config->anonymous_identity != NULL)
1150 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
1152 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
1154 if (conf->eap_config->ca_cert != NULL)
1155 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
1157 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
1159 if (conf->eap_config->client_cert != NULL)
1160 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
1162 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
1164 if (conf->eap_config->private_key != NULL)
1165 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
1167 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
1169 if (conf->eap_config->identity != NULL)
1170 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
1172 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
1174 if (conf->eap_config->eap_type != NULL)
1175 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
1177 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
1179 if (conf->eap_config->eap_auth_type != NULL)
1180 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
1182 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
1184 if (conf->eap_config->subject_match != NULL)
1185 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
1187 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
1190 __free_wifi_configuration(conf);
1192 wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
1193 g_variant_builder_unref(b);
1197 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1198 const gchar *config_id, GVariant *configuration)
1200 gboolean ret = FALSE;
1201 struct wifi_config *conf = NULL;
1202 GKeyFile *keyfile = NULL;
1206 gchar *group_name = NULL;
1208 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1209 ERR("Invalid parameter");
1210 netconfig_error_invalid_parameter(context);
1214 conf = g_new0(struct wifi_config, 1);
1215 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1217 g_variant_get(configuration, "a{sv}", &iter);
1218 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1219 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1220 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1221 conf->name = g_strdup(g_variant_get_string(value, NULL));
1222 DBG("name [%s]", conf->name);
1226 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1227 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1228 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1229 DBG("ssid [%s]", conf->ssid);
1233 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1234 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1235 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1236 DBG("passphrase [%s]", conf->passphrase);
1238 conf->passphrase = NULL;
1240 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1241 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1242 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1243 DBG("is_hidden [%s]", conf->is_hidden);
1245 conf->is_hidden = NULL;
1247 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1248 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1249 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1250 DBG("proxy_address [%s]", conf->proxy_address);
1252 conf->proxy_address = NULL;
1254 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1255 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1256 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
1257 DBG("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
1259 conf->eap_config->anonymous_identity = NULL;
1261 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
1262 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1263 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
1264 DBG("ca_cert [%s]", conf->eap_config->ca_cert);
1266 conf->eap_config->ca_cert = NULL;
1268 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1269 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1270 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
1271 DBG("client_cert [%s]", conf->eap_config->client_cert);
1273 conf->eap_config->client_cert = NULL;
1275 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1276 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1277 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
1278 DBG("private_key [%s]", conf->eap_config->private_key);
1280 conf->eap_config->private_key = NULL;
1282 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1283 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1284 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
1285 DBG("identity [%s]", conf->eap_config->identity);
1287 conf->eap_config->identity = NULL;
1289 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
1290 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1291 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
1292 DBG("eap_type [%s]", conf->eap_config->eap_type);
1294 conf->eap_config->eap_type = NULL;
1296 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1297 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1298 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
1299 DBG("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
1301 conf->eap_config->eap_auth_type = NULL;
1303 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1304 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1305 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
1306 DBG("subject_match [%s]", conf->eap_config->subject_match);
1308 conf->eap_config->subject_match = NULL;
1312 conf->favorite = TRUE;
1313 conf->autoconnect = TRUE;
1315 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1317 __free_wifi_configuration(conf);
1318 ERR("Fail to get_wifi_config_group_name");
1322 keyfile = g_key_file_new();
1323 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1324 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1326 if (conf->passphrase != NULL)
1327 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1329 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1330 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1332 /* Optional field */
1333 if (conf->proxy_address != NULL) {
1334 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1335 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1338 if (conf->is_hidden != NULL) {
1339 gboolean hidden = FALSE;
1340 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1342 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1345 if (conf->eap_config->anonymous_identity != NULL)
1346 g_key_file_set_string(keyfile, group_name,
1347 WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, conf->eap_config->anonymous_identity);
1349 if (conf->eap_config->ca_cert != NULL)
1350 g_key_file_set_string(keyfile, group_name,
1351 WIFI_CONFIG_EAP_CACERT, conf->eap_config->ca_cert);
1353 if (conf->eap_config->client_cert != NULL)
1354 g_key_file_set_string(keyfile, group_name,
1355 WIFI_CONFIG_EAP_CLIENTCERT, conf->eap_config->client_cert);
1357 if (conf->eap_config->private_key != NULL)
1358 g_key_file_set_string(keyfile, group_name,
1359 WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
1361 if (conf->eap_config->identity != NULL)
1362 g_key_file_set_string(keyfile, group_name,
1363 WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);
1365 if (conf->eap_config->eap_type != NULL)
1366 g_key_file_set_string(keyfile, group_name,
1367 WIFI_CONFIG_EAP_TYPE, conf->eap_config->eap_type);
1369 if (conf->eap_config->eap_auth_type != NULL)
1370 g_key_file_set_string(keyfile, group_name,
1371 WIFI_CONFIG_EAP_AUTH_TYPE, conf->eap_config->eap_auth_type);
1373 if (conf->eap_config->subject_match != NULL)
1374 g_key_file_set_string(keyfile, group_name,
1375 WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match);
1377 ret = _save_configuration(config_id, keyfile);
1379 INFO("Success to save eap configuration [%s]", config_id);
1380 wifi_complete_save_eap_configuration(wifi, context);
1382 INFO("Fail to save eap configuration [%s]", config_id);
1383 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1386 g_key_file_free(keyfile);
1388 __free_wifi_configuration(conf);
1390 g_variant_iter_free(iter);
1395 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1397 gboolean ret = FALSE;
1399 if ((wifi == NULL) || (config_id == NULL)) {
1400 ERR("Invalid parameter");
1401 netconfig_error_invalid_parameter(context);
1405 ret = _remove_configuration(config_id);
1407 /* no configuration or error */
1408 ERR("No [%s] configuration", config_id);
1409 netconfig_error_no_profile(context);
1413 wifi_complete_remove_configuration(wifi, context);
1417 /* config field key / value */
1419 * [wifi_macaddress_config_id]
1420 * Name=name (mandatory)
1421 * SSID=SSID (mandatory)
1422 * Frequency=2462 (X)
1424 * AutoConnect=true (Default true)
1425 * Modified=2015-03-20 (X)
1426 * IPv4.method=manual (O)
1427 * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1428 * IPv6.method=auto (X)
1429 * IPv6.privacy=disabled (X)
1430 * IPv4.netmask_prefixlen=24 (X)
1431 * IPv4.local_address=192.0.0.1 (O)
1432 * IPv4.gateway=192.0.0.1 (O ? X ?)
1433 * Nameservers=192.168.43.22; (O)
1434 * Proxy.Method=manual (O)
1435 * Proxy.Servers=trst.com:8888; (O)
1437 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1438 const gchar *config_id, const gchar *key, const gchar *value)
1440 gboolean ret = FALSE;
1441 gchar *keyfile_key = NULL;
1443 g_return_val_if_fail(wifi != NULL, FALSE);
1444 g_return_val_if_fail(config_id != NULL, FALSE);
1445 g_return_val_if_fail(key != NULL, FALSE);
1447 DBG("Key[%s] Value[%d]", key, value);
1449 if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1450 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1452 ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1453 netconfig_error_invalid_parameter(context);
1456 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1457 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1458 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1459 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1460 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1461 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1462 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1463 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1464 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1465 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1466 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1467 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1468 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1469 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1470 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1471 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1472 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1473 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1474 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1476 ERR("Not supported key[%s]", key);
1477 netconfig_error_invalid_parameter(context);
1481 ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1483 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1487 if (keyfile_key != NULL)
1488 g_free(keyfile_key);
1490 wifi_complete_set_config_field(wifi, context);
1494 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1496 gboolean ret = FALSE;
1497 gchar *passphrase = NULL;
1499 if ((wifi == NULL) || (config_id == NULL)) {
1500 ERR("Invalid parameter");
1501 netconfig_error_invalid_parameter(context);
1505 ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1507 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1508 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1512 wifi_complete_get_config_passphrase(wifi, context, passphrase);
1518 gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1519 int frame_id, const gchar *vsie)
1521 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1523 g_return_val_if_fail(wifi != NULL, FALSE);
1524 g_return_val_if_fail(vsie != NULL, FALSE);
1526 gboolean ret = FALSE;
1528 ret = _add_vsie(frame_id, vsie);
1530 DBG("Failed to add vsie: %s", vsie);
1531 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1535 wifi_complete_add_vsie(wifi, context);
1539 gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1542 DBG("Frame ID: [%d]", frame_id);
1544 g_return_val_if_fail(wifi != NULL, FALSE);
1546 gboolean ret = FALSE;
1549 ret = _get_vsie(frame_id, &vsie);
1551 DBG("Failed to get vsie for frame:[%d]", frame_id);
1552 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1556 DBG("Received vsie: %s", vsie);
1557 wifi_complete_get_vsie(wifi, context, vsie);
1562 gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1563 int frame_id, const gchar *vsie)
1565 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1567 g_return_val_if_fail(wifi != NULL, FALSE);
1568 g_return_val_if_fail(vsie != NULL, FALSE);
1570 gboolean ret = FALSE;
1572 ret = _remove_vsie(frame_id, vsie);
1574 DBG("Failed to remove vsie: %s", vsie);
1575 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1579 wifi_complete_remove_vsie(wifi, context);