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.
28 #include <net/route.h>
29 #include <arpa/inet.h>
32 #include <sys/ioctl.h>
33 #include <vconf-keys.h>
34 #include <syspopup_caller.h>
36 #include <bundle_internal.h>
37 #include <eventsystem.h>
38 #include <tzplatform_config.h>
43 #include "wifi-state.h"
45 #define MAC_INFO_FILEPATH tzplatform_mkpath(TZ_SYS_ETC, "/.mac.info")
46 #define MAC_ADDRESS_MAX_LEN 18
48 static gboolean netconfig_device_picker_test = FALSE;
49 static int mdnsd_ref_count = 0;
51 GKeyFile *netconfig_keyfile_load(const char *pathname)
53 GKeyFile *keyfile = NULL;
56 keyfile = g_key_file_new();
57 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
58 DBG("Unable to open %s, error %s", pathname, error->message);
61 g_key_file_free(keyfile);
65 DBG("loaded keyfile %s", pathname);
69 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
73 gchar *keydata = NULL;
74 gchar *needle = NULL, *directory = NULL;
76 directory = g_strdup(pathname);
77 needle = g_strrstr(directory, "/");
82 if (directory == NULL || (*directory) == '\0') {
84 ERR("directory is NULL");
88 if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
89 if (g_mkdir_with_parents(directory,
90 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
92 ERR("failed to make directory");
98 keydata = g_key_file_to_data(keyfile, &size, &error);
99 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
100 ERR("Unable to save %s, error %s", pathname, error->message);
104 chmod(pathname, S_IRUSR | S_IWUSR);
105 DBG("Successfully saved keyfile %s", pathname);
110 void netconfig_start_timer_seconds(guint secs,
111 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
115 if (callback == NULL) {
116 ERR("callback function is NULL");
120 if ((timer_id != NULL && *timer_id != 0)) {
121 ERR("timer already is registered");
125 t_id = g_timeout_add_seconds(secs, callback, user_data);
128 ERR("Can't add timer");
132 if (timer_id != NULL)
136 void netconfig_start_timer(guint msecs,
137 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
141 INFO("Register timer with callback pointer (%p)", callback);
143 if (callback == NULL) {
144 ERR("callback function is NULL");
148 if ((timer_id != NULL && *timer_id != 0)) {
149 ERR("timer already is registered");
153 t_id = g_timeout_add(msecs, callback, user_data);
156 ERR("Can't add timer");
160 if (timer_id != NULL)
164 void netconfig_stop_timer(guint *timer_id)
166 if (timer_id == NULL) {
167 ERR("timer is NULL");
171 if (*timer_id != 0) {
172 g_source_remove(*timer_id);
177 static gboolean __netconfig_test_device_picker()
179 char *favorite_wifi_service = NULL;
181 favorite_wifi_service = wifi_get_favorite_service();
182 if (favorite_wifi_service != NULL) {
183 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
184 g_free(favorite_wifi_service);
191 static void __netconfig_pop_device_picker(void)
193 #if defined TIZEN_WEARABLE
195 app_control_h control = NULL;
197 ret = app_control_create(&control);
198 if (APP_CONTROL_ERROR_NONE != ret) {
199 DBG("failed to create app control");
203 app_control_add_extra_data(control, "viewtype", "scanlist");
205 app_control_set_app_id(control, "org.tizen.wifi");
206 ret = app_control_send_launch_request(control, NULL, NULL);
207 if (APP_CONTROL_ERROR_NONE == ret)
208 DBG("Launch request sent successfully");
210 app_control_destroy(control);
213 int wifi_ug_state = 0;
215 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
216 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
221 DBG("Launch Wi-Fi device picker");
222 syspopup_launch("wifi-qs", b);
228 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
230 if (__netconfig_test_device_picker() == TRUE)
231 __netconfig_pop_device_picker();
236 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
238 static guint netconfig_wifi_device_picker_service_timer = 0;
240 if (is_set_method != TRUE)
241 return netconfig_wifi_device_picker_service_timer;
243 if (netconfig_wifi_device_picker_service_timer != timer_id)
244 netconfig_wifi_device_picker_service_timer = timer_id;
246 return netconfig_wifi_device_picker_service_timer;
249 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
251 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
254 static guint __netconfig_wifi_device_picker_get_timer_id(void)
256 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
259 void netconfig_wifi_enable_device_picker_test(void)
261 netconfig_device_picker_test = TRUE;
264 void netconfig_wifi_device_picker_service_start(void)
266 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
269 if (netconfig_device_picker_test == TRUE)
270 netconfig_device_picker_test = FALSE;
276 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
277 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
280 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
281 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
283 __netconfig_wifi_device_picker_set_timer_id(timer_id);
286 void netconfig_wifi_device_picker_service_stop(void)
290 timer_id = __netconfig_wifi_device_picker_get_timer_id();
294 DBG("Clear device picker timer with timer_id %d", timer_id);
296 netconfig_stop_timer(&timer_id);
298 __netconfig_wifi_device_picker_set_timer_id(timer_id);
301 gboolean netconfig_is_wifi_direct_on(void)
303 #if defined TIZEN_P2P_ENABLE
304 int wifi_direct_state = 0;
306 netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
308 DBG("Wi-Fi direct mode %d", wifi_direct_state);
309 return (wifi_direct_state != 0) ? TRUE : FALSE;
315 gboolean netconfig_is_wifi_tethering_on(void)
317 #if defined TIZEN_TETHERING_ENABLE
318 int wifi_tethering_state = 0;
320 netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
321 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
322 if (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
328 gboolean netconfig_interface_up(const char *ifname)
333 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
337 memset(&ifr, 0, sizeof(ifr));
338 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
340 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
345 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
346 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
353 DBG("Successfully activated wireless interface");
357 gboolean netconfig_interface_down(const char *ifname)
362 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
366 memset(&ifr, 0, sizeof(ifr));
367 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
369 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
374 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
375 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
382 DBG("Successfully de-activated wireless interface");
386 int netconfig_execute_file(const char *file_path,
387 char *const args[], char *const envs[])
393 register unsigned int index = 0;
394 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
396 while (args[index] != NULL) {
397 DBG("%s", args[index]);
401 if (!(pid = fork())) {
402 DBG("pid(%d), ppid (%d)", getpid(), getppid());
403 DBG("Inside child, exec (%s) command", file_path);
406 if (execve(file_path, args, envs) == -1) {
407 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
408 DBG("Fail to execute command (%s)", error_buf);
411 } else if (pid > 0) {
412 if (waitpid(pid, &status, 0) == -1)
413 DBG("wait pid (%u) status (%d)", pid, status);
415 if (WIFEXITED(status)) {
416 rv = WEXITSTATUS(status);
417 DBG("exited, status=%d", rv);
418 } else if (WIFSIGNALED(status)) {
419 DBG("killed by signal %d", WTERMSIG(status));
420 } else if (WIFSTOPPED(status)) {
421 DBG("stopped by signal %d", WSTOPSIG(status));
422 } else if (WIFCONTINUED(status)) {
429 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
430 DBG("failed to fork(%s)", error_buf);
434 static void on_clat_handler()
439 clat_pid = waitpid(-1, &state, WNOHANG);
441 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
444 int netconfig_execute_clatd(const char *file_path, char *const args[])
449 register unsigned int index = 0;
450 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
452 struct sigaction act;
455 act.sa_handler = on_clat_handler;
456 sigemptyset(&act.sa_mask);
459 state = sigaction(SIGCHLD, &act, 0);
461 DBG("sigaction() : %d");
465 while (args[index] != NULL) {
466 DBG("%s", args[index]);
470 if (!(pid = fork())) {
471 DBG("pid(%d), ppid (%d)", getpid(), getppid());
472 DBG("Inside child, exec (%s) command", file_path);
475 if (execvp(file_path, args) == -1) {
476 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
477 ERR("Fail to execute command (%s)", error_buf);
480 } else if (pid > 0) {
481 ERR("Success to launch clatd");
485 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
486 DBG("failed to fork(%s)", error_buf);
490 int __netconfig_get_interface_index(const char *interface_name)
495 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
497 if (interface_name == NULL) {
498 DBG("Inteface name is NULL");
503 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
505 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
506 DBG("Failed to create socket : %s", error_buf);
510 memset(&ifr, 0, sizeof(ifr));
511 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
512 result = ioctl(sock, SIOCGIFINDEX, &ifr);
516 DBG("Failed to get ifr index: %s", error_buf);
520 return ifr.ifr_ifindex;
523 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
527 struct sockaddr_in addr_in;
529 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
531 memset(&ifr, 0, sizeof(ifr));
533 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
535 if (ifr.ifr_ifindex < 0)
538 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
540 memset(&rt, 0, sizeof(rt));
542 rt.rt_flags = RTF_UP | RTF_HOST;
543 memset(&addr_in, 0, sizeof(struct sockaddr_in));
544 addr_in.sin_family = address_family;
545 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
546 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
548 memset(&addr_in, 0, sizeof(struct sockaddr_in));
549 addr_in.sin_family = address_family;
550 addr_in.sin_addr.s_addr = INADDR_ANY;
551 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
553 memset(&addr_in, 0, sizeof(struct sockaddr_in));
554 addr_in.sin_family = AF_INET;
555 addr_in.sin_addr.s_addr = inet_addr(subnet);
556 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
558 rt.rt_dev = ifr.ifr_name;
561 sock = socket(PF_INET, SOCK_DGRAM, 0);
564 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
565 DBG("Failed to create socket : %s", error_buf);
569 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
570 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
571 DBG("Failed to set route address : %s", error_buf);
581 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
585 struct sockaddr_in addr_in;
587 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
589 memset(&ifr, 0, sizeof(ifr));
590 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
592 if (ifr.ifr_ifindex < 0)
595 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
597 memset(&rt, 0, sizeof(rt));
599 rt.rt_flags = RTF_UP;
600 memset(&addr_in, 0, sizeof(struct sockaddr_in));
601 addr_in.sin_family = address_family;
602 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
603 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
605 memset(&addr_in, 0, sizeof(struct sockaddr_in));
606 addr_in.sin_family = address_family;
607 addr_in.sin_addr.s_addr = inet_addr(subnet);
608 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
609 rt.rt_dev = ifr.ifr_name;
612 sock = socket(PF_INET, SOCK_DGRAM, 0);
615 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
616 DBG("Failed to create socket : %s", error_buf);
620 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
621 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
622 DBG("Failed to set route address : %s", error_buf);
632 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
637 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
639 memset(&rt, 0, sizeof(rt));
641 rt.rtmsg_dst_len = prefix_len;
643 rt.rtmsg_flags = RTF_UP | RTF_HOST;
646 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
647 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
648 DBG("inet_pton failed : %s", error_buf);
652 if (gateway != NULL) {
653 rt.rtmsg_flags |= RTF_GATEWAY;
654 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
655 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
656 DBG("inet_pton failed : %s", error_buf);
663 fd = socket(AF_INET6, SOCK_DGRAM, 0);
665 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
666 DBG("Failed to create socket : %s", error_buf);
670 rt.rtmsg_ifindex = 0;
674 memset(&ifr, 0, sizeof(ifr));
675 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
676 ioctl(fd, SIOCGIFINDEX, &ifr);
677 rt.rtmsg_ifindex = ifr.ifr_ifindex;
680 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
681 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
682 DBG("Failed to add route: %s", error_buf);
692 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
698 memset(&rt, 0, sizeof(rt));
700 rt.rtmsg_dst_len = prefix_len;
702 rt.rtmsg_flags = RTF_UP | RTF_HOST;
704 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
709 if (gateway != NULL) {
710 rt.rtmsg_flags |= RTF_GATEWAY;
711 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
719 fd = socket(AF_INET6, SOCK_DGRAM, 0);
723 rt.rtmsg_ifindex = 0;
727 memset(&ifr, 0, sizeof(ifr));
728 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
729 ioctl(fd, SIOCGIFINDEX, &ifr);
730 rt.rtmsg_ifindex = ifr.ifr_ifindex;
733 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
734 DBG("Failed to del route: %d\n", err);
744 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
746 #if defined TIZEN_P2P_ENABLE
748 DBG("Launch Wi-Fi direct daemon");
750 const char *path = "/usr/bin/wifi-direct-server.sh";
751 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
752 char *const envs[] = { NULL };
754 ret = netconfig_execute_file(path, args, envs);
756 ERR("Failed to launch Wi-Fi direct daemon");
757 netconfig_error_wifi_direct_failed(context);
761 wifi_complete_launch_direct(wifi, context);
764 wifi_complete_launch_direct(wifi, context);
769 int execute_mdnsd_script(char* op) {
770 const char *path = "/usr/bin/mdnsresponder-server.sh";
771 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
772 char *const envs[] = { NULL };
774 return netconfig_execute_file(path, args, envs);
777 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context)
779 DBG("Launch mdnsresponder daemon");
781 if (execute_mdnsd_script("start") < 0) {
782 ERR("Failed to launch mdnsresponder daemon");
783 netconfig_error_invalid_parameter(context);
788 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
790 network_complete_launch_mdns(object, context);
794 gboolean handle_unref_mdns(Network *object, GDBusMethodInvocation *context)
796 DBG("Unef mdnsresponder daemon");
798 if (mdnsd_ref_count <= 0) {
799 ERR("Invalid access");
800 netconfig_error_invalid_parameter(context);
806 DBG("Unref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
807 if (mdnsd_ref_count == 0) {
808 if (execute_mdnsd_script("stop") < 0) {
809 ERR("Failed to stop mdnsresponder daemon");
810 netconfig_error_invalid_parameter(context);
815 network_complete_unref_mdns(object, context);
819 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
823 static gboolean is_found_noti_exists = FALSE;
824 static gboolean is_portal_noti_exists = FALSE;
827 ERR("Invalid notification");
831 if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) {
832 if (is_found_noti_exists == FALSE)
835 is_found_noti_exists = FALSE;
836 } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) {
837 if (is_found_noti_exists == TRUE)
840 is_found_noti_exists = TRUE;
841 } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) {
842 if (is_portal_noti_exists == TRUE)
845 is_portal_noti_exists = TRUE;
846 } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) {
847 if (is_portal_noti_exists == FALSE)
850 is_portal_noti_exists = FALSE;
854 bundle_add(b, "_SYSPOPUP_TYPE_", noti);
857 DBG("ssid (%s)", ssid);
858 bundle_add(b, "_AP_NAME_", ssid);
861 ret = syspopup_launch("net-popup", b);
866 ERR("Unable to launch noti-popup. Err = %d", ret);
870 DBG("Successfully sent notification (%s)", noti);
874 int netconfig_send_message_to_net_popup(const char *title,
875 const char *content, const char *type, const char *ssid)
878 bundle *b = bundle_create();
880 bundle_add(b, "_SYSPOPUP_TITLE_", title);
881 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
882 bundle_add(b, "_SYSPOPUP_TYPE_", type);
883 bundle_add(b, "_AP_NAME_", ssid);
885 ret = syspopup_launch("net-popup", b);
892 int netconfig_send_restriction_to_net_popup(const char *title,
893 const char *type, const char *restriction)
896 bundle *b = bundle_create();
898 bundle_add(b, "_SYSPOPUP_TITLE_", title);
899 bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
900 bundle_add(b, "_SYSPOPUP_TYPE_", type);
901 bundle_add(b, "_RESTRICTED_TYPE_", restriction);
903 ret = syspopup_launch("net-popup", b);
910 void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val)
914 DBG("System event set [%s : %s : %s]", sys_evt, evt_key, evt_val);
917 bundle_add_str(b, evt_key, evt_val);
918 eventsystem_send_system_event(sys_evt, b);
922 void netconfig_set_vconf_int(const char * key, int value)
926 DBG("[%s: %d]", key, value);
928 ret = vconf_set_int(key, value);
930 ERR("Failed to set");
933 void netconfig_set_vconf_str(const char * key, const char * value)
937 DBG("[%s: %s]", key, value);
939 ret = vconf_set_str(key, value);
941 ERR("Failed to set");
944 int netconfig_vconf_get_int(const char * key, int *value)
948 ret = vconf_get_int(key, value);
949 if (ret != VCONF_OK) {
950 ERR("Failed to get vconfkey [%s] value", key);
957 int netconfig_vconf_get_bool(const char * key, int *value)
961 ret = vconf_get_bool(key, value);
962 if (ret != VCONF_OK) {
963 ERR("Failed to get vconfkey [%s] value", key);
970 char* netconfig_get_env(const char *key)
973 char buf[256], *entry = NULL, *value = NULL, *last;
979 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
983 while (fgets(buf, sizeof(buf), fp)) {
985 entry = strtok_r(entry, "=", &last);
987 if (strstr(entry, key)) {
988 entry = strtok_r(NULL, "\n", &last);
991 value = (char*)malloc(len+1);
992 g_strlcpy(value, entry, len+1);
994 value = (char*)malloc(sizeof(char));
995 g_strlcpy(value, "\n", sizeof(char));
1006 void netconfig_set_mac_address_from_file(void)
1009 char mac_str[MAC_ADDRESS_MAX_LEN];
1010 gchar *mac_lower_str = NULL;
1013 file = fopen(MAC_INFO_FILEPATH, "r");
1015 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1018 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1019 ERR("Fail to read mac address");
1024 mac_len = strlen(mac_str);
1026 ERR("mac.info is empty");
1031 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1032 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1034 g_free(mac_lower_str);