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");
172 g_name = g_strdup_printf("%s%s_%s", prefix, mac_address, config_id);
173 if (g_name == NULL) {
178 *group_name = g_strdup(g_name);
186 static gboolean __get_security_type(const gchar *config_id, gchar **type)
188 if (g_str_has_suffix(config_id, WIFI_SECURITY_NONE) == TRUE) {
189 *type = g_strdup(WIFI_SECURITY_NONE);
190 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WEP) == TRUE) {
191 *type = g_strdup(WIFI_SECURITY_WEP);
192 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WPA_PSK) == TRUE) {
193 *type = g_strdup(WIFI_SECURITY_WPA_PSK);
194 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_EAP) == TRUE) {
195 *type = g_strdup(WIFI_SECURITY_EAP);
204 static gboolean __get_config_id(const gchar *profile, gchar **config_id)
206 *config_id = g_strdup(profile + PROFILE_PREFIX_LENGTH);
207 if (*config_id == NULL) {
216 static GKeyFile *__get_configuration_keyfile(const gchar *group_name)
218 GKeyFile *keyfile = NULL;
221 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
223 keyfile = netconfig_keyfile_load(path);
225 ERR("keyfile[%s] is NULL", path);
232 static gboolean __remove_file(const gchar *pathname, const gchar *filename)
234 gboolean ret = FALSE;
237 path = g_strdup_printf("%s/%s", pathname, filename);
238 if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) {
240 } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) {
249 static gboolean __remove_configuration(const gchar *pathname)
253 if (__remove_file(pathname, "settings") != TRUE) {
254 ERR("Cannot remove [%s/settings]", pathname);
257 if (__remove_file(pathname, "data") != TRUE) {
258 ERR("Cannot remove [%s/data]", pathname);
262 ret = rmdir(pathname);
264 ERR("Cannot remove [%s]", pathname);
271 static gboolean _load_configuration(const gchar *config_id, struct wifi_config *config)
275 gboolean hidden = FALSE;
276 gboolean ret = FALSE;
278 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
280 ERR("Fail to get_wifi_config_group_name");
284 keyfile = __get_configuration_keyfile(group_name);
285 if (keyfile == NULL) {
286 ERR("Fail to __get_configuration_keyfile[%s]", group_name);
291 config->name = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
292 DBG("name [%s]", config->name);
294 __get_security_type(config_id, &config->security_type);
295 if (config->security_type == NULL) {
296 ERR("Fail to _get_security_type");
297 g_key_file_free(keyfile);
301 DBG("security_type [%s]", config->security_type);
303 config->proxy_address = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
304 if (config->proxy_address)
305 DBG("proxy_address [%s]", config->proxy_address);
307 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
309 config->is_hidden = g_strdup("TRUE");
311 config->is_hidden = g_strdup("FALSE");
312 DBG("is_hidden [%s]", config->is_hidden);
314 if (g_strcmp0(config->security_type, WIFI_SECURITY_EAP) == 0) {
315 config->eap_config->anonymous_identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
316 config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
317 config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
318 config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
319 config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
320 config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
321 config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
322 config->eap_config->subject_match = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
324 if (config->eap_config->anonymous_identity)
325 DBG("anonymous_identity [%s]", config->eap_config->anonymous_identity);
326 if (config->eap_config->ca_cert)
327 DBG("ca_cert [%s]", config->eap_config->ca_cert);
328 if (config->eap_config->client_cert)
329 DBG("client_cert [%s]", config->eap_config->client_cert);
330 if (config->eap_config->private_key)
331 DBG("private_key [%s]", config->eap_config->private_key);
332 if (config->eap_config->identity)
333 DBG("identity [%s]", config->eap_config->identity);
334 if (config->eap_config->eap_type)
335 DBG("eap_type [%s]", config->eap_config->eap_type);
336 if (config->eap_config->eap_auth_type)
337 DBG("eap_auth_type [%s]", config->eap_config->eap_auth_type);
338 if (config->eap_config->subject_match)
339 DBG("subject_match [%s]", config->eap_config->subject_match);
342 config->last_error = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
343 if (config->last_error)
344 DBG("last_error [%s]", config->last_error);
346 g_key_file_free(keyfile);
352 static gboolean _save_configuration(const gchar *config_id, GKeyFile *keyfile)
357 gboolean ret = FALSE;
359 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
361 ERR("Fail to get_wifi_config_group_name");
365 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
366 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
367 if (__remove_configuration(dir) != TRUE) {
368 ERR("[%s] is existed, but cannot remove", dir);
375 if (mkdir(dir, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) < 0) {
376 ERR("Cannot mkdir %s", dir);
382 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
383 netconfig_keyfile_save(keyfile, path);
391 static gboolean _remove_configuration(const gchar *config_id)
393 gboolean ret = FALSE;
397 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
399 ERR("Fail to get_wifi_config_group_name");
403 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
404 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
405 if (__remove_configuration(dir) != TRUE) {
406 ERR("[%s] is existed, but cannot remove", dir);
409 INFO("Success to remove [%s]", dir);
412 ERR("[%s] is not existed", dir);
423 static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar *value)
429 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
431 ERR("Fail to get_wifi_config_group_name");
434 DBG("group_name %s", group_name);
436 keyfile = __get_configuration_keyfile(group_name);
437 if (keyfile == NULL) {
438 ERR("Fail to __get_configuration_keyfile");
443 if (g_strcmp0(key, WIFI_CONFIG_PROXY_METHOD) == 0) {
444 g_key_file_set_string(keyfile, group_name, key, value);
445 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
446 g_key_file_set_string(keyfile, group_name, key, value);
447 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
448 gboolean hidden = FALSE;
449 if (g_strcmp0(value, "TRUE") == 0)
451 g_key_file_set_boolean(keyfile, group_name, key, hidden);
452 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
453 g_key_file_set_string(keyfile, group_name, key, value);
454 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
455 g_key_file_set_string(keyfile, group_name, key, value);
456 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
457 g_key_file_set_string(keyfile, group_name, key, value);
458 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
459 g_key_file_set_string(keyfile, group_name, key, value);
460 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
461 g_key_file_set_string(keyfile, group_name, key, value);
462 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
463 g_key_file_set_string(keyfile, group_name, key, value);
464 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
465 g_key_file_set_string(keyfile, group_name, key, value);
466 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
467 g_key_file_set_string(keyfile, group_name, key, value);
469 ERR("key[%s] is not supported", key);
473 _save_configuration(config_id, keyfile);
475 g_key_file_free(keyfile);
481 static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **value)
486 gboolean hidden = FALSE;
487 gboolean ret = FALSE;
489 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
491 ERR("Fail to get_wifi_config_group_name");
494 DBG("group_name %s", group_name);
496 keyfile = __get_configuration_keyfile(group_name);
497 if (keyfile == NULL) {
498 ERR("Fail to __get_configuration_keyfile");
503 if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) {
504 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
505 } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) {
506 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL);
507 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
508 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
509 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
510 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
512 val = g_strdup("TRUE");
514 val = g_strdup("FALSE");
515 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
516 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
517 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
518 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
519 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
520 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
521 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
522 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
523 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
524 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
525 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
526 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
527 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
528 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
529 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
530 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
531 } else if (g_strcmp0(key, WIFI_CONFIG_FAILURE) == 0) {
532 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
534 ERR("Invalid key[%s]", key);
535 val = g_strdup("NOTSUPPORTED");
538 *value = g_strdup(val);
541 g_key_file_free(keyfile);
547 static GSList *_get_list(void)
550 struct dirent *dp = NULL;
553 dir = opendir(CONNMAN_STORAGE);
555 ERR("Cannot open dir %s", CONNMAN_STORAGE);
559 while ((dp = readdir(dir)) != NULL) {
560 if (g_strcmp0(dp->d_name, ".") == 0 || g_strcmp0(dp->d_name, "..") == 0 ||
561 strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
564 gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH);
565 list = g_slist_append(list, g_strdup(config_id));
573 gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id)
575 gboolean ret = FALSE;
578 if ((service_profile == NULL) || (config_id == NULL)) {
579 ERR("Invalid parameter");
583 ret = __get_config_id(service_profile, &val);
584 *config_id = g_strdup(val);
590 gboolean wifi_config_remove_configuration(const gchar *config_id)
592 gboolean ret = FALSE;
594 ret = _remove_configuration(config_id);
599 int __netconfig_hex_char_to_num(char c)
601 if (c >= '0' && c <= '9')
604 if (c >= 'a' && c <= 'f')
607 if (c >= 'A' && c <= 'F')
613 int __netconfig_hex_to_byte(const char *hex)
617 a = __netconfig_hex_char_to_num(*hex++);
621 b = __netconfig_hex_char_to_num(*hex++);
628 int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len)
632 const char *ipos = hex;
633 unsigned char *opos = buf;
635 for (i = 0; i < len; i++) {
636 a = __netconfig_hex_to_byte(ipos);
647 static int __netconfig_byte_to_txt(const unsigned char *src, char **dst, int src_len)
654 ERR("Invalid parameter.");
658 *dst = (char *) g_try_malloc0((2*src_len)+1);
660 ERR("failed to allocate memory to buffer.");
666 for (i = 0; i < src_len; i++) {
667 snprintf(buf, 3, "%02x", src[i]);
675 static int __netconfig_unpack_ay_malloc(unsigned char **dst, GVariantIter *iter)
677 GVariantIter *iter_copy = NULL;
680 unsigned char *tmp_dst = NULL;
682 if (!dst || *dst || !iter) {
683 ERR("Invalid parameter");
687 iter_copy = g_variant_iter_copy(iter);
689 while (g_variant_iter_loop(iter, "y", &tmp))
691 g_variant_iter_free(iter);
693 tmp_dst = (unsigned char *)g_try_malloc0(length + 1);
695 ERR("failed to allocate memory");
696 g_variant_iter_free(iter_copy);
701 while (g_variant_iter_loop(iter_copy, "y", &tmp_dst[length]))
703 g_variant_iter_free(iter_copy);
709 tmp_dst[length] = '\0';
713 DBG("Length [%d]", length);
717 gboolean _add_vsie(int frame_id, const char* vsie)
719 GVariant *params = NULL;
720 GVariant *message = NULL;
721 GVariantBuilder *bytearray_builder = NULL;
726 unsigned char *bytearray = NULL;
727 size_t bytearray_len = 0;
729 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
730 DBG("Invalid parameter, frame-id: %d", frame_id);
734 vsie_len = strlen(vsie);
736 DBG("vsie length is zero");
740 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
742 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
743 if (bytearray == NULL) {
744 DBG("Failed to allocate memory to bytearray");
748 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
749 DBG("invalid vsie string");
754 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
755 for (i = 0; i < bytearray_len; i++)
756 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
758 params = g_variant_new("(iay)", frame_id, bytearray_builder);
759 g_variant_builder_unref(bytearray_builder);
761 if_path = netconfig_wifi_get_supplicant_interface();
763 if (if_path == NULL) {
764 ERR("Fail to get wpa_supplicant DBus path");
769 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
770 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemAdd", params);
773 if (message == NULL) {
774 ERR("Failed to send command to wpa_supplicant");
779 DBG("Succeeded to add vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
785 gboolean _get_vsie(int frame_id, char **vsie)
787 GVariant *params = NULL;
788 GVariant *message = NULL;
791 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
792 DBG("Invalid parameter, frame-id: %d", frame_id);
796 if_path = netconfig_wifi_get_supplicant_interface();
797 if (if_path == NULL) {
798 ERR("Fail to get wpa_supplicant DBus path");
802 params = g_variant_new("(i)", frame_id);
804 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
805 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemGet", params);
808 if (message == NULL) {
809 ERR("Failed to send command to wpa_supplicant");
812 GVariantIter *iter = NULL;
813 unsigned char *vsie_bytes = NULL;
817 g_variant_get(message, "(ay)", &iter);
819 ERR("vsie is not present");
823 vsie_len = __netconfig_unpack_ay_malloc(&vsie_bytes, iter);
824 if (vsie_bytes == NULL) {
825 ERR("vsie_bytes not allocated");
829 ret = __netconfig_byte_to_txt(vsie_bytes, vsie, vsie_len);
832 ERR("vsie not allocated.");
839 ERR("Succeeded to get vsie: Frame ID[%d], VSIE[%s]", frame_id, *vsie);
845 gboolean _remove_vsie(int frame_id, const char *vsie)
847 GVariant *params = NULL;
848 GVariant *message = NULL;
849 GVariantBuilder *bytearray_builder = NULL;
854 unsigned char *bytearray = NULL;
855 size_t bytearray_len = 0;
857 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
858 DBG("Invalid parameter, frame-id: %d", frame_id);
862 vsie_len = strlen(vsie);
864 DBG("vsie length is zero");
868 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
870 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
871 if (bytearray == NULL) {
872 DBG("Failed to allocate memory to bytearray");
876 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
877 DBG("invalid vsie string");
882 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
883 for (i = 0; i < bytearray_len; i++)
884 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
886 params = g_variant_new("(iay)", frame_id, bytearray_builder);
887 g_variant_builder_unref(bytearray_builder);
889 if_path = netconfig_wifi_get_supplicant_interface();
890 if (if_path == NULL) {
891 ERR("Fail to get wpa_supplicant DBus path");
896 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
897 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemRem", params);
900 if (message == NULL) {
901 ERR("Failed to send command to wpa_supplicant");
906 DBG("Succeeded to remove vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
913 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context)
916 GSList *config_ids = NULL;
918 gchar **result = NULL;
920 g_return_val_if_fail(wifi != NULL, TRUE);
922 config_ids = _get_list();
923 if (config_ids == NULL) {
924 ERR("Fail to get config list");
925 netconfig_error_no_profile(context);
929 length = g_slist_length(config_ids);
930 result = g_new0(gchar *, length + 1);
931 for (i = 0; i < length; i++) {
932 gchar *config_id = g_slist_nth_data(config_ids, i);
933 result[i] = g_strdup(config_id);
936 config_ids = g_slist_nth(config_ids, 0);
937 g_slist_free_full(config_ids, g_free);
939 wifi_complete_get_config_ids(wifi, context, (const gchar * const *)result);
941 for (i = 0; i < length; i++)
951 gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context,
952 const gchar *config_id)
954 gboolean ret = FALSE;
955 GVariantBuilder *b = NULL;
956 struct wifi_config *conf = NULL;
958 g_return_val_if_fail(wifi != NULL, TRUE);
960 conf = g_new0(struct wifi_config, 1);
962 ret = _load_configuration(config_id, conf);
965 ERR("Fail to _load_configuration");
966 netconfig_error_no_profile(context);
970 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
971 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
972 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
973 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
975 if (conf->proxy_address != NULL)
976 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
978 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
980 if (conf->last_error != NULL)
981 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
983 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
985 g_free(conf->proxy_address);
986 g_free(conf->last_error);
988 g_free(conf->security_type);
989 g_free(conf->is_hidden);
992 wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b));
993 g_variant_builder_unref(b);
997 gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
998 const gchar *config_id, GVariant *configuration)
1000 gboolean ret = FALSE;
1001 struct wifi_config *conf = NULL;
1002 GKeyFile *keyfile = NULL;
1006 gchar *group_name = NULL;
1008 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1009 ERR("Invalid parameter");
1010 netconfig_error_invalid_parameter(context);
1014 conf = g_new0(struct wifi_config, 1);
1016 g_variant_get(configuration, "a{sv}", &iter);
1017 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1018 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1019 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1020 conf->name = g_strdup(g_variant_get_string(value, NULL));
1021 DBG("name [%s]", conf->name);
1025 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1026 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1027 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1028 DBG("ssid [%s]", conf->ssid);
1032 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1033 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1034 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1035 DBG("passphrase []");
1037 conf->passphrase = NULL;
1039 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1040 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1041 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1042 DBG("is_hidden [%s]", conf->is_hidden);
1044 conf->is_hidden = NULL;
1046 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1047 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1048 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1049 DBG("proxy_address [%s]", conf->proxy_address);
1051 conf->proxy_address = NULL;
1055 conf->favorite = TRUE;
1056 conf->autoconnect = TRUE;
1058 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1062 g_free(conf->passphrase);
1063 g_free(conf->is_hidden);
1064 g_free(conf->proxy_address);
1066 ERR("Fail to get_wifi_config_group_name");
1067 netconfig_error_fail_save_congifuration(context);
1071 keyfile = g_key_file_new();
1072 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1073 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1075 if (conf->passphrase != NULL) {
1076 gchar *enc_data = NULL;
1077 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1080 ERR("Failed to encrypt the passphrase");
1082 g_free(conf->passphrase);
1083 conf->passphrase = enc_data;
1086 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1089 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1090 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1092 /* Optional field */
1093 if (conf->proxy_address != NULL) {
1094 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1095 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1098 if (conf->is_hidden != NULL) {
1099 gboolean hidden = FALSE;
1100 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1102 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1105 ret = _save_configuration(config_id, keyfile);
1107 INFO("Success to save configuration [%s]", config_id);
1108 wifi_complete_save_configuration(wifi, context);
1110 INFO("Fail to save configuration [%s]", config_id);
1111 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
1114 g_key_file_free(keyfile);
1118 g_free(conf->passphrase);
1119 g_free(conf->is_hidden);
1120 g_free(conf->proxy_address);
1123 g_variant_iter_free(iter);
1128 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1129 const gchar *config_id)
1131 gboolean ret = FALSE;
1132 GVariantBuilder *b = NULL;
1133 struct wifi_config *conf = NULL;
1135 g_return_val_if_fail(wifi != NULL, TRUE);
1137 conf = g_new0(struct wifi_config, 1);
1138 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1140 ret = _load_configuration(config_id, conf);
1142 g_free(conf->eap_config);
1144 ERR("Fail to _load_configuration");
1145 netconfig_error_no_profile(context);
1149 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1150 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
1151 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
1152 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
1153 if (conf->proxy_address != NULL)
1154 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
1156 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
1158 if (conf->last_error != NULL)
1159 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
1161 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
1163 if (conf->eap_config != NULL) {
1164 if (conf->eap_config->anonymous_identity != NULL)
1165 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
1167 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
1169 if (conf->eap_config->ca_cert != NULL)
1170 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
1172 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
1174 if (conf->eap_config->client_cert != NULL)
1175 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
1177 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
1179 if (conf->eap_config->private_key != NULL)
1180 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
1182 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
1184 if (conf->eap_config->identity != NULL)
1185 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
1187 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
1189 if (conf->eap_config->eap_type != NULL)
1190 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
1192 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
1194 if (conf->eap_config->eap_auth_type != NULL)
1195 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
1197 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
1199 if (conf->eap_config->subject_match != NULL)
1200 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
1202 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
1205 __free_wifi_configuration(conf);
1207 wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
1208 g_variant_builder_unref(b);
1212 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1213 const gchar *config_id, GVariant *configuration)
1215 gboolean ret = FALSE;
1216 struct wifi_config *conf = NULL;
1217 GKeyFile *keyfile = NULL;
1221 gchar *group_name = NULL;
1223 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1224 ERR("Invalid parameter");
1225 netconfig_error_invalid_parameter(context);
1229 conf = g_new0(struct wifi_config, 1);
1230 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1232 g_variant_get(configuration, "a{sv}", &iter);
1233 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1234 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1235 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1236 conf->name = g_strdup(g_variant_get_string(value, NULL));
1237 DBG("name [%s]", conf->name);
1241 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1242 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1243 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1244 DBG("ssid [%s]", conf->ssid);
1248 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1249 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1250 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1251 DBG("passphrase [%s]", conf->passphrase);
1253 conf->passphrase = NULL;
1255 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1256 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1257 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1258 DBG("is_hidden [%s]", conf->is_hidden);
1260 conf->is_hidden = NULL;
1262 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1263 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1264 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1265 DBG("proxy_address [%s]", conf->proxy_address);
1267 conf->proxy_address = NULL;
1269 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1270 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1271 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
1272 DBG("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
1274 conf->eap_config->anonymous_identity = NULL;
1276 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
1277 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1278 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
1279 DBG("ca_cert [%s]", conf->eap_config->ca_cert);
1281 conf->eap_config->ca_cert = NULL;
1283 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1284 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1285 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
1286 DBG("client_cert [%s]", conf->eap_config->client_cert);
1288 conf->eap_config->client_cert = NULL;
1290 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1291 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1292 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
1293 DBG("private_key [%s]", conf->eap_config->private_key);
1295 conf->eap_config->private_key = NULL;
1297 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1298 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1299 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
1300 DBG("identity [%s]", conf->eap_config->identity);
1302 conf->eap_config->identity = NULL;
1304 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
1305 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1306 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
1307 DBG("eap_type [%s]", conf->eap_config->eap_type);
1309 conf->eap_config->eap_type = NULL;
1311 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1312 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1313 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
1314 DBG("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
1316 conf->eap_config->eap_auth_type = NULL;
1318 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1319 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1320 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
1321 DBG("subject_match [%s]", conf->eap_config->subject_match);
1323 conf->eap_config->subject_match = NULL;
1327 conf->favorite = TRUE;
1328 conf->autoconnect = TRUE;
1330 ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name);
1332 __free_wifi_configuration(conf);
1333 ERR("Fail to get_wifi_config_group_name");
1337 keyfile = g_key_file_new();
1338 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1339 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1341 if (conf->passphrase != NULL) {
1342 gchar *enc_data = NULL;
1343 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1346 ERR("Failed to encrypt the passphrase");
1348 g_free(conf->passphrase);
1349 conf->passphrase = enc_data;
1351 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1354 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1355 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1357 /* Optional field */
1358 if (conf->proxy_address != NULL) {
1359 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1360 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1363 if (conf->is_hidden != NULL) {
1364 gboolean hidden = FALSE;
1365 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1367 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1370 if (conf->eap_config->anonymous_identity != NULL)
1371 g_key_file_set_string(keyfile, group_name,
1372 WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, conf->eap_config->anonymous_identity);
1374 if (conf->eap_config->ca_cert != NULL)
1375 g_key_file_set_string(keyfile, group_name,
1376 WIFI_CONFIG_EAP_CACERT, conf->eap_config->ca_cert);
1378 if (conf->eap_config->client_cert != NULL)
1379 g_key_file_set_string(keyfile, group_name,
1380 WIFI_CONFIG_EAP_CLIENTCERT, conf->eap_config->client_cert);
1382 if (conf->eap_config->private_key != NULL)
1383 g_key_file_set_string(keyfile, group_name,
1384 WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
1386 if (conf->eap_config->identity != NULL)
1387 g_key_file_set_string(keyfile, group_name,
1388 WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);
1390 if (conf->eap_config->eap_type != NULL)
1391 g_key_file_set_string(keyfile, group_name,
1392 WIFI_CONFIG_EAP_TYPE, conf->eap_config->eap_type);
1394 if (conf->eap_config->eap_auth_type != NULL)
1395 g_key_file_set_string(keyfile, group_name,
1396 WIFI_CONFIG_EAP_AUTH_TYPE, conf->eap_config->eap_auth_type);
1398 if (conf->eap_config->subject_match != NULL)
1399 g_key_file_set_string(keyfile, group_name,
1400 WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match);
1402 ret = _save_configuration(config_id, keyfile);
1404 INFO("Success to save eap configuration [%s]", config_id);
1405 wifi_complete_save_eap_configuration(wifi, context);
1407 INFO("Fail to save eap configuration [%s]", config_id);
1408 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1411 g_key_file_free(keyfile);
1413 __free_wifi_configuration(conf);
1415 g_variant_iter_free(iter);
1420 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1422 gboolean ret = FALSE;
1424 if ((wifi == NULL) || (config_id == NULL)) {
1425 ERR("Invalid parameter");
1426 netconfig_error_invalid_parameter(context);
1430 ret = _remove_configuration(config_id);
1432 /* no configuration or error */
1433 ERR("No [%s] configuration", config_id);
1434 netconfig_error_no_profile(context);
1438 wifi_complete_remove_configuration(wifi, context);
1442 /* config field key / value */
1444 * [wifi_macaddress_config_id]
1445 * Name=name (mandatory)
1446 * SSID=SSID (mandatory)
1447 * Frequency=2462 (X)
1449 * AutoConnect=true (Default true)
1450 * Modified=2015-03-20 (X)
1451 * IPv4.method=manual (O)
1452 * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1453 * IPv6.method=auto (X)
1454 * IPv6.privacy=disabled (X)
1455 * IPv4.netmask_prefixlen=24 (X)
1456 * IPv4.local_address=192.0.0.1 (O)
1457 * IPv4.gateway=192.0.0.1 (O ? X ?)
1458 * Nameservers=192.168.43.22; (O)
1459 * Proxy.Method=manual (O)
1460 * Proxy.Servers=trst.com:8888; (O)
1462 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1463 const gchar *config_id, const gchar *key, const gchar *value)
1465 gboolean ret = FALSE;
1466 gchar *keyfile_key = NULL;
1468 g_return_val_if_fail(wifi != NULL, TRUE);
1469 g_return_val_if_fail(config_id != NULL, TRUE);
1470 g_return_val_if_fail(key != NULL, TRUE);
1472 DBG("Key[%s] Value[%d]", key, value);
1474 if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1475 ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1477 ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1478 netconfig_error_invalid_parameter(context);
1481 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1482 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1483 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1484 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1485 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1486 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1487 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1488 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1489 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1490 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1491 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1492 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1493 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1494 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1495 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1496 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1497 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1498 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1499 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1501 ERR("Not supported key[%s]", key);
1502 netconfig_error_invalid_parameter(context);
1506 ret = _set_field(config_id, keyfile_key, (const gchar *)value);
1508 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1511 if (keyfile_key != NULL)
1512 g_free(keyfile_key);
1514 wifi_complete_set_config_field(wifi, context);
1518 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id)
1520 gboolean ret = FALSE;
1521 gchar *passphrase = NULL;
1523 if ((wifi == NULL) || (config_id == NULL)) {
1524 ERR("Invalid parameter");
1525 netconfig_error_invalid_parameter(context);
1529 ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1531 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1532 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1536 wifi_complete_get_config_passphrase(wifi, context, passphrase);
1542 gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1543 int frame_id, const gchar *vsie)
1545 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1547 g_return_val_if_fail(wifi != NULL, TRUE);
1548 g_return_val_if_fail(vsie != NULL, TRUE);
1550 gboolean ret = FALSE;
1552 ret = _add_vsie(frame_id, vsie);
1554 DBG("Failed to add vsie: %s", vsie);
1555 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1559 wifi_complete_add_vsie(wifi, context);
1563 gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1566 DBG("Frame ID: [%d]", frame_id);
1568 g_return_val_if_fail(wifi != NULL, TRUE);
1570 gboolean ret = FALSE;
1573 ret = _get_vsie(frame_id, &vsie);
1575 DBG("Failed to get vsie for frame:[%d]", frame_id);
1576 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1580 DBG("Received vsie: %s", vsie);
1581 wifi_complete_get_vsie(wifi, context, vsie);
1586 gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1587 int frame_id, const gchar *vsie)
1589 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
1591 g_return_val_if_fail(wifi != NULL, TRUE);
1592 g_return_val_if_fail(vsie != NULL, TRUE);
1594 gboolean ret = FALSE;
1596 ret = _remove_vsie(frame_id, vsie);
1598 DBG("Failed to remove vsie: %s", vsie);
1599 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1603 wifi_complete_remove_vsie(wifi, context);