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;
58 gchar *private_key_password;
74 struct wifi_eap_config *eap_config;
78 static void __free_wifi_configuration(struct wifi_config *conf)
85 g_free(conf->passphrase);
86 g_free(conf->security_type);
87 g_free(conf->is_hidden);
88 g_free(conf->proxy_address);
89 g_free(conf->last_error);
90 if (conf->eap_config) {
91 g_free(conf->eap_config->anonymous_identity);
92 g_free(conf->eap_config->ca_cert);
93 g_free(conf->eap_config->client_cert);
94 g_free(conf->eap_config->private_key);
95 g_free(conf->eap_config->private_key_password);
96 g_free(conf->eap_config->identity);
97 g_free(conf->eap_config->eap_type);
98 g_free(conf->eap_config->eap_auth_type);
99 g_free(conf->eap_config->subject_match);
100 g_free(conf->eap_config);
105 static gboolean __get_mac_address(gchar **mac_address)
107 gchar *tmp_mac = NULL;
109 gchar mac[13] = { 0, };
114 char buf[WIFI_MAC_ADD_LENGTH + 1];
115 if (0 == access(WIFI_MAC_ADD_PATH, F_OK))
116 fp = fopen(WIFI_MAC_ADD_PATH, "r");
119 ERR("Failed to open file %s\n", WIFI_MAC_ADD_PATH);
124 if (fgets(buf, sizeof(buf), fp) == NULL) {
125 ERR("Failed to get MAC info from %s\n", WIFI_MAC_ADD_PATH);
130 tmp_mac = (gchar *)malloc(WIFI_MAC_ADD_LENGTH + 1);
131 if (tmp_mac == NULL) {
132 ERR("malloc() failed");
137 memset(tmp_mac, 0, WIFI_MAC_ADD_LENGTH + 1);
138 g_strlcpy(tmp_mac, buf, WIFI_MAC_ADD_LENGTH + 1);
141 tmp_mac = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
142 if (tmp_mac == NULL) {
143 ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed");
148 tmp = g_ascii_strdown(tmp_mac, (gssize)strlen(tmp_mac));
150 while (tmp && tmp[i]) {
156 *mac_address = g_strdup(mac);
161 static gboolean __get_group_name(const gchar *prefix, const gchar *config_id, gchar **group_name)
163 gchar *mac_address = NULL;
164 gchar *g_name = NULL;
165 gboolean ret = FALSE;
167 ret = __get_mac_address(&mac_address);
168 if ((ret != TRUE) || (strlen(mac_address) == 0)) {
169 ERR("Cannot get WIFI MAC address");
174 g_name = g_strdup_printf("%s%s_%s", prefix, mac_address, config_id);
175 if (g_name == NULL) {
180 *group_name = g_strdup(g_name);
188 static gboolean __get_security_type(const gchar *config_id, gchar **type)
190 if (g_str_has_suffix(config_id, WIFI_SECURITY_NONE) == TRUE) {
191 *type = g_strdup(WIFI_SECURITY_NONE);
192 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WEP) == TRUE) {
193 *type = g_strdup(WIFI_SECURITY_WEP);
194 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WPA_PSK) == TRUE) {
195 *type = g_strdup(WIFI_SECURITY_WPA_PSK);
196 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_EAP) == TRUE) {
197 *type = g_strdup(WIFI_SECURITY_EAP);
206 static gboolean __get_config_id(const gchar *profile, gchar **config_id)
208 *config_id = g_strdup(profile + PROFILE_PREFIX_LENGTH);
209 if (*config_id == NULL) {
218 static GKeyFile *__get_configuration_keyfile(const gchar *group_name)
220 GKeyFile *keyfile = NULL;
223 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
225 keyfile = netconfig_keyfile_load(path);
227 ERR("keyfile[%s] is NULL", path);
234 static gboolean __remove_file(const gchar *pathname, const gchar *filename)
236 gboolean ret = FALSE;
239 path = g_strdup_printf("%s/%s", pathname, filename);
240 if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) {
242 } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) {
251 static gboolean __remove_configuration(const gchar *pathname)
255 if (__remove_file(pathname, "settings") != TRUE) {
256 ERR("Cannot remove [%s/settings]", pathname);
259 if (__remove_file(pathname, "data") != TRUE) {
260 ERR("Cannot remove [%s/data]", pathname);
264 ret = rmdir(pathname);
266 ERR("Cannot remove [%s]", pathname);
273 static gboolean _load_configuration(const gchar *config_id, struct wifi_config *config)
277 gboolean hidden = FALSE;
278 gboolean ret = FALSE;
280 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
282 ERR("Fail to get_wifi_config_group_name");
286 keyfile = __get_configuration_keyfile(group_name);
287 if (keyfile == NULL) {
288 ERR("Fail to __get_configuration_keyfile[%s]", group_name);
293 config->name = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
294 DBG("name [%s]", config->name);
296 __get_security_type(config_id, &config->security_type);
297 if (config->security_type == NULL) {
298 ERR("Fail to _get_security_type");
299 g_key_file_free(keyfile);
303 DBG("security_type [%s]", config->security_type);
305 config->proxy_address = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
306 if (config->proxy_address)
307 DBG("proxy_address [%s]", config->proxy_address);
309 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
311 config->is_hidden = g_strdup("TRUE");
313 config->is_hidden = g_strdup("FALSE");
314 DBG("is_hidden [%s]", config->is_hidden);
316 if (g_strcmp0(config->security_type, WIFI_SECURITY_EAP) == 0) {
317 config->eap_config->anonymous_identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
318 config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
319 config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
320 config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
321 config->eap_config->private_key_password = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, NULL);
322 config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
323 config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
324 config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
325 config->eap_config->subject_match = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
327 if (config->eap_config->anonymous_identity)
328 DBG("anonymous_identity [%s]", config->eap_config->anonymous_identity);
329 if (config->eap_config->ca_cert)
330 DBG("ca_cert [%s]", config->eap_config->ca_cert);
331 if (config->eap_config->client_cert)
332 DBG("client_cert [%s]", config->eap_config->client_cert);
333 if (config->eap_config->private_key)
334 DBG("private_key [%s]", config->eap_config->private_key);
335 if (config->eap_config->private_key_password)
336 DBG("private_key_password [%s]", config->eap_config->private_key_password);
337 if (config->eap_config->identity)
338 DBG("identity [%s]", config->eap_config->identity);
339 if (config->eap_config->eap_type)
340 DBG("eap_type [%s]", config->eap_config->eap_type);
341 if (config->eap_config->eap_auth_type)
342 DBG("eap_auth_type [%s]", config->eap_config->eap_auth_type);
343 if (config->eap_config->subject_match)
344 DBG("subject_match [%s]", config->eap_config->subject_match);
347 config->last_error = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
348 if (config->last_error)
349 DBG("last_error [%s]", config->last_error);
351 g_key_file_free(keyfile);
357 static gboolean _save_configuration(const gchar *config_id, GKeyFile *keyfile)
362 gboolean ret = FALSE;
364 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
366 ERR("Fail to get_wifi_config_group_name");
370 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
371 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
372 if (__remove_configuration(dir) != TRUE) {
373 ERR("[%s] is existed, but cannot remove", dir);
380 if (mkdir(dir, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) < 0) {
381 ERR("Cannot mkdir %s", dir);
387 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
388 netconfig_keyfile_save(keyfile, path);
396 static gboolean _remove_configuration(const gchar *config_id)
398 gboolean ret = FALSE;
402 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
404 ERR("Fail to get_wifi_config_group_name");
408 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
409 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
410 if (__remove_configuration(dir) != TRUE) {
411 ERR("[%s] is existed, but cannot remove", dir);
414 INFO("Success to remove [%s]", dir);
417 ERR("[%s] is not existed", dir);
428 static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar *value)
434 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
436 ERR("Fail to get_wifi_config_group_name");
439 DBG("group_name %s", group_name);
441 keyfile = __get_configuration_keyfile(group_name);
442 if (keyfile == NULL) {
443 ERR("Fail to __get_configuration_keyfile");
448 if (g_strcmp0(key, WIFI_CONFIG_PROXY_METHOD) == 0) {
449 g_key_file_set_string(keyfile, group_name, key, value);
450 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
451 g_key_file_set_string(keyfile, group_name, key, value);
452 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
453 gboolean hidden = FALSE;
454 if (g_strcmp0(value, "TRUE") == 0)
456 g_key_file_set_boolean(keyfile, group_name, key, hidden);
457 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
458 g_key_file_set_string(keyfile, group_name, key, value);
459 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
460 g_key_file_set_string(keyfile, group_name, key, value);
461 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
462 g_key_file_set_string(keyfile, group_name, key, value);
463 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
464 g_key_file_set_string(keyfile, group_name, key, value);
465 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
466 g_key_file_set_string(keyfile, group_name, key, value);
467 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
468 g_key_file_set_string(keyfile, group_name, key, value);
469 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
470 g_key_file_set_string(keyfile, group_name, key, value);
471 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
472 g_key_file_set_string(keyfile, group_name, key, value);
474 ERR("key[%s] is not supported", key);
478 _save_configuration(config_id, keyfile);
480 g_key_file_free(keyfile);
486 static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **value)
491 gboolean hidden = FALSE;
492 gboolean ret = FALSE;
494 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
496 ERR("Fail to get_wifi_config_group_name");
499 DBG("group_name %s", group_name);
501 keyfile = __get_configuration_keyfile(group_name);
502 if (keyfile == NULL) {
503 ERR("Fail to __get_configuration_keyfile");
508 if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) {
509 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
510 } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) {
511 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL);
512 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
513 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
514 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
515 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
517 val = g_strdup("TRUE");
519 val = g_strdup("FALSE");
520 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
521 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
522 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
523 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
524 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
525 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
526 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
527 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
528 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
529 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
530 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
531 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
532 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
533 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
534 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
535 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
536 } else if (g_strcmp0(key, WIFI_CONFIG_FAILURE) == 0) {
537 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
539 ERR("Invalid key[%s]", key);
540 val = g_strdup("NOTSUPPORTED");
543 *value = g_strdup(val);
546 g_key_file_free(keyfile);
552 static GSList *_get_list(void)
555 struct dirent *dp = NULL;
558 dir = opendir(CONNMAN_STORAGE);
560 ERR("Cannot open dir %s", CONNMAN_STORAGE);
564 while ((dp = readdir(dir)) != NULL) {
565 if (g_strcmp0(dp->d_name, ".") == 0 || g_strcmp0(dp->d_name, "..") == 0 ||
566 strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
569 gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH);
570 list = g_slist_append(list, g_strdup(config_id));
578 gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id)
580 gboolean ret = FALSE;
583 if ((service_profile == NULL) || (config_id == NULL)) {
584 ERR("Invalid parameter");
588 ret = __get_config_id(service_profile, &val);
589 *config_id = g_strdup(val);
595 gboolean wifi_config_remove_configuration(const gchar *config_id)
597 gboolean ret = FALSE;
599 ret = _remove_configuration(config_id);
604 int __netconfig_hex_char_to_num(char c)
606 if (c >= '0' && c <= '9')
609 if (c >= 'a' && c <= 'f')
612 if (c >= 'A' && c <= 'F')
618 int __netconfig_hex_to_byte(const char *hex)
622 a = __netconfig_hex_char_to_num(*hex++);
626 b = __netconfig_hex_char_to_num(*hex++);
633 int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len)
637 const char *ipos = hex;
638 unsigned char *opos = buf;
640 for (i = 0; i < len; i++) {
641 a = __netconfig_hex_to_byte(ipos);
652 static int __netconfig_byte_to_txt(const unsigned char *src, char **dst, int src_len)
659 ERR("Invalid parameter.");
663 *dst = (char *) g_try_malloc0((2*src_len)+1);
665 ERR("failed to allocate memory to buffer.");
671 for (i = 0; i < src_len; i++) {
672 snprintf(buf, 3, "%02x", src[i]);
680 static int __netconfig_unpack_ay_malloc(unsigned char **dst, GVariantIter *iter)
682 GVariantIter *iter_copy = NULL;
685 unsigned char *tmp_dst = NULL;
687 if (!dst || *dst || !iter) {
688 ERR("Invalid parameter");
692 iter_copy = g_variant_iter_copy(iter);
694 while (g_variant_iter_loop(iter, "y", &tmp))
696 g_variant_iter_free(iter);
698 tmp_dst = (unsigned char *)g_try_malloc0(length + 1);
700 ERR("failed to allocate memory");
701 g_variant_iter_free(iter_copy);
706 while (g_variant_iter_loop(iter_copy, "y", &tmp_dst[length]))
708 g_variant_iter_free(iter_copy);
714 tmp_dst[length] = '\0';
718 DBG("Length [%d]", length);
722 gboolean _add_vsie(int frame_id, const char* vsie)
724 GVariant *params = NULL;
725 GVariant *message = NULL;
726 GVariantBuilder *bytearray_builder = NULL;
731 unsigned char *bytearray = NULL;
732 size_t bytearray_len = 0;
734 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
735 DBG("Invalid parameter, frame-id: %d", frame_id);
739 vsie_len = strlen(vsie);
741 DBG("vsie length is zero");
745 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
747 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
748 if (bytearray == NULL) {
749 DBG("Failed to allocate memory to bytearray");
753 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
754 DBG("invalid vsie string");
759 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
760 for (i = 0; i < bytearray_len; i++)
761 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
763 params = g_variant_new("(iay)", frame_id, bytearray_builder);
764 g_variant_builder_unref(bytearray_builder);
766 if_path = netconfig_wifi_get_supplicant_interface();
768 if (if_path == NULL) {
769 ERR("Fail to get wpa_supplicant DBus path");
774 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
775 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemAdd", params);
778 if (message == NULL) {
779 ERR("Failed to send command to wpa_supplicant");
784 DBG("Succeeded to add vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
790 gboolean _get_vsie(int frame_id, char **vsie)
792 GVariant *params = NULL;
793 GVariant *message = NULL;
796 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
797 DBG("Invalid parameter, frame-id: %d", frame_id);
801 if_path = netconfig_wifi_get_supplicant_interface();
802 if (if_path == NULL) {
803 ERR("Fail to get wpa_supplicant DBus path");
807 params = g_variant_new("(i)", frame_id);
809 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
810 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemGet", params);
813 if (message == NULL) {
814 ERR("Failed to send command to wpa_supplicant");
817 GVariantIter *iter = NULL;
818 unsigned char *vsie_bytes = NULL;
822 g_variant_get(message, "(ay)", &iter);
824 ERR("vsie is not present");
828 vsie_len = __netconfig_unpack_ay_malloc(&vsie_bytes, iter);
829 if (vsie_bytes == NULL) {
830 ERR("vsie_bytes not allocated");
834 ret = __netconfig_byte_to_txt(vsie_bytes, vsie, vsie_len);
837 ERR("vsie not allocated.");
844 ERR("Succeeded to get vsie: Frame ID[%d], VSIE[%s]", frame_id, *vsie);
850 gboolean _remove_vsie(int frame_id, const char *vsie)
852 GVariant *params = NULL;
853 GVariant *message = NULL;
854 GVariantBuilder *bytearray_builder = NULL;
859 unsigned char *bytearray = NULL;
860 size_t bytearray_len = 0;
862 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
863 DBG("Invalid parameter, frame-id: %d", frame_id);
867 vsie_len = strlen(vsie);
869 DBG("vsie length is zero");
873 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
875 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
876 if (bytearray == NULL) {
877 DBG("Failed to allocate memory to bytearray");
881 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
882 DBG("invalid vsie string");
887 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
888 for (i = 0; i < bytearray_len; i++)
889 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
891 params = g_variant_new("(iay)", frame_id, bytearray_builder);
892 g_variant_builder_unref(bytearray_builder);
894 if_path = netconfig_wifi_get_supplicant_interface();
895 if (if_path == NULL) {
896 ERR("Fail to get wpa_supplicant DBus path");
901 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
902 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemRem", params);
905 if (message == NULL) {
906 ERR("Failed to send command to wpa_supplicant");
911 DBG("Succeeded to remove vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
918 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context)
921 GSList *config_ids = NULL;
923 gchar **result = NULL;
925 g_return_val_if_fail(wifi != NULL, TRUE);
927 config_ids = _get_list();
928 if (config_ids == NULL) {
929 ERR("Fail to get config list");
930 netconfig_error_no_profile(context);
934 length = g_slist_length(config_ids);
935 result = g_new0(gchar *, length + 1);
936 for (i = 0; i < length; i++) {
937 gchar *config_id = g_slist_nth_data(config_ids, i);
938 result[i] = g_strdup(config_id);
941 config_ids = g_slist_nth(config_ids, 0);
942 g_slist_free_full(config_ids, g_free);
944 wifi_complete_get_config_ids(wifi, context, (const gchar * const *)result);
946 for (i = 0; i < length; i++)
956 gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context,
957 const gchar *config_id)
959 gboolean ret = FALSE;
960 GVariantBuilder *b = NULL;
961 struct wifi_config *conf = NULL;
963 g_return_val_if_fail(wifi != NULL, TRUE);
965 conf = g_new0(struct wifi_config, 1);
967 ret = _load_configuration(config_id, conf);
970 ERR("Fail to _load_configuration");
971 netconfig_error_no_profile(context);
975 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
976 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
977 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
978 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
980 if (conf->proxy_address != NULL)
981 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
983 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
985 if (conf->last_error != NULL)
986 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
988 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
990 g_free(conf->proxy_address);
991 g_free(conf->last_error);
993 g_free(conf->security_type);
994 g_free(conf->is_hidden);
997 wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b));
998 g_variant_builder_unref(b);
1002 gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1003 const gchar *config_id, GVariant *configuration)
1005 gboolean ret = FALSE;
1006 struct wifi_config *conf = NULL;
1007 GKeyFile *keyfile = NULL;
1011 gchar *group_name = NULL;
1013 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1014 ERR("Invalid parameter");
1015 netconfig_error_invalid_parameter(context);
1019 conf = g_new0(struct wifi_config, 1);
1021 g_variant_get(configuration, "a{sv}", &iter);
1022 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1023 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1024 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1025 conf->name = g_strdup(g_variant_get_string(value, NULL));
1026 DBG("name [%s]", conf->name);
1030 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1031 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1032 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1033 DBG("ssid [%s]", conf->ssid);
1037 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1038 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1039 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1040 DBG("passphrase []");
1042 conf->passphrase = NULL;
1044 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1045 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1046 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1047 DBG("is_hidden [%s]", conf->is_hidden);
1049 conf->is_hidden = NULL;
1051 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1052 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1053 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1054 DBG("proxy_address [%s]", conf->proxy_address);
1056 conf->proxy_address = NULL;
1060 conf->favorite = TRUE;
1061 conf->autoconnect = TRUE;
1063 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1067 g_free(conf->passphrase);
1068 g_free(conf->is_hidden);
1069 g_free(conf->proxy_address);
1071 ERR("Fail to get_wifi_config_group_name");
1072 netconfig_error_fail_save_congifuration(context);
1076 keyfile = g_key_file_new();
1077 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1078 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1080 if (conf->passphrase != NULL) {
1081 gchar *enc_data = NULL;
1082 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1085 ERR("Failed to encrypt the passphrase");
1087 g_free(conf->passphrase);
1088 conf->passphrase = enc_data;
1091 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1094 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1095 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1097 /* Optional field */
1098 if (conf->proxy_address != NULL) {
1099 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1100 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1103 if (conf->is_hidden != NULL) {
1104 gboolean hidden = FALSE;
1105 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1107 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1110 ret = _save_configuration(config_id, keyfile);
1112 INFO("Success to save configuration [%s]", config_id);
1113 wifi_complete_save_configuration(wifi, context);
1115 INFO("Fail to save configuration [%s]", config_id);
1116 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
1119 g_key_file_free(keyfile);
1123 g_free(conf->passphrase);
1124 g_free(conf->is_hidden);
1125 g_free(conf->proxy_address);
1128 g_variant_iter_free(iter);
1133 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1134 const gchar *config_id)
1136 gboolean ret = FALSE;
1137 GVariantBuilder *b = NULL;
1138 struct wifi_config *conf = NULL;
1140 g_return_val_if_fail(wifi != NULL, TRUE);
1142 conf = g_new0(struct wifi_config, 1);
1143 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1145 ret = _load_configuration(config_id, conf);
1147 g_free(conf->eap_config);
1149 ERR("Fail to _load_configuration");
1150 netconfig_error_no_profile(context);
1154 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1155 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
1156 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
1157 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
1158 if (conf->proxy_address != NULL)
1159 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
1161 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
1163 if (conf->last_error != NULL)
1164 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
1166 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
1168 if (conf->eap_config != NULL) {
1169 if (conf->eap_config->anonymous_identity != NULL)
1170 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
1172 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
1174 if (conf->eap_config->ca_cert != NULL)
1175 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
1177 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
1179 if (conf->eap_config->client_cert != NULL)
1180 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
1182 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
1184 if (conf->eap_config->private_key != NULL)
1185 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
1187 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
1189 if (conf->eap_config->private_key_password != NULL)
1190 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, g_variant_new_string(conf->eap_config->private_key_password));
1192 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, g_variant_new_string("NONE"));
1194 if (conf->eap_config->identity != NULL)
1195 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
1197 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
1199 if (conf->eap_config->eap_type != NULL)
1200 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
1202 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
1204 if (conf->eap_config->eap_auth_type != NULL)
1205 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
1207 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
1209 if (conf->eap_config->subject_match != NULL)
1210 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
1212 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
1215 __free_wifi_configuration(conf);
1217 wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
1218 g_variant_builder_unref(b);
1222 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1223 const gchar *config_id, GVariant *configuration)
1225 gboolean ret = FALSE;
1226 struct wifi_config *conf = NULL;
1227 GKeyFile *keyfile = NULL;
1231 gchar *group_name = NULL;
1233 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1234 ERR("Invalid parameter");
1235 netconfig_error_invalid_parameter(context);
1239 conf = g_new0(struct wifi_config, 1);
1240 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1242 g_variant_get(configuration, "a{sv}", &iter);
1243 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1244 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1245 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1246 conf->name = g_strdup(g_variant_get_string(value, NULL));
1247 DBG("name [%s]", conf->name);
1251 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1252 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1253 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1254 DBG("ssid [%s]", conf->ssid);
1258 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1259 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1260 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1261 DBG("passphrase [%s]", conf->passphrase);
1263 conf->passphrase = NULL;
1265 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1266 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1267 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1268 DBG("is_hidden [%s]", conf->is_hidden);
1270 conf->is_hidden = NULL;
1272 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1273 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1274 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1275 DBG("proxy_address [%s]", conf->proxy_address);
1277 conf->proxy_address = NULL;
1279 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1280 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1281 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
1282 DBG("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
1284 conf->eap_config->anonymous_identity = NULL;
1286 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
1287 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1288 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
1289 DBG("ca_cert [%s]", conf->eap_config->ca_cert);
1291 conf->eap_config->ca_cert = NULL;
1293 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1294 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1295 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
1296 DBG("client_cert [%s]", conf->eap_config->client_cert);
1298 conf->eap_config->client_cert = NULL;
1300 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1301 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1302 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
1303 DBG("private_key [%s]", conf->eap_config->private_key);
1305 conf->eap_config->private_key = NULL;
1307 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD) == 0) {
1308 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1309 conf->eap_config->private_key_password = g_strdup(g_variant_get_string(value, NULL));
1310 DBG("private_key_password[%s]", conf->eap_config->private_key_password);
1312 conf->eap_config->private_key_password = NULL;
1314 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1315 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1316 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
1317 DBG("identity [%s]", conf->eap_config->identity);
1319 conf->eap_config->identity = NULL;
1321 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
1322 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1323 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
1324 DBG("eap_type [%s]", conf->eap_config->eap_type);
1326 conf->eap_config->eap_type = NULL;
1328 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1329 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1330 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
1331 DBG("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
1333 conf->eap_config->eap_auth_type = NULL;
1335 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1336 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1337 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
1338 DBG("subject_match [%s]", conf->eap_config->subject_match);
1340 conf->eap_config->subject_match = NULL;
1344 conf->favorite = TRUE;
1345 conf->autoconnect = TRUE;
1347 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1349 __free_wifi_configuration(conf);
1350 ERR("Fail to get_wifi_config_group_name");
1354 keyfile = g_key_file_new();
1355 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1356 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1358 if (conf->passphrase != NULL) {
1359 gchar *enc_data = NULL;
1360 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1363 ERR("Failed to encrypt the passphrase");
1365 g_free(conf->passphrase);
1366 conf->passphrase = enc_data;
1368 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1371 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1372 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1374 /* Optional field */
1375 if (conf->proxy_address != NULL) {
1376 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1377 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1380 if (conf->is_hidden != NULL) {
1381 gboolean hidden = FALSE;
1382 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1384 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1387 if (conf->eap_config->anonymous_identity != NULL)
1388 g_key_file_set_string(keyfile, group_name,
1389 WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, conf->eap_config->anonymous_identity);
1391 if (conf->eap_config->ca_cert != NULL)
1392 g_key_file_set_string(keyfile, group_name,
1393 WIFI_CONFIG_EAP_CACERT, conf->eap_config->ca_cert);
1395 if (conf->eap_config->client_cert != NULL)
1396 g_key_file_set_string(keyfile, group_name,
1397 WIFI_CONFIG_EAP_CLIENTCERT, conf->eap_config->client_cert);
1399 if (conf->eap_config->private_key != NULL)
1400 g_key_file_set_string(keyfile, group_name,
1401 WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
1403 if (conf->eap_config->private_key_password != NULL)
1404 g_key_file_set_string(keyfile, group_name,
1405 WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, conf->eap_config->private_key_password);
1407 if (conf->eap_config->identity != NULL)
1408 g_key_file_set_string(keyfile, group_name,
1409 WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);
1411 if (conf->eap_config->eap_type != NULL)
1412 g_key_file_set_string(keyfile, group_name,
1413 WIFI_CONFIG_EAP_TYPE, conf->eap_config->eap_type);
1415 if (conf->eap_config->eap_auth_type != NULL)
1416 g_key_file_set_string(keyfile, group_name,
1417 WIFI_CONFIG_EAP_AUTH_TYPE, conf->eap_config->eap_auth_type);
1419 if (conf->eap_config->subject_match != NULL)
1420 g_key_file_set_string(keyfile, group_name,
1421 WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match);
1423 ret = _save_configuration(config_id, keyfile);
1425 INFO("Success to save eap configuration [%s]", config_id);
1426 wifi_complete_save_eap_configuration(wifi, context);
1428 INFO("Fail to save eap configuration [%s]", config_id);
1429 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1432 g_key_file_free(keyfile);
1434 __free_wifi_configuration(conf);
1436 g_variant_iter_free(iter);
1441 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1443 gboolean ret = FALSE;
1445 if ((wifi == NULL) || (config_id == NULL)) {
1446 ERR("Invalid parameter");
1447 netconfig_error_invalid_parameter(context);
1451 ret = _remove_configuration(config_id);
1453 /* no configuration or error */
1454 ERR("No [%s] configuration", config_id);
1455 netconfig_error_no_profile(context);
1459 wifi_complete_remove_configuration(wifi, context);
1463 /* config field key / value */
1465 * [wifi_macaddress_config_id]
1466 * Name=name (mandatory)
1467 * SSID=SSID (mandatory)
1468 * Frequency=2462 (X)
1470 * AutoConnect=true (Default true)
1471 * Modified=2015-03-20 (X)
1472 * IPv4.method=manual (O)
1473 * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1474 * IPv6.method=auto (X)
1475 * IPv6.privacy=disabled (X)
1476 * IPv4.netmask_prefixlen=24 (X)
1477 * IPv4.local_address=192.0.0.1 (O)
1478 * IPv4.gateway=192.0.0.1 (O ? X ?)
1479 * Nameservers=192.168.43.22; (O)
1480 * Proxy.Method=manual (O)
1481 * Proxy.Servers=trst.com:8888; (O)
1483 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1484 const gchar *config_id, const gchar *key, const gchar *value)
1486 gboolean ret = FALSE;
1487 gchar *keyfile_key = NULL;
1489 g_return_val_if_fail(wifi != NULL, TRUE);
1490 g_return_val_if_fail(config_id != NULL, TRUE);
1491 g_return_val_if_fail(key != NULL, TRUE);
1493 DBG("Key[%s] Value[%d]", key, value);
1495 if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1496 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1498 ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1499 netconfig_error_invalid_parameter(context);
1502 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1503 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1504 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1505 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1506 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1507 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1508 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1509 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1510 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1511 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1512 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1513 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1514 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1515 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1516 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1517 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1518 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1519 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1520 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1522 ERR("Not supported key[%s]", key);
1523 netconfig_error_invalid_parameter(context);
1527 ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1529 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1532 if (keyfile_key != NULL)
1533 g_free(keyfile_key);
1535 wifi_complete_set_config_field(wifi, context);
1539 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1541 gboolean ret = FALSE;
1542 gchar *passphrase = NULL;
1544 if ((wifi == NULL) || (config_id == NULL)) {
1545 ERR("Invalid parameter");
1546 netconfig_error_invalid_parameter(context);
1550 ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1552 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1553 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1557 wifi_complete_get_config_passphrase(wifi, context, passphrase);
1563 gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1564 int frame_id, const gchar *vsie)
1566 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1568 g_return_val_if_fail(wifi != NULL, TRUE);
1569 g_return_val_if_fail(vsie != NULL, TRUE);
1571 gboolean ret = FALSE;
1573 ret = _add_vsie(frame_id, vsie);
1575 DBG("Failed to add vsie: %s", vsie);
1576 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1580 wifi_complete_add_vsie(wifi, context);
1584 gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1587 DBG("Frame ID: [%d]", frame_id);
1589 g_return_val_if_fail(wifi != NULL, TRUE);
1591 gboolean ret = FALSE;
1594 ret = _get_vsie(frame_id, &vsie);
1596 DBG("Failed to get vsie for frame:[%d]", frame_id);
1597 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1601 DBG("Received vsie: %s", vsie);
1602 wifi_complete_get_vsie(wifi, context, vsie);
1607 gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1608 int frame_id, const gchar *vsie)
1610 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1612 g_return_val_if_fail(wifi != NULL, TRUE);
1613 g_return_val_if_fail(vsie != NULL, TRUE);
1615 gboolean ret = FALSE;
1617 ret = _remove_vsie(frame_id, vsie);
1619 DBG("Failed to remove vsie: %s", vsie);
1620 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1624 wifi_complete_remove_vsie(wifi, context);