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>
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
37 #include "wifi-config.h"
38 #include "wifi-state.h"
39 #include "netsupplicant.h"
40 #include "wifi-key-encryption.h"
42 #define CONNMAN_STORAGE "/var/lib/connman"
44 #define WIFI_SECURITY_NONE "none"
45 #define WIFI_SECURITY_WEP "wep"
46 #define WIFI_SECURITY_WPA_PSK "psk"
47 #define WIFI_SECURITY_EAP "ieee8021x"
48 #define WIFI_SECURITY_SAE "sae"
50 #define WIFI_CONFIG_PREFIX "wifi_"
51 #define MAC_ADDRESS_LENGTH 12
52 #define WIFI_PREFIX_LENGTH MAC_ADDRESS_LENGTH + 6 /* wifi_485a3f2f506a_ */
53 #define PROFILE_PREFIX_LENGTH WIFI_PREFIX_LENGTH + 21 /* /net/connman/service/wifi_485a3f2f506a_ */
55 #define NET_DNS_ADDR_MAX 2
57 #define MAX_WIFI_PROFILES 200
59 struct wifi_eap_config {
60 gchar *anonymous_identity;
64 gchar *private_key_password;
74 gchar *gateway_address;
75 gchar *dns_address[NET_DNS_ADDR_MAX];
92 struct wifi_eap_config *eap_config;
93 wifi_ip_info_s *ip_info;
98 static void __free_wifi_configuration(struct wifi_config *conf)
105 g_free(conf->passphrase);
106 g_free(conf->security_type);
107 g_free(conf->is_hidden);
108 g_free(conf->proxy_address);
109 g_free(conf->last_error);
110 if (conf->eap_config) {
111 g_free(conf->eap_config->anonymous_identity);
112 g_free(conf->eap_config->ca_cert);
113 g_free(conf->eap_config->client_cert);
114 g_free(conf->eap_config->private_key);
115 g_free(conf->eap_config->private_key_password);
116 g_free(conf->eap_config->identity);
117 g_free(conf->eap_config->eap_type);
118 g_free(conf->eap_config->eap_auth_type);
119 g_free(conf->eap_config->subject_match);
120 g_free(conf->eap_config);
124 g_free(conf->ip_info->ip_type);
125 g_free(conf->ip_info->ip_address);
126 g_free(conf->ip_info->subnet_mask);
127 g_free(conf->ip_info->gateway_address);
128 g_free(conf->ip_info->dns_type);
129 conf->ip_info->prefix_length = 0;
131 int i = 0, count = conf->ip_info->dns_count;
133 g_free(conf->ip_info->dns_address[i]);
136 g_free(conf->ip_info);
141 static gboolean __get_mac_address(const gchar *interface_name, gchar **mac_address)
144 char buf[WIFI_MAC_ADDR_LENGTH + 1];
145 char path[WIFI_MAC_PATH_LENGTH];
146 gchar *tmp_mac = NULL;
148 gchar mac[13] = { 0, };
151 snprintf(path, WIFI_MAC_PATH_LENGTH, WIFI_MAC_ADDR_PATH, interface_name);
153 if (0 == access(path, F_OK))
154 fp = fopen(path, "r");
157 if (fgets(buf, sizeof(buf), fp) == NULL) {
158 ERR("Failed to get MAC info from %s\n", path);
163 tmp_mac = (gchar *)malloc(WIFI_MAC_ADDR_LENGTH + 1);
164 if (tmp_mac == NULL) {
165 ERR("malloc() failed");
170 memset(tmp_mac, 0, WIFI_MAC_ADDR_LENGTH + 1);
171 g_strlcpy(tmp_mac, buf, WIFI_MAC_ADDR_LENGTH + 1);
174 ERR("Failed to open file %s\n", path);
176 tmp_mac = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
177 if (tmp_mac == NULL) {
178 ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed");
184 tmp = g_ascii_strdown(tmp_mac, (gssize)strlen(tmp_mac));
186 while (tmp && tmp[i]) {
192 *mac_address = g_strdup(mac);
198 gboolean wifi_config_get_group_name(const gchar *prefix,
199 const gchar *interface_name, const gchar *config_id, gchar **group_name)
201 gchar *mac_address = NULL;
202 gchar *g_name = NULL;
203 gboolean ret = FALSE;
205 ret = __get_mac_address(interface_name, &mac_address);
206 if ((ret != TRUE) || (strlen(mac_address) == 0)) {
207 ERR("Cannot get WIFI MAC address");
212 g_name = g_strdup_printf("%s%s_%s", prefix, mac_address, config_id);
213 if (g_name == NULL) {
218 *group_name = g_strdup(g_name);
226 static gboolean __get_security_type(const gchar *config_id, gchar **type)
228 if (g_str_has_suffix(config_id, WIFI_SECURITY_NONE) == TRUE) {
229 *type = g_strdup(WIFI_SECURITY_NONE);
230 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WEP) == TRUE) {
231 *type = g_strdup(WIFI_SECURITY_WEP);
232 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WPA_PSK) == TRUE) {
233 *type = g_strdup(WIFI_SECURITY_WPA_PSK);
234 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_EAP) == TRUE) {
235 *type = g_strdup(WIFI_SECURITY_EAP);
236 } else if (g_str_has_suffix(config_id, WIFI_SECURITY_SAE) == TRUE) {
237 *type = g_strdup(WIFI_SECURITY_SAE);
246 static gboolean __get_config_id(const gchar *profile, gchar **config_id)
248 *config_id = g_strdup(profile + PROFILE_PREFIX_LENGTH);
249 if (*config_id == NULL) {
258 static GKeyFile *__get_configuration_keyfile(const gchar *group_name)
260 GKeyFile *keyfile = NULL;
263 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
265 keyfile = netconfig_keyfile_load(path);
267 ERR("keyfile[%s] is NULL", path);
274 static gboolean __remove_file(const gchar *pathname, const gchar *filename)
276 gboolean ret = FALSE;
279 path = g_strdup_printf("%s/%s", pathname, filename);
280 if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) {
282 } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) {
291 static gboolean __remove_all_files(const gchar *pathname)
294 struct dirent *file = NULL;
296 if ((dir_ptr = opendir(pathname)) == NULL)
299 while ((file = readdir(dir_ptr)) != NULL) {
300 if (strncmp(file->d_name, ".", 1) == 0 || strncmp(file->d_name, "..", 2) == 0)
303 if (__remove_file(pathname, file->d_name) != TRUE) {
304 ERR("Cannot remove [%s/%s]", pathname, file->d_name);
316 static gboolean __remove_configuration(const gchar *pathname)
320 if (__remove_all_files(pathname) != TRUE) {
321 ERR("Cannot remove [%s] directory", pathname);
325 ret = rmdir(pathname);
327 ERR("Cannot remove [%s]", pathname);
333 static gboolean _load_configuration(const gchar *interface_name,
334 const gchar *config_id, struct wifi_config *config)
338 gboolean hidden = FALSE;
339 gboolean ret = FALSE;
341 ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX,
342 interface_name, config_id, &group_name);
344 ERR("Fail to get_wifi_config_group_name");
348 keyfile = __get_configuration_keyfile(group_name);
349 if (keyfile == NULL) {
350 ERR("Fail to __get_configuration_keyfile[%s]", group_name);
355 config->name = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
356 DBG("name [%s]", config->name);
358 if (config->name == NULL) {
359 ERR("Fail to get Name of [%s]", group_name);
360 g_key_file_free(keyfile);
365 __get_security_type(config_id, &config->security_type);
366 if (config->security_type == NULL) {
367 ERR("Fail to _get_security_type");
368 g_key_file_free(keyfile);
372 DBG("security_type [%s]", config->security_type);
374 config->passphrase = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL);
375 DBG("passphrase []");
377 config->proxy_address = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
378 if (config->proxy_address)
379 DBG("proxy_address [%s]", config->proxy_address);
381 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
383 config->is_hidden = g_strdup("TRUE");
385 config->is_hidden = g_strdup("FALSE");
386 DBG("is_hidden [%s]", config->is_hidden);
388 config->frequency = g_key_file_get_integer(keyfile, group_name, WIFI_CONFIG_FREQUENCY, NULL);
389 if (config->frequency)
390 DBG("Frequency [%d]", config->frequency);
392 if (config->ip_info) {
393 config->ip_info->ip_type = g_key_file_get_string(keyfile, group_name,
394 WIFI_CONFIG_IPV4_METHOD, NULL);
395 if (config->ip_info->ip_type)
396 DBG("IPv4.Method:%s", config->ip_info->ip_type);
398 config->ip_info->ip_address = g_key_file_get_string(keyfile, group_name,
399 WIFI_CONFIG_IPV4_ADDRESS, NULL);
400 if (config->ip_info->ip_address)
401 DBG("IPv4.Address:%s", config->ip_info->ip_address);
405 struct in_addr netmask;
407 GError *error = NULL;
408 prefix_len = g_key_file_get_integer(keyfile, group_name,
409 WIFI_CONFIG_IPV4_SUBNET_MASK, &error);
411 DBG("g_key_file_get_integer failed error[%d: %s]", error->code, error->message);
414 if (prefix_len > 0 && prefix_len < 32) {
415 addr = 0xffffffff << (32 - prefix_len);
416 netmask.s_addr = htonl(addr);
417 mask = inet_ntoa(netmask);
418 config->ip_info->subnet_mask = g_strdup(mask);
420 if (config->ip_info->subnet_mask)
421 DBG("IPv4.SubnetMask:%s", config->ip_info->subnet_mask);
424 config->ip_info->gateway_address = g_key_file_get_string(keyfile,
425 group_name, WIFI_CONFIG_IPV4_GATEWAY_ADDRESS, NULL);
426 if (config->ip_info->gateway_address)
427 DBG("IPv4.gateway:%s", config->ip_info->gateway_address);
429 config->ip_info->dns_type = g_key_file_get_string(keyfile, group_name,
430 WIFI_CONFIG_IPV4_DNS_METHOD, NULL);
431 if (config->ip_info->dns_type)
432 DBG("DNS.IPv4Method:%s", config->ip_info->dns_type);
436 nameservers = g_key_file_get_string_list(keyfile, group_name,
437 WIFI_CONFIG_DNS_ADDRESS, &length, NULL);
440 config->ip_info->dns_count = length;
442 while (i < NET_DNS_ADDR_MAX && nameservers[i]) {
443 config->ip_info->dns_address[i] = g_strdup(nameservers[i]);
444 DBG("DNSAddress[%d]:%s", i+1, config->ip_info->dns_address[i]);
448 g_strfreev(nameservers);
453 if (g_strcmp0(config->security_type, WIFI_SECURITY_EAP) == 0) {
454 config->eap_config->anonymous_identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
455 config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
456 config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
457 config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
458 config->eap_config->private_key_password = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, NULL);
459 config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
460 config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
461 config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
462 config->eap_config->subject_match = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
464 if (config->eap_config->anonymous_identity)
465 DBG("anonymous_identity [%s]", config->eap_config->anonymous_identity);
466 if (config->eap_config->ca_cert)
467 DBG("ca_cert [%s]", config->eap_config->ca_cert);
468 if (config->eap_config->client_cert)
469 DBG("client_cert [%s]", config->eap_config->client_cert);
470 if (config->eap_config->private_key)
471 DBG("private_key [%s]", config->eap_config->private_key);
472 if (config->eap_config->private_key_password)
473 DBG("private_key_password [%s]", config->eap_config->private_key_password);
474 if (config->eap_config->identity)
475 DBG("identity [%s]", config->eap_config->identity);
476 if (config->eap_config->eap_type)
477 DBG("eap_type [%s]", config->eap_config->eap_type);
478 if (config->eap_config->eap_auth_type)
479 DBG("eap_auth_type [%s]", config->eap_config->eap_auth_type);
480 if (config->eap_config->subject_match)
481 DBG("subject_match [%s]", config->eap_config->subject_match);
484 config->last_error = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
485 if (config->last_error)
486 DBG("last_error [%s]", config->last_error);
488 g_key_file_free(keyfile);
494 gboolean wifi_config_save_configuration(const gchar *interface_name,
495 const gchar *config_id, GKeyFile *keyfile)
500 gboolean ret = FALSE;
502 ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX,
503 interface_name, config_id, &group_name);
505 ERR("Fail to get_wifi_config_group_name");
509 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
510 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
511 if (__remove_configuration(dir) != TRUE) {
512 ERR("[%s] is existed, but cannot remove", dir);
519 if (mkdir(dir, (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) < 0) {
520 ERR("Cannot mkdir %s", dir);
526 path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name);
527 netconfig_keyfile_save(keyfile, path);
535 static gboolean _remove_configuration(const gchar *interface_name, const gchar *config_id)
537 gboolean ret = FALSE;
541 ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX,
542 interface_name, config_id, &group_name);
544 ERR("Fail to get_wifi_config_group_name");
548 dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name);
549 if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) {
550 if (__remove_configuration(dir) != TRUE) {
551 ERR("[%s] is existed, but cannot remove", dir);
554 INFO("Success to remove [%s]", dir);
558 ERR("[%s] is not existed", dir);
569 static gboolean _set_field(const gchar *interface_name,
570 const gchar *config_id, const gchar *key, const gchar *value)
576 ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX,
577 interface_name, config_id, &group_name);
579 ERR("Fail to get_wifi_config_group_name");
582 DBG("group_name %s", group_name);
584 keyfile = __get_configuration_keyfile(group_name);
585 if (keyfile == NULL) {
586 ERR("Fail to __get_configuration_keyfile");
591 if (g_strcmp0(key, WIFI_CONFIG_PROXY_METHOD) == 0) {
592 g_key_file_set_string(keyfile, group_name, key, value);
593 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
594 g_key_file_set_string(keyfile, group_name, key, value);
595 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
596 gboolean hidden = FALSE;
597 if (g_strcmp0(value, "TRUE") == 0)
599 g_key_file_set_boolean(keyfile, group_name, key, hidden);
600 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
601 g_key_file_set_string(keyfile, group_name, key, value);
602 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
603 g_key_file_set_string(keyfile, group_name, key, value);
604 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
605 g_key_file_set_string(keyfile, group_name, key, value);
606 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
607 g_key_file_set_string(keyfile, group_name, key, value);
608 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
609 g_key_file_set_string(keyfile, group_name, key, value);
610 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
611 g_key_file_set_string(keyfile, group_name, key, value);
612 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
613 g_key_file_set_string(keyfile, group_name, key, value);
614 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
615 g_key_file_set_string(keyfile, group_name, key, value);
617 ERR("key[%s] is not supported", key);
621 wifi_config_save_configuration(interface_name, config_id, keyfile);
623 g_key_file_free(keyfile);
629 static gboolean _get_field(const gchar *interface_name,
630 const gchar *config_id, const gchar *key, gchar **value)
635 gboolean hidden = FALSE;
636 gboolean ret = FALSE;
638 ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX,
639 interface_name, config_id, &group_name);
641 ERR("Fail to get_wifi_config_group_name");
644 DBG("group_name %s", group_name);
646 keyfile = __get_configuration_keyfile(group_name);
647 if (keyfile == NULL) {
648 ERR("Fail to __get_configuration_keyfile");
653 if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) {
654 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL);
655 } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) {
656 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL);
657 } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) {
658 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL);
659 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
660 hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL);
662 val = g_strdup("TRUE");
664 val = g_strdup("FALSE");
665 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
666 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL);
667 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
668 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
669 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
670 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
671 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
672 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
673 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
674 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
675 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
676 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
677 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
678 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
679 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
680 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL);
681 } else if (g_strcmp0(key, WIFI_CONFIG_FAILURE) == 0) {
682 val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL);
684 ERR("Invalid key[%s]", key);
685 val = g_strdup("NOTSUPPORTED");
688 *value = g_strdup(val);
691 g_key_file_free(keyfile);
697 static GSList *_get_list(const char *mac_addr)
700 struct dirent *dp = NULL;
703 dir = opendir(CONNMAN_STORAGE);
705 ERR("Cannot open dir %s", CONNMAN_STORAGE);
709 while ((dp = readdir(dir)) != NULL) {
710 if (g_strcmp0(dp->d_name, ".") == 0 || g_strcmp0(dp->d_name, "..") == 0 ||
711 strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
715 DBG("%s", dp->d_name);
717 if (netconfig_check_mac_address(dp->d_name, mac_addr)) {
718 gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH);
719 DBG("%s", config_id);
720 list = g_slist_append(list, g_strdup(config_id));
729 gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id)
731 gboolean ret = FALSE;
734 if ((service_profile == NULL) || (config_id == NULL)) {
735 ERR("Invalid parameter");
739 ret = __get_config_id(service_profile, &val);
740 *config_id = g_strdup(val);
746 gboolean wifi_config_remove_configuration(const gchar *interface_name,
747 const gchar *config_id)
749 gboolean ret = FALSE;
751 ret = _remove_configuration(interface_name, config_id);
756 int __netconfig_hex_char_to_num(char c)
758 if (c >= '0' && c <= '9')
761 if (c >= 'a' && c <= 'f')
764 if (c >= 'A' && c <= 'F')
770 int __netconfig_hex_to_byte(const char *hex)
774 a = __netconfig_hex_char_to_num(*hex++);
778 b = __netconfig_hex_char_to_num(*hex++);
785 int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len)
789 const char *ipos = hex;
790 unsigned char *opos = buf;
792 for (i = 0; i < len; i++) {
793 a = __netconfig_hex_to_byte(ipos);
804 static int __netconfig_byte_to_txt(const unsigned char *src, char **dst, int src_len)
811 ERR("Invalid parameter.");
815 *dst = (char *) g_try_malloc0((2*src_len)+1);
817 ERR("failed to allocate memory to buffer.");
823 for (i = 0; i < src_len; i++) {
824 snprintf(buf, 3, "%02x", src[i]);
832 static int __netconfig_unpack_ay_malloc(unsigned char **dst, GVariantIter *iter)
834 GVariantIter *iter_copy = NULL;
837 unsigned char *tmp_dst = NULL;
839 if (!dst || *dst || !iter) {
840 ERR("Invalid parameter");
844 iter_copy = g_variant_iter_copy(iter);
846 while (g_variant_iter_loop(iter, "y", &tmp))
848 g_variant_iter_free(iter);
850 tmp_dst = (unsigned char *)g_try_malloc0(length + 1);
852 ERR("failed to allocate memory");
853 g_variant_iter_free(iter_copy);
858 while (g_variant_iter_loop(iter_copy, "y", &tmp_dst[length]))
860 g_variant_iter_free(iter_copy);
866 tmp_dst[length] = '\0';
870 DBG("Length [%d]", length);
874 gboolean _add_vsie(const char *interface_name, int frame_id, const char* vsie)
876 GVariant *params = NULL;
877 GVariant *message = NULL;
878 GVariantBuilder *bytearray_builder = NULL;
883 unsigned char *bytearray = NULL;
884 size_t bytearray_len = 0;
886 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
887 DBG("Invalid parameter, frame-id: %d", frame_id);
891 vsie_len = strlen(vsie);
893 DBG("vsie length is zero");
897 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
899 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
900 if (bytearray == NULL) {
901 DBG("Failed to allocate memory to bytearray");
905 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
906 DBG("invalid vsie string");
911 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
912 for (i = 0; i < bytearray_len; i++)
913 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
915 params = g_variant_new("(iay)", frame_id, bytearray_builder);
916 g_variant_builder_unref(bytearray_builder);
918 if_path = netconfig_wifi_get_supplicant_interface_path(interface_name);
919 if (if_path == NULL) {
920 ERR("Fail to get wpa_supplicant DBus path");
925 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
926 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemAdd", params);
929 if (message == NULL) {
930 ERR("Failed to send command to wpa_supplicant");
935 DBG("Succeeded to add vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
941 gboolean _get_vsie(const char *interface_name, int frame_id, char **vsie)
943 GVariant *params = NULL;
944 GVariant *message = NULL;
947 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
948 DBG("Invalid parameter, frame-id: %d", frame_id);
952 if_path = netconfig_wifi_get_supplicant_interface_path(interface_name);
953 if (if_path == NULL) {
954 ERR("Fail to get wpa_supplicant DBus path");
958 params = g_variant_new("(i)", frame_id);
960 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
961 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemGet", params);
964 if (message == NULL) {
965 ERR("Failed to send command to wpa_supplicant");
968 GVariantIter *iter = NULL;
969 unsigned char *vsie_bytes = NULL;
973 g_variant_get(message, "(ay)", &iter);
975 ERR("vsie is not present");
979 vsie_len = __netconfig_unpack_ay_malloc(&vsie_bytes, iter);
980 if (vsie_bytes == NULL) {
981 ERR("vsie_bytes not allocated");
985 ret = __netconfig_byte_to_txt(vsie_bytes, vsie, vsie_len);
988 ERR("vsie not allocated.");
995 ERR("Succeeded to get vsie: Frame ID[%d], VSIE[%s]", frame_id, *vsie);
1001 gboolean _remove_vsie(const char *interface_name, int frame_id, const char *vsie)
1003 GVariant *params = NULL;
1004 GVariant *message = NULL;
1005 GVariantBuilder *bytearray_builder = NULL;
1008 size_t vsie_len = 0;
1010 unsigned char *bytearray = NULL;
1011 size_t bytearray_len = 0;
1013 if (frame_id >= NETCONFIG_VSIE_FRAME_MAX) {
1014 DBG("Invalid parameter, frame-id: %d", frame_id);
1018 vsie_len = strlen(vsie);
1019 if (vsie_len == 0) {
1020 DBG("vsie length is zero");
1024 bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
1026 bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
1027 if (bytearray == NULL) {
1028 DBG("Failed to allocate memory to bytearray");
1032 if (__netconfig_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
1033 DBG("invalid vsie string");
1038 bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
1039 for (i = 0; i < bytearray_len; i++)
1040 g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
1042 params = g_variant_new("(iay)", frame_id, bytearray_builder);
1043 g_variant_builder_unref(bytearray_builder);
1045 if_path = netconfig_wifi_get_supplicant_interface_path(interface_name);
1046 if (if_path == NULL) {
1047 ERR("Fail to get wpa_supplicant DBus path");
1052 message = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
1053 if_path, SUPPLICANT_INTERFACE ".Interface", "VendorElemRem", params);
1056 if (message == NULL) {
1057 ERR("Failed to send command to wpa_supplicant");
1062 DBG("Succeeded to remove vsie: Frame ID[%d], VSIE[%s]", frame_id, vsie);
1069 gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context,
1070 const gchar *ifname)
1073 GSList *config_ids = NULL;
1075 gchar **result = NULL;
1076 const gchar *mac_addr = NULL;
1078 g_return_val_if_fail(wifi != NULL, TRUE);
1080 mac_addr = wifi_state_get_mac_address(ifname);
1082 ERR("Fail to get mac-address");
1083 netconfig_error_no_profile(context);
1087 DBG("%s", mac_addr);
1088 config_ids = _get_list(mac_addr);
1089 if (config_ids == NULL) {
1090 ERR("Fail to get config list");
1091 netconfig_error_no_profile(context);
1095 length = g_slist_length(config_ids);
1096 result = g_new0(gchar *, length + 1);
1097 for (i = 0; i < length; i++) {
1098 gchar *config_id = g_slist_nth_data(config_ids, i);
1099 result[i] = g_strdup(config_id);
1102 config_ids = g_slist_nth(config_ids, 0);
1103 g_slist_free_full(config_ids, g_free);
1105 wifi_complete_get_config_ids(wifi, context, (const gchar * const *)result);
1107 for (i = 0; i < length; i++)
1117 gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1118 const gchar *ifname, const gchar *config_id)
1120 gboolean ret = FALSE;
1121 GVariantBuilder *b = NULL;
1122 struct wifi_config *conf = NULL;
1124 g_return_val_if_fail(wifi != NULL, TRUE);
1126 conf = g_new0(struct wifi_config, 1);
1127 conf->ip_info = g_new0(wifi_ip_info_s, 1);
1129 ret = _load_configuration(ifname, config_id, conf);
1131 g_free(conf->ip_info);
1133 ERR("Fail to _load_configuration");
1134 netconfig_error_no_profile(context);
1138 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1139 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
1140 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
1141 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PASSPHRASE, g_variant_new_string(conf->passphrase));
1142 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
1143 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FREQUENCY, g_variant_new_int32(conf->frequency));
1145 if (conf->proxy_address != NULL)
1146 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
1148 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
1150 if (conf->ip_info->ip_type != NULL)
1151 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_METHOD, g_variant_new_string(conf->ip_info->ip_type));
1153 if (conf->ip_info->ip_address != NULL)
1154 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_ADDRESS, g_variant_new_string(conf->ip_info->ip_address));
1156 if (conf->ip_info->subnet_mask != NULL)
1157 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_SUBNET_MASK, g_variant_new_string(conf->ip_info->subnet_mask));
1159 if (conf->ip_info->prefix_length > 0)
1160 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV6_PREFIX_LEN, g_variant_new_int32(conf->ip_info->prefix_length));
1162 if (conf->ip_info->gateway_address != NULL)
1163 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_GATEWAY_ADDRESS, g_variant_new_string(conf->ip_info->gateway_address));
1165 if (conf->ip_info->dns_type != NULL)
1166 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_DNS_METHOD, g_variant_new_string(conf->ip_info->dns_type));
1168 int i = 0, count = conf->ip_info->dns_count;
1170 if (conf->ip_info->dns_address[i] != NULL)
1171 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_DNS_ADDRESS, g_variant_new_string(conf->ip_info->dns_address[i]));
1176 if (conf->last_error != NULL)
1177 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
1179 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
1181 __free_wifi_configuration(conf);
1183 INFO("Success to load configuration [%s:%s]", ifname, config_id);
1185 wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b));
1186 g_variant_builder_unref(b);
1190 static unsigned char __netconfig_convert_netmask_to_prefixlen(
1191 const char *netmask)
1200 mask = inet_network(netmask);
1203 /* a valid netmask must be 2^n - 1 */
1204 if ((host & (host + 1)) != 0)
1208 for (; mask; mask <<= 1)
1214 gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1215 const gchar *ifname, const gchar *config_id, GVariant *configuration)
1217 gboolean ret = FALSE;
1218 struct wifi_config *conf = NULL;
1219 GKeyFile *keyfile = NULL;
1223 gchar *group_name = NULL;
1226 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1227 ERR("Invalid parameter");
1228 netconfig_error_invalid_parameter(context);
1232 conf = g_new0(struct wifi_config, 1);
1233 conf->ip_info = g_new0(wifi_ip_info_s, 1);
1235 g_variant_get(configuration, "a{sv}", &iter);
1236 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1237 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1238 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1239 conf->name = g_strdup(g_variant_get_string(value, NULL));
1240 DBG("name [%s]", conf->name);
1244 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1245 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1246 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1247 DBG("ssid [%s]", conf->ssid);
1251 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1252 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1253 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1254 DBG("passphrase []");
1256 conf->passphrase = NULL;
1258 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1259 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1260 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1261 DBG("is_hidden [%s]", conf->is_hidden);
1263 conf->is_hidden = NULL;
1265 } else if (g_strcmp0(field, WIFI_CONFIG_FREQUENCY) == 0) {
1266 if (g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
1267 conf->frequency = g_variant_get_uint32(value);
1268 DBG("frequency [%d]", conf->frequency);
1270 conf->frequency = 0;
1272 } else if (g_strcmp0(field, WIFI_CONFIG_CREATED) == 0) {
1273 if (g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) {
1274 conf->is_created = g_variant_get_boolean(value);
1275 DBG("is_created [%d]", conf->is_created);
1277 conf->is_created = FALSE;
1279 } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_METHOD) == 0) {
1280 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1281 conf->ip_info->ip_type = g_strdup(g_variant_get_string(value, NULL));
1282 DBG("IP config type [%s]", conf->ip_info->ip_type);
1284 conf->ip_info->ip_type = NULL;
1286 } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_ADDRESS) == 0) {
1287 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1288 conf->ip_info->ip_address = g_strdup(g_variant_get_string(value, NULL));
1289 DBG("IP address [%s]", conf->ip_info->ip_address);
1291 conf->ip_info->ip_address = NULL;
1293 } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_SUBNET_MASK) == 0) {
1294 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1295 conf->ip_info->subnet_mask = g_strdup(g_variant_get_string(value, NULL));
1296 DBG("Subnet Mask [%s]", conf->ip_info->subnet_mask);
1298 conf->ip_info->subnet_mask = NULL;
1300 } else if (g_strcmp0(field, WIFI_CONFIG_IPV6_PREFIX_LEN) == 0) {
1301 if (g_variant_is_of_type(value, G_VARIANT_TYPE_INT32)) {
1302 conf->ip_info->prefix_length = g_variant_get_int32(value);
1303 DBG("IPv6 Prefix Length [%d]", conf->ip_info->prefix_length);
1305 conf->ip_info->prefix_length = 0;
1307 } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_GATEWAY_ADDRESS) == 0) {
1308 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1309 conf->ip_info->gateway_address = g_strdup(g_variant_get_string(value, NULL));
1310 DBG("Gateway address [%s]", conf->ip_info->gateway_address);
1312 conf->ip_info->gateway_address = NULL;
1314 } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_DNS_METHOD) == 0) {
1315 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1316 conf->ip_info->dns_type = g_strdup(g_variant_get_string(value, NULL));
1317 DBG("DNS config type [%s]", conf->ip_info->dns_type);
1319 conf->ip_info->dns_type = NULL;
1321 } else if (g_strcmp0(field, WIFI_CONFIG_DNS_ADDRESS) == 0) {
1322 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1323 conf->ip_info->dns_address[order] = g_strdup(g_variant_get_string(value, NULL));
1324 DBG("DNS address [%s]", conf->ip_info->dns_address[order]);
1325 conf->ip_info->dns_count = order + 1;
1328 conf->ip_info->dns_address[order++] = NULL;
1330 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1331 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1332 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1333 DBG("proxy_address [%s]", conf->proxy_address);
1335 conf->proxy_address = NULL;
1339 conf->favorite = TRUE;
1340 conf->autoconnect = TRUE;
1342 ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX,
1343 ifname, config_id, &group_name);
1345 __free_wifi_configuration(conf);
1346 ERR("Fail to get_wifi_config_group_name");
1347 netconfig_error_fail_save_congifuration(context);
1351 keyfile = g_key_file_new();
1352 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1353 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1355 if (conf->passphrase != NULL) {
1356 gchar *enc_data = NULL;
1358 if (conf->is_created == true)
1359 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1361 enc_data = g_strdup(conf->passphrase);
1364 ERR("Failed to encrypt the passphrase");
1366 g_free(conf->passphrase);
1367 conf->passphrase = enc_data;
1370 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1373 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1374 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1376 #if GLIB_CHECK_VERSION(2,62,0)
1377 gint64 real_time = 0;
1378 GDateTime *dt_real_time = NULL;
1380 real_time = g_get_real_time();
1381 dt_real_time = g_date_time_new_from_unix_utc(real_time);
1383 gchar *str = g_date_time_format_iso8601(dt_real_time);
1384 g_date_time_unref(dt_real_time);
1386 g_key_file_set_string(keyfile, group_name,
1387 WIFI_CONFIG_MODIFIED, str);
1391 #else /* GLIB_CHECK_VERSION(2,62,0) */
1393 g_get_current_time(&modified);
1394 gchar *str = g_time_val_to_iso8601(&modified);
1396 g_key_file_set_string(keyfile, group_name,
1397 WIFI_CONFIG_MODIFIED, str);
1400 #endif /* GLIB_CHECK_VERSION(2,62,0) */
1402 /* Optional field */
1403 if (conf->proxy_address != NULL) {
1404 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1405 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1408 if (conf->is_hidden != NULL) {
1409 gboolean hidden = FALSE;
1410 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1412 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1415 if (conf->frequency > 0)
1416 g_key_file_set_integer(keyfile, group_name,
1417 WIFI_CONFIG_FREQUENCY, conf->frequency);
1419 if (conf->ip_info->ip_type != NULL)
1420 g_key_file_set_string(keyfile, group_name,
1421 WIFI_CONFIG_IPV4_METHOD, conf->ip_info->ip_type);
1423 if (conf->ip_info->ip_address != NULL)
1424 g_key_file_set_string(keyfile, group_name,
1425 WIFI_CONFIG_IPV4_ADDRESS, conf->ip_info->ip_address);
1427 if (conf->ip_info->subnet_mask != NULL) {
1428 unsigned char prefix_len;
1429 prefix_len = __netconfig_convert_netmask_to_prefixlen(
1430 conf->ip_info->subnet_mask);
1431 if (prefix_len > 0 && prefix_len < 32)
1432 g_key_file_set_integer(keyfile, group_name,
1433 WIFI_CONFIG_IPV4_SUBNET_MASK, prefix_len);
1436 if (conf->ip_info->prefix_length > 0)
1437 g_key_file_set_integer(keyfile, group_name,
1438 WIFI_CONFIG_IPV6_PREFIX_LEN, conf->ip_info->prefix_length);
1440 if (conf->ip_info->gateway_address != NULL)
1441 g_key_file_set_string(keyfile, group_name,
1442 WIFI_CONFIG_IPV4_GATEWAY_ADDRESS, conf->ip_info->gateway_address);
1444 if (conf->ip_info->dns_type != NULL)
1445 g_key_file_set_string(keyfile, group_name,
1446 WIFI_CONFIG_IPV4_DNS_METHOD, conf->ip_info->dns_type);
1448 int i = 0, count = conf->ip_info->dns_count;
1450 if (conf->ip_info->dns_address[i] != NULL)
1451 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_DNS_ADDRESS,
1452 conf->ip_info->dns_address[i]);
1457 ret = wifi_config_save_configuration(ifname, config_id, keyfile);
1459 INFO("Success to save configuration [%s]", config_id);
1460 wifi_complete_save_configuration(wifi, context);
1462 if (get_files_count(CONNMAN_STORAGE) > MAX_WIFI_PROFILES) {
1463 file = get_least_recently_profile(CONNMAN_STORAGE);
1465 gchar *profileName = g_strdup_printf(CONNMAN_STORAGE "/%s", file);
1466 INFO("least modified file: %s", profileName);
1468 if (__remove_configuration(profileName) != TRUE)
1469 DBG("Failed to remove profile: [%s]", profileName);
1471 ERR("Profile: [%s] does not exist", file);
1473 g_free(profileName);
1477 INFO("Fail to save configuration [%s]", config_id);
1478 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");
1481 g_key_file_free(keyfile);
1483 __free_wifi_configuration(conf);
1485 g_variant_iter_free(iter);
1490 gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1491 const gchar *ifname, const gchar *config_id)
1493 gboolean ret = FALSE;
1494 GVariantBuilder *b = NULL;
1495 struct wifi_config *conf = NULL;
1497 g_return_val_if_fail(wifi != NULL, TRUE);
1499 conf = g_new0(struct wifi_config, 1);
1500 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1501 conf->ip_info = g_new0(wifi_ip_info_s, 1);
1503 ret = _load_configuration(ifname, config_id, conf);
1505 g_free(conf->eap_config);
1506 g_free(conf->ip_info);
1508 ERR("Fail to _load_configuration");
1509 netconfig_error_no_profile(context);
1513 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1514 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name));
1515 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type));
1516 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden));
1517 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FREQUENCY, g_variant_new_int32(conf->frequency));
1519 if (conf->proxy_address != NULL)
1520 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address));
1522 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE"));
1524 if (conf->last_error != NULL)
1525 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error));
1527 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE"));
1529 if (conf->eap_config != NULL) {
1530 if (conf->eap_config->anonymous_identity != NULL)
1531 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity));
1533 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE"));
1535 if (conf->eap_config->ca_cert != NULL)
1536 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert));
1538 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE"));
1540 if (conf->eap_config->client_cert != NULL)
1541 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert));
1543 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE"));
1545 if (conf->eap_config->private_key != NULL)
1546 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key));
1548 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
1550 if (conf->eap_config->private_key_password != NULL)
1551 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, g_variant_new_string(conf->eap_config->private_key_password));
1553 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, g_variant_new_string("NONE"));
1555 if (conf->eap_config->identity != NULL)
1556 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
1558 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE"));
1560 if (conf->eap_config->eap_type != NULL)
1561 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type));
1563 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE"));
1565 if (conf->eap_config->eap_auth_type != NULL)
1566 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type));
1568 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE"));
1570 if (conf->eap_config->subject_match != NULL)
1571 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match));
1573 g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE"));
1576 __free_wifi_configuration(conf);
1578 wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b));
1579 g_variant_builder_unref(b);
1583 gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1584 const gchar *ifname, const gchar *config_id, GVariant *configuration)
1586 gboolean ret = FALSE;
1587 struct wifi_config *conf = NULL;
1588 GKeyFile *keyfile = NULL;
1592 gchar *group_name = NULL;
1594 if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
1595 ERR("Invalid parameter");
1596 netconfig_error_invalid_parameter(context);
1600 conf = g_new0(struct wifi_config, 1);
1601 conf->eap_config = g_new0(struct wifi_eap_config, 1);
1603 g_variant_get(configuration, "a{sv}", &iter);
1604 while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
1605 if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) {
1606 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1607 conf->name = g_strdup(g_variant_get_string(value, NULL));
1608 DBG("name [%s]", conf->name);
1612 } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) {
1613 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1614 conf->ssid = g_strdup(g_variant_get_string(value, NULL));
1615 DBG("ssid [%s]", conf->ssid);
1619 } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) {
1620 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1621 conf->passphrase = g_strdup(g_variant_get_string(value, NULL));
1622 DBG("passphrase [%s]", conf->passphrase);
1624 conf->passphrase = NULL;
1626 } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) {
1627 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1628 conf->is_hidden = g_strdup(g_variant_get_string(value, NULL));
1629 DBG("is_hidden [%s]", conf->is_hidden);
1631 conf->is_hidden = NULL;
1633 } else if (g_strcmp0(field, WIFI_CONFIG_FREQUENCY) == 0) {
1634 if (g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
1635 conf->frequency = g_variant_get_uint32(value);
1636 DBG("frequency [%d]", conf->frequency);
1638 conf->frequency = 0;
1640 } else if (g_strcmp0(field, WIFI_CONFIG_CREATED) == 0) {
1641 if (g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) {
1642 conf->is_created = g_variant_get_boolean(value);
1643 DBG("is_created [%d]", conf->is_created);
1645 conf->is_created = FALSE;
1647 } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) {
1648 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1649 conf->proxy_address = g_strdup(g_variant_get_string(value, NULL));
1650 DBG("proxy_address [%s]", conf->proxy_address);
1652 conf->proxy_address = NULL;
1654 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1655 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1656 conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL));
1657 DBG("anonymous_identity [%s]", conf->eap_config->anonymous_identity);
1659 conf->eap_config->anonymous_identity = NULL;
1661 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) {
1662 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1663 conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL));
1664 DBG("ca_cert [%s]", conf->eap_config->ca_cert);
1666 conf->eap_config->ca_cert = NULL;
1668 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1669 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1670 conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL));
1671 DBG("client_cert [%s]", conf->eap_config->client_cert);
1673 conf->eap_config->client_cert = NULL;
1675 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1676 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1677 conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL));
1678 DBG("private_key [%s]", conf->eap_config->private_key);
1680 conf->eap_config->private_key = NULL;
1682 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD) == 0) {
1683 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1684 conf->eap_config->private_key_password = g_strdup(g_variant_get_string(value, NULL));
1685 DBG("private_key_password[%s]", conf->eap_config->private_key_password);
1687 conf->eap_config->private_key_password = NULL;
1689 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1690 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1691 conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
1692 DBG("identity [%s]", conf->eap_config->identity);
1694 conf->eap_config->identity = NULL;
1696 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) {
1697 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1698 conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL));
1699 DBG("eap_type [%s]", conf->eap_config->eap_type);
1701 conf->eap_config->eap_type = NULL;
1703 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1704 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1705 conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL));
1706 DBG("eap_auth_type [%s]", conf->eap_config->eap_auth_type);
1708 conf->eap_config->eap_auth_type = NULL;
1710 } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1711 if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
1712 conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL));
1713 DBG("subject_match [%s]", conf->eap_config->subject_match);
1715 conf->eap_config->subject_match = NULL;
1719 conf->favorite = TRUE;
1720 conf->autoconnect = TRUE;
1722 ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX,
1723 ifname, config_id, &group_name);
1725 __free_wifi_configuration(conf);
1726 ERR("Fail to get_wifi_config_group_name");
1730 keyfile = g_key_file_new();
1731 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name);
1732 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid);
1734 if (conf->passphrase != NULL) {
1735 gchar *enc_data = NULL;
1737 if (conf->is_created == true)
1738 enc_data = _netconfig_encrypt_passphrase(conf->passphrase);
1740 enc_data = g_strdup(conf->passphrase);
1743 ERR("Failed to encrypt the passphrase");
1745 g_free(conf->passphrase);
1746 conf->passphrase = enc_data;
1748 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase);
1751 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
1752 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
1754 /* Optional field */
1755 if (conf->proxy_address != NULL) {
1756 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
1757 g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address);
1760 if (conf->is_hidden != NULL) {
1761 gboolean hidden = FALSE;
1762 if (g_strcmp0(conf->is_hidden, "TRUE") == 0)
1764 g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden);
1767 if (conf->frequency > 0)
1768 g_key_file_set_integer(keyfile, group_name,
1769 WIFI_CONFIG_FREQUENCY, conf->frequency);
1771 if (conf->eap_config->anonymous_identity != NULL)
1772 g_key_file_set_string(keyfile, group_name,
1773 WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, conf->eap_config->anonymous_identity);
1775 if (conf->eap_config->ca_cert != NULL)
1776 g_key_file_set_string(keyfile, group_name,
1777 WIFI_CONFIG_EAP_CACERT, conf->eap_config->ca_cert);
1779 if (conf->eap_config->client_cert != NULL)
1780 g_key_file_set_string(keyfile, group_name,
1781 WIFI_CONFIG_EAP_CLIENTCERT, conf->eap_config->client_cert);
1783 if (conf->eap_config->private_key != NULL)
1784 g_key_file_set_string(keyfile, group_name,
1785 WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
1787 if (conf->eap_config->private_key_password != NULL)
1788 g_key_file_set_string(keyfile, group_name,
1789 WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, conf->eap_config->private_key_password);
1791 if (conf->eap_config->identity != NULL)
1792 g_key_file_set_string(keyfile, group_name,
1793 WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);
1795 if (conf->eap_config->eap_type != NULL)
1796 g_key_file_set_string(keyfile, group_name,
1797 WIFI_CONFIG_EAP_TYPE, conf->eap_config->eap_type);
1799 if (conf->eap_config->eap_auth_type != NULL)
1800 g_key_file_set_string(keyfile, group_name,
1801 WIFI_CONFIG_EAP_AUTH_TYPE, conf->eap_config->eap_auth_type);
1803 if (conf->eap_config->subject_match != NULL)
1804 g_key_file_set_string(keyfile, group_name,
1805 WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match);
1807 ret = wifi_config_save_configuration(ifname, config_id, keyfile);
1809 INFO("Success to save eap configuration [%s]", config_id);
1810 wifi_complete_save_eap_configuration(wifi, context);
1812 INFO("Fail to save eap configuration [%s]", config_id);
1813 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration");
1816 g_key_file_free(keyfile);
1818 __free_wifi_configuration(conf);
1820 g_variant_iter_free(iter);
1825 gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context,
1826 const gchar *ifname, const gchar *config_id)
1828 gboolean ret = FALSE;
1830 if ((wifi == NULL) || (config_id == NULL)) {
1831 ERR("Invalid parameter");
1832 netconfig_error_invalid_parameter(context);
1836 ret = _remove_configuration(ifname, config_id);
1838 /* no configuration or error */
1839 ERR("No [%s] configuration", config_id);
1840 netconfig_error_no_profile(context);
1844 wifi_complete_remove_configuration(wifi, context);
1848 gboolean handle_reset_wifi_config(Wifi *wifi, GDBusMethodInvocation *context)
1850 DIR *dir_ptr = NULL;
1851 struct dirent *file = NULL;
1853 char dir_name[512] = { 0, };
1854 char file_name[1024] = { 0, };
1856 g_return_val_if_fail(wifi != NULL, TRUE);
1858 DBG("Try to remove connman Wi-Fi config files...");
1860 if ((dir_ptr = opendir(CONNMAN_STORAGE)) != NULL) {
1861 while ((file = readdir(dir_ptr)) != NULL) {
1862 if (strncmp(file->d_name, ".", 1) == 0 || strncmp(file->d_name, "..", 2) == 0 ||
1863 strncmp(file->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) {
1867 snprintf(dir_name, 512, CONNMAN_STORAGE"/%s", file->d_name);
1869 if (lstat(dir_name, &buf) == -1)
1872 DBG("Remove wifi config: %s", file->d_name);
1874 if (S_ISDIR(buf.st_mode)) {
1875 memset(file_name, 0, 1024);
1876 snprintf(file_name, 1024, "%s/data", dir_name);
1878 memset(file_name, 0, 1024);
1879 snprintf(file_name, 1024, "%s/settings", dir_name);
1889 wifi_complete_reset_wifi_config(wifi, context);
1894 /* config field key / value */
1896 * [wifi_macaddress_config_id]
1897 * Name=name (mandatory)
1898 * SSID=SSID (mandatory)
1899 * Frequency=2462 (X)
1901 * AutoConnect=true (Default true)
1902 * Modified=2015-03-20 (X)
1903 * IPv4.method=manual (O)
1904 * IPv4.DHCP.LastAddress=192.0.0.1 (X)
1905 * IPv6.method=auto (X)
1906 * IPv6.privacy=disabled (X)
1907 * IPv4.netmask_prefixlen=24 (X)
1908 * IPv4.local_address=192.0.0.1 (O)
1909 * IPv4.gateway=192.0.0.1 (O ? X ?)
1910 * Nameservers=192.168.43.22; (O)
1911 * Proxy.Method=manual (O)
1912 * Proxy.Servers=trst.com:8888; (O)
1914 gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context,
1915 const gchar *ifname, const gchar *config_id, const gchar *key, const gchar *value)
1917 gboolean ret = FALSE;
1918 gchar *keyfile_key = NULL;
1920 g_return_val_if_fail(wifi != NULL, TRUE);
1921 g_return_val_if_fail(config_id != NULL, TRUE);
1922 g_return_val_if_fail(key != NULL, TRUE);
1924 DBG("Key[%s] Value[%s]", key, value);
1926 if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) {
1927 ret = _set_field(ifname, config_id, WIFI_CONFIG_PROXY_METHOD, "manual");
1929 ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD);
1930 netconfig_error_invalid_parameter(context);
1933 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER);
1934 } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) {
1935 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN);
1936 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) {
1937 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY);
1938 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) {
1939 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT);
1940 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) {
1941 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT);
1942 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) {
1943 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY);
1944 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) {
1945 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY);
1946 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) {
1947 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE);
1948 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) {
1949 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE);
1950 } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) {
1951 keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH);
1953 ERR("Not supported key[%s]", key);
1954 netconfig_error_invalid_parameter(context);
1958 ret = _set_field(ifname, config_id, keyfile_key, (const gchar *)value);
1960 ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value);
1963 if (keyfile_key != NULL)
1964 g_free(keyfile_key);
1966 wifi_complete_set_config_field(wifi, context);
1970 gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context,
1971 const gchar *ifname, const gchar *config_id)
1973 gboolean ret = FALSE;
1974 gchar *passphrase = NULL;
1976 if ((wifi == NULL) || (config_id == NULL)) {
1977 ERR("Invalid parameter");
1978 netconfig_error_invalid_parameter(context);
1982 ret = _get_field(ifname, config_id, WIFI_CONFIG_PASSPHRASE, &passphrase);
1984 ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE);
1985 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
1989 wifi_complete_get_config_passphrase(wifi, context, passphrase);
1995 gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context,
1996 const gchar *ifname, int frame_id, const gchar *vsie)
1998 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
2000 g_return_val_if_fail(wifi != NULL, TRUE);
2001 g_return_val_if_fail(vsie != NULL, TRUE);
2003 gboolean ret = FALSE;
2005 ret = _add_vsie(ifname, frame_id, vsie);
2007 DBG("Failed to add vsie: %s", vsie);
2008 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
2012 wifi_complete_add_vsie(wifi, context);
2016 gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context,
2017 const gchar *ifname, int frame_id)
2019 DBG("Frame ID: [%d]", frame_id);
2021 g_return_val_if_fail(wifi != NULL, TRUE);
2023 gboolean ret = FALSE;
2026 ret = _get_vsie(ifname, frame_id, &vsie);
2028 DBG("Failed to get vsie for frame:[%d]", frame_id);
2029 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
2033 DBG("Received vsie: %s", vsie);
2034 wifi_complete_get_vsie(wifi, context, vsie);
2039 gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context,
2040 const gchar *ifname, int frame_id, const gchar *vsie)
2042 DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie);
2044 g_return_val_if_fail(wifi != NULL, TRUE);
2045 g_return_val_if_fail(vsie != NULL, TRUE);
2047 gboolean ret = FALSE;
2049 ret = _remove_vsie(ifname, frame_id, vsie);
2051 DBG("Failed to remove vsie: %s", vsie);
2052 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed");
2056 wifi_complete_remove_vsie(wifi, context);