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 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 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 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");
695 g_variant_iter_free(iter_copy);
700 while (g_variant_iter_loop(iter_copy, "y", &tmp_dst[length]))
702 g_variant_iter_free(iter_copy);
708 tmp_dst[length] = '\0';
712 DBG("Length [%d]", length);
716 gboolean _add_vsie(int frame_id, const char* vsie)
718 GVariant *params = NULL;
719 GVariant *message = NULL;
720 GVariantBuilder *bytearray_builder = NULL;
725 unsigned char *bytearray = NULL;
726 size_t bytearray_len = 0;
728 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
729 DBG("Invalid parameter, frame-id: %d", frame_id);
733 vsie_len = strlen(vsie);
735 DBG("vsie length is zero");
739 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
741 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
742 if (bytearray == NULL) {
743 DBG("Failed to allocate memory to bytearray");
747 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
748 DBG("invalid vsie string");
753 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
754 for (i = 0; i < bytearray_len; i++)
755 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
757 params = g_variant_new("(iay)", frame_id, bytearray_builder);
758 g_variant_builder_unref(bytearray_builder);
760 if_path = netconfig_wifi_get_supplicant_interface();
762 if (if_path == NULL) {
763 ERR("Fail to get wpa_supplicant DBus path");
768 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
769 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemAdd", params);
772 if (message == NULL) {
773 ERR("Failed to send command to wpa_supplicant");
778 DBG("Succeeded to add vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
784 gboolean _get_vsie(int frame_id, char **vsie)
786 GVariant *params = NULL;
787 GVariant *message = NULL;
790 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
791 DBG("Invalid parameter, frame-id: %d", frame_id);
795 if_path = netconfig_wifi_get_supplicant_interface();
796 if (if_path == NULL) {
797 ERR("Fail to get wpa_supplicant DBus path");
801 params = g_variant_new("(i)", frame_id);
803 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
804 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemGet", params);
807 if (message == NULL) {
808 ERR("Failed to send command to wpa_supplicant");
811 GVariantIter *iter = NULL;
812 unsigned char *vsie_bytes = NULL;
816 g_variant_get(message, "(ay)", &iter);
818 ERR("vsie is not present");
822 vsie_len = __netconfig_unpack_ay_malloc(&vsie_bytes, iter);
823 if (vsie_bytes == NULL) {
824 ERR("vsie_bytes not allocated");
828 ret = __netconfig_byte_to_txt(vsie_bytes, vsie, vsie_len);
831 ERR("vsie not allocated.");
838 ERR("Succeeded to get vsie: Frame ID[%d], VSIE[%s]", frame_id, *vsie);
844 gboolean _remove_vsie(int frame_id, const char *vsie)
846 GVariant *params = NULL;
847 GVariant *message = NULL;
848 GVariantBuilder *bytearray_builder = NULL;
853 unsigned char *bytearray = NULL;
854 size_t bytearray_len = 0;
856 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
857 DBG("Invalid parameter, frame-id: %d", frame_id);
861 vsie_len = strlen(vsie);
863 DBG("vsie length is zero");
867 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
869 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
870 if (bytearray == NULL) {
871 DBG("Failed to allocate memory to bytearray");
875 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
876 DBG("invalid vsie string");
881 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
882 for (i = 0; i < bytearray_len; i++)
883 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
885 params = g_variant_new("(iay)", frame_id, bytearray_builder);
886 g_variant_builder_unref(bytearray_builder);
888 if_path = netconfig_wifi_get_supplicant_interface();
889 if (if_path == NULL) {
890 ERR("Fail to get wpa_supplicant DBus path");
895 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
896 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemRem", params);
899 if (message == NULL) {
900 ERR("Failed to send command to wpa_supplicant");
905 DBG("Succeeded to remove vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
912 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context)
915 GSList *config_ids = NULL;
917 gchar **result = NULL;
919 g_return_val_if_fail(wifi != NULL, TRUE);
921 config_ids = _get_list();
922 if (config_ids == NULL) {
923 ERR("Fail to get config list");
924 netconfig_error_no_profile(context);
928 length = g_slist_length(config_ids);
929 result = g_new0(gchar *, length + 1);
930 for (i = 0; i < length; i++) {
931 gchar *config_id = g_slist_nth_data(config_ids, i);
932 result[i] = g_strdup(config_id);
935 config_ids = g_slist_nth(config_ids, 0);
936 g_slist_free_full(config_ids, g_free);
938 wifi_complete_get_config_ids(wifi, context, (const gchar * const *)result);
940 for (i = 0; i < length; i++)
950 gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context,
951 const gchar *config_id)
953 gboolean ret = FALSE;
954 GVariantBuilder *b = NULL;
955 struct wifi_config *conf = NULL;
957 g_return_val_if_fail(wifi != NULL, TRUE);
959 conf = g_new0(struct wifi_config, 1);
961 ret = _load_configuration(config_id, conf);
964 ERR("Fail to _load_configuration");
965 netconfig_error_no_profile(context);
969 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
970 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
971 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
972 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
974 if (conf->proxy_address != NULL)
975 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
977 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
979 if (conf->last_error != NULL)
980 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
982 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
984 g_free(conf->proxy_address);
985 g_free(conf->last_error);
987 g_free(conf->security_type);
988 g_free(conf->is_hidden);
991 wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b));
992 g_variant_builder_unref(b);
996 gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
997 const gchar *config_id, GVariant *configuration)
999 gboolean ret = FALSE;
1000 struct wifi_config *conf = NULL;
1001 GKeyFile *keyfile = NULL;
1005 gchar *group_name = NULL;
1007 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1008 ERR("Invalid parameter");
1009 netconfig_error_invalid_parameter(context);
1013 conf = g_new0(struct wifi_config, 1);
1015 g_variant_get(configuration, "a{sv}", &iter);
1016 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1017 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1018 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1019 conf->name = g_strdup(g_variant_get_string(value, NULL));
1020 DBG("name [%s]", conf->name);
1024 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1025 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1026 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1027 DBG("ssid [%s]", conf->ssid);
1031 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1032 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1033 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1034 DBG("passphrase []");
1036 conf->passphrase = NULL;
1038 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1039 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1040 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1041 DBG("is_hidden [%s]", conf->is_hidden);
1043 conf->is_hidden = NULL;
1045 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1046 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1047 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1048 DBG("proxy_address [%s]", conf->proxy_address);
1050 conf->proxy_address = NULL;
1054 conf->favorite = TRUE;
1055 conf->autoconnect = TRUE;
1057 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1061 g_free(conf->passphrase);
1062 g_free(conf->is_hidden);
1063 g_free(conf->proxy_address);
1065 ERR("Fail to get_wifi_config_group_name");
1066 netconfig_error_fail_save_congifuration(context);
1070 keyfile = g_key_file_new();
1071 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1072 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1074 if (conf->passphrase != NULL) {
1075 gchar *enc_data = NULL;
1076 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1079 ERR("Failed to encrypt the passphrase");
1081 g_free(conf->passphrase);
1082 conf->passphrase = enc_data;
1085 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1088 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1089 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1091 /* Optional field */
1092 if (conf->proxy_address != NULL) {
1093 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1094 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1097 if (conf->is_hidden != NULL) {
1098 gboolean hidden = FALSE;
1099 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1101 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1104 ret = _save_configuration(config_id, keyfile);
1106 INFO("Success to save configuration [%s]", config_id);
1107 wifi_complete_save_configuration(wifi, context);
1109 INFO("Fail to save configuration [%s]", config_id);
1110 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
1113 g_key_file_free(keyfile);
1117 g_free(conf->passphrase);
1118 g_free(conf->is_hidden);
1119 g_free(conf->proxy_address);
1122 g_variant_iter_free(iter);
1127 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1128 const gchar *config_id)
1130 gboolean ret = FALSE;
1131 GVariantBuilder *b = NULL;
1132 struct wifi_config *conf = NULL;
1134 g_return_val_if_fail(wifi != NULL, TRUE);
1136 conf = g_new0(struct wifi_config, 1);
1137 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1139 ret = _load_configuration(config_id, conf);
1141 g_free(conf->eap_config);
1143 ERR("Fail to _load_configuration");
1144 netconfig_error_no_profile(context);
1148 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1149 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
1150 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
1151 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
1152 if (conf->proxy_address != NULL)
1153 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
1155 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
1157 if (conf->last_error != NULL)
1158 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
1160 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
1162 if (conf->eap_config != NULL) {
1163 if (conf->eap_config->anonymous_identity != NULL)
1164 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
1166 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
1168 if (conf->eap_config->ca_cert != NULL)
1169 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
1171 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
1173 if (conf->eap_config->client_cert != NULL)
1174 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
1176 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
1178 if (conf->eap_config->private_key != NULL)
1179 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
1181 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
1183 if (conf->eap_config->identity != NULL)
1184 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
1186 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
1188 if (conf->eap_config->eap_type != NULL)
1189 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
1191 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
1193 if (conf->eap_config->eap_auth_type != NULL)
1194 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
1196 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
1198 if (conf->eap_config->subject_match != NULL)
1199 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
1201 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
1204 __free_wifi_configuration(conf);
1206 wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
1207 g_variant_builder_unref(b);
1211 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1212 const gchar *config_id, GVariant *configuration)
1214 gboolean ret = FALSE;
1215 struct wifi_config *conf = NULL;
1216 GKeyFile *keyfile = NULL;
1220 gchar *group_name = NULL;
1222 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1223 ERR("Invalid parameter");
1224 netconfig_error_invalid_parameter(context);
1228 conf = g_new0(struct wifi_config, 1);
1229 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1231 g_variant_get(configuration, "a{sv}", &iter);
1232 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1233 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1234 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1235 conf->name = g_strdup(g_variant_get_string(value, NULL));
1236 DBG("name [%s]", conf->name);
1240 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1241 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1242 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1243 DBG("ssid [%s]", conf->ssid);
1247 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1248 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1249 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1250 DBG("passphrase [%s]", conf->passphrase);
1252 conf->passphrase = NULL;
1254 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1255 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1256 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1257 DBG("is_hidden [%s]", conf->is_hidden);
1259 conf->is_hidden = NULL;
1261 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1262 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1263 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1264 DBG("proxy_address [%s]", conf->proxy_address);
1266 conf->proxy_address = NULL;
1268 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1269 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1270 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
1271 DBG("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
1273 conf->eap_config->anonymous_identity = NULL;
1275 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
1276 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1277 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
1278 DBG("ca_cert [%s]", conf->eap_config->ca_cert);
1280 conf->eap_config->ca_cert = NULL;
1282 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1283 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1284 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
1285 DBG("client_cert [%s]", conf->eap_config->client_cert);
1287 conf->eap_config->client_cert = NULL;
1289 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1290 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1291 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
1292 DBG("private_key [%s]", conf->eap_config->private_key);
1294 conf->eap_config->private_key = NULL;
1296 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1297 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1298 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
1299 DBG("identity [%s]", conf->eap_config->identity);
1301 conf->eap_config->identity = NULL;
1303 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
1304 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1305 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
1306 DBG("eap_type [%s]", conf->eap_config->eap_type);
1308 conf->eap_config->eap_type = NULL;
1310 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1311 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1312 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
1313 DBG("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
1315 conf->eap_config->eap_auth_type = NULL;
1317 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1318 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1319 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
1320 DBG("subject_match [%s]", conf->eap_config->subject_match);
1322 conf->eap_config->subject_match = NULL;
1326 conf->favorite = TRUE;
1327 conf->autoconnect = TRUE;
1329 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1331 __free_wifi_configuration(conf);
1332 ERR("Fail to get_wifi_config_group_name");
1336 keyfile = g_key_file_new();
1337 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1338 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1340 if (conf->passphrase != NULL) {
1341 gchar *enc_data = NULL;
1342 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1345 ERR("Failed to encrypt the passphrase");
1347 g_free(conf->passphrase);
1348 conf->passphrase = enc_data;
1350 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1353 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1354 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1356 /* Optional field */
1357 if (conf->proxy_address != NULL) {
1358 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1359 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1362 if (conf->is_hidden != NULL) {
1363 gboolean hidden = FALSE;
1364 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1366 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1369 if (conf->eap_config->anonymous_identity != NULL)
1370 g_key_file_set_string(keyfile, group_name,
1371 WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, conf->eap_config->anonymous_identity);
1373 if (conf->eap_config->ca_cert != NULL)
1374 g_key_file_set_string(keyfile, group_name,
1375 WIFI_CONFIG_EAP_CACERT, conf->eap_config->ca_cert);
1377 if (conf->eap_config->client_cert != NULL)
1378 g_key_file_set_string(keyfile, group_name,
1379 WIFI_CONFIG_EAP_CLIENTCERT, conf->eap_config->client_cert);
1381 if (conf->eap_config->private_key != NULL)
1382 g_key_file_set_string(keyfile, group_name,
1383 WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
1385 if (conf->eap_config->identity != NULL)
1386 g_key_file_set_string(keyfile, group_name,
1387 WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);
1389 if (conf->eap_config->eap_type != NULL)
1390 g_key_file_set_string(keyfile, group_name,
1391 WIFI_CONFIG_EAP_TYPE, conf->eap_config->eap_type);
1393 if (conf->eap_config->eap_auth_type != NULL)
1394 g_key_file_set_string(keyfile, group_name,
1395 WIFI_CONFIG_EAP_AUTH_TYPE, conf->eap_config->eap_auth_type);
1397 if (conf->eap_config->subject_match != NULL)
1398 g_key_file_set_string(keyfile, group_name,
1399 WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match);
1401 ret = _save_configuration(config_id, keyfile);
1403 INFO("Success to save eap configuration [%s]", config_id);
1404 wifi_complete_save_eap_configuration(wifi, context);
1406 INFO("Fail to save eap configuration [%s]", config_id);
1407 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1410 g_key_file_free(keyfile);
1412 __free_wifi_configuration(conf);
1414 g_variant_iter_free(iter);
1419 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1421 gboolean ret = FALSE;
1423 if ((wifi == NULL) || (config_id == NULL)) {
1424 ERR("Invalid parameter");
1425 netconfig_error_invalid_parameter(context);
1429 ret = _remove_configuration(config_id);
1431 /* no configuration or error */
1432 ERR("No [%s] configuration", config_id);
1433 netconfig_error_no_profile(context);
1437 wifi_complete_remove_configuration(wifi, context);
1441 /* config field key / value */
1443 * [wifi_macaddress_config_id]
1444 * Name=name (mandatory)
1445 * SSID=SSID (mandatory)
1446 * Frequency=2462 (X)
1448 * AutoConnect=true (Default true)
1449 * Modified=2015-03-20 (X)
1450 * IPv4.method=manual (O)
1451 * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1452 * IPv6.method=auto (X)
1453 * IPv6.privacy=disabled (X)
1454 * IPv4.netmask_prefixlen=24 (X)
1455 * IPv4.local_address=192.0.0.1 (O)
1456 * IPv4.gateway=192.0.0.1 (O ? X ?)
1457 * Nameservers=192.168.43.22; (O)
1458 * Proxy.Method=manual (O)
1459 * Proxy.Servers=trst.com:8888; (O)
1461 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1462 const gchar *config_id, const gchar *key, const gchar *value)
1464 gboolean ret = FALSE;
1465 gchar *keyfile_key = NULL;
1467 g_return_val_if_fail(wifi != NULL, TRUE);
1468 g_return_val_if_fail(config_id != NULL, TRUE);
1469 g_return_val_if_fail(key != NULL, TRUE);
1471 DBG("Key[%s] Value[%d]", key, value);
1473 if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1474 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1476 ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1477 netconfig_error_invalid_parameter(context);
1480 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1481 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1482 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1483 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1484 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1485 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1486 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1487 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1488 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1489 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1490 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1491 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1492 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1493 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1494 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1495 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1496 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1497 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1498 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1500 ERR("Not supported key[%s]", key);
1501 netconfig_error_invalid_parameter(context);
1505 ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1507 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1510 if (keyfile_key != NULL)
1511 g_free(keyfile_key);
1513 wifi_complete_set_config_field(wifi, context);
1517 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1519 gboolean ret = FALSE;
1520 gchar *passphrase = NULL;
1522 if ((wifi == NULL) || (config_id == NULL)) {
1523 ERR("Invalid parameter");
1524 netconfig_error_invalid_parameter(context);
1528 ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1530 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1531 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1535 wifi_complete_get_config_passphrase(wifi, context, passphrase);
1541 gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1542 int frame_id, const gchar *vsie)
1544 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1546 g_return_val_if_fail(wifi != NULL, TRUE);
1547 g_return_val_if_fail(vsie != NULL, TRUE);
1549 gboolean ret = FALSE;
1551 ret = _add_vsie(frame_id, vsie);
1553 DBG("Failed to add vsie: %s", vsie);
1554 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1558 wifi_complete_add_vsie(wifi, context);
1562 gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1565 DBG("Frame ID: [%d]", frame_id);
1567 g_return_val_if_fail(wifi != NULL, TRUE);
1569 gboolean ret = FALSE;
1572 ret = _get_vsie(frame_id, &vsie);
1574 DBG("Failed to get vsie for frame:[%d]", frame_id);
1575 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1579 DBG("Received vsie: %s", vsie);
1580 wifi_complete_get_vsie(wifi, context, vsie);
1585 gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1586 int frame_id, const gchar *vsie)
1588 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1590 g_return_val_if_fail(wifi != NULL, TRUE);
1591 g_return_val_if_fail(vsie != NULL, TRUE);
1593 gboolean ret = FALSE;
1595 ret = _remove_vsie(frame_id, vsie);
1597 DBG("Failed to remove vsie: %s", vsie);
1598 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1602 wifi_complete_remove_vsie(wifi, context);