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"
36 #include "wifi-key-encryption.h"
38 #define CONNMAN_STORAGE "/var/lib/connman"
40 #define WIFI_SECURITY_NONE "none"
41 #define WIFI_SECURITY_WEP "wep"
42 #define WIFI_SECURITY_WPA_PSK "psk"
43 #define WIFI_SECURITY_EAP "ieee8021x"
45 #define WIFI_CONFIG_PREFIX "wifi_"
46 #define MAC_ADDRESS_LENGTH 12
47 #define WIFI_PREFIX_LENGTH MAC_ADDRESS_LENGTH + 6 /* wifi_485a3f2f506a_ */
48 #define PROFILE_PREFIX_LENGTH WIFI_PREFIX_LENGTH + 21 /* /net/connman/service/wifi_485a3f2f506a_ */
50 #define WIFI_MAC_ADD_LENGTH 17
51 #define WIFI_MAC_ADD_PATH "/sys/class/net/wlan0/address"
53 struct wifi_eap_config {
54 gchar *anonymous_identity;
73 struct wifi_eap_config *eap_config;
77 static void __free_wifi_configuration(struct wifi_config *conf)
84 g_free(conf->passphrase);
85 g_free(conf->security_type);
86 g_free(conf->is_hidden);
87 g_free(conf->proxy_address);
88 g_free(conf->last_error);
89 if (conf->eap_config) {
90 g_free(conf->eap_config->anonymous_identity);
91 g_free(conf->eap_config->ca_cert);
92 g_free(conf->eap_config->client_cert);
93 g_free(conf->eap_config->private_key);
94 g_free(conf->eap_config->identity);
95 g_free(conf->eap_config->eap_type);
96 g_free(conf->eap_config->eap_auth_type);
97 g_free(conf->eap_config->subject_match);
98 g_free(conf->eap_config);
103 static gboolean __get_mac_address(gchar **mac_address)
105 gchar *tmp_mac = NULL;
107 gchar mac[13] = { 0, };
112 char buf[WIFI_MAC_ADD_LENGTH + 1];
113 if (0 == access(WIFI_MAC_ADD_PATH, F_OK))
114 fp = fopen(WIFI_MAC_ADD_PATH, "r");
117 ERR("Failed to open file %s\n", WIFI_MAC_ADD_PATH);
122 if (fgets(buf, sizeof(buf), fp) == NULL) {
123 ERR("Failed to get MAC info from %s\n", WIFI_MAC_ADD_PATH);
128 tmp_mac = (gchar *)malloc(WIFI_MAC_ADD_LENGTH + 1);
129 if (tmp_mac == NULL) {
130 ERR("malloc() failed");
135 memset(tmp_mac, 0, WIFI_MAC_ADD_LENGTH + 1);
136 g_strlcpy(tmp_mac, buf, WIFI_MAC_ADD_LENGTH + 1);
139 tmp_mac = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
140 if (tmp_mac == NULL) {
141 ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed");
146 tmp = g_ascii_strdown(tmp_mac, (gssize)strlen(tmp_mac));
148 while (tmp && tmp[i]) {
154 *mac_address = g_strdup(mac);
159 static gboolean __get_group_name(const gchar *prefix, const gchar *config_id, gchar **group_name)
161 gchar *mac_address = NULL;
162 gchar *g_name = NULL;
163 gboolean ret = FALSE;
165 ret = __get_mac_address(&mac_address);
166 if ((ret != TRUE) || (strlen(mac_address) == 0)) {
167 ERR("Cannot get WIFI MAC address");
171 g_name = g_strdup_printf("%s%s_%s", prefix, mac_address, config_id);
172 if (g_name == NULL) {
177 *group_name = g_strdup(g_name);
185 static gboolean __get_security_type(const gchar *config_id, gchar **type)
187 if (g_str_has_suffix(config_id, WIFI_SECURITY_NONE) == TRUE) {
188 *type = g_strdup(WIFI_SECURITY_NONE);
189 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WEP) == TRUE) {
190 *type = g_strdup(WIFI_SECURITY_WEP);
191 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WPA_PSK) == TRUE) {
192 *type = g_strdup(WIFI_SECURITY_WPA_PSK);
193 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_EAP) == TRUE) {
194 *type = g_strdup(WIFI_SECURITY_EAP);
203 static gboolean __get_config_id(const gchar *profile, gchar **config_id)
205 *config_id = g_strdup(profile + PROFILE_PREFIX_LENGTH);
206 if (*config_id == NULL) {
215 static GKeyFile *__get_configuration_keyfile(const gchar *group_name)
217 GKeyFile *keyfile = NULL;
220 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
222 keyfile = netconfig_keyfile_load(path);
224 ERR("keyfile[%s] is NULL", path);
231 static gboolean __remove_file(const gchar *pathname, const gchar *filename)
233 gboolean ret = FALSE;
236 path = g_strdup_printf("%s/%s", pathname, filename);
237 if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) {
239 } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) {
248 static gboolean __remove_configuration(const gchar *pathname)
252 if (__remove_file(pathname, "settings") != TRUE) {
253 ERR("Cannot remove [%s/settings]", pathname);
256 if (__remove_file(pathname, "data") != TRUE) {
257 ERR("Cannot remove [%s/data]", pathname);
261 ret = rmdir(pathname);
263 ERR("Cannot remove [%s]", pathname);
270 static gboolean _load_configuration(const gchar *config_id, struct wifi_config *config)
274 gboolean hidden = FALSE;
275 gboolean ret = FALSE;
277 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
279 ERR("Fail to get_wifi_config_group_name");
283 keyfile = __get_configuration_keyfile(group_name);
284 if (keyfile == NULL) {
285 ERR("Fail to __get_configuration_keyfile[%s]", group_name);
290 config->name = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
291 DBG("name [%s]", config->name);
293 __get_security_type(config_id, &config->security_type);
294 if (config->security_type == NULL) {
295 ERR("Fail to _get_security_type");
296 g_key_file_free(keyfile);
300 DBG("security_type [%s]", config->security_type);
302 config->proxy_address = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
303 if (config->proxy_address)
304 DBG("proxy_address [%s]", config->proxy_address);
306 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
308 config->is_hidden = g_strdup("TRUE");
310 config->is_hidden = g_strdup("FALSE");
311 DBG("is_hidden [%s]", config->is_hidden);
313 if (g_strcmp0(config->security_type, WIFI_SECURITY_EAP) == 0) {
314 config->eap_config->anonymous_identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
315 config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
316 config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
317 config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
318 config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
319 config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
320 config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
321 config->eap_config->subject_match = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
323 if (config->eap_config->anonymous_identity)
324 DBG("anonymous_identity [%s]", config->eap_config->anonymous_identity);
325 if (config->eap_config->ca_cert)
326 DBG("ca_cert [%s]", config->eap_config->ca_cert);
327 if (config->eap_config->client_cert)
328 DBG("client_cert [%s]", config->eap_config->client_cert);
329 if (config->eap_config->private_key)
330 DBG("private_key [%s]", config->eap_config->private_key);
331 if (config->eap_config->identity)
332 DBG("identity [%s]", config->eap_config->identity);
333 if (config->eap_config->eap_type)
334 DBG("eap_type [%s]", config->eap_config->eap_type);
335 if (config->eap_config->eap_auth_type)
336 DBG("eap_auth_type [%s]", config->eap_config->eap_auth_type);
337 if (config->eap_config->subject_match)
338 DBG("subject_match [%s]", config->eap_config->subject_match);
341 config->last_error = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
342 if (config->last_error)
343 DBG("last_error [%s]", config->last_error);
345 g_key_file_free(keyfile);
351 static gboolean _save_configuration(const gchar *config_id, GKeyFile *keyfile)
356 gboolean ret = FALSE;
358 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
360 ERR("Fail to get_wifi_config_group_name");
364 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
365 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
366 if (__remove_configuration(dir) != TRUE) {
367 ERR("[%s] is existed, but cannot remove", dir);
374 if (mkdir(dir, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) < 0) {
375 ERR("Cannot mkdir %s", dir);
381 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
382 netconfig_keyfile_save(keyfile, path);
390 static gboolean _remove_configuration(const gchar *config_id)
392 gboolean ret = FALSE;
396 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
398 ERR("Fail to get_wifi_config_group_name");
402 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
403 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
404 if (__remove_configuration(dir) != TRUE) {
405 ERR("[%s] is existed, but cannot remove", dir);
408 INFO("Success to remove [%s]", dir);
411 ERR("[%s] is not existed", dir);
422 static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar *value)
428 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
430 ERR("Fail to get_wifi_config_group_name");
433 DBG("group_name %s", group_name);
435 keyfile = __get_configuration_keyfile(group_name);
436 if (keyfile == NULL) {
437 ERR("Fail to __get_configuration_keyfile");
442 if (g_strcmp0(key, WIFI_CONFIG_PROXY_METHOD) == 0) {
443 g_key_file_set_string(keyfile, group_name, key, value);
444 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
445 g_key_file_set_string(keyfile, group_name, key, value);
446 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
447 gboolean hidden = FALSE;
448 if (g_strcmp0(value, "TRUE") == 0)
450 g_key_file_set_boolean(keyfile, group_name, key, hidden);
451 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
452 g_key_file_set_string(keyfile, group_name, key, value);
453 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
454 g_key_file_set_string(keyfile, group_name, key, value);
455 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
456 g_key_file_set_string(keyfile, group_name, key, value);
457 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
458 g_key_file_set_string(keyfile, group_name, key, value);
459 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
460 g_key_file_set_string(keyfile, group_name, key, value);
461 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
462 g_key_file_set_string(keyfile, group_name, key, value);
463 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
464 g_key_file_set_string(keyfile, group_name, key, value);
465 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
466 g_key_file_set_string(keyfile, group_name, key, value);
468 ERR("key[%s] is not supported", key);
472 _save_configuration(config_id, keyfile);
474 g_key_file_free(keyfile);
480 static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **value)
485 gboolean hidden = FALSE;
486 gboolean ret = FALSE;
488 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
490 ERR("Fail to get_wifi_config_group_name");
493 DBG("group_name %s", group_name);
495 keyfile = __get_configuration_keyfile(group_name);
496 if (keyfile == NULL) {
497 ERR("Fail to __get_configuration_keyfile");
502 if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) {
503 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
504 } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) {
505 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL);
506 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
507 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
508 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
509 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
511 val = g_strdup("TRUE");
513 val = g_strdup("FALSE");
514 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
515 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
516 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
517 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
518 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
519 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
520 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
521 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
522 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
523 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
524 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
525 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
526 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
527 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
528 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
529 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
530 } else if (g_strcmp0(key, WIFI_CONFIG_FAILURE) == 0) {
531 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
533 ERR("Invalid key[%s]", key);
534 val = g_strdup("NOTSUPPORTED");
537 *value = g_strdup(val);
540 g_key_file_free(keyfile);
546 static GSList *_get_list(void)
549 struct dirent *dp = NULL;
552 dir = opendir(CONNMAN_STORAGE);
554 ERR("Cannot open dir %s", CONNMAN_STORAGE);
558 while ((dp = readdir(dir)) != NULL) {
559 if (g_strcmp0(dp->d_name, ".") == 0 || g_strcmp0(dp->d_name, "..") == 0 ||
560 strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
563 gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH);
564 list = g_slist_append(list, g_strdup(config_id));
572 gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id)
574 gboolean ret = FALSE;
577 if ((service_profile == NULL) || (config_id == NULL)) {
578 ERR("Invalid parameter");
582 ret = __get_config_id(service_profile, &val);
583 *config_id = g_strdup(val);
589 gboolean wifi_config_remove_configuration(const gchar *config_id)
591 gboolean ret = FALSE;
593 ret = _remove_configuration(config_id);
598 static int __netconfig_hex_char_to_num(char c)
600 if (c >= '0' && c <= '9')
603 if (c >= 'a' && c <= 'f')
606 if (c >= 'A' && c <= 'F')
612 static int __netconfig_hex_to_byte(const char *hex)
616 a = __netconfig_hex_char_to_num(*hex++);
620 b = __netconfig_hex_char_to_num(*hex++);
627 static int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len)
631 const char *ipos = hex;
632 unsigned char *opos = buf;
634 for (i = 0; i < len; i++) {
635 a = __netconfig_hex_to_byte(ipos);
646 static int __netconfig_byte_to_txt(const unsigned char *src, char **dst, int src_len)
653 ERR("Invalid parameter.");
657 *dst = (char *) g_try_malloc0((2*src_len)+1);
659 ERR("failed to allocate memory to buffer.");
665 for (i = 0; i < src_len; i++) {
666 snprintf(buf, 3, "%02x", src[i]);
674 static int __netconfig_unpack_ay_malloc(unsigned char **dst, GVariantIter *iter)
676 GVariantIter *iter_copy = NULL;
679 unsigned char *tmp_dst = NULL;
681 if (!dst || *dst || !iter) {
682 ERR("Invalid parameter");
686 iter_copy = g_variant_iter_copy(iter);
688 while (g_variant_iter_loop(iter, "y", &tmp))
690 g_variant_iter_free(iter);
692 tmp_dst = (unsigned char *)g_try_malloc0(length + 1);
694 ERR("failed to allocate memory");
699 while (g_variant_iter_loop(iter_copy, "y", &tmp_dst[length]))
701 g_variant_iter_free(iter_copy);
707 tmp_dst[length] = '\0';
711 DBG("Length [%d]", length);
715 gboolean _add_vsie(int frame_id, const char* vsie)
717 GVariant *params = NULL;
718 GVariant *message = NULL;
719 GVariantBuilder *bytearray_builder = NULL;
724 unsigned char *bytearray = NULL;
725 size_t bytearray_len = 0;
727 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
728 DBG("Invalid parameter, frame-id: %d", frame_id);
732 vsie_len = strlen(vsie);
734 DBG("vsie length is zero");
738 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
740 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
741 if (bytearray == NULL) {
742 DBG("Failed to allocate memory to bytearray");
746 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
747 DBG("invalid vsie string");
752 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
753 for (i = 0; i < bytearray_len; i++)
754 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
756 params = g_variant_new("(iay)", frame_id, bytearray_builder);
757 g_variant_builder_unref(bytearray_builder);
759 if_path = netconfig_wifi_get_supplicant_interface();
761 if (if_path == NULL) {
762 ERR("Fail to get wpa_supplicant DBus path");
767 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
768 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemAdd", params);
771 if (message == NULL) {
772 ERR("Failed to send command to wpa_supplicant");
777 DBG("Succeeded to add vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
783 gboolean _get_vsie(int frame_id, char **vsie)
785 GVariant *params = NULL;
786 GVariant *message = NULL;
789 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
790 DBG("Invalid parameter, frame-id: %d", frame_id);
794 if_path = netconfig_wifi_get_supplicant_interface();
795 if (if_path == NULL) {
796 ERR("Fail to get wpa_supplicant DBus path");
800 params = g_variant_new("(i)", frame_id);
802 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
803 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemGet", params);
806 if (message == NULL) {
807 ERR("Failed to send command to wpa_supplicant");
810 GVariantIter *iter = NULL;
811 unsigned char *vsie_bytes = NULL;
815 g_variant_get(message, "(ay)", &iter);
817 ERR("vsie is not present");
821 vsie_len = __netconfig_unpack_ay_malloc(&vsie_bytes, iter);
822 if (vsie_bytes == NULL) {
823 ERR("vsie_bytes not allocated");
827 ret = __netconfig_byte_to_txt(vsie_bytes, vsie, vsie_len);
830 ERR("vsie not allocated.");
837 ERR("Succeeded to get vsie: Frame ID[%d], VSIE[%s]", frame_id, *vsie);
843 gboolean _remove_vsie(int frame_id, const char *vsie)
845 GVariant *params = NULL;
846 GVariant *message = NULL;
847 GVariantBuilder *bytearray_builder = NULL;
852 unsigned char *bytearray = NULL;
853 size_t bytearray_len = 0;
855 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
856 DBG("Invalid parameter, frame-id: %d", frame_id);
860 vsie_len = strlen(vsie);
862 DBG("vsie length is zero");
866 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
868 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
869 if (bytearray == NULL) {
870 DBG("Failed to allocate memory to bytearray");
874 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
875 DBG("invalid vsie string");
880 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
881 for (i = 0; i < bytearray_len; i++)
882 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
884 params = g_variant_new("(iay)", frame_id, bytearray_builder);
885 g_variant_builder_unref(bytearray_builder);
887 if_path = netconfig_wifi_get_supplicant_interface();
888 if (if_path == NULL) {
889 ERR("Fail to get wpa_supplicant DBus path");
894 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
895 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemRem", params);
898 if (message == NULL) {
899 ERR("Failed to send command to wpa_supplicant");
904 DBG("Succeeded to remove vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
911 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context)
914 GSList *config_ids = NULL;
916 gchar **result = NULL;
918 g_return_val_if_fail(wifi != NULL, FALSE);
920 config_ids = _get_list();
921 if (config_ids == NULL) {
922 ERR("Fail to get config list");
923 netconfig_error_no_profile(context);
927 length = g_slist_length(config_ids);
928 result = g_new0(gchar *, length + 1);
929 for (i = 0; i < length; i++) {
930 gchar *config_id = g_slist_nth_data(config_ids, i);
931 result[i] = g_strdup(config_id);
934 config_ids = g_slist_nth(config_ids, 0);
935 g_slist_free_full(config_ids, g_free);
937 wifi_complete_get_config_ids(wifi, context, (const gchar * const *)result);
939 for (i = 0; i < length; i++)
949 gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context,
950 const gchar *config_id)
952 gboolean ret = FALSE;
953 GVariantBuilder *b = NULL;
954 struct wifi_config *conf = NULL;
956 g_return_val_if_fail(wifi != NULL, FALSE);
958 conf = g_new0(struct wifi_config, 1);
960 ret = _load_configuration(config_id, conf);
963 ERR("Fail to _load_configuration");
964 netconfig_error_no_profile(context);
968 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
969 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
970 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
971 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
973 if (conf->proxy_address != NULL)
974 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
976 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
978 if (conf->last_error != NULL)
979 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
981 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
983 g_free(conf->proxy_address);
984 g_free(conf->last_error);
986 g_free(conf->security_type);
987 g_free(conf->is_hidden);
990 wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b));
991 g_variant_builder_unref(b);
995 gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
996 const gchar *config_id, GVariant *configuration)
998 gboolean ret = FALSE;
999 struct wifi_config *conf = NULL;
1000 GKeyFile *keyfile = NULL;
1004 gchar *group_name = NULL;
1006 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1007 ERR("Invalid parameter");
1008 netconfig_error_invalid_parameter(context);
1012 conf = g_new0(struct wifi_config, 1);
1014 g_variant_get(configuration, "a{sv}", &iter);
1015 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1016 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1017 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1018 conf->name = g_strdup(g_variant_get_string(value, NULL));
1019 DBG("name [%s]", conf->name);
1023 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1024 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1025 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1026 DBG("ssid [%s]", conf->ssid);
1030 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1031 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1032 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1033 DBG("passphrase []");
1035 conf->passphrase = NULL;
1037 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1038 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1039 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1040 DBG("is_hidden [%s]", conf->is_hidden);
1042 conf->is_hidden = NULL;
1044 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1045 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1046 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1047 DBG("proxy_address [%s]", conf->proxy_address);
1049 conf->proxy_address = NULL;
1053 conf->favorite = TRUE;
1054 conf->autoconnect = TRUE;
1056 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1060 g_free(conf->passphrase);
1061 g_free(conf->is_hidden);
1062 g_free(conf->proxy_address);
1064 ERR("Fail to get_wifi_config_group_name");
1068 keyfile = g_key_file_new();
1069 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1070 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1072 if (conf->passphrase != NULL) {
1073 gchar *enc_data = NULL;
1074 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1077 ERR("Failed to encrypt the passphrase");
1079 g_free(conf->passphrase);
1080 conf->passphrase = enc_data;
1083 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1086 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1087 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1089 /* Optional field */
1090 if (conf->proxy_address != NULL) {
1091 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1092 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1095 if (conf->is_hidden != NULL) {
1096 gboolean hidden = FALSE;
1097 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1099 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1102 ret = _save_configuration(config_id, keyfile);
1104 INFO("Success to save configuration [%s]", config_id);
1105 wifi_complete_save_configuration(wifi, context);
1107 INFO("Fail to save configuration [%s]", config_id);
1108 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
1111 g_key_file_free(keyfile);
1115 g_free(conf->passphrase);
1116 g_free(conf->is_hidden);
1117 g_free(conf->proxy_address);
1120 g_variant_iter_free(iter);
1125 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1126 const gchar *config_id)
1128 gboolean ret = FALSE;
1129 GVariantBuilder *b = NULL;
1130 struct wifi_config *conf = NULL;
1132 g_return_val_if_fail(wifi != NULL, FALSE);
1134 conf = g_new0(struct wifi_config, 1);
1135 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1137 ret = _load_configuration(config_id, conf);
1139 g_free(conf->eap_config);
1141 ERR("Fail to _load_configuration");
1142 netconfig_error_no_profile(context);
1146 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1147 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
1148 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
1149 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
1150 if (conf->proxy_address != NULL)
1151 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
1153 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
1155 if (conf->last_error != NULL)
1156 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
1158 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
1160 if (conf->eap_config != NULL) {
1161 if (conf->eap_config->anonymous_identity != NULL)
1162 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
1164 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
1166 if (conf->eap_config->ca_cert != NULL)
1167 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
1169 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
1171 if (conf->eap_config->client_cert != NULL)
1172 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
1174 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
1176 if (conf->eap_config->private_key != NULL)
1177 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
1179 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
1181 if (conf->eap_config->identity != NULL)
1182 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
1184 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
1186 if (conf->eap_config->eap_type != NULL)
1187 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
1189 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
1191 if (conf->eap_config->eap_auth_type != NULL)
1192 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
1194 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
1196 if (conf->eap_config->subject_match != NULL)
1197 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
1199 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
1202 __free_wifi_configuration(conf);
1204 wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
1205 g_variant_builder_unref(b);
1209 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1210 const gchar *config_id, GVariant *configuration)
1212 gboolean ret = FALSE;
1213 struct wifi_config *conf = NULL;
1214 GKeyFile *keyfile = NULL;
1218 gchar *group_name = NULL;
1220 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1221 ERR("Invalid parameter");
1222 netconfig_error_invalid_parameter(context);
1226 conf = g_new0(struct wifi_config, 1);
1227 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1229 g_variant_get(configuration, "a{sv}", &iter);
1230 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1231 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1232 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1233 conf->name = g_strdup(g_variant_get_string(value, NULL));
1234 DBG("name [%s]", conf->name);
1238 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1239 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1240 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1241 DBG("ssid [%s]", conf->ssid);
1245 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1246 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1247 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1248 DBG("passphrase [%s]", conf->passphrase);
1250 conf->passphrase = NULL;
1252 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1253 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1254 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1255 DBG("is_hidden [%s]", conf->is_hidden);
1257 conf->is_hidden = NULL;
1259 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1260 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1261 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1262 DBG("proxy_address [%s]", conf->proxy_address);
1264 conf->proxy_address = NULL;
1266 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1267 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1268 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
1269 DBG("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
1271 conf->eap_config->anonymous_identity = NULL;
1273 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
1274 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1275 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
1276 DBG("ca_cert [%s]", conf->eap_config->ca_cert);
1278 conf->eap_config->ca_cert = NULL;
1280 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1281 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1282 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
1283 DBG("client_cert [%s]", conf->eap_config->client_cert);
1285 conf->eap_config->client_cert = NULL;
1287 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1288 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1289 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
1290 DBG("private_key [%s]", conf->eap_config->private_key);
1292 conf->eap_config->private_key = NULL;
1294 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1295 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1296 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
1297 DBG("identity [%s]", conf->eap_config->identity);
1299 conf->eap_config->identity = NULL;
1301 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
1302 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1303 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
1304 DBG("eap_type [%s]", conf->eap_config->eap_type);
1306 conf->eap_config->eap_type = NULL;
1308 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1309 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1310 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
1311 DBG("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
1313 conf->eap_config->eap_auth_type = NULL;
1315 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1316 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1317 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
1318 DBG("subject_match [%s]", conf->eap_config->subject_match);
1320 conf->eap_config->subject_match = NULL;
1324 conf->favorite = TRUE;
1325 conf->autoconnect = TRUE;
1327 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1329 __free_wifi_configuration(conf);
1330 ERR("Fail to get_wifi_config_group_name");
1334 keyfile = g_key_file_new();
1335 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1336 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1338 if (conf->passphrase != NULL) {
1339 gchar *enc_data = NULL;
1340 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1343 ERR("Failed to encrypt the passphrase");
1345 g_free(conf->passphrase);
1346 conf->passphrase = enc_data;
1348 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1351 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1352 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1354 /* Optional field */
1355 if (conf->proxy_address != NULL) {
1356 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1357 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1360 if (conf->is_hidden != NULL) {
1361 gboolean hidden = FALSE;
1362 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1364 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1367 if (conf->eap_config->anonymous_identity != NULL)
1368 g_key_file_set_string(keyfile, group_name,
1369 WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, conf->eap_config->anonymous_identity);
1371 if (conf->eap_config->ca_cert != NULL)
1372 g_key_file_set_string(keyfile, group_name,
1373 WIFI_CONFIG_EAP_CACERT, conf->eap_config->ca_cert);
1375 if (conf->eap_config->client_cert != NULL)
1376 g_key_file_set_string(keyfile, group_name,
1377 WIFI_CONFIG_EAP_CLIENTCERT, conf->eap_config->client_cert);
1379 if (conf->eap_config->private_key != NULL)
1380 g_key_file_set_string(keyfile, group_name,
1381 WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
1383 if (conf->eap_config->identity != NULL)
1384 g_key_file_set_string(keyfile, group_name,
1385 WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);
1387 if (conf->eap_config->eap_type != NULL)
1388 g_key_file_set_string(keyfile, group_name,
1389 WIFI_CONFIG_EAP_TYPE, conf->eap_config->eap_type);
1391 if (conf->eap_config->eap_auth_type != NULL)
1392 g_key_file_set_string(keyfile, group_name,
1393 WIFI_CONFIG_EAP_AUTH_TYPE, conf->eap_config->eap_auth_type);
1395 if (conf->eap_config->subject_match != NULL)
1396 g_key_file_set_string(keyfile, group_name,
1397 WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match);
1399 ret = _save_configuration(config_id, keyfile);
1401 INFO("Success to save eap configuration [%s]", config_id);
1402 wifi_complete_save_eap_configuration(wifi, context);
1404 INFO("Fail to save eap configuration [%s]", config_id);
1405 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1408 g_key_file_free(keyfile);
1410 __free_wifi_configuration(conf);
1412 g_variant_iter_free(iter);
1417 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1419 gboolean ret = FALSE;
1421 if ((wifi == NULL) || (config_id == NULL)) {
1422 ERR("Invalid parameter");
1423 netconfig_error_invalid_parameter(context);
1427 ret = _remove_configuration(config_id);
1429 /* no configuration or error */
1430 ERR("No [%s] configuration", config_id);
1431 netconfig_error_no_profile(context);
1435 wifi_complete_remove_configuration(wifi, context);
1439 /* config field key / value */
1441 * [wifi_macaddress_config_id]
1442 * Name=name (mandatory)
1443 * SSID=SSID (mandatory)
1444 * Frequency=2462 (X)
1446 * AutoConnect=true (Default true)
1447 * Modified=2015-03-20 (X)
1448 * IPv4.method=manual (O)
1449 * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1450 * IPv6.method=auto (X)
1451 * IPv6.privacy=disabled (X)
1452 * IPv4.netmask_prefixlen=24 (X)
1453 * IPv4.local_address=192.0.0.1 (O)
1454 * IPv4.gateway=192.0.0.1 (O ? X ?)
1455 * Nameservers=192.168.43.22; (O)
1456 * Proxy.Method=manual (O)
1457 * Proxy.Servers=trst.com:8888; (O)
1459 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1460 const gchar *config_id, const gchar *key, const gchar *value)
1462 gboolean ret = FALSE;
1463 gchar *keyfile_key = NULL;
1465 g_return_val_if_fail(wifi != NULL, FALSE);
1466 g_return_val_if_fail(config_id != NULL, FALSE);
1467 g_return_val_if_fail(key != NULL, FALSE);
1469 DBG("Key[%s] Value[%d]", key, value);
1471 if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1472 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1474 ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1475 netconfig_error_invalid_parameter(context);
1478 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1479 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1480 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1481 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1482 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1483 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1484 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1485 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1486 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1487 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1488 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1489 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1490 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1491 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1492 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1493 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1494 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1495 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1496 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1498 ERR("Not supported key[%s]", key);
1499 netconfig_error_invalid_parameter(context);
1503 ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1505 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1509 if (keyfile_key != NULL)
1510 g_free(keyfile_key);
1512 wifi_complete_set_config_field(wifi, context);
1516 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1518 gboolean ret = FALSE;
1519 gchar *passphrase = NULL;
1521 if ((wifi == NULL) || (config_id == NULL)) {
1522 ERR("Invalid parameter");
1523 netconfig_error_invalid_parameter(context);
1527 ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1529 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1530 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1534 wifi_complete_get_config_passphrase(wifi, context, passphrase);
1540 gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1541 int frame_id, const gchar *vsie)
1543 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1545 g_return_val_if_fail(wifi != NULL, FALSE);
1546 g_return_val_if_fail(vsie != NULL, FALSE);
1548 gboolean ret = FALSE;
1550 ret = _add_vsie(frame_id, vsie);
1552 DBG("Failed to add vsie: %s", vsie);
1553 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1557 wifi_complete_add_vsie(wifi, context);
1561 gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1564 DBG("Frame ID: [%d]", frame_id);
1566 g_return_val_if_fail(wifi != NULL, FALSE);
1568 gboolean ret = FALSE;
1571 ret = _get_vsie(frame_id, &vsie);
1573 DBG("Failed to get vsie for frame:[%d]", frame_id);
1574 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1578 DBG("Received vsie: %s", vsie);
1579 wifi_complete_get_vsie(wifi, context, vsie);
1584 gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1585 int frame_id, const gchar *vsie)
1587 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1589 g_return_val_if_fail(wifi != NULL, FALSE);
1590 g_return_val_if_fail(vsie != NULL, FALSE);
1592 gboolean ret = FALSE;
1594 ret = _remove_vsie(frame_id, vsie);
1596 DBG("Failed to remove vsie: %s", vsie);
1597 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1601 wifi_complete_remove_vsie(wifi, context);