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");
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, TRUE);
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, TRUE);
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");
1065 netconfig_error_fail_save_congifuration(context);
1069 keyfile = g_key_file_new();
1070 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1071 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1073 if (conf->passphrase != NULL) {
1074 gchar *enc_data = NULL;
1075 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1078 ERR("Failed to encrypt the passphrase");
1080 g_free(conf->passphrase);
1081 conf->passphrase = enc_data;
1084 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1087 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1088 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1090 /* Optional field */
1091 if (conf->proxy_address != NULL) {
1092 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1093 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1096 if (conf->is_hidden != NULL) {
1097 gboolean hidden = FALSE;
1098 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1100 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1103 ret = _save_configuration(config_id, keyfile);
1105 INFO("Success to save configuration [%s]", config_id);
1106 wifi_complete_save_configuration(wifi, context);
1108 INFO("Fail to save configuration [%s]", config_id);
1109 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
1112 g_key_file_free(keyfile);
1116 g_free(conf->passphrase);
1117 g_free(conf->is_hidden);
1118 g_free(conf->proxy_address);
1121 g_variant_iter_free(iter);
1126 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1127 const gchar *config_id)
1129 gboolean ret = FALSE;
1130 GVariantBuilder *b = NULL;
1131 struct wifi_config *conf = NULL;
1133 g_return_val_if_fail(wifi != NULL, TRUE);
1135 conf = g_new0(struct wifi_config, 1);
1136 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1138 ret = _load_configuration(config_id, conf);
1140 g_free(conf->eap_config);
1142 ERR("Fail to _load_configuration");
1143 netconfig_error_no_profile(context);
1147 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1148 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
1149 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
1150 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
1151 if (conf->proxy_address != NULL)
1152 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
1154 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
1156 if (conf->last_error != NULL)
1157 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
1159 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
1161 if (conf->eap_config != NULL) {
1162 if (conf->eap_config->anonymous_identity != NULL)
1163 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
1165 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
1167 if (conf->eap_config->ca_cert != NULL)
1168 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
1170 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
1172 if (conf->eap_config->client_cert != NULL)
1173 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
1175 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
1177 if (conf->eap_config->private_key != NULL)
1178 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
1180 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
1182 if (conf->eap_config->identity != NULL)
1183 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
1185 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
1187 if (conf->eap_config->eap_type != NULL)
1188 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
1190 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
1192 if (conf->eap_config->eap_auth_type != NULL)
1193 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
1195 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
1197 if (conf->eap_config->subject_match != NULL)
1198 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
1200 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
1203 __free_wifi_configuration(conf);
1205 wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
1206 g_variant_builder_unref(b);
1210 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1211 const gchar *config_id, GVariant *configuration)
1213 gboolean ret = FALSE;
1214 struct wifi_config *conf = NULL;
1215 GKeyFile *keyfile = NULL;
1219 gchar *group_name = NULL;
1221 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1222 ERR("Invalid parameter");
1223 netconfig_error_invalid_parameter(context);
1227 conf = g_new0(struct wifi_config, 1);
1228 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1230 g_variant_get(configuration, "a{sv}", &iter);
1231 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1232 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1233 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1234 conf->name = g_strdup(g_variant_get_string(value, NULL));
1235 DBG("name [%s]", conf->name);
1239 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1240 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1241 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1242 DBG("ssid [%s]", conf->ssid);
1246 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1247 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1248 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1249 DBG("passphrase [%s]", conf->passphrase);
1251 conf->passphrase = NULL;
1253 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1254 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1255 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1256 DBG("is_hidden [%s]", conf->is_hidden);
1258 conf->is_hidden = NULL;
1260 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1261 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1262 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1263 DBG("proxy_address [%s]", conf->proxy_address);
1265 conf->proxy_address = NULL;
1267 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1268 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1269 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
1270 DBG("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
1272 conf->eap_config->anonymous_identity = NULL;
1274 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
1275 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1276 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
1277 DBG("ca_cert [%s]", conf->eap_config->ca_cert);
1279 conf->eap_config->ca_cert = NULL;
1281 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1282 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1283 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
1284 DBG("client_cert [%s]", conf->eap_config->client_cert);
1286 conf->eap_config->client_cert = NULL;
1288 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1289 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1290 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
1291 DBG("private_key [%s]", conf->eap_config->private_key);
1293 conf->eap_config->private_key = NULL;
1295 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1296 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1297 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
1298 DBG("identity [%s]", conf->eap_config->identity);
1300 conf->eap_config->identity = NULL;
1302 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
1303 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1304 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
1305 DBG("eap_type [%s]", conf->eap_config->eap_type);
1307 conf->eap_config->eap_type = NULL;
1309 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1310 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1311 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
1312 DBG("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
1314 conf->eap_config->eap_auth_type = NULL;
1316 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1317 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1318 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
1319 DBG("subject_match [%s]", conf->eap_config->subject_match);
1321 conf->eap_config->subject_match = NULL;
1325 conf->favorite = TRUE;
1326 conf->autoconnect = TRUE;
1328 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1330 __free_wifi_configuration(conf);
1331 ERR("Fail to get_wifi_config_group_name");
1335 keyfile = g_key_file_new();
1336 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1337 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1339 if (conf->passphrase != NULL) {
1340 gchar *enc_data = NULL;
1341 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1344 ERR("Failed to encrypt the passphrase");
1346 g_free(conf->passphrase);
1347 conf->passphrase = enc_data;
1349 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1352 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1353 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1355 /* Optional field */
1356 if (conf->proxy_address != NULL) {
1357 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1358 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1361 if (conf->is_hidden != NULL) {
1362 gboolean hidden = FALSE;
1363 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1365 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1368 if (conf->eap_config->anonymous_identity != NULL)
1369 g_key_file_set_string(keyfile, group_name,
1370 WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, conf->eap_config->anonymous_identity);
1372 if (conf->eap_config->ca_cert != NULL)
1373 g_key_file_set_string(keyfile, group_name,
1374 WIFI_CONFIG_EAP_CACERT, conf->eap_config->ca_cert);
1376 if (conf->eap_config->client_cert != NULL)
1377 g_key_file_set_string(keyfile, group_name,
1378 WIFI_CONFIG_EAP_CLIENTCERT, conf->eap_config->client_cert);
1380 if (conf->eap_config->private_key != NULL)
1381 g_key_file_set_string(keyfile, group_name,
1382 WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
1384 if (conf->eap_config->identity != NULL)
1385 g_key_file_set_string(keyfile, group_name,
1386 WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);
1388 if (conf->eap_config->eap_type != NULL)
1389 g_key_file_set_string(keyfile, group_name,
1390 WIFI_CONFIG_EAP_TYPE, conf->eap_config->eap_type);
1392 if (conf->eap_config->eap_auth_type != NULL)
1393 g_key_file_set_string(keyfile, group_name,
1394 WIFI_CONFIG_EAP_AUTH_TYPE, conf->eap_config->eap_auth_type);
1396 if (conf->eap_config->subject_match != NULL)
1397 g_key_file_set_string(keyfile, group_name,
1398 WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match);
1400 ret = _save_configuration(config_id, keyfile);
1402 INFO("Success to save eap configuration [%s]", config_id);
1403 wifi_complete_save_eap_configuration(wifi, context);
1405 INFO("Fail to save eap configuration [%s]", config_id);
1406 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1409 g_key_file_free(keyfile);
1411 __free_wifi_configuration(conf);
1413 g_variant_iter_free(iter);
1418 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1420 gboolean ret = FALSE;
1422 if ((wifi == NULL) || (config_id == NULL)) {
1423 ERR("Invalid parameter");
1424 netconfig_error_invalid_parameter(context);
1428 ret = _remove_configuration(config_id);
1430 /* no configuration or error */
1431 ERR("No [%s] configuration", config_id);
1432 netconfig_error_no_profile(context);
1436 wifi_complete_remove_configuration(wifi, context);
1440 /* config field key / value */
1442 * [wifi_macaddress_config_id]
1443 * Name=name (mandatory)
1444 * SSID=SSID (mandatory)
1445 * Frequency=2462 (X)
1447 * AutoConnect=true (Default true)
1448 * Modified=2015-03-20 (X)
1449 * IPv4.method=manual (O)
1450 * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1451 * IPv6.method=auto (X)
1452 * IPv6.privacy=disabled (X)
1453 * IPv4.netmask_prefixlen=24 (X)
1454 * IPv4.local_address=192.0.0.1 (O)
1455 * IPv4.gateway=192.0.0.1 (O ? X ?)
1456 * Nameservers=192.168.43.22; (O)
1457 * Proxy.Method=manual (O)
1458 * Proxy.Servers=trst.com:8888; (O)
1460 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1461 const gchar *config_id, const gchar *key, const gchar *value)
1463 gboolean ret = FALSE;
1464 gchar *keyfile_key = NULL;
1466 g_return_val_if_fail(wifi != NULL, TRUE);
1467 g_return_val_if_fail(config_id != NULL, TRUE);
1468 g_return_val_if_fail(key != NULL, TRUE);
1470 DBG("Key[%s] Value[%d]", key, value);
1472 if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1473 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1475 ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1476 netconfig_error_invalid_parameter(context);
1479 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1480 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1481 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1482 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1483 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1484 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1485 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1486 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1487 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1488 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1489 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1490 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1491 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1492 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1493 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1494 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1495 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1496 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1497 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1499 ERR("Not supported key[%s]", key);
1500 netconfig_error_invalid_parameter(context);
1504 ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1506 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, TRUE);
1546 g_return_val_if_fail(vsie != NULL, TRUE);
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, TRUE);
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, TRUE);
1590 g_return_val_if_fail(vsie != NULL, TRUE);
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);